blob: 48a08be8a516a5093f6a8d5f1219dc20e7e81c6f [file] [log] [blame]
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -07001%%
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
9%%
10%% http://www.apache.org/licenses/LICENSE-2.0
11%%
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
17%% under the License.
18%%
19
20-module(nameConflictTest_test).
21-compile(export_all).
22
23-include_lib("eunit/include/eunit.hrl").
24
25-include("nameConflictTest_constants.hrl").
26
27record_generation_test_() ->
28 [
29 {"using record", ?_assertMatch(
30 {using, _, _},
31 #using{single=null,integer=null}
32 )},
33 {"delegate record", ?_assertMatch(
34 {delegate, _, _},
35 #delegate{partial=null,delegate=null}
36 )},
37 {"get record", ?_assertMatch(
38 {get, _},
39 #get{sbyte=null}
40 )},
41 {"partial record", ?_assertMatch(
42 {partial, _},
43 #partial{using=null}
44 )},
45 {"ClassAndProp record", ?_assertMatch(
46 {classAndProp, _, _, _, _},
47 #classAndProp{
48 'ClassAndProp'=null,
49 'ClassAndProp_'=null,
50 'ClassAndProp__'=null,
51 'ClassAndProper'=null
52 }
53 )},
54 {"second_chance record", ?_assertMatch(
55 {second_chance, _, _, _, _},
56 #second_chance{
57 'SECOND_CHANCE'=null,
58 'SECOND_CHANCE_'=null,
59 'SECOND_CHANCE__'=null,
60 'SECOND_CHANCES'=null
61 }
62 )},
63 {"NOW_EAT_THIS record", ?_assertMatch(
64 {nOW_EAT_THIS, _, _, _, _},
65 #nOW_EAT_THIS{
66 now_eat_this=null,
67 now_eat_this_=null,
68 now_eat_this__=null,
69 now_eat_this_and_this=null
70 }
71 )},
72 {"TheEdgeCase record", ?_assertMatch(
73 {theEdgeCase, _, _, _, _, _, _},
74 #theEdgeCase{
75 theEdgeCase=null,
76 theEdgeCase_=null,
77 theEdgeCase__=null,
78 'TheEdgeCase'=null,
79 'TheEdgeCase_'=null,
80 'TheEdgeCase__'=null
81 }
82 )},
83 {"Tricky_ record", ?_assertMatch(
84 {tricky_, _, _},
85 #tricky_{tricky=null,'Tricky'=null}
86 )},
87 {"Nested record", ?_assertMatch(
88 {nested, _, _, _, _, _, _},
89 #nested{
90 'ClassAndProp'=null,
91 second_chance=null,
92 'NOW_EAT_THIS'=null,
93 'TheEdgeCase'=null,
94 'Tricky_'=null,
95 'Nested'=null
96 }
97 )},
98 {"Problem_ record", ?_assertMatch(
99 {problem_, _, _},
100 #problem_{problem=null,'Problem'=null}
101 )}
102 ].
103
104struct_info_test_() ->
105 [
106 {"using definition", ?_assertEqual(
107 {struct, [{1, double},{2, double}]},
108 nameConflictTest_types:struct_info(using)
109 )},
110 {"delegate definition", ?_assertEqual(
111 {struct, [
112 {1, string},
113 {2, {struct, {nameConflictTest_types, delegate}}}
114 ]},
115 nameConflictTest_types:struct_info(delegate)
116 )},
117 {"get definition", ?_assertEqual(
118 {struct, [{1, bool}]},
119 nameConflictTest_types:struct_info(get)
120 )},
121 {"partial definition", ?_assertEqual(
122 {struct, [{1, {struct, {nameConflictTest_types, using}}}]},
123 nameConflictTest_types:struct_info(partial)
124 )},
125 {"ClassAndProp definition", ?_assertEqual(
126 {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]},
127 nameConflictTest_types:struct_info(classAndProp)
128 )},
129 {"second_chance definition", ?_assertEqual(
130 {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]},
131 nameConflictTest_types:struct_info(second_chance)
132 )},
133 {"NOW_EAT_THIS definition", ?_assertEqual(
134 {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]},
135 nameConflictTest_types:struct_info(nOW_EAT_THIS)
136 )},
137 {"TheEdgeCase definition", ?_assertEqual(
138 {struct, [{1, bool},{2, bool},{3, bool},{4, bool},{5, bool},{6, bool}]},
139 nameConflictTest_types:struct_info(theEdgeCase)
140 )},
141 {"Tricky_ definition", ?_assertEqual(
142 {struct, [{1, bool},{2, bool}]},
143 nameConflictTest_types:struct_info(tricky_)
144 )},
145 {"Nested definition", ?_assertEqual(
146 {struct, [
147 {1, {struct, {nameConflictTest_types, classAndProp}}},
148 {2, {struct, {nameConflictTest_types, second_chance}}},
149 {3, {struct, {nameConflictTest_types, nOW_EAT_THIS}}},
150 {4, {struct, {nameConflictTest_types, theEdgeCase}}},
151 {5, {struct, {nameConflictTest_types, tricky_}}},
152 {6, {struct, {nameConflictTest_types, nested}}}
153 ]},
154 nameConflictTest_types:struct_info(nested)
155 )},
156 {"Problem_ definition", ?_assertEqual(
157 {struct, [{1, bool},{2, bool}]},
158 nameConflictTest_types:struct_info(problem_)
159 )},
160 {"using extended definition", ?_assertEqual(
161 {struct, [
162 {1, undefined, double, single, undefined},
163 {2, undefined, double, integer, undefined}
164 ]},
165 nameConflictTest_types:struct_info_ext(using)
166 )},
167 {"delegate extended definition", ?_assertEqual(
168 {struct, [
169 {1, undefined, string, partial, undefined},
170 {2, undefined, {struct, {nameConflictTest_types, delegate}}, delegate, undefined}
171 ]},
172 nameConflictTest_types:struct_info_ext(delegate)
173 )},
174 {"get extended definition", ?_assertEqual(
175 {struct, [{1, undefined, bool, sbyte, undefined}]},
176 nameConflictTest_types:struct_info_ext(get)
177 )},
178 {"partial extended definition", ?_assertEqual(
179 {struct, [
180 {1, undefined, {struct, {nameConflictTest_types, using}}, using, #using{}}
181 ]},
182 nameConflictTest_types:struct_info_ext(partial)
183 )},
184 {"ClassAndProp extended definition", ?_assertEqual(
185 {struct, [
186 {1, undefined, bool, 'ClassAndProp', undefined},
187 {2, undefined, bool, 'ClassAndProp_', undefined},
188 {3, undefined, bool, 'ClassAndProp__', undefined},
189 {4, undefined, bool, 'ClassAndProper', undefined}
190 ]},
191 nameConflictTest_types:struct_info_ext(classAndProp)
192 )},
193 {"second_chance extended definition", ?_assertEqual(
194 {struct, [
195 {1, undefined, bool, 'SECOND_CHANCE', undefined},
196 {2, undefined, bool, 'SECOND_CHANCE_', undefined},
197 {3, undefined, bool, 'SECOND_CHANCE__', undefined},
198 {4, undefined, bool, 'SECOND_CHANCES', undefined}
199 ]},
200 nameConflictTest_types:struct_info_ext(second_chance)
201 )},
202 {"NOW_EAT_THIS extended definition", ?_assertEqual(
203 {struct, [
204 {1, undefined, bool, now_eat_this, undefined},
205 {2, undefined, bool, now_eat_this_, undefined},
206 {3, undefined, bool, now_eat_this__, undefined},
207 {4, undefined, bool, now_eat_this_and_this, undefined}
208 ]},
209 nameConflictTest_types:struct_info_ext(nOW_EAT_THIS)
210 )},
211 {"TheEdgeCase extended definition", ?_assertEqual(
212 {struct, [
213 {1, undefined, bool, theEdgeCase, undefined},
214 {2, undefined, bool, theEdgeCase_, undefined},
215 {3, undefined, bool, theEdgeCase__, undefined},
216 {4, undefined, bool, 'TheEdgeCase', undefined},
217 {5, undefined, bool, 'TheEdgeCase_', undefined},
218 {6, undefined, bool, 'TheEdgeCase__', undefined}
219 ]},
220 nameConflictTest_types:struct_info_ext(theEdgeCase)
221 )},
222 {"Tricky_ extended definition", ?_assertEqual(
223 {struct, [
224 {1, undefined, bool, tricky, undefined},
225 {2, undefined, bool, 'Tricky', undefined}
226 ]},
227 nameConflictTest_types:struct_info_ext(tricky_)
228 )},
229 {"Nested extended definition", ?_assertEqual(
230 {struct, [
231 {1, undefined, {struct, {
232 nameConflictTest_types,
233 classAndProp
234 }}, 'ClassAndProp', #classAndProp{}},
235 {2, undefined, {struct, {
236 nameConflictTest_types,
237 second_chance
238 }}, second_chance, #second_chance{}},
239 {3, undefined, {struct, {
240 nameConflictTest_types,
241 nOW_EAT_THIS
242 }}, 'NOW_EAT_THIS', #nOW_EAT_THIS{}},
243 {4, undefined, {struct, {
244 nameConflictTest_types,
245 theEdgeCase
246 }}, 'TheEdgeCase', #theEdgeCase{}},
247 {5, undefined, {struct, {
248 nameConflictTest_types,
249 tricky_
250 }}, 'Tricky_', #tricky_{}},
251 {6, undefined, {struct, {
252 nameConflictTest_types,
253 nested
254 }}, 'Nested', undefined}
255 ]},
256 nameConflictTest_types:struct_info_ext(nested)
257 )},
258 {"Problem_ extended definition", ?_assertEqual(
259 {struct, [
260 {1, undefined, bool, problem, undefined},
261 {2, undefined, bool, 'Problem', undefined}
262 ]},
263 nameConflictTest_types:struct_info_ext(problem_)
264 )}
265 ].
266
267service_info_test_() ->
268 [
269 {"event params", ?_assertEqual(
270 {struct, [{1, {struct, {nameConflictTest_types, partial}}}]},
271 extern_thrift:function_info(event, params_type)
272 )},
273 {"event reply", ?_assertEqual(
274 {struct, {nameConflictTest_types, delegate}},
275 extern_thrift:function_info(event, reply_type)
276 )},
277 {"event exceptions", ?_assertEqual(
278 {struct, []},
279 extern_thrift:function_info(event, exceptions)
280 )},
281 {"Foo params", ?_assertEqual(
282 {struct, [{1, {struct, {nameConflictTest_types, nested}}}]},
283 extern_thrift:function_info('Foo', params_type)
284 )},
285 {"Foo reply", ?_assertEqual(
286 {struct, []},
287 extern_thrift:function_info('Foo', reply_type)
288 )},
289 {"Foo exceptions", ?_assertEqual(
290 {struct, [{1, {struct, {nameConflictTest_types, problem_}}}]},
291 extern_thrift:function_info('Foo', exceptions)
292 )}
293 ].