T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 2 | |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 3 | # |
| 4 | # Licensed to the Apache Software Foundation (ASF) under one |
| 5 | # or more contributor license agreements. See the NOTICE file |
| 6 | # distributed with this work for additional information |
| 7 | # regarding copyright ownership. The ASF licenses this file |
| 8 | # to you under the Apache License, Version 2.0 (the |
| 9 | # "License"); you may not use this file except in compliance |
| 10 | # with the License. You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, |
| 15 | # software distributed under the License is distributed on an |
| 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | # KIND, either express or implied. See the License for the |
| 18 | # specific language governing permissions and limitations |
| 19 | # under the License. |
| 20 | # |
| 21 | |
James E. King, III | 177c37c | 2017-03-30 17:09:04 -0400 | [diff] [blame] | 22 | use 5.10.0; |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 23 | use strict; |
| 24 | use warnings; |
| 25 | use Data::Dumper; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 26 | use Getopt::Long qw(GetOptions); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 27 | use Time::HiRes qw(gettimeofday); |
| 28 | |
| 29 | use lib '../../lib/perl/lib'; |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 30 | use lib 'gen-perl'; |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 31 | |
| 32 | use Thrift; |
| 33 | use Thrift::BinaryProtocol; |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 34 | use Thrift::BufferedTransport; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 35 | use Thrift::FramedTransport; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 36 | use Thrift::MultiplexedProtocol; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 37 | use Thrift::SSLSocket; |
| 38 | use Thrift::Socket; |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 39 | use Thrift::UnixSocket; |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 40 | |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 41 | use ThriftTest::SecondService; |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 42 | use ThriftTest::ThriftTest; |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 43 | use ThriftTest::Types; |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 44 | |
| 45 | $|++; |
| 46 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 47 | sub usage { |
| 48 | print <<EOF; |
| 49 | Usage: $0 [OPTIONS] |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 50 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 51 | Options: (default) |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 52 | --ca CA to validate server with. |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 53 | --cert Certificate to use. |
| 54 | Required if using --ssl. |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 55 | --ciphers Acceptable cipher list. |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 56 | --domain-socket <file> Use a unix domain socket. |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 57 | --help Show usage. |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 58 | --key Certificate key. |
| 59 | Required if using --ssl. |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 60 | --port <portnum> 9090 Port to use. |
| 61 | --protocol {binary} binary Protocol to use. |
| 62 | --ssl If present, use SSL. |
| 63 | --transport {buffered|framed} buffered Transport to use. |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 64 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 65 | EOF |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 66 | } |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 67 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 68 | my %opts = ( |
| 69 | 'port' => 9090, |
| 70 | 'protocol' => 'binary', |
| 71 | 'transport' => 'buffered' |
| 72 | ); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 73 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 74 | GetOptions(\%opts, qw ( |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 75 | ca=s |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 76 | cert=s |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 77 | ciphers=s |
| 78 | key=s |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 79 | domain-socket=s |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 80 | help |
| 81 | host=s |
| 82 | port=i |
| 83 | protocol=s |
| 84 | ssl |
| 85 | transport=s |
| 86 | )) || exit 1; |
| 87 | |
| 88 | if ($opts{help}) { |
| 89 | usage(); |
| 90 | exit 0; |
| 91 | } |
| 92 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 93 | my $socket = undef; |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 94 | if ($opts{"domain-socket"}) { |
| 95 | $socket = new Thrift::UnixSocket($opts{"domain-socket"}); |
| 96 | } elsif ($opts{ssl}) { |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 97 | $socket = new Thrift::SSLSocket(\%opts); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 98 | } else { |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 99 | $socket = new Thrift::Socket($opts{host}, $opts{port}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | my $transport; |
| 103 | if ($opts{transport} eq 'buffered') { |
| 104 | $transport = new Thrift::BufferedTransport($socket, 1024, 1024); |
| 105 | } elsif ($opts{transport} eq 'framed') { |
| 106 | $transport = new Thrift::FramedTransport($socket); |
| 107 | } else { |
| 108 | usage(); |
| 109 | exit 1; |
| 110 | } |
| 111 | |
| 112 | my $protocol; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 113 | my $protocol2; |
| 114 | if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 115 | $protocol = new Thrift::BinaryProtocol($transport); |
| 116 | } else { |
| 117 | usage(); |
| 118 | exit 1; |
| 119 | } |
| 120 | |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 121 | my $secondService = undef; |
| 122 | if (index($opts{protocol}, 'multi') == 0) { |
| 123 | $protocol2 = new Thrift::MultiplexedProtocol($protocol, "SecondService"); |
| 124 | $protocol = new Thrift::MultiplexedProtocol($protocol, "ThriftTest"); |
| 125 | $secondService = new ThriftTest::SecondServiceClient($protocol2); |
| 126 | } |
| 127 | |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 128 | my $testClient = new ThriftTest::ThriftTestClient($protocol); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 129 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 130 | eval { |
| 131 | $transport->open(); |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 132 | }; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 133 | if($@){ |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 134 | die(Dumper($@)); |
| 135 | } |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 136 | |
| 137 | use constant ERR_BASETYPES => 1; |
| 138 | use constant ERR_STRUCTS => 2; |
| 139 | use constant ERR_CONTAINERS => 4; |
| 140 | use constant ERR_EXCEPTIONS => 8; |
| 141 | use constant ERR_PROTOCOL => 16; |
| 142 | use constant ERR_UNKNOWN => 64; |
| 143 | |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 144 | my $start = gettimeofday(); |
| 145 | |
| 146 | # |
| 147 | # VOID TEST |
| 148 | # |
| 149 | print("testVoid()"); |
| 150 | $testClient->testVoid(); |
| 151 | print(" = void\n"); |
| 152 | |
| 153 | # |
| 154 | # STRING TEST |
| 155 | # |
| 156 | print("testString(\"Test\")"); |
| 157 | my $s = $testClient->testString("Test"); |
| 158 | print(" = \"$s\"\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 159 | exit(ERR_BASETYPES) if ($s ne 'Test'); |
| 160 | |
| 161 | # |
| 162 | # MULTIPLEXED TEST |
| 163 | # |
| 164 | if (index($opts{protocol}, 'multi') == 0) { |
| 165 | print("secondtestString(\"Test2\")"); |
| 166 | $s = $secondService->secondtestString("Test2"); |
| 167 | print(" = \"$s\"\n"); |
| 168 | exit(ERR_PROTOCOL) if ($s ne 'testString("Test2")'); |
| 169 | } |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 170 | |
| 171 | # |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 172 | # BOOL TEST |
| 173 | # |
| 174 | print("testBool(1)"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 175 | my $t = $testClient->testBool(1); |
| 176 | print(" = $t\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 177 | exit(ERR_BASETYPES) if ($t ne 1); |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 178 | print("testBool(0)"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 179 | my $f = $testClient->testBool(0); |
| 180 | print(" = $f\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 181 | exit(ERR_BASETYPES) if ($f ne ""); |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 182 | |
| 183 | |
| 184 | # |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 185 | # BYTE TEST |
| 186 | # |
| 187 | print("testByte(1)"); |
| 188 | my $u8 = $testClient->testByte(1); |
| 189 | print(" = $u8\n"); |
| 190 | |
| 191 | # |
| 192 | # I32 TEST |
| 193 | # |
| 194 | print("testI32(-1)"); |
| 195 | my $i32 = $testClient->testI32(-1); |
| 196 | print(" = $i32\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 197 | exit(ERR_BASETYPES) if ($i32 ne -1); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 198 | |
| 199 | # |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 200 | # I64 TEST |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 201 | # |
| 202 | print("testI64(-34359738368)"); |
| 203 | my $i64 = $testClient->testI64(-34359738368); |
| 204 | print(" = $i64\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 205 | exit(ERR_BASETYPES) if ($i64 ne -34359738368); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 206 | |
| 207 | # |
| 208 | # DOUBLE TEST |
| 209 | # |
| 210 | print("testDouble(-852.234234234)"); |
| 211 | my $dub = $testClient->testDouble(-852.234234234); |
| 212 | print(" = $dub\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 213 | exit(ERR_BASETYPES) if ($dub ne -852.234234234); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 214 | |
| 215 | # |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 216 | # BINARY TEST --- TODO |
| 217 | # |
| 218 | |
| 219 | |
| 220 | # |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 221 | # STRUCT TEST |
| 222 | # |
| 223 | print("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 224 | my $out = new ThriftTest::Xtruct(); |
| 225 | $out->string_thing("Zero"); |
| 226 | $out->byte_thing(1); |
| 227 | $out->i32_thing(-3); |
| 228 | $out->i64_thing(-5); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 229 | my $in = $testClient->testStruct($out); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 230 | print(" = {\"".$in->string_thing."\", ". |
| 231 | $in->byte_thing.", ". |
| 232 | $in->i32_thing.", ". |
| 233 | $in->i64_thing."}\n"); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 234 | |
| 235 | # |
| 236 | # NESTED STRUCT TEST |
| 237 | # |
| 238 | print("testNest({1, {\"Zero\", 1, -3, -5}, 5}"); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 239 | my $out2 = new ThriftTest::Xtruct2(); |
| 240 | $out2->byte_thing(1); |
| 241 | $out2->struct_thing($out); |
| 242 | $out2->i32_thing(5); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 243 | my $in2 = $testClient->testNest($out2); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 244 | $in = $in2->struct_thing; |
| 245 | print(" = {".$in2->byte_thing.", {\"". |
| 246 | $in->string_thing."\", ". |
| 247 | $in->byte_thing.", ". |
| 248 | $in->i32_thing.", ". |
| 249 | $in->i64_thing."}, ". |
| 250 | $in2->i32_thing."}\n"); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 251 | |
| 252 | # |
| 253 | # MAP TEST |
| 254 | # |
| 255 | my $mapout = {}; |
| 256 | for (my $i = 0; $i < 5; ++$i) { |
| 257 | $mapout->{$i} = $i-10; |
| 258 | } |
| 259 | print("testMap({"); |
| 260 | my $first = 1; |
| 261 | while( my($key,$val) = each %$mapout) { |
| 262 | if ($first) { |
| 263 | $first = 0; |
| 264 | } else { |
| 265 | print(", "); |
| 266 | } |
| 267 | print("$key => $val"); |
| 268 | } |
| 269 | print("})"); |
| 270 | |
| 271 | |
| 272 | my $mapin = $testClient->testMap($mapout); |
| 273 | print(" = {"); |
| 274 | |
| 275 | $first = 1; |
| 276 | while( my($key,$val) = each %$mapin){ |
| 277 | if ($first) { |
| 278 | $first = 0; |
| 279 | } else { |
| 280 | print(", "); |
| 281 | } |
| 282 | print("$key => $val"); |
| 283 | } |
| 284 | print("}\n"); |
| 285 | |
| 286 | # |
| 287 | # SET TEST |
| 288 | # |
| 289 | my $setout = []; |
| 290 | for (my $i = -2; $i < 3; ++$i) { |
| 291 | push(@$setout, $i); |
| 292 | } |
| 293 | |
| 294 | print("testSet({".join(",",@$setout)."})"); |
| 295 | |
| 296 | my $setin = $testClient->testSet($setout); |
| 297 | |
| 298 | print(" = {".join(",",@$setout)."}\n"); |
| 299 | |
| 300 | # |
| 301 | # LIST TEST |
| 302 | # |
| 303 | my $listout = []; |
| 304 | for (my $i = -2; $i < 3; ++$i) { |
| 305 | push(@$listout, $i); |
| 306 | } |
| 307 | |
| 308 | print("testList({".join(",",@$listout)."})"); |
| 309 | |
| 310 | my $listin = $testClient->testList($listout); |
| 311 | |
| 312 | print(" = {".join(",",@$listin)."}\n"); |
| 313 | |
| 314 | # |
| 315 | # ENUM TEST |
| 316 | # |
| 317 | print("testEnum(ONE)"); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 318 | my $ret = $testClient->testEnum(ThriftTest::Numberz::ONE); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 319 | print(" = $ret\n"); |
| 320 | |
| 321 | print("testEnum(TWO)"); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 322 | $ret = $testClient->testEnum(ThriftTest::Numberz::TWO); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 323 | print(" = $ret\n"); |
| 324 | |
| 325 | print("testEnum(THREE)"); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 326 | $ret = $testClient->testEnum(ThriftTest::Numberz::THREE); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 327 | print(" = $ret\n"); |
| 328 | |
| 329 | print("testEnum(FIVE)"); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 330 | $ret = $testClient->testEnum(ThriftTest::Numberz::FIVE); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 331 | print(" = $ret\n"); |
| 332 | |
| 333 | print("testEnum(EIGHT)"); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 334 | $ret = $testClient->testEnum(ThriftTest::Numberz::EIGHT); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 335 | print(" = $ret\n"); |
| 336 | |
| 337 | # |
| 338 | # TYPEDEF TEST |
| 339 | # |
| 340 | print("testTypedef(309858235082523)"); |
| 341 | my $uid = $testClient->testTypedef(309858235082523); |
| 342 | print(" = $uid\n"); |
| 343 | |
| 344 | # |
| 345 | # NESTED MAP TEST |
| 346 | # |
| 347 | print("testMapMap(1)"); |
| 348 | my $mm = $testClient->testMapMap(1); |
| 349 | print(" = {"); |
| 350 | while( my ($key,$val) = each %$mm) { |
| 351 | print("$key => {"); |
| 352 | while( my($k2,$v2) = each %$val) { |
| 353 | print("$k2 => $v2, "); |
| 354 | } |
| 355 | print("}, "); |
| 356 | } |
| 357 | print("}\n"); |
| 358 | |
| 359 | # |
| 360 | # INSANITY TEST |
| 361 | # |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 362 | my $insane = new ThriftTest::Insanity(); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 363 | $insane->{userMap}->{ThriftTest::Numberz::FIVE} = 5000; |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 364 | my $truck = new ThriftTest::Xtruct(); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 365 | $truck->string_thing("Hello2"); |
| 366 | $truck->byte_thing(2); |
| 367 | $truck->i32_thing(2); |
| 368 | $truck->i64_thing(2); |
| 369 | my $truck2 = new ThriftTest::Xtruct(); |
| 370 | $truck2->string_thing("Goodbye4"); |
| 371 | $truck2->byte_thing(4); |
| 372 | $truck2->i32_thing(4); |
| 373 | $truck2->i64_thing(4); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 374 | push(@{$insane->{xtructs}}, $truck); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 375 | push(@{$insane->{xtructs}}, $truck2); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 376 | |
| 377 | print("testInsanity()"); |
| 378 | my $whoa = $testClient->testInsanity($insane); |
| 379 | print(" = {"); |
| 380 | while( my ($key,$val) = each %$whoa) { |
| 381 | print("$key => {"); |
| 382 | while( my($k2,$v2) = each %$val) { |
| 383 | print("$k2 => {"); |
| 384 | my $userMap = $v2->{userMap}; |
| 385 | print("{"); |
| 386 | if (ref($userMap) eq "HASH") { |
| 387 | while( my($k3,$v3) = each %$userMap) { |
| 388 | print("$k3 => $v3, "); |
| 389 | } |
| 390 | } |
| 391 | print("}, "); |
| 392 | |
| 393 | my $xtructs = $v2->{xtructs}; |
| 394 | print("{"); |
| 395 | if (ref($xtructs) eq "ARRAY") { |
| 396 | foreach my $x (@$xtructs) { |
| 397 | print("{\"".$x->{string_thing}."\", ". |
| 398 | $x->{byte_thing}.", ".$x->{i32_thing}.", ".$x->{i64_thing}."}, "); |
| 399 | } |
| 400 | } |
| 401 | print("}"); |
| 402 | |
| 403 | print("}, "); |
| 404 | } |
| 405 | print("}, "); |
| 406 | } |
| 407 | print("}\n"); |
| 408 | |
| 409 | # |
| 410 | # EXCEPTION TEST |
| 411 | # |
| 412 | print("testException('Xception')"); |
| 413 | eval { |
| 414 | $testClient->testException('Xception'); |
| 415 | print(" void\nFAILURE\n"); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 416 | }; if($@ && $@->UNIVERSAL::isa('ThriftTest::Xception')) { |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 417 | print(' caught xception '.$@->{errorCode}.': '.$@->{message}."\n"); |
| 418 | } |
| 419 | |
| 420 | |
| 421 | # |
| 422 | # Normal tests done. |
| 423 | # |
| 424 | my $stop = gettimeofday(); |
| 425 | my $elp = sprintf("%d",1000*($stop - $start), 0); |
| 426 | print("Total time: $elp ms\n"); |
| 427 | |
| 428 | # |
| 429 | # Extraneous "I don't trust PHP to pack/unpack integer" tests |
| 430 | # |
| 431 | |
| 432 | # Max I32 |
| 433 | my $num = 2**30 + 2**30 - 1; |
| 434 | my $num2 = $testClient->testI32($num); |
| 435 | if ($num != $num2) { |
| 436 | print "Missed max32 $num = $num2\n"; |
| 437 | } |
| 438 | |
| 439 | # Min I32 |
| 440 | $num = 0 - 2**31; |
| 441 | $num2 = $testClient->testI32($num); |
| 442 | if ($num != $num2) { |
| 443 | print "Missed min32 $num = $num2\n"; |
| 444 | } |
| 445 | |
| 446 | # Max Number I can get out of my perl |
| 447 | $num = 2**40; |
| 448 | $num2 = $testClient->testI64($num); |
| 449 | if ($num != $num2) { |
| 450 | print "Missed max64 $num = $num2\n"; |
| 451 | } |
| 452 | |
| 453 | # Max Number I can get out of my perl |
| 454 | $num = 0 - 2**40; |
| 455 | $num2 = $testClient->testI64($num); |
| 456 | if ($num != $num2) { |
| 457 | print "Missed min64 $num = $num2\n"; |
| 458 | } |
| 459 | |
| 460 | $transport->close(); |
| 461 | |
| 462 | |
| 463 | |