summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2014-12-16 21:20:55 +0100
committerrekado <rekado@elephly.net>2014-12-16 21:20:55 +0100
commit3d65d3ea84db4853987a90542485213cff2786cd (patch)
treeb0d307ef78306a7f515b2791cf9ddd4c2c4e0c17
parent71ac7c2b1cdf22e1203ce378874faec4d0edd6c4 (diff)
add tests for register-temp-stanza-handler-for-idHEADmaster
-rw-r--r--spec/xmpp.scm36
1 files 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