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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 <?php
2
3 # phpunit has memory leak by itself. Thus, it cannot be used to test memory leak .
4
5 require_once('generated/Bar/TestInclude.php');
6 require_once('generated/Foo/TestEnum.php');
7 require_once('generated/Foo/TestMessage.php');
8 require_once('generated/Foo/TestMessage_Sub.php');
9 require_once('generated/Foo/TestPackedMessage.php');
10 require_once('generated/Foo/TestPhpDoc.php');
11 require_once('generated/Foo/TestUnpackedMessage.php');
12 require_once('generated/GPBMetadata/Proto/Test.php');
13 require_once('generated/GPBMetadata/Proto/TestInclude.php');
14 require_once('test_util.php');
15
16 use Google\Protobuf\Internal\RepeatedField;
17 use Google\Protobuf\Internal\GPBType;
18 use Foo\TestMessage;
19 use Foo\TestMessage_Sub;
20
21 $from = new TestMessage();
22 TestUtil::setTestMessage($from);
23 TestUtil::assertTestMessage($from);
24
25 $data = $from->encode();
26
27 $to = new TestMessage();
28 $to->decode($data);
29
30 TestUtil::assertTestMessage($to);
31
32 $from->setRecursive($from);
33
34 $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
35 $arr []= new TestMessage;
36 $arr[0]->SetRepeatedRecursive($arr);
37
38 // Test oneof fields.
39 $m = new TestMessage();
40
41 $m->setOneofInt32(1);
42 assert(1 === $m->getOneofInt32());
43 assert(0.0 === $m->getOneofFloat());
44 assert('' === $m->getOneofString());
45 assert(NULL === $m->getOneofMessage());
46 $data = $m->encode();
47 $n = new TestMessage();
48 $n->decode($data);
49 assert(1 === $n->getOneofInt32());
50
51 $m->setOneofFloat(2.0);
52 assert(0 === $m->getOneofInt32());
53 assert(2.0 === $m->getOneofFloat());
54 assert('' === $m->getOneofString());
55 assert(NULL === $m->getOneofMessage());
56 $data = $m->encode();
57 $n = new TestMessage();
58 $n->decode($data);
59 assert(2.0 === $n->getOneofFloat());
60
61 $m->setOneofString('abc');
62 assert(0 === $m->getOneofInt32());
63 assert(0.0 === $m->getOneofFloat());
64 assert('abc' === $m->getOneofString());
65 assert(NULL === $m->getOneofMessage());
66 $data = $m->encode();
67 $n = new TestMessage();
68 $n->decode($data);
69 assert('abc' === $n->getOneofString());
70
71 $sub_m = new TestMessage_Sub();
72 $sub_m->setA(1);
73 $m->setOneofMessage($sub_m);
74 assert(0 === $m->getOneofInt32());
75 assert(0.0 === $m->getOneofFloat());
76 assert('' === $m->getOneofString());
77 assert(1 === $m->getOneofMessage()->getA());
78 $data = $m->encode();
79 $n = new TestMessage();
80 $n->decode($data);
81 assert(1 === $n->getOneofMessage()->getA());
OLDNEW
« 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