blob: fba0178ba27242c3193ebe769c6ff5ac723fad33 [file] [log] [blame]
Bryan Duxburya971fb02011-03-04 00:49:40 +00001<?php
Roger Meier21c0a852012-09-05 19:47:14 +00002
3namespace test\php;
4
Robert Lu68707d92018-01-17 19:40:39 +08005/** @var \Composer\Autoload\ClassLoader $loader */
6$loader = require __DIR__ . '/../../vendor/autoload.php';
Roger Meier21c0a852012-09-05 19:47:14 +00007
8use Thrift\ClassLoader\ThriftClassLoader;
9
10if (!isset($GEN_DIR)) {
11 $GEN_DIR = 'gen-php';
12}
13if (!isset($MODE)) {
14 $MODE = 'normal';
15}
16
Robert Lu68707d92018-01-17 19:40:39 +080017
18if ($GEN_DIR == 'gen-php') {
19 $loader->addPsr4('', $GEN_DIR);
Andreas Schejad1ceba42016-05-15 21:49:04 +020020} else {
Robert Lu68707d92018-01-17 19:40:39 +080021 $loader = new ThriftClassLoader();
Andreas Schejad1ceba42016-05-15 21:49:04 +020022 $loader->registerDefinition('ThriftTest', $GEN_DIR);
Robert Lu68707d92018-01-17 19:40:39 +080023 $loader->register();
Andreas Schejad1ceba42016-05-15 21:49:04 +020024}
Roger Meier21c0a852012-09-05 19:47:14 +000025
David Reissea2cba82009-03-30 21:35:00 +000026/*
27 * Licensed to the Apache Software Foundation (ASF) under one
28 * or more contributor license agreements. See the NOTICE file
29 * distributed with this work for additional information
30 * regarding copyright ownership. The ASF licenses this file
31 * to you under the Apache License, Version 2.0 (the
32 * "License"); you may not use this file except in compliance
33 * with the License. You may obtain a copy of the License at
34 *
35 * http://www.apache.org/licenses/LICENSE-2.0
36 *
37 * Unless required by applicable law or agreed to in writing,
38 * software distributed under the License is distributed on an
39 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
40 * KIND, either express or implied. See the License for the
41 * specific language governing permissions and limitations
42 * under the License.
43 */
44
Mark Slee6e536442006-06-30 18:28:50 +000045/** Include the Thrift base */
Jim King5903d672015-06-29 18:12:48 -040046/** Include the protocols */
Roger Meier21c0a852012-09-05 19:47:14 +000047use Thrift\Protocol\TBinaryProtocol;
Håkon Hitlandf39d4c82016-11-17 16:18:03 +010048use Thrift\Protocol\TBinaryProtocolAccelerated;
Jim King5903d672015-06-29 18:12:48 -040049use Thrift\Protocol\TCompactProtocol;
50use Thrift\Protocol\TJSONProtocol;
Mark Slee6e536442006-06-30 18:28:50 +000051
52/** Include the socket layer */
Roger Meier21c0a852012-09-05 19:47:14 +000053use Thrift\Transport\TSocket;
54use Thrift\Transport\TSocketPool;
Mark Slee6e536442006-06-30 18:28:50 +000055
56/** Include the socket layer */
Roger Meier21c0a852012-09-05 19:47:14 +000057use Thrift\Transport\TFramedTransport;
58use Thrift\Transport\TBufferedTransport;
Mark Slee5b743072007-11-13 04:00:29 +000059
Jim King5903d672015-06-29 18:12:48 -040060function makeProtocol($transport, $PROTO)
61{
62 if ($PROTO == 'binary') {
63 return new TBinaryProtocol($transport);
64 } else if ($PROTO == 'compact') {
65 return new TCompactProtocol($transport);
66 } else if ($PROTO == 'json') {
67 return new TJSONProtocol($transport);
Håkon Hitlandf39d4c82016-11-17 16:18:03 +010068 } else if ($PROTO == 'accel') {
69 if (!function_exists('thrift_protocol_write_binary')) {
70 echo "Acceleration extension is not loaded\n";
71 exit(1);
72 }
73 return new TBinaryProtocolAccelerated($transport);
Jim King5903d672015-06-29 18:12:48 -040074 }
75
Håkon Hitlandf39d4c82016-11-17 16:18:03 +010076 echo "--protocol must be one of {binary|compact|json|accel}\n";
77 exit(1);
Jim King5903d672015-06-29 18:12:48 -040078}
79
Mark Slee6e536442006-06-30 18:28:50 +000080$host = 'localhost';
81$port = 9090;
82
83if ($argc > 1) {
84 $host = $argv[0];
85}
86
87if ($argc > 2) {
88 $host = $argv[1];
89}
90
Roger Meier41ad4342015-03-24 22:30:40 +010091foreach ($argv as $arg) {
92 if (substr($arg, 0, 7) == '--port=') {
93 $port = substr($arg, 7);
Jim King5903d672015-06-29 18:12:48 -040094 } else if (substr($arg, 0, 12) == '--transport=') {
95 $MODE = substr($arg, 12);
96 } else if (substr($arg, 0, 11) == '--protocol=') {
97 $PROTO = substr($arg, 11);
Robert Lu68707d92018-01-17 19:40:39 +080098 }
Roger Meier41ad4342015-03-24 22:30:40 +010099}
100
Mark Slee1dd819c2006-10-26 04:56:18 +0000101$hosts = array('localhost');
Mark Sleeade2c832006-09-08 03:41:50 +0000102
Mark Slee6e536442006-06-30 18:28:50 +0000103$socket = new TSocket($host, $port);
Mark Sleeade2c832006-09-08 03:41:50 +0000104$socket = new TSocketPool($hosts, $port);
105$socket->setDebug(TRUE);
Mark Slee6e536442006-06-30 18:28:50 +0000106
Mark Sleed3d733a2006-09-01 22:19:06 +0000107if ($MODE == 'inline') {
108 $transport = $socket;
Roger Meier21c0a852012-09-05 19:47:14 +0000109 $testClient = new \ThriftTest\ThriftTestClient($transport);
Bryan Duxburya971fb02011-03-04 00:49:40 +0000110} else if ($MODE == 'framed') {
111 $framedSocket = new TFramedTransport($socket);
112 $transport = $framedSocket;
Jim King5903d672015-06-29 18:12:48 -0400113 $protocol = makeProtocol($transport, $PROTO);
Roger Meier21c0a852012-09-05 19:47:14 +0000114 $testClient = new \ThriftTest\ThriftTestClient($protocol);
Mark Sleed3d733a2006-09-01 22:19:06 +0000115} else {
116 $bufferedSocket = new TBufferedTransport($socket, 1024, 1024);
117 $transport = $bufferedSocket;
Jim King5903d672015-06-29 18:12:48 -0400118 $protocol = makeProtocol($transport, $PROTO);
Roger Meier21c0a852012-09-05 19:47:14 +0000119 $testClient = new \ThriftTest\ThriftTestClient($protocol);
Mark Sleed3d733a2006-09-01 22:19:06 +0000120}
121
122$transport->open();
Mark Slee6e536442006-06-30 18:28:50 +0000123
124$start = microtime(true);
125
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100126define('ERR_BASETYPES', 1);
127define('ERR_STRUCTS', 2);
128define('ERR_CONTAINERS', 4);
129define('ERR_EXCEPTIONS', 8);
130define('ERR_UNKNOWN', 64);
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900131$exitcode = 0;
Mark Slee6e536442006-06-30 18:28:50 +0000132/**
133 * VOID TEST
134 */
135print_r("testVoid()");
136$testClient->testVoid();
137print_r(" = void\n");
138
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900139function roundtrip($testClient, $method, $value) {
140 global $exitcode;
141 print_r("$method($value)");
142 $ret = $testClient->$method($value);
143 print_r(" = \"$ret\"\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100144 if ($value !== $ret) {
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900145 print_r("*** FAILED ***\n");
146 $exitcode |= ERR_BASETYPES;
147 }
148}
149
Mark Slee6e536442006-06-30 18:28:50 +0000150/**
151 * STRING TEST
152 */
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900153roundtrip($testClient, 'testString', "Test");
Mark Slee5b743072007-11-13 04:00:29 +0000154
Mark Slee6e536442006-06-30 18:28:50 +0000155/**
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100156 * BOOL TEST
157 */
158roundtrip($testClient, 'testBool', true);
159roundtrip($testClient, 'testBool', false);
160
161/**
Mark Slee6e536442006-06-30 18:28:50 +0000162 * BYTE TEST
163 */
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900164roundtrip($testClient, 'testByte', 1);
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100165roundtrip($testClient, 'testByte', -1);
166roundtrip($testClient, 'testByte', 127);
167roundtrip($testClient, 'testByte', -128);
Mark Slee6e536442006-06-30 18:28:50 +0000168
169/**
170 * I32 TEST
171 */
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900172roundtrip($testClient, 'testI32', -1);
Mark Slee6e536442006-06-30 18:28:50 +0000173
174/**
175 * I64 TEST
176 */
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100177roundtrip($testClient, 'testI64', 0);
178roundtrip($testClient, 'testI64', 1);
179roundtrip($testClient, 'testI64', -1);
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900180roundtrip($testClient, 'testI64', -34359738368);
Mark Slee6e536442006-06-30 18:28:50 +0000181
182/**
Mark Sleec98d0502006-09-06 02:42:25 +0000183 * DOUBLE TEST
184 */
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900185roundtrip($testClient, 'testDouble', -852.234234234);
Mark Sleec98d0502006-09-06 02:42:25 +0000186
187/**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100188 * BINARY TEST -- TODO
189 */
190
191/**
Volodymyr Panivko05644342026-03-07 14:16:50 +0100192 * UUID TEST
193 */
194print_r("testUuid('00000000-0000-0000-0000-000000000000')");
195$uuid_in = '00000000-0000-0000-0000-000000000000';
196$uuid_out = $testClient->testUuid($uuid_in);
197print_r(" = \"$uuid_out\"\n");
198if ($uuid_in !== $uuid_out) {
199 echo "**FAILED**\n";
200 $exitcode |= ERR_BASETYPES;
201}
202
203roundtrip($testClient, 'testUuid', '00000000-0000-0000-0000-000000000000');
204roundtrip($testClient, 'testUuid', '550e8400-e29b-41d4-a716-446655440000');
205
206/**
Mark Slee6e536442006-06-30 18:28:50 +0000207 * STRUCT TEST
208 */
209print_r("testStruct({\"Zero\", 1, -3, -5})");
Roger Meier21c0a852012-09-05 19:47:14 +0000210$out = new \ThriftTest\Xtruct();
Mark Slee6e536442006-06-30 18:28:50 +0000211$out->string_thing = "Zero";
212$out->byte_thing = 1;
213$out->i32_thing = -3;
214$out->i64_thing = -5;
215$in = $testClient->testStruct($out);
216print_r(" = {\"".$in->string_thing."\", ".
217 $in->byte_thing.", ".
218 $in->i32_thing.", ".
219 $in->i64_thing."}\n");
220
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100221if ($in != $out) {
222 echo "**FAILED**\n";
223 $exitcode |= ERR_STRUCTS;
224}
225
Mark Slee6e536442006-06-30 18:28:50 +0000226/**
227 * NESTED STRUCT TEST
228 */
229print_r("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Roger Meier21c0a852012-09-05 19:47:14 +0000230$out2 = new \ThriftTest\Xtruct2();
Mark Slee6e536442006-06-30 18:28:50 +0000231$out2->byte_thing = 1;
232$out2->struct_thing = $out;
233$out2->i32_thing = 5;
234$in2 = $testClient->testNest($out2);
235$in = $in2->struct_thing;
236print_r(" = {".$in2->byte_thing.", {\"".
237 $in->string_thing."\", ".
238 $in->byte_thing.", ".
239 $in->i32_thing.", ".
240 $in->i64_thing."}, ".
241 $in2->i32_thing."}\n");
242
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100243if ($in2 != $out2) {
244 echo "**FAILED**\n";
245 $exitcode |= ERR_STRUCTS;
246}
247
Mark Slee6e536442006-06-30 18:28:50 +0000248/**
249 * MAP TEST
250 */
251$mapout = array();
252for ($i = 0; $i < 5; ++$i) {
253 $mapout[$i] = $i-10;
254}
255print_r("testMap({");
256$first = true;
257foreach ($mapout as $key => $val) {
258 if ($first) {
259 $first = false;
260 } else {
261 print_r(", ");
262 }
263 print_r("$key => $val");
264}
265print_r("})");
266
267$mapin = $testClient->testMap($mapout);
268print_r(" = {");
269$first = true;
270foreach ($mapin as $key => $val) {
271 if ($first) {
272 $first = false;
273 } else {
274 print_r(", ");
275 }
276 print_r("$key => $val");
277}
278print_r("}\n");
279
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100280if ($mapin != $mapout) {
281 echo "**FAILED**\n";
282 $exitcode |= ERR_CONTAINERS;
283}
284
Håkon Hitlande66b8fc2016-12-05 18:42:41 +0100285$mapout = array();
286for ($i = 0; $i < 10; $i++) {
287 $mapout["key$i"] = "val$i";
288}
289print_r('testStringMap({');
290$first = true;
291foreach ($mapout as $key => $val) {
292 if ($first) {
293 $first = false;
294 } else {
295 print_r(", ");
296 }
297 print_r("\"$key\" => \"$val\"");
298}
299print_r("})");
300$mapin = $testClient->testStringMap($mapout);
301print_r(" = {");
302$first = true;
303foreach ($mapin as $key => $val) {
304 if ($first) {
305 $first = false;
306 } else {
307 print_r(", ");
308 }
309 print_r("\"$key\" => \"$val\"");
310}
311print_r("}\n");
312ksort($mapin);
313if ($mapin != $mapout) {
314 echo "**FAILED**\n";
315 $exitcode |= ERR_CONTAINERS;
316}
317
Mark Slee6e536442006-06-30 18:28:50 +0000318/**
319 * SET TEST
320 */
321$setout = array();;
322for ($i = -2; $i < 3; ++$i) {
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100323 $setout[$i]= true;
Mark Slee6e536442006-06-30 18:28:50 +0000324}
325print_r("testSet({");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100326echo implode(',', array_keys($setout));
Mark Slee6e536442006-06-30 18:28:50 +0000327print_r("})");
328$setin = $testClient->testSet($setout);
329print_r(" = {");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100330echo implode(', ', array_keys($setin));
Mark Slee6e536442006-06-30 18:28:50 +0000331print_r("}\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100332// Order of keys in set does not matter
333ksort($setin);
334if ($setout !== $setin) {
335 echo "**FAILED**\n";
336 $exitcode |= ERR_CONTAINERS;
337}
338// Regression test for corrupted array
339if ($setin[2] !== $setout[2] || is_int($setin[2])) {
340 echo "**FAILED**\n";
341 $exitcode |= ERR_CONTAINERS;
342}
Mark Slee6e536442006-06-30 18:28:50 +0000343
344/**
345 * LIST TEST
346 */
347$listout = array();
348for ($i = -2; $i < 3; ++$i) {
349 $listout []= $i;
350}
351print_r("testList({");
352$first = true;
353foreach ($listout as $val) {
354 if ($first) {
355 $first = false;
356 } else {
357 print_r(", ");
358 }
359 print_r($val);
360}
361print_r("})");
362$listin = $testClient->testList($listout);
363print_r(" = {");
364$first = true;
365foreach ($listin as $val) {
366 if ($first) {
367 $first = false;
368 } else {
369 print_r(", ");
370 }
371 print_r($val);
372}
373print_r("}\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100374if ($listin !== $listout) {
375 echo "**FAILED**\n";
376 $exitcode |= ERR_CONTAINERS;
377}
Mark Slee6e536442006-06-30 18:28:50 +0000378
379/**
380 * ENUM TEST
381 */
382print_r("testEnum(ONE)");
Roger Meier87afaac2013-01-06 20:10:42 +0100383$ret = $testClient->testEnum(\ThriftTest\Numberz::ONE);
Mark Slee6e536442006-06-30 18:28:50 +0000384print_r(" = $ret\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100385if ($ret != \ThriftTest\Numberz::ONE) {
386 echo "**FAILED**\n";
387 $exitcode |= ERR_STRUCTS;
388}
Mark Slee6e536442006-06-30 18:28:50 +0000389
390print_r("testEnum(TWO)");
Roger Meier87afaac2013-01-06 20:10:42 +0100391$ret = $testClient->testEnum(\ThriftTest\Numberz::TWO);
Mark Slee6e536442006-06-30 18:28:50 +0000392print_r(" = $ret\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100393if ($ret != \ThriftTest\Numberz::TWO) {
394 echo "**FAILED**\n";
395 $exitcode |= ERR_STRUCTS;
396}
Mark Slee6e536442006-06-30 18:28:50 +0000397
398print_r("testEnum(THREE)");
Roger Meier87afaac2013-01-06 20:10:42 +0100399$ret = $testClient->testEnum(\ThriftTest\Numberz::THREE);
Mark Slee6e536442006-06-30 18:28:50 +0000400print_r(" = $ret\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100401if ($ret != \ThriftTest\Numberz::THREE) {
402 echo "**FAILED**\n";
403 $exitcode |= ERR_STRUCTS;
404}
Mark Slee6e536442006-06-30 18:28:50 +0000405
406print_r("testEnum(FIVE)");
Roger Meier87afaac2013-01-06 20:10:42 +0100407$ret = $testClient->testEnum(\ThriftTest\Numberz::FIVE);
Mark Slee6e536442006-06-30 18:28:50 +0000408print_r(" = $ret\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100409if ($ret != \ThriftTest\Numberz::FIVE) {
410 echo "**FAILED**\n";
411 $exitcode |= ERR_STRUCTS;
412}
Mark Slee6e536442006-06-30 18:28:50 +0000413
414print_r("testEnum(EIGHT)");
Roger Meier87afaac2013-01-06 20:10:42 +0100415$ret = $testClient->testEnum(\ThriftTest\Numberz::EIGHT);
Mark Slee6e536442006-06-30 18:28:50 +0000416print_r(" = $ret\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100417if ($ret != \ThriftTest\Numberz::EIGHT) {
418 echo "**FAILED**\n";
419 $exitcode |= ERR_STRUCTS;
420}
Mark Slee6e536442006-06-30 18:28:50 +0000421
422/**
423 * TYPEDEF TEST
424 */
425print_r("testTypedef(309858235082523)");
426$uid = $testClient->testTypedef(309858235082523);
427print_r(" = $uid\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100428if ($uid !== 309858235082523) {
429 echo "**FAILED**\n";
430 $exitcode |= ERR_STRUCTS;
431}
Mark Slee6e536442006-06-30 18:28:50 +0000432
433/**
434 * NESTED MAP TEST
435 */
436print_r("testMapMap(1)");
437$mm = $testClient->testMapMap(1);
438print_r(" = {");
439foreach ($mm as $key => $val) {
440 print_r("$key => {");
441 foreach ($val as $k2 => $v2) {
442 print_r("$k2 => $v2, ");
443 }
444 print_r("}, ");
445}
446print_r("}\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100447$expected_mm = [
448 -4 => [-4 => -4, -3 => -3, -2 => -2, -1 => -1],
449 4 => [4 => 4, 3 => 3, 2 => 2, 1 => 1],
450];
451if ($mm != $expected_mm) {
452 echo "**FAILED**\n";
453 $exitcode |= ERR_CONTAINERS;
454}
Mark Slee6e536442006-06-30 18:28:50 +0000455
456/**
457 * INSANITY TEST
458 */
Roger Meier21c0a852012-09-05 19:47:14 +0000459$insane = new \ThriftTest\Insanity();
Roger Meier87afaac2013-01-06 20:10:42 +0100460$insane->userMap[\ThriftTest\Numberz::FIVE] = 5000;
Roger Meier21c0a852012-09-05 19:47:14 +0000461$truck = new \ThriftTest\Xtruct();
Mark Slee6e536442006-06-30 18:28:50 +0000462$truck->string_thing = "Truck";
463$truck->byte_thing = 8;
464$truck->i32_thing = 8;
465$truck->i64_thing = 8;
466$insane->xtructs []= $truck;
467print_r("testInsanity()");
468$whoa = $testClient->testInsanity($insane);
469print_r(" = {");
470foreach ($whoa as $key => $val) {
471 print_r("$key => {");
472 foreach ($val as $k2 => $v2) {
473 print_r("$k2 => {");
474 $userMap = $v2->userMap;
475 print_r("{");
Bryan Duxburya971fb02011-03-04 00:49:40 +0000476 if (is_array($userMap)) {
Mark Sleed3d733a2006-09-01 22:19:06 +0000477 foreach ($userMap as $k3 => $v3) {
478 print_r("$k3 => $v3, ");
479 }
Mark Slee6e536442006-06-30 18:28:50 +0000480 }
481 print_r("}, ");
Mark Slee5b743072007-11-13 04:00:29 +0000482
Mark Slee6e536442006-06-30 18:28:50 +0000483 $xtructs = $v2->xtructs;
484 print_r("{");
Mark Sleed3d733a2006-09-01 22:19:06 +0000485 if (is_array($xtructs)) {
486 foreach ($xtructs as $x) {
487 print_r("{\"".$x->string_thing."\", ".
488 $x->byte_thing.", ".$x->i32_thing.", ".$x->i64_thing."}, ");
489 }
Mark Slee6e536442006-06-30 18:28:50 +0000490 }
491 print_r("}");
Mark Slee5b743072007-11-13 04:00:29 +0000492
Mark Slee6e536442006-06-30 18:28:50 +0000493 print_r("}, ");
494 }
495 print_r("}, ");
496}
497print_r("}\n");
498
Mark Sleed3d733a2006-09-01 22:19:06 +0000499/**
500 * EXCEPTION TEST
501 */
502print_r("testException('Xception')");
503try {
504 $testClient->testException('Xception');
505 print_r(" void\nFAILURE\n");
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100506 $exitcode |= ERR_EXCEPTIONS;
Roger Meier87afaac2013-01-06 20:10:42 +0100507} catch (\ThriftTest\Xception $x) {
Mark Sleed3d733a2006-09-01 22:19:06 +0000508 print_r(' caught xception '.$x->errorCode.': '.$x->message."\n");
509}
510
Roy Sindre Norangsholec64f232017-07-26 20:49:38 +0200511// Regression test for THRIFT-4263
512print_r("testBinarySerializer_Deserialize('foo')");
513try {
514 \Thrift\Serializer\TBinarySerializer::deserialize(base64_decode('foo'), \ThriftTest\Xtruct2::class);
515 echo "**FAILED**\n";
516 $exitcode |= ERR_STRUCTS;
517} catch (\Thrift\Exception\TTransportException $happy_exception) {
518 // We expected this due to binary data of base64_decode('foo') is less then 4
519 // bytes and it tries to find thrift version number in the transport by
520 // reading i32() at the beginning. Casting to string validates that
521 // exception is still accessible in memory and not corrupted. Without patch,
522 // PHP will error log that the exception doesn't have any tostring method,
523 // which is a lie due to corrupted memory.
524 for($i=99; $i > 0; $i--) {
525 (string)$happy_exception;
526 }
527 print_r(" SUCCESS\n");
528}
529
Mark Slee6e536442006-06-30 18:28:50 +0000530/**
531 * Normal tests done.
532 */
533
534$stop = microtime(true);
535$elp = round(1000*($stop - $start), 0);
536print_r("Total time: $elp ms\n");
537
538/**
539 * Extraneous "I don't trust PHP to pack/unpack integer" tests
540 */
541
Håkon Hitlande66b8fc2016-12-05 18:42:41 +0100542if ($protocol instanceof TBinaryProtocolAccelerated) {
543 // Regression check: check that method name is not double-freed
544 // Method name should not be an interned string.
545 $method_name = "Void";
546 $method_name = "test$method_name";
547
548 $seqid = 0;
549 $args = new \ThriftTest\ThriftTest_testVoid_args();
550 thrift_protocol_write_binary($protocol, $method_name, \Thrift\Type\TMessageType::CALL, $args, $seqid, $protocol->isStrictWrite());
551 $testClient->recv_testVoid();
552
553}
554
Mark Slee6e536442006-06-30 18:28:50 +0000555// Max I32
556$num = pow(2, 30) + (pow(2, 30) - 1);
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100557roundtrip($testClient, 'testI32', $num);
Mark Slee6e536442006-06-30 18:28:50 +0000558
559// Min I32
560$num = 0 - pow(2, 31);
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100561roundtrip($testClient, 'testI32', $num);
Mark Slee6e536442006-06-30 18:28:50 +0000562
563// Max I64
564$num = pow(2, 62) + (pow(2, 62) - 1);
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100565roundtrip($testClient, 'testI64', $num);
Mark Slee6e536442006-06-30 18:28:50 +0000566
567// Min I64
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900568$num = 0 - pow(2, 62) - pow(2, 62);
Håkon Hitlandf39d4c82016-11-17 16:18:03 +0100569roundtrip($testClient, 'testI64', $num);
Mark Slee6e536442006-06-30 18:28:50 +0000570
Mark Sleed3d733a2006-09-01 22:19:06 +0000571$transport->close();
Nobuaki Sukegawae4ba1642016-07-22 18:09:32 +0900572exit($exitcode);