1 (in-package #:zmq.tests
)
10 (defparameter *test-endpoint
* "tcp://127.0.0.1:31723")
15 "Version should return"
16 (is (not (null (zmq:version
)))))
18 ;: Creating and configuring contexts
21 "Context should be creatable and destroyable."
22 (let ((ctx (zmq:ctx-new
)))
24 (is (zerop (zmq:ctx-destroy ctx
)))
25 (signals (zmq:zmq-error
26 "Destroyed context shouldn't be destroyable")
27 (zmq:ctx-destroy ctx
))))
30 "Context settings should be retrievable."
31 (zmq:with-context
(ctx)
32 (let ((ctx (zmq:ctx-new
)))
33 (is (= 1 (zmq:ctx-get ctx
:io-threads
)))
34 (is (= 1024 (zmq:ctx-get ctx
:max-sockets
)))
35 (signals (zmq:zmq-error
36 "Invalid setting keywords should signal an error")
37 (zmq:ctx-get ctx
:invalid-stuff
)))))
40 "Context setting should be changeable."
41 (zmq:with-context
(ctx)
42 (is (zerop (zmq:ctx-set ctx
:io-threads
10)))
43 (is (= 10 (zmq:ctx-get ctx
:io-threads
))
44 "Setting settings should make getting return appropriately")
45 (signals (zmq:zmq-error
46 "Invalid setting keywords should signal an error")
47 (zmq:ctx-set ctx
:invalid-stuff
10))))
49 (test ctx-abnormal-get-set
50 "Accesing settings of destroyed context should signal an error"
51 (let ((ctx (zmq:ctx-new
)))
53 (signals (zmq:zmq-error
)
54 (zmq:ctx-set ctx
:io-threads
10))
55 (signals (zmq:zmq-error
)
56 (zmq:ctx-get ctx
:max-sockets
))))
58 ;; Creating and configuring sockets
61 "Sockets should be creatable and closable"
62 (zmq:with-context
(ctx)
63 (let ((socket (zmq:socket ctx
:pub
)))
64 (is (not (null socket
)))
65 (is (zerop (zmq:close socket
)))
66 (signals (zmq:zmq-error
67 "Closed sockets can't be closed again")
68 (zmq:close socket
)))))
70 (test socket-abnormal-creation
71 "Abnormal socket creation should signal error."
72 (let ((ctx (zmq:ctx-new
)))
73 (signals (zmq:zmq-error
74 "Creating socket with wrong type should signal error")
75 (zmq:socket ctx
:invalid-type
))
77 (signals (zmq:zmq-error
78 "Socket can't be created from closed context")
79 (zmq:socket ctx
:pub
))))
82 "Socket should be bindable and unbindable."
83 (zmq:with-context
(ctx)
84 (zmq:with-socket
(s ctx
:push
)
85 (is (zerop (zmq:bind s
*test-endpoint
*)))
86 (signals (zmq:zmq-error
87 "Can't bind to one endpoint twice")
88 (zerop (zmq:bind s
*test-endpoint
*)))
89 (is (zerop (zmq:unbind s
*test-endpoint
*)))
90 (signals (zmq:zmq-error
91 "Socket can not be unbound if not bound")
92 (zerop (zmq:unbind s
*test-endpoint
*))))))
95 "Socket should be able to connect and disconnect."
96 (zmq:with-context
(ctx)
97 (zmq:with-socket
(s ctx
:push
)
98 (is (zerop (zmq:connect s
*test-endpoint
*)))
99 (is (zerop (zmq:disconnect s
*test-endpoint
*)))
100 (signals (zmq:zmq-error
101 "Socket can not be connected if it is not")
102 (zerop (zmq:disconnect s
*test-endpoint
*))))))
105 "Socket settings should be retrievable."
106 (zmq:with-context
(ctx)
107 (zmq:with-socket
(s ctx
:pub
)
108 (is (= 0 (zmq:getsockopt s
:affinity
)))
109 (signals (zmq:zmq-error
110 "Invalid setting keywords should signal an error.")
111 (zmq:getsockopt s
:invalid-stuff
)))))
114 "Socket settings should be settable."
115 (zmq:with-context
(ctx)
116 (zmq:with-socket
(s ctx
:pub
)
117 (is (zerop (zmq:setsockopt s
:affinity
10)))
118 (is (= 10 (zmq:getsockopt s
:affinity
)))
119 (signals (zmq:zmq-error
120 "Invalid setting keywords should signal an error")
121 (zmq:setsockopt s
:invalid-stuff
10)))))
123 (test socket-get-set-string
124 "Socket settings that are strings should work too."
125 (zmq:with-context
(ctx)
126 (zmq:with-socket
(s ctx
:pub
)
127 (is (zerop (zmq:setsockopt s
:identity
"Foobar")))
128 (is (equal "Foobar" (zmq:getsockopt s
:identity
))))))