Mark Slee | 02d1edc | 2007-03-07 05:17:25 +0000 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
Mark Slee | 157d9f7 | 2007-02-07 06:03:53 +0000 | [diff] [blame] | 2 | |
| 3 | $:.push('gen-rb') |
| 4 | $:.push('../../lib/rb/lib') |
| 5 | |
| 6 | require 'thrift/transport/tsocket' |
| 7 | require 'thrift/protocol/tbinaryprotocol' |
| 8 | require 'thrift/server/tserver' |
| 9 | require 'ThriftTest' |
| 10 | |
| 11 | class TestHandler |
Mark Slee | 157d9f7 | 2007-02-07 06:03:53 +0000 | [diff] [blame] | 12 | 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 Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 43 | print " with attrs: #{thing.string_thing}, #{thing.byte_thing}, #{thing.i32_thing}" |
Mark Slee | 157d9f7 | 2007-02-07 06:03:53 +0000 | [diff] [blame] | 44 | return thing |
| 45 | end |
| 46 | |
| 47 | def testMap(thing) |
| 48 | print "testMap(#{thing})\n" |
| 49 | return thing |
| 50 | end |
Mark Slee | 8067485 | 2007-11-20 05:54:13 +0000 | [diff] [blame] | 51 | |
Mark Slee | 157d9f7 | 2007-02-07 06:03:53 +0000 | [diff] [blame] | 52 | 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 Slee | 477a580 | 2007-06-30 01:18:12 +0000 | [diff] [blame] | 62 | 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 Slee | 8067485 | 2007-11-20 05:54:13 +0000 | [diff] [blame] | 71 | |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 72 | 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 Slee | 477a580 | 2007-06-30 01:18:12 +0000 | [diff] [blame] | 83 | |
Mark Slee | 8067485 | 2007-11-20 05:54:13 +0000 | [diff] [blame] | 84 | 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 Slee | 157d9f7 | 2007-02-07 06:03:53 +0000 | [diff] [blame] | 94 | end |
| 95 | |
| 96 | handler = TestHandler.new() |
Mark Slee | 58dfb4f | 2007-07-06 02:45:25 +0000 | [diff] [blame] | 97 | processor = Thrift::Test::ThriftTest::Processor.new(handler) |
Mark Slee | 157d9f7 | 2007-02-07 06:03:53 +0000 | [diff] [blame] | 98 | transport = TServerSocket.new(9090) |
| 99 | server = TSimpleServer.new(processor, transport) |
| 100 | server.serve() |