Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: third_party/protobuf/php/tests/memory_leak_test.php

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/php/tests/memory_leak_test.php
diff --git a/third_party/protobuf/php/tests/memory_leak_test.php b/third_party/protobuf/php/tests/memory_leak_test.php
new file mode 100644
index 0000000000000000000000000000000000000000..af3272734f4b280578468459c974aee44ab6a1e4
--- /dev/null
+++ b/third_party/protobuf/php/tests/memory_leak_test.php
@@ -0,0 +1,81 @@
+<?php
+
+# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
+
+require_once('generated/Bar/TestInclude.php');
+require_once('generated/Foo/TestEnum.php');
+require_once('generated/Foo/TestMessage.php');
+require_once('generated/Foo/TestMessage_Sub.php');
+require_once('generated/Foo/TestPackedMessage.php');
+require_once('generated/Foo/TestPhpDoc.php');
+require_once('generated/Foo/TestUnpackedMessage.php');
+require_once('generated/GPBMetadata/Proto/Test.php');
+require_once('generated/GPBMetadata/Proto/TestInclude.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());
« no previous file with comments | « third_party/protobuf/php/tests/map_field_test.php ('k') | third_party/protobuf/php/tests/php_implementation_test.php » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698