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