add tests for register-temp-stanza-handler-for-id master
authorrekado <rekado@elephly.net>
Tue, 16 Dec 2014 20:20:55 +0000 (21:20 +0100)
committerrekado <rekado@elephly.net>
Tue, 16 Dec 2014 20:20:55 +0000 (21:20 +0100)
spec/xmpp.scm

index 0b9a74b25ade684272fb7c07a202f4be9e5f9d88..9282e033a39f4fed924d2ec52988c7d93adb9f1c 100644 (file)
         (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