aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests
diff options
context:
space:
mode:
Diffstat (limited to 'php/tests')
-rw-r--r--php/tests/encode_decode_test.php41
-rw-r--r--php/tests/generated_class_test.php11
-rw-r--r--php/tests/php_implementation_test.php52
-rw-r--r--php/tests/proto/test.proto3
-rw-r--r--php/tests/proto/test_no_namespace.proto7
5 files changed, 82 insertions, 32 deletions
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index af9c0415..992f1631 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -132,4 +132,45 @@ class EncodeDecodeTest extends TestBase
$to->decode(TestUtil::getGoldenTestUnpackedMessage());
TestUtil::assertTestPackedMessage($to);
}
+
+ public function testDecodeInt64()
+ {
+ // Read 64 testing
+ $testVals = array(
+ '10' => '100a',
+ '100' => '1064',
+ '800' => '10a006',
+ '6400' => '108032',
+ '70400' => '1080a604',
+ '774400' => '1080a22f',
+ '9292800' => '108098b704',
+ '74342400' => '1080c0b923',
+ '743424000' => '108080bfe202',
+ '8177664000' => '108080b5bb1e',
+ '65421312000' => '108080a8dbf301',
+ '785055744000' => '108080e0c7ec16',
+ '9420668928000' => '10808080dd969202',
+ '103627358208000' => '10808080fff9c717',
+ '1139900940288000' => '10808080f5bd978302',
+ '13678811283456000' => '10808080fce699a618',
+ '109430490267648000' => '10808080e0b7ceb1c201',
+ '984874412408832000' => '10808080e0f5c1bed50d',
+ );
+
+ $msg = new TestMessage();
+ foreach ($testVals as $original => $encoded) {
+ $msg->setOptionalInt64($original);
+ $data = $msg->encode();
+ $this->assertSame($encoded, bin2hex($data));
+ $msg->setOptionalInt64(0);
+ $msg->decode($data);
+ $this->assertEquals($original, $msg->getOptionalInt64());
+ }
+ }
+
+ public function testDecodeFieldNonExist() {
+ $data = hex2bin('c80501');
+ $m = new TestMessage();
+ $m->decode($data);
+ }
}
diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php
index 3587092e..d347e8b4 100644
--- a/php/tests/generated_class_test.php
+++ b/php/tests/generated_class_test.php
@@ -1,6 +1,7 @@
<?php
-require_once('generated/NoNameSpace.php');
+require_once('generated/NoNameSpaceEnum.php');
+require_once('generated/NoNameSpaceMessage.php');
require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField;
@@ -607,10 +608,14 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase
}
#########################################################
- # Test oneof field.
+ # Test message/enum without namespace.
#########################################################
public function testMessageWithoutNamespace() {
- $m = new NoNameSpace();
+ $m = new NoNameSpaceMessage();
+ }
+
+ public function testEnumWithoutNamespace() {
+ $m = new NoNameSpaceEnum();
}
}
diff --git a/php/tests/php_implementation_test.php b/php/tests/php_implementation_test.php
index 6b922a9b..ac7c13dc 100644
--- a/php/tests/php_implementation_test.php
+++ b/php/tests/php_implementation_test.php
@@ -368,33 +368,31 @@ class ImplementationTest extends TestBase
$this->assertFalse($input->readVarint64($var));
// Read 64 testing
- if (PHP_INT_SIZE > 4) {
- $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 InputStream(hex2bin($encoded));
- $this->assertTrue($input->readVarint64($var));
- $this->assertSame($original, $var);
- }
+ $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 InputStream(hex2bin($encoded));
+ $this->assertTrue($input->readVarint64($var));
+ $this->assertEquals($original, $var);
}
}
diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto
index fc283a05..594aee4d 100644
--- a/php/tests/proto/test.proto
+++ b/php/tests/proto/test.proto
@@ -92,7 +92,8 @@ message TestMessage {
int32 a = 1;
}
- // NestedMessage nested_message = 90;
+ // Reserved for non-existing field test.
+ // int32 non_exist = 89;
}
enum TestEnum {
diff --git a/php/tests/proto/test_no_namespace.proto b/php/tests/proto/test_no_namespace.proto
index 4331aeab..b8c4fdf2 100644
--- a/php/tests/proto/test_no_namespace.proto
+++ b/php/tests/proto/test_no_namespace.proto
@@ -1,5 +1,10 @@
syntax = "proto3";
-message NoNameSpace {
+message NoNameSpaceMessage {
int32 a = 1;
}
+
+enum NoNameSpaceEnum {
+ VALUE_A = 0;
+ VALUE_B = 1;
+}