Add dependencies locally
This commit is contained in:
658
deps/protobuf/php/tests/ArrayTest.php
vendored
Normal file
658
deps/protobuf/php/tests/ArrayTest.php
vendored
Normal file
@ -0,0 +1,658 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestMessage\Sub;
|
||||
|
||||
class ArrayTest extends TestBase
|
||||
{
|
||||
|
||||
#########################################################
|
||||
# Test int32 field.
|
||||
#########################################################
|
||||
|
||||
public function testInt32()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::INT32);
|
||||
|
||||
// Test append.
|
||||
$arr[] = MAX_INT32;
|
||||
$this->assertSame(MAX_INT32, $arr[0]);
|
||||
$arr[] = MIN_INT32;
|
||||
$this->assertSame(MIN_INT32, $arr[1]);
|
||||
|
||||
$arr[] = 1.1;
|
||||
$this->assertSame(1, $arr[2]);
|
||||
$arr[] = MAX_INT32_FLOAT;
|
||||
$this->assertSame(MAX_INT32, $arr[3]);
|
||||
$arr[] = MAX_INT32_FLOAT;
|
||||
$this->assertSame(MAX_INT32, $arr[4]);
|
||||
|
||||
$arr[] = '2';
|
||||
$this->assertSame(2, $arr[5]);
|
||||
$arr[] = '3.1';
|
||||
$this->assertSame(3, $arr[6]);
|
||||
$arr[] = MAX_INT32_STRING;
|
||||
$this->assertSame(MAX_INT32, $arr[7]);
|
||||
|
||||
$this->assertEquals(8, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
$this->assertSame(0, $arr[$i]);
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = MAX_INT32;
|
||||
$this->assertSame(MAX_INT32, $arr[0]);
|
||||
$arr[1] = MIN_INT32;
|
||||
$this->assertSame(MIN_INT32, $arr[1]);
|
||||
|
||||
$arr[2] = 1.1;
|
||||
$this->assertSame(1, $arr[2]);
|
||||
$arr[3] = MAX_INT32_FLOAT;
|
||||
$this->assertSame(MAX_INT32, $arr[3]);
|
||||
$arr[4] = MAX_INT32_FLOAT;
|
||||
$this->assertSame(MAX_INT32, $arr[4]);
|
||||
|
||||
$arr[5] = '2';
|
||||
$this->assertSame(2, $arr[5]);
|
||||
$arr[6] = '3.1';
|
||||
$this->assertSame(3, $arr[6]);
|
||||
$arr[7] = MAX_INT32_STRING;
|
||||
$this->assertSame(MAX_INT32, $arr[7]);
|
||||
|
||||
// Test foreach.
|
||||
$arr = new RepeatedField(GPBType::INT32);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$arr[] = $i;
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($arr as $val) {
|
||||
$this->assertSame($i++, $val);
|
||||
}
|
||||
$this->assertSame(3, $i);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test uint32 field.
|
||||
#########################################################
|
||||
|
||||
public function testUint32()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::UINT32);
|
||||
|
||||
// Test append.
|
||||
$arr[] = MAX_UINT32;
|
||||
$this->assertSame(-1, $arr[0]);
|
||||
$arr[] = -1;
|
||||
$this->assertSame(-1, $arr[1]);
|
||||
$arr[] = MIN_UINT32;
|
||||
$this->assertSame(MIN_UINT32, $arr[2]);
|
||||
|
||||
$arr[] = 1.1;
|
||||
$this->assertSame(1, $arr[3]);
|
||||
$arr[] = MAX_UINT32_FLOAT;
|
||||
$this->assertSame(-1, $arr[4]);
|
||||
$arr[] = -1.0;
|
||||
$this->assertSame(-1, $arr[5]);
|
||||
$arr[] = MIN_UINT32_FLOAT;
|
||||
$this->assertSame(MIN_UINT32, $arr[6]);
|
||||
|
||||
$arr[] = '2';
|
||||
$this->assertSame(2, $arr[7]);
|
||||
$arr[] = '3.1';
|
||||
$this->assertSame(3, $arr[8]);
|
||||
$arr[] = MAX_UINT32_STRING;
|
||||
$this->assertSame(-1, $arr[9]);
|
||||
$arr[] = '-1.0';
|
||||
$this->assertSame(-1, $arr[10]);
|
||||
$arr[] = MIN_UINT32_STRING;
|
||||
$this->assertSame(MIN_UINT32, $arr[11]);
|
||||
|
||||
$this->assertEquals(12, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
$this->assertSame(0, $arr[$i]);
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = MAX_UINT32;
|
||||
$this->assertSame(-1, $arr[0]);
|
||||
$arr[1] = -1;
|
||||
$this->assertSame(-1, $arr[1]);
|
||||
$arr[2] = MIN_UINT32;
|
||||
$this->assertSame(MIN_UINT32, $arr[2]);
|
||||
|
||||
$arr[3] = 1.1;
|
||||
$this->assertSame(1, $arr[3]);
|
||||
$arr[4] = MAX_UINT32_FLOAT;
|
||||
$this->assertSame(-1, $arr[4]);
|
||||
$arr[5] = -1.0;
|
||||
$this->assertSame(-1, $arr[5]);
|
||||
$arr[6] = MIN_UINT32_FLOAT;
|
||||
$this->assertSame(MIN_UINT32, $arr[6]);
|
||||
|
||||
$arr[7] = '2';
|
||||
$this->assertSame(2, $arr[7]);
|
||||
$arr[8] = '3.1';
|
||||
$this->assertSame(3, $arr[8]);
|
||||
$arr[9] = MAX_UINT32_STRING;
|
||||
$this->assertSame(-1, $arr[9]);
|
||||
$arr[10] = '-1.0';
|
||||
$this->assertSame(-1, $arr[10]);
|
||||
$arr[11] = MIN_UINT32_STRING;
|
||||
$this->assertSame(MIN_UINT32, $arr[11]);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test int64 field.
|
||||
#########################################################
|
||||
|
||||
public function testInt64()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::INT64);
|
||||
|
||||
// Test append.
|
||||
$arr[] = MAX_INT64;
|
||||
$arr[] = MIN_INT64;
|
||||
$arr[] = 1.1;
|
||||
$arr[] = '2';
|
||||
$arr[] = '3.1';
|
||||
$arr[] = MAX_INT64_STRING;
|
||||
$arr[] = MIN_INT64_STRING;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(MAX_INT64, $arr[0]);
|
||||
$this->assertSame(MIN_INT64, $arr[1]);
|
||||
$this->assertSame('1', $arr[2]);
|
||||
$this->assertSame('2', $arr[3]);
|
||||
$this->assertSame('3', $arr[4]);
|
||||
$this->assertSame(MAX_INT64_STRING, $arr[5]);
|
||||
$this->assertSame(MIN_INT64_STRING, $arr[6]);
|
||||
} else {
|
||||
$this->assertSame(MAX_INT64, $arr[0]);
|
||||
$this->assertSame(MIN_INT64, $arr[1]);
|
||||
$this->assertSame(1, $arr[2]);
|
||||
$this->assertSame(2, $arr[3]);
|
||||
$this->assertSame(3, $arr[4]);
|
||||
$this->assertSame(MAX_INT64, $arr[5]);
|
||||
$this->assertSame(MIN_INT64, $arr[6]);
|
||||
}
|
||||
|
||||
|
||||
$this->assertEquals(7, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('0', $arr[$i]);
|
||||
} else {
|
||||
$this->assertSame(0, $arr[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = MAX_INT64;
|
||||
$arr[1] = MIN_INT64;
|
||||
$arr[2] = 1.1;
|
||||
$arr[3] = '2';
|
||||
$arr[4] = '3.1';
|
||||
$arr[5] = MAX_INT64_STRING;
|
||||
$arr[6] = MIN_INT64_STRING;
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(MAX_INT64_STRING, $arr[0]);
|
||||
$this->assertSame(MIN_INT64_STRING, $arr[1]);
|
||||
$this->assertSame('1', $arr[2]);
|
||||
$this->assertSame('2', $arr[3]);
|
||||
$this->assertSame('3', $arr[4]);
|
||||
$this->assertSame(MAX_INT64_STRING, $arr[5]);
|
||||
$this->assertEquals(MIN_INT64_STRING, $arr[6]);
|
||||
} else {
|
||||
$this->assertSame(MAX_INT64, $arr[0]);
|
||||
$this->assertSame(MIN_INT64, $arr[1]);
|
||||
$this->assertSame(1, $arr[2]);
|
||||
$this->assertSame(2, $arr[3]);
|
||||
$this->assertSame(3, $arr[4]);
|
||||
$this->assertSame(MAX_INT64, $arr[5]);
|
||||
$this->assertEquals(MIN_INT64, $arr[6]);
|
||||
}
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test uint64 field.
|
||||
#########################################################
|
||||
|
||||
public function testUint64()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::UINT64);
|
||||
|
||||
// Test append.
|
||||
$arr[] = MAX_UINT64;
|
||||
$arr[] = 1.1;
|
||||
$arr[] = '2';
|
||||
$arr[] = '3.1';
|
||||
$arr[] = MAX_UINT64_STRING;
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(MAX_UINT64_STRING, $arr[0]);
|
||||
$this->assertSame('1', $arr[1]);
|
||||
$this->assertSame('2', $arr[2]);
|
||||
$this->assertSame('3', $arr[3]);
|
||||
$this->assertSame(MAX_UINT64_STRING, $arr[4]);
|
||||
} else {
|
||||
$this->assertSame(MAX_UINT64, $arr[0]);
|
||||
$this->assertSame(1, $arr[1]);
|
||||
$this->assertSame(2, $arr[2]);
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$this->assertSame(MAX_UINT64, $arr[4]);
|
||||
$this->assertSame(5, count($arr));
|
||||
}
|
||||
|
||||
$this->assertSame(5, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('0', $arr[$i]);
|
||||
} else {
|
||||
$this->assertSame(0, $arr[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = MAX_UINT64;
|
||||
$arr[1] = 1.1;
|
||||
$arr[2] = '2';
|
||||
$arr[3] = '3.1';
|
||||
$arr[4] = MAX_UINT64_STRING;
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(MAX_UINT64_STRING, $arr[0]);
|
||||
$this->assertSame('1', $arr[1]);
|
||||
$this->assertSame('2', $arr[2]);
|
||||
$this->assertSame('3', $arr[3]);
|
||||
$this->assertSame(MAX_UINT64_STRING, $arr[4]);
|
||||
} else {
|
||||
$this->assertSame(MAX_UINT64, $arr[0]);
|
||||
$this->assertSame(1, $arr[1]);
|
||||
$this->assertSame(2, $arr[2]);
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$this->assertSame(MAX_UINT64, $arr[4]);
|
||||
}
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test float field.
|
||||
#########################################################
|
||||
|
||||
public function testFloat()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::FLOAT);
|
||||
|
||||
// Test append.
|
||||
$arr[] = 1;
|
||||
$this->assertFloatEquals(1.0, $arr[0], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[] = 1.1;
|
||||
$this->assertFloatEquals(1.1, $arr[1], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[] = '2';
|
||||
$this->assertFloatEquals(2.0, $arr[2], MAX_FLOAT_DIFF);
|
||||
$arr[] = '3.1';
|
||||
$this->assertFloatEquals(3.1, $arr[3], MAX_FLOAT_DIFF);
|
||||
|
||||
$this->assertEquals(4, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
$this->assertSame(0.0, $arr[$i]);
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = 1;
|
||||
$this->assertFloatEquals(1.0, $arr[0], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[1] = 1.1;
|
||||
$this->assertFloatEquals(1.1, $arr[1], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[2] = '2';
|
||||
$this->assertFloatEquals(2.0, $arr[2], MAX_FLOAT_DIFF);
|
||||
$arr[3] = '3.1';
|
||||
$this->assertFloatEquals(3.1, $arr[3], MAX_FLOAT_DIFF);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test double field.
|
||||
#########################################################
|
||||
|
||||
public function testDouble()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::DOUBLE);
|
||||
|
||||
// Test append.
|
||||
$arr[] = 1;
|
||||
$this->assertFloatEquals(1.0, $arr[0], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[] = 1.1;
|
||||
$this->assertFloatEquals(1.1, $arr[1], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[] = '2';
|
||||
$this->assertFloatEquals(2.0, $arr[2], MAX_FLOAT_DIFF);
|
||||
$arr[] = '3.1';
|
||||
$this->assertFloatEquals(3.1, $arr[3], MAX_FLOAT_DIFF);
|
||||
|
||||
$this->assertEquals(4, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
$this->assertSame(0.0, $arr[$i]);
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = 1;
|
||||
$this->assertFloatEquals(1.0, $arr[0], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[1] = 1.1;
|
||||
$this->assertFloatEquals(1.1, $arr[1], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[2] = '2';
|
||||
$this->assertFloatEquals(2.0, $arr[2], MAX_FLOAT_DIFF);
|
||||
$arr[3] = '3.1';
|
||||
$this->assertFloatEquals(3.1, $arr[3], MAX_FLOAT_DIFF);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test bool field.
|
||||
#########################################################
|
||||
|
||||
public function testBool()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::BOOL);
|
||||
|
||||
// Test append.
|
||||
$arr[] = true;
|
||||
$this->assertSame(true, $arr[0]);
|
||||
|
||||
$arr[] = -1;
|
||||
$this->assertSame(true, $arr[1]);
|
||||
|
||||
$arr[] = 1.1;
|
||||
$this->assertSame(true, $arr[2]);
|
||||
|
||||
$arr[] = '';
|
||||
$this->assertSame(false, $arr[3]);
|
||||
|
||||
$this->assertEquals(4, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = 0;
|
||||
$this->assertSame(false, $arr[$i]);
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = true;
|
||||
$this->assertSame(true, $arr[0]);
|
||||
|
||||
$arr[1] = -1;
|
||||
$this->assertSame(true, $arr[1]);
|
||||
|
||||
$arr[2] = 1.1;
|
||||
$this->assertSame(true, $arr[2]);
|
||||
|
||||
$arr[3] = '';
|
||||
$this->assertSame(false, $arr[3]);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test string field.
|
||||
#########################################################
|
||||
|
||||
public function testString()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::STRING);
|
||||
|
||||
// Test append.
|
||||
$arr[] = 'abc';
|
||||
$this->assertSame('abc', $arr[0]);
|
||||
|
||||
$arr[] = 1;
|
||||
$this->assertSame('1', $arr[1]);
|
||||
|
||||
$arr[] = 1.1;
|
||||
$this->assertSame('1.1', $arr[2]);
|
||||
|
||||
$arr[] = true;
|
||||
$this->assertSame('1', $arr[3]);
|
||||
|
||||
$this->assertEquals(4, count($arr));
|
||||
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$arr[$i] = '';
|
||||
$this->assertSame('', $arr[$i]);
|
||||
}
|
||||
|
||||
// Test set.
|
||||
$arr[0] = 'abc';
|
||||
$this->assertSame('abc', $arr[0]);
|
||||
|
||||
$arr[1] = 1;
|
||||
$this->assertSame('1', $arr[1]);
|
||||
|
||||
$arr[2] = 1.1;
|
||||
$this->assertSame('1.1', $arr[2]);
|
||||
|
||||
$arr[3] = true;
|
||||
$this->assertSame('1', $arr[3]);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test message field.
|
||||
#########################################################
|
||||
|
||||
public function testMessage()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
|
||||
|
||||
// Test append.
|
||||
$sub_m = new Sub();
|
||||
$sub_m->setA(1);
|
||||
$arr[] = $sub_m;
|
||||
$this->assertSame(1, $arr[0]->getA());
|
||||
|
||||
$this->assertEquals(1, count($arr));
|
||||
|
||||
// Test set.
|
||||
$sub_m = new Sub();
|
||||
$sub_m->setA(2);
|
||||
$arr[0] = $sub_m;
|
||||
$this->assertSame(2, $arr[0]->getA());
|
||||
|
||||
// Test foreach.
|
||||
$arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$arr[] = new Sub();
|
||||
$arr[$i]->setA($i);
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($arr as $val) {
|
||||
$this->assertSame($i++, $val->getA());
|
||||
}
|
||||
$this->assertSame(3, $i);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test offset type
|
||||
#########################################################
|
||||
|
||||
public function testOffset()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::INT32);
|
||||
$arr[] = 0;
|
||||
|
||||
$arr[0] = 1;
|
||||
$this->assertSame(1, $arr[0]);
|
||||
$this->assertSame(1, count($arr));
|
||||
|
||||
$arr['0'] = 2;
|
||||
$this->assertSame(2, $arr['0']);
|
||||
$this->assertSame(2, $arr[0]);
|
||||
$this->assertSame(1, count($arr));
|
||||
|
||||
$arr[0.0] = 3;
|
||||
$this->assertSame(3, $arr[0.0]);
|
||||
$this->assertSame(1, count($arr));
|
||||
}
|
||||
|
||||
public function testInsertRemoval()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::INT32);
|
||||
|
||||
$arr[] = 0;
|
||||
$arr[] = 1;
|
||||
$arr[] = 2;
|
||||
$this->assertSame(3, count($arr));
|
||||
|
||||
unset($arr[2]);
|
||||
$this->assertSame(2, count($arr));
|
||||
$this->assertSame(0, $arr[0]);
|
||||
$this->assertSame(1, $arr[1]);
|
||||
|
||||
$arr[] = 3;
|
||||
$this->assertSame(3, count($arr));
|
||||
$this->assertSame(0, $arr[0]);
|
||||
$this->assertSame(1, $arr[1]);
|
||||
$this->assertSame(3, $arr[2]);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test reference in array
|
||||
#########################################################
|
||||
|
||||
public function testArrayElementIsReferenceInSetters()
|
||||
{
|
||||
// Bool elements
|
||||
$values = [true];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setRepeatedBool($values);
|
||||
|
||||
// Int32 elements
|
||||
$values = [1];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setRepeatedInt32($values);
|
||||
|
||||
// Double elements
|
||||
$values = [1.0];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setRepeatedDouble($values);
|
||||
|
||||
// String elements
|
||||
$values = ['a'];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setRepeatedString($values);
|
||||
|
||||
// Message elements
|
||||
$m = new TestMessage();
|
||||
$subs = [1, 2];
|
||||
foreach ($subs as &$sub) {
|
||||
$sub = new Sub(['a' => $sub]);
|
||||
}
|
||||
$m->setRepeatedMessage($subs);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test memory leak
|
||||
#########################################################
|
||||
|
||||
public function testCycleLeak()
|
||||
{
|
||||
if (getenv("USE_ZEND_ALLOC") === "0") {
|
||||
// If we are disabling Zend's internal allocator (as we do for
|
||||
// Valgrind tests, for example) then memory_get_usage() will not
|
||||
// return a useful value.
|
||||
$this->markTestSkipped();
|
||||
return;
|
||||
}
|
||||
|
||||
gc_collect_cycles();
|
||||
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
|
||||
$arr[] = new TestMessage;
|
||||
$arr[0]->SetRepeatedRecursive($arr);
|
||||
|
||||
// Clean up memory before test.
|
||||
gc_collect_cycles();
|
||||
$start = memory_get_usage();
|
||||
unset($arr);
|
||||
|
||||
// Explicitly trigger garbage collection.
|
||||
gc_collect_cycles();
|
||||
|
||||
$end = memory_get_usage();
|
||||
$this->assertLessThan($start, $end);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test incorrect types
|
||||
#########################################################
|
||||
|
||||
public function testAppendNull()
|
||||
{
|
||||
$this->expectException(TypeError::class);
|
||||
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
|
||||
$arr[] = null;
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test equality
|
||||
#########################################################
|
||||
|
||||
public function testEquality()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::INT32);
|
||||
$arr2 = new RepeatedField(GPBType::INT32);
|
||||
|
||||
$this->assertTrue($arr == $arr2);
|
||||
|
||||
$arr[] = 0;
|
||||
$arr[] = 1;
|
||||
$arr[] = 2;
|
||||
|
||||
$this->assertFalse($arr == $arr2);
|
||||
|
||||
$arr2[] = 0;
|
||||
$arr2[] = 1;
|
||||
$arr2[] = 2;
|
||||
|
||||
$this->assertTrue($arr == $arr2);
|
||||
|
||||
// Arrays of different types always compare false.
|
||||
$this->assertFalse(new RepeatedField(GPBType::INT32) ==
|
||||
new RepeatedField(GPBType::INT64));
|
||||
$this->assertFalse(
|
||||
new RepeatedField(GPBType::MESSAGE, TestMessage::class) ==
|
||||
new RepeatedField(GPBType::MESSAGE, Sub::class));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test clone
|
||||
#########################################################
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
|
||||
$arr[] = new TestMessage;
|
||||
$arr2 = clone $arr;
|
||||
$this->assertSame($arr[0], $arr2[0]);
|
||||
}
|
||||
}
|
255
deps/protobuf/php/tests/DescriptorsTest.php
vendored
Normal file
255
deps/protobuf/php/tests/DescriptorsTest.php
vendored
Normal file
@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Google\Protobuf\DescriptorPool;
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\MapField;
|
||||
use Descriptors\TestDescriptorsEnum;
|
||||
use Descriptors\TestDescriptorsMessage;
|
||||
use Descriptors\TestDescriptorsMessage\Sub;
|
||||
use Foo\TestMessage;
|
||||
use Bar\TestInclude;
|
||||
|
||||
class DescriptorsTest extends TestBase
|
||||
{
|
||||
|
||||
// Redefine these here for compatibility with c extension
|
||||
const GPBLABEL_OPTIONAL = 1;
|
||||
const GPBLABEL_REQUIRED = 2;
|
||||
const GPBLABEL_REPEATED = 3;
|
||||
|
||||
const GPBTYPE_DOUBLE = 1;
|
||||
const GPBTYPE_FLOAT = 2;
|
||||
const GPBTYPE_INT64 = 3;
|
||||
const GPBTYPE_UINT64 = 4;
|
||||
const GPBTYPE_INT32 = 5;
|
||||
const GPBTYPE_FIXED64 = 6;
|
||||
const GPBTYPE_FIXED32 = 7;
|
||||
const GPBTYPE_BOOL = 8;
|
||||
const GPBTYPE_STRING = 9;
|
||||
const GPBTYPE_GROUP = 10;
|
||||
const GPBTYPE_MESSAGE = 11;
|
||||
const GPBTYPE_BYTES = 12;
|
||||
const GPBTYPE_UINT32 = 13;
|
||||
const GPBTYPE_ENUM = 14;
|
||||
const GPBTYPE_SFIXED32 = 15;
|
||||
const GPBTYPE_SFIXED64 = 16;
|
||||
const GPBTYPE_SINT32 = 17;
|
||||
const GPBTYPE_SINT64 = 18;
|
||||
|
||||
#########################################################
|
||||
# Test descriptor pool.
|
||||
#########################################################
|
||||
|
||||
public function testDescriptorPool()
|
||||
{
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
|
||||
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
|
||||
$this->assertInstanceOf('\Google\Protobuf\Descriptor', $desc);
|
||||
|
||||
$enumDesc = $pool->getEnumDescriptorByClassName(get_class(new TestDescriptorsEnum()));
|
||||
$this->assertInstanceOf('\Google\Protobuf\EnumDescriptor', $enumDesc);
|
||||
}
|
||||
|
||||
public function testDescriptorPoolIncorrectArgs()
|
||||
{
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
|
||||
$desc = $pool->getDescriptorByClassName('NotAClass');
|
||||
$this->assertNull($desc);
|
||||
|
||||
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsEnum()));
|
||||
$this->assertNull($desc);
|
||||
|
||||
$enumDesc = $pool->getEnumDescriptorByClassName(get_class(new TestDescriptorsMessage()));
|
||||
$this->assertNull($enumDesc);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test descriptor.
|
||||
#########################################################
|
||||
|
||||
public function testDescriptor()
|
||||
{
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
$class = get_class(new TestDescriptorsMessage());
|
||||
$this->assertSame('Descriptors\TestDescriptorsMessage', $class);
|
||||
$desc = $pool->getDescriptorByClassName($class);
|
||||
|
||||
$this->assertSame('descriptors.TestDescriptorsMessage', $desc->getFullName());
|
||||
$this->assertSame($class, $desc->getClass());
|
||||
|
||||
$this->assertInstanceOf('\Google\Protobuf\FieldDescriptor', $desc->getField(0));
|
||||
$this->assertSame(7, $desc->getFieldCount());
|
||||
|
||||
$this->assertInstanceOf('\Google\Protobuf\OneofDescriptor', $desc->getOneofDecl(0));
|
||||
$this->assertSame(1, $desc->getOneofDeclCount());
|
||||
}
|
||||
|
||||
public function testDescriptorForIncludedMessage()
|
||||
{
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
$class = get_class(new TestMessage());
|
||||
$this->assertSame('Foo\TestMessage', $class);
|
||||
$desc = $pool->getDescriptorByClassName($class);
|
||||
$fielddesc = $desc->getField(17);
|
||||
$subdesc = $fielddesc->getMessageType();
|
||||
$this->assertSame('Bar\TestInclude', $subdesc->getClass());
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test enum descriptor.
|
||||
#########################################################
|
||||
|
||||
public function testEnumDescriptor()
|
||||
{
|
||||
// WARNING - we need to do this so that TestDescriptorsEnum is registered!!?
|
||||
new TestDescriptorsMessage();
|
||||
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
|
||||
$enumDesc = $pool->getEnumDescriptorByClassName(get_class(new TestDescriptorsEnum()));
|
||||
|
||||
// Build map of enum values
|
||||
$enumDescMap = [];
|
||||
for ($i = 0; $i < $enumDesc->getValueCount(); $i++) {
|
||||
$enumValueDesc = $enumDesc->getValue($i);
|
||||
$this->assertInstanceOf('\Google\Protobuf\EnumValueDescriptor', $enumValueDesc);
|
||||
$enumDescMap[$enumValueDesc->getNumber()] = $enumValueDesc->getName();
|
||||
}
|
||||
|
||||
$this->assertSame('ZERO', $enumDescMap[0]);
|
||||
$this->assertSame('ONE', $enumDescMap[1]);
|
||||
|
||||
$this->assertSame(2, $enumDesc->getValueCount());
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test field descriptor.
|
||||
#########################################################
|
||||
|
||||
public function testFieldDescriptor()
|
||||
{
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
|
||||
|
||||
$fieldDescMap = $this->buildFieldMap($desc);
|
||||
|
||||
// Optional int field
|
||||
$fieldDesc = $fieldDescMap[1];
|
||||
$this->assertSame('optional_int32', $fieldDesc->getName());
|
||||
$this->assertSame(1, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_OPTIONAL, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_INT32, $fieldDesc->getType());
|
||||
$this->assertFalse($fieldDesc->isMap());
|
||||
|
||||
// Optional enum field
|
||||
$fieldDesc = $fieldDescMap[16];
|
||||
$this->assertSame('optional_enum', $fieldDesc->getName());
|
||||
$this->assertSame(16, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_OPTIONAL, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_ENUM, $fieldDesc->getType());
|
||||
$this->assertInstanceOf('\Google\Protobuf\EnumDescriptor', $fieldDesc->getEnumType());
|
||||
$this->assertFalse($fieldDesc->isMap());
|
||||
|
||||
// Optional message field
|
||||
$fieldDesc = $fieldDescMap[17];
|
||||
$this->assertSame('optional_message', $fieldDesc->getName());
|
||||
$this->assertSame(17, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_OPTIONAL, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_MESSAGE, $fieldDesc->getType());
|
||||
$this->assertInstanceOf('\Google\Protobuf\Descriptor', $fieldDesc->getMessageType());
|
||||
$this->assertFalse($fieldDesc->isMap());
|
||||
|
||||
// Repeated int field
|
||||
$fieldDesc = $fieldDescMap[31];
|
||||
$this->assertSame('repeated_int32', $fieldDesc->getName());
|
||||
$this->assertSame(31, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_REPEATED, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_INT32, $fieldDesc->getType());
|
||||
$this->assertFalse($fieldDesc->isMap());
|
||||
|
||||
// Repeated message field
|
||||
$fieldDesc = $fieldDescMap[47];
|
||||
$this->assertSame('repeated_message', $fieldDesc->getName());
|
||||
$this->assertSame(47, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_REPEATED, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_MESSAGE, $fieldDesc->getType());
|
||||
$this->assertInstanceOf('\Google\Protobuf\Descriptor', $fieldDesc->getMessageType());
|
||||
$this->assertFalse($fieldDesc->isMap());
|
||||
|
||||
// Oneof int field
|
||||
// Tested further in testOneofDescriptor()
|
||||
$fieldDesc = $fieldDescMap[51];
|
||||
$this->assertSame('oneof_int32', $fieldDesc->getName());
|
||||
$this->assertSame(51, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_OPTIONAL, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_INT32, $fieldDesc->getType());
|
||||
$this->assertFalse($fieldDesc->isMap());
|
||||
|
||||
// Map int-enum field
|
||||
$fieldDesc = $fieldDescMap[71];
|
||||
$this->assertSame('map_int32_enum', $fieldDesc->getName());
|
||||
$this->assertSame(71, $fieldDesc->getNumber());
|
||||
$this->assertSame(self::GPBLABEL_REPEATED, $fieldDesc->getLabel());
|
||||
$this->assertSame(self::GPBTYPE_MESSAGE, $fieldDesc->getType());
|
||||
$this->assertTrue($fieldDesc->isMap());
|
||||
$mapDesc = $fieldDesc->getMessageType();
|
||||
$this->assertSame('descriptors.TestDescriptorsMessage.MapInt32EnumEntry', $mapDesc->getFullName());
|
||||
$this->assertSame(self::GPBTYPE_INT32, $mapDesc->getField(0)->getType());
|
||||
$this->assertSame(self::GPBTYPE_ENUM, $mapDesc->getField(1)->getType());
|
||||
}
|
||||
|
||||
public function testFieldDescriptorEnumException()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
|
||||
$fieldDesc = $desc->getField(0);
|
||||
$fieldDesc->getEnumType();
|
||||
}
|
||||
|
||||
public function testFieldDescriptorMessageException()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
|
||||
$fieldDesc = $desc->getField(0);
|
||||
$fieldDesc->getMessageType();
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test oneof descriptor.
|
||||
#########################################################
|
||||
|
||||
public function testOneofDescriptor()
|
||||
{
|
||||
$pool = DescriptorPool::getGeneratedPool();
|
||||
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
|
||||
|
||||
$fieldDescMap = $this->buildFieldMap($desc);
|
||||
$fieldDesc = $fieldDescMap[51];
|
||||
|
||||
$oneofDesc = $desc->getOneofDecl(0);
|
||||
|
||||
$this->assertSame('my_oneof', $oneofDesc->getName());
|
||||
$fieldDescFromOneof = $oneofDesc->getField(0);
|
||||
$this->assertSame($fieldDesc, $fieldDescFromOneof);
|
||||
$this->assertSame(1, $oneofDesc->getFieldCount());
|
||||
}
|
||||
|
||||
private function buildFieldMap($desc)
|
||||
{
|
||||
$fieldDescMap = [];
|
||||
for ($i = 0; $i < $desc->getFieldCount(); $i++) {
|
||||
$fieldDesc = $desc->getField($i);
|
||||
$fieldDescMap[$fieldDesc->getNumber()] = $fieldDesc;
|
||||
}
|
||||
return $fieldDescMap;
|
||||
}
|
||||
}
|
1516
deps/protobuf/php/tests/EncodeDecodeTest.php
vendored
Normal file
1516
deps/protobuf/php/tests/EncodeDecodeTest.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1874
deps/protobuf/php/tests/GeneratedClassTest.php
vendored
Normal file
1874
deps/protobuf/php/tests/GeneratedClassTest.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
350
deps/protobuf/php/tests/GeneratedPhpdocTest.php
vendored
Normal file
350
deps/protobuf/php/tests/GeneratedPhpdocTest.php
vendored
Normal file
@ -0,0 +1,350 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Foo\TestMessage;
|
||||
|
||||
class GeneratedPhpdocTest extends TestBase
|
||||
{
|
||||
public function testPhpDocForClass()
|
||||
{
|
||||
$class = new ReflectionClass('Foo\TestMessage');
|
||||
$doc = $class->getDocComment();
|
||||
$this->assertStringContains('foo.TestMessage', $doc);
|
||||
}
|
||||
|
||||
public function testPhpDocForConstructor()
|
||||
{
|
||||
$class = new ReflectionClass('Foo\TestMessage');
|
||||
$doc = $class->getMethod('__construct')->getDocComment();
|
||||
$this->assertStringContains('@param array $data', $doc);
|
||||
$this->assertStringContains('@type int $optional_int32', $doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePhpDocForGettersAndSetters
|
||||
*/
|
||||
public function testPhpDocForIntGetters($methods, $expectedDoc)
|
||||
{
|
||||
$class = new ReflectionClass('Foo\TestMessage');
|
||||
foreach ($methods as $method) {
|
||||
$doc = $class->getMethod($method)->getDocComment();
|
||||
$this->assertStringContains($expectedDoc, $doc);
|
||||
}
|
||||
}
|
||||
|
||||
public function providePhpDocForGettersAndSetters()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'setOptionalInt32',
|
||||
'setOptionalUint32',
|
||||
'setOptionalSint32',
|
||||
'setOptionalFixed32',
|
||||
'setOptionalSfixed32',
|
||||
'setOneofInt32',
|
||||
'setOneofUint32',
|
||||
'setOneofSint32',
|
||||
'setOneofFixed32',
|
||||
'setOneofSfixed32',
|
||||
'setOptionalEnum',
|
||||
'setOptionalNoNamespaceEnum',
|
||||
'setOptionalNestedEnum',
|
||||
'setOneofEnum'
|
||||
],
|
||||
'@param int $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalInt64',
|
||||
'setOptionalUint64',
|
||||
'setOptionalSint64',
|
||||
'setOptionalFixed64',
|
||||
'setOptionalSfixed64',
|
||||
'setOneofInt64',
|
||||
'setOneofUint64',
|
||||
'setOneofSint64',
|
||||
'setOneofFixed64',
|
||||
'setOneofSfixed64',
|
||||
],
|
||||
'@param int|string $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getOptionalInt32',
|
||||
'getOptionalUint32',
|
||||
'getOptionalSint32',
|
||||
'getOptionalFixed32',
|
||||
'getOptionalSfixed32',
|
||||
'getOneofInt32',
|
||||
'getOneofUint32',
|
||||
'getOneofSint32',
|
||||
'getOneofFixed32',
|
||||
'getOneofSfixed32',
|
||||
'getOptionalEnum',
|
||||
'getOptionalNoNamespaceEnum',
|
||||
'getOptionalNestedEnum',
|
||||
'getOneofEnum',
|
||||
],
|
||||
'@return int'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalInt64',
|
||||
'setOptionalUint64',
|
||||
'setOptionalSint64',
|
||||
'setOptionalFixed64',
|
||||
'setOptionalSfixed64',
|
||||
'setOneofInt64',
|
||||
'setOneofUint64',
|
||||
'setOneofSint64',
|
||||
'setOneofFixed64',
|
||||
'setOneofSfixed64',
|
||||
],
|
||||
'@param int|string $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getRepeatedInt32',
|
||||
'getRepeatedInt64',
|
||||
'getRepeatedUint32',
|
||||
'getRepeatedUint64',
|
||||
'getRepeatedSint32',
|
||||
'getRepeatedSint64',
|
||||
'getRepeatedFixed32',
|
||||
'getRepeatedFixed64',
|
||||
'getRepeatedSfixed32',
|
||||
'getRepeatedSfixed64',
|
||||
'getRepeatedFloat',
|
||||
'getRepeatedDouble',
|
||||
'getRepeatedBool',
|
||||
'getRepeatedString',
|
||||
'getRepeatedBytes',
|
||||
'getRepeatedEnum',
|
||||
'getRepeatedMessage',
|
||||
'getRepeatedRecursive',
|
||||
'getRepeatedNoNamespaceMessage',
|
||||
'getRepeatedNoNamespaceEnum',
|
||||
],
|
||||
'@return \Google\Protobuf\Internal\RepeatedField'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getMapInt32Int32',
|
||||
'getMapInt64Int64',
|
||||
'getMapUint32Uint32',
|
||||
'getMapUint64Uint64',
|
||||
'getMapSint32Sint32',
|
||||
'getMapSint64Sint64',
|
||||
'getMapFixed32Fixed32',
|
||||
'getMapFixed64Fixed64',
|
||||
'getMapSfixed32Sfixed32',
|
||||
'getMapSfixed64Sfixed64',
|
||||
'getMapInt32Float',
|
||||
'getMapInt32Double',
|
||||
'getMapBoolBool',
|
||||
'getMapStringString',
|
||||
'getMapInt32Bytes',
|
||||
'getMapInt32Enum',
|
||||
'getMapInt32Message',
|
||||
'getMapRecursive',
|
||||
],
|
||||
'@return \Google\Protobuf\Internal\MapField'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedInt32',
|
||||
'setRepeatedUint32',
|
||||
'setRepeatedSint32',
|
||||
'setRepeatedFixed32',
|
||||
'setRepeatedSfixed32',
|
||||
'setRepeatedEnum',
|
||||
'setRepeatedNoNamespaceEnum',
|
||||
],
|
||||
'@param int[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedInt64',
|
||||
'setRepeatedUint64',
|
||||
'setRepeatedSint64',
|
||||
'setRepeatedFixed64',
|
||||
'setRepeatedSfixed64',
|
||||
],
|
||||
'@param int[]|string[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedFloat',
|
||||
'setRepeatedDouble',
|
||||
],
|
||||
'@param float[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedBool',
|
||||
],
|
||||
'@param bool[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedString',
|
||||
'setRepeatedBytes',
|
||||
],
|
||||
'@param string[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedMessage',
|
||||
],
|
||||
'@param \Foo\TestMessage\Sub[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedRecursive',
|
||||
],
|
||||
'@param \Foo\TestMessage[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRepeatedNoNamespaceMessage',
|
||||
],
|
||||
'@param \NoNamespaceMessage[]|\Google\Protobuf\Internal\RepeatedField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setMapInt32Int32',
|
||||
'setMapInt64Int64',
|
||||
'setMapUint32Uint32',
|
||||
'setMapUint64Uint64',
|
||||
'setMapSint32Sint32',
|
||||
'setMapSint64Sint64',
|
||||
'setMapFixed32Fixed32',
|
||||
'setMapFixed64Fixed64',
|
||||
'setMapSfixed32Sfixed32',
|
||||
'setMapSfixed64Sfixed64',
|
||||
'setMapInt32Float',
|
||||
'setMapInt32Double',
|
||||
'setMapBoolBool',
|
||||
'setMapStringString',
|
||||
'setMapInt32Bytes',
|
||||
'setMapInt32Enum',
|
||||
'setMapInt32Message',
|
||||
'setMapRecursive',
|
||||
],
|
||||
'@param array|\Google\Protobuf\Internal\MapField $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getOptionalFloat',
|
||||
'getOptionalDouble',
|
||||
'getOneofDouble',
|
||||
'getOneofFloat',
|
||||
],
|
||||
'@return float'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalFloat',
|
||||
'setOptionalDouble',
|
||||
'setOneofDouble',
|
||||
'setOneofFloat',
|
||||
],
|
||||
'@param float $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getOptionalBool',
|
||||
'getOneofBool',
|
||||
],
|
||||
'@return bool'],
|
||||
[
|
||||
[
|
||||
'setOptionalBool',
|
||||
'setOneofBool',
|
||||
],
|
||||
'@param bool $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getOptionalString',
|
||||
'getOptionalBytes',
|
||||
'getOneofString',
|
||||
'getOneofBytes',
|
||||
'getMyOneof',
|
||||
],
|
||||
'@return string'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalString',
|
||||
'setOptionalBytes',
|
||||
'setOneofString',
|
||||
'setOneofBytes',
|
||||
],
|
||||
'@param string $var'
|
||||
],
|
||||
|
||||
[
|
||||
[
|
||||
'getOptionalMessage',
|
||||
'getOneofMessage'
|
||||
],
|
||||
'@return \Foo\TestMessage\Sub'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalMessage',
|
||||
'setOneofMessage'
|
||||
],
|
||||
'@param \Foo\TestMessage\Sub $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getOptionalIncludedMessage'
|
||||
],
|
||||
'@return \Bar\TestInclude'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalIncludedMessage'
|
||||
],
|
||||
'@param \Bar\TestInclude $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'getRecursive'
|
||||
],
|
||||
'@return \Foo\TestMessage'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setRecursive'
|
||||
],
|
||||
'@param \Foo\TestMessage $var'
|
||||
],
|
||||
|
||||
[
|
||||
[
|
||||
'getOptionalNoNamespaceMessage'
|
||||
],
|
||||
'@return \NoNamespaceMessage'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setOptionalNoNamespaceMessage'
|
||||
],
|
||||
'@param \NoNamespaceMessage $var'
|
||||
],
|
||||
[
|
||||
[
|
||||
'setDeprecatedOptionalInt32',
|
||||
'getDeprecatedOptionalInt32',
|
||||
],
|
||||
'@deprecated'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
127
deps/protobuf/php/tests/GeneratedServiceTest.php
vendored
Normal file
127
deps/protobuf/php/tests/GeneratedServiceTest.php
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\MapField;
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Foo\Greeter;
|
||||
use Foo\HelloRequest;
|
||||
use Foo\HelloReply;
|
||||
|
||||
class GeneratedServiceTest extends TestBase
|
||||
{
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $serviceClass;
|
||||
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $namespacedServiceClass;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $methodNames = [
|
||||
'sayHello',
|
||||
'sayHelloAgain'
|
||||
];
|
||||
|
||||
/**
|
||||
* Avoid calling setUp, which has void return type (not avalialbe in php7.0).
|
||||
*
|
||||
* @before
|
||||
*/
|
||||
public function setUpTest()
|
||||
{
|
||||
$this->serviceClass = new ReflectionClass('Foo\GreeterInterface');
|
||||
|
||||
$this->namespacedServiceClass = new ReflectionClass('Bar\OtherGreeterInterface');
|
||||
}
|
||||
|
||||
public function testIsInterface()
|
||||
{
|
||||
$this->assertTrue($this->serviceClass->isInterface());
|
||||
}
|
||||
|
||||
public function testPhpDocForClass()
|
||||
{
|
||||
$this->assertStringContains(
|
||||
'foo.Greeter', $this->serviceClass->getDocComment());
|
||||
}
|
||||
|
||||
public function testPhpDocForNamespacedClass()
|
||||
{
|
||||
$this->assertStringContains(
|
||||
'foo.OtherGreeter', $this->namespacedServiceClass->getDocComment());
|
||||
}
|
||||
|
||||
public function testServiceMethodsAreGenerated()
|
||||
{
|
||||
$this->assertCount(
|
||||
count($this->methodNames), $this->serviceClass->getMethods());
|
||||
foreach ($this->methodNames as $methodName) {
|
||||
$this->assertTrue($this->serviceClass->hasMethod($methodName));
|
||||
}
|
||||
}
|
||||
|
||||
public function testPhpDocForServiceMethod()
|
||||
{
|
||||
foreach ($this->methodNames as $methodName) {
|
||||
$docComment =
|
||||
$this->serviceClass->getMethod($methodName)->getDocComment();
|
||||
$this->assertStringContains($methodName, $docComment);
|
||||
$this->assertStringContains(
|
||||
'@param \Foo\HelloRequest $request', $docComment);
|
||||
$this->assertStringContains(
|
||||
'@return \Foo\HelloReply', $docComment);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPhpDocForServiceMethodInNamespacedClass()
|
||||
{
|
||||
foreach ($this->methodNames as $methodName) {
|
||||
$docComment =
|
||||
$this->namespacedServiceClass->getMethod(
|
||||
$methodName)->getDocComment();
|
||||
$this->assertStringContains($methodName, $docComment);
|
||||
$this->assertStringContains(
|
||||
'@param \Foo\HelloRequest $request', $docComment);
|
||||
$this->assertStringContains(
|
||||
'@return \Foo\HelloReply', $docComment);
|
||||
}
|
||||
}
|
||||
|
||||
public function testParamForServiceMethod()
|
||||
{
|
||||
foreach ($this->methodNames as $methodName) {
|
||||
$method = $this->serviceClass->getMethod($methodName);
|
||||
$this->assertCount(1, $method->getParameters());
|
||||
$param = $method->getParameters()[0];
|
||||
$this->assertFalse($param->isOptional());
|
||||
$this->assertSame('request', $param->getName());
|
||||
// ReflectionParameter::getType only exists in PHP 7+, so get the
|
||||
// type from __toString
|
||||
$this->assertStringContains(
|
||||
'Foo\HelloRequest $request', (string) $param);
|
||||
}
|
||||
}
|
||||
|
||||
public function testParamForServiceMethodInNamespacedClass()
|
||||
{
|
||||
foreach ($this->methodNames as $methodName) {
|
||||
$method = $this->serviceClass->getMethod($methodName);
|
||||
$this->assertCount(1, $method->getParameters());
|
||||
$param = $method->getParameters()[0];
|
||||
$this->assertFalse($param->isOptional());
|
||||
$this->assertSame('request', $param->getName());
|
||||
// ReflectionParameter::getType only exists in PHP 7+, so get the
|
||||
// type from __toString
|
||||
$this->assertStringContains(
|
||||
'Foo\HelloRequest $request', (string) $param);
|
||||
}
|
||||
}
|
||||
}
|
555
deps/protobuf/php/tests/MapFieldTest.php
vendored
Normal file
555
deps/protobuf/php/tests/MapFieldTest.php
vendored
Normal file
@ -0,0 +1,555 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\MapField;
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestMessage\Sub;
|
||||
|
||||
class MapFieldTest extends TestBase {
|
||||
|
||||
#########################################################
|
||||
# Test int32 field.
|
||||
#########################################################
|
||||
|
||||
public function testInt32() {
|
||||
$arr = new MapField(GPBType::INT32, GPBType::INT32);
|
||||
|
||||
// Test integer argument.
|
||||
$arr[MAX_INT32] = MAX_INT32;
|
||||
$this->assertSame(MAX_INT32, $arr[MAX_INT32]);
|
||||
$arr[MIN_INT32] = MIN_INT32;
|
||||
$this->assertSame(MIN_INT32, $arr[MIN_INT32]);
|
||||
$this->assertEquals(2, count($arr));
|
||||
$this->assertTrue(isset($arr[MAX_INT32]));
|
||||
$this->assertTrue(isset($arr[MIN_INT32]));
|
||||
unset($arr[MAX_INT32]);
|
||||
unset($arr[MIN_INT32]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test float argument.
|
||||
$arr[1.9] = 1.9;
|
||||
$arr[2.1] = 2.1;
|
||||
$this->assertSame(1, $arr[1]);
|
||||
$this->assertSame(2, $arr[2]);
|
||||
$arr[MAX_INT32_FLOAT] = MAX_INT32_FLOAT;
|
||||
$this->assertSame(MAX_INT32, $arr[MAX_INT32]);
|
||||
$arr[MIN_INT32_FLOAT] = MIN_INT32_FLOAT;
|
||||
$this->assertSame(MIN_INT32, $arr[MIN_INT32]);
|
||||
$this->assertEquals(4, count($arr));
|
||||
unset($arr[1.9]);
|
||||
unset($arr[2.9]);
|
||||
unset($arr[MAX_INT32_FLOAT]);
|
||||
unset($arr[MIN_INT32_FLOAT]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test string argument.
|
||||
$arr['2'] = '2';
|
||||
$this->assertSame(2, $arr[2]);
|
||||
$arr['3.1'] = '3.1';
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$arr[MAX_INT32_STRING] = MAX_INT32_STRING;
|
||||
$this->assertSame(MAX_INT32, $arr[MAX_INT32]);
|
||||
$this->assertEquals(3, count($arr));
|
||||
unset($arr['2']);
|
||||
unset($arr['3.1']);
|
||||
unset($arr[MAX_INT32_STRING]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test foreach.
|
||||
$arr = new MapField(GPBType::INT32, GPBType::INT32);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$arr[$i] = $i;
|
||||
}
|
||||
$i = 0;
|
||||
$arr_test = [];
|
||||
foreach ($arr as $key => $val) {
|
||||
$this->assertSame($key, $val);
|
||||
$arr_test[] = $key;
|
||||
$i++;
|
||||
}
|
||||
$this->assertTrue(isset($arr_test[0]));
|
||||
$this->assertTrue(isset($arr_test[1]));
|
||||
$this->assertTrue(isset($arr_test[2]));
|
||||
$this->assertSame(3, $i);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test uint32 field.
|
||||
#########################################################
|
||||
|
||||
public function testUint32() {
|
||||
$arr = new MapField(GPBType::UINT32, GPBType::UINT32);
|
||||
|
||||
// Test integer argument.
|
||||
$arr[MAX_UINT32] = MAX_UINT32;
|
||||
$this->assertSame(-1, $arr[-1]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[MAX_UINT32]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[-1] = -1;
|
||||
$this->assertSame(-1, $arr[-1]);
|
||||
$arr[MIN_UINT32] = MIN_UINT32;
|
||||
$this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
|
||||
$this->assertEquals(2, count($arr));
|
||||
unset($arr[-1]);
|
||||
unset($arr[MIN_UINT32]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test float argument.
|
||||
$arr[MAX_UINT32_FLOAT] = MAX_UINT32_FLOAT;
|
||||
$this->assertSame(-1, $arr[-1]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[MAX_UINT32_FLOAT]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[3.1] = 3.1;
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$arr[-1.0] = -1.0;
|
||||
$this->assertSame(-1, $arr[-1]);
|
||||
$arr[MIN_UINT32_FLOAT] = MIN_UINT32_FLOAT;
|
||||
$this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
|
||||
$this->assertEquals(3, count($arr));
|
||||
unset($arr[3.1]);
|
||||
unset($arr[-1.0]);
|
||||
unset($arr[MIN_UINT32_FLOAT]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test string argument.
|
||||
$arr[MAX_UINT32_STRING] = MAX_UINT32_STRING;
|
||||
$this->assertSame(-1, $arr[-1]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[MAX_UINT32_STRING]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr['7'] = '7';
|
||||
$this->assertSame(7, $arr[7]);
|
||||
$arr['3.1'] = '3.1';
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$arr['-1.0'] = '-1.0';
|
||||
$this->assertSame(-1, $arr[-1]);
|
||||
$arr[MIN_UINT32_STRING] = MIN_UINT32_STRING;
|
||||
$this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
|
||||
$this->assertEquals(4, count($arr));
|
||||
unset($arr['7']);
|
||||
unset($arr['3.1']);
|
||||
unset($arr['-1.0']);
|
||||
unset($arr[MIN_UINT32_STRING]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test int64 field.
|
||||
#########################################################
|
||||
|
||||
public function testInt64() {
|
||||
$arr = new MapField(GPBType::INT64, GPBType::INT64);
|
||||
|
||||
// Test integer argument.
|
||||
$arr[MAX_INT64] = MAX_INT64;
|
||||
$arr[MIN_INT64] = MIN_INT64;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]);
|
||||
$this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]);
|
||||
} else {
|
||||
$this->assertSame(MAX_INT64, $arr[MAX_INT64]);
|
||||
$this->assertSame(MIN_INT64, $arr[MIN_INT64]);
|
||||
}
|
||||
$this->assertEquals(2, count($arr));
|
||||
unset($arr[MAX_INT64]);
|
||||
unset($arr[MIN_INT64]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test float argument.
|
||||
$arr[1.1] = 1.1;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('1', $arr['1']);
|
||||
} else {
|
||||
$this->assertSame(1, $arr[1]);
|
||||
}
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[1.1]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test string argument.
|
||||
$arr['2'] = '2';
|
||||
$arr['3.1'] = '3.1';
|
||||
$arr[MAX_INT64_STRING] = MAX_INT64_STRING;
|
||||
$arr[MIN_INT64_STRING] = MIN_INT64_STRING;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('2', $arr['2']);
|
||||
$this->assertSame('3', $arr['3']);
|
||||
$this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]);
|
||||
$this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]);
|
||||
} else {
|
||||
$this->assertSame(2, $arr[2]);
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$this->assertSame(MAX_INT64, $arr[MAX_INT64]);
|
||||
$this->assertSame(MIN_INT64, $arr[MIN_INT64]);
|
||||
}
|
||||
$this->assertEquals(4, count($arr));
|
||||
unset($arr['2']);
|
||||
unset($arr['3.1']);
|
||||
unset($arr[MAX_INT64_STRING]);
|
||||
unset($arr[MIN_INT64_STRING]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test uint64 field.
|
||||
#########################################################
|
||||
|
||||
public function testUint64() {
|
||||
$arr = new MapField(GPBType::UINT64, GPBType::UINT64);
|
||||
|
||||
// Test integer argument.
|
||||
$arr[MAX_UINT64] = MAX_UINT64;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]);
|
||||
} else {
|
||||
$this->assertSame(MAX_UINT64, $arr[MAX_UINT64]);
|
||||
}
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[MAX_UINT64]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test float argument.
|
||||
$arr[1.1] = 1.1;
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('1', $arr['1']);
|
||||
} else {
|
||||
$this->assertSame(1, $arr[1]);
|
||||
}
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[1.1]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test string argument.
|
||||
$arr['2'] = '2';
|
||||
$arr['3.1'] = '3.1';
|
||||
$arr[MAX_UINT64_STRING] = MAX_UINT64_STRING;
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('2', $arr['2']);
|
||||
$this->assertSame('3', $arr['3']);
|
||||
$this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]);
|
||||
} else {
|
||||
$this->assertSame(2, $arr[2]);
|
||||
$this->assertSame(3, $arr[3]);
|
||||
$this->assertSame(MAX_UINT64, $arr[MAX_UINT64]);
|
||||
}
|
||||
|
||||
$this->assertEquals(3, count($arr));
|
||||
unset($arr['2']);
|
||||
unset($arr['3.1']);
|
||||
unset($arr[MAX_UINT64_STRING]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test float field.
|
||||
#########################################################
|
||||
|
||||
public function testFloat() {
|
||||
$arr = new MapField(GPBType::INT32, GPBType::FLOAT);
|
||||
|
||||
// Test set.
|
||||
$arr[0] = 1;
|
||||
$this->assertFloatEquals(1.0, $arr[0], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[1] = 1.1;
|
||||
$this->assertFloatEquals(1.1, $arr[1], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[2] = '2';
|
||||
$this->assertFloatEquals(2.0, $arr[2], MAX_FLOAT_DIFF);
|
||||
$arr[3] = '3.1';
|
||||
$this->assertFloatEquals(3.1, $arr[3], MAX_FLOAT_DIFF);
|
||||
|
||||
$this->assertEquals(4, count($arr));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test double field.
|
||||
#########################################################
|
||||
|
||||
public function testDouble() {
|
||||
$arr = new MapField(GPBType::INT32, GPBType::DOUBLE);
|
||||
|
||||
// Test set.
|
||||
$arr[0] = 1;
|
||||
$this->assertFloatEquals(1.0, $arr[0], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[1] = 1.1;
|
||||
$this->assertFloatEquals(1.1, $arr[1], MAX_FLOAT_DIFF);
|
||||
|
||||
$arr[2] = '2';
|
||||
$this->assertFloatEquals(2.0, $arr[2], MAX_FLOAT_DIFF);
|
||||
$arr[3] = '3.1';
|
||||
$this->assertFloatEquals(3.1, $arr[3], MAX_FLOAT_DIFF);
|
||||
|
||||
$this->assertEquals(4, count($arr));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test bool field.
|
||||
#########################################################
|
||||
|
||||
public function testBool() {
|
||||
$arr = new MapField(GPBType::BOOL, GPBType::BOOL);
|
||||
|
||||
// Test boolean.
|
||||
$arr[True] = True;
|
||||
$this->assertSame(True, $arr[True]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[True]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[False] = False;
|
||||
$this->assertSame(False, $arr[False]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[False]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test integer.
|
||||
$arr[-1] = -1;
|
||||
$this->assertSame(True, $arr[True]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[-1]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[0] = 0;
|
||||
$this->assertSame(False, $arr[False]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[0]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test float.
|
||||
$arr[1.1] = 1.1;
|
||||
$this->assertSame(True, $arr[True]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[1.1]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[0.0] = 0.0;
|
||||
$this->assertSame(False, $arr[False]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[0.0]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test string.
|
||||
$arr['a'] = 'a';
|
||||
$this->assertSame(True, $arr[True]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr['a']);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[''] = '';
|
||||
$this->assertSame(False, $arr[False]);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr['']);
|
||||
$this->assertEquals(0, count($arr));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test string field.
|
||||
#########################################################
|
||||
|
||||
public function testString() {
|
||||
$arr = new MapField(GPBType::STRING, GPBType::STRING);
|
||||
|
||||
// Test set.
|
||||
$arr['abc'] = 'abc';
|
||||
$this->assertSame('abc', $arr['abc']);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr['abc']);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[1] = 1;
|
||||
$this->assertSame('1', $arr['1']);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[1]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[1.1] = 1.1;
|
||||
$this->assertSame('1.1', $arr['1.1']);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[1.1]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
$arr[True] = True;
|
||||
$this->assertSame('1', $arr['1']);
|
||||
$this->assertEquals(1, count($arr));
|
||||
unset($arr[True]);
|
||||
$this->assertEquals(0, count($arr));
|
||||
|
||||
// Test foreach.
|
||||
$arr = new MapField(GPBType::STRING, GPBType::STRING);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$arr[$i] = $i;
|
||||
}
|
||||
$i = 0;
|
||||
$arr_test = [];
|
||||
foreach ($arr as $key => $val) {
|
||||
$this->assertSame($key, $val);
|
||||
$arr_test[] = $key;
|
||||
$i++;
|
||||
}
|
||||
$this->assertTrue(isset($arr_test['0']));
|
||||
$this->assertTrue(isset($arr_test['1']));
|
||||
$this->assertTrue(isset($arr_test['2']));
|
||||
$this->assertSame(3, $i);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test message field.
|
||||
#########################################################
|
||||
|
||||
public function testMessage() {
|
||||
$arr = new MapField(GPBType::INT32,
|
||||
GPBType::MESSAGE, Sub::class);
|
||||
|
||||
// Test append.
|
||||
$sub_m = new Sub();
|
||||
$sub_m->setA(1);
|
||||
$arr[0] = $sub_m;
|
||||
$this->assertSame(1, $arr[0]->getA());
|
||||
|
||||
$this->assertEquals(1, count($arr));
|
||||
|
||||
// Test foreach.
|
||||
$arr = new MapField(GPBType::INT32,
|
||||
GPBType::MESSAGE, Sub::class);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$arr[$i] = new Sub();;
|
||||
$arr[$i]->setA($i);
|
||||
}
|
||||
$i = 0;
|
||||
$key_test = [];
|
||||
$value_test = [];
|
||||
foreach ($arr as $key => $val) {
|
||||
$key_test[] = $key;
|
||||
$value_test[] = $val->getA();
|
||||
$i++;
|
||||
}
|
||||
$this->assertTrue(isset($key_test['0']));
|
||||
$this->assertTrue(isset($key_test['1']));
|
||||
$this->assertTrue(isset($key_test['2']));
|
||||
$this->assertTrue(isset($value_test['0']));
|
||||
$this->assertTrue(isset($value_test['1']));
|
||||
$this->assertTrue(isset($value_test['2']));
|
||||
$this->assertSame(3, $i);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test reference in map
|
||||
#########################################################
|
||||
|
||||
public function testMapElementIsReference()
|
||||
{
|
||||
// Bool elements
|
||||
$values = [true => true];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setMapBoolBool($values);
|
||||
|
||||
// Int32 elements
|
||||
$values = [1 => 1];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setMapInt32Int32($values);
|
||||
|
||||
// Double elements
|
||||
$values = [1 => 1.0];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setMapInt32Double($values);
|
||||
|
||||
// String elements
|
||||
$values = ['a' => 'a'];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setMapStringString($values);
|
||||
|
||||
// Message elements
|
||||
$values = [1 => new Sub()];
|
||||
array_walk($values, function (&$value) {});
|
||||
$m = new TestMessage();
|
||||
$m->setMapInt32Message($values);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test equality
|
||||
#########################################################
|
||||
|
||||
public function testEquality()
|
||||
{
|
||||
$map = new MapField(GPBType::INT32, GPBType::INT32);
|
||||
$map2 = new MapField(GPBType::INT32, GPBType::INT32);
|
||||
|
||||
$this->assertTrue($map == $map2);
|
||||
|
||||
$map[1] = 2;
|
||||
|
||||
$this->assertFalse($map == $map2);
|
||||
|
||||
$map2[1] = 2;
|
||||
|
||||
$this->assertTrue($map == $map2);
|
||||
|
||||
// Arrays of different types always compare false.
|
||||
$this->assertFalse(new MapField(GPBType::INT32, GPBType::INT32) ==
|
||||
new MapField(GPBType::INT32, GPBType::INT64));
|
||||
$this->assertFalse(new MapField(GPBType::INT32, GPBType::INT32) ==
|
||||
new MapField(GPBType::INT64, GPBType::INT32));
|
||||
$this->assertFalse(
|
||||
new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class) ==
|
||||
new MapField(GPBType::INT32, GPBType::MESSAGE, Sub::class));
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test clone
|
||||
#########################################################
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$map = new MapField(GPBType::INT32,
|
||||
GPBType::MESSAGE, Sub::class);
|
||||
|
||||
// Test append.
|
||||
$sub_m = new Sub();
|
||||
$sub_m->setA(1);
|
||||
$map[0] = $sub_m;
|
||||
|
||||
$map2 = clone $map;
|
||||
$this->assertSame($map[0], $map2[0]);
|
||||
}
|
||||
|
||||
#########################################################
|
||||
# Test memory leak
|
||||
#########################################################
|
||||
|
||||
// TODO(teboring): Add it back.
|
||||
// public function testCycleLeak()
|
||||
// {
|
||||
// $arr = new MapField(GPBType::INT32,
|
||||
// GPBType::MESSAGE, TestMessage::class);
|
||||
// $arr[0] = new TestMessage;
|
||||
// $arr[0]->SetMapRecursive($arr);
|
||||
|
||||
// // Clean up memory before test.
|
||||
// gc_collect_cycles();
|
||||
// $start = memory_get_usage();
|
||||
// unset($arr);
|
||||
|
||||
// // Explicitly trigger garbage collection.
|
||||
// gc_collect_cycles();
|
||||
|
||||
// $end = memory_get_usage();
|
||||
// $this->assertLessThan($start, $end);
|
||||
// }
|
||||
}
|
605
deps/protobuf/php/tests/PhpImplementationTest.php
vendored
Normal file
605
deps/protobuf/php/tests/PhpImplementationTest.php
vendored
Normal file
@ -0,0 +1,605 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Foo\TestEnum;
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestMessage\Sub;
|
||||
use Foo\TestPackedMessage;
|
||||
use Google\Protobuf\Internal\CodedInputStream;
|
||||
use Google\Protobuf\Internal\FileDescriptorSet;
|
||||
use Google\Protobuf\Internal\GPBLabel;
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Google\Protobuf\Internal\GPBWire;
|
||||
use Google\Protobuf\Internal\CodedOutputStream;
|
||||
|
||||
/**
|
||||
* Please note, this test is only intended to be run without the protobuf C
|
||||
* extension.
|
||||
*/
|
||||
class PhpImplementationTest extends TestBase
|
||||
{
|
||||
/**
|
||||
* Avoid calling setUp, which has void return type (not avalialbe in php7.0).
|
||||
* @before
|
||||
*/
|
||||
public function skipTestsForExtension()
|
||||
{
|
||||
if (extension_loaded('protobuf')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
}
|
||||
|
||||
public function testReadInt32()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
// Positive number.
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readInt32($input, $value);
|
||||
$this->assertSame(1, $value);
|
||||
|
||||
// Negative number.
|
||||
$input = new CodedInputStream(hex2bin("ffffffff0f"));
|
||||
GPBWire::readInt32($input, $value);
|
||||
$this->assertSame(-1, $value);
|
||||
|
||||
// Discard overflow bits.
|
||||
$input = new CodedInputStream(hex2bin("ffffffff7f"));
|
||||
GPBWire::readInt32($input, $value);
|
||||
$this->assertSame(-1, $value);
|
||||
}
|
||||
|
||||
public function testReadUint32()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
// Positive number.
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readUint32($input, $value);
|
||||
$this->assertSame(1, $value);
|
||||
|
||||
// Max uint32.
|
||||
$input = new CodedInputStream(hex2bin("ffffffff0f"));
|
||||
GPBWire::readUint32($input, $value);
|
||||
$this->assertSame(-1, $value);
|
||||
|
||||
// Discard overflow bits.
|
||||
$input = new CodedInputStream(hex2bin("ffffffff7f"));
|
||||
GPBWire::readUint32($input, $value);
|
||||
$this->assertSame(-1, $value);
|
||||
}
|
||||
|
||||
public function testReadInt64()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
// Positive number.
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readInt64($input, $value);
|
||||
$this->assertEquals(1, $value);
|
||||
|
||||
// Negative number.
|
||||
$input = new CodedInputStream(hex2bin("ffffffffffffffffff01"));
|
||||
GPBWire::readInt64($input, $value);
|
||||
$this->assertEquals(-1, $value);
|
||||
|
||||
// Discard overflow bits.
|
||||
$input = new CodedInputStream(hex2bin("ffffffffffffffffff0f"));
|
||||
GPBWire::readInt64($input, $value);
|
||||
$this->assertEquals(-1, $value);
|
||||
}
|
||||
|
||||
public function testReadUint64()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
// Positive number.
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readUint64($input, $value);
|
||||
$this->assertEquals(1, $value);
|
||||
|
||||
// Negative number.
|
||||
$input = new CodedInputStream(hex2bin("FFFFFFFFFFFFFFFFFF01"));
|
||||
GPBWire::readUint64($input, $value);
|
||||
$this->assertEquals(-1, $value);
|
||||
|
||||
// Discard overflow bits.
|
||||
$input = new CodedInputStream(hex2bin("FFFFFFFFFFFFFFFFFF0F"));
|
||||
GPBWire::readUint64($input, $value);
|
||||
$this->assertEquals(-1, $value);
|
||||
}
|
||||
|
||||
public function testReadSint32()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
$input = new CodedInputStream(hex2bin("00"));
|
||||
GPBWire::readSint32($input, $value);
|
||||
$this->assertSame(0, $value);
|
||||
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readSint32($input, $value);
|
||||
$this->assertSame(-1, $value);
|
||||
|
||||
$input = new CodedInputStream(hex2bin("02"));
|
||||
GPBWire::readSint32($input, $value);
|
||||
$this->assertSame(1, $value);
|
||||
}
|
||||
|
||||
public function testReadSint64()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
$input = new CodedInputStream(hex2bin("00"));
|
||||
GPBWire::readSint64($input, $value);
|
||||
$this->assertEquals(0, $value);
|
||||
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readSint64($input, $value);
|
||||
$this->assertEquals(-1, $value);
|
||||
|
||||
$input = new CodedInputStream(hex2bin("02"));
|
||||
GPBWire::readSint64($input, $value);
|
||||
$this->assertEquals(1, $value);
|
||||
}
|
||||
|
||||
public function testReadFixed32()
|
||||
{
|
||||
$value = null;
|
||||
$input = new CodedInputStream(hex2bin("12345678"));
|
||||
GPBWire::readFixed32($input, $value);
|
||||
$this->assertSame(0x78563412, $value);
|
||||
}
|
||||
|
||||
public function testReadFixed64()
|
||||
{
|
||||
$value = null;
|
||||
$input = new CodedInputStream(hex2bin("1234567812345678"));
|
||||
GPBWire::readFixed64($input, $value);
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame("8671175386481439762", $value);
|
||||
} else {
|
||||
$this->assertSame(0x7856341278563412, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReadSfixed32()
|
||||
{
|
||||
$value = null;
|
||||
$input = new CodedInputStream(hex2bin("12345678"));
|
||||
GPBWire::readSfixed32($input, $value);
|
||||
$this->assertSame(0x78563412, $value);
|
||||
}
|
||||
|
||||
public function testReadFloat()
|
||||
{
|
||||
$value = null;
|
||||
$input = new CodedInputStream(hex2bin("0000803F"));
|
||||
GPBWire::readFloat($input, $value);
|
||||
$this->assertSame(1.0, $value);
|
||||
}
|
||||
|
||||
public function testReadBool()
|
||||
{
|
||||
$value = null;
|
||||
|
||||
$input = new CodedInputStream(hex2bin("00"));
|
||||
GPBWire::readBool($input, $value);
|
||||
$this->assertSame(false, $value);
|
||||
|
||||
$input = new CodedInputStream(hex2bin("01"));
|
||||
GPBWire::readBool($input, $value);
|
||||
$this->assertSame(true, $value);
|
||||
}
|
||||
|
||||
public function testReadDouble()
|
||||
{
|
||||
$value = null;
|
||||
$input = new CodedInputStream(hex2bin("000000000000F03F"));
|
||||
GPBWire::readDouble($input, $value);
|
||||
$this->assertSame(1.0, $value);
|
||||
}
|
||||
|
||||
public function testReadSfixed64()
|
||||
{
|
||||
$value = null;
|
||||
$input = new CodedInputStream(hex2bin("1234567812345678"));
|
||||
GPBWire::readSfixed64($input, $value);
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame("8671175386481439762", $value);
|
||||
} else {
|
||||
$this->assertSame(0x7856341278563412, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function testZigZagEncodeDecode()
|
||||
{
|
||||
$this->assertSame(0, GPBWire::zigZagEncode32(0));
|
||||
$this->assertSame(1, GPBWire::zigZagEncode32(-1));
|
||||
$this->assertSame(2, GPBWire::zigZagEncode32(1));
|
||||
$this->assertSame(3, GPBWire::zigZagEncode32(-2));
|
||||
$this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode32(0x3FFFFFFF));
|
||||
$this->assertSame(0x7FFFFFFF, GPBWire::zigZagEncode32(0xC0000000));
|
||||
$this->assertSame(0x7FFFFFFF, GPBWire::zigZagEncode32(-1073741824));
|
||||
|
||||
$this->assertSame(0, GPBWire::zigZagDecode32(0));
|
||||
$this->assertSame(-1, GPBWire::zigZagDecode32(1));
|
||||
$this->assertSame(1, GPBWire::zigZagDecode32(2));
|
||||
$this->assertSame(-2, GPBWire::zigZagDecode32(3));
|
||||
$this->assertSame(0x3FFFFFFF, GPBWire::zigZagDecode32(0x7FFFFFFE));
|
||||
$this->assertSame(-1073741824, GPBWire::zigZagDecode32(0x7FFFFFFF));
|
||||
$this->assertSame(0x7FFFFFFF, GPBWire::zigZagDecode32(0xFFFFFFFE));
|
||||
$this->assertSame((int)-2147483648,GPBWire::zigZagDecode32(0xFFFFFFFF));
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame(-2, GPBWire::zigZagEncode32(0x7FFFFFFF));
|
||||
$this->assertSame(-1, GPBWire::zigZagEncode32(0x80000000));
|
||||
$this->assertSame('0', GPBWire::zigZagEncode64(0));
|
||||
$this->assertSame('1', GPBWire::zigZagEncode64(-1));
|
||||
$this->assertSame('2', GPBWire::zigZagEncode64(1));
|
||||
$this->assertSame('3', GPBWire::zigZagEncode64(-2));
|
||||
$this->assertSame(
|
||||
'2147483646', // 0x7FFFFFE
|
||||
GPBWire::zigZagEncode64(0x3FFFFFFF));
|
||||
$this->assertSame(
|
||||
'2147483647', // 0x7FFFFFF
|
||||
GPBWire::zigZagEncode64(-1073741824)); // 0xFFFFFFFFC0000000
|
||||
$this->assertSame(
|
||||
'4294967294', // 0xFFFFFFFE
|
||||
GPBWire::zigZagEncode64(2147483647)); // 0x7FFFFFFF
|
||||
$this->assertSame(
|
||||
'4294967295', // 0xFFFFFFFF
|
||||
GPBWire::zigZagEncode64(-2147483648)); // 0xFFFFFFFF80000000
|
||||
$this->assertSame(
|
||||
'18446744073709551614', // 0xFFFFFFFFFFFFFFFE
|
||||
// 0x7FFFFFFFFFFFFFFF
|
||||
GPBWire::zigZagEncode64("9223372036854775807"));
|
||||
$this->assertSame(
|
||||
'18446744073709551615', // 0xFFFFFFFFFFFFFFFF
|
||||
// 0x8000000000000000
|
||||
GPBWire::zigZagEncode64("-9223372036854775808"));
|
||||
|
||||
$this->assertSame('0', GPBWire::zigZagDecode64(0));
|
||||
$this->assertSame('-1', GPBWire::zigZagDecode64(1));
|
||||
$this->assertSame('1', GPBWire::zigZagDecode64(2));
|
||||
$this->assertSame('-2', GPBWire::zigZagDecode64(3));
|
||||
} else {
|
||||
$this->assertSame(4294967294, GPBWire::zigZagEncode32(0x7FFFFFFF));
|
||||
$this->assertSame(4294967295, GPBWire::zigZagEncode32(0x80000000));
|
||||
$this->assertSame(0, GPBWire::zigZagEncode64(0));
|
||||
$this->assertSame(1, GPBWire::zigZagEncode64(-1));
|
||||
$this->assertSame(2, GPBWire::zigZagEncode64(1));
|
||||
$this->assertSame(3, GPBWire::zigZagEncode64(-2));
|
||||
$this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode64(0x3FFFFFFF));
|
||||
$this->assertSame(
|
||||
0x7FFFFFFF,
|
||||
GPBWire::zigZagEncode64(0xFFFFFFFFC0000000));
|
||||
$this->assertSame(
|
||||
0xFFFFFFFE,
|
||||
GPBWire::zigZagEncode64(0x7FFFFFFF));
|
||||
$this->assertSame(
|
||||
0xFFFFFFFF,
|
||||
GPBWire::zigZagEncode64(0xFFFFFFFF80000000));
|
||||
$this->assertSame(
|
||||
-2, // 0xFFFFFFFFFFFFFFFE
|
||||
GPBWire::zigZagEncode64(0x7FFFFFFFFFFFFFFF));
|
||||
$this->assertSame(
|
||||
-1, // 0xFFFFFFFFFFFFFFFF
|
||||
GPBWire::zigZagEncode64(0x8000000000000000));
|
||||
|
||||
$this->assertSame(0, GPBWire::zigZagDecode64(0));
|
||||
$this->assertSame(-1, GPBWire::zigZagDecode64(1));
|
||||
$this->assertSame(1, GPBWire::zigZagDecode64(2));
|
||||
$this->assertSame(-2, GPBWire::zigZagDecode64(3));
|
||||
}
|
||||
|
||||
// Round trip
|
||||
$this->assertSame(0, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(0)));
|
||||
$this->assertSame(1, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(1)));
|
||||
$this->assertSame(-1, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(-1)));
|
||||
$this->assertSame(14927,
|
||||
GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(14927)));
|
||||
$this->assertSame(-3612,
|
||||
GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(-3612)));
|
||||
}
|
||||
|
||||
public function testDecode()
|
||||
{
|
||||
$m = new TestMessage();
|
||||
$m->mergeFromString(TestUtil::getGoldenTestMessage());
|
||||
TestUtil::assertTestMessage($m);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testDescriptorDecode()
|
||||
{
|
||||
$file_desc_set = new FileDescriptorSet();
|
||||
$file_desc_set->mergeFromString(hex2bin(
|
||||
"0a3b0a12746573745f696e636c7564652e70726f746f120362617222180a" .
|
||||
"0b54657374496e636c75646512090a0161180120012805620670726f746f33"));
|
||||
|
||||
$this->assertSame(1, sizeof($file_desc_set->getFile()));
|
||||
|
||||
$file_desc = $file_desc_set->getFile()[0];
|
||||
$this->assertSame("test_include.proto", $file_desc->getName());
|
||||
$this->assertSame("bar", $file_desc->getPackage());
|
||||
$this->assertSame(0, sizeof($file_desc->getDependency()));
|
||||
$this->assertSame(1, sizeof($file_desc->getMessageType()));
|
||||
$this->assertSame(0, sizeof($file_desc->getEnumType()));
|
||||
$this->assertSame("proto3", $file_desc->getSyntax());
|
||||
|
||||
$desc = $file_desc->getMessageType()[0];
|
||||
$this->assertSame("TestInclude", $desc->getName());
|
||||
$this->assertSame(1, sizeof($desc->getField()));
|
||||
$this->assertSame(0, sizeof($desc->getNestedType()));
|
||||
$this->assertSame(0, sizeof($desc->getEnumType()));
|
||||
$this->assertSame(0, sizeof($desc->getOneofDecl()));
|
||||
|
||||
$field = $desc->getField()[0];
|
||||
$this->assertSame("a", $field->getName());
|
||||
$this->assertSame(1, $field->getNumber());
|
||||
$this->assertSame(GPBLabel::OPTIONAL, $field->getLabel());
|
||||
$this->assertSame(GPBType::INT32, $field->getType());
|
||||
}
|
||||
|
||||
public function testReadVarint64()
|
||||
{
|
||||
$var = 0;
|
||||
|
||||
// Empty buffer.
|
||||
$input = new CodedInputStream(hex2bin(''));
|
||||
$this->assertFalse($input->readVarint64($var));
|
||||
|
||||
// The largest varint is 10 bytes long.
|
||||
$input = new CodedInputStream(hex2bin('8080808080808080808001'));
|
||||
$this->assertFalse($input->readVarint64($var));
|
||||
|
||||
// Corrupted varint.
|
||||
$input = new CodedInputStream(hex2bin('808080'));
|
||||
$this->assertFalse($input->readVarint64($var));
|
||||
|
||||
// Normal case.
|
||||
$input = new CodedInputStream(hex2bin('808001'));
|
||||
$this->assertTrue($input->readVarint64($var));
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('16384', $var);
|
||||
} else {
|
||||
$this->assertSame(16384, $var);
|
||||
}
|
||||
$this->assertFalse($input->readVarint64($var));
|
||||
|
||||
// Read two varint.
|
||||
$input = new CodedInputStream(hex2bin('808001808002'));
|
||||
$this->assertTrue($input->readVarint64($var));
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('16384', $var);
|
||||
} else {
|
||||
$this->assertSame(16384, $var);
|
||||
}
|
||||
$this->assertTrue($input->readVarint64($var));
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('32768', $var);
|
||||
} else {
|
||||
$this->assertSame(32768, $var);
|
||||
}
|
||||
$this->assertFalse($input->readVarint64($var));
|
||||
|
||||
// Read 64 testing
|
||||
$testVals = array(
|
||||
'10' => '0a000000000000000000',
|
||||
'100' => '64000000000000000000',
|
||||
'800' => 'a0060000000000000000',
|
||||
'6400' => '80320000000000000000',
|
||||
'70400' => '80a60400000000000000',
|
||||
'774400' => '80a22f00000000000000',
|
||||
'9292800' => '8098b704000000000000',
|
||||
'74342400' => '80c0b923000000000000',
|
||||
'743424000' => '8080bfe2020000000000',
|
||||
'8177664000' => '8080b5bb1e0000000000',
|
||||
'65421312000' => '8080a8dbf30100000000',
|
||||
'785055744000' => '8080e0c7ec1600000000',
|
||||
'9420668928000' => '808080dd969202000000',
|
||||
'103627358208000' => '808080fff9c717000000',
|
||||
'1139900940288000' => '808080f5bd9783020000',
|
||||
'13678811283456000' => '808080fce699a6180000',
|
||||
'109430490267648000' => '808080e0b7ceb1c20100',
|
||||
'984874412408832000' => '808080e0f5c1bed50d00',
|
||||
);
|
||||
|
||||
foreach ($testVals as $original => $encoded) {
|
||||
$input = new CodedInputStream(hex2bin($encoded));
|
||||
$this->assertTrue($input->readVarint64($var));
|
||||
$this->assertEquals($original, $var);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReadVarint32()
|
||||
{
|
||||
$var = 0;
|
||||
|
||||
// Empty buffer.
|
||||
$input = new CodedInputStream(hex2bin(''));
|
||||
$this->assertFalse($input->readVarint32($var));
|
||||
|
||||
// The largest varint is 10 bytes long.
|
||||
$input = new CodedInputStream(hex2bin('8080808080808080808001'));
|
||||
$this->assertFalse($input->readVarint32($var));
|
||||
|
||||
// Corrupted varint.
|
||||
$input = new CodedInputStream(hex2bin('808080'));
|
||||
$this->assertFalse($input->readVarint32($var));
|
||||
|
||||
// Normal case.
|
||||
$input = new CodedInputStream(hex2bin('808001'));
|
||||
$this->assertTrue($input->readVarint32($var));
|
||||
$this->assertSame(16384, $var);
|
||||
$this->assertFalse($input->readVarint32($var));
|
||||
|
||||
// Read two varint.
|
||||
$input = new CodedInputStream(hex2bin('808001808002'));
|
||||
$this->assertTrue($input->readVarint32($var));
|
||||
$this->assertSame(16384, $var);
|
||||
$this->assertTrue($input->readVarint32($var));
|
||||
$this->assertSame(32768, $var);
|
||||
$this->assertFalse($input->readVarint32($var));
|
||||
|
||||
// Read a 64-bit integer. High-order bits should be discarded.
|
||||
$input = new CodedInputStream(hex2bin('808081808001'));
|
||||
$this->assertTrue($input->readVarint32($var));
|
||||
$this->assertSame(16384, $var);
|
||||
$this->assertFalse($input->readVarint32($var));
|
||||
}
|
||||
|
||||
public function testReadTag()
|
||||
{
|
||||
$input = new CodedInputStream(hex2bin('808001'));
|
||||
$tag = $input->readTag();
|
||||
$this->assertSame(16384, $tag);
|
||||
$tag = $input->readTag();
|
||||
$this->assertSame(0, $tag);
|
||||
}
|
||||
|
||||
public function testPushPopLimit()
|
||||
{
|
||||
$input = new CodedInputStream(hex2bin('808001'));
|
||||
$old_limit = $input->pushLimit(0);
|
||||
$tag = $input->readTag();
|
||||
$this->assertSame(0, $tag);
|
||||
$input->popLimit($old_limit);
|
||||
$tag = $input->readTag();
|
||||
$this->assertSame(16384, $tag);
|
||||
}
|
||||
|
||||
public function testReadRaw()
|
||||
{
|
||||
$input = new CodedInputStream(hex2bin('808001'));
|
||||
$buffer = null;
|
||||
|
||||
$this->assertTrue($input->readRaw(3, $buffer));
|
||||
$this->assertSame(hex2bin('808001'), $buffer);
|
||||
|
||||
$this->assertFalse($input->readRaw(1, $buffer));
|
||||
}
|
||||
|
||||
public function testWriteVarint32()
|
||||
{
|
||||
$output = new CodedOutputStream(3);
|
||||
$output->writeVarint32(16384, true);
|
||||
$this->assertSame(hex2bin('808001'), $output->getData());
|
||||
|
||||
// Negative numbers are padded to be compatible with int64.
|
||||
$output = new CodedOutputStream(10);
|
||||
$output->writeVarint32(-43, false);
|
||||
$this->assertSame(hex2bin('D5FFFFFFFFFFFFFFFF01'), $output->getData());
|
||||
}
|
||||
|
||||
public function testWriteVarint64()
|
||||
{
|
||||
$output = new CodedOutputStream(10);
|
||||
$output->writeVarint64(-43);
|
||||
$this->assertSame(hex2bin('D5FFFFFFFFFFFFFFFF01'), $output->getData());
|
||||
}
|
||||
|
||||
public function testWriteLittleEndian32()
|
||||
{
|
||||
$output = new CodedOutputStream(4);
|
||||
$output->writeLittleEndian32(46);
|
||||
$this->assertSame(hex2bin('2E000000'), $output->getData());
|
||||
}
|
||||
|
||||
public function testWriteLittleEndian64()
|
||||
{
|
||||
$output = new CodedOutputStream(8);
|
||||
$output->writeLittleEndian64(47);
|
||||
$this->assertSame(hex2bin('2F00000000000000'), $output->getData());
|
||||
}
|
||||
|
||||
public function testByteSize()
|
||||
{
|
||||
$m = new TestMessage();
|
||||
TestUtil::setTestMessage($m);
|
||||
$this->assertSame(504, $m->byteSize());
|
||||
}
|
||||
|
||||
public function testPackedByteSize()
|
||||
{
|
||||
$m = new TestPackedMessage();
|
||||
TestUtil::setTestPackedMessage($m);
|
||||
$this->assertSame(166, $m->byteSize());
|
||||
}
|
||||
|
||||
public function testArrayConstructorJsonCaseThrowsException()
|
||||
{
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Invalid message property: optionalInt32');
|
||||
|
||||
$m = new TestMessage([
|
||||
'optionalInt32' => -42,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testArraysForMessagesThrowsException()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Expect Foo\TestMessage\Sub.');
|
||||
|
||||
$m = new TestMessage([
|
||||
'optional_message' => [
|
||||
'a' => 33
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testArrayConstructorWithNullValues()
|
||||
{
|
||||
$requestData = [
|
||||
'optional_bool' => null,
|
||||
'optional_string' => null,
|
||||
'optional_bytes' => null,
|
||||
'optional_message' => null,
|
||||
];
|
||||
|
||||
$m = new TestMessage($requestData);
|
||||
|
||||
$this->assertSame(false, $m->getOptionalBool());
|
||||
$this->assertSame('', $m->getOptionalString());
|
||||
$this->assertSame('', $m->getOptionalBytes());
|
||||
$this->assertSame(null, $m->getOptionalMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideArrayConstructorWithNullValuesThrowsException
|
||||
*/
|
||||
public function testArrayConstructorWithNullValuesThrowsException($requestData)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$m = new TestMessage($requestData);
|
||||
}
|
||||
|
||||
public function provideArrayConstructorWithNullValuesThrowsException()
|
||||
{
|
||||
return [
|
||||
[['optional_int32' => null]],
|
||||
[['optional_int64' => null]],
|
||||
[['optional_uint32' => null]],
|
||||
[['optional_uint64' => null]],
|
||||
[['optional_sint32' => null]],
|
||||
[['optional_sint64' => null]],
|
||||
[['optional_fixed32' => null]],
|
||||
[['optional_fixed64' => null]],
|
||||
[['optional_sfixed32' => null]],
|
||||
[['optional_sfixed64' => null]],
|
||||
[['optional_float' => null]],
|
||||
[['optional_double' => null]],
|
||||
[['optional_enum' => null]],
|
||||
[['repeated_int32' => null]],
|
||||
[['map_int32_int32' => null]],
|
||||
];
|
||||
}
|
||||
}
|
419
deps/protobuf/php/tests/WellKnownTest.php
vendored
Normal file
419
deps/protobuf/php/tests/WellKnownTest.php
vendored
Normal file
@ -0,0 +1,419 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestImportDescriptorProto;
|
||||
use Google\Protobuf\Any;
|
||||
use Google\Protobuf\Api;
|
||||
use Google\Protobuf\BoolValue;
|
||||
use Google\Protobuf\BytesValue;
|
||||
use Google\Protobuf\DoubleValue;
|
||||
use Google\Protobuf\Duration;
|
||||
use Google\Protobuf\Enum;
|
||||
use Google\Protobuf\EnumValue;
|
||||
use Google\Protobuf\Field;
|
||||
use Google\Protobuf\FieldMask;
|
||||
use Google\Protobuf\Field\Cardinality;
|
||||
use Google\Protobuf\Field\Kind;
|
||||
use Google\Protobuf\FloatValue;
|
||||
use Google\Protobuf\GPBEmpty;
|
||||
use Google\Protobuf\Int32Value;
|
||||
use Google\Protobuf\Int64Value;
|
||||
use Google\Protobuf\ListValue;
|
||||
use Google\Protobuf\Method;
|
||||
use Google\Protobuf\Mixin;
|
||||
use Google\Protobuf\NullValue;
|
||||
use Google\Protobuf\Option;
|
||||
use Google\Protobuf\SourceContext;
|
||||
use Google\Protobuf\StringValue;
|
||||
use Google\Protobuf\Struct;
|
||||
use Google\Protobuf\Syntax;
|
||||
use Google\Protobuf\Timestamp;
|
||||
use Google\Protobuf\Type;
|
||||
use Google\Protobuf\UInt32Value;
|
||||
use Google\Protobuf\UInt64Value;
|
||||
use Google\Protobuf\Value;
|
||||
|
||||
class NotMessage {}
|
||||
|
||||
class WellKnownTest extends TestBase {
|
||||
|
||||
public function testEmpty()
|
||||
{
|
||||
$msg = new GPBEmpty();
|
||||
$this->assertTrue($msg instanceof \Google\Protobuf\Internal\Message);
|
||||
}
|
||||
|
||||
public function testImportDescriptorProto()
|
||||
{
|
||||
$msg = new TestImportDescriptorProto();
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testAny()
|
||||
{
|
||||
// Create embed message
|
||||
$embed = new TestMessage();
|
||||
$this->setFields($embed);
|
||||
$data = $embed->serializeToString();
|
||||
|
||||
// Set any via normal setter.
|
||||
$any = new Any();
|
||||
|
||||
$this->assertSame(
|
||||
$any, $any->setTypeUrl("type.googleapis.com/foo.TestMessage"));
|
||||
$this->assertSame("type.googleapis.com/foo.TestMessage",
|
||||
$any->getTypeUrl());
|
||||
|
||||
$this->assertSame($any, $any->setValue($data));
|
||||
$this->assertSame($data, $any->getValue());
|
||||
|
||||
// Test unpack.
|
||||
$msg = $any->unpack();
|
||||
$this->assertTrue($msg instanceof TestMessage);
|
||||
$this->expectFields($msg);
|
||||
|
||||
// Test pack.
|
||||
$any = new Any();
|
||||
$any->pack($embed);
|
||||
$this->assertSame($data, $any->getValue());
|
||||
$this->assertSame("type.googleapis.com/foo.TestMessage", $any->getTypeUrl());
|
||||
|
||||
// Test is.
|
||||
$this->assertTrue($any->is(TestMessage::class));
|
||||
$this->assertFalse($any->is(Any::class));
|
||||
}
|
||||
|
||||
public function testAnyUnpackInvalidTypeUrl()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$any = new Any();
|
||||
$any->setTypeUrl("invalid");
|
||||
$any->unpack();
|
||||
}
|
||||
|
||||
public function testAnyUnpackMessageNotAdded()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$any = new Any();
|
||||
$any->setTypeUrl("type.googleapis.com/MessageNotAdded");
|
||||
$any->unpack();
|
||||
}
|
||||
|
||||
public function testAnyUnpackDecodeError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$any = new Any();
|
||||
$any->setTypeUrl("type.googleapis.com/foo.TestMessage");
|
||||
$any->setValue("abc");
|
||||
$any->unpack();
|
||||
}
|
||||
|
||||
public function testApi()
|
||||
{
|
||||
$m = new Api();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setMethods([new Method()]);
|
||||
$this->assertSame(1, count($m->getMethods()));
|
||||
|
||||
$m->setOptions([new Option()]);
|
||||
$this->assertSame(1, count($m->getOptions()));
|
||||
|
||||
$m->setVersion("a");
|
||||
$this->assertSame("a", $m->getVersion());
|
||||
|
||||
$m->setSourceContext(new SourceContext());
|
||||
$this->assertFalse(is_null($m->getSourceContext()));
|
||||
|
||||
$m->setMixins([new Mixin()]);
|
||||
$this->assertSame(1, count($m->getMixins()));
|
||||
|
||||
$m->setSyntax(Syntax::SYNTAX_PROTO2);
|
||||
$this->assertSame(Syntax::SYNTAX_PROTO2, $m->getSyntax());
|
||||
|
||||
$m = new Method();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setRequestTypeUrl("a");
|
||||
$this->assertSame("a", $m->getRequestTypeUrl());
|
||||
|
||||
$m->setRequestStreaming(true);
|
||||
$this->assertSame(true, $m->getRequestStreaming());
|
||||
|
||||
$m->setResponseTypeUrl("a");
|
||||
$this->assertSame("a", $m->getResponseTypeUrl());
|
||||
|
||||
$m->setResponseStreaming(true);
|
||||
$this->assertSame(true, $m->getResponseStreaming());
|
||||
|
||||
$m->setOptions([new Option()]);
|
||||
$this->assertSame(1, count($m->getOptions()));
|
||||
|
||||
$m = new Mixin();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setRoot("a");
|
||||
$this->assertSame("a", $m->getRoot());
|
||||
}
|
||||
|
||||
public function testEnum()
|
||||
{
|
||||
$m = new Enum();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setEnumvalue([new EnumValue()]);
|
||||
$this->assertSame(1, count($m->getEnumvalue()));
|
||||
|
||||
$m->setOptions([new Option()]);
|
||||
$this->assertSame(1, count($m->getOptions()));
|
||||
|
||||
$m->setSourceContext(new SourceContext());
|
||||
$this->assertFalse(is_null($m->getSourceContext()));
|
||||
|
||||
$m->setSyntax(Syntax::SYNTAX_PROTO2);
|
||||
$this->assertSame(Syntax::SYNTAX_PROTO2, $m->getSyntax());
|
||||
}
|
||||
|
||||
public function testEnumValue()
|
||||
{
|
||||
$m = new EnumValue();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setNumber(1);
|
||||
$this->assertSame(1, $m->getNumber());
|
||||
|
||||
$m->setOptions([new Option()]);
|
||||
$this->assertSame(1, count($m->getOptions()));
|
||||
}
|
||||
|
||||
public function testField()
|
||||
{
|
||||
$m = new Field();
|
||||
|
||||
$m->setKind(Kind::TYPE_DOUBLE);
|
||||
$this->assertSame(Kind::TYPE_DOUBLE, $m->getKind());
|
||||
|
||||
$m->setCardinality(Cardinality::CARDINALITY_OPTIONAL);
|
||||
$this->assertSame(Cardinality::CARDINALITY_OPTIONAL, $m->getCardinality());
|
||||
|
||||
$m->setNumber(1);
|
||||
$this->assertSame(1, $m->getNumber());
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setTypeUrl("a");
|
||||
$this->assertSame("a", $m->getTypeUrl());
|
||||
|
||||
$m->setOneofIndex(1);
|
||||
$this->assertSame(1, $m->getOneofIndex());
|
||||
|
||||
$m->setPacked(true);
|
||||
$this->assertSame(true, $m->getPacked());
|
||||
|
||||
$m->setOptions([new Option()]);
|
||||
$this->assertSame(1, count($m->getOptions()));
|
||||
|
||||
$m->setJsonName("a");
|
||||
$this->assertSame("a", $m->getJsonName());
|
||||
|
||||
$m->setDefaultValue("a");
|
||||
$this->assertSame("a", $m->getDefaultValue());
|
||||
}
|
||||
|
||||
public function testFieldMask()
|
||||
{
|
||||
$m = new FieldMask();
|
||||
$m->setPaths(["a"]);
|
||||
$this->assertSame(1, count($m->getPaths()));
|
||||
}
|
||||
|
||||
public function testOption()
|
||||
{
|
||||
$m = new Option();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setValue(new Any());
|
||||
$this->assertFalse(is_null($m->getValue()));
|
||||
}
|
||||
|
||||
public function testSourceContext()
|
||||
{
|
||||
$m = new SourceContext();
|
||||
$m->setFileName("a");
|
||||
$this->assertSame("a", $m->getFileName());
|
||||
}
|
||||
|
||||
public function testStruct()
|
||||
{
|
||||
$m = new ListValue();
|
||||
$m->setValues([new Value()]);
|
||||
$this->assertSame(1, count($m->getValues()));
|
||||
|
||||
$m = new Value();
|
||||
|
||||
$this->assertNull($m->getStructValue());
|
||||
|
||||
$m->setNullValue(NullValue::NULL_VALUE);
|
||||
$this->assertSame(NullValue::NULL_VALUE, $m->getNullValue());
|
||||
$this->assertSame("null_value", $m->getKind());
|
||||
|
||||
$m->setNumberValue(1.0);
|
||||
$this->assertSame(1.0, $m->getNumberValue());
|
||||
$this->assertSame("number_value", $m->getKind());
|
||||
|
||||
$m->setStringValue("a");
|
||||
$this->assertSame("a", $m->getStringValue());
|
||||
$this->assertSame("string_value", $m->getKind());
|
||||
|
||||
$m->setBoolValue(true);
|
||||
$this->assertSame(true, $m->getBoolValue());
|
||||
$this->assertSame("bool_value", $m->getKind());
|
||||
|
||||
$m->setStructValue(new Struct());
|
||||
$this->assertFalse(is_null($m->getStructValue()));
|
||||
$this->assertSame("struct_value", $m->getKind());
|
||||
|
||||
$m->setListValue(new ListValue());
|
||||
$this->assertFalse(is_null($m->getListValue()));
|
||||
$this->assertSame("list_value", $m->getKind());
|
||||
|
||||
$m = new Struct();
|
||||
$m->setFields(array("a"=>new Value()));
|
||||
$this->assertSame(1, count($m->getFields()));
|
||||
}
|
||||
|
||||
public function testTimestamp()
|
||||
{
|
||||
$timestamp = new Timestamp();
|
||||
|
||||
$timestamp->setSeconds(1);
|
||||
$timestamp->setNanos(2);
|
||||
$this->assertEquals(1, $timestamp->getSeconds());
|
||||
$this->assertSame(2, $timestamp->getNanos());
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
$from = new DateTime('2011-01-01T15:03:01.012345UTC');
|
||||
$timestamp->fromDateTime($from);
|
||||
$this->assertEquals($from->format('U'), $timestamp->getSeconds());
|
||||
$this->assertEquals(1000 * $from->format('u'), $timestamp->getNanos());
|
||||
|
||||
$to = $timestamp->toDateTime();
|
||||
$this->assertSame(\DateTime::class, get_class($to));
|
||||
$this->assertSame($from->format('U'), $to->format('U'));
|
||||
$this->assertSame($from->format('u'), $to->format('u'));
|
||||
}
|
||||
|
||||
public function testType()
|
||||
{
|
||||
$m = new Type();
|
||||
|
||||
$m->setName("a");
|
||||
$this->assertSame("a", $m->getName());
|
||||
|
||||
$m->setFields([new Field()]);
|
||||
$this->assertSame(1, count($m->getFields()));
|
||||
|
||||
$m->setOneofs(["a"]);
|
||||
$this->assertSame(1, count($m->getOneofs()));
|
||||
|
||||
$m->setOptions([new Option()]);
|
||||
$this->assertSame(1, count($m->getOptions()));
|
||||
|
||||
$m->setSourceContext(new SourceContext());
|
||||
$this->assertFalse(is_null($m->getSourceContext()));
|
||||
|
||||
$m->setSyntax(Syntax::SYNTAX_PROTO2);
|
||||
$this->assertSame(Syntax::SYNTAX_PROTO2, $m->getSyntax());
|
||||
}
|
||||
|
||||
public function testDuration()
|
||||
{
|
||||
$duration = new Duration();
|
||||
|
||||
$duration->setSeconds(1);
|
||||
$duration->setNanos(2);
|
||||
$this->assertEquals(1, $duration->getSeconds());
|
||||
$this->assertSame(2, $duration->getNanos());
|
||||
}
|
||||
|
||||
public function testWrappers()
|
||||
{
|
||||
$m = new DoubleValue();
|
||||
$m->setValue(1.0);
|
||||
$this->assertSame(1.0, $m->getValue());
|
||||
|
||||
$m = new FloatValue();
|
||||
$m->setValue(1.0);
|
||||
$this->assertSame(1.0, $m->getValue());
|
||||
|
||||
$m = new Int64Value();
|
||||
$m->setValue(1);
|
||||
$this->assertEquals(1, $m->getValue());
|
||||
|
||||
$m = new UInt64Value();
|
||||
$m->setValue(1);
|
||||
$this->assertEquals(1, $m->getValue());
|
||||
|
||||
$m = new Int32Value();
|
||||
$m->setValue(1);
|
||||
$this->assertSame(1, $m->getValue());
|
||||
|
||||
$m = new UInt32Value();
|
||||
$m->setValue(1);
|
||||
$this->assertSame(1, $m->getValue());
|
||||
|
||||
$m = new BoolValue();
|
||||
$m->setValue(true);
|
||||
$this->assertSame(true, $m->getValue());
|
||||
|
||||
$m = new StringValue();
|
||||
$m->setValue("a");
|
||||
$this->assertSame("a", $m->getValue());
|
||||
|
||||
$m = new BytesValue();
|
||||
$m->setValue("a");
|
||||
$this->assertSame("a", $m->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider enumNameValueConversionDataProvider
|
||||
*/
|
||||
public function testEnumNameValueConversion($class)
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
$constants = $reflectionClass->getConstants();
|
||||
foreach ($constants as $k => $v) {
|
||||
$this->assertSame($k, $class::name($v));
|
||||
$this->assertSame($v, $class::value($k));
|
||||
}
|
||||
}
|
||||
|
||||
public function enumNameValueConversionDataProvider()
|
||||
{
|
||||
return [
|
||||
['\Google\Protobuf\Field\Cardinality'],
|
||||
['\Google\Protobuf\Field\Kind'],
|
||||
['\Google\Protobuf\NullValue'],
|
||||
['\Google\Protobuf\Syntax'],
|
||||
];
|
||||
}
|
||||
}
|
317
deps/protobuf/php/tests/WrapperTypeSettersTest.php
vendored
Normal file
317
deps/protobuf/php/tests/WrapperTypeSettersTest.php
vendored
Normal file
@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
require_once('test_base.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
use Foo\TestWrapperSetters;
|
||||
use Google\Protobuf\BoolValue;
|
||||
use Google\Protobuf\BytesValue;
|
||||
use Google\Protobuf\DoubleValue;
|
||||
use Google\Protobuf\FloatValue;
|
||||
use Google\Protobuf\Int32Value;
|
||||
use Google\Protobuf\Int64Value;
|
||||
use Google\Protobuf\StringValue;
|
||||
use Google\Protobuf\UInt32Value;
|
||||
use Google\Protobuf\UInt64Value;
|
||||
|
||||
class WrapperTypeSettersTest extends TestBase
|
||||
{
|
||||
/**
|
||||
* @dataProvider gettersAndSettersDataProvider
|
||||
*/
|
||||
public function testGettersAndSetters(
|
||||
$class,
|
||||
$wrapperClass,
|
||||
$setter,
|
||||
$valueSetter,
|
||||
$getter,
|
||||
$valueGetter,
|
||||
$sequence
|
||||
) {
|
||||
$oldSetterMsg = new $class();
|
||||
$newSetterMsg = new $class();
|
||||
foreach ($sequence as list($value, $expectedValue)) {
|
||||
// Manually wrap the value to pass to the old setter
|
||||
$wrappedValue = is_null($value) ? $value : new $wrapperClass(['value' => $value]);
|
||||
|
||||
// Set values using new and old setters
|
||||
$oldSetterMsg->$setter($wrappedValue);
|
||||
$newSetterMsg->$valueSetter($value);
|
||||
|
||||
// Get expected values old getter
|
||||
$expectedValue = $oldSetterMsg->$getter();
|
||||
|
||||
// Check that old getter returns the same value after using the
|
||||
// new setter
|
||||
$actualValue = $newSetterMsg->$getter();
|
||||
$this->assertEquals($expectedValue, $actualValue);
|
||||
|
||||
// Check that new getter returns the unwrapped value from
|
||||
// $expectedValue
|
||||
$actualValueNewGetter = $newSetterMsg->$valueGetter();
|
||||
if (is_null($expectedValue)) {
|
||||
$this->assertNull($actualValueNewGetter);
|
||||
} else {
|
||||
$this->assertEquals($expectedValue->getValue(), $actualValueNewGetter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function gettersAndSettersDataProvider()
|
||||
{
|
||||
return [
|
||||
[TestWrapperSetters::class, DoubleValue::class, "setDoubleValue", "setDoubleValueUnwrapped", "getDoubleValue", "getDoubleValueUnwrapped", [
|
||||
[1.1, new DoubleValue(["value" => 1.1])],
|
||||
[2.2, new DoubleValue(["value" => 2.2])],
|
||||
[null, null],
|
||||
[0, new DoubleValue()],
|
||||
]],
|
||||
[TestWrapperSetters::class, FloatValue::class, "setFloatValue", "setFloatValueUnwrapped", "getFloatValue", "getFloatValueUnwrapped", [
|
||||
[1.1, new FloatValue(["value" => 1.1])],
|
||||
[2.2, new FloatValue(["value" => 2.2])],
|
||||
[null, null],
|
||||
[0, new FloatValue()],
|
||||
]],
|
||||
[TestWrapperSetters::class, Int64Value::class, "setInt64Value", "setInt64ValueUnwrapped", "getInt64Value", "getInt64ValueUnwrapped", [
|
||||
[123, new Int64Value(["value" => 123])],
|
||||
[-789, new Int64Value(["value" => -789])],
|
||||
[null, null],
|
||||
[0, new Int64Value()],
|
||||
[5.5, new Int64Value(["value" => 5])], // Test conversion from float to int
|
||||
]],
|
||||
[TestWrapperSetters::class, UInt64Value::class, "setUInt64Value", "setUInt64ValueUnwrapped", "getUInt64Value", "getUInt64ValueUnwrapped", [
|
||||
[123, new UInt64Value(["value" => 123])],
|
||||
[789, new UInt64Value(["value" => 789])],
|
||||
[null, null],
|
||||
[0, new UInt64Value()],
|
||||
[5.5, new UInt64Value(["value" => 5])], // Test conversion from float to int
|
||||
[-7, new UInt64Value(["value" => -7])], // Test conversion from -ve to +ve
|
||||
]],
|
||||
[TestWrapperSetters::class, Int32Value::class, "setInt32Value", "setInt32ValueUnwrapped", "getInt32Value", "getInt32ValueUnwrapped", [
|
||||
[123, new Int32Value(["value" => 123])],
|
||||
[-789, new Int32Value(["value" => -789])],
|
||||
[null, null],
|
||||
[0, new Int32Value()],
|
||||
[5.5, new Int32Value(["value" => 5])], // Test conversion from float to int
|
||||
]],
|
||||
[TestWrapperSetters::class, UInt32Value::class, "setUInt32Value", "setUInt32ValueUnwrapped", "getUInt32Value", "getUInt32ValueUnwrapped", [
|
||||
[123, new UInt32Value(["value" => 123])],
|
||||
[789, new UInt32Value(["value" => 789])],
|
||||
[null, null],
|
||||
[0, new UInt32Value()],
|
||||
[5.5, new UInt32Value(["value" => 5])], // Test conversion from float to int
|
||||
[-7, new UInt32Value(["value" => -7])], // Test conversion from -ve to +ve
|
||||
]],
|
||||
[TestWrapperSetters::class, BoolValue::class, "setBoolValue", "setBoolValueUnwrapped", "getBoolValue", "getBoolValueUnwrapped", [
|
||||
[true, new BoolValue(["value" => true])],
|
||||
[false, new BoolValue(["value" => false])],
|
||||
[null, null],
|
||||
]],
|
||||
[TestWrapperSetters::class, StringValue::class, "setStringValue", "setStringValueUnwrapped", "getStringValue", "getStringValueUnwrapped", [
|
||||
["asdf", new StringValue(["value" => "asdf"])],
|
||||
["", new StringValue(["value" => ""])],
|
||||
[null, null],
|
||||
["", new StringValue()],
|
||||
[5, new StringValue(["value" => "5"])], // Test conversion from number to string
|
||||
[5.5, new StringValue(["value" => "5.5"])], // Test conversion from number to string
|
||||
[-7, new StringValue(["value" => "-7"])], // Test conversion from number to string
|
||||
[-7.5, new StringValue(["value" => "-7.5"])], // Test conversion from number to string
|
||||
]],
|
||||
[TestWrapperSetters::class, BytesValue::class, "setBytesValue", "setBytesValueUnwrapped", "getBytesValue", "getBytesValueUnwrapped", [
|
||||
["asdf", new BytesValue(["value" => "asdf"])],
|
||||
["", new BytesValue(["value" => ""])],
|
||||
[null, null],
|
||||
["", new BytesValue()],
|
||||
[5, new BytesValue(["value" => "5"])], // Test conversion from number to bytes
|
||||
[5.5, new BytesValue(["value" => "5.5"])], // Test conversion from number to bytes
|
||||
[-7, new BytesValue(["value" => "-7"])], // Test conversion from number to bytes
|
||||
[-7.5, new BytesValue(["value" => "-7.5"])], // Test conversion from number to bytes
|
||||
]],
|
||||
[TestWrapperSetters::class, DoubleValue::class, "setDoubleValueOneof", "setDoubleValueOneofUnwrapped", "getDoubleValueOneof", "getDoubleValueOneofUnwrapped", [
|
||||
[1.1, new DoubleValue(["value" => 1.1])],
|
||||
[2.2, new DoubleValue(["value" => 2.2])],
|
||||
[null, null],
|
||||
[0, new DoubleValue()],
|
||||
]],
|
||||
[TestWrapperSetters::class, StringValue::class, "setStringValueOneof", "setStringValueOneofUnwrapped", "getStringValueOneof", "getStringValueOneofUnwrapped", [
|
||||
["asdf", new StringValue(["value" => "asdf"])],
|
||||
["", new StringValue(["value" => ""])],
|
||||
[null, null],
|
||||
["", new StringValue()],
|
||||
[5, new StringValue(["value" => "5"])], // Test conversion from number to string
|
||||
[5.5, new StringValue(["value" => "5.5"])], // Test conversion from number to string
|
||||
[-7, new StringValue(["value" => "-7"])], // Test conversion from number to string
|
||||
[-7.5, new StringValue(["value" => "-7.5"])], // Test conversion from number to string
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidSettersDataProvider
|
||||
*/
|
||||
public function testInvalidSetters($class, $setter, $value)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
(new $class())->$setter($value);
|
||||
}
|
||||
|
||||
public function invalidSettersDataProvider()
|
||||
{
|
||||
return [
|
||||
[TestWrapperSetters::class, "setDoubleValueUnwrapped", "abc"],
|
||||
[TestWrapperSetters::class, "setDoubleValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setDoubleValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setDoubleValueUnwrapped", new DoubleValue()],
|
||||
|
||||
[TestWrapperSetters::class, "setFloatValueUnwrapped", "abc"],
|
||||
[TestWrapperSetters::class, "setFloatValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setFloatValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setFloatValueUnwrapped", new FloatValue()],
|
||||
|
||||
[TestWrapperSetters::class, "setInt64ValueUnwrapped", "abc"],
|
||||
[TestWrapperSetters::class, "setInt64ValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setInt64ValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setInt64ValueUnwrapped", new Int64Value()],
|
||||
|
||||
[TestWrapperSetters::class, "setUInt64ValueUnwrapped", "abc"],
|
||||
[TestWrapperSetters::class, "setUInt64ValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setUInt64ValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setUInt64ValueUnwrapped", new UInt64Value()],
|
||||
|
||||
[TestWrapperSetters::class, "setInt32ValueUnwrapped", "abc"],
|
||||
[TestWrapperSetters::class, "setInt32ValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setInt32ValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setInt32ValueUnwrapped", new Int32Value()],
|
||||
|
||||
[TestWrapperSetters::class, "setUInt32ValueUnwrapped", "abc"],
|
||||
[TestWrapperSetters::class, "setUInt32ValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setUInt32ValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setUInt32ValueUnwrapped", new UInt32Value()],
|
||||
|
||||
[TestWrapperSetters::class, "setBoolValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setBoolValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setBoolValueUnwrapped", new BoolValue()],
|
||||
|
||||
[TestWrapperSetters::class, "setStringValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setStringValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setStringValueUnwrapped", new StringValue()],
|
||||
|
||||
[TestWrapperSetters::class, "setBytesValueUnwrapped", []],
|
||||
[TestWrapperSetters::class, "setBytesValueUnwrapped", new stdClass()],
|
||||
[TestWrapperSetters::class, "setBytesValueUnwrapped", new BytesValue()],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider constructorWithWrapperTypeDataProvider
|
||||
*/
|
||||
public function testConstructorWithWrapperType($class, $wrapperClass, $wrapperField, $getter, $value)
|
||||
{
|
||||
$actualInstance = new $class([$wrapperField => $value]);
|
||||
$expectedInstance = new $class([$wrapperField => new $wrapperClass(['value' => $value])]);
|
||||
$this->assertEquals($expectedInstance->$getter()->getValue(), $actualInstance->$getter()->getValue());
|
||||
}
|
||||
|
||||
public function constructorWithWrapperTypeDataProvider()
|
||||
{
|
||||
return [
|
||||
[TestWrapperSetters::class, DoubleValue::class, 'double_value', 'getDoubleValue', 1.1],
|
||||
[TestWrapperSetters::class, FloatValue::class, 'float_value', 'getFloatValue', 2.2],
|
||||
[TestWrapperSetters::class, Int64Value::class, 'int64_value', 'getInt64Value', 3],
|
||||
[TestWrapperSetters::class, UInt64Value::class, 'uint64_value', 'getUInt64Value', 4],
|
||||
[TestWrapperSetters::class, Int32Value::class, 'int32_value', 'getInt32Value', 5],
|
||||
[TestWrapperSetters::class, UInt32Value::class, 'uint32_value', 'getUInt32Value', 6],
|
||||
[TestWrapperSetters::class, BoolValue::class, 'bool_value', 'getBoolValue', true],
|
||||
[TestWrapperSetters::class, StringValue::class, 'string_value', 'getStringValue', "eight"],
|
||||
[TestWrapperSetters::class, BytesValue::class, 'bytes_value', 'getBytesValue', "nine"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider constructorWithRepeatedWrapperTypeDataProvider
|
||||
*/
|
||||
public function testConstructorWithRepeatedWrapperType($wrapperField, $getter, $value)
|
||||
{
|
||||
$actualInstance = new TestWrapperSetters([$wrapperField => $value]);
|
||||
foreach ($actualInstance->$getter() as $key => $actualWrapperValue) {
|
||||
$actualInnerValue = $actualWrapperValue->getValue();
|
||||
$expectedElement = $value[$key];
|
||||
if (is_object($expectedElement) && is_a($expectedElement, '\Google\Protobuf\StringValue')) {
|
||||
$expectedInnerValue = $expectedElement->getValue();
|
||||
} else {
|
||||
$expectedInnerValue = $expectedElement;
|
||||
}
|
||||
$this->assertEquals($expectedInnerValue, $actualInnerValue);
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function constructorWithRepeatedWrapperTypeDataProvider()
|
||||
{
|
||||
$sv7 = new StringValue(['value' => 'seven']);
|
||||
$sv8 = new StringValue(['value' => 'eight']);
|
||||
|
||||
$testWrapperSetters = new TestWrapperSetters();
|
||||
$testWrapperSetters->setRepeatedStringValue([$sv7, $sv8]);
|
||||
$repeatedField = $testWrapperSetters->getRepeatedStringValue();
|
||||
|
||||
return [
|
||||
['repeated_string_value', 'getRepeatedStringValue', []],
|
||||
['repeated_string_value', 'getRepeatedStringValue', [$sv7]],
|
||||
['repeated_string_value', 'getRepeatedStringValue', [$sv7, $sv8]],
|
||||
['repeated_string_value', 'getRepeatedStringValue', ['seven']],
|
||||
['repeated_string_value', 'getRepeatedStringValue', [7]],
|
||||
['repeated_string_value', 'getRepeatedStringValue', [7.7]],
|
||||
['repeated_string_value', 'getRepeatedStringValue', ['seven', 'eight']],
|
||||
['repeated_string_value', 'getRepeatedStringValue', [$sv7, 'eight']],
|
||||
['repeated_string_value', 'getRepeatedStringValue', ['seven', $sv8]],
|
||||
['repeated_string_value', 'getRepeatedStringValue', $repeatedField],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider constructorWithMapWrapperTypeDataProvider
|
||||
*/
|
||||
public function testConstructorWithMapWrapperType($wrapperField, $getter, $value)
|
||||
{
|
||||
$actualInstance = new TestWrapperSetters([$wrapperField => $value]);
|
||||
foreach ($actualInstance->$getter() as $key => $actualWrapperValue) {
|
||||
$actualInnerValue = $actualWrapperValue->getValue();
|
||||
$expectedElement = $value[$key];
|
||||
if (is_object($expectedElement) && is_a($expectedElement, '\Google\Protobuf\StringValue')) {
|
||||
$expectedInnerValue = $expectedElement->getValue();
|
||||
} elseif (is_object($expectedElement) && is_a($expectedElement, '\Google\Protobuf\Internal\MapEntry')) {
|
||||
$expectedInnerValue = $expectedElement->getValue()->getValue();
|
||||
} else {
|
||||
$expectedInnerValue = $expectedElement;
|
||||
}
|
||||
$this->assertEquals($expectedInnerValue, $actualInnerValue);
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function constructorWithMapWrapperTypeDataProvider()
|
||||
{
|
||||
$sv7 = new StringValue(['value' => 'seven']);
|
||||
$sv8 = new StringValue(['value' => 'eight']);
|
||||
|
||||
$testWrapperSetters = new TestWrapperSetters();
|
||||
$testWrapperSetters->setMapStringValue(['key' => $sv7, 'key2' => $sv8]);
|
||||
$mapField = $testWrapperSetters->getMapStringValue();
|
||||
|
||||
return [
|
||||
['map_string_value', 'getMapStringValue', []],
|
||||
['map_string_value', 'getMapStringValue', ['key' => $sv7]],
|
||||
['map_string_value', 'getMapStringValue', ['key' => $sv7, 'key2' => $sv8]],
|
||||
['map_string_value', 'getMapStringValue', ['key' => 'seven']],
|
||||
['map_string_value', 'getMapStringValue', ['key' => 7]],
|
||||
['map_string_value', 'getMapStringValue', ['key' => 7.7]],
|
||||
['map_string_value', 'getMapStringValue', ['key' => 'seven', 'key2' => 'eight']],
|
||||
['map_string_value', 'getMapStringValue', ['key' => $sv7, 'key2' => 'eight']],
|
||||
['map_string_value', 'getMapStringValue', ['key' => 'seven', 'key2' => $sv8]],
|
||||
['map_string_value', 'getMapStringValue', $mapField],
|
||||
];
|
||||
}
|
||||
}
|
152
deps/protobuf/php/tests/compatibility_test.sh
vendored
Normal file
152
deps/protobuf/php/tests/compatibility_test.sh
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
#!/bin/bash
|
||||
|
||||
function generate_proto() {
|
||||
PROTOC1=$1
|
||||
PROTOC2=$2
|
||||
|
||||
rm -rf generated
|
||||
mkdir generated
|
||||
|
||||
$PROTOC1 --php_out=generated proto/test_include.proto
|
||||
$PROTOC2 --php_out=generated \
|
||||
-I../../src -I. \
|
||||
proto/empty/echo.proto \
|
||||
proto/test.proto \
|
||||
proto/test_no_namespace.proto \
|
||||
proto/test_prefix.proto \
|
||||
proto/test_php_namespace.proto \
|
||||
proto/test_empty_php_namespace.proto \
|
||||
proto/test_reserved_enum_lower.proto \
|
||||
proto/test_reserved_enum_upper.proto \
|
||||
proto/test_reserved_enum_value_lower.proto \
|
||||
proto/test_reserved_enum_value_upper.proto \
|
||||
proto/test_reserved_message_lower.proto \
|
||||
proto/test_reserved_message_upper.proto \
|
||||
proto/test_service.proto \
|
||||
proto/test_service_namespace.proto \
|
||||
proto/test_wrapper_type_setters.proto \
|
||||
proto/test_descriptors.proto
|
||||
|
||||
pushd ../../src
|
||||
$PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto
|
||||
popd
|
||||
}
|
||||
|
||||
# Remove tests to expect error. These were added to API tests by mistake.
|
||||
function remove_error_test() {
|
||||
local TEMPFILE=`tempfile`
|
||||
cat $1 | \
|
||||
awk -v file=`basename $1` -v dir=`basename $(dirname $1)` '
|
||||
BEGIN {
|
||||
show = 1
|
||||
}
|
||||
/@expectedException PHPUnit_Framework_Error/ { show = 0; next; }
|
||||
/ *\*\// { print; next; }
|
||||
/ *}/ {
|
||||
if (!show) {
|
||||
show = 1;
|
||||
next;
|
||||
}
|
||||
}
|
||||
show { print }
|
||||
' > $TEMPFILE
|
||||
cp $TEMPFILE $1
|
||||
}
|
||||
|
||||
set -ex
|
||||
|
||||
# Change to the script's directory.
|
||||
cd $(dirname $0)
|
||||
|
||||
OLD_VERSION=$1
|
||||
OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe
|
||||
|
||||
# Extract the latest protobuf version number.
|
||||
VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"`
|
||||
|
||||
echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION"
|
||||
|
||||
# Check protoc
|
||||
[ -f ../../src/protoc ] || {
|
||||
echo "[ERROR]: Please build protoc first."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Download old test.
|
||||
rm -rf protobuf
|
||||
git clone https://github.com/protocolbuffers/protobuf.git
|
||||
pushd protobuf
|
||||
git checkout v$OLD_VERSION
|
||||
popd
|
||||
|
||||
# Build and copy the new runtime
|
||||
pushd ../ext/google/protobuf
|
||||
make clean || true
|
||||
phpize && ./configure && make
|
||||
popd
|
||||
|
||||
rm -rf protobuf/php/ext
|
||||
rm -rf protobuf/php/src
|
||||
cp -r ../ext protobuf/php/ext/
|
||||
cp -r ../src protobuf/php/src/
|
||||
|
||||
# Download old version protoc compiler (for linux)
|
||||
wget $OLD_VERSION_PROTOC -O old_protoc
|
||||
chmod +x old_protoc
|
||||
|
||||
NEW_PROTOC=`pwd`/../../src/protoc
|
||||
OLD_PROTOC=`pwd`/old_protoc
|
||||
cd protobuf/php
|
||||
composer install
|
||||
|
||||
# Remove implementation detail tests.
|
||||
# TODO(teboring): Temporarily disable encode_decode_test.php. In 3.13.0-rc1,
|
||||
# repeated primitive field encoding is changed to packed, which is a bug fix.
|
||||
# However, this fails the compatibility test which hard coded old encoding.
|
||||
# Will re-enable the test after making a release. After the version bump, the
|
||||
# compatibility test will use the updated test code.
|
||||
tests=( array_test.php generated_class_test.php map_field_test.php well_known_test.php )
|
||||
sed -i.bak '/php_implementation_test.php/d' phpunit.xml
|
||||
sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
|
||||
sed -i.bak '/encode_decode_test.php/d' phpunit.xml
|
||||
sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
|
||||
sed -i.bak 's/generated_service_test.php//g' tests/test.sh
|
||||
sed -i.bak 's/encode_decode_test.php//g' tests/test.sh
|
||||
sed -i.bak '/memory_leak_test.php/d' tests/test.sh
|
||||
sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php
|
||||
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php
|
||||
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php
|
||||
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php
|
||||
for t in "${tests[@]}"
|
||||
do
|
||||
remove_error_test tests/$t
|
||||
done
|
||||
|
||||
cd tests
|
||||
|
||||
# Test A.1:
|
||||
# proto set 1: use old version
|
||||
# proto set 2 which may import protos in set 1: use old version
|
||||
generate_proto $OLD_PROTOC $OLD_PROTOC
|
||||
./test.sh
|
||||
pushd ..
|
||||
./vendor/bin/phpunit
|
||||
popd
|
||||
|
||||
# Test A.2:
|
||||
# proto set 1: use new version
|
||||
# proto set 2 which may import protos in set 1: use old version
|
||||
generate_proto $NEW_PROTOC $OLD_PROTOC
|
||||
./test.sh
|
||||
pushd ..
|
||||
./vendor/bin/phpunit
|
||||
popd
|
||||
|
||||
# Test A.3:
|
||||
# proto set 1: use old version
|
||||
# proto set 2 which may import protos in set 1: use new version
|
||||
generate_proto $OLD_PROTOC $NEW_PROTOC
|
||||
./test.sh
|
||||
pushd ..
|
||||
./vendor/bin/phpunit
|
||||
popd
|
37
deps/protobuf/php/tests/compile_extension.sh
vendored
Normal file
37
deps/protobuf/php/tests/compile_extension.sh
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)/..
|
||||
|
||||
# utf8_range has to live in the base third_party directory.
|
||||
# We copy it into the ext/google/protobuf directory for the build
|
||||
# (and for the release to PECL).
|
||||
rm -rf ext/google/protobuf/third_party
|
||||
mkdir -p ext/google/protobuf/third_party/utf8_range
|
||||
cp ../third_party/utf8_range/* ext/google/protobuf/third_party/utf8_range
|
||||
|
||||
echo "Copied utf8_range from ../third_party -> ext/google/protobuf/third_party"
|
||||
|
||||
pushd ext/google/protobuf > /dev/null
|
||||
|
||||
CONFIGURE_OPTIONS=("./configure" "--with-php-config=$(which php-config)")
|
||||
|
||||
if [ "$1" != "--release" ]; then
|
||||
CONFIGURE_OPTIONS+=("CFLAGS=-g -O0 -Wall -DPBPHP_ENABLE_ASSERTS")
|
||||
fi
|
||||
|
||||
FINGERPRINT="$(sha256sum $(which php)) ${CONFIGURE_OPTIONS[@]}"
|
||||
|
||||
# If the PHP interpreter we are building against or the arguments
|
||||
# have changed, we must regenerated the Makefile.
|
||||
if [[ ! -f BUILD_STAMP ]] || [[ "$(cat BUILD_STAMP)" != "$FINGERPRINT" ]]; then
|
||||
phpize --clean
|
||||
rm -f configure.in configure.ac
|
||||
phpize
|
||||
"${CONFIGURE_OPTIONS[@]}"
|
||||
echo "$FINGERPRINT" > BUILD_STAMP
|
||||
fi
|
||||
|
||||
make
|
||||
popd > /dev/null
|
14
deps/protobuf/php/tests/force_c_ext.php
vendored
Normal file
14
deps/protobuf/php/tests/force_c_ext.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
// We have to test this because the command-line argument will fail silently
|
||||
// if the extension could not be loaded:
|
||||
// php -dextension=ext/google/protobuf/modules/protouf.so
|
||||
if (!extension_loaded("protobuf")) {
|
||||
throw new Exception("Protobuf extension not loaded");
|
||||
}
|
||||
|
||||
spl_autoload_register(function($class) {
|
||||
if (strpos($class, "Google\\Protobuf") === 0) {
|
||||
throw new Exception("When using the C extension, we should not load runtime class: " . $class);
|
||||
}
|
||||
}, true, true);
|
13
deps/protobuf/php/tests/gdb_test.sh
vendored
Normal file
13
deps/protobuf/php/tests/gdb_test.sh
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
php -i | grep "Configuration"
|
||||
|
||||
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which
|
||||
# phpunit` --bootstrap autoload.php tmp_test.php
|
||||
#
|
||||
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php generated_class_test.php
|
||||
gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php
|
||||
#
|
||||
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
|
||||
#
|
||||
# USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
|
178
deps/protobuf/php/tests/memory_leak_test.php
vendored
Normal file
178
deps/protobuf/php/tests/memory_leak_test.php
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
|
||||
|
||||
class HasDestructor
|
||||
{
|
||||
function __construct() {
|
||||
$this->foo = $this;
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
new Foo\TestMessage();
|
||||
}
|
||||
}
|
||||
|
||||
require_once('../vendor/autoload.php');
|
||||
require_once('test_util.php');
|
||||
|
||||
$has_destructor = new HasDestructor();
|
||||
|
||||
use Google\Protobuf\Internal\RepeatedField;
|
||||
use Google\Protobuf\Internal\GPBType;
|
||||
use Foo\TestAny;
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestMessage\Sub;
|
||||
|
||||
$from = new TestMessage();
|
||||
TestUtil::setTestMessage($from);
|
||||
TestUtil::assertTestMessage($from);
|
||||
|
||||
$data = $from->serializeToString();
|
||||
|
||||
$to = new TestMessage();
|
||||
$to->mergeFromString($data);
|
||||
|
||||
TestUtil::assertTestMessage($to);
|
||||
|
||||
$from = new TestMessage();
|
||||
TestUtil::setTestMessage2($from);
|
||||
|
||||
$data = $from->serializeToString();
|
||||
|
||||
$to->mergeFromString($data);
|
||||
|
||||
// TODO(teboring): This causes following tests fail in php7.
|
||||
# $from->setRecursive($from);
|
||||
|
||||
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
|
||||
$arr[] = new TestMessage;
|
||||
$arr[0]->SetRepeatedRecursive($arr);
|
||||
|
||||
// Test oneof fields.
|
||||
$m = new TestMessage();
|
||||
|
||||
$m->setOneofInt32(1);
|
||||
assert(1 === $m->getOneofInt32());
|
||||
assert(0.0 === $m->getOneofFloat());
|
||||
assert('' === $m->getOneofString());
|
||||
assert(NULL === $m->getOneofMessage());
|
||||
$data = $m->serializeToString();
|
||||
$n = new TestMessage();
|
||||
$n->mergeFromString($data);
|
||||
assert(1 === $n->getOneofInt32());
|
||||
|
||||
$m->setOneofFloat(2.0);
|
||||
assert(0 === $m->getOneofInt32());
|
||||
assert(2.0 === $m->getOneofFloat());
|
||||
assert('' === $m->getOneofString());
|
||||
assert(NULL === $m->getOneofMessage());
|
||||
$data = $m->serializeToString();
|
||||
$n = new TestMessage();
|
||||
$n->mergeFromString($data);
|
||||
assert(2.0 === $n->getOneofFloat());
|
||||
|
||||
$m->setOneofString('abc');
|
||||
assert(0 === $m->getOneofInt32());
|
||||
assert(0.0 === $m->getOneofFloat());
|
||||
assert('abc' === $m->getOneofString());
|
||||
assert(NULL === $m->getOneofMessage());
|
||||
$data = $m->serializeToString();
|
||||
$n = new TestMessage();
|
||||
$n->mergeFromString($data);
|
||||
assert('abc' === $n->getOneofString());
|
||||
|
||||
$sub_m = new Sub();
|
||||
$sub_m->setA(1);
|
||||
$m->setOneofMessage($sub_m);
|
||||
assert(0 === $m->getOneofInt32());
|
||||
assert(0.0 === $m->getOneofFloat());
|
||||
assert('' === $m->getOneofString());
|
||||
assert(1 === $m->getOneofMessage()->getA());
|
||||
$data = $m->serializeToString();
|
||||
$n = new TestMessage();
|
||||
$n->mergeFromString($data);
|
||||
assert(1 === $n->getOneofMessage()->getA());
|
||||
|
||||
$m = new TestMessage();
|
||||
$m->mergeFromString(hex2bin('F80601'));
|
||||
assert('f80601' === bin2hex($m->serializeToString()));
|
||||
|
||||
// Test create repeated field via array.
|
||||
$str_arr = array("abc");
|
||||
$m = new TestMessage();
|
||||
$m->setRepeatedString($str_arr);
|
||||
|
||||
// Test create map field via array.
|
||||
$str_arr = array("abc"=>"abc");
|
||||
$m = new TestMessage();
|
||||
$m->setMapStringString($str_arr);
|
||||
|
||||
// Test unset
|
||||
$from = new TestMessage();
|
||||
TestUtil::setTestMessage($from);
|
||||
unset($from);
|
||||
|
||||
// Test wellknown
|
||||
$from = new \Google\Protobuf\Timestamp();
|
||||
$from->setSeconds(1);
|
||||
assert(1, $from->getSeconds());
|
||||
|
||||
$timestamp = new \Google\Protobuf\Timestamp();
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
$from = new DateTime('2011-01-01T15:03:01.012345UTC');
|
||||
$timestamp->fromDateTime($from);
|
||||
assert($from->format('U') == $timestamp->getSeconds());
|
||||
assert(1000 * $from->format('u') == $timestamp->getNanos());
|
||||
|
||||
$to = $timestamp->toDateTime();
|
||||
assert(\DateTime::class == get_class($to));
|
||||
assert($from->format('U') == $to->format('U'));
|
||||
|
||||
$from = new \Google\Protobuf\Value();
|
||||
$from->setNumberValue(1);
|
||||
assert(1, $from->getNumberValue());
|
||||
|
||||
// Test discard unknown in message.
|
||||
$m = new TestMessage();
|
||||
$from = hex2bin('F80601');
|
||||
$m->mergeFromString($from);
|
||||
$m->discardUnknownFields();
|
||||
$to = $m->serializeToString();
|
||||
assert("" === bin2hex($to));
|
||||
|
||||
// Test clear
|
||||
$m = new TestMessage();
|
||||
TestUtil::setTestMessage($m);
|
||||
$m->clear();
|
||||
|
||||
// Test unset map element
|
||||
$m = new TestMessage();
|
||||
$map = $m->getMapStringString();
|
||||
$map[1] = 1;
|
||||
unset($map[1]);
|
||||
|
||||
// Test descriptor
|
||||
$pool = \Google\Protobuf\DescriptorPool::getGeneratedPool();
|
||||
$desc = $pool->getDescriptorByClassName("\Foo\TestMessage");
|
||||
$field = $desc->getField(1);
|
||||
|
||||
$from = new TestMessage();
|
||||
$to = new TestMessage();
|
||||
TestUtil::setTestMessage($from);
|
||||
$to->mergeFrom($from);
|
||||
TestUtil::assertTestMessage($to);
|
||||
|
||||
// Test decode Any
|
||||
// Make sure packed message has been created at least once.
|
||||
$packed = new TestMessage();
|
||||
|
||||
$m = new TestAny();
|
||||
$m->mergeFromJsonString(
|
||||
"{\"any\":" .
|
||||
" {\"@type\":\"type.googleapis.com/foo.TestMessage\"," .
|
||||
" \"optionalInt32\":1}}");
|
||||
assert("type.googleapis.com/foo.TestMessage" ===
|
||||
$m->getAny()->getTypeUrl());
|
||||
assert("0801" === bin2hex($m->getAny()->getValue()));
|
40
deps/protobuf/php/tests/memory_leak_test.sh
vendored
Normal file
40
deps/protobuf/php/tests/memory_leak_test.sh
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
set -ex
|
||||
|
||||
PORT=12345
|
||||
TIMEOUT=10
|
||||
|
||||
./compile_extension.sh
|
||||
|
||||
run_test() {
|
||||
echo
|
||||
echo "Running memory leak test, args: $@"
|
||||
|
||||
EXTRA_ARGS=""
|
||||
ARGS="-d xdebug.profiler_enable=0 -d display_errors=on -dextension=../ext/google/protobuf/modules/protobuf.so"
|
||||
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
--keep_descriptors)
|
||||
EXTRA_ARGS=-dprotobuf.keep_descriptor_pool_after_request=1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
export ZEND_DONT_UNLOAD_MODULES=1
|
||||
export USE_ZEND_ALLOC=0
|
||||
|
||||
if valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all --suppressions=valgrind.supp --num-callers=100 php $ARGS $EXTRA_ARGS memory_leak_test.php; then
|
||||
echo "Memory leak test SUCCEEDED"
|
||||
else
|
||||
echo "Memory leak test FAILED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_test
|
||||
run_test --keep_descriptors
|
8
deps/protobuf/php/tests/multirequest.php
vendored
Normal file
8
deps/protobuf/php/tests/multirequest.php
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
if (extension_loaded("protobuf")) {
|
||||
require_once('memory_leak_test.php');
|
||||
echo "<p>protobuf loaded</p>";
|
||||
} else {
|
||||
echo "<p>protobuf not loaded</p>";
|
||||
}
|
62
deps/protobuf/php/tests/multirequest.sh
vendored
Normal file
62
deps/protobuf/php/tests/multirequest.sh
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
set -e
|
||||
|
||||
PORT=12345
|
||||
TIMEOUT=10
|
||||
|
||||
./compile_extension.sh
|
||||
|
||||
run_test() {
|
||||
echo
|
||||
echo "Running multirequest test, args: $@"
|
||||
|
||||
RUN_UNDER=""
|
||||
EXTRA_ARGS=""
|
||||
ARGS="-d xdebug.profiler_enable=0 -d display_errors=on -dextension=../ext/google/protobuf/modules/protobuf.so"
|
||||
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
--valgrind)
|
||||
RUN_UNDER="valgrind --error-exitcode=1"
|
||||
shift
|
||||
;;
|
||||
--keep_descriptors)
|
||||
EXTRA_ARGS=-dprotobuf.keep_descriptor_pool_after_request=1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
export ZEND_DONT_UNLOAD_MODULES=1
|
||||
export USE_ZEND_ALLOC=0
|
||||
rm -f nohup.out
|
||||
nohup $RUN_UNDER php $ARGS $EXTRA_ARGS -S localhost:$PORT multirequest.php >nohup.out 2>&1 &
|
||||
PID=$!
|
||||
|
||||
if ! timeout $TIMEOUT bash -c "until echo > /dev/tcp/localhost/$PORT; do sleep 0.1; done" > /dev/null 2>&1; then
|
||||
echo "Server failed to come up after $TIMEOUT seconds"
|
||||
cat nohup.out
|
||||
exit 1
|
||||
fi
|
||||
|
||||
seq 2 | xargs -I{} wget -nv http://localhost:$PORT/multirequest.result -O multirequest{}.result
|
||||
REQUESTS_SUCCEEDED=$?
|
||||
|
||||
|
||||
if kill $PID > /dev/null 2>&1 && [[ $REQUESTS_SUCCEEDED == "0" ]]; then
|
||||
wait
|
||||
echo "Multirequest test SUCCEEDED"
|
||||
else
|
||||
echo "Multirequest test FAILED"
|
||||
cat nohup.out
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_test
|
||||
run_test --keep_descriptors
|
||||
run_test --valgrind
|
||||
run_test --valgrind --keep_descriptors
|
17
deps/protobuf/php/tests/proto/empty/echo.proto
vendored
Normal file
17
deps/protobuf/php/tests/proto/empty/echo.proto
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package empty.echo;
|
||||
|
||||
message TestEmptyPackage {
|
||||
int32 a = 1;
|
||||
|
||||
// Test nested messages, enums, and reserved names
|
||||
NestedMessage nested_message = 2;
|
||||
NestedEnum nested_enum = 3;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
};
|
||||
}
|
343
deps/protobuf/php/tests/proto/test.proto
vendored
Normal file
343
deps/protobuf/php/tests/proto/test.proto
vendored
Normal file
@ -0,0 +1,343 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import 'google/protobuf/any.proto';
|
||||
import 'google/protobuf/wrappers.proto';
|
||||
import 'google/protobuf/struct.proto';
|
||||
import 'proto/test_include.proto';
|
||||
import 'proto/test_no_namespace.proto';
|
||||
import 'proto/test_php_namespace.proto';
|
||||
import 'proto/test_empty_php_namespace.proto';
|
||||
import 'proto/test_prefix.proto';
|
||||
|
||||
package foo;
|
||||
|
||||
message TestMessage {
|
||||
// Singular
|
||||
int32 optional_int32 = 1;
|
||||
int64 optional_int64 = 2;
|
||||
uint32 optional_uint32 = 3;
|
||||
uint64 optional_uint64 = 4;
|
||||
sint32 optional_sint32 = 5;
|
||||
sint64 optional_sint64 = 6;
|
||||
fixed32 optional_fixed32 = 7;
|
||||
fixed64 optional_fixed64 = 8;
|
||||
sfixed32 optional_sfixed32 = 9;
|
||||
sfixed64 optional_sfixed64 = 10;
|
||||
float optional_float = 11;
|
||||
double optional_double = 12;
|
||||
bool optional_bool = 13;
|
||||
string optional_string = 14;
|
||||
bytes optional_bytes = 15;
|
||||
|
||||
TestEnum optional_enum = 16;
|
||||
Sub optional_message = 17;
|
||||
bar.TestInclude optional_included_message = 18;
|
||||
TestMessage recursive = 19;
|
||||
|
||||
// True optional
|
||||
optional int32 true_optional_int32 = 201;
|
||||
optional int64 true_optional_int64 = 202;
|
||||
optional uint32 true_optional_uint32 = 203;
|
||||
optional uint64 true_optional_uint64 = 204;
|
||||
optional sint32 true_optional_sint32 = 205;
|
||||
optional sint64 true_optional_sint64 = 206;
|
||||
optional fixed32 true_optional_fixed32 = 207;
|
||||
optional fixed64 true_optional_fixed64 = 208;
|
||||
optional sfixed32 true_optional_sfixed32 = 209;
|
||||
optional sfixed64 true_optional_sfixed64 = 210;
|
||||
optional float true_optional_float = 211;
|
||||
optional double true_optional_double = 212;
|
||||
optional bool true_optional_bool = 213;
|
||||
optional string true_optional_string = 214;
|
||||
optional bytes true_optional_bytes = 215;
|
||||
|
||||
optional TestEnum true_optional_enum = 216;
|
||||
optional Sub true_optional_message = 217;
|
||||
optional bar.TestInclude true_optional_included_message = 218;
|
||||
|
||||
// Repeated
|
||||
repeated int32 repeated_int32 = 31;
|
||||
repeated int64 repeated_int64 = 32;
|
||||
repeated uint32 repeated_uint32 = 33;
|
||||
repeated uint64 repeated_uint64 = 34;
|
||||
repeated sint32 repeated_sint32 = 35;
|
||||
repeated sint64 repeated_sint64 = 36;
|
||||
repeated fixed32 repeated_fixed32 = 37;
|
||||
repeated fixed64 repeated_fixed64 = 38;
|
||||
repeated sfixed32 repeated_sfixed32 = 39;
|
||||
repeated sfixed64 repeated_sfixed64 = 40;
|
||||
repeated float repeated_float = 41;
|
||||
repeated double repeated_double = 42;
|
||||
repeated bool repeated_bool = 43;
|
||||
repeated string repeated_string = 44;
|
||||
repeated bytes repeated_bytes = 45;
|
||||
|
||||
repeated TestEnum repeated_enum = 46;
|
||||
repeated Sub repeated_message = 47;
|
||||
repeated TestMessage repeated_recursive = 48;
|
||||
|
||||
oneof my_oneof {
|
||||
int32 oneof_int32 = 51;
|
||||
int64 oneof_int64 = 52;
|
||||
uint32 oneof_uint32 = 53;
|
||||
uint64 oneof_uint64 = 54;
|
||||
uint32 oneof_sint32 = 55;
|
||||
uint64 oneof_sint64 = 56;
|
||||
uint32 oneof_fixed32 = 57;
|
||||
uint64 oneof_fixed64 = 58;
|
||||
uint32 oneof_sfixed32 = 59;
|
||||
uint64 oneof_sfixed64 = 60;
|
||||
double oneof_double = 61;
|
||||
float oneof_float = 62;
|
||||
bool oneof_bool = 63;
|
||||
string oneof_string = 64;
|
||||
bytes oneof_bytes = 65;
|
||||
TestEnum oneof_enum = 66;
|
||||
Sub oneof_message = 67;
|
||||
}
|
||||
|
||||
map<int32, int32> map_int32_int32 = 71;
|
||||
map<int64, int64> map_int64_int64 = 72;
|
||||
map<uint32, uint32> map_uint32_uint32 = 73;
|
||||
map<uint64, uint64> map_uint64_uint64 = 74;
|
||||
map<sint32, sint32> map_sint32_sint32 = 75;
|
||||
map<sint64, sint64> map_sint64_sint64 = 76;
|
||||
map<fixed32, fixed32> map_fixed32_fixed32 = 77;
|
||||
map<fixed64, fixed64> map_fixed64_fixed64 = 78;
|
||||
map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 79;
|
||||
map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 80;
|
||||
map<int32, float> map_int32_float = 81;
|
||||
map<int32, double> map_int32_double = 82;
|
||||
map<bool, bool> map_bool_bool = 83;
|
||||
map<string, string> map_string_string = 84;
|
||||
map<int32, bytes> map_int32_bytes = 85;
|
||||
map<int32, TestEnum> map_int32_enum = 86;
|
||||
map<int32, Sub> map_int32_message = 87;
|
||||
|
||||
map<int32, TestMessage> map_recursive = 88;
|
||||
|
||||
message Sub {
|
||||
int32 a = 1;
|
||||
repeated int32 b = 2;
|
||||
}
|
||||
|
||||
// Reserved for non-existing field test.
|
||||
// int32 non_exist = 89;
|
||||
|
||||
NoNamespaceMessage optional_no_namespace_message = 91;
|
||||
NoNamespaceEnum optional_no_namespace_enum = 92;
|
||||
repeated NoNamespaceMessage repeated_no_namespace_message = 93;
|
||||
repeated NoNamespaceEnum repeated_no_namespace_enum = 94;
|
||||
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
}
|
||||
|
||||
NestedEnum optional_nested_enum = 101;
|
||||
|
||||
// Test prefix for reserved words.
|
||||
message Empty {
|
||||
int32 a = 1;
|
||||
}
|
||||
|
||||
reserved 111;
|
||||
|
||||
// Test map with missing message value
|
||||
map<string, TestMessage> map_string_message = 121;
|
||||
map<string, google.protobuf.Any> map_string_any = 122;
|
||||
map<string, google.protobuf.ListValue> map_string_list = 123;
|
||||
map<string, google.protobuf.Struct> map_string_struct = 124;
|
||||
|
||||
// deprecated field
|
||||
int32 deprecated_optional_int32 = 125 [deprecated=true];
|
||||
}
|
||||
|
||||
enum TestEnum {
|
||||
ZERO = 0;
|
||||
ONE = 1;
|
||||
TWO = 2;
|
||||
ECHO = 3; // Test reserved name.
|
||||
}
|
||||
|
||||
// Test prefix for reserved words.
|
||||
message Empty {
|
||||
int32 a = 1;
|
||||
}
|
||||
|
||||
message ARRAY {
|
||||
int32 a = 1;
|
||||
}
|
||||
|
||||
message TestPackedMessage {
|
||||
repeated int32 repeated_int32 = 90 [packed = true];
|
||||
repeated int64 repeated_int64 = 91 [packed = true];
|
||||
repeated uint32 repeated_uint32 = 92 [packed = true];
|
||||
repeated uint64 repeated_uint64 = 93 [packed = true];
|
||||
repeated sint32 repeated_sint32 = 94 [packed = true];
|
||||
repeated sint64 repeated_sint64 = 95 [packed = true];
|
||||
repeated fixed32 repeated_fixed32 = 96 [packed = true];
|
||||
repeated fixed64 repeated_fixed64 = 97 [packed = true];
|
||||
repeated sfixed32 repeated_sfixed32 = 98 [packed = true];
|
||||
repeated sfixed64 repeated_sfixed64 = 99 [packed = true];
|
||||
repeated float repeated_float = 100 [packed = true];
|
||||
repeated double repeated_double = 101 [packed = true];
|
||||
repeated bool repeated_bool = 102 [packed = true];
|
||||
repeated TestEnum repeated_enum = 103 [packed = true];
|
||||
}
|
||||
|
||||
// Need to be in sync with TestPackedMessage.
|
||||
message TestUnpackedMessage {
|
||||
repeated int32 repeated_int32 = 90 [packed = false];
|
||||
repeated int64 repeated_int64 = 91 [packed = false];
|
||||
repeated uint32 repeated_uint32 = 92 [packed = false];
|
||||
repeated uint64 repeated_uint64 = 93 [packed = false];
|
||||
repeated sint32 repeated_sint32 = 94 [packed = false];
|
||||
repeated sint64 repeated_sint64 = 95 [packed = false];
|
||||
repeated fixed32 repeated_fixed32 = 96 [packed = false];
|
||||
repeated fixed64 repeated_fixed64 = 97 [packed = false];
|
||||
repeated sfixed32 repeated_sfixed32 = 98 [packed = false];
|
||||
repeated sfixed64 repeated_sfixed64 = 99 [packed = false];
|
||||
repeated float repeated_float = 100 [packed = false];
|
||||
repeated double repeated_double = 101 [packed = false];
|
||||
repeated bool repeated_bool = 102 [packed = false];
|
||||
repeated TestEnum repeated_enum = 103 [packed = false];
|
||||
}
|
||||
|
||||
// /**/@<>&\{
|
||||
message TestPhpDoc {
|
||||
int32 a = 1;
|
||||
}
|
||||
|
||||
message TestIncludePrefixMessage {
|
||||
TestPrefix prefix_message = 1;
|
||||
}
|
||||
|
||||
message TestIncludeNamespaceMessage {
|
||||
TestNamespace namespace_message = 1;
|
||||
TestEmptyNamespace empty_namespace_message = 2;
|
||||
}
|
||||
|
||||
// This will cause upb fields not ordered by the order in the generated code.
|
||||
message TestRandomFieldOrder {
|
||||
int64 tag13 = 150;
|
||||
string tag14 = 160;
|
||||
}
|
||||
|
||||
message TestLargeFieldNumber {
|
||||
int32 large_field_number = 536870911;
|
||||
}
|
||||
|
||||
message TestReverseFieldOrder {
|
||||
repeated int32 a = 2;
|
||||
string b = 1;
|
||||
}
|
||||
|
||||
message testLowerCaseMessage {
|
||||
}
|
||||
|
||||
enum testLowerCaseEnum {
|
||||
VALUE = 0;
|
||||
}
|
||||
|
||||
message TestAny {
|
||||
google.protobuf.Any any = 1;
|
||||
}
|
||||
|
||||
message TestInt32Value {
|
||||
google.protobuf.Int32Value field = 1;
|
||||
repeated google.protobuf.Int32Value repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.Int32Value oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TestInt64Value {
|
||||
google.protobuf.Int64Value field = 1;
|
||||
repeated google.protobuf.Int64Value repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.Int64Value oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TestUInt32Value {
|
||||
google.protobuf.UInt32Value field = 1;
|
||||
repeated google.protobuf.UInt32Value repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.UInt32Value oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TestUInt64Value {
|
||||
google.protobuf.UInt64Value field = 1;
|
||||
repeated google.protobuf.UInt64Value repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.UInt64Value oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TestBoolValue {
|
||||
google.protobuf.BoolValue field = 1;
|
||||
repeated google.protobuf.BoolValue repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.BoolValue oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TestStringValue {
|
||||
google.protobuf.StringValue field = 1;
|
||||
repeated google.protobuf.StringValue repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.StringValue oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
map<int32, google.protobuf.StringValue> map_field = 5;
|
||||
}
|
||||
|
||||
message TestBytesValue {
|
||||
google.protobuf.BytesValue field = 1;
|
||||
repeated google.protobuf.BytesValue repeated_field = 2;
|
||||
oneof oneof_fields {
|
||||
google.protobuf.BytesValue oneof_field = 3;
|
||||
int32 int32_field = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message Test32Fields {
|
||||
optional uint32 id = 1;
|
||||
optional uint32 random_name_a0 = 2;
|
||||
optional uint32 random_name_a1 = 3;
|
||||
optional uint32 random_name_a2 = 4;
|
||||
optional uint32 random_name_a3 = 5;
|
||||
optional uint32 random_name_a4 = 6;
|
||||
optional uint32 random_name_a5 = 7;
|
||||
optional uint32 random_name_a6 = 8;
|
||||
optional uint32 random_name_a7 = 9;
|
||||
optional uint32 random_name_a8 = 10;
|
||||
optional uint32 random_name_a9 = 11;
|
||||
optional uint32 random_name_b0 = 12;
|
||||
optional uint32 random_name_b1 = 13;
|
||||
optional uint32 random_name_b2 = 14;
|
||||
optional uint32 random_name_b3 = 15;
|
||||
optional uint32 random_name_b4 = 16;
|
||||
optional uint32 random_name_b5 = 17;
|
||||
optional uint32 random_name_b6 = 18;
|
||||
optional uint32 random_name_b7 = 19;
|
||||
optional uint32 random_name_b8 = 20;
|
||||
optional uint32 random_name_b9 = 21;
|
||||
optional uint32 random_name_c0 = 22;
|
||||
optional uint32 random_name_c1 = 23;
|
||||
optional uint32 random_name_c2 = 24;
|
||||
optional uint32 random_name_c3 = 25;
|
||||
optional uint32 random_name_c4 = 26;
|
||||
optional uint32 random_name_c5 = 27;
|
||||
optional uint32 random_name_c6 = 28;
|
||||
optional uint32 random_name_c7 = 29;
|
||||
optional uint32 random_name_c8 = 30;
|
||||
optional uint32 random_name_c9 = 31;
|
||||
optional string version = 32;
|
||||
}
|
35
deps/protobuf/php/tests/proto/test_descriptors.proto
vendored
Normal file
35
deps/protobuf/php/tests/proto/test_descriptors.proto
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package descriptors;
|
||||
|
||||
message TestDescriptorsMessage {
|
||||
int32 optional_int32 = 1;
|
||||
TestDescriptorsEnum optional_enum = 16;
|
||||
Sub optional_message = 17;
|
||||
|
||||
// Repeated
|
||||
repeated int32 repeated_int32 = 31;
|
||||
repeated Sub repeated_message = 47;
|
||||
|
||||
oneof my_oneof {
|
||||
int32 oneof_int32 = 51;
|
||||
}
|
||||
|
||||
map<int32, EnumSub> map_int32_enum = 71;
|
||||
|
||||
message Sub {
|
||||
int32 a = 1;
|
||||
repeated int32 b = 2;
|
||||
}
|
||||
|
||||
enum EnumSub {
|
||||
ZERO = 0;
|
||||
ONE = 1;
|
||||
}
|
||||
}
|
||||
|
||||
enum TestDescriptorsEnum {
|
||||
ZERO = 0;
|
||||
ONE = 1;
|
||||
}
|
||||
|
19
deps/protobuf/php/tests/proto/test_empty_php_namespace.proto
vendored
Normal file
19
deps/protobuf/php/tests/proto/test_empty_php_namespace.proto
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package foo;
|
||||
option php_namespace = "";
|
||||
option php_metadata_namespace = "";
|
||||
|
||||
message TestEmptyNamespace {
|
||||
int32 a = 1;
|
||||
|
||||
// Test nested messages, enums, and reserved names
|
||||
NestedMessage nested_message = 2;
|
||||
NestedEnum nested_enum = 3;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
};
|
||||
}
|
16
deps/protobuf/php/tests/proto/test_import_descriptor_proto.proto
vendored
Normal file
16
deps/protobuf/php/tests/proto/test_import_descriptor_proto.proto
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package foo;
|
||||
|
||||
import "google/protobuf/descriptor.proto";
|
||||
|
||||
message TestImportDescriptorProto {
|
||||
extend google.protobuf.MethodOptions {
|
||||
int32 a = 72295727;
|
||||
}
|
||||
}
|
||||
|
||||
extend google.protobuf.MethodOptions {
|
||||
int32 a = 72295728;
|
||||
}
|
||||
|
18
deps/protobuf/php/tests/proto/test_include.proto
vendored
Normal file
18
deps/protobuf/php/tests/proto/test_include.proto
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package bar;
|
||||
|
||||
message TestInclude {
|
||||
int32 a = 1;
|
||||
}
|
||||
|
||||
message TestLegacyMessage {
|
||||
NestedMessage message = 1;
|
||||
NestedEnum enum = 2;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
}
|
||||
}
|
22
deps/protobuf/php/tests/proto/test_no_namespace.proto
vendored
Normal file
22
deps/protobuf/php/tests/proto/test_no_namespace.proto
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option php_metadata_namespace = "\\";
|
||||
|
||||
message NoNamespaceMessage {
|
||||
int32 a = 1;
|
||||
|
||||
// Test nested messages, enums, and reserved names
|
||||
NestedMessage nested_message = 2;
|
||||
NestedEnum nested_enum = 3;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
};
|
||||
}
|
||||
|
||||
enum NoNamespaceEnum {
|
||||
VALUE_A = 0;
|
||||
VALUE_B = 1;
|
||||
}
|
31
deps/protobuf/php/tests/proto/test_php_namespace.proto
vendored
Normal file
31
deps/protobuf/php/tests/proto/test_php_namespace.proto
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package foo;
|
||||
option php_namespace = "Php\\Test";
|
||||
option php_metadata_namespace = "Metadata\\Php\\Test";
|
||||
|
||||
message TestNamespace {
|
||||
int32 a = 1;
|
||||
|
||||
// Test nested messages, enums, and reserved names
|
||||
NestedMessage nested_message = 2;
|
||||
NestedEnum nested_enum = 3;
|
||||
Empty reserved_name = 4;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
};
|
||||
// Test reserved name
|
||||
message Empty {
|
||||
NestedMessage nested_message = 1;
|
||||
NestedEnum nested_enum = 2;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
};
|
||||
}
|
||||
}
|
20
deps/protobuf/php/tests/proto/test_prefix.proto
vendored
Normal file
20
deps/protobuf/php/tests/proto/test_prefix.proto
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option php_class_prefix = "Prefix";
|
||||
|
||||
message TestPrefix {
|
||||
int32 a = 1;
|
||||
NestedMessage nested_message = 2;
|
||||
NestedEnum nested_enum = 3;
|
||||
message NestedMessage {
|
||||
int32 a = 1;
|
||||
}
|
||||
enum NestedEnum {
|
||||
ZERO = 0;
|
||||
};
|
||||
}
|
||||
|
||||
// Test prefix for reserved words.
|
||||
message Empty {
|
||||
int32 a = 1;
|
||||
}
|
83
deps/protobuf/php/tests/proto/test_reserved_enum_lower.proto
vendored
Normal file
83
deps/protobuf/php/tests/proto/test_reserved_enum_lower.proto
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package lower_enum;
|
||||
|
||||
enum abstract { ZERO1 = 0; }
|
||||
enum and { ZERO2 = 0; }
|
||||
enum array { ZERO3 = 0; }
|
||||
enum as { ZERO4 = 0; }
|
||||
enum break { ZERO5 = 0; }
|
||||
enum callable { ZERO6 = 0; }
|
||||
enum case { ZERO7 = 0; }
|
||||
enum catch { ZERO8 = 0; }
|
||||
enum class { ZERO9 = 0; }
|
||||
enum clone { ZERO10 = 0; }
|
||||
enum const { ZERO11 = 0; }
|
||||
enum continue { ZERO12 = 0; }
|
||||
enum declare { ZERO13 = 0; }
|
||||
enum default { ZERO14 = 0; }
|
||||
enum die { ZERO15 = 0; }
|
||||
enum do { ZERO16 = 0; }
|
||||
enum echo { ZERO17 = 0; }
|
||||
enum else { ZERO18 = 0; }
|
||||
enum elseif { ZERO19 = 0; }
|
||||
enum empty { ZERO20 = 0; }
|
||||
enum enddeclare { ZERO21 = 0; }
|
||||
enum endfor { ZERO22 = 0; }
|
||||
enum endforeach { ZERO23 = 0; }
|
||||
enum endif { ZERO24 = 0; }
|
||||
enum endswitch { ZERO25 = 0; }
|
||||
enum endwhile { ZERO26 = 0; }
|
||||
enum eval { ZERO27 = 0; }
|
||||
enum exit { ZERO28 = 0; }
|
||||
enum extends { ZERO29 = 0; }
|
||||
enum final { ZERO30 = 0; }
|
||||
enum finally { ZERO31 = 0; }
|
||||
enum fn { ZERO32 = 0; }
|
||||
enum for { ZERO33 = 0; }
|
||||
enum foreach { ZERO34 = 0; }
|
||||
enum function { ZERO35 = 0; }
|
||||
enum global { ZERO36 = 0; }
|
||||
enum goto { ZERO37 = 0; }
|
||||
enum if { ZERO38 = 0; }
|
||||
enum implements { ZERO39 = 0; }
|
||||
enum include { ZERO40 = 0; }
|
||||
enum include_once { ZERO41 = 0; }
|
||||
enum instanceof { ZERO42 = 0; }
|
||||
enum insteadof { ZERO43 = 0; }
|
||||
enum interface { ZERO44 = 0; }
|
||||
enum isset { ZERO45 = 0; }
|
||||
enum list { ZERO46 = 0; }
|
||||
enum match { ZERO47 = 0; }
|
||||
enum namespace { ZERO48 = 0; }
|
||||
enum new { ZERO49 = 0; }
|
||||
enum or { ZERO50 = 0; }
|
||||
enum parent { ZERO78 = 0; }
|
||||
enum print { ZERO51 = 0; }
|
||||
enum private { ZERO52 = 0; }
|
||||
enum protected { ZERO53 = 0; }
|
||||
enum public { ZERO54 = 0; }
|
||||
enum require { ZERO55 = 0; }
|
||||
enum require_once { ZERO56 = 0; }
|
||||
enum return { ZERO57 = 0; }
|
||||
enum self { ZERO79 = 0; }
|
||||
enum static { ZERO58 = 0; }
|
||||
enum switch { ZERO59 = 0; }
|
||||
enum throw { ZERO60 = 0; }
|
||||
enum trait { ZERO61 = 0; }
|
||||
enum try { ZERO62 = 0; }
|
||||
enum unset { ZERO63 = 0; }
|
||||
enum use { ZERO64 = 0; }
|
||||
enum var { ZERO65 = 0; }
|
||||
enum while { ZERO66 = 0; }
|
||||
enum xor { ZERO67 = 0; }
|
||||
enum yield { ZERO68 = 0; }
|
||||
enum int { ZERO69 = 0; }
|
||||
enum float { ZERO70 = 0; }
|
||||
enum bool { ZERO71 = 0; }
|
||||
enum string { ZERO72 = 0; }
|
||||
enum true { ZERO73 = 0; }
|
||||
enum false { ZERO74 = 0; }
|
||||
enum null { ZERO75 = 0; }
|
||||
enum void { ZERO76 = 0; }
|
||||
enum iterable { ZERO77 = 0; }
|
83
deps/protobuf/php/tests/proto/test_reserved_enum_upper.proto
vendored
Normal file
83
deps/protobuf/php/tests/proto/test_reserved_enum_upper.proto
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package upper_enum;
|
||||
|
||||
enum ABSTRACT { ZERO1 = 0; }
|
||||
enum AND { ZERO2 = 0; }
|
||||
enum ARRAY { ZERO3 = 0; }
|
||||
enum AS { ZERO4 = 0; }
|
||||
enum BREAK { ZERO5 = 0; }
|
||||
enum CALLABLE { ZERO6 = 0; }
|
||||
enum CASE { ZERO7 = 0; }
|
||||
enum CATCH { ZERO8 = 0; }
|
||||
enum CLASS { ZERO9 = 0; }
|
||||
enum CLONE { ZERO10 = 0; }
|
||||
enum CONST { ZERO11 = 0; }
|
||||
enum CONTINUE { ZERO12 = 0; }
|
||||
enum DECLARE { ZERO13 = 0; }
|
||||
enum DEFAULT { ZERO14 = 0; }
|
||||
enum DIE { ZERO15 = 0; }
|
||||
enum DO { ZERO16 = 0; }
|
||||
enum ECHO { ZERO17 = 0; }
|
||||
enum ELSE { ZERO18 = 0; }
|
||||
enum ELSEIF { ZERO19 = 0; }
|
||||
enum EMPTY { ZERO20 = 0; }
|
||||
enum ENDDECLARE { ZERO21 = 0; }
|
||||
enum ENDFOR { ZERO22 = 0; }
|
||||
enum ENDFOREACH { ZERO23 = 0; }
|
||||
enum ENDIF { ZERO24 = 0; }
|
||||
enum ENDSWITCH { ZERO25 = 0; }
|
||||
enum ENDWHILE { ZERO26 = 0; }
|
||||
enum EVAL { ZERO27 = 0; }
|
||||
enum EXIT { ZERO28 = 0; }
|
||||
enum EXTENDS { ZERO29 = 0; }
|
||||
enum FINAL { ZERO30 = 0; }
|
||||
enum FINALLY { ZERO31 = 0; }
|
||||
enum FN { ZERO32 = 0; }
|
||||
enum FOR { ZERO33 = 0; }
|
||||
enum FOREACH { ZERO34 = 0; }
|
||||
enum FUNCTION { ZERO35 = 0; }
|
||||
enum GLOBAL { ZERO36 = 0; }
|
||||
enum GOTO { ZERO37 = 0; }
|
||||
enum IF { ZERO38 = 0; }
|
||||
enum IMPLEMENTS { ZERO39 = 0; }
|
||||
enum INCLUDE { ZERO40 = 0; }
|
||||
enum INCLUDE_ONCE { ZERO41 = 0; }
|
||||
enum INSTANCEOF { ZERO42 = 0; }
|
||||
enum INSTEADOF { ZERO43 = 0; }
|
||||
enum INTERFACE { ZERO44 = 0; }
|
||||
enum ISSET { ZERO45 = 0; }
|
||||
enum LIST { ZERO46 = 0; }
|
||||
enum MATCH { ZERO47 = 0; }
|
||||
enum NAMESPACE { ZERO48 = 0; }
|
||||
enum NEW { ZERO49 = 0; }
|
||||
enum OR { ZERO50 = 0; }
|
||||
enum PARENT { ZERO78 = 0; }
|
||||
enum PRINT { ZERO51 = 0; }
|
||||
enum PRIVATE { ZERO52 = 0; }
|
||||
enum PROTECTED { ZERO53 = 0; }
|
||||
enum PUBLIC { ZERO54 = 0; }
|
||||
enum REQUIRE { ZERO55 = 0; }
|
||||
enum REQUIRE_ONCE { ZERO56 = 0; }
|
||||
enum RETURN { ZERO57 = 0; }
|
||||
enum SELF { ZERO79 = 0; }
|
||||
enum STATIC { ZERO58 = 0; }
|
||||
enum SWITCH { ZERO59 = 0; }
|
||||
enum THROW { ZERO60 = 0; }
|
||||
enum TRAIT { ZERO61 = 0; }
|
||||
enum TRY { ZERO62 = 0; }
|
||||
enum UNSET { ZERO63 = 0; }
|
||||
enum USE { ZERO64 = 0; }
|
||||
enum VAR { ZERO65 = 0; }
|
||||
enum WHILE { ZERO66 = 0; }
|
||||
enum XOR { ZERO67 = 0; }
|
||||
enum YIELD { ZERO68 = 0; }
|
||||
enum INT { ZERO69 = 0; }
|
||||
enum FLOAT { ZERO70 = 0; }
|
||||
enum BOOL { ZERO71 = 0; }
|
||||
enum STRING { ZERO72 = 0; }
|
||||
enum TRUE { ZERO73 = 0; }
|
||||
enum FALSE { ZERO74 = 0; }
|
||||
enum NULL { ZERO75 = 0; }
|
||||
enum VOID { ZERO76 = 0; }
|
||||
enum ITERABLE { ZERO77 = 0; }
|
85
deps/protobuf/php/tests/proto/test_reserved_enum_value_lower.proto
vendored
Normal file
85
deps/protobuf/php/tests/proto/test_reserved_enum_value_lower.proto
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package lower_enum_value;
|
||||
|
||||
enum NotAllowed {
|
||||
abstract = 0;
|
||||
and = 1;
|
||||
array = 2;
|
||||
as = 3;
|
||||
break = 4;
|
||||
callable = 5;
|
||||
case = 6;
|
||||
catch = 7;
|
||||
class = 8;
|
||||
clone = 9;
|
||||
const = 10;
|
||||
continue = 11;
|
||||
declare = 12;
|
||||
default = 13;
|
||||
die = 14;
|
||||
do = 15;
|
||||
echo = 16;
|
||||
else = 17;
|
||||
elseif = 18;
|
||||
empty = 19;
|
||||
enddeclare = 20;
|
||||
endfor = 21;
|
||||
endforeach = 22;
|
||||
endif = 23;
|
||||
endswitch = 24;
|
||||
endwhile = 25;
|
||||
eval = 26;
|
||||
exit = 27;
|
||||
extends = 28;
|
||||
final = 29;
|
||||
finally = 30;
|
||||
fn = 31;
|
||||
for = 32;
|
||||
foreach = 33;
|
||||
function = 34;
|
||||
global = 35;
|
||||
goto = 36;
|
||||
if = 37;
|
||||
implements = 38;
|
||||
include = 39;
|
||||
include_once = 40;
|
||||
instanceof = 41;
|
||||
insteadof = 42;
|
||||
interface = 43;
|
||||
isset = 44;
|
||||
list = 45;
|
||||
match = 46;
|
||||
namespace = 47;
|
||||
new = 48;
|
||||
or = 49;
|
||||
parent = 77;
|
||||
print = 50;
|
||||
private = 51;
|
||||
protected = 52;
|
||||
public = 53;
|
||||
require = 54;
|
||||
require_once = 55;
|
||||
return = 56;
|
||||
self = 78;
|
||||
static = 57;
|
||||
switch = 58;
|
||||
throw = 59;
|
||||
trait = 60;
|
||||
try = 61;
|
||||
unset = 62;
|
||||
use = 63;
|
||||
var = 64;
|
||||
while = 65;
|
||||
xor = 66;
|
||||
yield = 67;
|
||||
int = 68;
|
||||
float = 69;
|
||||
bool = 70;
|
||||
string = 71;
|
||||
true = 72;
|
||||
false = 73;
|
||||
null = 74;
|
||||
void = 75;
|
||||
iterable = 76;
|
||||
}
|
85
deps/protobuf/php/tests/proto/test_reserved_enum_value_upper.proto
vendored
Normal file
85
deps/protobuf/php/tests/proto/test_reserved_enum_value_upper.proto
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package upper_enum_value;
|
||||
|
||||
enum NotAllowed {
|
||||
ABSTRACT = 0;
|
||||
AND = 1;
|
||||
ARRAY = 2;
|
||||
AS = 3;
|
||||
BREAK = 4;
|
||||
CALLABLE = 5;
|
||||
CASE = 6;
|
||||
CATCH = 7;
|
||||
CLASS = 8;
|
||||
CLONE = 9;
|
||||
CONST = 10;
|
||||
CONTINUE = 11;
|
||||
DECLARE = 12;
|
||||
DEFAULT = 13;
|
||||
DIE = 14;
|
||||
DO = 15;
|
||||
ECHO = 16;
|
||||
ELSE = 17;
|
||||
ELSEIF = 18;
|
||||
EMPTY = 19;
|
||||
ENDDECLARE = 20;
|
||||
ENDFOR = 21;
|
||||
ENDFOREACH = 22;
|
||||
ENDIF = 23;
|
||||
ENDSWITCH = 24;
|
||||
ENDWHILE = 25;
|
||||
EVAL = 26;
|
||||
EXIT = 27;
|
||||
EXTENDS = 28;
|
||||
FINAL = 29;
|
||||
FINALLY = 30;
|
||||
FOR = 31;
|
||||
FOREACH = 32;
|
||||
FUNCTION = 33;
|
||||
FN = 34;
|
||||
GLOBAL = 35;
|
||||
GOTO = 36;
|
||||
IF = 37;
|
||||
IMPLEMENTS = 38;
|
||||
INCLUDE = 39;
|
||||
INCLUDE_ONCE = 40;
|
||||
INSTANCEOF = 41;
|
||||
INSTEADOF = 42;
|
||||
INTERFACE = 43;
|
||||
ISSET = 44;
|
||||
LIST = 45;
|
||||
MATCH = 46;
|
||||
NAMESPACE = 47;
|
||||
NEW = 48;
|
||||
OR = 49;
|
||||
PARENT = 77;
|
||||
PRINT = 50;
|
||||
PRIVATE = 51;
|
||||
PROTECTED = 52;
|
||||
PUBLIC = 53;
|
||||
REQUIRE = 54;
|
||||
REQUIRE_ONCE = 55;
|
||||
RETURN = 56;
|
||||
SELF = 78;
|
||||
STATIC = 57;
|
||||
SWITCH = 58;
|
||||
THROW = 59;
|
||||
TRAIT = 60;
|
||||
TRY = 61;
|
||||
UNSET = 62;
|
||||
USE = 63;
|
||||
VAR = 64;
|
||||
WHILE = 65;
|
||||
XOR = 66;
|
||||
YIELD = 67;
|
||||
INT = 68;
|
||||
FLOAT = 69;
|
||||
BOOL = 70;
|
||||
STRING = 71;
|
||||
TRUE = 72;
|
||||
FALSE = 73;
|
||||
NULL = 74;
|
||||
VOID = 75;
|
||||
ITERABLE = 76;
|
||||
}
|
83
deps/protobuf/php/tests/proto/test_reserved_message_lower.proto
vendored
Normal file
83
deps/protobuf/php/tests/proto/test_reserved_message_lower.proto
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package lower;
|
||||
|
||||
message abstract {}
|
||||
message and {}
|
||||
message array {}
|
||||
message as {}
|
||||
message break {}
|
||||
message callable {}
|
||||
message case {}
|
||||
message catch {}
|
||||
message class {}
|
||||
message clone {}
|
||||
message const {}
|
||||
message continue {}
|
||||
message declare {}
|
||||
message default {}
|
||||
message die {}
|
||||
message do {}
|
||||
message echo {}
|
||||
message else {}
|
||||
message elseif {}
|
||||
message empty {}
|
||||
message enddeclare {}
|
||||
message endfor {}
|
||||
message endforeach {}
|
||||
message endif {}
|
||||
message endswitch {}
|
||||
message endwhile {}
|
||||
message eval {}
|
||||
message exit {}
|
||||
message extends {}
|
||||
message final {}
|
||||
message finally {}
|
||||
message fn {}
|
||||
message for {}
|
||||
message foreach {}
|
||||
message function {}
|
||||
message global {}
|
||||
message goto {}
|
||||
message if {}
|
||||
message implements {}
|
||||
message include {}
|
||||
message include_once {}
|
||||
message instanceof {}
|
||||
message insteadof {}
|
||||
message interface {}
|
||||
message isset {}
|
||||
message list {}
|
||||
message match {}
|
||||
message namespace {}
|
||||
message new {}
|
||||
message or {}
|
||||
message parent {}
|
||||
message print {}
|
||||
message private {}
|
||||
message protected {}
|
||||
message public {}
|
||||
message require {}
|
||||
message require_once {}
|
||||
message return {}
|
||||
message self {}
|
||||
message static {}
|
||||
message switch {}
|
||||
message throw {}
|
||||
message trait {}
|
||||
message try {}
|
||||
message unset {}
|
||||
message use {}
|
||||
message var {}
|
||||
message while {}
|
||||
message xor {}
|
||||
message yield {}
|
||||
message int {}
|
||||
message float {}
|
||||
message bool {}
|
||||
message string {}
|
||||
message true {}
|
||||
message false {}
|
||||
message null {}
|
||||
message void {}
|
||||
message iterable {}
|
83
deps/protobuf/php/tests/proto/test_reserved_message_upper.proto
vendored
Normal file
83
deps/protobuf/php/tests/proto/test_reserved_message_upper.proto
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package upper;
|
||||
|
||||
message ABSTRACT {}
|
||||
message AND {}
|
||||
message ARRAY {}
|
||||
message AS {}
|
||||
message BREAK {}
|
||||
message CALLABLE {}
|
||||
message CASE {}
|
||||
message CATCH {}
|
||||
message CLASS {}
|
||||
message CLONE {}
|
||||
message CONST {}
|
||||
message CONTINUE {}
|
||||
message DECLARE {}
|
||||
message DEFAULT {}
|
||||
message DIE {}
|
||||
message DO {}
|
||||
message ECHO {}
|
||||
message ELSE {}
|
||||
message ELSEIF {}
|
||||
message EMPTY {}
|
||||
message ENDDECLARE {}
|
||||
message ENDFOR {}
|
||||
message ENDFOREACH {}
|
||||
message ENDIF {}
|
||||
message ENDSWITCH {}
|
||||
message ENDWHILE {}
|
||||
message EVAL {}
|
||||
message EXIT {}
|
||||
message EXTENDS {}
|
||||
message FINAL {}
|
||||
message FINALLY {}
|
||||
message FN {}
|
||||
message FOR {}
|
||||
message FOREACH {}
|
||||
message FUNCTION {}
|
||||
message GLOBAL {}
|
||||
message GOTO {}
|
||||
message IF {}
|
||||
message IMPLEMENTS {}
|
||||
message INCLUDE {}
|
||||
message INCLUDE_ONCE {}
|
||||
message INSTANCEOF {}
|
||||
message INSTEADOF {}
|
||||
message INTERFACE {}
|
||||
message ISSET {}
|
||||
message LIST {}
|
||||
message MATCH {}
|
||||
message NAMESPACE {}
|
||||
message NEW {}
|
||||
message OR {}
|
||||
message PARENT {}
|
||||
message PRINT {}
|
||||
message PRIVATE {}
|
||||
message PROTECTED {}
|
||||
message PUBLIC {}
|
||||
message REQUIRE {}
|
||||
message REQUIRE_ONCE {}
|
||||
message RETURN {}
|
||||
message SELF {}
|
||||
message STATIC {}
|
||||
message SWITCH {}
|
||||
message THROW {}
|
||||
message TRAIT {}
|
||||
message TRY {}
|
||||
message UNSET {}
|
||||
message USE {}
|
||||
message VAR {}
|
||||
message WHILE {}
|
||||
message XOR {}
|
||||
message YIELD {}
|
||||
message INT {}
|
||||
message FLOAT {}
|
||||
message BOOL {}
|
||||
message STRING {}
|
||||
message TRUE {}
|
||||
message FALSE {}
|
||||
message NULL {}
|
||||
message VOID {}
|
||||
message ITERABLE {}
|
18
deps/protobuf/php/tests/proto/test_service.proto
vendored
Normal file
18
deps/protobuf/php/tests/proto/test_service.proto
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package foo;
|
||||
|
||||
option php_generic_services = true;
|
||||
|
||||
service Greeter {
|
||||
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
||||
rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
13
deps/protobuf/php/tests/proto/test_service_namespace.proto
vendored
Normal file
13
deps/protobuf/php/tests/proto/test_service_namespace.proto
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "proto/test_service.proto";
|
||||
|
||||
package foo;
|
||||
|
||||
option php_generic_services = true;
|
||||
option php_namespace = "Bar";
|
||||
|
||||
service OtherGreeter {
|
||||
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
||||
rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
|
||||
}
|
26
deps/protobuf/php/tests/proto/test_wrapper_type_setters.proto
vendored
Normal file
26
deps/protobuf/php/tests/proto/test_wrapper_type_setters.proto
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
package foo;
|
||||
|
||||
message TestWrapperSetters {
|
||||
google.protobuf.DoubleValue double_value = 1;
|
||||
google.protobuf.FloatValue float_value = 2;
|
||||
google.protobuf.Int64Value int64_value = 3;
|
||||
google.protobuf.UInt64Value uint64_value = 4;
|
||||
google.protobuf.Int32Value int32_value = 5;
|
||||
google.protobuf.UInt32Value uint32_value = 6;
|
||||
google.protobuf.BoolValue bool_value = 7;
|
||||
google.protobuf.StringValue string_value = 8;
|
||||
google.protobuf.BytesValue bytes_value = 9;
|
||||
|
||||
oneof wrapped_oneofs {
|
||||
google.protobuf.DoubleValue double_value_oneof = 10;
|
||||
google.protobuf.StringValue string_value_oneof = 11;
|
||||
}
|
||||
|
||||
repeated google.protobuf.StringValue repeated_string_value = 12;
|
||||
|
||||
map<string, google.protobuf.StringValue> map_string_value = 13;
|
||||
}
|
367
deps/protobuf/php/tests/test_base.php
vendored
Normal file
367
deps/protobuf/php/tests/test_base.php
vendored
Normal file
@ -0,0 +1,367 @@
|
||||
<?php
|
||||
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestEnum;
|
||||
use Foo\TestMessage\Sub;
|
||||
|
||||
class TestBase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function setFields(TestMessage $m)
|
||||
{
|
||||
TestUtil::setTestMessage($m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Polyfill for phpunit6.
|
||||
*/
|
||||
static public function assertStringContains($needle, $haystack)
|
||||
{
|
||||
if (function_exists('PHPUnit\Framework\assertStringContainsString')) {
|
||||
parent::assertStringContainsString($needle, $haystack);
|
||||
} else {
|
||||
parent::assertContains($needle, $haystack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Polyfill for phpunit6.
|
||||
*/
|
||||
static public function assertFloatEquals($expected, $actual, $delta)
|
||||
{
|
||||
if (function_exists('PHPUnit\Framework\assertEqualsWithDelta')) {
|
||||
parent::assertEqualsWithDelta($expected, $actual, $delta);
|
||||
} else {
|
||||
parent::assertEquals($expected, $actual, '', $delta);
|
||||
}
|
||||
}
|
||||
|
||||
public function setFields2(TestMessage $m)
|
||||
{
|
||||
TestUtil::setTestMessage2($m);
|
||||
}
|
||||
|
||||
public function expectFields(TestMessage $m)
|
||||
{
|
||||
$this->assertSame(-42, $m->getOptionalInt32());
|
||||
$this->assertSame(42, $m->getOptionalUint32());
|
||||
$this->assertSame(-44, $m->getOptionalSint32());
|
||||
$this->assertSame(46, $m->getOptionalFixed32());
|
||||
$this->assertSame(-46, $m->getOptionalSfixed32());
|
||||
$this->assertSame(1.5, $m->getOptionalFloat());
|
||||
$this->assertSame(1.6, $m->getOptionalDouble());
|
||||
$this->assertSame(true, $m->getOptionalBool());
|
||||
$this->assertSame('a', $m->getOptionalString());
|
||||
$this->assertSame('bbbb', $m->getOptionalBytes());
|
||||
$this->assertSame(TestEnum::ONE, $m->getOptionalEnum());
|
||||
$this->assertSame(33, $m->getOptionalMessage()->getA());
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('-43', $m->getOptionalInt64());
|
||||
$this->assertSame('43', $m->getOptionalUint64());
|
||||
$this->assertSame('-45', $m->getOptionalSint64());
|
||||
$this->assertSame('47', $m->getOptionalFixed64());
|
||||
$this->assertSame('-47', $m->getOptionalSfixed64());
|
||||
} else {
|
||||
$this->assertSame(-43, $m->getOptionalInt64());
|
||||
$this->assertSame(43, $m->getOptionalUint64());
|
||||
$this->assertSame(-45, $m->getOptionalSint64());
|
||||
$this->assertSame(47, $m->getOptionalFixed64());
|
||||
$this->assertSame(-47, $m->getOptionalSfixed64());
|
||||
}
|
||||
|
||||
$this->assertEquals(-42, $m->getRepeatedInt32()[0]);
|
||||
$this->assertEquals(42, $m->getRepeatedUint32()[0]);
|
||||
$this->assertEquals(-43, $m->getRepeatedInt64()[0]);
|
||||
$this->assertEquals(43, $m->getRepeatedUint64()[0]);
|
||||
$this->assertEquals(-44, $m->getRepeatedSint32()[0]);
|
||||
$this->assertEquals(-45, $m->getRepeatedSint64()[0]);
|
||||
$this->assertEquals(46, $m->getRepeatedFixed32()[0]);
|
||||
$this->assertEquals(47, $m->getRepeatedFixed64()[0]);
|
||||
$this->assertEquals(-46, $m->getRepeatedSfixed32()[0]);
|
||||
$this->assertEquals(-47, $m->getRepeatedSfixed64()[0]);
|
||||
$this->assertEquals(1.5, $m->getRepeatedFloat()[0]);
|
||||
$this->assertEquals(1.6, $m->getRepeatedDouble()[0]);
|
||||
$this->assertEquals(true, $m->getRepeatedBool()[0]);
|
||||
$this->assertEquals('a', $m->getRepeatedString()[0]);
|
||||
$this->assertEquals('bbbb', $m->getRepeatedBytes()[0]);
|
||||
$this->assertEquals(34, $m->getRepeatedMessage()[0]->GetA());
|
||||
|
||||
$this->assertEquals(-52, $m->getRepeatedInt32()[1]);
|
||||
$this->assertEquals(52, $m->getRepeatedUint32()[1]);
|
||||
$this->assertEquals(-53, $m->getRepeatedInt64()[1]);
|
||||
$this->assertEquals(53, $m->getRepeatedUint64()[1]);
|
||||
$this->assertEquals(-54, $m->getRepeatedSint32()[1]);
|
||||
$this->assertEquals(-55, $m->getRepeatedSint64()[1]);
|
||||
$this->assertEquals(56, $m->getRepeatedFixed32()[1]);
|
||||
$this->assertEquals(57, $m->getRepeatedFixed64()[1]);
|
||||
$this->assertEquals(-56, $m->getRepeatedSfixed32()[1]);
|
||||
$this->assertEquals(-57, $m->getRepeatedSfixed64()[1]);
|
||||
$this->assertEquals(2.5, $m->getRepeatedFloat()[1]);
|
||||
$this->assertEquals(2.6, $m->getRepeatedDouble()[1]);
|
||||
$this->assertEquals(false, $m->getRepeatedBool()[1]);
|
||||
$this->assertEquals('c', $m->getRepeatedString()[1]);
|
||||
$this->assertEquals('dddd', $m->getRepeatedBytes()[1]);
|
||||
$this->assertEquals(35, $m->getRepeatedMessage()[1]->GetA());
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertEquals('-63', $m->getMapInt64Int64()['-63']);
|
||||
$this->assertEquals('63', $m->getMapUint64Uint64()['63']);
|
||||
$this->assertEquals('-65', $m->getMapSint64Sint64()['-65']);
|
||||
$this->assertEquals('67', $m->getMapFixed64Fixed64()['67']);
|
||||
$this->assertEquals('-69', $m->getMapSfixed64Sfixed64()['-69']);
|
||||
} else {
|
||||
$this->assertEquals(-63, $m->getMapInt64Int64()[-63]);
|
||||
$this->assertEquals(63, $m->getMapUint64Uint64()[63]);
|
||||
$this->assertEquals(-65, $m->getMapSint64Sint64()[-65]);
|
||||
$this->assertEquals(67, $m->getMapFixed64Fixed64()[67]);
|
||||
$this->assertEquals(-69, $m->getMapSfixed64Sfixed64()[-69]);
|
||||
}
|
||||
$this->assertEquals(-62, $m->getMapInt32Int32()[-62]);
|
||||
$this->assertEquals(62, $m->getMapUint32Uint32()[62]);
|
||||
$this->assertEquals(-64, $m->getMapSint32Sint32()[-64]);
|
||||
$this->assertEquals(66, $m->getMapFixed32Fixed32()[66]);
|
||||
$this->assertEquals(-68, $m->getMapSfixed32Sfixed32()[-68]);
|
||||
$this->assertEquals(3.5, $m->getMapInt32Float()[1]);
|
||||
$this->assertEquals(3.6, $m->getMapInt32Double()[1]);
|
||||
$this->assertEquals(true , $m->getMapBoolBool()[true]);
|
||||
$this->assertEquals('e', $m->getMapStringString()['e']);
|
||||
$this->assertEquals('ffff', $m->getMapInt32Bytes()[1]);
|
||||
$this->assertEquals(TestEnum::ONE, $m->getMapInt32Enum()[1]);
|
||||
$this->assertEquals(36, $m->getMapInt32Message()[1]->GetA());
|
||||
}
|
||||
|
||||
// Test message merged from setFields and setFields2.
|
||||
public function expectFieldsMerged(TestMessage $m)
|
||||
{
|
||||
$this->assertSame(-144, $m->getOptionalSint32());
|
||||
$this->assertSame(146, $m->getOptionalFixed32());
|
||||
$this->assertSame(-146, $m->getOptionalSfixed32());
|
||||
$this->assertSame(11.5, $m->getOptionalFloat());
|
||||
$this->assertSame(11.6, $m->getOptionalDouble());
|
||||
$this->assertSame(true, $m->getOptionalBool());
|
||||
$this->assertSame('aa', $m->getOptionalString());
|
||||
$this->assertSame('bb', $m->getOptionalBytes());
|
||||
$this->assertSame(133, $m->getOptionalMessage()->getA());
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame('-143', $m->getOptionalInt64());
|
||||
$this->assertSame('143', $m->getOptionalUint64());
|
||||
$this->assertSame('-145', $m->getOptionalSint64());
|
||||
$this->assertSame('147', $m->getOptionalFixed64());
|
||||
$this->assertSame('-147', $m->getOptionalSfixed64());
|
||||
} else {
|
||||
$this->assertSame(-143, $m->getOptionalInt64());
|
||||
$this->assertSame(143, $m->getOptionalUint64());
|
||||
$this->assertSame(-145, $m->getOptionalSint64());
|
||||
$this->assertSame(147, $m->getOptionalFixed64());
|
||||
$this->assertSame(-147, $m->getOptionalSfixed64());
|
||||
}
|
||||
|
||||
$this->assertEquals(-42, $m->getRepeatedInt32()[0]);
|
||||
$this->assertEquals(42, $m->getRepeatedUint32()[0]);
|
||||
$this->assertEquals(-43, $m->getRepeatedInt64()[0]);
|
||||
$this->assertEquals(43, $m->getRepeatedUint64()[0]);
|
||||
$this->assertEquals(-44, $m->getRepeatedSint32()[0]);
|
||||
$this->assertEquals(-45, $m->getRepeatedSint64()[0]);
|
||||
$this->assertEquals(46, $m->getRepeatedFixed32()[0]);
|
||||
$this->assertEquals(47, $m->getRepeatedFixed64()[0]);
|
||||
$this->assertEquals(-46, $m->getRepeatedSfixed32()[0]);
|
||||
$this->assertEquals(-47, $m->getRepeatedSfixed64()[0]);
|
||||
$this->assertEquals(1.5, $m->getRepeatedFloat()[0]);
|
||||
$this->assertEquals(1.6, $m->getRepeatedDouble()[0]);
|
||||
$this->assertEquals(true, $m->getRepeatedBool()[0]);
|
||||
$this->assertEquals('a', $m->getRepeatedString()[0]);
|
||||
$this->assertEquals('bbbb', $m->getRepeatedBytes()[0]);
|
||||
$this->assertEquals(TestEnum::ZERO, $m->getRepeatedEnum()[0]);
|
||||
$this->assertEquals(34, $m->getRepeatedMessage()[0]->GetA());
|
||||
|
||||
$this->assertEquals(-52, $m->getRepeatedInt32()[1]);
|
||||
$this->assertEquals(52, $m->getRepeatedUint32()[1]);
|
||||
$this->assertEquals(-53, $m->getRepeatedInt64()[1]);
|
||||
$this->assertEquals(53, $m->getRepeatedUint64()[1]);
|
||||
$this->assertEquals(-54, $m->getRepeatedSint32()[1]);
|
||||
$this->assertEquals(-55, $m->getRepeatedSint64()[1]);
|
||||
$this->assertEquals(56, $m->getRepeatedFixed32()[1]);
|
||||
$this->assertEquals(57, $m->getRepeatedFixed64()[1]);
|
||||
$this->assertEquals(-56, $m->getRepeatedSfixed32()[1]);
|
||||
$this->assertEquals(-57, $m->getRepeatedSfixed64()[1]);
|
||||
$this->assertEquals(2.5, $m->getRepeatedFloat()[1]);
|
||||
$this->assertEquals(2.6, $m->getRepeatedDouble()[1]);
|
||||
$this->assertEquals(false, $m->getRepeatedBool()[1]);
|
||||
$this->assertEquals('c', $m->getRepeatedString()[1]);
|
||||
$this->assertEquals('dddd', $m->getRepeatedBytes()[1]);
|
||||
$this->assertEquals(TestEnum::ONE, $m->getRepeatedEnum()[1]);
|
||||
$this->assertEquals(35, $m->getRepeatedMessage()[1]->GetA());
|
||||
|
||||
$this->assertEquals(-142, $m->getRepeatedInt32()[2]);
|
||||
$this->assertEquals(142, $m->getRepeatedUint32()[2]);
|
||||
$this->assertEquals(-143, $m->getRepeatedInt64()[2]);
|
||||
$this->assertEquals(143, $m->getRepeatedUint64()[2]);
|
||||
$this->assertEquals(-144, $m->getRepeatedSint32()[2]);
|
||||
$this->assertEquals(-145, $m->getRepeatedSint64()[2]);
|
||||
$this->assertEquals(146, $m->getRepeatedFixed32()[2]);
|
||||
$this->assertEquals(147, $m->getRepeatedFixed64()[2]);
|
||||
$this->assertEquals(-146, $m->getRepeatedSfixed32()[2]);
|
||||
$this->assertEquals(-147, $m->getRepeatedSfixed64()[2]);
|
||||
$this->assertEquals(11.5, $m->getRepeatedFloat()[2]);
|
||||
$this->assertEquals(11.6, $m->getRepeatedDouble()[2]);
|
||||
$this->assertEquals(false, $m->getRepeatedBool()[2]);
|
||||
$this->assertEquals('aa', $m->getRepeatedString()[2]);
|
||||
$this->assertEquals('bb', $m->getRepeatedBytes()[2]);
|
||||
$this->assertEquals(TestEnum::TWO, $m->getRepeatedEnum()[2]);
|
||||
$this->assertEquals(134, $m->getRepeatedMessage()[2]->GetA());
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertEquals('-163', $m->getMapInt64Int64()['-63']);
|
||||
$this->assertEquals('163', $m->getMapUint64Uint64()['63']);
|
||||
$this->assertEquals('-165', $m->getMapSint64Sint64()['-65']);
|
||||
$this->assertEquals('167', $m->getMapFixed64Fixed64()['67']);
|
||||
$this->assertEquals('-169', $m->getMapSfixed64Sfixed64()['-69']);
|
||||
} else {
|
||||
$this->assertEquals(-163, $m->getMapInt64Int64()[-63]);
|
||||
$this->assertEquals(163, $m->getMapUint64Uint64()[63]);
|
||||
$this->assertEquals(-165, $m->getMapSint64Sint64()[-65]);
|
||||
$this->assertEquals(167, $m->getMapFixed64Fixed64()[67]);
|
||||
$this->assertEquals(-169, $m->getMapSfixed64Sfixed64()[-69]);
|
||||
}
|
||||
$this->assertEquals(-162, $m->getMapInt32Int32()[-62]);
|
||||
$this->assertEquals(162, $m->getMapUint32Uint32()[62]);
|
||||
$this->assertEquals(-164, $m->getMapSint32Sint32()[-64]);
|
||||
$this->assertEquals(166, $m->getMapFixed32Fixed32()[66]);
|
||||
$this->assertEquals(-168, $m->getMapSfixed32Sfixed32()[-68]);
|
||||
$this->assertEquals(13.5, $m->getMapInt32Float()[1]);
|
||||
$this->assertEquals(13.6, $m->getMapInt32Double()[1]);
|
||||
$this->assertEquals(false , $m->getMapBoolBool()[true]);
|
||||
$this->assertEquals('ee', $m->getMapStringString()['e']);
|
||||
$this->assertEquals('ff', $m->getMapInt32Bytes()[1]);
|
||||
$this->assertEquals(TestEnum::TWO, $m->getMapInt32Enum()[1]);
|
||||
$this->assertEquals(136, $m->getMapInt32Message()[1]->GetA());
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertEquals('-163', $m->getMapInt64Int64()['-163']);
|
||||
$this->assertEquals('163', $m->getMapUint64Uint64()['163']);
|
||||
$this->assertEquals('-165', $m->getMapSint64Sint64()['-165']);
|
||||
$this->assertEquals('167', $m->getMapFixed64Fixed64()['167']);
|
||||
$this->assertEquals('-169', $m->getMapSfixed64Sfixed64()['-169']);
|
||||
} else {
|
||||
$this->assertEquals(-163, $m->getMapInt64Int64()[-163]);
|
||||
$this->assertEquals(163, $m->getMapUint64Uint64()[163]);
|
||||
$this->assertEquals(-165, $m->getMapSint64Sint64()[-165]);
|
||||
$this->assertEquals(167, $m->getMapFixed64Fixed64()[167]);
|
||||
$this->assertEquals(-169, $m->getMapSfixed64Sfixed64()[-169]);
|
||||
}
|
||||
$this->assertEquals(-162, $m->getMapInt32Int32()[-162]);
|
||||
$this->assertEquals(162, $m->getMapUint32Uint32()[162]);
|
||||
$this->assertEquals(-164, $m->getMapSint32Sint32()[-164]);
|
||||
$this->assertEquals(166, $m->getMapFixed32Fixed32()[166]);
|
||||
$this->assertEquals(-168, $m->getMapSfixed32Sfixed32()[-168]);
|
||||
$this->assertEquals(13.5, $m->getMapInt32Float()[2]);
|
||||
$this->assertEquals(13.6, $m->getMapInt32Double()[2]);
|
||||
$this->assertEquals(false , $m->getMapBoolBool()[false]);
|
||||
$this->assertEquals('ee', $m->getMapStringString()['ee']);
|
||||
$this->assertEquals('ff', $m->getMapInt32Bytes()[2]);
|
||||
$this->assertEquals(TestEnum::TWO, $m->getMapInt32Enum()[2]);
|
||||
$this->assertEquals(136, $m->getMapInt32Message()[2]->GetA());
|
||||
}
|
||||
|
||||
public function expectEmptyFields(TestMessage $m)
|
||||
{
|
||||
$this->assertSame(0, $m->getOptionalInt32());
|
||||
$this->assertSame(0, $m->getOptionalUint32());
|
||||
$this->assertSame(0, $m->getOptionalSint32());
|
||||
$this->assertSame(0, $m->getOptionalFixed32());
|
||||
$this->assertSame(0, $m->getOptionalSfixed32());
|
||||
$this->assertSame(0.0, $m->getOptionalFloat());
|
||||
$this->assertSame(0.0, $m->getOptionalDouble());
|
||||
$this->assertSame(false, $m->getOptionalBool());
|
||||
$this->assertSame('', $m->getOptionalString());
|
||||
$this->assertSame('', $m->getOptionalBytes());
|
||||
$this->assertSame(0, $m->getOptionalEnum());
|
||||
$this->assertNull($m->getOptionalMessage());
|
||||
$this->assertNull($m->getOptionalIncludedMessage());
|
||||
$this->assertNull($m->getRecursive());
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame("0", $m->getOptionalInt64());
|
||||
$this->assertSame("0", $m->getOptionalUint64());
|
||||
$this->assertSame("0", $m->getOptionalSint64());
|
||||
$this->assertSame("0", $m->getOptionalFixed64());
|
||||
$this->assertSame("0", $m->getOptionalSfixed64());
|
||||
} else {
|
||||
$this->assertSame(0, $m->getOptionalInt64());
|
||||
$this->assertSame(0, $m->getOptionalUint64());
|
||||
$this->assertSame(0, $m->getOptionalSint64());
|
||||
$this->assertSame(0, $m->getOptionalFixed64());
|
||||
$this->assertSame(0, $m->getOptionalSfixed64());
|
||||
}
|
||||
|
||||
$this->assertEquals(0, count($m->getRepeatedInt32()));
|
||||
$this->assertEquals(0, count($m->getRepeatedUint32()));
|
||||
$this->assertEquals(0, count($m->getRepeatedInt64()));
|
||||
$this->assertEquals(0, count($m->getRepeatedUint64()));
|
||||
$this->assertEquals(0, count($m->getRepeatedSint32()));
|
||||
$this->assertEquals(0, count($m->getRepeatedSint64()));
|
||||
$this->assertEquals(0, count($m->getRepeatedFixed32()));
|
||||
$this->assertEquals(0, count($m->getRepeatedFixed64()));
|
||||
$this->assertEquals(0, count($m->getRepeatedSfixed32()));
|
||||
$this->assertEquals(0, count($m->getRepeatedSfixed64()));
|
||||
$this->assertEquals(0, count($m->getRepeatedFloat()));
|
||||
$this->assertEquals(0, count($m->getRepeatedDouble()));
|
||||
$this->assertEquals(0, count($m->getRepeatedBool()));
|
||||
$this->assertEquals(0, count($m->getRepeatedString()));
|
||||
$this->assertEquals(0, count($m->getRepeatedBytes()));
|
||||
$this->assertEquals(0, count($m->getRepeatedEnum()));
|
||||
$this->assertEquals(0, count($m->getRepeatedMessage()));
|
||||
$this->assertEquals(0, count($m->getRepeatedRecursive()));
|
||||
|
||||
$this->assertSame("", $m->getMyOneof());
|
||||
$this->assertSame(0, $m->getOneofInt32());
|
||||
$this->assertSame(0, $m->getOneofUint32());
|
||||
$this->assertSame(0, $m->getOneofSint32());
|
||||
$this->assertSame(0, $m->getOneofFixed32());
|
||||
$this->assertSame(0, $m->getOneofSfixed32());
|
||||
$this->assertSame(0.0, $m->getOneofFloat());
|
||||
$this->assertSame(0.0, $m->getOneofDouble());
|
||||
$this->assertSame(false, $m->getOneofBool());
|
||||
$this->assertSame('', $m->getOneofString());
|
||||
$this->assertSame('', $m->getOneofBytes());
|
||||
$this->assertSame(0, $m->getOneofEnum());
|
||||
$this->assertNull($m->getOptionalMessage());
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$this->assertSame("0", $m->getOneofInt64());
|
||||
$this->assertSame("0", $m->getOneofUint64());
|
||||
$this->assertSame("0", $m->getOneofSint64());
|
||||
$this->assertSame("0", $m->getOneofFixed64());
|
||||
$this->assertSame("0", $m->getOneofSfixed64());
|
||||
} else {
|
||||
$this->assertSame(0, $m->getOneofInt64());
|
||||
$this->assertSame(0, $m->getOneofUint64());
|
||||
$this->assertSame(0, $m->getOneofSint64());
|
||||
$this->assertSame(0, $m->getOneofFixed64());
|
||||
$this->assertSame(0, $m->getOneofSfixed64());
|
||||
}
|
||||
|
||||
$this->assertEquals(0, count($m->getMapInt64Int64()));
|
||||
$this->assertEquals(0, count($m->getMapUint64Uint64()));
|
||||
$this->assertEquals(0, count($m->getMapSint64Sint64()));
|
||||
$this->assertEquals(0, count($m->getMapFixed64Fixed64()));
|
||||
$this->assertEquals(0, count($m->getMapInt32Int32()));
|
||||
$this->assertEquals(0, count($m->getMapUint32Uint32()));
|
||||
$this->assertEquals(0, count($m->getMapSint32Sint32()));
|
||||
$this->assertEquals(0, count($m->getMapFixed32Fixed32()));
|
||||
$this->assertEquals(0, count($m->getMapSfixed32Sfixed32()));
|
||||
$this->assertEquals(0, count($m->getMapSfixed64Sfixed64()));
|
||||
$this->assertEquals(0, count($m->getMapInt32Float()));
|
||||
$this->assertEquals(0, count($m->getMapInt32Double()));
|
||||
$this->assertEquals(0, count($m->getMapBoolBool()));
|
||||
$this->assertEquals(0, count($m->getMapStringString()));
|
||||
$this->assertEquals(0, count($m->getMapInt32Bytes()));
|
||||
$this->assertEquals(0, count($m->getMapInt32Enum()));
|
||||
$this->assertEquals(0, count($m->getMapInt32Message()));
|
||||
$this->assertEquals(0, count($m->getMapRecursive()));
|
||||
}
|
||||
|
||||
// This test is to avoid the warning of no test by php unit.
|
||||
public function testNone()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
533
deps/protobuf/php/tests/test_util.php
vendored
Normal file
533
deps/protobuf/php/tests/test_util.php
vendored
Normal file
@ -0,0 +1,533 @@
|
||||
<?php
|
||||
|
||||
use Foo\TestEnum;
|
||||
use Foo\TestMessage;
|
||||
use Foo\TestMessage\Sub;
|
||||
use Foo\TestPackedMessage;
|
||||
use Foo\TestUnpackedMessage;
|
||||
|
||||
define('MAX_FLOAT_DIFF', 0.000001);
|
||||
|
||||
if (PHP_INT_SIZE == 8) {
|
||||
define('MAX_INT_STRING', '9223372036854775807');
|
||||
define('MAX_INT_UPPER_STRING', '9223372036854775808');
|
||||
} else {
|
||||
define('MAX_INT_STRING', '2147483647');
|
||||
define('MAX_INT_UPPER_STRING', '2147483648');
|
||||
}
|
||||
|
||||
define('MAX_INT32', 2147483647);
|
||||
define('MAX_INT32_FLOAT', 2147483647.0);
|
||||
define('MAX_INT32_STRING', '2147483647');
|
||||
|
||||
define('MIN_INT32', (int)-2147483648);
|
||||
define('MIN_INT32_FLOAT', -2147483648.0);
|
||||
define('MIN_INT32_STRING', '-2147483648');
|
||||
|
||||
define('MAX_UINT32', 4294967295);
|
||||
define('MAX_UINT32_FLOAT', 4294967295.0);
|
||||
define('MAX_UINT32_STRING', '4294967295');
|
||||
|
||||
define('MIN_UINT32', (int)-2147483648);
|
||||
define('MIN_UINT32_FLOAT', -2147483648.0);
|
||||
define('MIN_UINT32_STRING', '-2147483648');
|
||||
|
||||
define('MAX_INT64_STRING', '9223372036854775807');
|
||||
define('MIN_INT64_STRING', '-9223372036854775808');
|
||||
define('MAX_UINT64_STRING', '-9223372036854775808');
|
||||
|
||||
if (PHP_INT_SIZE === 8) {
|
||||
define('MAX_INT64', (int)9223372036854775807);
|
||||
define('MIN_INT64', (int)-9223372036854775808);
|
||||
define('MAX_UINT64', (int)-9223372036854775808);
|
||||
} else {
|
||||
define('MAX_INT64', MAX_INT64_STRING);
|
||||
define('MIN_INT64', MIN_INT64_STRING);
|
||||
define('MAX_UINT64', MAX_UINT64_STRING);
|
||||
}
|
||||
|
||||
class TestUtil
|
||||
{
|
||||
|
||||
public static function setTestMessage(TestMessage $m)
|
||||
{
|
||||
$m->setOptionalInt32(-42);
|
||||
$m->setOptionalInt64(-43);
|
||||
$m->setOptionalUint32(42);
|
||||
$m->setOptionalUint64(43);
|
||||
$m->setOptionalSint32(-44);
|
||||
$m->setOptionalSint64(-45);
|
||||
$m->setOptionalFixed32(46);
|
||||
$m->setOptionalFixed64(47);
|
||||
$m->setOptionalSfixed32(-46);
|
||||
$m->setOptionalSfixed64(-47);
|
||||
$m->setOptionalFloat(1.5);
|
||||
$m->setOptionalDouble(1.6);
|
||||
$m->setOptionalBool(true);
|
||||
$m->setOptionalString('a');
|
||||
$m->setOptionalBytes('bbbb');
|
||||
$m->setOptionalEnum(TestEnum::ONE);
|
||||
$sub = new Sub();
|
||||
$m->setOptionalMessage($sub);
|
||||
$m->getOptionalMessage()->SetA(33);
|
||||
|
||||
self::appendHelper($m, 'RepeatedInt32', -42);
|
||||
self::appendHelper($m, 'RepeatedInt64', -43);
|
||||
self::appendHelper($m, 'RepeatedUint32', 42);
|
||||
self::appendHelper($m, 'RepeatedUint64', 43);
|
||||
self::appendHelper($m, 'RepeatedSint32', -44);
|
||||
self::appendHelper($m, 'RepeatedSint64', -45);
|
||||
self::appendHelper($m, 'RepeatedFixed32', 46);
|
||||
self::appendHelper($m, 'RepeatedFixed64', 47);
|
||||
self::appendHelper($m, 'RepeatedSfixed32', -46);
|
||||
self::appendHelper($m, 'RepeatedSfixed64', -47);
|
||||
self::appendHelper($m, 'RepeatedFloat', 1.5);
|
||||
self::appendHelper($m, 'RepeatedDouble', 1.6);
|
||||
self::appendHelper($m, 'RepeatedBool', true);
|
||||
self::appendHelper($m, 'RepeatedString', 'a');
|
||||
self::appendHelper($m, 'RepeatedBytes', 'bbbb');
|
||||
self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO);
|
||||
self::appendHelper($m, 'RepeatedMessage', new Sub());
|
||||
$m->getRepeatedMessage()[0]->setA(34);
|
||||
|
||||
self::appendHelper($m, 'RepeatedInt32', -52);
|
||||
self::appendHelper($m, 'RepeatedInt64', -53);
|
||||
self::appendHelper($m, 'RepeatedUint32', 52);
|
||||
self::appendHelper($m, 'RepeatedUint64', 53);
|
||||
self::appendHelper($m, 'RepeatedSint32', -54);
|
||||
self::appendHelper($m, 'RepeatedSint64', -55);
|
||||
self::appendHelper($m, 'RepeatedFixed32', 56);
|
||||
self::appendHelper($m, 'RepeatedFixed64', 57);
|
||||
self::appendHelper($m, 'RepeatedSfixed32', -56);
|
||||
self::appendHelper($m, 'RepeatedSfixed64', -57);
|
||||
self::appendHelper($m, 'RepeatedFloat', 2.5);
|
||||
self::appendHelper($m, 'RepeatedDouble', 2.6);
|
||||
self::appendHelper($m, 'RepeatedBool', false);
|
||||
self::appendHelper($m, 'RepeatedString', 'c');
|
||||
self::appendHelper($m, 'RepeatedBytes', 'dddd');
|
||||
self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE);
|
||||
self::appendHelper($m, 'RepeatedMessage', new Sub());
|
||||
$m->getRepeatedMessage()[1]->SetA(35);
|
||||
|
||||
self::kvUpdateHelper($m, 'MapInt32Int32', -62, -62);
|
||||
self::kvUpdateHelper($m, 'MapInt64Int64', -63, -63);
|
||||
self::kvUpdateHelper($m, 'MapUint32Uint32', 62, 62);
|
||||
self::kvUpdateHelper($m, 'MapUint64Uint64', 63, 63);
|
||||
self::kvUpdateHelper($m, 'MapSint32Sint32', -64, -64);
|
||||
self::kvUpdateHelper($m, 'MapSint64Sint64', -65, -65);
|
||||
self::kvUpdateHelper($m, 'MapFixed32Fixed32', 66, 66);
|
||||
self::kvUpdateHelper($m, 'MapFixed64Fixed64', 67, 67);
|
||||
self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -68, -68);
|
||||
self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -69, -69);
|
||||
self::kvUpdateHelper($m, 'MapInt32Float', 1, 3.5);
|
||||
self::kvUpdateHelper($m, 'MapInt32Double', 1, 3.6);
|
||||
self::kvUpdateHelper($m, 'MapBoolBool', true, true);
|
||||
self::kvUpdateHelper($m, 'MapStringString', 'e', 'e');
|
||||
self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'ffff');
|
||||
self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::ONE);
|
||||
self::kvUpdateHelper($m, 'MapInt32Message', 1, new Sub());
|
||||
$m->getMapInt32Message()[1]->SetA(36);
|
||||
}
|
||||
|
||||
public static function setTestMessage2(TestMessage $m)
|
||||
{
|
||||
$sub = new Sub();
|
||||
|
||||
$m->setOptionalInt32(-142);
|
||||
$m->setOptionalInt64(-143);
|
||||
$m->setOptionalUint32(142);
|
||||
$m->setOptionalUint64(143);
|
||||
$m->setOptionalSint32(-144);
|
||||
$m->setOptionalSint64(-145);
|
||||
$m->setOptionalFixed32(146);
|
||||
$m->setOptionalFixed64(147);
|
||||
$m->setOptionalSfixed32(-146);
|
||||
$m->setOptionalSfixed64(-147);
|
||||
$m->setOptionalFloat(11.5);
|
||||
$m->setOptionalDouble(11.6);
|
||||
$m->setOptionalBool(true);
|
||||
$m->setOptionalString('aa');
|
||||
$m->setOptionalBytes('bb');
|
||||
$m->setOptionalEnum(TestEnum::TWO);
|
||||
$m->setOptionalMessage($sub);
|
||||
$m->getOptionalMessage()->SetA(133);
|
||||
|
||||
self::appendHelper($m, 'RepeatedInt32', -142);
|
||||
self::appendHelper($m, 'RepeatedInt64', -143);
|
||||
self::appendHelper($m, 'RepeatedUint32', 142);
|
||||
self::appendHelper($m, 'RepeatedUint64', 143);
|
||||
self::appendHelper($m, 'RepeatedSint32', -144);
|
||||
self::appendHelper($m, 'RepeatedSint64', -145);
|
||||
self::appendHelper($m, 'RepeatedFixed32', 146);
|
||||
self::appendHelper($m, 'RepeatedFixed64', 147);
|
||||
self::appendHelper($m, 'RepeatedSfixed32', -146);
|
||||
self::appendHelper($m, 'RepeatedSfixed64', -147);
|
||||
self::appendHelper($m, 'RepeatedFloat', 11.5);
|
||||
self::appendHelper($m, 'RepeatedDouble', 11.6);
|
||||
self::appendHelper($m, 'RepeatedBool', false);
|
||||
self::appendHelper($m, 'RepeatedString', 'aa');
|
||||
self::appendHelper($m, 'RepeatedBytes', 'bb');
|
||||
self::appendHelper($m, 'RepeatedEnum', TestEnum::TWO);
|
||||
self::appendHelper($m, 'RepeatedMessage', new Sub());
|
||||
$m->getRepeatedMessage()[0]->setA(134);
|
||||
|
||||
self::kvUpdateHelper($m, 'MapInt32Int32', -62, -162);
|
||||
self::kvUpdateHelper($m, 'MapInt64Int64', -63, -163);
|
||||
self::kvUpdateHelper($m, 'MapUint32Uint32', 62, 162);
|
||||
self::kvUpdateHelper($m, 'MapUint64Uint64', 63, 163);
|
||||
self::kvUpdateHelper($m, 'MapSint32Sint32', -64, -164);
|
||||
self::kvUpdateHelper($m, 'MapSint64Sint64', -65, -165);
|
||||
self::kvUpdateHelper($m, 'MapFixed32Fixed32', 66, 166);
|
||||
self::kvUpdateHelper($m, 'MapFixed64Fixed64', 67, 167);
|
||||
self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -68, -168);
|
||||
self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -69, -169);
|
||||
self::kvUpdateHelper($m, 'MapInt32Float', 1, 13.5);
|
||||
self::kvUpdateHelper($m, 'MapInt32Double', 1, 13.6);
|
||||
self::kvUpdateHelper($m, 'MapBoolBool', true, false);
|
||||
self::kvUpdateHelper($m, 'MapStringString', 'e', 'ee');
|
||||
self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'ff');
|
||||
self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::TWO);
|
||||
self::kvUpdateHelper($m, 'MapInt32Message', 1, new Sub());
|
||||
$m->getMapInt32Message()[1]->SetA(136);
|
||||
|
||||
self::kvUpdateHelper($m, 'MapInt32Int32', -162, -162);
|
||||
self::kvUpdateHelper($m, 'MapInt64Int64', -163, -163);
|
||||
self::kvUpdateHelper($m, 'MapUint32Uint32', 162, 162);
|
||||
self::kvUpdateHelper($m, 'MapUint64Uint64', 163, 163);
|
||||
self::kvUpdateHelper($m, 'MapSint32Sint32', -164, -164);
|
||||
self::kvUpdateHelper($m, 'MapSint64Sint64', -165, -165);
|
||||
self::kvUpdateHelper($m, 'MapFixed32Fixed32', 166, 166);
|
||||
self::kvUpdateHelper($m, 'MapFixed64Fixed64', 167, 167);
|
||||
self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -168, -168);
|
||||
self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -169, -169);
|
||||
self::kvUpdateHelper($m, 'MapInt32Float', 2, 13.5);
|
||||
self::kvUpdateHelper($m, 'MapInt32Double', 2, 13.6);
|
||||
self::kvUpdateHelper($m, 'MapBoolBool', false, false);
|
||||
self::kvUpdateHelper($m, 'MapStringString', 'ee', 'ee');
|
||||
self::kvUpdateHelper($m, 'MapInt32Bytes', 2, 'ff');
|
||||
self::kvUpdateHelper($m, 'MapInt32Enum', 2, TestEnum::TWO);
|
||||
self::kvUpdateHelper($m, 'MapInt32Message', 2, new Sub());
|
||||
$m->getMapInt32Message()[2]->SetA(136);
|
||||
}
|
||||
|
||||
public static function assertTestMessage(TestMessage $m)
|
||||
{
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
assert('-43' === $m->getOptionalInt64());
|
||||
assert('43' === $m->getOptionalUint64());
|
||||
assert('-45' === $m->getOptionalSint64());
|
||||
assert('47' === $m->getOptionalFixed64());
|
||||
assert('-47' === $m->getOptionalSfixed64());
|
||||
} else {
|
||||
assert(-43 === $m->getOptionalInt64());
|
||||
assert(43 === $m->getOptionalUint64());
|
||||
assert(-45 === $m->getOptionalSint64());
|
||||
assert(47 === $m->getOptionalFixed64());
|
||||
assert(-47 === $m->getOptionalSfixed64());
|
||||
}
|
||||
assert(-42 === $m->getOptionalInt32());
|
||||
assert(42 === $m->getOptionalUint32());
|
||||
assert(-44 === $m->getOptionalSint32());
|
||||
assert(46 === $m->getOptionalFixed32());
|
||||
assert(-46 === $m->getOptionalSfixed32());
|
||||
assert(1.5 === $m->getOptionalFloat());
|
||||
assert(1.6 === $m->getOptionalDouble());
|
||||
assert(true=== $m->getOptionalBool());
|
||||
assert('a' === $m->getOptionalString());
|
||||
assert('bbbb' === $m->getOptionalBytes());
|
||||
assert(TestEnum::ONE === $m->getOptionalEnum());
|
||||
assert(33 === $m->getOptionalMessage()->getA());
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
assert('-43' === $m->getRepeatedInt64()[0]);
|
||||
assert('43' === $m->getRepeatedUint64()[0]);
|
||||
assert('-45' === $m->getRepeatedSint64()[0]);
|
||||
assert('47' === $m->getRepeatedFixed64()[0]);
|
||||
assert('-47' === $m->getRepeatedSfixed64()[0]);
|
||||
} else {
|
||||
assert(-43 === $m->getRepeatedInt64()[0]);
|
||||
assert(43 === $m->getRepeatedUint64()[0]);
|
||||
assert(-45 === $m->getRepeatedSint64()[0]);
|
||||
assert(47 === $m->getRepeatedFixed64()[0]);
|
||||
assert(-47 === $m->getRepeatedSfixed64()[0]);
|
||||
}
|
||||
assert(-42 === $m->getRepeatedInt32()[0]);
|
||||
assert(42 === $m->getRepeatedUint32()[0]);
|
||||
assert(-44 === $m->getRepeatedSint32()[0]);
|
||||
assert(46 === $m->getRepeatedFixed32()[0]);
|
||||
assert(-46 === $m->getRepeatedSfixed32()[0]);
|
||||
assert(1.5 === $m->getRepeatedFloat()[0]);
|
||||
assert(1.6 === $m->getRepeatedDouble()[0]);
|
||||
assert(true=== $m->getRepeatedBool()[0]);
|
||||
assert('a' === $m->getRepeatedString()[0]);
|
||||
assert('bbbb' === $m->getRepeatedBytes()[0]);
|
||||
assert(TestEnum::ZERO === $m->getRepeatedEnum()[0]);
|
||||
assert(34 === $m->getRepeatedMessage()[0]->getA());
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
assert('-53' === $m->getRepeatedInt64()[1]);
|
||||
assert('53' === $m->getRepeatedUint64()[1]);
|
||||
assert('-55' === $m->getRepeatedSint64()[1]);
|
||||
assert('57' === $m->getRepeatedFixed64()[1]);
|
||||
assert('-57' === $m->getRepeatedSfixed64()[1]);
|
||||
} else {
|
||||
assert(-53 === $m->getRepeatedInt64()[1]);
|
||||
assert(53 === $m->getRepeatedUint64()[1]);
|
||||
assert(-55 === $m->getRepeatedSint64()[1]);
|
||||
assert(57 === $m->getRepeatedFixed64()[1]);
|
||||
assert(-57 === $m->getRepeatedSfixed64()[1]);
|
||||
}
|
||||
assert(-52 === $m->getRepeatedInt32()[1]);
|
||||
assert(52 === $m->getRepeatedUint32()[1]);
|
||||
assert(-54 === $m->getRepeatedSint32()[1]);
|
||||
assert(56 === $m->getRepeatedFixed32()[1]);
|
||||
assert(-56 === $m->getRepeatedSfixed32()[1]);
|
||||
assert(2.5 === $m->getRepeatedFloat()[1]);
|
||||
assert(2.6 === $m->getRepeatedDouble()[1]);
|
||||
assert(false === $m->getRepeatedBool()[1]);
|
||||
assert('c' === $m->getRepeatedString()[1]);
|
||||
assert('dddd' === $m->getRepeatedBytes()[1]);
|
||||
assert(TestEnum::ONE === $m->getRepeatedEnum()[1]);
|
||||
assert(35 === $m->getRepeatedMessage()[1]->getA());
|
||||
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
assert('-63' === $m->getMapInt64Int64()['-63']);
|
||||
assert('63' === $m->getMapUint64Uint64()['63']);
|
||||
assert('-65' === $m->getMapSint64Sint64()['-65']);
|
||||
assert('67' === $m->getMapFixed64Fixed64()['67']);
|
||||
assert('-69' === $m->getMapSfixed64Sfixed64()['-69']);
|
||||
} else {
|
||||
assert(-63 === $m->getMapInt64Int64()[-63]);
|
||||
assert(63 === $m->getMapUint64Uint64()[63]);
|
||||
assert(-65 === $m->getMapSint64Sint64()[-65]);
|
||||
assert(67 === $m->getMapFixed64Fixed64()[67]);
|
||||
assert(-69 === $m->getMapSfixed64Sfixed64()[-69]);
|
||||
}
|
||||
assert(-62 === $m->getMapInt32Int32()[-62]);
|
||||
assert(62 === $m->getMapUint32Uint32()[62]);
|
||||
assert(-64 === $m->getMapSint32Sint32()[-64]);
|
||||
assert(66 === $m->getMapFixed32Fixed32()[66]);
|
||||
assert(-68 === $m->getMapSfixed32Sfixed32()[-68]);
|
||||
assert(3.5 === $m->getMapInt32Float()[1]);
|
||||
assert(3.6 === $m->getMapInt32Double()[1]);
|
||||
assert(true === $m->getMapBoolBool()[true]);
|
||||
assert('e' === $m->getMapStringString()['e']);
|
||||
assert('ffff' === $m->getMapInt32Bytes()[1]);
|
||||
assert(TestEnum::ONE === $m->getMapInt32Enum()[1]);
|
||||
assert(36 === $m->getMapInt32Message()[1]->GetA());
|
||||
}
|
||||
|
||||
public static function getGoldenTestMessage()
|
||||
{
|
||||
return hex2bin(
|
||||
"08D6FFFFFFFFFFFFFFFF01" .
|
||||
"10D5FFFFFFFFFFFFFFFF01" .
|
||||
"182A" .
|
||||
"202B" .
|
||||
"2857" .
|
||||
"3059" .
|
||||
"3D2E000000" .
|
||||
"412F00000000000000" .
|
||||
"4DD2FFFFFF" .
|
||||
"51D1FFFFFFFFFFFFFF" .
|
||||
"5D0000C03F" .
|
||||
"619A9999999999F93F" .
|
||||
"6801" .
|
||||
"720161" .
|
||||
"7A0462626262" .
|
||||
"800101" .
|
||||
"8A01020821" .
|
||||
|
||||
"FA0114D6FFFFFFFFFFFFFFFF01CCFFFFFFFFFFFFFFFF01" .
|
||||
"820214D5FFFFFFFFFFFFFFFF01CBFFFFFFFFFFFFFFFF01" .
|
||||
"8A02022A34" .
|
||||
"9202022B35" .
|
||||
"9A0202576B" .
|
||||
"A20202596D" .
|
||||
"AA02082E00000038000000" .
|
||||
"B202102F000000000000003900000000000000" .
|
||||
"BA0208D2FFFFFFC8FFFFFF" .
|
||||
"C20210D1FFFFFFFFFFFFFFC7FFFFFFFFFFFFFF" .
|
||||
"CA02080000C03F00002040" .
|
||||
"D202109A9999999999F93FCDCCCCCCCCCC0440" .
|
||||
"DA02020100" .
|
||||
"E2020161" .
|
||||
"E2020163" .
|
||||
"EA020462626262" .
|
||||
"EA020464646464" .
|
||||
"F202020001" .
|
||||
"FA02020822" .
|
||||
"FA02020823" .
|
||||
|
||||
"BA041608C2FFFFFFFFFFFFFFFF0110C2FFFFFFFFFFFFFFFF01" .
|
||||
"C2041608C1FFFFFFFFFFFFFFFF0110C1FFFFFFFFFFFFFFFF01" .
|
||||
"CA0404083E103E" .
|
||||
"D20404083F103F" .
|
||||
"DA0404087f107F" .
|
||||
"E20406088101108101" .
|
||||
"EA040A0D420000001542000000" .
|
||||
"F20412094300000000000000114300000000000000" .
|
||||
"FA040A0DBCFFFFFF15BCFFFFFF" .
|
||||
"82051209BBFFFFFFFFFFFFFF11BBFFFFFFFFFFFFFF" .
|
||||
"8A050708011500006040" .
|
||||
"92050B080111CDCCCCCCCCCC0C40" .
|
||||
"9A050408011001" .
|
||||
"A205060a0165120165" .
|
||||
"AA05080801120466666666" .
|
||||
"B2050408011001" .
|
||||
"Ba0506080112020824"
|
||||
);
|
||||
}
|
||||
|
||||
public static function setTestPackedMessage($m)
|
||||
{
|
||||
self::appendHelper($m, 'RepeatedInt32', -42);
|
||||
self::appendHelper($m, 'RepeatedInt32', -52);
|
||||
self::appendHelper($m, 'RepeatedInt64', -43);
|
||||
self::appendHelper($m, 'RepeatedInt64', -53);
|
||||
self::appendHelper($m, 'RepeatedUint32', 42);
|
||||
self::appendHelper($m, 'RepeatedUint32', 52);
|
||||
self::appendHelper($m, 'RepeatedUint64', 43);
|
||||
self::appendHelper($m, 'RepeatedUint64', 53);
|
||||
self::appendHelper($m, 'RepeatedSint32', -44);
|
||||
self::appendHelper($m, 'RepeatedSint32', -54);
|
||||
self::appendHelper($m, 'RepeatedSint64', -45);
|
||||
self::appendHelper($m, 'RepeatedSint64', -55);
|
||||
self::appendHelper($m, 'RepeatedFixed32', 46);
|
||||
self::appendHelper($m, 'RepeatedFixed32', 56);
|
||||
self::appendHelper($m, 'RepeatedFixed64', 47);
|
||||
self::appendHelper($m, 'RepeatedFixed64', 57);
|
||||
self::appendHelper($m, 'RepeatedSfixed32', -46);
|
||||
self::appendHelper($m, 'RepeatedSfixed32', -56);
|
||||
self::appendHelper($m, 'RepeatedSfixed64', -47);
|
||||
self::appendHelper($m, 'RepeatedSfixed64', -57);
|
||||
self::appendHelper($m, 'RepeatedFloat', 1.5);
|
||||
self::appendHelper($m, 'RepeatedFloat', 2.5);
|
||||
self::appendHelper($m, 'RepeatedDouble', 1.6);
|
||||
self::appendHelper($m, 'RepeatedDouble', 2.6);
|
||||
self::appendHelper($m, 'RepeatedBool', true);
|
||||
self::appendHelper($m, 'RepeatedBool', false);
|
||||
self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE);
|
||||
self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO);
|
||||
}
|
||||
|
||||
public static function assertTestPackedMessage($m)
|
||||
{
|
||||
assert(2 === count($m->getRepeatedInt32()));
|
||||
assert(2 === count($m->getRepeatedInt64()));
|
||||
assert(2 === count($m->getRepeatedUint32()));
|
||||
assert(2 === count($m->getRepeatedUint64()));
|
||||
assert(2 === count($m->getRepeatedSint32()));
|
||||
assert(2 === count($m->getRepeatedSint64()));
|
||||
assert(2 === count($m->getRepeatedFixed32()));
|
||||
assert(2 === count($m->getRepeatedFixed64()));
|
||||
assert(2 === count($m->getRepeatedSfixed32()));
|
||||
assert(2 === count($m->getRepeatedSfixed64()));
|
||||
assert(2 === count($m->getRepeatedFloat()));
|
||||
assert(2 === count($m->getRepeatedDouble()));
|
||||
assert(2 === count($m->getRepeatedBool()));
|
||||
assert(2 === count($m->getRepeatedEnum()));
|
||||
|
||||
assert(-42 === $m->getRepeatedInt32()[0]);
|
||||
assert(-52 === $m->getRepeatedInt32()[1]);
|
||||
assert(42 === $m->getRepeatedUint32()[0]);
|
||||
assert(52 === $m->getRepeatedUint32()[1]);
|
||||
assert(-44 === $m->getRepeatedSint32()[0]);
|
||||
assert(-54 === $m->getRepeatedSint32()[1]);
|
||||
assert(46 === $m->getRepeatedFixed32()[0]);
|
||||
assert(56 === $m->getRepeatedFixed32()[1]);
|
||||
assert(-46 === $m->getRepeatedSfixed32()[0]);
|
||||
assert(-56 === $m->getRepeatedSfixed32()[1]);
|
||||
assert(1.5 === $m->getRepeatedFloat()[0]);
|
||||
assert(2.5 === $m->getRepeatedFloat()[1]);
|
||||
assert(1.6 === $m->getRepeatedDouble()[0]);
|
||||
assert(2.6 === $m->getRepeatedDouble()[1]);
|
||||
assert(true === $m->getRepeatedBool()[0]);
|
||||
assert(false === $m->getRepeatedBool()[1]);
|
||||
assert(TestEnum::ONE === $m->getRepeatedEnum()[0]);
|
||||
assert(TestEnum::ZERO === $m->getRepeatedEnum()[1]);
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
assert('-43' === $m->getRepeatedInt64()[0]);
|
||||
assert('-53' === $m->getRepeatedInt64()[1]);
|
||||
assert('43' === $m->getRepeatedUint64()[0]);
|
||||
assert('53' === $m->getRepeatedUint64()[1]);
|
||||
assert('-45' === $m->getRepeatedSint64()[0]);
|
||||
assert('-55' === $m->getRepeatedSint64()[1]);
|
||||
assert('47' === $m->getRepeatedFixed64()[0]);
|
||||
assert('57' === $m->getRepeatedFixed64()[1]);
|
||||
assert('-47' === $m->getRepeatedSfixed64()[0]);
|
||||
assert('-57' === $m->getRepeatedSfixed64()[1]);
|
||||
} else {
|
||||
assert(-43 === $m->getRepeatedInt64()[0]);
|
||||
assert(-53 === $m->getRepeatedInt64()[1]);
|
||||
assert(43 === $m->getRepeatedUint64()[0]);
|
||||
assert(53 === $m->getRepeatedUint64()[1]);
|
||||
assert(-45 === $m->getRepeatedSint64()[0]);
|
||||
assert(-55 === $m->getRepeatedSint64()[1]);
|
||||
assert(47 === $m->getRepeatedFixed64()[0]);
|
||||
assert(57 === $m->getRepeatedFixed64()[1]);
|
||||
assert(-47 === $m->getRepeatedSfixed64()[0]);
|
||||
assert(-57 === $m->getRepeatedSfixed64()[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getGoldenTestPackedMessage()
|
||||
{
|
||||
return hex2bin(
|
||||
"D20514D6FFFFFFFFFFFFFFFF01CCFFFFFFFFFFFFFFFF01" .
|
||||
"DA0514D5FFFFFFFFFFFFFFFF01CBFFFFFFFFFFFFFFFF01" .
|
||||
"E205022A34" .
|
||||
"EA05022B35" .
|
||||
"F20502576B" .
|
||||
"FA0502596D" .
|
||||
"8206082E00000038000000" .
|
||||
"8A06102F000000000000003900000000000000" .
|
||||
"920608D2FFFFFFC8FFFFFF" .
|
||||
"9A0610D1FFFFFFFFFFFFFFC7FFFFFFFFFFFFFF" .
|
||||
"A206080000C03F00002040" .
|
||||
"AA06109A9999999999F93FCDCCCCCCCCCC0440" .
|
||||
"B206020100" .
|
||||
"BA06020100"
|
||||
);
|
||||
}
|
||||
|
||||
public static function getGoldenTestUnpackedMessage()
|
||||
{
|
||||
return hex2bin(
|
||||
"D005D6FFFFFFFFFFFFFFFF01D005CCFFFFFFFFFFFFFFFF01" .
|
||||
"D805D5FFFFFFFFFFFFFFFF01D805CBFFFFFFFFFFFFFFFF01" .
|
||||
"E0052AE00534" .
|
||||
"E8052BE80535" .
|
||||
"F00557F0056B" .
|
||||
"F80559F8056D" .
|
||||
"85062E000000850638000000" .
|
||||
"89062F0000000000000089063900000000000000" .
|
||||
"9506D2FFFFFF9506C8FFFFFF" .
|
||||
"9906D1FFFFFFFFFFFFFF9906C7FFFFFFFFFFFFFF" .
|
||||
"A5060000C03FA50600002040" .
|
||||
"A9069A9999999999F93FA906CDCCCCCCCCCC0440" .
|
||||
"B00601B00600" .
|
||||
"B80601B80600"
|
||||
);
|
||||
}
|
||||
|
||||
private static function appendHelper($obj, $func_suffix, $value)
|
||||
{
|
||||
$getter_function = 'get'.$func_suffix;
|
||||
$setter_function = 'set'.$func_suffix;
|
||||
|
||||
$arr = $obj->$getter_function();
|
||||
$arr[] = $value;
|
||||
$obj->$setter_function($arr);
|
||||
}
|
||||
|
||||
private static function kvUpdateHelper($obj, $func_suffix, $key, $value)
|
||||
{
|
||||
$getter_function = 'get'.$func_suffix;
|
||||
$setter_function = 'set'.$func_suffix;
|
||||
|
||||
$arr = $obj->$getter_function();
|
||||
$arr[$key] = $value;
|
||||
$obj->$setter_function($arr);
|
||||
}
|
||||
}
|
33
deps/protobuf/php/tests/valgrind.supp
vendored
Normal file
33
deps/protobuf/php/tests/valgrind.supp
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
PHP_Equal_Val
|
||||
Memcheck:Cond
|
||||
fun:zend_string_equal_val
|
||||
}
|
||||
|
||||
{
|
||||
PHP_ScanDir_Tail
|
||||
Memcheck:Cond
|
||||
obj:/usr/bin/php7.3
|
||||
fun:__scandir64_tail
|
||||
}
|
||||
|
||||
{
|
||||
PHP_ModuleLoadingLeaks
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:php_module_startup
|
||||
}
|
||||
|
||||
{
|
||||
PHP_ModuleLoadingLeaks
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:php_module_startup
|
||||
}
|
||||
|
||||
{
|
||||
PHP_ModuleLoadingLeaks2
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:php_load_shlib
|
||||
}
|
Reference in New Issue
Block a user