diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2016-09-15 11:09:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-15 11:09:01 -0700 |
commit | e0e54661f76183684dca66694967a60cbb10f04e (patch) | |
tree | 0a2a20f984705fdf6ef13de8829901b80f88efb5 /php/tests/memory_leak_test.php | |
parent | 86fcd879b38505446799b2f2a2929415ddad620a (diff) | |
download | protobuf-e0e54661f76183684dca66694967a60cbb10f04e.tar.gz protobuf-e0e54661f76183684dca66694967a60cbb10f04e.tar.bz2 protobuf-e0e54661f76183684dca66694967a60cbb10f04e.zip |
Check in php implementation. (#2052)
This pull request includes two implementation: C extension and PHP
package. Both implementations support encode/decode of singular,
repeated and map fields.
Diffstat (limited to 'php/tests/memory_leak_test.php')
-rw-r--r-- | php/tests/memory_leak_test.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php new file mode 100644 index 00000000..ec54597b --- /dev/null +++ b/php/tests/memory_leak_test.php @@ -0,0 +1,73 @@ +<?php + +# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak. + +require_once('test.pb.php'); +require_once('test_util.php'); + +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBType; +use Foo\TestMessage; +use Foo\TestMessage_Sub; + +$from = new TestMessage(); +TestUtil::setTestMessage($from); +TestUtil::assertTestMessage($from); + +$data = $from->encode(); + +$to = new TestMessage(); +$to->decode($data); + +TestUtil::assertTestMessage($to); + +$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->encode(); +$n = new TestMessage(); +$n->decode($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->encode(); +$n = new TestMessage(); +$n->decode($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->encode(); +$n = new TestMessage(); +$n->decode($data); +assert('abc' === $n->getOneofString()); + +$sub_m = new TestMessage_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->encode(); +$n = new TestMessage(); +$n->decode($data); +assert(1 === $n->getOneofMessage()->getA()); |