1/*
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 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21 * details.
22 */
23
24namespace c_glib TTest
25namespace cpp thrift.test
26namespace delphi Thrift.Test
27namespace go thrifttest
28namespace java thrift.test
29namespace js ThriftTest
30namespace lua ThriftTest
31namespace netstd ThriftTest
32namespace perl ThriftTest
33namespace php ThriftTest
34namespace py ThriftTest
35namespace py.twisted ThriftTest
36namespace rb Thrift.Test
37namespace st ThriftTest
38namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
39
40// Presence of namespaces and sub-namespaces for which there is
41// no generator should compile with warnings only
42namespace noexist ThriftTest
43namespace cpp.noexist ThriftTest
44
45namespace * thrift.test
46
47/**
48 * Docstring!
49 */
50enum Numberz
51{
52  ONE = 1,
53  TWO,
54  THREE,
55  FIVE = 5,
56  SIX,
57  EIGHT = 8
58}
59
60const Numberz myNumberz = Numberz.ONE;
61// the following is expected to fail:
62// const Numberz urNumberz = ONE;
63
64typedef i64 UserId
65
66struct Bonk
67{
68  1: string message,
69  2: i32 type
70}
71
72typedef map<string,Bonk> MapType
73
74struct Bools {
75  1: bool im_true,
76  2: bool im_false,
77}
78
79struct Xtruct
80{
81  1:  string string_thing,
82  4:  i8     byte_thing,
83  9:  i32    i32_thing,
84  11: i64    i64_thing
85}
86
87struct Xtruct2
88{
89  1: i8     byte_thing,  // used to be byte, hence the name
90  2: Xtruct struct_thing,
91  3: i32    i32_thing
92}
93
94struct Xtruct3
95{
96  1:  string string_thing,
97  4:  i32    changed,
98  9:  i32    i32_thing,
99  11: i64    i64_thing
100}
101
102
103struct Insanity
104{
105  1: map<Numberz, UserId> userMap,
106  2: list<Xtruct> xtructs
107} (python.immutable= "")
108
109struct CrazyNesting {
110  1: string string_field,
111  2: optional set<Insanity> set_field,
112  // Do not insert line break as test/go/Makefile.am is removing this line with pattern match
113  3: required list<map<set<i32> (python.immutable = ""), map<i32,set<list<map<Insanity,string>(python.immutable = "")> (python.immutable = "")>>>> list_field,
114  4: binary binary_field
115}
116
117union SomeUnion {
118  1: map<Numberz, UserId> map_thing,
119  2: string string_thing,
120  3: i32 i32_thing,
121  4: Xtruct3 xtruct_thing,
122  5: Insanity insanity_thing
123}
124
125exception Xception {
126  1: i32 errorCode,
127  2: string message
128}
129
130exception Xception2 {
131  1: i32 errorCode,
132  2: Xtruct struct_thing
133}
134
135struct EmptyStruct {}
136
137struct OneField {
138  1: EmptyStruct field
139}
140
141service ThriftTest
142{
143  /**
144   * Prints "testVoid()" and returns nothing.
145   */
146  void         testVoid(),
147
148  /**
149   * Prints 'testString("%s")' with thing as '%s'
150   * @param string thing - the string to print
151   * @return string - returns the string 'thing'
152   */
153  string       testString(1: string thing),
154
155  /**
156   * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
157   * @param bool  thing - the bool data to print
158   * @return bool  - returns the bool 'thing'
159   */
160  bool         testBool(1: bool thing),
161
162  /**
163   * Prints 'testByte("%d")' with thing as '%d'
164   * The types i8 and byte are synonyms, use of i8 is encouraged, byte still exists for the sake of compatibility.
165   * @param byte thing - the i8/byte to print
166   * @return i8 - returns the i8/byte 'thing'
167   */
168  i8           testByte(1: i8 thing),
169
170  /**
171   * Prints 'testI32("%d")' with thing as '%d'
172   * @param i32 thing - the i32 to print
173   * @return i32 - returns the i32 'thing'
174   */
175  i32          testI32(1: i32 thing),
176
177  /**
178   * Prints 'testI64("%d")' with thing as '%d'
179   * @param i64 thing - the i64 to print
180   * @return i64 - returns the i64 'thing'
181   */
182  i64          testI64(1: i64 thing),
183
184  /**
185   * Prints 'testDouble("%f")' with thing as '%f'
186   * @param double thing - the double to print
187   * @return double - returns the double 'thing'
188   */
189  double       testDouble(1: double thing),
190
191  /**
192   * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
193   * @param binary  thing - the binary data to print
194   * @return binary  - returns the binary 'thing'
195   */
196  binary       testBinary(1: binary thing),
197
198  /**
199   * Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
200   * @param Xtruct thing - the Xtruct to print
201   * @return Xtruct - returns the Xtruct 'thing'
202   */
203  Xtruct       testStruct(1: Xtruct thing),
204
205  /**
206   * Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
207   * @param Xtruct2 thing - the Xtruct2 to print
208   * @return Xtruct2 - returns the Xtruct2 'thing'
209   */
210  Xtruct2      testNest(1: Xtruct2 thing),
211
212  /**
213   * Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
214   *  separated by commas and new lines
215   * @param map<i32,i32> thing - the map<i32,i32> to print
216   * @return map<i32,i32> - returns the map<i32,i32> 'thing'
217   */
218  map<i32,i32> testMap(1: map<i32,i32> thing),
219
220  /**
221   * Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
222   *  separated by commas and new lines
223   * @param map<string,string> thing - the map<string,string> to print
224   * @return map<string,string> - returns the map<string,string> 'thing'
225   */
226  map<string,string> testStringMap(1: map<string,string> thing),
227
228  /**
229   * Prints 'testSet("{%s}")' where thing has been formatted into a string of values
230   *  separated by commas and new lines
231   * @param set<i32> thing - the set<i32> to print
232   * @return set<i32> - returns the set<i32> 'thing'
233   */
234  set<i32>     testSet(1: set<i32> thing),
235
236  /**
237   * Prints 'testList("{%s}")' where thing has been formatted into a string of values
238   *  separated by commas and new lines
239   * @param list<i32> thing - the list<i32> to print
240   * @return list<i32> - returns the list<i32> 'thing'
241   */
242  list<i32>    testList(1: list<i32> thing),
243
244  /**
245   * Prints 'testEnum("%d")' where thing has been formatted into its numeric value
246   * @param Numberz thing - the Numberz to print
247   * @return Numberz - returns the Numberz 'thing'
248   */
249  Numberz      testEnum(1: Numberz thing),
250
251  /**
252   * Prints 'testTypedef("%d")' with thing as '%d'
253   * @param UserId thing - the UserId to print
254   * @return UserId - returns the UserId 'thing'
255   */
256  UserId       testTypedef(1: UserId thing),
257
258  /**
259   * Prints 'testMapMap("%d")' with hello as '%d'
260   * @param i32 hello - the i32 to print
261   * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
262   *   {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
263   */
264  map<i32,map<i32,i32>> testMapMap(1: i32 hello),
265
266  /**
267   * So you think you've got this all worked out, eh?
268   *
269   * Creates a map with these values and prints it out:
270   *   { 1 => { 2 => argument,
271   *            3 => argument,
272   *          },
273   *     2 => { 6 => <empty Insanity struct>, },
274   *   }
275   * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
276   */
277  map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
278
279  /**
280   * Prints 'testMulti()'
281   * @param i8 arg0 -
282   * @param i32 arg1 -
283   * @param i64 arg2 -
284   * @param map<i16, string> arg3 -
285   * @param Numberz arg4 -
286   * @param UserId arg5 -
287   * @return Xtruct - returns an Xtruct with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
288   *    and i64_thing = arg2
289   */
290  Xtruct testMulti(1: i8 arg0, 2: i32 arg1, 3: i64 arg2, 4: map<i16, string> arg3, 5: Numberz arg4, 6: UserId arg5),
291
292  /**
293   * Print 'testException(%s)' with arg as '%s'
294   * @param string arg - a string indication what type of exception to throw
295   * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
296   * else if arg == "TException" throw TException
297   * else do not throw anything
298   */
299  void testException(1: string arg) throws(1: Xception err1),
300
301  /**
302   * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
303   * @param string arg - a string indicating what type of exception to throw
304   * if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
305   * else if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and struct_thing.string_thing = "This is an Xception2"
306   * else do not throw anything
307   * @return Xtruct - an Xtruct with string_thing = arg1
308   */
309  Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2)
310
311  /**
312   * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
313   * sleep 'secondsToSleep'
314   * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
315   * @param i32 secondsToSleep - the number of seconds to sleep
316   */
317  oneway void testOneway(1:i32 secondsToSleep)
318}
319
320service SecondService
321{
322  /**
323   * Prints 'testString("%s")' with thing as '%s'
324   * @param string thing - the string to print
325   * @return string - returns the string 'thing'
326   */
327  string secondtestString(1: string thing)
328}
329
330struct VersioningTestV1 {
331       1: i32 begin_in_both,
332       3: string old_string,
333       12: i32 end_in_both
334}
335
336struct VersioningTestV2 {
337       1: i32 begin_in_both,
338
339       2: i32 newint,
340       3: i8 newbyte,
341       4: i16 newshort,
342       5: i64 newlong,
343       6: double newdouble
344       7: Bonk newstruct,
345       8: list<i32> newlist,
346       9: set<i32> newset,
347       10: map<i32, i32> newmap,
348       11: string newstring,
349       12: i32 end_in_both
350}
351
352struct ListTypeVersioningV1 {
353       1: list<i32> myints;
354       2: string hello;
355}
356
357struct ListTypeVersioningV2 {
358       1: list<string> strings;
359       2: string hello;
360}
361
362struct GuessProtocolStruct {
363  7: map<string,string> map_field,
364}
365
366struct LargeDeltas {
367  1: Bools b1,
368  10: Bools b10,
369  100: Bools b100,
370  500: bool check_true,
371  1000: Bools b1000,
372  1500: bool check_false,
373  2000: VersioningTestV2 vertwo2000,
374  2500: set<string> a_set2500,
375  3000: VersioningTestV2 vertwo3000,
376  4000: list<i32> big_numbers
377}
378
379struct NestedListsI32x2 {
380  1: list<list<i32>> integerlist
381}
382struct NestedListsI32x3 {
383  1: list<list<list<i32>>> integerlist
384}
385struct NestedMixedx2 {
386  1: list<set<i32>> int_set_list
387  2: map<i32,set<string>> map_int_strset
388  3: list<map<i32,set<string>>> map_int_strset_list
389}
390struct ListBonks {
391  1: list<Bonk> bonk
392}
393struct NestedListsBonk {
394  1: list<list<list<Bonk>>> bonk
395}
396
397struct BoolTest {
398  1: optional bool b = true;
399  2: optional string s = "true";
400}
401
402struct StructA {
403  1: required string s;
404}
405
406struct StructB {
407  1: optional StructA aa;
408  2: required StructA ab;
409}
410
411struct OptionalSetDefaultTest {
412  1: optional set<string> with_default = [ "test" ]
413}
414
415struct OptionalBinary {
416  1: optional set<binary> bin_set = {}
417  2: optional map<binary,i32> bin_map = {}
418}
419