Roger Meier | 32f3982 | 2014-06-18 22:43:17 +0200 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 2 | # encoding: utf-8 |
Roger Meier | 32f3982 | 2014-06-18 22:43:17 +0200 | [diff] [blame] | 3 | |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 4 | # |
| 5 | # Licensed to the Apache Software Foundation (ASF) under one |
| 6 | # or more contributor license agreements. See the NOTICE file |
| 7 | # distributed with this work for additional information |
| 8 | # regarding copyright ownership. The ASF licenses this file |
| 9 | # to you under the Apache License, Version 2.0 (the |
| 10 | # "License"); you may not use this file except in compliance |
| 11 | # with the License. You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, |
| 16 | # software distributed under the License is distributed on an |
| 17 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 18 | # KIND, either express or implied. See the License for the |
| 19 | # specific language governing permissions and limitations |
| 20 | # under the License. |
| 21 | # |
| 22 | |
Roger Meier | c95d5df | 2014-01-19 21:53:02 +0100 | [diff] [blame] | 23 | $:.push File.dirname(__FILE__) + '/..' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 24 | |
Roger Meier | c95d5df | 2014-01-19 21:53:02 +0100 | [diff] [blame] | 25 | require 'test_helper' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 26 | require 'thrift' |
Roger Meier | c95d5df | 2014-01-19 21:53:02 +0100 | [diff] [blame] | 27 | require 'thrift_test' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 28 | |
James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 29 | $domain_socket = nil |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 30 | $protocolType = "binary" |
| 31 | $host = "localhost" |
| 32 | $port = 9090 |
| 33 | $transport = "buffered" |
James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 34 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 35 | ARGV.each do|a| |
| 36 | if a == "--help" |
| 37 | puts "Allowed options:" |
| 38 | puts "\t -h [ --help ] \t produce help message" |
James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 39 | puts "\t--domain-socket arg (=) \t Unix domain socket path - if not empty, host and port are ignored" |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 40 | puts "\t--host arg (=localhost) \t Host to connect" |
| 41 | puts "\t--port arg (=9090) \t Port number to listen" |
James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 42 | puts "\t--protocol arg (=binary) \t protocol: accel, binary, compact, json" |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 43 | puts "\t--transport arg (=buffered) transport: buffered, framed, http" |
| 44 | exit |
James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 45 | elsif a.start_with?("--domain-socket") |
| 46 | $domain_socket = a.split("=")[1] |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 47 | elsif a.start_with?("--host") |
| 48 | $host = a.split("=")[1] |
| 49 | elsif a.start_with?("--protocol") |
| 50 | $protocolType = a.split("=")[1] |
| 51 | elsif a.start_with?("--transport") |
| 52 | $transport = a.split("=")[1] |
| 53 | elsif a.start_with?("--port") |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 54 | $port = a.split("=")[1].to_i |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 55 | end |
| 56 | end |
| 57 | ARGV=[] |
| 58 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 59 | class SimpleClientTest < Test::Unit::TestCase |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 60 | def setup |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 61 | unless @socket |
James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 62 | if $domain_socket.to_s.strip.empty? |
| 63 | @socket = Thrift::Socket.new($host, $port) |
| 64 | else |
| 65 | @socket = Thrift::UNIXSocket.new($domain_socket) |
| 66 | end |
| 67 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 68 | if $transport == "buffered" |
| 69 | transportFactory = Thrift::BufferedTransport.new(@socket) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 70 | elsif $transport == "framed" |
| 71 | transportFactory = Thrift::FramedTransport.new(@socket) |
| 72 | else |
| 73 | raise 'Unknown transport type' |
| 74 | end |
| 75 | |
| 76 | if $protocolType == "binary" |
| 77 | @protocol = Thrift::BinaryProtocol.new(transportFactory) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 78 | elsif $protocolType == "compact" |
| 79 | @protocol = Thrift::CompactProtocol.new(transportFactory) |
| 80 | elsif $protocolType == "json" |
| 81 | @protocol = Thrift::JsonProtocol.new(transportFactory) |
| 82 | elsif $protocolType == "accel" |
| 83 | @protocol = Thrift::BinaryProtocolAccelerated.new(transportFactory) |
| 84 | else |
| 85 | raise 'Unknown protocol type' |
| 86 | end |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 87 | @client = Thrift::Test::ThriftTest::Client.new(@protocol) |
| 88 | @socket.open |
| 89 | end |
| 90 | end |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 91 | |
| 92 | def teardown |
| 93 | @socket.close |
| 94 | end |
| 95 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 96 | def test_void |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 97 | p 'test_void' |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 98 | @client.testVoid() |
| 99 | end |
| 100 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 101 | def test_string |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 102 | p 'test_string' |
Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 103 | test_string = |
| 104 | 'quote: \" backslash:' + |
| 105 | ' forwardslash-escaped: \/ ' + |
| 106 | ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + |
| 107 | ' now-all-of-them-together: "\\\/\b\n\r\t' + |
| 108 | ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' + |
| 109 | ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ' |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 110 | test_string = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " + |
| 111 | "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " + |
| 112 | "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " + |
| 113 | "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " + |
| 114 | "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " + |
| 115 | "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " + |
| 116 | "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " + |
| 117 | "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " + |
| 118 | "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " + |
| 119 | "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " + |
| 120 | "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " + |
| 121 | "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " + |
| 122 | "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " + |
| 123 | "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " + |
| 124 | "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " + |
| 125 | "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " + |
| 126 | "Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " + |
| 127 | "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " + |
| 128 | "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " + |
| 129 | "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " + |
| 130 | "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " + |
| 131 | "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " + |
| 132 | "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " + |
| 133 | "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " + |
| 134 | "Bân-lâm-gú, 粵語" |
Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 135 | |
| 136 | result_string = @client.testString(test_string) |
| 137 | assert_equal(test_string, result_string.force_encoding(Encoding::UTF_8)) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 138 | end |
| 139 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 140 | def test_bool |
| 141 | p 'test_bool' |
| 142 | assert_equal(@client.testBool(true), true) |
| 143 | assert_equal(@client.testBool(false), false) |
| 144 | end |
| 145 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 146 | def test_byte |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 147 | p 'test_byte' |
| 148 | val = 120 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 149 | assert_equal(@client.testByte(val), val) |
| 150 | assert_equal(@client.testByte(-val), -val) |
| 151 | end |
| 152 | |
| 153 | def test_i32 |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 154 | p 'test_i32' |
| 155 | val = 2000000032 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 156 | assert_equal(@client.testI32(val), val) |
| 157 | assert_equal(@client.testI32(-val), -val) |
| 158 | end |
| 159 | |
| 160 | def test_i64 |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 161 | p 'test_i64' |
| 162 | val = 9000000000000000064 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 163 | assert_equal(@client.testI64(val), val) |
| 164 | assert_equal(@client.testI64(-val), -val) |
| 165 | end |
| 166 | |
| 167 | def test_double |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 168 | p 'test_double' |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 169 | val = 3.14159265358979323846 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 170 | assert_equal(@client.testDouble(val), val) |
| 171 | assert_equal(@client.testDouble(-val), -val) |
| 172 | assert_kind_of(Float, @client.testDouble(val)) |
| 173 | end |
| 174 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 175 | def test_binary |
| 176 | p 'test_binary' |
Jens Geyer | 123258b | 2015-10-02 00:38:17 +0200 | [diff] [blame] | 177 | val = (0...256).reverse_each.to_a |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 178 | ret = @client.testBinary(val.pack('C*')) |
| 179 | assert_equal(val, ret.bytes.to_a) |
| 180 | end |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 181 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 182 | def test_map |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 183 | p 'test_map' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 184 | val = {1 => 1, 2 => 2, 3 => 3} |
| 185 | assert_equal(@client.testMap(val), val) |
| 186 | assert_kind_of(Hash, @client.testMap(val)) |
| 187 | end |
| 188 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 189 | def test_string_map |
| 190 | p 'test_string_map' |
| 191 | val = {'a' => '2', 'b' => 'blah', 'some' => 'thing'} |
| 192 | ret = @client.testStringMap(val) |
| 193 | assert_equal(val, ret) |
| 194 | assert_kind_of(Hash, ret) |
| 195 | end |
| 196 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 197 | def test_list |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 198 | p 'test_list' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 199 | val = [1,2,3,4,5] |
| 200 | assert_equal(@client.testList(val), val) |
| 201 | assert_kind_of(Array, @client.testList(val)) |
| 202 | end |
| 203 | |
| 204 | def test_enum |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 205 | p 'test_enum' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 206 | val = Thrift::Test::Numberz::SIX |
| 207 | ret = @client.testEnum(val) |
| 208 | |
| 209 | assert_equal(ret, 6) |
| 210 | assert_kind_of(Fixnum, ret) |
| 211 | end |
| 212 | |
| 213 | def test_typedef |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 214 | p 'test_typedef' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 215 | #UserId testTypedef(1: UserId thing), |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 216 | assert_equal(@client.testTypedef(309858235082523), 309858235082523) |
| 217 | assert_kind_of(Fixnum, @client.testTypedef(309858235082523)) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 218 | true |
| 219 | end |
| 220 | |
| 221 | def test_set |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 222 | p 'test_set' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 223 | val = Set.new([1,2,3]) |
| 224 | assert_equal(@client.testSet(val), val) |
| 225 | assert_kind_of(Set, @client.testSet(val)) |
| 226 | end |
| 227 | |
| 228 | def get_struct |
| 229 | Thrift::Test::Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 }) |
| 230 | end |
| 231 | |
| 232 | def test_struct |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 233 | p 'test_struct' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 234 | ret = @client.testStruct(get_struct) |
| 235 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 236 | # TODO: not sure what unspecified "default" requiredness values should be |
| 237 | assert(ret.byte_thing == nil || ret.byte_thing == 0) |
| 238 | assert(ret.i64_thing == nil || ret.i64_thing == 0) |
| 239 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 240 | assert_equal(ret.string_thing, 'hi!') |
| 241 | assert_equal(ret.i32_thing, 4) |
| 242 | assert_kind_of(Thrift::Test::Xtruct, ret) |
| 243 | end |
| 244 | |
| 245 | def test_nest |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 246 | p 'test_nest' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 247 | struct2 = Thrift::Test::Xtruct2.new({'struct_thing' => get_struct, 'i32_thing' => 10}) |
| 248 | |
| 249 | ret = @client.testNest(struct2) |
| 250 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 251 | # TODO: not sure what unspecified "default" requiredness values should be |
| 252 | assert(ret.struct_thing.byte_thing == nil || ret.struct_thing.byte_thing == 0) |
| 253 | assert(ret.struct_thing.i64_thing == nil || ret.struct_thing.i64_thing == 0) |
| 254 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 255 | assert_equal(ret.struct_thing.string_thing, 'hi!') |
| 256 | assert_equal(ret.struct_thing.i32_thing, 4) |
| 257 | assert_equal(ret.i32_thing, 10) |
| 258 | |
| 259 | assert_kind_of(Thrift::Test::Xtruct, ret.struct_thing) |
| 260 | assert_kind_of(Thrift::Test::Xtruct2, ret) |
| 261 | end |
| 262 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 263 | def test_insanity |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 264 | p 'test_insanity' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 265 | insane = Thrift::Test::Insanity.new({ |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 266 | 'userMap' => { |
| 267 | Thrift::Test::Numberz::FIVE => 5, |
| 268 | Thrift::Test::Numberz::EIGHT => 8, |
| 269 | }, |
| 270 | 'xtructs' => [ |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 271 | Thrift::Test::Xtruct.new({ |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 272 | 'string_thing' => 'Goodbye4', |
| 273 | 'byte_thing' => 4, |
| 274 | 'i32_thing' => 4, |
| 275 | 'i64_thing' => 4, |
| 276 | }), |
| 277 | Thrift::Test::Xtruct.new({ |
| 278 | 'string_thing' => 'Hello2', |
| 279 | 'byte_thing' => 2, |
| 280 | 'i32_thing' => 2, |
| 281 | 'i64_thing' => 2, |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 282 | }) |
| 283 | ] |
| 284 | }) |
| 285 | |
| 286 | ret = @client.testInsanity(insane) |
| 287 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 288 | assert_equal(insane, ret[1][2]) |
| 289 | assert_equal(insane, ret[1][3]) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 290 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 291 | assert(ret[2][6].userMap == nil || ret[2][6].userMap.length == 0) |
| 292 | assert(ret[2][6].xtructs == nil || ret[2][6].xtructs.length == 0) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 293 | end |
| 294 | |
| 295 | def test_map_map |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 296 | p 'test_map_map' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 297 | ret = @client.testMapMap(4) |
| 298 | assert_kind_of(Hash, ret) |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 299 | expected = { |
| 300 | -4 => { |
| 301 | -4 => -4, |
| 302 | -3 => -3, |
| 303 | -2 => -2, |
| 304 | -1 => -1, |
| 305 | }, |
| 306 | 4 => { |
| 307 | 4 => 4, |
| 308 | 3 => 3, |
| 309 | 2 => 2, |
| 310 | 1 => 1, |
| 311 | } |
| 312 | } |
| 313 | assert_equal(expected, ret) |
| 314 | end |
| 315 | |
| 316 | def test_multi |
| 317 | p 'test_multi' |
| 318 | ret = @client.testMulti(42, 4242, 424242, {1 => 'blah', 2 => 'thing'}, Thrift::Test::Numberz::EIGHT, 24) |
| 319 | expected = Thrift::Test::Xtruct.new({ |
| 320 | :string_thing => 'Hello2', |
| 321 | :byte_thing => 42, |
| 322 | :i32_thing => 4242, |
| 323 | :i64_thing => 424242 |
| 324 | }) |
| 325 | assert_equal(expected, ret) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 326 | end |
| 327 | |
| 328 | def test_exception |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 329 | p 'test_exception' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 330 | assert_raise Thrift::Test::Xception do |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 331 | @client.testException('Xception') |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 332 | end |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 333 | begin |
| 334 | @client.testException('TException') |
| 335 | rescue => e |
| 336 | assert e.class.ancestors.include?(Thrift::Exception) |
| 337 | end |
| 338 | assert_nothing_raised do |
| 339 | @client.testException('test') |
| 340 | end |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 341 | end |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 342 | |
| 343 | def test_multi_exception |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 344 | p 'test_multi_exception' |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 345 | assert_raise Thrift::Test::Xception do |
| 346 | @client.testMultiException("Xception", "test 1") |
| 347 | end |
| 348 | assert_raise Thrift::Test::Xception2 do |
| 349 | @client.testMultiException("Xception2", "test 2") |
| 350 | end |
| 351 | assert_equal( @client.testMultiException("Success", "test 3").string_thing, "test 3") |
| 352 | end |
| 353 | |
| 354 | def test_oneway |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 355 | p 'test_oneway' |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 356 | time1 = Time.now.to_f |
Nobuaki Sukegawa | a6ab1f5 | 2015-11-28 15:04:39 +0900 | [diff] [blame] | 357 | @client.testOneway(1) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 358 | time2 = Time.now.to_f |
Nobuaki Sukegawa | a6ab1f5 | 2015-11-28 15:04:39 +0900 | [diff] [blame] | 359 | assert_operator (time2-time1), :<, 0.1 |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 360 | end |
| 361 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 362 | end |
| 363 | |