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 { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 48 | print <<"EOF"; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 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; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 94 | if ($opts{'domain-socket'}) { |
| 95 | $socket = Thrift::UnixSocket->new($opts{'domain-socket'}); |
| 96 | } |
| 97 | elsif ($opts{ssl}) { |
| 98 | $socket = Thrift::SSLSocket->new(\%opts); |
| 99 | } |
| 100 | else { |
| 101 | $socket = Thrift::Socket->new($opts{host}, $opts{port}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | my $transport; |
| 105 | if ($opts{transport} eq 'buffered') { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 106 | $transport = Thrift::BufferedTransport->new($socket, 1024, 1024); |
| 107 | } |
| 108 | elsif ($opts{transport} eq 'framed') { |
| 109 | $transport = Thrift::FramedTransport->new($socket); |
| 110 | } |
| 111 | else { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 112 | usage(); |
| 113 | exit 1; |
| 114 | } |
| 115 | |
| 116 | my $protocol; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 117 | my $protocol2; |
| 118 | if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 119 | $protocol = Thrift::BinaryProtocol->new($transport); |
| 120 | } |
| 121 | else { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 122 | usage(); |
| 123 | exit 1; |
| 124 | } |
| 125 | |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 126 | my $secondService = undef; |
| 127 | if (index($opts{protocol}, 'multi') == 0) { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 128 | $protocol2 = Thrift::MultiplexedProtocol->new($protocol, 'SecondService'); |
| 129 | $protocol = Thrift::MultiplexedProtocol->new($protocol, 'ThriftTest'); |
| 130 | $secondService = ThriftTest::SecondServiceClient->new($protocol2); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 133 | my $testClient = ThriftTest::ThriftTestClient->new($protocol); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 134 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 135 | eval { |
| 136 | $transport->open(); |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 137 | }; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 138 | if($@){ |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 139 | die(Dumper($@)); |
| 140 | } |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 141 | |
| 142 | use constant ERR_BASETYPES => 1; |
| 143 | use constant ERR_STRUCTS => 2; |
| 144 | use constant ERR_CONTAINERS => 4; |
| 145 | use constant ERR_EXCEPTIONS => 8; |
| 146 | use constant ERR_PROTOCOL => 16; |
| 147 | use constant ERR_UNKNOWN => 64; |
| 148 | |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 149 | my $start = gettimeofday(); |
| 150 | |
| 151 | # |
| 152 | # VOID TEST |
| 153 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 154 | print('testVoid()'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 155 | $testClient->testVoid(); |
| 156 | print(" = void\n"); |
| 157 | |
| 158 | # |
| 159 | # STRING TEST |
| 160 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 161 | print('testString("Test")'); |
| 162 | my $s = $testClient->testString('Test'); |
| 163 | print(qq| = "$s"\n|); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 164 | exit(ERR_BASETYPES) if ($s ne 'Test'); |
| 165 | |
| 166 | # |
| 167 | # MULTIPLEXED TEST |
| 168 | # |
| 169 | if (index($opts{protocol}, 'multi') == 0) { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 170 | print('secondtestString("Test2")'); |
| 171 | $s = $secondService->secondtestString('Test2'); |
| 172 | print(qq| = "$s"\n|); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 173 | exit(ERR_PROTOCOL) if ($s ne 'testString("Test2")'); |
| 174 | } |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 175 | |
| 176 | # |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 177 | # BOOL TEST |
| 178 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 179 | print('testBool(1)'); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 180 | my $t = $testClient->testBool(1); |
| 181 | print(" = $t\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 182 | exit(ERR_BASETYPES) if ($t ne 1); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 183 | print('testBool(0)'); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 184 | my $f = $testClient->testBool(0); |
| 185 | print(" = $f\n"); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 186 | exit(ERR_BASETYPES) if ($f ne q||); |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 187 | |
| 188 | |
| 189 | # |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 190 | # BYTE TEST |
| 191 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 192 | print('testByte(1)'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 193 | my $u8 = $testClient->testByte(1); |
| 194 | print(" = $u8\n"); |
| 195 | |
| 196 | # |
| 197 | # I32 TEST |
| 198 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 199 | print('testI32(-1)'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 200 | my $i32 = $testClient->testI32(-1); |
| 201 | print(" = $i32\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 202 | exit(ERR_BASETYPES) if ($i32 ne -1); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 203 | |
| 204 | # |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 205 | # I64 TEST |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 206 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 207 | print('testI64(-34359738368)'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 208 | my $i64 = $testClient->testI64(-34359738368); |
| 209 | print(" = $i64\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 210 | exit(ERR_BASETYPES) if ($i64 ne -34359738368); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 211 | |
| 212 | # |
| 213 | # DOUBLE TEST |
| 214 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 215 | print('testDouble(-852.234234234)'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 216 | my $dub = $testClient->testDouble(-852.234234234); |
| 217 | print(" = $dub\n"); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 218 | exit(ERR_BASETYPES) if ($dub ne -852.234234234); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 219 | |
| 220 | # |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 221 | # BINARY TEST --- TODO |
| 222 | # |
| 223 | |
| 224 | |
| 225 | # |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 226 | # STRUCT TEST |
| 227 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 228 | print('testStruct({"Zero", 1, -3, -5})'); |
| 229 | my $out = ThriftTest::Xtruct->new(); |
| 230 | $out->string_thing('Zero'); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 231 | $out->byte_thing(1); |
| 232 | $out->i32_thing(-3); |
| 233 | $out->i64_thing(-5); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 234 | my $in = $testClient->testStruct($out); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 235 | print(' = {"'.$in->string_thing.'", '. |
| 236 | $in->byte_thing.', '. |
| 237 | $in->i32_thing.', '. |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 238 | $in->i64_thing."}\n"); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 239 | |
| 240 | # |
| 241 | # NESTED STRUCT TEST |
| 242 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 243 | print('testNest({1, {"Zero", 1, -3, -5}, 5}'); |
| 244 | my $out2 = ThriftTest::Xtruct2->new(); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 245 | $out2->byte_thing(1); |
| 246 | $out2->struct_thing($out); |
| 247 | $out2->i32_thing(5); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 248 | my $in2 = $testClient->testNest($out2); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 249 | $in = $in2->struct_thing; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 250 | print(' = {'.$in2->byte_thing.', {"'. |
| 251 | $in->string_thing.'", '. |
| 252 | $in->byte_thing.', '. |
| 253 | $in->i32_thing.', '. |
| 254 | $in->i64_thing.'}, '. |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 255 | $in2->i32_thing."}\n"); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 256 | |
| 257 | # |
| 258 | # MAP TEST |
| 259 | # |
| 260 | my $mapout = {}; |
| 261 | for (my $i = 0; $i < 5; ++$i) { |
| 262 | $mapout->{$i} = $i-10; |
| 263 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 264 | print('testMap({'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 265 | my $first = 1; |
| 266 | while( my($key,$val) = each %$mapout) { |
| 267 | if ($first) { |
| 268 | $first = 0; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 269 | } |
| 270 | else { |
| 271 | print(', '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 272 | } |
| 273 | print("$key => $val"); |
| 274 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 275 | print('})'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 276 | |
| 277 | |
| 278 | my $mapin = $testClient->testMap($mapout); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 279 | print(' = {'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 280 | |
| 281 | $first = 1; |
| 282 | while( my($key,$val) = each %$mapin){ |
| 283 | if ($first) { |
| 284 | $first = 0; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 285 | } |
| 286 | else { |
| 287 | print(', '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 288 | } |
| 289 | print("$key => $val"); |
| 290 | } |
| 291 | print("}\n"); |
| 292 | |
| 293 | # |
| 294 | # SET TEST |
| 295 | # |
| 296 | my $setout = []; |
| 297 | for (my $i = -2; $i < 3; ++$i) { |
| 298 | push(@$setout, $i); |
| 299 | } |
| 300 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 301 | print('testSet({'.join(',',@$setout).'})'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 302 | |
| 303 | my $setin = $testClient->testSet($setout); |
| 304 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 305 | print(' = {'.join(',',@$setout)."}\n"); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 306 | |
| 307 | # |
| 308 | # LIST TEST |
| 309 | # |
| 310 | my $listout = []; |
| 311 | for (my $i = -2; $i < 3; ++$i) { |
| 312 | push(@$listout, $i); |
| 313 | } |
| 314 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 315 | print('testList({'.join(',',@$listout).'})'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 316 | |
| 317 | my $listin = $testClient->testList($listout); |
| 318 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 319 | print(' = {'.join(',',@$listin)."}\n"); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 320 | |
| 321 | # |
| 322 | # ENUM TEST |
| 323 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 324 | print('testEnum(ONE)'); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 325 | my $ret = $testClient->testEnum(ThriftTest::Numberz::ONE); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 326 | print(" = $ret\n"); |
| 327 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 328 | print('testEnum(TWO)'); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 329 | $ret = $testClient->testEnum(ThriftTest::Numberz::TWO); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 330 | print(" = $ret\n"); |
| 331 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 332 | print('testEnum(THREE)'); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 333 | $ret = $testClient->testEnum(ThriftTest::Numberz::THREE); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 334 | print(" = $ret\n"); |
| 335 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 336 | print('testEnum(FIVE)'); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 337 | $ret = $testClient->testEnum(ThriftTest::Numberz::FIVE); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 338 | print(" = $ret\n"); |
| 339 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 340 | print('testEnum(EIGHT)'); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 341 | $ret = $testClient->testEnum(ThriftTest::Numberz::EIGHT); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 342 | print(" = $ret\n"); |
| 343 | |
| 344 | # |
| 345 | # TYPEDEF TEST |
| 346 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 347 | print('testTypedef(309858235082523)'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 348 | my $uid = $testClient->testTypedef(309858235082523); |
| 349 | print(" = $uid\n"); |
| 350 | |
| 351 | # |
| 352 | # NESTED MAP TEST |
| 353 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 354 | print('testMapMap(1)'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 355 | my $mm = $testClient->testMapMap(1); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 356 | print(' = {'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 357 | while( my ($key,$val) = each %$mm) { |
| 358 | print("$key => {"); |
| 359 | while( my($k2,$v2) = each %$val) { |
| 360 | print("$k2 => $v2, "); |
| 361 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 362 | print('}, '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 363 | } |
| 364 | print("}\n"); |
| 365 | |
| 366 | # |
| 367 | # INSANITY TEST |
| 368 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 369 | my $insane = ThriftTest::Insanity->new(); |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 370 | $insane->{userMap}->{ThriftTest::Numberz::FIVE} = 5000; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 371 | my $truck = ThriftTest::Xtruct->new(); |
| 372 | $truck->string_thing('Hello2'); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 373 | $truck->byte_thing(2); |
| 374 | $truck->i32_thing(2); |
| 375 | $truck->i64_thing(2); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 376 | my $truck2 = ThriftTest::Xtruct->new(); |
| 377 | $truck2->string_thing('Goodbye4'); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 378 | $truck2->byte_thing(4); |
| 379 | $truck2->i32_thing(4); |
| 380 | $truck2->i64_thing(4); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 381 | push(@{$insane->{xtructs}}, $truck); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 382 | push(@{$insane->{xtructs}}, $truck2); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 383 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 384 | print('testInsanity()'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 385 | my $whoa = $testClient->testInsanity($insane); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 386 | print(' = {'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 387 | while( my ($key,$val) = each %$whoa) { |
| 388 | print("$key => {"); |
| 389 | while( my($k2,$v2) = each %$val) { |
| 390 | print("$k2 => {"); |
| 391 | my $userMap = $v2->{userMap}; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 392 | print('{'); |
| 393 | if (ref($userMap) eq 'HASH') { |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 394 | while( my($k3,$v3) = each %$userMap) { |
| 395 | print("$k3 => $v3, "); |
| 396 | } |
| 397 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 398 | print('}, '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 399 | |
| 400 | my $xtructs = $v2->{xtructs}; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 401 | print('{'); |
| 402 | if (ref($xtructs) eq 'ARRAY') { |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 403 | foreach my $x (@$xtructs) { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 404 | print('{"'.$x->{string_thing}.'", '. |
| 405 | $x->{byte_thing}.', '.$x->{i32_thing}.', '.$x->{i64_thing}.'}, '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 408 | print('}'); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 409 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 410 | print('}, '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 411 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 412 | print('}, '); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 413 | } |
| 414 | print("}\n"); |
| 415 | |
| 416 | # |
| 417 | # EXCEPTION TEST |
| 418 | # |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 419 | print(q|testException('Xception')|); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 420 | eval { |
| 421 | $testClient->testException('Xception'); |
| 422 | print(" void\nFAILURE\n"); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 423 | }; if($@ && $@->UNIVERSAL::isa('ThriftTest::Xception')) { |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 424 | print(' caught xception '.$@->{errorCode}.': '.$@->{message}."\n"); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | # |
| 429 | # Normal tests done. |
| 430 | # |
| 431 | my $stop = gettimeofday(); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame^] | 432 | my $elp = sprintf('%d',1000*($stop - $start), 0); |
Mark Slee | 3e3d7ad | 2007-05-16 02:35:58 +0000 | [diff] [blame] | 433 | print("Total time: $elp ms\n"); |
| 434 | |
| 435 | # |
| 436 | # Extraneous "I don't trust PHP to pack/unpack integer" tests |
| 437 | # |
| 438 | |
| 439 | # Max I32 |
| 440 | my $num = 2**30 + 2**30 - 1; |
| 441 | my $num2 = $testClient->testI32($num); |
| 442 | if ($num != $num2) { |
| 443 | print "Missed max32 $num = $num2\n"; |
| 444 | } |
| 445 | |
| 446 | # Min I32 |
| 447 | $num = 0 - 2**31; |
| 448 | $num2 = $testClient->testI32($num); |
| 449 | if ($num != $num2) { |
| 450 | print "Missed min32 $num = $num2\n"; |
| 451 | } |
| 452 | |
| 453 | # Max Number I can get out of my perl |
| 454 | $num = 2**40; |
| 455 | $num2 = $testClient->testI64($num); |
| 456 | if ($num != $num2) { |
| 457 | print "Missed max64 $num = $num2\n"; |
| 458 | } |
| 459 | |
| 460 | # Max Number I can get out of my perl |
| 461 | $num = 0 - 2**40; |
| 462 | $num2 = $testClient->testI64($num); |
| 463 | if ($num != $num2) { |
| 464 | print "Missed min64 $num = $num2\n"; |
| 465 | } |
| 466 | |
| 467 | $transport->close(); |
| 468 | |
| 469 | |
| 470 | |