blob: be000b6a9fb19dda110ff57e45714408566fab58 [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
Christian Lavoieafc6d8f2011-02-20 02:39:19 +000034namespace 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
Henrique Mendonça8ad13a32013-05-16 21:26:20 +020038
39// Presence of namespaces and sub-namespaces for which there is
40// no generator should compile with warnings only
41namespace noexist ThriftTest
42namespace cpp.noexist ThriftTest
43
David Reissfb790d72010-09-02 16:41:45 +000044namespace * thrift.test
Marc Slemko17859852006-08-15 00:21:31 +000045
Bryan Duxbury9af23d92009-11-19 17:26:38 +000046/**
47 * Docstring!
48 */
Mark Sleee8540632006-05-30 09:24:40 +000049enum Numberz
50{
51 ONE = 1,
52 TWO,
53 THREE,
54 FIVE = 5,
55 SIX,
56 EIGHT = 8
57}
58
Bryan Duxbury9f0a7862010-09-12 14:38:36 +000059const Numberz myNumberz = Numberz.ONE;
60// the following is expected to fail:
61// const Numberz urNumberz = ONE;
62
Mark Slee6e536442006-06-30 18:28:50 +000063typedef i64 UserId
Mark Sleee8540632006-05-30 09:24:40 +000064
Mark Sleee129a2d2007-02-21 05:17:48 +000065struct Bonk
66{
67 1: string message,
68 2: i32 type
69}
70
Kevin Clark9a863ee2009-03-24 16:04:36 +000071struct Bools {
72 1: bool im_true,
73 2: bool im_false,
74}
75
Mark Sleee8540632006-05-30 09:24:40 +000076struct Xtruct
77{
Mark Sleea3302652006-10-25 19:03:32 +000078 1: string string_thing,
79 4: byte byte_thing,
80 9: i32 i32_thing,
81 11: i64 i64_thing
Mark Sleee8540632006-05-30 09:24:40 +000082}
83
84struct Xtruct2
85{
Mark Sleea3302652006-10-25 19:03:32 +000086 1: byte byte_thing,
87 2: Xtruct struct_thing,
88 3: i32 i32_thing
Mark Sleee8540632006-05-30 09:24:40 +000089}
90
David Reiss233ace52009-03-30 20:46:47 +000091struct Xtruct3
92{
93 1: string string_thing,
94 4: i32 changed,
95 9: i32 i32_thing,
96 11: i64 i64_thing
97}
98
99
Mark Sleee8540632006-05-30 09:24:40 +0000100struct Insanity
101{
Mark Sleea3302652006-10-25 19:03:32 +0000102 1: map<Numberz, UserId> userMap,
103 2: list<Xtruct> xtructs
Mark Sleee8540632006-05-30 09:24:40 +0000104}
105
Bryan Duxbury986d7052009-01-29 01:51:08 +0000106struct CrazyNesting {
107 1: string string_field,
108 2: optional set<Insanity> set_field,
Bryan Duxburyb3d0aa02010-10-06 20:00:03 +0000109 3: required list< map<set<i32>,map<i32,set<list<map<Insanity,string>>>>>> list_field,
110 4: binary binary_field
Bryan Duxbury986d7052009-01-29 01:51:08 +0000111}
112
Marc Slemkobf4fd192006-08-15 21:29:39 +0000113exception Xception {
Mark Sleea3302652006-10-25 19:03:32 +0000114 1: i32 errorCode,
115 2: string message
Marc Slemkod8b10512006-08-14 23:30:37 +0000116}
117
Marc Slemkobf4fd192006-08-15 21:29:39 +0000118exception Xception2 {
Mark Sleea3302652006-10-25 19:03:32 +0000119 1: i32 errorCode,
120 2: Xtruct struct_thing
Marc Slemkod8b10512006-08-14 23:30:37 +0000121}
Mark Slee27ed6ec2007-08-16 01:26:31 +0000122
Mark Sleed3d733a2006-09-01 22:19:06 +0000123struct EmptyStruct {}
124
Marc Slemkod8b10512006-08-14 23:30:37 +0000125struct OneField {
Mark Sleea3302652006-10-25 19:03:32 +0000126 1: EmptyStruct field
Marc Slemkod8b10512006-08-14 23:30:37 +0000127}
Marc Slemko5b126d62006-08-11 23:03:42 +0000128
Mark Sleee8540632006-05-30 09:24:40 +0000129service ThriftTest
130{
Roger Meier1f8b48f2012-05-02 22:56:47 +0000131 /**
132 * Prints "testVoid()" and returns nothing.
133 */
Marc Slemkod8b10512006-08-14 23:30:37 +0000134 void testVoid(),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000135
136 /**
137 * Prints 'testString("%s")' with thing as '%s'
138 * @param string thing - the string to print
139 * @return string - returns the string 'thing'
140 */
Mark Sleea3302652006-10-25 19:03:32 +0000141 string testString(1: string thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000142
143 /**
144 * Prints 'testByte("%d")' with thing as '%d'
145 * @param byte thing - the byte to print
146 * @return byte - returns the byte 'thing'
147 */
Mark Sleea3302652006-10-25 19:03:32 +0000148 byte testByte(1: byte thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000149
150 /**
151 * Prints 'testI32("%d")' with thing as '%d'
152 * @param i32 thing - the i32 to print
153 * @return i32 - returns the i32 'thing'
154 */
Mark Sleea3302652006-10-25 19:03:32 +0000155 i32 testI32(1: i32 thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000156
157 /**
158 * Prints 'testI64("%d")' with thing as '%d'
159 * @param i64 thing - the i64 to print
160 * @return i64 - returns the i64 'thing'
161 */
Mark Sleea3302652006-10-25 19:03:32 +0000162 i64 testI64(1: i64 thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000163
164 /**
165 * Prints 'testDouble("%f")' with thing as '%f'
166 * @param double thing - the double to print
167 * @return double - returns the double 'thing'
168 */
Mark Sleea3302652006-10-25 19:03:32 +0000169 double testDouble(1: double thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000170
171 /**
172 * Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma seperated values
173 * @param Xtruct thing - the Xtruct to print
174 * @return Xtruct - returns the Xtruct 'thing'
175 */
Mark Sleea3302652006-10-25 19:03:32 +0000176 Xtruct testStruct(1: Xtruct thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000177
178 /**
179 * Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
180 * @param Xtruct2 thing - the Xtruct2 to print
181 * @return Xtruct2 - returns the Xtruct2 'thing'
182 */
Mark Sleea3302652006-10-25 19:03:32 +0000183 Xtruct2 testNest(1: Xtruct2 thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000184
185 /**
186 * Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
187 * seperated by commas and new lines
188 * @param map<i32,i32> thing - the map<i32,i32> to print
189 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
190 */
Mark Sleea3302652006-10-25 19:03:32 +0000191 map<i32,i32> testMap(1: map<i32,i32> thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000192
193 /**
194 * Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
195 * seperated by commas and new lines
196 * @param map<string,string> thing - the map<string,string> to print
197 * @return map<string,string> - returns the map<string,string> 'thing'
198 */
Roger Meier9d8e8f82011-06-14 19:38:27 +0000199 map<string,string> testStringMap(1: map<string,string> thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000200
201 /**
202 * Prints 'testSet("{%s}")' where thing has been formatted into a string of values
203 * seperated by commas and new lines
204 * @param set<i32> thing - the set<i32> to print
205 * @return set<i32> - returns the set<i32> 'thing'
206 */
Mark Sleea3302652006-10-25 19:03:32 +0000207 set<i32> testSet(1: set<i32> thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000208
209 /**
210 * Prints 'testList("{%s}")' where thing has been formatted into a string of values
211 * seperated by commas and new lines
212 * @param list<i32> thing - the list<i32> to print
213 * @return list<i32> - returns the list<i32> 'thing'
214 */
Mark Sleea3302652006-10-25 19:03:32 +0000215 list<i32> testList(1: list<i32> thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000216
217 /**
218 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
219 * @param Numberz thing - the Numberz to print
220 * @return Numberz - returns the Numberz 'thing'
221 */
Mark Sleea3302652006-10-25 19:03:32 +0000222 Numberz testEnum(1: Numberz thing),
Roger Meier1f8b48f2012-05-02 22:56:47 +0000223
224 /**
225 * Prints 'testTypedef("%d")' with thing as '%d'
226 * @param UserId thing - the UserId to print
227 * @return UserId - returns the UserId 'thing'
228 */
Mark Sleea3302652006-10-25 19:03:32 +0000229 UserId testTypedef(1: UserId thing),
Mark Sleee8540632006-05-30 09:24:40 +0000230
Roger Meier1f8b48f2012-05-02 22:56:47 +0000231 /**
232 * Prints 'testMapMap("%d")' with hello as '%d'
233 * @param i32 hello - the i32 to print
234 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
235 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
236 */
Mark Sleea3302652006-10-25 19:03:32 +0000237 map<i32,map<i32,i32>> testMapMap(1: i32 hello),
Mark Sleee8540632006-05-30 09:24:40 +0000238
Roger Meier1f8b48f2012-05-02 22:56:47 +0000239 /**
240 * So you think you've got this all worked, out eh?
241 *
242 * Creates a the returned map with these values and prints it out:
243 * { 1 => { 2 => argument,
244 * 3 => argument,
245 * },
246 * 2 => { 6 => <empty Insanity struct>, },
247 * }
248 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
249 */
Mark Sleea3302652006-10-25 19:03:32 +0000250 map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
Marc Slemkod8b10512006-08-14 23:30:37 +0000251
Roger Meier1f8b48f2012-05-02 22:56:47 +0000252 /**
253 * Prints 'testMulti()'
254 * @param byte arg0 -
255 * @param i32 arg1 -
256 * @param i64 arg2 -
257 * @param map<i16, string> arg3 -
258 * @param Numberz arg4 -
259 * @param UserId arg5 -
260 * @return Xtruct - returns an Xtruct with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
261 * and i64_thing = arg2
262 */
David Reiss689c9ad2009-04-02 19:24:02 +0000263 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 +0000264
Roger Meier1f8b48f2012-05-02 22:56:47 +0000265 /**
266 * Print 'testException(%s)' with arg as '%s'
267 * @param string arg - a string indication what type of exception to throw
268 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
269 * elsen if arg == "TException" throw TException
270 * else do not throw anything
271 */
David Reiss689c9ad2009-04-02 19:24:02 +0000272 void testException(1: string arg) throws(1: Xception err1),
Marc Slemkod8b10512006-08-14 23:30:37 +0000273
Roger Meier1f8b48f2012-05-02 22:56:47 +0000274 /**
275 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
276 * @param string arg - a string indication what type of exception to throw
277 * if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
278 * elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
279 * else do not throw anything
280 * @return Xtruct - an Xtruct with string_thing = arg1
281 */
David Reiss689c9ad2009-04-02 19:24:02 +0000282 Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2)
David Reiss2ab6fe82008-02-18 02:11:44 +0000283
Roger Meier1f8b48f2012-05-02 22:56:47 +0000284 /**
285 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
286 * sleep 'secondsToSleep'
287 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
288 * @param i32 secondsToSleep - the number of seconds to sleep
289 */
David Reisscecbed82009-03-24 20:02:22 +0000290 oneway void testOneway(1:i32 secondsToSleep)
Mark Sleee8540632006-05-30 09:24:40 +0000291}
Mark Sleedafa3cf2006-09-02 23:56:49 +0000292
293service SecondService
294{
295 void blahBlah()
296}
David Reiss9ff3b9d2008-02-15 01:10:23 +0000297
298struct VersioningTestV1 {
299 1: i32 begin_in_both,
David Reissa528f542009-03-24 22:48:40 +0000300 3: string old_string,
David Reiss9ff3b9d2008-02-15 01:10:23 +0000301 12: i32 end_in_both
302}
303
304struct VersioningTestV2 {
305 1: i32 begin_in_both,
306
307 2: i32 newint,
308 3: byte newbyte,
309 4: i16 newshort,
310 5: i64 newlong,
311 6: double newdouble
312 7: Bonk newstruct,
313 8: list<i32> newlist,
314 9: set<i32> newset,
315 10: map<i32, i32> newmap,
316 11: string newstring,
317 12: i32 end_in_both
David Reiss9a08dc62008-02-27 01:55:17 +0000318}
David Reiss2a4bfd62008-04-07 23:45:00 +0000319
320struct ListTypeVersioningV1 {
321 1: list<i32> myints;
322 2: string hello;
323}
324
325struct ListTypeVersioningV2 {
326 1: list<string> strings;
327 2: string hello;
Bryan Duxbury986d7052009-01-29 01:51:08 +0000328}
Bryan Duxbury206c0dc2010-10-19 23:00:27 +0000329
330struct GuessProtocolStruct {
331 7: map<string,string> map_field,
332}
Bryan Duxburydf4cffd2011-03-15 17:16:09 +0000333
334struct LargeDeltas {
335 1: Bools b1,
336 10: Bools b10,
337 100: Bools b100,
338 500: bool check_true,
339 1000: Bools b1000,
340 1500: bool check_false,
341 2000: VersioningTestV2 vertwo2000,
342 2500: set<string> a_set2500,
343 3000: VersioningTestV2 vertwo3000,
344 4000: list<i32> big_numbers
345}
Roger Meierf4eec7a2011-09-11 18:16:21 +0000346
347struct NestedListsI32x2 {
348 1: list<list<i32>> integerlist
349}
350struct NestedListsI32x3 {
351 1: list<list<list<i32>>> integerlist
352}
353struct NestedMixedx2 {
354 1: list<set<i32>> int_set_list
355 2: map<i32,set<string>> map_int_strset
356 3: list<map<i32,set<string>>> map_int_strset_list
357}
358struct ListBonks {
359 1: list<Bonk> bonk
360}
361struct NestedListsBonk {
362 1: list<list<list<Bonk>>> bonk
363}
Bryan Duxbury6c928f32011-10-13 21:32:52 +0000364
365struct BoolTest {
366 1: optional bool b = true;
367 2: optional string s = "true";
368}
Bryan Duxburya3df5472011-12-27 22:26:59 +0000369
370struct StructA {
371 1: required string s;
372}
373
374struct StructB {
375 1: optional StructA aa;
376 2: required StructA ab;
Henrique Mendonça8ad13a32013-05-16 21:26:20 +0200377}