From 3d65d3ea84db4853987a90542485213cff2786cd Mon Sep 17 00:00:00 2001 From: rekado Date: Tue, 16 Dec 2014 21:20:55 +0100 Subject: add tests for register-temp-stanza-handler-for-id --- spec/xmpp.scm | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/spec/xmpp.scm b/spec/xmpp.scm index 0b9a74b..9282e03 100644 --- a/spec/xmpp.scm +++ b/spec/xmpp.scm @@ -38,8 +38,40 @@ (setup 'presence2 (presence "body" #:id "1234")) (setup 'presence3 (presence "body" #:id "1234" #:from "romeo@capulet.it")))) -;; TODO -(suite "register-temp-stanza-handler-for-id" (tests)) +(suite "register-temp-stanza-handler-for-id" + (tests + (test "handler is not executed if stanza with non-matching id is received" e + (assert-false (error? + (begin + (register-temp-stanza-handler-for-id + "1234a" + (lambda _ (throw 'error))) + ((@@ (gnubba xmpp) handle-stanza) (e 'stanza)))))) + (test "handler remains if stanza with non-matching id is received" e + (assert-equal 1 + (begin + (register-temp-stanza-handler-for-id + "1234b" + (lambda _ (throw 'error))) + ((@@ (gnubba xmpp) handle-stanza) (e 'stanza)) + (hash-count (const #t) + (@@ (gnubba xmpp) *stanza-id-handlers*))))) + (test "handler is removed after execution" e + (assert-equal 0 + (begin + (register-temp-stanza-handler-for-id + "999" + (lambda _ 'handler)) + ((@@ (gnubba xmpp) handle-stanza) (e 'stanza)) + (hash-count (const #t) + (@@ (gnubba xmpp) *stanza-id-handlers*)))))) + (options) + (setups + (setup 'stanza (iq "payload" #:to "romeo@capulet.it" #:id "999"))) + (teardowns + ;; always reset the internal state after each test + (teardown e (set! (@@ (gnubba xmpp) *stanza-id-handlers*) + (make-hash-table))))) (suite "register-stanza-handler" (tests -- cgit v1.2.3