diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-02-07 21:33:28 -0800 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2017-03-15 14:16:49 -0700 |
commit | f23869c6154d8b083ee3417fac277bc25e13a4ac (patch) | |
tree | 2e9ea1cfcc88211ac1e364155d696c808acb11ba /php/tests/encode_decode_test.php | |
parent | 014a5507fb4b1ccc12f35ff313b8a04c05d69b7f (diff) | |
download | protobuf-f23869c6154d8b083ee3417fac277bc25e13a4ac.tar.gz protobuf-f23869c6154d8b083ee3417fac277bc25e13a4ac.tar.bz2 protobuf-f23869c6154d8b083ee3417fac277bc25e13a4ac.zip |
Bug fix: When encoding, negative int32 values should be padded to int64 (#2660)
in order to be wire compatible.
Diffstat (limited to 'php/tests/encode_decode_test.php')
-rw-r--r-- | php/tests/encode_decode_test.php | 21 |
1 files changed, 21 insertions, 0 deletions
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() |