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

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: Update to new HEAD (b7632464b4) + restore GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER 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('test.pb.php');
6 require_once('test_util.php');
7
8 use Google\Protobuf\Internal\RepeatedField;
9 use Google\Protobuf\Internal\GPBType;
10 use Foo\TestMessage;
11 use Foo\TestMessage_Sub;
12
13 $from = new TestMessage();
14 TestUtil::setTestMessage($from);
15 TestUtil::assertTestMessage($from);
16
17 $data = $from->encode();
18
19 $to = new TestMessage();
20 $to->decode($data);
21
22 TestUtil::assertTestMessage($to);
23
24 $from->setRecursive($from);
25
26 $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
27 $arr []= new TestMessage;
28 $arr[0]->SetRepeatedRecursive($arr);
29
30 // Test oneof fields.
31 $m = new TestMessage();
32
33 $m->setOneofInt32(1);
34 assert(1 === $m->getOneofInt32());
35 assert(0.0 === $m->getOneofFloat());
36 assert('' === $m->getOneofString());
37 assert(NULL === $m->getOneofMessage());
38 $data = $m->encode();
39 $n = new TestMessage();
40 $n->decode($data);
41 assert(1 === $n->getOneofInt32());
42
43 $m->setOneofFloat(2.0);
44 assert(0 === $m->getOneofInt32());
45 assert(2.0 === $m->getOneofFloat());
46 assert('' === $m->getOneofString());
47 assert(NULL === $m->getOneofMessage());
48 $data = $m->encode();
49 $n = new TestMessage();
50 $n->decode($data);
51 assert(2.0 === $n->getOneofFloat());
52
53 $m->setOneofString('abc');
54 assert(0 === $m->getOneofInt32());
55 assert(0.0 === $m->getOneofFloat());
56 assert('abc' === $m->getOneofString());
57 assert(NULL === $m->getOneofMessage());
58 $data = $m->encode();
59 $n = new TestMessage();
60 $n->decode($data);
61 assert('abc' === $n->getOneofString());
62
63 $sub_m = new TestMessage_Sub();
64 $sub_m->setA(1);
65 $m->setOneofMessage($sub_m);
66 assert(0 === $m->getOneofInt32());
67 assert(0.0 === $m->getOneofFloat());
68 assert('' === $m->getOneofString());
69 assert(1 === $m->getOneofMessage()->getA());
70 $data = $m->encode();
71 $n = new TestMessage();
72 $n->decode($data);
73 assert(1 === $n->getOneofMessage()->getA());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698