blob: 16f6d4e9cc41dbce11d8395c464fcdc401b24578 [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.
18#
19
Roger Meierc95d5df2014-01-19 21:53:02 +010020$:.push File.dirname(__FILE__) + '/..'
Kevin Clark4bd89162008-07-08 00:47:49 +000021
Roger Meierc95d5df2014-01-19 21:53:02 +010022require 'test_helper'
Kevin Clark4bd89162008-07-08 00:47:49 +000023require 'thrift'
Roger Meierc95d5df2014-01-19 21:53:02 +010024require 'thrift_test'
Kevin Clark4bd89162008-07-08 00:47:49 +000025
26class BufferedClientTest < Test::Unit::TestCase
27 def setup
28 unless @socket
29 @socket = Thrift::Socket.new('localhost', 9090)
30 @protocol = Thrift::BinaryProtocol.new(Thrift::BufferedTransport.new(@socket))
31 @client = Thrift::Test::ThriftTest::Client.new(@protocol)
32 @socket.open
33 end
34 end
35
36 def test_string
37 assert_equal(@client.testString('string'), 'string')
38 end
39
40 def test_byte
41 val = 8
42 assert_equal(@client.testByte(val), val)
43 assert_equal(@client.testByte(-val), -val)
44 end
45
46 def test_i32
47 val = 32
48 assert_equal(@client.testI32(val), val)
49 assert_equal(@client.testI32(-val), -val)
50 end
51
52 def test_i64
53 val = 64
54 assert_equal(@client.testI64(val), val)
55 assert_equal(@client.testI64(-val), -val)
56 end
57
58 def test_double
59 val = 3.14
60 assert_equal(@client.testDouble(val), val)
61 assert_equal(@client.testDouble(-val), -val)
62 assert_kind_of(Float, @client.testDouble(val))
63 end
64
65 def test_map
66 val = {1 => 1, 2 => 2, 3 => 3}
67 assert_equal(@client.testMap(val), val)
68 assert_kind_of(Hash, @client.testMap(val))
69 end
70
71 def test_list
72 val = [1,2,3,4,5]
73 assert_equal(@client.testList(val), val)
74 assert_kind_of(Array, @client.testList(val))
75 end
76
77 def test_enum
78 val = Thrift::Test::Numberz::SIX
79 ret = @client.testEnum(val)
80
81 assert_equal(ret, 6)
82 assert_kind_of(Fixnum, ret)
83 end
84
85 def test_typedef
86 #UserId testTypedef(1: UserId thing),
87 true
88 end
89
90 def test_set
91 val = Set.new([1,2,3])
92 assert_equal(@client.testSet(val), val)
93 assert_kind_of(Set, @client.testSet(val))
94 end
95
96 def get_struct
97 Thrift::Test::Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 })
98 end
99
100 def test_struct
101 ret = @client.testStruct(get_struct)
102
103 assert_nil(ret.byte_thing, nil)
104 assert_nil(ret.i64_thing, nil)
105 assert_equal(ret.string_thing, 'hi!')
106 assert_equal(ret.i32_thing, 4)
107 assert_kind_of(Thrift::Test::Xtruct, ret)
108 end
109
110 def test_nest
111 struct2 = Thrift::Test::Xtruct2.new({'struct_thing' => get_struct, 'i32_thing' => 10})
112
113 ret = @client.testNest(struct2)
114
115 assert_nil(ret.struct_thing.byte_thing, nil)
116 assert_nil(ret.struct_thing.i64_thing, nil)
117 assert_equal(ret.struct_thing.string_thing, 'hi!')
118 assert_equal(ret.struct_thing.i32_thing, 4)
119 assert_equal(ret.i32_thing, 10)
120
121 assert_kind_of(Thrift::Test::Xtruct, ret.struct_thing)
122 assert_kind_of(Thrift::Test::Xtruct2, ret)
123 end
124
125 def test_insane
126 insane = Thrift::Test::Insanity.new({
127 'userMap' => { Thrift::Test::Numberz::ONE => 44 },
128 'xtructs' => [get_struct,
129 Thrift::Test::Xtruct.new({
130 'string_thing' => 'hi again',
131 'i32_thing' => 12
132 })
133 ]
134 })
135
136 ret = @client.testInsanity(insane)
137
138 assert_not_nil(ret[44])
139 assert_not_nil(ret[44][1])
140
141 struct = ret[44][1]
142
143 assert_equal(struct.userMap[Thrift::Test::Numberz::ONE], 44)
144 assert_equal(struct.xtructs[1].string_thing, 'hi again')
145 assert_equal(struct.xtructs[1].i32_thing, 12)
146
147 assert_kind_of(Hash, struct.userMap)
148 assert_kind_of(Array, struct.xtructs)
149 assert_kind_of(Thrift::Test::Insanity, struct)
150 end
151
152 def test_map_map
153 ret = @client.testMapMap(4)
154 assert_kind_of(Hash, ret)
155 assert_equal(ret, { 4 => { 4 => 4}})
156 end
157
158 def test_exception
159 assert_raise Thrift::Test::Xception do
160 @client.testException('foo')
161 end
162 end
163end
164