blob: 16fe5f696859574f136e4433342fd83769c063f3 [file] [log] [blame]
Mark Slee02d1edc2007-03-07 05:17:25 +00001#!/usr/bin/env ruby
Mark Slee157d9f72007-02-07 06:03:53 +00002
3$:.push('gen-rb')
4$:.push('../../lib/rb/lib')
5
6require 'thrift/transport/tsocket'
7require 'thrift/protocol/tbinaryprotocol'
8require 'thrift/server/tserver'
9require 'ThriftTest'
10
11class TestHandler
Mark Slee157d9f72007-02-07 06:03:53 +000012 def testVoid()
13 print "testVoid()\n"
14 end
15
16 def testString(thing)
17 print "testString(#{thing})\n"
18 return thing
19 end
20
21 def testByte(thing)
22 print "testByte(#{thing})\n"
23 return thing
24 end
25
26 def testI32(thing)
27 print "testI32(#{thing})\n"
28 return thing
29 end
30
31 def testI64(thing)
32 print "testI64(#{thing})\n"
33 return thing
34 end
35
36 def testDouble(thing)
37 print "testDouble(#{thing})\n"
38 return thing
39 end
40
41 def testStruct(thing)
42 print "testStruct(#{thing})\n"
Mark Slee58dfb4f2007-07-06 02:45:25 +000043 print " with attrs: #{thing.string_thing}, #{thing.byte_thing}, #{thing.i32_thing}"
Mark Slee157d9f72007-02-07 06:03:53 +000044 return thing
45 end
46
47 def testMap(thing)
48 print "testMap(#{thing})\n"
49 return thing
50 end
Mark Slee80674852007-11-20 05:54:13 +000051
Mark Slee157d9f72007-02-07 06:03:53 +000052 def testSet(thing)
53 print "testSet(#{thing})\n"
54 return thing
55 end
56
57 def testList(thing)
58 print "testList(#{thing})\n"
59 return thing
60 end
61
Mark Slee477a5802007-06-30 01:18:12 +000062 def testNest(thing)
63 print "testNest(#{thing})\n"
64 puts " i32_thing: #{thing.i32_thing}"
65 puts " with struct: "
66 %w{ string_thing byte_thing i32_thing }.each do |t|
67 puts " #{t}: #{thing.struct_thing.send(t)}"
68 end
69 return thing
70 end
Mark Slee80674852007-11-20 05:54:13 +000071
Mark Slee58dfb4f2007-07-06 02:45:25 +000072 def testInsanity(thing)
73 puts "insanity:"
74 puts " #{thing.inspect}"
75 num, uid = thing.userMap.find { true }
76 return {uid => {num => thing}}
77 end
78
79 def testMapMap(thing)
80 puts "got: #{thing}"
81 return {thing => {thing => thing}}
82 end
Mark Slee477a5802007-06-30 01:18:12 +000083
Mark Slee80674852007-11-20 05:54:13 +000084 def testEnum(thing)
85 puts "testEnum(#{thing})"
86 return thing
87 end
88
89 def testTypedef(thing)
90 puts "testTypedef(#{thing})"
91 return thing
92 end
93
Mark Slee157d9f72007-02-07 06:03:53 +000094end
95
96handler = TestHandler.new()
Mark Slee58dfb4f2007-07-06 02:45:25 +000097processor = Thrift::Test::ThriftTest::Processor.new(handler)
Mark Slee157d9f72007-02-07 06:03:53 +000098transport = TServerSocket.new(9090)
99server = TSimpleServer.new(processor, transport)
100server.serve()