Figured that my tests were never added.
[cl-zmq.git] / tests / main.lisp
blob2dd51814d7b2ebcc275dfb012e2133362dfcebaa
1 (in-package #:zmq.tests)
3 (defun run-tests ()
4 (run! 'main))
6 (def-suite main)
8 (in-suite main)
10 (defparameter *test-endpoint* "tcp://127.0.0.1:31723")
12 ;; Version
14 (test version
15 "Version should return"
16 (is (not (null (zmq:version)))))
18 ;: Creating and configuring contexts
20 (test ctx
21 "Context should be creatable and destroyable."
22 (let ((ctx (zmq:ctx-new)))
23 (is (not (null ctx)))
24 (is (zerop (zmq:ctx-destroy ctx)))
25 (signals (zmq:zmq-error
26 "Destroyed context shouldn't be destroyable")
27 (zmq:ctx-destroy ctx))))
29 (test ctx-get
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)))))
39 (test ctx-set
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)))
52 (zmq:ctx-destroy ctx)
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
60 (test socket
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))
76 (zmq:ctx-destroy ctx)
77 (signals (zmq:zmq-error
78 "Socket can't be created from closed context")
79 (zmq:socket ctx :pub))))
81 (test socket-bind
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*))))))
94 (test socket-connect
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*))))))
104 (test socket-get
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)))))
113 (test socket-set
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))))))