2 %% Licensed to the Apache Software Foundation (ASF) under one
3 %% or more contributor license agreements. See the NOTICE file
4 %% distributed with this work for additional information
5 %% regarding copyright ownership. The ASF licenses this file
6 %% to you under the Apache License, Version 2.0 (the
7 %% "License"); you may not use this file except in compliance
8 %% with the License. You may obtain a copy of the License at
10 %% http://www.apache.org/licenses/LICENSE-2.0
12 %% Unless required by applicable law or agreed to in writing,
13 %% software distributed under the License is distributed on an
14 %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 %% KIND, either express or implied. See the License for the
16 %% specific language governing permissions and limitations
20 % don't rename this thrift_test, it clobbers generated files
21 -module(thrift_test_test).
24 -include_lib("eunit/include/eunit.hrl").
26 -include("gen-erl/thrift_test_constants.hrl").
30 {"myNumberz equals 1", ?_assertEqual(1, ?THRIFT_TEST_MYNUMBERZ)}
33 record_generation_test_() ->
35 {"Bonk record", ?_assertMatch(
36 {'thrift.test.Bonk', _, _},
37 #'thrift.test.Bonk'{message=null,type=null}
39 {"Bools record", ?_assertMatch(
40 {'thrift.test.Bools', _, _},
41 #'thrift.test.Bools'{im_true=null,im_false=null}
43 {"Xtruct record", ?_assertMatch(
44 {'thrift.test.Xtruct', _, _, _, _},
45 #'thrift.test.Xtruct'{string_thing=null,byte_thing=null,i32_thing=null,i64_thing=null}
47 {"Xtruct2 record", ?_assertMatch(
48 {'thrift.test.Xtruct2', _, _, _},
49 #'thrift.test.Xtruct2'{byte_thing=null,struct_thing=null,i32_thing=null}
51 {"Xtruct3 record", ?_assertMatch(
52 {'thrift.test.Xtruct3', _, _, _, _},
53 #'thrift.test.Xtruct3'{string_thing=null,changed=null,i32_thing=null,i64_thing=null}
55 {"Insanity record", ?_assertMatch(
56 {'thrift.test.Insanity', _, _},
57 #'thrift.test.Insanity'{userMap=null,xtructs=null}
59 {"CrazyNesting record", ?_assertMatch(
60 {'thrift.test.CrazyNesting', _, _, _, _},
61 #'thrift.test.CrazyNesting'{
68 {"Xception record", ?_assertMatch(
69 {'thrift.test.Xception', _, _},
70 #'thrift.test.Xception'{errorCode=null,message=null}
72 {"Xception2 record", ?_assertMatch(
73 {'thrift.test.Xception2', _, _},
74 #'thrift.test.Xception2'{errorCode=null,struct_thing=null}
76 {"EmptyStruct record", ?_assertMatch({'thrift.test.EmptyStruct'}, #'thrift.test.EmptyStruct'{})},
77 {"OneField record", ?_assertMatch({'thrift.test.OneField', _}, #'thrift.test.OneField'{field=null})},
78 {"VersioningTestV1 record", ?_assertMatch(
79 {'thrift.test.VersioningTestV1', _, _, _},
80 #'thrift.test.VersioningTestV1'{begin_in_both=null,old_string=null,end_in_both=null}
82 {"VersioningTestV2 record", ?_assertMatch(
83 {'thrift.test.VersioningTestV2', _, _, _, _, _, _, _, _, _, _, _, _},
84 #'thrift.test.VersioningTestV2'{
99 {"ListTypeVersioningV1 record", ?_assertMatch(
100 {'thrift.test.ListTypeVersioningV1', _, _},
101 #'thrift.test.ListTypeVersioningV1'{myints=null,hello=null}
103 {"ListTypeVersioningV2 record", ?_assertMatch(
104 {'thrift.test.ListTypeVersioningV2', _, _},
105 #'thrift.test.ListTypeVersioningV2'{strings=null,hello=null}
107 {"GuessProtocolStruct record", ?_assertMatch(
108 {'thrift.test.GuessProtocolStruct', _},
109 #'thrift.test.GuessProtocolStruct'{map_field=null}
111 {"LargeDeltas record", ?_assertMatch(
112 {'thrift.test.LargeDeltas', _, _, _, _, _, _, _, _, _, _},
113 #'thrift.test.LargeDeltas'{
126 {"NestedListsI32x2 record", ?_assertMatch(
127 {'thrift.test.NestedListsI32x2', _},
128 #'thrift.test.NestedListsI32x2'{integerlist=null}
130 {"NestedListsI32x3 record", ?_assertMatch(
131 {'thrift.test.NestedListsI32x3', _},
132 #'thrift.test.NestedListsI32x3'{integerlist=null}
134 {"NestedMixedx2 record", ?_assertMatch(
135 {'thrift.test.NestedMixedx2', _, _, _},
136 #'thrift.test.NestedMixedx2'{
139 map_int_strset_list=null
142 {"ListBonks record", ?_assertMatch({'thrift.test.ListBonks', _}, #'thrift.test.ListBonks'{bonk=null})},
143 {"NestedListsBonk record", ?_assertMatch(
144 {'thrift.test.NestedListsBonk', _},
145 #'thrift.test.NestedListsBonk'{bonk=null}
147 {"BoolTest record", ?_assertMatch(
148 {'thrift.test.BoolTest', _, _},
149 #'thrift.test.BoolTest'{b=null,s=null}
151 {"StructA record", ?_assertMatch({'thrift.test.StructA', _}, #'thrift.test.StructA'{s=null})},
152 {"StructB record", ?_assertMatch(
153 {'thrift.test.StructB', _, _},
154 #'thrift.test.StructB'{aa=null,ab=null}
158 struct_info_test_() ->
160 {"Bonk definition (short version)", ?_assertEqual(
161 {struct, [{1, string}, {2, i32}]},
162 thrift_test_types:struct_info('thrift.test.Bonk')
164 {"Bonk definition", ?_assertEqual(
166 {1, undefined, string, message, undefined},
167 {2, undefined, i32, type, undefined}
169 thrift_test_types:struct_info_ext('thrift.test.Bonk')
171 {"Bools definition", ?_assertEqual(
173 {1, undefined, bool, im_true, undefined},
174 {2, undefined, bool, im_false, undefined}
176 thrift_test_types:struct_info_ext('thrift.test.Bools')
178 {"Xtruct definition", ?_assertEqual(
180 {1, undefined, string, string_thing, undefined},
181 {4, undefined, byte, byte_thing, undefined},
182 {9, undefined, i32, i32_thing, undefined},
183 {11, undefined, i64, i64_thing, undefined}
185 thrift_test_types:struct_info_ext('thrift.test.Xtruct')
187 {"Xtruct2 definition", ?_assertEqual(
189 {1, undefined, byte, byte_thing, undefined},
190 {2, undefined, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}, struct_thing, #'thrift.test.Xtruct'{}},
191 {3, undefined, i32, i32_thing, undefined}
193 thrift_test_types:struct_info_ext('thrift.test.Xtruct2')
195 {"Xtruct3 definition", ?_assertEqual(
197 {1, undefined, string, string_thing, undefined},
198 {4, undefined, i32, changed, undefined},
199 {9, undefined, i32, i32_thing, undefined},
200 {11, undefined, i64, i64_thing, undefined}
202 thrift_test_types:struct_info_ext('thrift.test.Xtruct3')
204 {"Insanity definition", ?_assertEqual(
206 {1, undefined, {map, i32, i64}, userMap, dict:new()},
207 {2, undefined, {list, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}}, xtructs, []}
209 thrift_test_types:struct_info_ext('thrift.test.Insanity')
211 {"CrazyNesting definition", ?_assertEqual(
213 {1, undefined, string, string_field, undefined},
214 {2, optional, {set, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}}, set_field, sets:new()},
215 {3, required, {list, {map,
217 {map, i32, {set, {list, {map, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}, string}}}}
219 {4, undefined, string, binary_field, undefined}
221 thrift_test_types:struct_info_ext('thrift.test.CrazyNesting')
223 {"Xception definition", ?_assertEqual(
225 {1, undefined, i32, errorCode, undefined},
226 {2, undefined, string, message, undefined}
228 thrift_test_types:struct_info_ext('thrift.test.Xception')
230 {"Xception2 definition", ?_assertEqual(
232 {1, undefined, i32, errorCode, undefined},
233 {2, undefined, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}, struct_thing, #'thrift.test.Xtruct'{}}
235 thrift_test_types:struct_info_ext('thrift.test.Xception2')
237 {"EmptyStruct definition", ?_assertEqual(
239 thrift_test_types:struct_info_ext('thrift.test.EmptyStruct')
241 {"OneField definition", ?_assertEqual(
243 {1, undefined, {struct, {'thrift_test_types', 'thrift.test.EmptyStruct'}}, field, #'thrift.test.EmptyStruct'{}}
245 thrift_test_types:struct_info_ext('thrift.test.OneField')
247 {"VersioningTestV1 definition", ?_assertEqual(
249 {1, undefined, i32, begin_in_both, undefined},
250 {3, undefined, string, old_string, undefined},
251 {12, undefined, i32, end_in_both, undefined}
253 thrift_test_types:struct_info_ext('thrift.test.VersioningTestV1')
255 {"VersioningTestV2 definition", ?_assertEqual(
257 {1, undefined, i32, begin_in_both, undefined},
258 {2, undefined, i32, newint, undefined},
259 {3, undefined, byte, newbyte, undefined},
260 {4, undefined, i16, newshort, undefined},
261 {5, undefined, i64, newlong, undefined},
262 {6, undefined, double, newdouble, undefined},
263 {7, undefined, {struct, {thrift_test_types, 'thrift.test.Bonk'}}, newstruct, #'thrift.test.Bonk'{}},
264 {8, undefined, {list, i32}, newlist, []},
265 {9, undefined, {set, i32}, newset, sets:new()},
266 {10, undefined, {map, i32, i32}, newmap, dict:new()},
267 {11, undefined, string, newstring, undefined},
268 {12, undefined, i32, end_in_both, undefined}
270 thrift_test_types:struct_info_ext('thrift.test.VersioningTestV2')
272 {"ListTypeVersioningV1 definition", ?_assertEqual(
274 {1, undefined, {list, i32}, myints, []},
275 {2, undefined, string, hello, undefined}
277 thrift_test_types:struct_info_ext('thrift.test.ListTypeVersioningV1')
279 {"ListTypeVersioningV2 definition", ?_assertEqual(
281 {1, undefined, {list, string}, strings, []},
282 {2, undefined, string, hello, undefined}
284 thrift_test_types:struct_info_ext('thrift.test.ListTypeVersioningV2')
286 {"GuessProtocolStruct definition", ?_assertEqual(
288 {7, undefined, {map, string, string}, map_field, dict:new()}
290 thrift_test_types:struct_info_ext('thrift.test.GuessProtocolStruct')
292 {"LargeDeltas definition", ?_assertEqual(
294 {1, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b1, #'thrift.test.Bools'{}},
295 {10, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b10, #'thrift.test.Bools'{}},
296 {100, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b100, #'thrift.test.Bools'{}},
297 {500, undefined, bool, check_true, undefined},
298 {1000, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b1000, #'thrift.test.Bools'{}},
299 {1500, undefined, bool, check_false, undefined},
300 {2000, undefined, {struct, {thrift_test_types, 'thrift.test.VersioningTestV2'}}, vertwo2000, #'thrift.test.VersioningTestV2'{}},
301 {2500, undefined, {set, string}, a_set2500, sets:new()},
302 {3000, undefined, {struct, {thrift_test_types, 'thrift.test.VersioningTestV2'}}, vertwo3000, #'thrift.test.VersioningTestV2'{}},
303 {4000, undefined, {list, i32}, big_numbers, []}
305 thrift_test_types:struct_info_ext('thrift.test.LargeDeltas')
307 {"NestedListsI32x2 definition", ?_assertEqual(
309 {1, undefined, {list, {list, i32}}, integerlist, []}
311 thrift_test_types:struct_info_ext('thrift.test.NestedListsI32x2')
313 {"NestedListsI32x3 definition", ?_assertEqual(
315 {1, undefined, {list, {list, {list, i32}}}, integerlist, []}
317 thrift_test_types:struct_info_ext('thrift.test.NestedListsI32x3')
319 {"NestedMixedx2 definition", ?_assertEqual(
321 {1, undefined, {list, {set, i32}}, int_set_list, []},
322 {2, undefined, {map, i32, {set, string}}, map_int_strset, dict:new()},
323 {3, undefined, {list, {map, i32, {set, string}}}, map_int_strset_list, []}
325 thrift_test_types:struct_info_ext('thrift.test.NestedMixedx2')
327 {"ListBonks definition", ?_assertEqual(
329 {1, undefined, {list, {struct, {thrift_test_types, 'thrift.test.Bonk'}}}, bonk, []}
331 thrift_test_types:struct_info_ext('thrift.test.ListBonks')
333 {"NestedListsBonk definition", ?_assertEqual(
335 {1, undefined, {list, {list, {list, {struct, {thrift_test_types, 'thrift.test.Bonk'}}}}}, bonk, []}
337 thrift_test_types:struct_info_ext('thrift.test.NestedListsBonk')
339 {"BoolTest definition", ?_assertEqual(
341 {1, optional, bool, b, true},
342 {2, optional, string, s, "true"}
344 thrift_test_types:struct_info_ext('thrift.test.BoolTest')
346 {"StructA definition", ?_assertEqual(
347 {struct, [{1, required, string, s, undefined}]},
348 thrift_test_types:struct_info_ext('thrift.test.StructA')
350 {"StructB definition", ?_assertEqual(
352 {1, optional, {struct, {thrift_test_types, 'thrift.test.StructA'}}, aa, #'thrift.test.StructA'{}},
353 {2, required, {struct, {thrift_test_types, 'thrift.test.StructA'}}, ab, #'thrift.test.StructA'{}}
355 thrift_test_types:struct_info_ext('thrift.test.StructB')
359 service_info_test_() ->
361 {"testVoid params", ?_assertEqual(
363 thrift_test_thrift:function_info(testVoid, params_type)
365 {"testVoid reply", ?_assertEqual(
367 thrift_test_thrift:function_info(testVoid, reply_type)
369 {"testVoid exceptions", ?_assertEqual(
371 thrift_test_thrift:function_info(testVoid, exceptions)
373 {"testString params", ?_assertEqual(
374 {struct, [{1, string}]},
375 thrift_test_thrift:function_info(testString, params_type)
377 {"testString reply", ?_assertEqual(
379 thrift_test_thrift:function_info(testString, reply_type)
381 {"testString exceptions", ?_assertEqual(
383 thrift_test_thrift:function_info(testString, exceptions)
385 {"testByte params", ?_assertEqual(
386 {struct, [{1, byte}]},
387 thrift_test_thrift:function_info(testByte, params_type)
389 {"testByte reply", ?_assertEqual(
391 thrift_test_thrift:function_info(testByte, reply_type)
393 {"testByte exceptions", ?_assertEqual(
395 thrift_test_thrift:function_info(testByte, exceptions)
397 {"testI32 params", ?_assertEqual(
398 {struct, [{1, i32}]},
399 thrift_test_thrift:function_info(testI32, params_type)
401 {"testI32 reply", ?_assertEqual(
403 thrift_test_thrift:function_info(testI32, reply_type)
405 {"testI32 exceptions", ?_assertEqual(
407 thrift_test_thrift:function_info(testI32, exceptions)
409 {"testI64 params", ?_assertEqual(
410 {struct, [{1, i64}]},
411 thrift_test_thrift:function_info(testI64, params_type)
413 {"testI64 reply", ?_assertEqual(
415 thrift_test_thrift:function_info(testI64, reply_type)
417 {"testI64 exceptions", ?_assertEqual(
419 thrift_test_thrift:function_info(testI64, exceptions)
421 {"testDouble params", ?_assertEqual(
422 {struct, [{1, double}]},
423 thrift_test_thrift:function_info(testDouble, params_type)
425 {"testDouble reply", ?_assertEqual(
427 thrift_test_thrift:function_info(testDouble, reply_type)
429 {"testDouble exceptions", ?_assertEqual(
431 thrift_test_thrift:function_info(testDouble, exceptions)
433 {"testStruct params", ?_assertEqual(
435 {1, {struct, {thrift_test_types, 'thrift.test.Xtruct'}}}
437 thrift_test_thrift:function_info(testStruct, params_type)
439 {"testStruct reply", ?_assertEqual(
440 {struct, {thrift_test_types, 'thrift.test.Xtruct'}},
441 thrift_test_thrift:function_info(testStruct, reply_type)
443 {"testStruct exceptions", ?_assertEqual(
445 thrift_test_thrift:function_info(testStruct, exceptions)
447 {"testNest params", ?_assertEqual(
449 {1, {struct, {thrift_test_types, 'thrift.test.Xtruct2'}}}
451 thrift_test_thrift:function_info(testNest, params_type)
453 {"testNest reply", ?_assertEqual(
454 {struct, {thrift_test_types, 'thrift.test.Xtruct2'}},
455 thrift_test_thrift:function_info(testNest, reply_type)
457 {"testNest exceptions", ?_assertEqual(
459 thrift_test_thrift:function_info(testNest, exceptions)
461 {"testMap params", ?_assertEqual(
465 thrift_test_thrift:function_info(testMap, params_type)
467 {"testMap reply", ?_assertEqual(
469 thrift_test_thrift:function_info(testMap, reply_type)
471 {"testMap exceptions", ?_assertEqual(
473 thrift_test_thrift:function_info(testMap, exceptions)
475 {"testStringMap params", ?_assertEqual(
477 {1, {map, string, string}}
479 thrift_test_thrift:function_info(testStringMap, params_type)
481 {"testStringMap reply", ?_assertEqual(
482 {map, string, string},
483 thrift_test_thrift:function_info(testStringMap, reply_type)
485 {"testStringMap exceptions", ?_assertEqual(
487 thrift_test_thrift:function_info(testStringMap, exceptions)
489 {"testSet params", ?_assertEqual(
493 thrift_test_thrift:function_info(testSet, params_type)
495 {"testSet reply", ?_assertEqual(
497 thrift_test_thrift:function_info(testSet, reply_type)
499 {"testSet exceptions", ?_assertEqual(
501 thrift_test_thrift:function_info(testSet, exceptions)
503 {"testList params", ?_assertEqual(
507 thrift_test_thrift:function_info(testList, params_type)
509 {"testList reply", ?_assertEqual(
511 thrift_test_thrift:function_info(testList, reply_type)
513 {"testList exceptions", ?_assertEqual(
515 thrift_test_thrift:function_info(testList, exceptions)
517 {"testEnum params", ?_assertEqual(
521 thrift_test_thrift:function_info(testEnum, params_type)
523 {"testEnum reply", ?_assertEqual(
525 thrift_test_thrift:function_info(testEnum, reply_type)
527 {"testEnum exceptions", ?_assertEqual(
529 thrift_test_thrift:function_info(testEnum, exceptions)
531 {"testTypedef params", ?_assertEqual(
532 {struct, [{1, i64}]},
533 thrift_test_thrift:function_info(testTypedef, params_type)
535 {"testTypedef reply", ?_assertEqual(
537 thrift_test_thrift:function_info(testTypedef, reply_type)
539 {"testTypedef exceptions", ?_assertEqual(
541 thrift_test_thrift:function_info(testTypedef, exceptions)
543 {"testMapMap params", ?_assertEqual(
547 thrift_test_thrift:function_info(testMapMap, params_type)
549 {"testMapMap reply", ?_assertEqual(
550 {map, i32, {map, i32,i32}},
551 thrift_test_thrift:function_info(testMapMap, reply_type)
553 {"testMapMap exceptions", ?_assertEqual(
555 thrift_test_thrift:function_info(testMapMap, exceptions)
557 {"testInsanity params", ?_assertEqual(
559 {1, {struct, {thrift_test_types, 'thrift.test.Insanity'}}}
561 thrift_test_thrift:function_info(testInsanity, params_type)
563 {"testInsanity reply", ?_assertEqual(
564 {map, i64, {map, i32, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}}},
565 thrift_test_thrift:function_info(testInsanity, reply_type)
567 {"testInsanity exceptions", ?_assertEqual(
569 thrift_test_thrift:function_info(testInsanity, exceptions)
571 {"testMulti params", ?_assertEqual(
576 {4, {map, i16, string}},
580 thrift_test_thrift:function_info(testMulti, params_type)
582 {"testMulti reply", ?_assertEqual(
583 {struct, {thrift_test_types, 'thrift.test.Xtruct'}},
584 thrift_test_thrift:function_info(testMulti, reply_type)
586 {"testMulti exceptions", ?_assertEqual(
588 thrift_test_thrift:function_info(testMulti, exceptions)
590 {"testException params", ?_assertEqual(
591 {struct, [{1, string}]},
592 thrift_test_thrift:function_info(testException, params_type)
594 {"testException reply", ?_assertEqual(
596 thrift_test_thrift:function_info(testException, reply_type)
598 {"testException exceptions", ?_assertEqual(
600 {1, {struct, {thrift_test_types, 'thrift.test.Xception'}}}
602 thrift_test_thrift:function_info(testException, exceptions)
604 {"testMultiException params", ?_assertEqual(
605 {struct, [{1, string}, {2, string}]},
606 thrift_test_thrift:function_info(testMultiException, params_type)
608 {"testMultiException reply", ?_assertEqual(
609 {struct, {thrift_test_types, 'thrift.test.Xtruct'}},
610 thrift_test_thrift:function_info(testMultiException, reply_type)
612 {"testMultiException exceptions", ?_assertEqual(
614 {1, {struct, {thrift_test_types, 'thrift.test.Xception'}}},
615 {2, {struct, {thrift_test_types, 'thrift.test.Xception2'}}}
617 thrift_test_thrift:function_info(testMultiException, exceptions)
619 {"testOneway params", ?_assertEqual(
620 {struct, [{1, i32}]},
621 thrift_test_thrift:function_info(testOneway, params_type)
623 {"testOneway reply", ?_assertEqual(
625 thrift_test_thrift:function_info(testOneway, reply_type)
627 {"testOneway exceptions", ?_assertEqual(
629 thrift_test_thrift:function_info(testOneway, exceptions)
631 {"secondtestString params", ?_assertEqual(
632 {struct, [{1, string}]},
633 second_service_thrift:function_info(secondtestString, params_type)
635 {"secondtestString reply", ?_assertEqual(
637 second_service_thrift:function_info(secondtestString, reply_type)
639 {"secondtestString exceptions", ?_assertEqual(
641 second_service_thrift:function_info(secondtestString, exceptions)