blob: cf28b2adf13a426f847611191d70df9e2d3d3d7c [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 Reiss9a08dc62008-02-27 01:55:17 +000025namespace cpp thrift.test
David Reiss9d65bf02008-03-27 21:41:37 +000026namespace csharp Thrift.Test
James E. King III234fb472019-01-13 23:19:18 -050027namespace delphi Thrift.Test
28namespace go thrifttest
29namespace java thrift.test
T Jake Luciani322caa22010-02-15 03:24:55 +000030namespace js ThriftTest
James E. King III234fb472019-01-13 23:19:18 -050031namespace lua ThriftTest
32namespace netcore ThriftTest
Jens Geyeraa0c8b32019-01-28 23:27:45 +010033namespace netstd ThriftTest
James E. King III234fb472019-01-13 23:19:18 -050034namespace perl ThriftTest
35namespace php ThriftTest
Anthony F. Molinaro0b4936d2010-09-27 04:43:39 +000036namespace py ThriftTest
Roger Meier50e43492010-10-08 17:46:06 +000037namespace py.twisted ThriftTest
James E. King III234fb472019-01-13 23:19:18 -050038namespace rb Thrift.Test
39namespace st ThriftTest
BCGcc193c12015-11-12 21:02:51 -050040namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
Henrique Mendonça8ad13a32013-05-16 21:26:20 +020041
42// Presence of namespaces and sub-namespaces for which there is
43// no generator should compile with warnings only
44namespace noexist ThriftTest
45namespace cpp.noexist ThriftTest
46
David Reissfb790d72010-09-02 16:41:45 +000047namespace * thrift.test
Marc Slemko17859852006-08-15 00:21:31 +000048
Bryan Duxbury9af23d92009-11-19 17:26:38 +000049/**
50 * Docstring!
51 */
Mark Sleee8540632006-05-30 09:24:40 +000052enum Numberz
53{
54 ONE = 1,
55 TWO,
56 THREE,
57 FIVE = 5,
58 SIX,
59 EIGHT = 8
60}
61
Bryan Duxbury9f0a7862010-09-12 14:38:36 +000062const Numberz myNumberz = Numberz.ONE;
63// the following is expected to fail:
64// const Numberz urNumberz = ONE;
65
Mark Slee6e536442006-06-30 18:28:50 +000066typedef i64 UserId
Mark Sleee8540632006-05-30 09:24:40 +000067
Mark Sleee129a2d2007-02-21 05:17:48 +000068struct Bonk
69{
70 1: string message,
71 2: i32 type
72}
73
Jens Geyer11430df2013-07-26 00:23:00 +020074typedef map<string,Bonk> MapType
75
Kevin Clark9a863ee2009-03-24 16:04:36 +000076struct Bools {
77 1: bool im_true,
78 2: bool im_false,
79}
80
Mark Sleee8540632006-05-30 09:24:40 +000081struct Xtruct
82{
Mark Sleea3302652006-10-25 19:03:32 +000083 1: string string_thing,
Nobuaki Sukegawaeb344a82016-03-25 09:37:18 +090084 4: i8 byte_thing,
Mark Sleea3302652006-10-25 19:03:32 +000085 9: i32 i32_thing,
86 11: i64 i64_thing
Mark Sleee8540632006-05-30 09:24:40 +000087}
88
89struct Xtruct2
90{
Jens Geyer40c28d32015-10-20 23:13:02 +020091 1: i8 byte_thing, // used to be byte, hence the name
Mark Sleea3302652006-10-25 19:03:32 +000092 2: Xtruct struct_thing,
93 3: i32 i32_thing
Mark Sleee8540632006-05-30 09:24:40 +000094}
95
David Reiss233ace52009-03-30 20:46:47 +000096struct Xtruct3
97{
98 1: string string_thing,
99 4: i32 changed,
100 9: i32 i32_thing,
101 11: i64 i64_thing
102}
103
104
Mark Sleee8540632006-05-30 09:24:40 +0000105struct Insanity
106{
Mark Sleea3302652006-10-25 19:03:32 +0000107 1: map<Numberz, UserId> userMap,
108 2: list<Xtruct> xtructs
Nobuaki Sukegawae841b3d2015-11-17 11:01:17 +0900109} (python.immutable= "")
Mark Sleee8540632006-05-30 09:24:40 +0000110
Bryan Duxbury986d7052009-01-29 01:51:08 +0000111struct CrazyNesting {
112 1: string string_field,
113 2: optional set<Insanity> set_field,
Nobuaki Sukegawa6dab9bb2015-11-28 22:27:16 +0900114 // Do not insert line break as test/go/Makefile.am is removing this line with pattern match
115 3: required list<map<set<i32> (python.immutable = ""), map<i32,set<list<map<Insanity,string>(python.immutable = "")> (python.immutable = "")>>>> list_field,
Bryan Duxburyb3d0aa02010-10-06 20:00:03 +0000116 4: binary binary_field
Bryan Duxbury986d7052009-01-29 01:51:08 +0000117}
118
Allen George60611912016-12-11 08:33:52 -0500119union SomeUnion {
120 1: map<Numberz, UserId> map_thing,
121 2: string string_thing,
122 3: i32 i32_thing,
123 4: Xtruct3 xtruct_thing,
124 5: Insanity insanity_thing
125}
126
Marc Slemkobf4fd192006-08-15 21:29:39 +0000127exception Xception {
Mark Sleea3302652006-10-25 19:03:32 +0000128 1: i32 errorCode,
129 2: string message
Marc Slemkod8b10512006-08-14 23:30:37 +0000130}
131
Marc Slemkobf4fd192006-08-15 21:29:39 +0000132exception Xception2 {
Mark Sleea3302652006-10-25 19:03:32 +0000133 1: i32 errorCode,
134 2: Xtruct struct_thing
Marc Slemkod8b10512006-08-14 23:30:37 +0000135}
Mark Slee27ed6ec2007-08-16 01:26:31 +0000136
Mark Sleed3d733a2006-09-01 22:19:06 +0000137struct EmptyStruct {}
138
Marc Slemkod8b10512006-08-14 23:30:37 +0000139struct OneField {
Mark Sleea3302652006-10-25 19:03:32 +0000140 1: EmptyStruct field
Marc Slemkod8b10512006-08-14 23:30:37 +0000141}
Marc Slemko5b126d62006-08-11 23:03:42 +0000142
Mark Sleee8540632006-05-30 09:24:40 +0000143service ThriftTest
144{
Roger Meier1f8b48f2012-05-02 22:56:47 +0000145 /**
146 * Prints "testVoid()" and returns nothing.
147 */
Marc Slemkod8b10512006-08-14 23:30:37 +0000148 void testVoid(),
Jens Geyeraaa89472014-10-03 20:22:28 +0200149
Roger Meier1f8b48f2012-05-02 22:56:47 +0000150 /**
151 * Prints 'testString("%s")' with thing as '%s'
152 * @param string thing - the string to print
153 * @return string - returns the string 'thing'
154 */
Mark Sleea3302652006-10-25 19:03:32 +0000155 string testString(1: string thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200156
Roger Meier1f8b48f2012-05-02 22:56:47 +0000157 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900158 * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
159 * @param bool thing - the bool data to print
160 * @return bool - returns the bool 'thing'
161 */
162 bool testBool(1: bool thing),
163
164 /**
Roger Meier1f8b48f2012-05-02 22:56:47 +0000165 * Prints 'testByte("%d")' with thing as '%d'
Jens Geyer40c28d32015-10-20 23:13:02 +0200166 * The types i8 and byte are synonyms, use of i8 is encouraged, byte still exists for the sake of compatibility.
167 * @param byte thing - the i8/byte to print
168 * @return i8 - returns the i8/byte 'thing'
Roger Meier1f8b48f2012-05-02 22:56:47 +0000169 */
Nobuaki Sukegawaeb344a82016-03-25 09:37:18 +0900170 i8 testByte(1: i8 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200171
Roger Meier1f8b48f2012-05-02 22:56:47 +0000172 /**
173 * Prints 'testI32("%d")' with thing as '%d'
174 * @param i32 thing - the i32 to print
175 * @return i32 - returns the i32 'thing'
176 */
Mark Sleea3302652006-10-25 19:03:32 +0000177 i32 testI32(1: i32 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200178
Roger Meier1f8b48f2012-05-02 22:56:47 +0000179 /**
180 * Prints 'testI64("%d")' with thing as '%d'
181 * @param i64 thing - the i64 to print
182 * @return i64 - returns the i64 'thing'
183 */
Mark Sleea3302652006-10-25 19:03:32 +0000184 i64 testI64(1: i64 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200185
Roger Meier1f8b48f2012-05-02 22:56:47 +0000186 /**
187 * Prints 'testDouble("%f")' with thing as '%f'
188 * @param double thing - the double to print
189 * @return double - returns the double 'thing'
190 */
Mark Sleea3302652006-10-25 19:03:32 +0000191 double testDouble(1: double thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200192
Roger Meier1f8b48f2012-05-02 22:56:47 +0000193 /**
Jens Geyera2d5dfd2014-12-13 23:39:45 +0100194 * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
195 * @param binary thing - the binary data to print
196 * @return binary - returns the binary 'thing'
197 */
198 binary testBinary(1: binary thing),
wilfrem2c69b5a2015-04-20 19:24:50 +0900199
Jens Geyera2d5dfd2014-12-13 23:39:45 +0100200 /**
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100201 * Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
Roger Meier1f8b48f2012-05-02 22:56:47 +0000202 * @param Xtruct thing - the Xtruct to print
203 * @return Xtruct - returns the Xtruct 'thing'
204 */
Mark Sleea3302652006-10-25 19:03:32 +0000205 Xtruct testStruct(1: Xtruct thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200206
Roger Meier1f8b48f2012-05-02 22:56:47 +0000207 /**
208 * Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
209 * @param Xtruct2 thing - the Xtruct2 to print
210 * @return Xtruct2 - returns the Xtruct2 'thing'
211 */
Mark Sleea3302652006-10-25 19:03:32 +0000212 Xtruct2 testNest(1: Xtruct2 thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200213
Roger Meier1f8b48f2012-05-02 22:56:47 +0000214 /**
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700215 * Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100216 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000217 * @param map<i32,i32> thing - the map<i32,i32> to print
218 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
219 */
Mark Sleea3302652006-10-25 19:03:32 +0000220 map<i32,i32> testMap(1: map<i32,i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200221
Roger Meier1f8b48f2012-05-02 22:56:47 +0000222 /**
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700223 * Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100224 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000225 * @param map<string,string> thing - the map<string,string> to print
226 * @return map<string,string> - returns the map<string,string> 'thing'
227 */
Roger Meier9d8e8f82011-06-14 19:38:27 +0000228 map<string,string> testStringMap(1: map<string,string> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200229
Roger Meier1f8b48f2012-05-02 22:56:47 +0000230 /**
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700231 * Prints 'testSet("{%s}")' where thing has been formatted into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100232 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000233 * @param set<i32> thing - the set<i32> to print
234 * @return set<i32> - returns the set<i32> 'thing'
235 */
Mark Sleea3302652006-10-25 19:03:32 +0000236 set<i32> testSet(1: set<i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200237
Roger Meier1f8b48f2012-05-02 22:56:47 +0000238 /**
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700239 * Prints 'testList("{%s}")' where thing has been formatted into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100240 * separated by commas and new lines
Roger Meier1f8b48f2012-05-02 22:56:47 +0000241 * @param list<i32> thing - the list<i32> to print
242 * @return list<i32> - returns the list<i32> 'thing'
243 */
Mark Sleea3302652006-10-25 19:03:32 +0000244 list<i32> testList(1: list<i32> thing),
Jens Geyeraaa89472014-10-03 20:22:28 +0200245
Roger Meier1f8b48f2012-05-02 22:56:47 +0000246 /**
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700247 * Prints 'testEnum("%d")' where thing has been formatted into its numeric value
Roger Meier1f8b48f2012-05-02 22:56:47 +0000248 * @param Numberz thing - the Numberz to print
249 * @return Numberz - returns the Numberz 'thing'
250 */
Mark Sleea3302652006-10-25 19:03:32 +0000251 Numberz testEnum(1: Numberz thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000252
253 /**
254 * Prints 'testTypedef("%d")' with thing as '%d'
255 * @param UserId thing - the UserId to print
256 * @return UserId - returns the UserId 'thing'
257 */
Mark Sleea3302652006-10-25 19:03:32 +0000258 UserId testTypedef(1: UserId thing),
Mark Sleee8540632006-05-30 09:24:40 +0000259
Roger Meier1f8b48f2012-05-02 22:56:47 +0000260 /**
261 * Prints 'testMapMap("%d")' with hello as '%d'
262 * @param i32 hello - the i32 to print
263 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
264 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
265 */
Mark Sleea3302652006-10-25 19:03:32 +0000266 map<i32,map<i32,i32>> testMapMap(1: i32 hello),
Mark Sleee8540632006-05-30 09:24:40 +0000267
Roger Meier1f8b48f2012-05-02 22:56:47 +0000268 /**
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700269 * So you think you've got this all worked out, eh?
Roger Meier1f8b48f2012-05-02 22:56:47 +0000270 *
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700271 * Creates a map with these values and prints it out:
Jens Geyeraaa89472014-10-03 20:22:28 +0200272 * { 1 => { 2 => argument,
273 * 3 => argument,
Roger Meier1f8b48f2012-05-02 22:56:47 +0000274 * },
275 * 2 => { 6 => <empty Insanity struct>, },
276 * }
Jens Geyeraaa89472014-10-03 20:22:28 +0200277 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
Roger Meier1f8b48f2012-05-02 22:56:47 +0000278 */
Mark Sleea3302652006-10-25 19:03:32 +0000279 map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
Marc Slemkod8b10512006-08-14 23:30:37 +0000280
Roger Meier1f8b48f2012-05-02 22:56:47 +0000281 /**
282 * Prints 'testMulti()'
Nobuaki Sukegawaeb344a82016-03-25 09:37:18 +0900283 * @param i8 arg0 -
Jens Geyeraaa89472014-10-03 20:22:28 +0200284 * @param i32 arg1 -
285 * @param i64 arg2 -
286 * @param map<i16, string> arg3 -
287 * @param Numberz arg4 -
288 * @param UserId arg5 -
Roger Meier1f8b48f2012-05-02 22:56:47 +0000289 * @return Xtruct - returns an Xtruct with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
290 * and i64_thing = arg2
291 */
Nobuaki Sukegawaeb344a82016-03-25 09:37:18 +0900292 Xtruct testMulti(1: i8 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 +0000293
Roger Meier1f8b48f2012-05-02 22:56:47 +0000294 /**
295 * Print 'testException(%s)' with arg as '%s'
296 * @param string arg - a string indication what type of exception to throw
297 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700298 * else if arg == "TException" throw TException
Roger Meier1f8b48f2012-05-02 22:56:47 +0000299 * else do not throw anything
300 */
David Reiss689c9ad2009-04-02 19:24:02 +0000301 void testException(1: string arg) throws(1: Xception err1),
Marc Slemkod8b10512006-08-14 23:30:37 +0000302
Roger Meier1f8b48f2012-05-02 22:56:47 +0000303 /**
304 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700305 * @param string arg - a string indicating what type of exception to throw
Roger Meier1f8b48f2012-05-02 22:56:47 +0000306 * if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
Kevin Wojniakc5068e22019-06-26 22:11:01 -0700307 * else if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and struct_thing.string_thing = "This is an Xception2"
Roger Meier1f8b48f2012-05-02 22:56:47 +0000308 * else do not throw anything
309 * @return Xtruct - an Xtruct with string_thing = arg1
310 */
David Reiss689c9ad2009-04-02 19:24:02 +0000311 Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2)
David Reiss2ab6fe82008-02-18 02:11:44 +0000312
Roger Meier1f8b48f2012-05-02 22:56:47 +0000313 /**
314 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
315 * sleep 'secondsToSleep'
316 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
317 * @param i32 secondsToSleep - the number of seconds to sleep
318 */
David Reisscecbed82009-03-24 20:02:22 +0000319 oneway void testOneway(1:i32 secondsToSleep)
Mark Sleee8540632006-05-30 09:24:40 +0000320}
Mark Sleedafa3cf2006-09-02 23:56:49 +0000321
322service SecondService
323{
henrique2fdd9162013-08-28 14:03:34 +0200324 /**
325 * Prints 'testString("%s")' with thing as '%s'
326 * @param string thing - the string to print
327 * @return string - returns the string 'thing'
328 */
James E. King, III58402ff2017-11-17 14:41:46 -0500329 string secondtestString(1: string thing)
Mark Sleedafa3cf2006-09-02 23:56:49 +0000330}
David Reiss9ff3b9d2008-02-15 01:10:23 +0000331
332struct VersioningTestV1 {
333 1: i32 begin_in_both,
David Reissa528f542009-03-24 22:48:40 +0000334 3: string old_string,
David Reiss9ff3b9d2008-02-15 01:10:23 +0000335 12: i32 end_in_both
336}
337
338struct VersioningTestV2 {
339 1: i32 begin_in_both,
340
341 2: i32 newint,
Nobuaki Sukegawaeb344a82016-03-25 09:37:18 +0900342 3: i8 newbyte,
David Reiss9ff3b9d2008-02-15 01:10:23 +0000343 4: i16 newshort,
344 5: i64 newlong,
345 6: double newdouble
346 7: Bonk newstruct,
347 8: list<i32> newlist,
348 9: set<i32> newset,
349 10: map<i32, i32> newmap,
350 11: string newstring,
351 12: i32 end_in_both
David Reiss9a08dc62008-02-27 01:55:17 +0000352}
David Reiss2a4bfd62008-04-07 23:45:00 +0000353
354struct ListTypeVersioningV1 {
355 1: list<i32> myints;
356 2: string hello;
357}
358
359struct ListTypeVersioningV2 {
360 1: list<string> strings;
361 2: string hello;
Bryan Duxbury986d7052009-01-29 01:51:08 +0000362}
Bryan Duxbury206c0dc2010-10-19 23:00:27 +0000363
364struct GuessProtocolStruct {
365 7: map<string,string> map_field,
366}
Bryan Duxburydf4cffd2011-03-15 17:16:09 +0000367
368struct LargeDeltas {
369 1: Bools b1,
370 10: Bools b10,
371 100: Bools b100,
372 500: bool check_true,
373 1000: Bools b1000,
374 1500: bool check_false,
375 2000: VersioningTestV2 vertwo2000,
376 2500: set<string> a_set2500,
377 3000: VersioningTestV2 vertwo3000,
378 4000: list<i32> big_numbers
379}
Roger Meierf4eec7a2011-09-11 18:16:21 +0000380
381struct NestedListsI32x2 {
382 1: list<list<i32>> integerlist
383}
384struct NestedListsI32x3 {
385 1: list<list<list<i32>>> integerlist
386}
387struct NestedMixedx2 {
388 1: list<set<i32>> int_set_list
389 2: map<i32,set<string>> map_int_strset
390 3: list<map<i32,set<string>>> map_int_strset_list
391}
392struct ListBonks {
393 1: list<Bonk> bonk
394}
395struct NestedListsBonk {
396 1: list<list<list<Bonk>>> bonk
397}
Bryan Duxbury6c928f32011-10-13 21:32:52 +0000398
399struct BoolTest {
400 1: optional bool b = true;
401 2: optional string s = "true";
402}
Bryan Duxburya3df5472011-12-27 22:26:59 +0000403
404struct StructA {
405 1: required string s;
406}
407
408struct StructB {
409 1: optional StructA aa;
410 2: required StructA ab;
Henrique Mendonça8ad13a32013-05-16 21:26:20 +0200411}
John Boiles5eef01f2019-06-13 10:49:45 -0700412
413struct OptionalSetDefaultTest {
414 1: optional set<string> with_default = [ "test" ]
415}