blob: e988adbeb21c028bfdf3c2bd1e899305e770dcc6 [file] [log] [blame]
Jens Geyerbd52f1a2014-07-28 01:25:30 +02001/*
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.
18 */
19
20package;
21
22import org.apache.thrift.*;
23import org.apache.thrift.protocol.*;
24import org.apache.thrift.transport.*;
25import org.apache.thrift.server.*;
26import org.apache.thrift.meta_data.*;
27import org.apache.thrift.helper.*;
28
29import haxe.Int32;
30import haxe.Int64;
31import haxe.io.Bytes;
32import haxe.ds.IntMap;
33import haxe.ds.StringMap;
34import haxe.ds.ObjectMap;
35
36import thrift.test.*; // generated code
37
38
39class TestServerHandler implements ThriftTest {
40
41 public var server:TServer;
42
43 public function new() {
44 }
45
46 /**
47 * Prints "testVoid()" and returns nothing.
48 */
49 public function testVoid():Void
50 {
51 trace("testVoid()");
52 }
53
54 /**
55 * Prints 'testString("%s")' with thing as '%s'
56 * @param string thing - the string to print
57 * @return string - returns the string 'thing'
58 *
59 * @param thing
60 */
61 public function testString(thing:String):String
62 {
63 trace("teststring(\"" + thing + "\")");
64 return thing;
65 }
66
67 /**
68 * Prints 'testByte("%d")' with thing as '%d'
69 * @param byte thing - the byte to print
70 * @return byte - returns the byte 'thing'
71 *
72 * @param thing
73 */
74 public function testByte(thing:haxe.Int32):haxe.Int32
75 {
76 trace("testByte(" + thing + ")");
77 return thing;
78 }
79
80 /**
81 * Prints 'testI32("%d")' with thing as '%d'
82 * @param i32 thing - the i32 to print
83 * @return i32 - returns the i32 'thing'
84 *
85 * @param thing
86 */
87 public function testI32(thing:haxe.Int32):haxe.Int32
88 {
89 trace("testI32(" + thing + ")");
90 return thing;
91 }
92
93 /**
94 * Prints 'testI64("%d")' with thing as '%d'
95 * @param i64 thing - the i64 to print
96 * @return i64 - returns the i64 'thing'
97 *
98 * @param thing
99 */
100 public function testI64(thing:haxe.Int64):haxe.Int64
101 {
102 trace("testI64(" + thing + ")");
103 return thing;
104 }
105
106 /**
107 * Prints 'testDouble("%f")' with thing as '%f'
108 * @param double thing - the double to print
109 * @return double - returns the double 'thing'
110 *
111 * @param thing
112 */
113 public function testDouble(thing:Float):Float
114 {
115 trace("testDouble(" + thing + ")");
116 return thing;
117 }
118
119 /**
120 * Prints 'testStruct("{%s}")' where thing has been formatted
121 * into a string of comma seperated values
122 * @param Xtruct thing - the Xtruct to print
123 * @return Xtruct - returns the Xtruct 'thing'
124 *
125 * @param thing
126 */
127 public function testStruct(thing:Xtruct):Xtruct
128 {
129 trace("testStruct({" +
130 "\"" + thing.string_thing + "\", " +
131 thing.byte_thing + ", " +
132 thing.i32_thing + ", " +
133 Int64.toStr(thing.i64_thing) + "})");
134 return thing;
135 }
136
137 /**
138 * Prints 'testNest("{%s}")' where thing has been formatted
139 * into a string of the nested struct
140 * @param Xtruct2 thing - the Xtruct2 to print
141 * @return Xtruct2 - returns the Xtruct2 'thing'
142 *
143 * @param thing
144 */
145 public function testNest(nest:Xtruct2):Xtruct2
146 {
147 var thing:Xtruct = nest.struct_thing;
148 trace("testNest({" +
149 nest.byte_thing + ", {" +
150 "\"" + thing.string_thing + "\", " +
151 thing.byte_thing + ", " +
152 thing.i32_thing + ", " +
153 Int64.toStr(thing.i64_thing) + "}, " +
154 nest.i32_thing + "})");
155 return nest;
156 }
157
158 /**
159 * Prints 'testMap("{%s")' where thing has been formatted
160 * into a string of 'key => value' pairs
161 * seperated by commas and new lines
162 * @param map<i32,i32> thing - the map<i32,i32> to print
163 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
164 *
165 * @param thing
166 */
167 public function testMap(thing:IntMap<haxe.Int32>):IntMap<haxe.Int32>
168 {
169 trace("testMap({");
170 var first:Bool = true;
171 for (key in thing.keys()) {
172 if (first) {
173 first = false;
174 } else {
175 trace(", ");
176 };
177 trace(key + " => " + thing.get(key));
178 };
179 trace("})");
180 return thing;
181 }
182
183 /**
184 * Prints 'testStringMap("{%s}")' where thing has been formatted
185 * into a string of 'key => value' pairs
186 * seperated by commas and new lines
187 * @param map<string,string> thing - the map<string,string> to print
188 * @return map<string,string> - returns the map<string,string> 'thing'
189 *
190 * @param thing
191 */
192 public function testStringMap(thing:StringMap<String>):StringMap<String>
193 {
194 trace("testStringMap({");
195 var first:Bool = true;
196 for (key in thing.keys()) {
197 if (first) {
198 first = false;
199 } else {
200 trace(", ");
201 };
202 trace(key + " => " + thing.get(key));
203 };
204 trace("})");
205 return thing;
206 }
207
208 /**
209 * Prints 'testSet("{%s}")' where thing has been formatted
210 * into a string of values
211 * seperated by commas and new lines
212 * @param set<i32> thing - the set<i32> to print
213 * @return set<i32> - returns the set<i32> 'thing'
214 *
215 * @param thing
216 */
217 public function testSet(thing:IntSet):IntSet
218 {
219 trace("testSet({");
220 var first:Bool = true;
221 for (elem in thing) {
222 if (first) {
223 first = false;
224 } else {
225 trace(", ");
226 };
227 trace(elem);
228 };
229 trace("})");
230 return thing;
231 }
232
233 /**
234 * Prints 'testList("{%s}")' where thing has been formatted
235 * into a string of values
236 * seperated by commas and new lines
237 * @param list<i32> thing - the list<i32> to print
238 * @return list<i32> - returns the list<i32> 'thing'
239 *
240 * @param thing
241 */
242 public function testList(thing:List<haxe.Int32>):List<haxe.Int32>
243 {
244 trace("testList({");
245 var first:Bool = true;
246 for (elem in thing) {
247 if (first) {
248 first = false;
249 } else {
250 trace(", ");
251 };
252 trace(elem);
253 };
254 trace("})");
255 return thing;
256 }
257
258 /**
259 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
260 * @param Numberz thing - the Numberz to print
261 * @return Numberz - returns the Numberz 'thing'
262 *
263 * @param thing
264 */
265 public function testEnum(thing:Int):Int
266 {
267 trace("testEnum(" + thing + ")");
268 return thing;
269 }
270
271 /**
272 * Prints 'testTypedef("%d")' with thing as '%d'
273 * @param UserId thing - the UserId to print
274 * @return UserId - returns the UserId 'thing'
275 *
276 * @param thing
277 */
278 public function testTypedef(thing:haxe.Int64):haxe.Int64
279 {
280 trace("testTypedef(" + thing + ")");
281 return thing;
282 }
283
284 /**
285 * Prints 'testMapMap("%d")' with hello as '%d'
286 * @param i32 hello - the i32 to print
287 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
288 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, },
289 * 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
290 *
291 * @param hello
292 */
293 public function testMapMap(hello:haxe.Int32):IntMap<IntMap<haxe.Int32>>
294 {
295 trace("testMapMap(" + hello + ")");
296 var mapmap = new IntMap<IntMap<Int>>();
297 var pos = new IntMap<Int>();
298 var neg = new IntMap<Int>();
299 for (i in 1 ... 5) {
300 pos.set(i, i);
301 neg.set(-i, -i);
302 };
303 mapmap.set(4, pos);
304 mapmap.set(-4, neg);
305 return mapmap;
306 }
307
308 /**
309 * So you think you've got this all worked, out eh?
310 *
311 * Creates a the returned map with these values and prints it out:
312 * { 1 => { 2 => argument,
313 * 3 => argument,
314 * },
315 * 2 => { 6 => <empty Insanity struct>, },
316 * }
317 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
318 *
319 * @param argument
320 */
321 public function testInsanity(argument : Insanity) : Int64Map< IntMap< Insanity>>
322 {
323 trace("testInsanity()");
324
325 var hello = new Xtruct();
326 hello.string_thing = "Hello2";
327 hello.byte_thing = 2;
328 hello.i32_thing = 2;
329 hello.i64_thing = Int64.make(0, 2);
330
331 var goodbye = new Xtruct();
332 goodbye.string_thing = "Goodbye4";
333 goodbye.byte_thing = 4;
334 goodbye.i32_thing = 4;
335 goodbye.i64_thing = Int64.make(0, 4);
336
337 var crazy = new Insanity();
338 crazy.userMap = new IntMap< haxe.Int64>();
339 crazy.userMap.set(Numberz.EIGHT, Int64.make(0,8));
340 crazy.xtructs = new List<Xtruct>();
341 crazy.xtructs.add(goodbye);
342
343 var looney = new Insanity();
344 crazy.userMap.set(Numberz.FIVE, Int64.make(0,5));
345 crazy.xtructs.add(hello);
346
347 var first_map = new IntMap< Insanity>();
348 first_map.set(Numberz.TWO, crazy);
349 first_map.set(Numberz.THREE, crazy);
350
351 var second_map = new IntMap< Insanity>();
352 second_map.set(Numberz.SIX, looney);
353
354 var insane = new Int64Map< IntMap< Insanity>>();
355 insane.set( Int64.make(0,1), first_map);
356 insane.set( Int64.make(0,2), second_map);
357
358 return insane;
359 }
360
361 /**
362 * Prints 'testMulti()'
363 * @param byte arg0 -
364 * @param i32 arg1 -
365 * @param i64 arg2 -
366 * @param map<i16, string> arg3 -
367 * @param Numberz arg4 -
368 * @param UserId arg5 -
369 * @return Xtruct - returns an Xtruct
370 * with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
371 * and i64_thing = arg2
372 *
373 * @param arg0
374 * @param arg1
375 * @param arg2
376 * @param arg3
377 * @param arg4
378 * @param arg5
379 */
380 public function testMulti(arg0:haxe.Int32, arg1:haxe.Int32, arg2:haxe.Int64,
381 arg3:IntMap<String>, arg4:Int, arg5:haxe.Int64):Xtruct
382 {
383 trace("testMulti()");
384 var hello = new Xtruct();
385 hello.string_thing = "Hello2";
386 hello.byte_thing = arg0;
387 hello.i32_thing = arg1;
388 hello.i64_thing = arg2;
389 return hello;
390 }
391
392 /**
393 * Print 'testException(%s)' with arg as '%s'
394 * @param string arg - a string indication what type of exception to throw
395 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
396 * elsen if arg == "TException" throw TException
397 * else do not throw anything
398 *
399 * @param arg
400 */
401 public function testException(arg:String):Void
402 {
403 trace("testException(" + arg + ")");
404 if (arg == "Xception") {
405 var x = new Xception();
406 x.errorCode = 1001;
407 x.message = arg;
408 throw x;
409 };
410 if (arg == "TException") {
411 throw new TException();
412 };
413 return;
414 }
415
416 /**
417 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
418 * @param string arg - a string indication what type of exception to throw
419 * if arg0 == "Xception"
420 * throw Xception with errorCode = 1001 and message = "This is an Xception"
421 * else if arg0 == "Xception2"
422 * throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
423 * else do not throw anything
424 * @return Xtruct - an Xtruct with string_thing = arg1
425 *
426 * @param arg0
427 * @param arg1
428 */
429 public function testMultiException(arg0:String, arg1:String):Xtruct
430 {
431 trace("testMultiException(" + arg0 + ", " + arg1 + ")");
432 if (arg0 == "Xception") {
433 var x = new Xception();
434 x.errorCode = 1001;
435 x.message = "This is an Xception";
436 throw x;
437 } else if (arg0 == "Xception2") {
438 var x = new Xception2();
439 x.errorCode = 2002;
440 x.struct_thing = new Xtruct();
441 x.struct_thing.string_thing = "This is an Xception2";
442 throw x;
443 };
444 var result = new Xtruct();
445 result.string_thing = arg1;
446 return result;
447 }
448
449 /**
450 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
451 * sleep 'secondsToSleep'
452 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
453 * @param i32 secondsToSleep - the number of seconds to sleep
454 *
455 * @param secondsToSleep
456 */
457 public function testOneway(secondsToSleep:haxe.Int32):Void
458 {
459 trace("testOneway(" + secondsToSleep + "), sleeping...");
460 Sys.sleep(secondsToSleep);
461 trace("testOneway finished");
462 }
463
464 public function testStop():Void
465 {
466 if (server != null) {
467 server.Stop();
468 };
469 }
470}