blob: 414f9a542d470e4bb2dae5ffab349e3e3cbaec5a [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
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.
Todd Lipcon53ae9f32009-12-07 00:42:38 +000018 *
19 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21 * details.
David Reissea2cba82009-03-30 21:35:00 +000022 */
23
Roger Meier213a6642010-10-27 12:30:11 +000024namespace c_glib TTest
David Reiss771f8c72008-02-27 01:55:25 +000025namespace java thrift.test
David Reiss9a08dc62008-02-27 01:55:17 +000026namespace cpp thrift.test
David Reiss6a4b82c2008-03-27 21:42:16 +000027namespace rb Thrift.Test
David Reiss07ef3a92008-03-27 21:42:39 +000028namespace perl ThriftTest
David Reiss9d65bf02008-03-27 21:41:37 +000029namespace csharp Thrift.Test
T Jake Luciani322caa22010-02-15 03:24:55 +000030namespace js ThriftTest
Bryan Duxbury4d8a9cd2010-08-30 17:09:58 +000031namespace st ThriftTest
Anthony F. Molinaro0b4936d2010-09-27 04:43:39 +000032namespace py ThriftTest
Roger Meier50e43492010-10-08 17:46:06 +000033namespace py.twisted ThriftTest
Jens Geyere52c0462014-05-02 23:37:39 +020034namespace go thrifttest
Bryan Duxbury1d373bc2011-03-02 18:13:30 +000035namespace php ThriftTest
Jake Farrell7ae13e12011-10-18 14:35:26 +000036namespace delphi Thrift.Test
Jake Farrell9689d892011-12-06 01:07:17 +000037namespace cocoa ThriftTest
Roger Meier6cf0ffc2014-04-05 00:45:42 +020038namespace lua ThriftTest
BCGcc193c12015-11-12 21:02:51 -050039namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
Henrique Mendonça8ad13a32013-05-16 21:26:20 +020040
41// Presence of namespaces and sub-namespaces for which there is
42// no generator should compile with warnings only
43namespace noexist ThriftTest
44namespace cpp.noexist ThriftTest
45
David Reissfb790d72010-09-02 16:41:45 +000046namespace * thrift.test
Marc Slemko17859852006-08-15 00:21:31 +000047
Bryan Duxbury9af23d92009-11-19 17:26:38 +000048/**
49 * Docstring!
50 */
Mark Sleee8540632006-05-30 09:24:40 +000051enum Numberz
52{
53 ONE = 1,
54 TWO,
55 THREE,
56 FIVE = 5,
57 SIX,
58 EIGHT = 8
59}
60
Bryan Duxbury9f0a7862010-09-12 14:38:36 +000061const Numberz myNumberz = Numberz.ONE;
62// the following is expected to fail:
63// const Numberz urNumberz = ONE;
64
Mark Slee6e536442006-06-30 18:28:50 +000065typedef i64 UserId
Mark Sleee8540632006-05-30 09:24:40 +000066
Mark Sleee129a2d2007-02-21 05:17:48 +000067struct Bonk
68{
69 1: string message,
70 2: i32 type
71}
72
Jens Geyer11430df2013-07-26 00:23:00 +020073typedef map<string,Bonk> MapType
74
Kevin Clark9a863ee2009-03-24 16:04:36 +000075struct Bools {
76 1: bool im_true,
77 2: bool im_false,
78}
79
Mark Sleee8540632006-05-30 09:24:40 +000080struct Xtruct
81{
Mark Sleea3302652006-10-25 19:03:32 +000082 1: string string_thing,
83 4: byte byte_thing,
84 9: i32 i32_thing,
85 11: i64 i64_thing
Mark Sleee8540632006-05-30 09:24:40 +000086}
87
88struct Xtruct2
89{
Jens Geyer40c28d32015-10-20 23:13:02 +020090 1: i8 byte_thing, // used to be byte, hence the name
Mark Sleea3302652006-10-25 19:03:32 +000091 2: Xtruct struct_thing,
92 3: i32 i32_thing
Mark Sleee8540632006-05-30 09:24:40 +000093}
94
David Reiss233ace52009-03-30 20:46:47 +000095struct Xtruct3
96{
97 1: string string_thing,
98 4: i32 changed,
99 9: i32 i32_thing,
100 11: i64 i64_thing
101}
102
103
Mark Sleee8540632006-05-30 09:24:40 +0000104struct Insanity
105{
Mark Sleea3302652006-10-25 19:03:32 +0000106 1: map<Numberz, UserId> userMap,
107 2: list<Xtruct> xtructs
Mark Sleee8540632006-05-30 09:24:40 +0000108}
109
Bryan Duxbury986d7052009-01-29 01:51:08 +0000110struct CrazyNesting {
111 1: string string_field,
112 2: optional set<Insanity> set_field,
Bryan Duxburyb3d0aa02010-10-06 20:00:03 +0000113 3: required list< map<set<i32>,map<i32,set<list<map<Insanity,string>>>>>> list_field,
114 4: binary binary_field
Bryan Duxbury986d7052009-01-29 01:51:08 +0000115}
116
Marc Slemkobf4fd192006-08-15 21:29:39 +0000117exception Xception {
Mark Sleea3302652006-10-25 19:03:32 +0000118 1: i32 errorCode,
119 2: string message
Marc Slemkod8b10512006-08-14 23:30:37 +0000120}
121
Marc Slemkobf4fd192006-08-15 21:29:39 +0000122exception Xception2 {
Mark Sleea3302652006-10-25 19:03:32 +0000123 1: i32 errorCode,
124 2: Xtruct struct_thing
Marc Slemkod8b10512006-08-14 23:30:37 +0000125}
Mark Slee27ed6ec2007-08-16 01:26:31 +0000126
Mark Sleed3d733a2006-09-01 22:19:06 +0000127struct EmptyStruct {}
128
Marc Slemkod8b10512006-08-14 23:30:37 +0000129struct OneField {
Mark Sleea3302652006-10-25 19:03:32 +0000130 1: EmptyStruct field
Marc Slemkod8b10512006-08-14 23:30:37 +0000131}
Marc Slemko5b126d62006-08-11 23:03:42 +0000132
Mark Sleee8540632006-05-30 09:24:40 +0000133service ThriftTest
134{
Roger Meier1f8b48f2012-05-02 22:56:47 +0000135 /**
136 * Prints "testVoid()" and returns nothing.
137 */
Marc Slemkod8b10512006-08-14 23:30:37 +0000138 void testVoid(),
Jens Geyeraaa89472014-10-03 20:22:28 +0200139
Roger Meier1f8b48f2012-05-02 22:56:47 +0000140 /**
141 * Prints 'testString("%s")' with thing as '%s'
142 * @param string thing - the string to print
143 * @return string - returns the string 'thing'
144 */
Mark Sleea3302652006-10-25 19:03:32 +0000145 string testString(1: string thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200146
Roger Meier1f8b48f2012-05-02 22:56:47 +0000147 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900148 * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
149 * @param bool thing - the bool data to print
150 * @return bool - returns the bool 'thing'
151 */
152 bool testBool(1: bool thing),
153
154 /**
Roger Meier1f8b48f2012-05-02 22:56:47 +0000155 * Prints 'testByte("%d")' with thing as '%d'
Jens Geyer40c28d32015-10-20 23:13:02 +0200156 * The types i8 and byte are synonyms, use of i8 is encouraged, byte still exists for the sake of compatibility.
157 * @param byte thing - the i8/byte to print
158 * @return i8 - returns the i8/byte 'thing'
Roger Meier1f8b48f2012-05-02 22:56:47 +0000159 */
Jens Geyer40c28d32015-10-20 23:13:02 +0200160 i8 testByte(1: byte thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200161
Roger Meier1f8b48f2012-05-02 22:56:47 +0000162 /**
163 * Prints 'testI32("%d")' with thing as '%d'
164 * @param i32 thing - the i32 to print
165 * @return i32 - returns the i32 'thing'
166 */
Mark Sleea3302652006-10-25 19:03:32 +0000167 i32 testI32(1: i32 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200168
Roger Meier1f8b48f2012-05-02 22:56:47 +0000169 /**
170 * Prints 'testI64("%d")' with thing as '%d'
171 * @param i64 thing - the i64 to print
172 * @return i64 - returns the i64 'thing'
173 */
Mark Sleea3302652006-10-25 19:03:32 +0000174 i64 testI64(1: i64 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200175
Roger Meier1f8b48f2012-05-02 22:56:47 +0000176 /**
177 * Prints 'testDouble("%f")' with thing as '%f'
178 * @param double thing - the double to print
179 * @return double - returns the double 'thing'
180 */
Mark Sleea3302652006-10-25 19:03:32 +0000181 double testDouble(1: double thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200182
Roger Meier1f8b48f2012-05-02 22:56:47 +0000183 /**
Jens Geyera2d5dfd2014-12-13 23:39:45 +0100184 * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
185 * @param binary thing - the binary data to print
186 * @return binary - returns the binary 'thing'
187 */
188 binary testBinary(1: binary thing),
189
190 /**
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100191 * Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
Roger Meier1f8b48f2012-05-02 22:56:47 +0000192 * @param Xtruct thing - the Xtruct to print
193 * @return Xtruct - returns the Xtruct 'thing'
194 */
Mark Sleea3302652006-10-25 19:03:32 +0000195 Xtruct testStruct(1: Xtruct thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200196
Roger Meier1f8b48f2012-05-02 22:56:47 +0000197 /**
198 * Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
199 * @param Xtruct2 thing - the Xtruct2 to print
200 * @return Xtruct2 - returns the Xtruct2 'thing'
201 */
Mark Sleea3302652006-10-25 19:03:32 +0000202 Xtruct2 testNest(1: Xtruct2 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200203
Roger Meier1f8b48f2012-05-02 22:56:47 +0000204 /**
205 * Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100206 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000207 * @param map<i32,i32> thing - the map<i32,i32> to print
208 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
209 */
Mark Sleea3302652006-10-25 19:03:32 +0000210 map<i32,i32> testMap(1: map<i32,i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200211
Roger Meier1f8b48f2012-05-02 22:56:47 +0000212 /**
213 * Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100214 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000215 * @param map<string,string> thing - the map<string,string> to print
216 * @return map<string,string> - returns the map<string,string> 'thing'
217 */
Roger Meier9d8e8f82011-06-14 19:38:27 +0000218 map<string,string> testStringMap(1: map<string,string> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200219
Roger Meier1f8b48f2012-05-02 22:56:47 +0000220 /**
221 * Prints 'testSet("{%s}")' where thing has been formatted into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100222 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000223 * @param set<i32> thing - the set<i32> to print
224 * @return set<i32> - returns the set<i32> 'thing'
225 */
Mark Sleea3302652006-10-25 19:03:32 +0000226 set<i32> testSet(1: set<i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200227
Roger Meier1f8b48f2012-05-02 22:56:47 +0000228 /**
229 * Prints 'testList("{%s}")' where thing has been formatted into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100230 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000231 * @param list<i32> thing - the list<i32> to print
232 * @return list<i32> - returns the list<i32> 'thing'
233 */
Mark Sleea3302652006-10-25 19:03:32 +0000234 list<i32> testList(1: list<i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200235
Roger Meier1f8b48f2012-05-02 22:56:47 +0000236 /**
237 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
238 * @param Numberz thing - the Numberz to print
239 * @return Numberz - returns the Numberz 'thing'
240 */
Mark Sleea3302652006-10-25 19:03:32 +0000241 Numberz testEnum(1: Numberz thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000242
243 /**
244 * Prints 'testTypedef("%d")' with thing as '%d'
245 * @param UserId thing - the UserId to print
246 * @return UserId - returns the UserId 'thing'
247 */
Mark Sleea3302652006-10-25 19:03:32 +0000248 UserId testTypedef(1: UserId thing),
Mark Sleee8540632006-05-30 09:24:40 +0000249
Roger Meier1f8b48f2012-05-02 22:56:47 +0000250 /**
251 * Prints 'testMapMap("%d")' with hello as '%d'
252 * @param i32 hello - the i32 to print
253 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
254 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
255 */
Mark Sleea3302652006-10-25 19:03:32 +0000256 map<i32,map<i32,i32>> testMapMap(1: i32 hello),
Mark Sleee8540632006-05-30 09:24:40 +0000257
Roger Meier1f8b48f2012-05-02 22:56:47 +0000258 /**
259 * So you think you've got this all worked, out eh?
260 *
261 * Creates a the returned map with these values and prints it out:
Jens Geyeraaa89472014-10-03 20:22:28 +0200262 * { 1 => { 2 => argument,
263 * 3 => argument,
Roger Meier1f8b48f2012-05-02 22:56:47 +0000264 * },
265 * 2 => { 6 => <empty Insanity struct>, },
266 * }
Jens Geyeraaa89472014-10-03 20:22:28 +0200267 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
Roger Meier1f8b48f2012-05-02 22:56:47 +0000268 */
Mark Sleea3302652006-10-25 19:03:32 +0000269 map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
Marc Slemkod8b10512006-08-14 23:30:37 +0000270
Roger Meier1f8b48f2012-05-02 22:56:47 +0000271 /**
272 * Prints 'testMulti()'
Jens Geyeraaa89472014-10-03 20:22:28 +0200273 * @param byte arg0 -
274 * @param i32 arg1 -
275 * @param i64 arg2 -
276 * @param map<i16, string> arg3 -
277 * @param Numberz arg4 -
278 * @param UserId arg5 -
Roger Meier1f8b48f2012-05-02 22:56:47 +0000279 * @return Xtruct - returns an Xtruct with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
280 * and i64_thing = arg2
281 */
David Reiss689c9ad2009-04-02 19:24:02 +0000282 Xtruct testMulti(1: byte arg0, 2: i32 arg1, 3: i64 arg2, 4: map<i16, string> arg3, 5: Numberz arg4, 6: UserId arg5),
Marc Slemkod8b10512006-08-14 23:30:37 +0000283
Roger Meier1f8b48f2012-05-02 22:56:47 +0000284 /**
285 * Print 'testException(%s)' with arg as '%s'
286 * @param string arg - a string indication what type of exception to throw
287 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
288 * elsen if arg == "TException" throw TException
289 * else do not throw anything
290 */
David Reiss689c9ad2009-04-02 19:24:02 +0000291 void testException(1: string arg) throws(1: Xception err1),
Marc Slemkod8b10512006-08-14 23:30:37 +0000292
Roger Meier1f8b48f2012-05-02 22:56:47 +0000293 /**
294 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
295 * @param string arg - a string indication what type of exception to throw
296 * if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900297 * elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and struct_thing.string_thing = "This is an Xception2"
Roger Meier1f8b48f2012-05-02 22:56:47 +0000298 * else do not throw anything
299 * @return Xtruct - an Xtruct with string_thing = arg1
300 */
David Reiss689c9ad2009-04-02 19:24:02 +0000301 Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2)
David Reiss2ab6fe82008-02-18 02:11:44 +0000302
Roger Meier1f8b48f2012-05-02 22:56:47 +0000303 /**
304 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
305 * sleep 'secondsToSleep'
306 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
307 * @param i32 secondsToSleep - the number of seconds to sleep
308 */
David Reisscecbed82009-03-24 20:02:22 +0000309 oneway void testOneway(1:i32 secondsToSleep)
Mark Sleee8540632006-05-30 09:24:40 +0000310}
Mark Sleedafa3cf2006-09-02 23:56:49 +0000311
312service SecondService
313{
314 void blahBlah()
henrique2fdd9162013-08-28 14:03:34 +0200315 /**
316 * Prints 'testString("%s")' with thing as '%s'
317 * @param string thing - the string to print
318 * @return string - returns the string 'thing'
319 */
320 string secondtestString(1: string thing),
Mark Sleedafa3cf2006-09-02 23:56:49 +0000321}
David Reiss9ff3b9d2008-02-15 01:10:23 +0000322
323struct VersioningTestV1 {
324 1: i32 begin_in_both,
David Reissa528f542009-03-24 22:48:40 +0000325 3: string old_string,
David Reiss9ff3b9d2008-02-15 01:10:23 +0000326 12: i32 end_in_both
327}
328
329struct VersioningTestV2 {
330 1: i32 begin_in_both,
331
332 2: i32 newint,
333 3: byte newbyte,
334 4: i16 newshort,
335 5: i64 newlong,
336 6: double newdouble
337 7: Bonk newstruct,
338 8: list<i32> newlist,
339 9: set<i32> newset,
340 10: map<i32, i32> newmap,
341 11: string newstring,
342 12: i32 end_in_both
David Reiss9a08dc62008-02-27 01:55:17 +0000343}
David Reiss2a4bfd62008-04-07 23:45:00 +0000344
345struct ListTypeVersioningV1 {
346 1: list<i32> myints;
347 2: string hello;
348}
349
350struct ListTypeVersioningV2 {
351 1: list<string> strings;
352 2: string hello;
Bryan Duxbury986d7052009-01-29 01:51:08 +0000353}
Bryan Duxbury206c0dc2010-10-19 23:00:27 +0000354
355struct GuessProtocolStruct {
356 7: map<string,string> map_field,
357}
Bryan Duxburydf4cffd2011-03-15 17:16:09 +0000358
359struct LargeDeltas {
360 1: Bools b1,
361 10: Bools b10,
362 100: Bools b100,
363 500: bool check_true,
364 1000: Bools b1000,
365 1500: bool check_false,
366 2000: VersioningTestV2 vertwo2000,
367 2500: set<string> a_set2500,
368 3000: VersioningTestV2 vertwo3000,
369 4000: list<i32> big_numbers
370}
Roger Meierf4eec7a2011-09-11 18:16:21 +0000371
372struct NestedListsI32x2 {
373 1: list<list<i32>> integerlist
374}
375struct NestedListsI32x3 {
376 1: list<list<list<i32>>> integerlist
377}
378struct NestedMixedx2 {
379 1: list<set<i32>> int_set_list
380 2: map<i32,set<string>> map_int_strset
381 3: list<map<i32,set<string>>> map_int_strset_list
382}
383struct ListBonks {
384 1: list<Bonk> bonk
385}
386struct NestedListsBonk {
387 1: list<list<list<Bonk>>> bonk
388}
Bryan Duxbury6c928f32011-10-13 21:32:52 +0000389
390struct BoolTest {
391 1: optional bool b = true;
392 2: optional string s = "true";
393}
Bryan Duxburya3df5472011-12-27 22:26:59 +0000394
395struct StructA {
396 1: required string s;
397}
398
399struct StructB {
400 1: optional StructA aa;
401 2: required StructA ab;
Henrique Mendonça8ad13a32013-05-16 21:26:20 +0200402}