]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/test/cl/tests.lisp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / test / cl / tests.lisp
1 (in-package #:thrift-cross)
2
3 ;;;; Licensed under the Apache License, Version 2.0 (the "License");
4 ;;;; you may not use this file except in compliance with the License.
5 ;;;; You may obtain a copy of the License at
6 ;;;;
7 ;;;; http://www.apache.org/licenses/LICENSE-2.0
8 ;;;;
9 ;;;; Unless required by applicable law or agreed to in writing, software
10 ;;;; distributed under the License is distributed on an "AS IS" BASIS,
11 ;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 ;;;; See the License for the specific language governing permissions and
13 ;;;; limitations under the License.
14
15 ;;;; The tests here only make sense in the context of a TestServer
16 ;;;; running and the dynamic variable thrift-cross::*prot*
17 ;;;; being set with a client connection to the TestServer. Normally,
18 ;;;; this is handled in make-test-client.lisp.
19
20
21 ;;; Standard Thrift cross-test error codes
22 (defparameter *test_basetypes* 1)
23 (defparameter *test_structs* 2)
24 (defparameter *test_containers* 4)
25 (defparameter *test_exceptions* 8)
26 (defparameter *test_unknown* 64)
27 (defparameter *test_timeout* 128)
28
29 (defun cross-test (&key (multiplexed nil))
30 "The main cross-test runner."
31 (let ((result nil))
32 (handler-case
33 (progn
34 (unless (run-package-tests :package :base-types)
35 (pushnew *test_basetypes* result))
36 (unless (run-package-tests :package :structs)
37 (pushnew *test_structs* result))
38 (unless (run-package-tests :package :containers)
39 (pushnew *test_containers* result))
40 (unless (run-package-tests :package :exceptions)
41 (pushnew *test_exceptions* result))
42 (unless (run-package-tests :package :misc)
43 (pushnew *test_unknown* result))
44
45 ;; It doesn't seem like anyone actually uses
46 ;; the second test service when testing multiplexing,
47 ;; so this would fail against servers in other
48 ;; languages. For now, anyway.
49 #+(or)
50 (when multiplexed
51 (unless (run-package-tests :package :multiplex)
52 (pushnew *test_unknown* result))))
53 (error (e) (pushnew *test_unknown* result)))
54 (apply #'+ result)))
55
56 (fiasco:define-test-package #:base-types)
57
58 (in-package #:base-types)
59
60 (defconstant *lang-string* "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語")
61
62 (defparameter *trick-string* (format nil "quote: \" backslash: \\ newline: ~% backspace: ~C ~
63 tab: ~T junk: !@#$%&()(&%$#{}{}<><><" #\backspace))
64
65 (defconstant *binary-sequence* #(128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127))
66
67 (deftest void-test ()
68 (is (null (thrift.test.thrift-test:test-void thrift-cross::*prot*))))
69
70 (deftest boolean-test ()
71 (is (thrift.test.thrift-test:test-bool thrift-cross::*prot* t))
72 (is (not (thrift.test.thrift-test:test-bool thrift-cross::*prot* nil))))
73
74 (deftest integer-test ()
75 (is (= (thrift.test.thrift-test:test-byte thrift-cross::*prot* 127) 127))
76 (is (= (thrift.test.thrift-test:test-byte thrift-cross::*prot* -128) -128))
77 (is (= (thrift.test.thrift-test:test-byte thrift-cross::*prot* 42) 42))
78 (is (= (thrift.test.thrift-test:test-byte thrift-cross::*prot* 0) 0))
79 (is (= (thrift.test.thrift-test:test-i32 thrift-cross::*prot* 0) 0))
80 (is (= (thrift.test.thrift-test:test-i32 thrift-cross::*prot* 2147483647) 2147483647))
81 (is (= (thrift.test.thrift-test:test-i32 thrift-cross::*prot* -2147483648) -2147483648))
82 (is (= (thrift.test.thrift-test:test-i64 thrift-cross::*prot* 0) 0))
83 (is (= (thrift.test.thrift-test:test-i64 thrift-cross::*prot* 9223372036854775807) 9223372036854775807))
84 (is (= (thrift.test.thrift-test:test-i64 thrift-cross::*prot* -9223372036854775808) -9223372036854775808)))
85
86 (deftest double-test ()
87 (is (= (thrift.test.thrift-test:test-double thrift-cross::*prot* 0.0) 0))
88 (is (= (thrift.test.thrift-test:test-double thrift-cross::*prot* 42.0) 42))
89 (is (= (thrift.test.thrift-test:test-double thrift-cross::*prot* -555.0) -555))
90 (is (= (thrift.test.thrift-test:test-double thrift-cross::*prot* -52.3678) -52.3678)))
91
92 (deftest string-test ()
93 (is (string= (thrift.test.thrift-test:test-string thrift-cross::*prot* "") ""))
94 (is (string= (thrift.test.thrift-test:test-string thrift-cross::*prot* "(defun botsbuildbots () (botsbuilsbots))")
95 "(defun botsbuildbots () (botsbuilsbots))"))
96 (is (string= (thrift.test.thrift-test:test-string thrift-cross::*prot* *lang-string*) *lang-string*))
97 (is (string= (thrift.test.thrift-test:test-string thrift-cross::*prot* *trick-string*) *trick-string*)))
98
99 (deftest binary-test ()
100 (is (equalp (thrift.test.thrift-test:test-binary thrift-cross::*prot* #()) #()))
101 (is (equalp (thrift.test.thrift-test:test-binary thrift-cross::*prot* *binary-sequence*) *binary-sequence*)))
102
103 (deftest enum-test ()
104 (is (= (thrift.test.thrift-test:test-enum thrift-cross::*prot* thrift.test:numberz.five) thrift.test:numberz.five))
105 (is (= (thrift.test.thrift-test:test-enum thrift-cross::*prot* thrift.test:numberz.eight) thrift.test:numberz.eight))
106 (is (= (thrift.test.thrift-test:test-enum thrift-cross::*prot* thrift.test:numberz.one) thrift.test:numberz.one)))
107
108 (deftest typedef-test ()
109 (is (= (thrift.test.thrift-test:test-typedef thrift-cross::*prot* 309858235082523) 309858235082523)))
110
111 (fiasco:define-test-package #:structs)
112
113 (in-package #:structs)
114
115 (defparameter *test-struct* (thrift.test:make-xtruct :string-thing "Hell is empty."
116 :byte-thing -2
117 :i32-thing 42
118 :i64-thing 42424242))
119
120 (defparameter *test-nest* (thrift.test:make-xtruct2 :byte-thing 42
121 :struct-thing *test-struct*
122 :i32-thing -42))
123
124 (deftest struct-test ()
125 (let ((rec-struct (thrift.test.thrift-test:test-struct thrift-cross::*prot* *test-struct*)))
126 (is (string= (thrift.test:xtruct-string-thing *test-struct*)
127 (thrift.test:xtruct-string-thing rec-struct)))
128 (is (= (thrift.test:xtruct-byte-thing *test-struct*)
129 (thrift.test:xtruct-byte-thing rec-struct)))
130 (is (= (thrift.test:xtruct-i32-thing *test-struct*)
131 (thrift.test:xtruct-i32-thing rec-struct)))
132 (is (= (thrift.test:xtruct-i64-thing *test-struct*)
133 (thrift.test:xtruct-i64-thing rec-struct)))))
134
135 (deftest nest-test ()
136 (let* ((rec-nest (thrift.test.thrift-test:test-nest thrift-cross::*prot* *test-nest*))
137 (rec-struct (thrift.test:xtruct2-struct-thing rec-nest)))
138 (is (string= (thrift.test:xtruct-string-thing *test-struct*)
139 (thrift.test:xtruct-string-thing rec-struct)))
140 (is (= (thrift.test:xtruct-byte-thing *test-struct*)
141 (thrift.test:xtruct-byte-thing rec-struct)))
142 (is (= (thrift.test:xtruct-i32-thing *test-struct*)
143 (thrift.test:xtruct-i32-thing rec-struct)))
144 (is (= (thrift.test:xtruct-i64-thing *test-struct*)
145 (thrift.test:xtruct-i64-thing rec-struct)))
146 (is (= (thrift.test:xtruct2-byte-thing *test-nest*)
147 (thrift.test:xtruct2-byte-thing rec-nest)))
148 (is (= (thrift.test:xtruct2-i32-thing *test-nest*)
149 (thrift.test:xtruct2-i32-thing rec-nest)))))
150
151 (fiasco:define-test-package #:containers)
152
153 (in-package #:containers)
154
155 (deftest list-test ()
156 (is (null (thrift.test.thrift-test:test-list thrift-cross::*prot* nil)))
157 (is (equal (thrift.test.thrift-test:test-list thrift-cross::*prot* '(42 -42 0 5)) '(42 -42 0 5))))
158
159 (deftest set-test ()
160 (is (null (thrift.test.thrift-test:test-set thrift-cross::*prot* nil)))
161 (is (equal (sort (thrift.test.thrift-test:test-set thrift-cross::*prot* (list 42 -42 0 5)) #'<)
162 '(-42 0 5 42))))
163
164 (defun map= (map1 map2 &key (car-predicate #'equal) (cdr-predicate #'equal))
165 "Compare two assoc maps according to the predicates given."
166 (not (set-exclusive-or map1 map2 :test (lambda (el1 el2)
167 (and (funcall car-predicate
168 (car el1)
169 (car el2))
170 (funcall cdr-predicate
171 (cdr el1)
172 (cdr el2)))))))
173
174 (deftest map-test ()
175 (is (null (thrift.test.thrift-test:test-map thrift-cross::*prot* nil)))
176 (is (map= (thrift.test.thrift-test:test-map thrift-cross::*prot* '((0 . 1) (42 . -42) (5 . 5)))
177 '((0 . 1) (42 . -42) (5 . 5))))
178 (is (map= (thrift.test.thrift-test:test-map-map thrift-cross::*prot* 42)
179 '((-4 . ((-4 . -4) (-3 . -3) (-2 . -2) (-1 . -1)))
180 (4 . ((1 . 1) (2 . 2) (3 . 3) (4 . 4))))
181 :cdr-predicate #'map=)))
182
183 (fiasco:define-test-package #:exceptions)
184
185 (in-package #:exceptions)
186
187 (defun test-xception (expected-code expected-message function &rest args)
188 "A helper function to test whether xception is signalled, and whether its fields have the expected values."
189 (handler-case (progn (apply function args)
190 nil)
191 (thrift.test:xception (ex) (and (= (thrift.test::xception-error-code ex) expected-code)
192 (string= (thrift.test::xception-message ex) expected-message)))))
193
194 (defun test-xception2 (expected-code expected-message function &rest args)
195 "A helper function to test whether xception2 is signalled, and whether its fields have the expected values."
196 (handler-case (progn (apply function args)
197 nil)
198 (thrift.test:xception2 (ex) (and (= (thrift.test::xception2-error-code ex) expected-code)
199 (string= (thrift.test::xtruct-string-thing
200 (thrift.test::xception2-struct-thing ex))
201 expected-message)))))
202
203 (deftest exception-test ()
204 (is (test-xception 1001 "Xception" #'thrift.test.thrift-test:test-exception thrift-cross::*prot* "Xception"))
205 (signals thrift:application-error (thrift.test.thrift-test:test-exception thrift-cross::*prot* "TException"))
206 (finishes (thrift.test.thrift-test:test-exception thrift-cross::*prot* "success")))
207
208 (deftest multi-exception-test ()
209 (is (test-xception 1001
210 "This is an Xception"
211 #'thrift.test.thrift-test:test-multi-exception
212 thrift-cross::*prot*
213 "Xception"
214 "meaningless"))
215 (is (test-xception2 2002
216 "This is an Xception2"
217 #'thrift.test.thrift-test:test-multi-exception
218 thrift-cross::*prot*
219 "Xception2"
220 "meaningless too!"))
221 (is (string= "foobar" (thrift.test:xtruct-string-thing
222 (thrift.test.thrift-test:test-multi-exception thrift-cross::*prot*
223 "success!"
224 "foobar")))))
225
226 (fiasco:define-test-package #:misc)
227
228 (in-package #:misc)
229
230 (deftest oneway-test ()
231 (is (null (thrift.test.thrift-test:test-oneway thrift-cross::*prot* 1))))
232
233 (fiasco:define-test-package #:multiplex)
234
235 (in-package #:multiplex)
236
237 (deftest multiplex-test ()
238 ;; Removed from the IDL definition.
239 ;; (finishes (thrift.test.second-service:blah-blah thrift-cross::*prot*))
240 (is (string= "asd" (thrift.test.second-service:secondtest-string thrift-cross::*prot* "asd"))))