David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 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. |
Todd Lipcon | 53ae9f3 | 2009-12-07 00:42:38 +0000 | [diff] [blame] | 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. |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 24 | namespace c_glib TTest |
David Reiss | 771f8c7 | 2008-02-27 01:55:25 +0000 | [diff] [blame] | 25 | namespace java thrift.test |
David Reiss | 9a08dc6 | 2008-02-27 01:55:17 +0000 | [diff] [blame] | 26 | namespace cpp thrift.test |
David Reiss | 6a4b82c | 2008-03-27 21:42:16 +0000 | [diff] [blame] | 27 | namespace rb Thrift.Test |
David Reiss | 07ef3a9 | 2008-03-27 21:42:39 +0000 | [diff] [blame] | 28 | namespace perl ThriftTest |
David Reiss | 9d65bf0 | 2008-03-27 21:41:37 +0000 | [diff] [blame] | 29 | namespace csharp Thrift.Test |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 30 | namespace js ThriftTest |
Bryan Duxbury | 4d8a9cd | 2010-08-30 17:09:58 +0000 | [diff] [blame] | 31 | namespace st ThriftTest |
Anthony F. Molinaro | 0b4936d | 2010-09-27 04:43:39 +0000 | [diff] [blame] | 32 | namespace py ThriftTest |
Roger Meier | 50e4349 | 2010-10-08 17:46:06 +0000 | [diff] [blame] | 33 | namespace py.twisted ThriftTest |
Christian Lavoie | afc6d8f | 2011-02-20 02:39:19 +0000 | [diff] [blame] | 34 | namespace go ThriftTest |
Bryan Duxbury | 1d373bc | 2011-03-02 18:13:30 +0000 | [diff] [blame] | 35 | namespace php ThriftTest |
David Reiss | fb790d7 | 2010-09-02 16:41:45 +0000 | [diff] [blame] | 36 | namespace * thrift.test |
Marc Slemko | 1785985 | 2006-08-15 00:21:31 +0000 | [diff] [blame] | 37 | |
Bryan Duxbury | 9af23d9 | 2009-11-19 17:26:38 +0000 | [diff] [blame] | 38 | /** |
| 39 | * Docstring! |
| 40 | */ |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 41 | enum Numberz |
| 42 | { |
| 43 | ONE = 1, |
| 44 | TWO, |
| 45 | THREE, |
| 46 | FIVE = 5, |
| 47 | SIX, |
| 48 | EIGHT = 8 |
| 49 | } |
| 50 | |
Bryan Duxbury | 9f0a786 | 2010-09-12 14:38:36 +0000 | [diff] [blame] | 51 | const Numberz myNumberz = Numberz.ONE; |
| 52 | // the following is expected to fail: |
| 53 | // const Numberz urNumberz = ONE; |
| 54 | |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 55 | typedef i64 UserId |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 56 | |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 57 | struct Bonk |
| 58 | { |
| 59 | 1: string message, |
| 60 | 2: i32 type |
| 61 | } |
| 62 | |
Kevin Clark | 9a863ee | 2009-03-24 16:04:36 +0000 | [diff] [blame] | 63 | struct Bools { |
| 64 | 1: bool im_true, |
| 65 | 2: bool im_false, |
| 66 | } |
| 67 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 68 | struct Xtruct |
| 69 | { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 70 | 1: string string_thing, |
| 71 | 4: byte byte_thing, |
| 72 | 9: i32 i32_thing, |
| 73 | 11: i64 i64_thing |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | struct Xtruct2 |
| 77 | { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 78 | 1: byte byte_thing, |
| 79 | 2: Xtruct struct_thing, |
| 80 | 3: i32 i32_thing |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 81 | } |
| 82 | |
David Reiss | 233ace5 | 2009-03-30 20:46:47 +0000 | [diff] [blame] | 83 | struct Xtruct3 |
| 84 | { |
| 85 | 1: string string_thing, |
| 86 | 4: i32 changed, |
| 87 | 9: i32 i32_thing, |
| 88 | 11: i64 i64_thing |
| 89 | } |
| 90 | |
| 91 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 92 | struct Insanity |
| 93 | { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 94 | 1: map<Numberz, UserId> userMap, |
| 95 | 2: list<Xtruct> xtructs |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Bryan Duxbury | 986d705 | 2009-01-29 01:51:08 +0000 | [diff] [blame] | 98 | struct CrazyNesting { |
| 99 | 1: string string_field, |
| 100 | 2: optional set<Insanity> set_field, |
Bryan Duxbury | b3d0aa0 | 2010-10-06 20:00:03 +0000 | [diff] [blame] | 101 | 3: required list< map<set<i32>,map<i32,set<list<map<Insanity,string>>>>>> list_field, |
| 102 | 4: binary binary_field |
Bryan Duxbury | 986d705 | 2009-01-29 01:51:08 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 105 | exception Xception { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 106 | 1: i32 errorCode, |
| 107 | 2: string message |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 110 | exception Xception2 { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 111 | 1: i32 errorCode, |
| 112 | 2: Xtruct struct_thing |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 113 | } |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 114 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 115 | struct EmptyStruct {} |
| 116 | |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 117 | struct OneField { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 118 | 1: EmptyStruct field |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 119 | } |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 120 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 121 | service ThriftTest |
| 122 | { |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 123 | void testVoid(), |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 124 | string testString(1: string thing), |
| 125 | byte testByte(1: byte thing), |
| 126 | i32 testI32(1: i32 thing), |
| 127 | i64 testI64(1: i64 thing), |
| 128 | double testDouble(1: double thing), |
| 129 | Xtruct testStruct(1: Xtruct thing), |
| 130 | Xtruct2 testNest(1: Xtruct2 thing), |
| 131 | map<i32,i32> testMap(1: map<i32,i32> thing), |
Roger Meier | 9d8e8f8 | 2011-06-14 19:38:27 +0000 | [diff] [blame] | 132 | map<string,string> testStringMap(1: map<string,string> thing), |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 133 | set<i32> testSet(1: set<i32> thing), |
| 134 | list<i32> testList(1: list<i32> thing), |
| 135 | Numberz testEnum(1: Numberz thing), |
| 136 | UserId testTypedef(1: UserId thing), |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 137 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 138 | map<i32,map<i32,i32>> testMapMap(1: i32 hello), |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 139 | |
| 140 | /* So you think you've got this all worked, out eh? */ |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 141 | map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument), |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 142 | |
| 143 | /* Multiple parameters */ |
David Reiss | 689c9ad | 2009-04-02 19:24:02 +0000 | [diff] [blame] | 144 | Xtruct testMulti(1: byte arg0, 2: i32 arg1, 3: i64 arg2, 4: map<i16, string> arg3, 5: Numberz arg4, 6: UserId arg5), |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 145 | |
| 146 | /* Exception specifier */ |
| 147 | |
David Reiss | 689c9ad | 2009-04-02 19:24:02 +0000 | [diff] [blame] | 148 | void testException(1: string arg) throws(1: Xception err1), |
Marc Slemko | d8b1051 | 2006-08-14 23:30:37 +0000 | [diff] [blame] | 149 | |
| 150 | /* Multiple exceptions specifier */ |
| 151 | |
David Reiss | 689c9ad | 2009-04-02 19:24:02 +0000 | [diff] [blame] | 152 | Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2) |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 153 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 154 | /* Test oneway void */ |
David Reiss | cecbed8 | 2009-03-24 20:02:22 +0000 | [diff] [blame] | 155 | oneway void testOneway(1:i32 secondsToSleep) |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 156 | } |
Mark Slee | dafa3cf | 2006-09-02 23:56:49 +0000 | [diff] [blame] | 157 | |
| 158 | service SecondService |
| 159 | { |
| 160 | void blahBlah() |
| 161 | } |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 162 | |
| 163 | struct VersioningTestV1 { |
| 164 | 1: i32 begin_in_both, |
David Reiss | a528f54 | 2009-03-24 22:48:40 +0000 | [diff] [blame] | 165 | 3: string old_string, |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 166 | 12: i32 end_in_both |
| 167 | } |
| 168 | |
| 169 | struct VersioningTestV2 { |
| 170 | 1: i32 begin_in_both, |
| 171 | |
| 172 | 2: i32 newint, |
| 173 | 3: byte newbyte, |
| 174 | 4: i16 newshort, |
| 175 | 5: i64 newlong, |
| 176 | 6: double newdouble |
| 177 | 7: Bonk newstruct, |
| 178 | 8: list<i32> newlist, |
| 179 | 9: set<i32> newset, |
| 180 | 10: map<i32, i32> newmap, |
| 181 | 11: string newstring, |
| 182 | 12: i32 end_in_both |
David Reiss | 9a08dc6 | 2008-02-27 01:55:17 +0000 | [diff] [blame] | 183 | } |
David Reiss | 2a4bfd6 | 2008-04-07 23:45:00 +0000 | [diff] [blame] | 184 | |
| 185 | struct ListTypeVersioningV1 { |
| 186 | 1: list<i32> myints; |
| 187 | 2: string hello; |
| 188 | } |
| 189 | |
| 190 | struct ListTypeVersioningV2 { |
| 191 | 1: list<string> strings; |
| 192 | 2: string hello; |
Bryan Duxbury | 986d705 | 2009-01-29 01:51:08 +0000 | [diff] [blame] | 193 | } |
Bryan Duxbury | 206c0dc | 2010-10-19 23:00:27 +0000 | [diff] [blame] | 194 | |
| 195 | struct GuessProtocolStruct { |
| 196 | 7: map<string,string> map_field, |
| 197 | } |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 198 | |
| 199 | struct LargeDeltas { |
| 200 | 1: Bools b1, |
| 201 | 10: Bools b10, |
| 202 | 100: Bools b100, |
| 203 | 500: bool check_true, |
| 204 | 1000: Bools b1000, |
| 205 | 1500: bool check_false, |
| 206 | 2000: VersioningTestV2 vertwo2000, |
| 207 | 2500: set<string> a_set2500, |
| 208 | 3000: VersioningTestV2 vertwo3000, |
| 209 | 4000: list<i32> big_numbers |
| 210 | } |