blob: 467968a035577124ebbd7cde66537b70c0301b13 [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
Henrique Mendonça8ad13a32013-05-16 21:26:20 +020039
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
David Reissfb790d72010-09-02 16:41:45 +000045namespace * thrift.test
Marc Slemko17859852006-08-15 00:21:31 +000046
Bryan Duxbury9af23d92009-11-19 17:26:38 +000047/**
48 * Docstring!
49 */
Mark Sleee8540632006-05-30 09:24:40 +000050enum Numberz
51{
52 ONE = 1,
53 TWO,
54 THREE,
55 FIVE = 5,
56 SIX,
57 EIGHT = 8
58}
59
Bryan Duxbury9f0a7862010-09-12 14:38:36 +000060const Numberz myNumberz = Numberz.ONE;
61// the following is expected to fail:
62// const Numberz urNumberz = ONE;
63
Mark Slee6e536442006-06-30 18:28:50 +000064typedef i64 UserId
Mark Sleee8540632006-05-30 09:24:40 +000065
Mark Sleee129a2d2007-02-21 05:17:48 +000066struct Bonk
67{
68 1: string message,
69 2: i32 type
70}
71
Jens Geyer11430df2013-07-26 00:23:00 +020072typedef map<string,Bonk> MapType
73
Kevin Clark9a863ee2009-03-24 16:04:36 +000074struct Bools {
75 1: bool im_true,
76 2: bool im_false,
77}
78
Mark Sleee8540632006-05-30 09:24:40 +000079struct Xtruct
80{
Mark Sleea3302652006-10-25 19:03:32 +000081 1: string string_thing,
82 4: byte byte_thing,
83 9: i32 i32_thing,
84 11: i64 i64_thing
Mark Sleee8540632006-05-30 09:24:40 +000085}
86
87struct Xtruct2
88{
Mark Sleea3302652006-10-25 19:03:32 +000089 1: byte byte_thing,
90 2: Xtruct struct_thing,
91 3: i32 i32_thing
Mark Sleee8540632006-05-30 09:24:40 +000092}
93
David Reiss233ace52009-03-30 20:46:47 +000094struct Xtruct3
95{
96 1: string string_thing,
97 4: i32 changed,
98 9: i32 i32_thing,
99 11: i64 i64_thing
100}
101
102
Mark Sleee8540632006-05-30 09:24:40 +0000103struct Insanity
104{
Mark Sleea3302652006-10-25 19:03:32 +0000105 1: map<Numberz, UserId> userMap,
106 2: list<Xtruct> xtructs
Mark Sleee8540632006-05-30 09:24:40 +0000107}
108
Bryan Duxbury986d7052009-01-29 01:51:08 +0000109struct CrazyNesting {
110 1: string string_field,
111 2: optional set<Insanity> set_field,
Bryan Duxburyb3d0aa02010-10-06 20:00:03 +0000112 3: required list< map<set<i32>,map<i32,set<list<map<Insanity,string>>>>>> list_field,
113 4: binary binary_field
Bryan Duxbury986d7052009-01-29 01:51:08 +0000114}
115
Marc Slemkobf4fd192006-08-15 21:29:39 +0000116exception Xception {
Mark Sleea3302652006-10-25 19:03:32 +0000117 1: i32 errorCode,
118 2: string message
Marc Slemkod8b10512006-08-14 23:30:37 +0000119}
120
Marc Slemkobf4fd192006-08-15 21:29:39 +0000121exception Xception2 {
Mark Sleea3302652006-10-25 19:03:32 +0000122 1: i32 errorCode,
123 2: Xtruct struct_thing
Marc Slemkod8b10512006-08-14 23:30:37 +0000124}
Mark Slee27ed6ec2007-08-16 01:26:31 +0000125
Mark Sleed3d733a2006-09-01 22:19:06 +0000126struct EmptyStruct {}
127
Marc Slemkod8b10512006-08-14 23:30:37 +0000128struct OneField {
Mark Sleea3302652006-10-25 19:03:32 +0000129 1: EmptyStruct field
Marc Slemkod8b10512006-08-14 23:30:37 +0000130}
Marc Slemko5b126d62006-08-11 23:03:42 +0000131
Mark Sleee8540632006-05-30 09:24:40 +0000132service ThriftTest
133{
Roger Meier1f8b48f2012-05-02 22:56:47 +0000134 /**
135 * Prints "testVoid()" and returns nothing.
136 */
Marc Slemkod8b10512006-08-14 23:30:37 +0000137 void testVoid(),
Jens Geyeraaa89472014-10-03 20:22:28 +0200138
Roger Meier1f8b48f2012-05-02 22:56:47 +0000139 /**
140 * Prints 'testString("%s")' with thing as '%s'
141 * @param string thing - the string to print
142 * @return string - returns the string 'thing'
143 */
Mark Sleea3302652006-10-25 19:03:32 +0000144 string testString(1: string thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200145
Roger Meier1f8b48f2012-05-02 22:56:47 +0000146 /**
147 * Prints 'testByte("%d")' with thing as '%d'
148 * @param byte thing - the byte to print
149 * @return byte - returns the byte 'thing'
150 */
Mark Sleea3302652006-10-25 19:03:32 +0000151 byte testByte(1: byte thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200152
Roger Meier1f8b48f2012-05-02 22:56:47 +0000153 /**
154 * Prints 'testI32("%d")' with thing as '%d'
155 * @param i32 thing - the i32 to print
156 * @return i32 - returns the i32 'thing'
157 */
Mark Sleea3302652006-10-25 19:03:32 +0000158 i32 testI32(1: i32 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200159
Roger Meier1f8b48f2012-05-02 22:56:47 +0000160 /**
161 * Prints 'testI64("%d")' with thing as '%d'
162 * @param i64 thing - the i64 to print
163 * @return i64 - returns the i64 'thing'
164 */
Mark Sleea3302652006-10-25 19:03:32 +0000165 i64 testI64(1: i64 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200166
Roger Meier1f8b48f2012-05-02 22:56:47 +0000167 /**
168 * Prints 'testDouble("%f")' with thing as '%f'
169 * @param double thing - the double to print
170 * @return double - returns the double 'thing'
171 */
Mark Sleea3302652006-10-25 19:03:32 +0000172 double testDouble(1: double thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200173
Roger Meier1f8b48f2012-05-02 22:56:47 +0000174 /**
Jens Geyera2d5dfd2014-12-13 23:39:45 +0100175 * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
176 * @param binary thing - the binary data to print
177 * @return binary - returns the binary 'thing'
178 */
179 binary testBinary(1: binary thing),
180
181 /**
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100182 * Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
Roger Meier1f8b48f2012-05-02 22:56:47 +0000183 * @param Xtruct thing - the Xtruct to print
184 * @return Xtruct - returns the Xtruct 'thing'
185 */
Mark Sleea3302652006-10-25 19:03:32 +0000186 Xtruct testStruct(1: Xtruct thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200187
Roger Meier1f8b48f2012-05-02 22:56:47 +0000188 /**
189 * Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
190 * @param Xtruct2 thing - the Xtruct2 to print
191 * @return Xtruct2 - returns the Xtruct2 'thing'
192 */
Mark Sleea3302652006-10-25 19:03:32 +0000193 Xtruct2 testNest(1: Xtruct2 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200194
Roger Meier1f8b48f2012-05-02 22:56:47 +0000195 /**
196 * Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100197 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000198 * @param map<i32,i32> thing - the map<i32,i32> to print
199 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
200 */
Mark Sleea3302652006-10-25 19:03:32 +0000201 map<i32,i32> testMap(1: map<i32,i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200202
Roger Meier1f8b48f2012-05-02 22:56:47 +0000203 /**
204 * Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100205 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000206 * @param map<string,string> thing - the map<string,string> to print
207 * @return map<string,string> - returns the map<string,string> 'thing'
208 */
Roger Meier9d8e8f82011-06-14 19:38:27 +0000209 map<string,string> testStringMap(1: map<string,string> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200210
Roger Meier1f8b48f2012-05-02 22:56:47 +0000211 /**
212 * Prints 'testSet("{%s}")' where thing has been formatted into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100213 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000214 * @param set<i32> thing - the set<i32> to print
215 * @return set<i32> - returns the set<i32> 'thing'
216 */
Mark Sleea3302652006-10-25 19:03:32 +0000217 set<i32> testSet(1: set<i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200218
Roger Meier1f8b48f2012-05-02 22:56:47 +0000219 /**
220 * Prints 'testList("{%s}")' where thing has been formatted into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100221 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000222 * @param list<i32> thing - the list<i32> to print
223 * @return list<i32> - returns the list<i32> 'thing'
224 */
Mark Sleea3302652006-10-25 19:03:32 +0000225 list<i32> testList(1: list<i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200226
Roger Meier1f8b48f2012-05-02 22:56:47 +0000227 /**
228 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
229 * @param Numberz thing - the Numberz to print
230 * @return Numberz - returns the Numberz 'thing'
231 */
Mark Sleea3302652006-10-25 19:03:32 +0000232 Numberz testEnum(1: Numberz thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000233
234 /**
235 * Prints 'testTypedef("%d")' with thing as '%d'
236 * @param UserId thing - the UserId to print
237 * @return UserId - returns the UserId 'thing'
238 */
Mark Sleea3302652006-10-25 19:03:32 +0000239 UserId testTypedef(1: UserId thing),
Mark Sleee8540632006-05-30 09:24:40 +0000240
Roger Meier1f8b48f2012-05-02 22:56:47 +0000241 /**
242 * Prints 'testMapMap("%d")' with hello as '%d'
243 * @param i32 hello - the i32 to print
244 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
245 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
246 */
Mark Sleea3302652006-10-25 19:03:32 +0000247 map<i32,map<i32,i32>> testMapMap(1: i32 hello),
Mark Sleee8540632006-05-30 09:24:40 +0000248
Roger Meier1f8b48f2012-05-02 22:56:47 +0000249 /**
250 * So you think you've got this all worked, out eh?
251 *
252 * Creates a the returned map with these values and prints it out:
Jens Geyeraaa89472014-10-03 20:22:28 +0200253 * { 1 => { 2 => argument,
254 * 3 => argument,
Roger Meier1f8b48f2012-05-02 22:56:47 +0000255 * },
256 * 2 => { 6 => <empty Insanity struct>, },
257 * }
Jens Geyeraaa89472014-10-03 20:22:28 +0200258 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
Roger Meier1f8b48f2012-05-02 22:56:47 +0000259 */
Mark Sleea3302652006-10-25 19:03:32 +0000260 map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
Marc Slemkod8b10512006-08-14 23:30:37 +0000261
Roger Meier1f8b48f2012-05-02 22:56:47 +0000262 /**
263 * Prints 'testMulti()'
Jens Geyeraaa89472014-10-03 20:22:28 +0200264 * @param byte arg0 -
265 * @param i32 arg1 -
266 * @param i64 arg2 -
267 * @param map<i16, string> arg3 -
268 * @param Numberz arg4 -
269 * @param UserId arg5 -
Roger Meier1f8b48f2012-05-02 22:56:47 +0000270 * @return Xtruct - returns an Xtruct with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
271 * and i64_thing = arg2
272 */
David Reiss689c9ad2009-04-02 19:24:02 +0000273 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 +0000274
Roger Meier1f8b48f2012-05-02 22:56:47 +0000275 /**
276 * Print 'testException(%s)' with arg as '%s'
277 * @param string arg - a string indication what type of exception to throw
278 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
279 * elsen if arg == "TException" throw TException
280 * else do not throw anything
281 */
David Reiss689c9ad2009-04-02 19:24:02 +0000282 void testException(1: string arg) throws(1: Xception err1),
Marc Slemkod8b10512006-08-14 23:30:37 +0000283
Roger Meier1f8b48f2012-05-02 22:56:47 +0000284 /**
285 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
286 * @param string arg - a string indication what type of exception to throw
287 * if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
288 * elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
289 * else do not throw anything
290 * @return Xtruct - an Xtruct with string_thing = arg1
291 */
David Reiss689c9ad2009-04-02 19:24:02 +0000292 Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2)
David Reiss2ab6fe82008-02-18 02:11:44 +0000293
Roger Meier1f8b48f2012-05-02 22:56:47 +0000294 /**
295 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
296 * sleep 'secondsToSleep'
297 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
298 * @param i32 secondsToSleep - the number of seconds to sleep
299 */
David Reisscecbed82009-03-24 20:02:22 +0000300 oneway void testOneway(1:i32 secondsToSleep)
Mark Sleee8540632006-05-30 09:24:40 +0000301}
Mark Sleedafa3cf2006-09-02 23:56:49 +0000302
303service SecondService
304{
305 void blahBlah()
henrique2fdd9162013-08-28 14:03:34 +0200306 /**
307 * Prints 'testString("%s")' with thing as '%s'
308 * @param string thing - the string to print
309 * @return string - returns the string 'thing'
310 */
311 string secondtestString(1: string thing),
Mark Sleedafa3cf2006-09-02 23:56:49 +0000312}
David Reiss9ff3b9d2008-02-15 01:10:23 +0000313
314struct VersioningTestV1 {
315 1: i32 begin_in_both,
David Reissa528f542009-03-24 22:48:40 +0000316 3: string old_string,
David Reiss9ff3b9d2008-02-15 01:10:23 +0000317 12: i32 end_in_both
318}
319
320struct VersioningTestV2 {
321 1: i32 begin_in_both,
322
323 2: i32 newint,
324 3: byte newbyte,
325 4: i16 newshort,
326 5: i64 newlong,
327 6: double newdouble
328 7: Bonk newstruct,
329 8: list<i32> newlist,
330 9: set<i32> newset,
331 10: map<i32, i32> newmap,
332 11: string newstring,
333 12: i32 end_in_both
David Reiss9a08dc62008-02-27 01:55:17 +0000334}
David Reiss2a4bfd62008-04-07 23:45:00 +0000335
336struct ListTypeVersioningV1 {
337 1: list<i32> myints;
338 2: string hello;
339}
340
341struct ListTypeVersioningV2 {
342 1: list<string> strings;
343 2: string hello;
Bryan Duxbury986d7052009-01-29 01:51:08 +0000344}
Bryan Duxbury206c0dc2010-10-19 23:00:27 +0000345
346struct GuessProtocolStruct {
347 7: map<string,string> map_field,
348}
Bryan Duxburydf4cffd2011-03-15 17:16:09 +0000349
350struct LargeDeltas {
351 1: Bools b1,
352 10: Bools b10,
353 100: Bools b100,
354 500: bool check_true,
355 1000: Bools b1000,
356 1500: bool check_false,
357 2000: VersioningTestV2 vertwo2000,
358 2500: set<string> a_set2500,
359 3000: VersioningTestV2 vertwo3000,
360 4000: list<i32> big_numbers
361}
Roger Meierf4eec7a2011-09-11 18:16:21 +0000362
363struct NestedListsI32x2 {
364 1: list<list<i32>> integerlist
365}
366struct NestedListsI32x3 {
367 1: list<list<list<i32>>> integerlist
368}
369struct NestedMixedx2 {
370 1: list<set<i32>> int_set_list
371 2: map<i32,set<string>> map_int_strset
372 3: list<map<i32,set<string>>> map_int_strset_list
373}
374struct ListBonks {
375 1: list<Bonk> bonk
376}
377struct NestedListsBonk {
378 1: list<list<list<Bonk>>> bonk
379}
Bryan Duxbury6c928f32011-10-13 21:32:52 +0000380
381struct BoolTest {
382 1: optional bool b = true;
383 2: optional string s = "true";
384}
Bryan Duxburya3df5472011-12-27 22:26:59 +0000385
386struct StructA {
387 1: required string s;
388}
389
390struct StructB {
391 1: optional StructA aa;
392 2: required StructA ab;
Henrique Mendonça8ad13a32013-05-16 21:26:20 +0200393}