blob: b01df573212b0c61e79c33fdcddd29edcac1150b [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
Jens Geyer6d15c302014-10-02 10:03:09 +020020-module(name_conflict_test).
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070021-compile(export_all).
22
23-include_lib("eunit/include/eunit.hrl").
24
Nobuaki Sukegawa826ea992015-10-28 22:19:45 +090025-include("gen-erl/name_conflict_test_constants.hrl").
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070026
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(
henrique2f34da72015-02-05 12:39:34 +110042 {partial, _, _, _},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070043 #partial{using=null}
44 )},
45 {"ClassAndProp record", ?_assertMatch(
Jens Geyercc4ac492014-10-01 21:13:39 +020046 {'ClassAndProp', _, _, _, _},
47 #'ClassAndProp'{
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070048 '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(
Jens Geyercc4ac492014-10-01 21:13:39 +020064 {'NOW_EAT_THIS', _, _, _, _},
65 #'NOW_EAT_THIS'{
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070066 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(
Jens Geyercc4ac492014-10-01 21:13:39 +020073 {'TheEdgeCase', _, _, _, _, _, _},
74 #'TheEdgeCase'{
75 theEdgeCase=null,
76 theEdgeCase_=null,
77 theEdgeCase__=null,
78 'TheEdgeCase'=null,
79 'TheEdgeCase_'=null,
80 'TheEdgeCase__'=null
81 }
82 )},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070083 {"Tricky_ record", ?_assertMatch(
Jens Geyercc4ac492014-10-01 21:13:39 +020084 {'Tricky_', _, _},
85 #'Tricky_'{tricky=null,'Tricky'=null}
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070086 )},
87 {"Nested record", ?_assertMatch(
Jens Geyercc4ac492014-10-01 21:13:39 +020088 {'Nested', _, _, _, _, _, _},
89 #'Nested'{
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -070090 '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(
Jens Geyercc4ac492014-10-01 21:13:39 +020099 {'Problem_', _, _},
100 #'Problem_'{problem=null,'Problem'=null}
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700101 )}
102 ].
103
104struct_info_test_() ->
105 [
106 {"using definition", ?_assertEqual(
107 {struct, [{1, double},{2, double}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200108 name_conflict_test_types:struct_info(using)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700109 )},
110 {"delegate definition", ?_assertEqual(
111 {struct, [
112 {1, string},
Jens Geyer6d15c302014-10-02 10:03:09 +0200113 {2, {struct, {name_conflict_test_types, delegate}}}
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700114 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200115 name_conflict_test_types:struct_info(delegate)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700116 )},
117 {"get definition", ?_assertEqual(
118 {struct, [{1, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200119 name_conflict_test_types:struct_info(get)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700120 )},
121 {"partial definition", ?_assertEqual(
henrique2f34da72015-02-05 12:39:34 +1100122 {struct, [
123 {1, {struct, {name_conflict_test_types, using}}},
124 {2, bool},
125 {3, bool}
126 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200127 name_conflict_test_types:struct_info(partial)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700128 )},
129 {"ClassAndProp definition", ?_assertEqual(
130 {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200131 name_conflict_test_types:struct_info('ClassAndProp')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700132 )},
133 {"second_chance definition", ?_assertEqual(
134 {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200135 name_conflict_test_types:struct_info(second_chance)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700136 )},
137 {"NOW_EAT_THIS definition", ?_assertEqual(
138 {struct, [{1, bool},{2, bool},{3, bool},{4, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200139 name_conflict_test_types:struct_info('NOW_EAT_THIS')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700140 )},
141 {"TheEdgeCase definition", ?_assertEqual(
142 {struct, [{1, bool},{2, bool},{3, bool},{4, bool},{5, bool},{6, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200143 name_conflict_test_types:struct_info('TheEdgeCase')
Jens Geyercc4ac492014-10-01 21:13:39 +0200144 )},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700145 {"Tricky_ definition", ?_assertEqual(
146 {struct, [{1, bool},{2, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200147 name_conflict_test_types:struct_info('Tricky_')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700148 )},
149 {"Nested definition", ?_assertEqual(
150 {struct, [
Jens Geyer6d15c302014-10-02 10:03:09 +0200151 {1, {struct, {name_conflict_test_types, 'ClassAndProp'}}},
152 {2, {struct, {name_conflict_test_types, second_chance}}},
153 {3, {struct, {name_conflict_test_types, 'NOW_EAT_THIS'}}},
154 {4, {struct, {name_conflict_test_types, 'TheEdgeCase'}}},
155 {5, {struct, {name_conflict_test_types, 'Tricky_'}}},
156 {6, {struct, {name_conflict_test_types, 'Nested'}}}
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700157 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200158 name_conflict_test_types:struct_info('Nested')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700159 )},
160 {"Problem_ definition", ?_assertEqual(
161 {struct, [{1, bool},{2, bool}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200162 name_conflict_test_types:struct_info('Problem_')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700163 )},
164 {"using extended definition", ?_assertEqual(
165 {struct, [
166 {1, undefined, double, single, undefined},
167 {2, undefined, double, integer, undefined}
168 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200169 name_conflict_test_types:struct_info_ext(using)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700170 )},
171 {"delegate extended definition", ?_assertEqual(
172 {struct, [
173 {1, undefined, string, partial, undefined},
Jens Geyer6d15c302014-10-02 10:03:09 +0200174 {2, undefined, {struct, {name_conflict_test_types, delegate}}, delegate, undefined}
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700175 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200176 name_conflict_test_types:struct_info_ext(delegate)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700177 )},
178 {"get extended definition", ?_assertEqual(
179 {struct, [{1, undefined, bool, sbyte, undefined}]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200180 name_conflict_test_types:struct_info_ext(get)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700181 )},
182 {"partial extended definition", ?_assertEqual(
183 {struct, [
henrique2f34da72015-02-05 12:39:34 +1100184 {1, undefined, {struct, {name_conflict_test_types, using}}, using, #using{}},
185 {2, undefined, bool, read, undefined},
186 {3, undefined, bool, write, undefined}
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700187 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200188 name_conflict_test_types:struct_info_ext(partial)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700189 )},
190 {"ClassAndProp extended definition", ?_assertEqual(
191 {struct, [
192 {1, undefined, bool, 'ClassAndProp', undefined},
193 {2, undefined, bool, 'ClassAndProp_', undefined},
194 {3, undefined, bool, 'ClassAndProp__', undefined},
195 {4, undefined, bool, 'ClassAndProper', undefined}
196 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200197 name_conflict_test_types:struct_info_ext('ClassAndProp')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700198 )},
199 {"second_chance extended definition", ?_assertEqual(
200 {struct, [
201 {1, undefined, bool, 'SECOND_CHANCE', undefined},
202 {2, undefined, bool, 'SECOND_CHANCE_', undefined},
203 {3, undefined, bool, 'SECOND_CHANCE__', undefined},
204 {4, undefined, bool, 'SECOND_CHANCES', undefined}
205 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200206 name_conflict_test_types:struct_info_ext(second_chance)
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700207 )},
208 {"NOW_EAT_THIS extended definition", ?_assertEqual(
209 {struct, [
210 {1, undefined, bool, now_eat_this, undefined},
211 {2, undefined, bool, now_eat_this_, undefined},
212 {3, undefined, bool, now_eat_this__, undefined},
213 {4, undefined, bool, now_eat_this_and_this, undefined}
214 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200215 name_conflict_test_types:struct_info_ext('NOW_EAT_THIS')
Jens Geyercc4ac492014-10-01 21:13:39 +0200216 )},
217 {"TheEdgeCase extended definition", ?_assertEqual(
218 {struct, [
219 {1, undefined, bool, theEdgeCase, undefined},
220 {2, undefined, bool, theEdgeCase_, undefined},
221 {3, undefined, bool, theEdgeCase__, undefined},
222 {4, undefined, bool, 'TheEdgeCase', undefined},
223 {5, undefined, bool, 'TheEdgeCase_', undefined},
224 {6, undefined, bool, 'TheEdgeCase__', undefined}
225 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200226 name_conflict_test_types:struct_info_ext('TheEdgeCase')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700227 )},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700228 {"Tricky_ extended definition", ?_assertEqual(
229 {struct, [
230 {1, undefined, bool, tricky, undefined},
231 {2, undefined, bool, 'Tricky', undefined}
232 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200233 name_conflict_test_types:struct_info_ext('Tricky_')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700234 )},
235 {"Nested extended definition", ?_assertEqual(
236 {struct, [
237 {1, undefined, {struct, {
Jens Geyer6d15c302014-10-02 10:03:09 +0200238 name_conflict_test_types,
Jens Geyercc4ac492014-10-01 21:13:39 +0200239 'ClassAndProp'
240 }}, 'ClassAndProp', #'ClassAndProp'{}},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700241 {2, undefined, {struct, {
Jens Geyer6d15c302014-10-02 10:03:09 +0200242 name_conflict_test_types,
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700243 second_chance
244 }}, second_chance, #second_chance{}},
245 {3, undefined, {struct, {
Jens Geyer6d15c302014-10-02 10:03:09 +0200246 name_conflict_test_types,
Jens Geyercc4ac492014-10-01 21:13:39 +0200247 'NOW_EAT_THIS'
248 }}, 'NOW_EAT_THIS', #'NOW_EAT_THIS'{}},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700249 {4, undefined, {struct, {
Jens Geyer6d15c302014-10-02 10:03:09 +0200250 name_conflict_test_types,
Jens Geyercc4ac492014-10-01 21:13:39 +0200251 'TheEdgeCase'
252 }}, 'TheEdgeCase', #'TheEdgeCase'{}},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700253 {5, undefined, {struct, {
Jens Geyer6d15c302014-10-02 10:03:09 +0200254 name_conflict_test_types,
Jens Geyercc4ac492014-10-01 21:13:39 +0200255 'Tricky_'
256 }}, 'Tricky_', #'Tricky_'{}},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700257 {6, undefined, {struct, {
Jens Geyer6d15c302014-10-02 10:03:09 +0200258 name_conflict_test_types,
Jens Geyercc4ac492014-10-01 21:13:39 +0200259 'Nested'
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700260 }}, 'Nested', undefined}
261 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200262 name_conflict_test_types:struct_info_ext('Nested')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700263 )},
264 {"Problem_ extended definition", ?_assertEqual(
265 {struct, [
266 {1, undefined, bool, problem, undefined},
267 {2, undefined, bool, 'Problem', undefined}
268 ]},
Jens Geyer6d15c302014-10-02 10:03:09 +0200269 name_conflict_test_types:struct_info_ext('Problem_')
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700270 )}
271 ].
272
273service_info_test_() ->
274 [
275 {"event params", ?_assertEqual(
Jens Geyer6d15c302014-10-02 10:03:09 +0200276 {struct, [{1, {struct, {name_conflict_test_types, partial}}}]},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700277 extern_thrift:function_info(event, params_type)
278 )},
279 {"event reply", ?_assertEqual(
Jens Geyer6d15c302014-10-02 10:03:09 +0200280 {struct, {name_conflict_test_types, delegate}},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700281 extern_thrift:function_info(event, reply_type)
282 )},
283 {"event exceptions", ?_assertEqual(
284 {struct, []},
285 extern_thrift:function_info(event, exceptions)
286 )},
287 {"Foo params", ?_assertEqual(
Jens Geyer6d15c302014-10-02 10:03:09 +0200288 {struct, [{1, {struct, {name_conflict_test_types, 'Nested'}}}]},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700289 extern_thrift:function_info('Foo', params_type)
290 )},
291 {"Foo reply", ?_assertEqual(
292 {struct, []},
293 extern_thrift:function_info('Foo', reply_type)
294 )},
295 {"Foo exceptions", ?_assertEqual(
Jens Geyer6d15c302014-10-02 10:03:09 +0200296 {struct, [{1, {struct, {name_conflict_test_types, 'Problem_'}}}]},
alisdair sullivanfb6ed7e2014-07-22 23:40:44 -0700297 extern_thrift:function_info('Foo', exceptions)
298 )}
Nobuaki Sukegawa826ea992015-10-28 22:19:45 +0900299 ].