From f23869c6154d8b083ee3417fac277bc25e13a4ac Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 7 Feb 2017 21:33:28 -0800 Subject: Bug fix: When encoding, negative int32 values should be padded to int64 (#2660) in order to be wire compatible. --- php/tests/encode_decode_test.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'php/tests/encode_decode_test.php') diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index b54b1239..ba4fff69 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -190,6 +190,27 @@ class EncodeDecodeTest extends TestBase $m->mergeFromString($data); } + public function testEncodeNegativeInt32() + { + $m = new TestMessage(); + $m->setOptionalInt32(-1); + $data = $m->encode(); + $this->assertSame("08ffffffffffffffffff01", bin2hex($data)); + } + + public function testDecodeNegativeInt32() + { + $m = new TestMessage(); + $this->assertEquals(0, $m->getOptionalInt32()); + $m->decode(hex2bin("08ffffffffffffffffff01")); + $this->assertEquals(-1, $m->getOptionalInt32()); + + $m = new TestMessage(); + $this->assertEquals(0, $m->getOptionalInt32()); + $m->decode(hex2bin("08ffffffff0f")); + $this->assertEquals(-1, $m->getOptionalInt32()); + } + # TODO(teboring): Add test back when php implementation is ready for json # encode/decode. # public function testJsonEncode() -- cgit v1.2.3