Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

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