1<?php
2
3use Foo\TestEnum;
4use Foo\TestMessage;
5use Foo\TestMessage\Sub;
6use Foo\TestPackedMessage;
7use Foo\TestUnpackedMessage;
8
9define('MAX_FLOAT_DIFF', 0.000001);
10
11if (PHP_INT_SIZE == 8) {
12    define('MAX_INT_STRING', '9223372036854775807');
13    define('MAX_INT_UPPER_STRING', '9223372036854775808');
14} else {
15    define('MAX_INT_STRING', '2147483647');
16    define('MAX_INT_UPPER_STRING', '2147483648');
17}
18
19define('MAX_INT32', 2147483647);
20define('MAX_INT32_FLOAT', 2147483647.0);
21define('MAX_INT32_STRING', '2147483647');
22
23define('MIN_INT32', (int)-2147483648);
24define('MIN_INT32_FLOAT', -2147483648.0);
25define('MIN_INT32_STRING', '-2147483648');
26
27define('MAX_UINT32', 4294967295);
28define('MAX_UINT32_FLOAT', 4294967295.0);
29define('MAX_UINT32_STRING', '4294967295');
30
31define('MIN_UINT32', (int)-2147483648);
32define('MIN_UINT32_FLOAT', -2147483648.0);
33define('MIN_UINT32_STRING', '-2147483648');
34
35define('MAX_INT64_STRING',  '9223372036854775807');
36define('MIN_INT64_STRING',  '-9223372036854775808');
37define('MAX_UINT64_STRING', '-9223372036854775808');
38
39if (PHP_INT_SIZE === 8) {
40    define('MAX_INT64',  (int)9223372036854775807);
41    define('MIN_INT64',  (int)-9223372036854775808);
42    define('MAX_UINT64', (int)-9223372036854775808);
43} else {
44    define('MAX_INT64', MAX_INT64_STRING);
45    define('MIN_INT64', MIN_INT64_STRING);
46    define('MAX_UINT64', MAX_UINT64_STRING);
47}
48
49class TestUtil
50{
51
52    public static function setTestMessage(TestMessage $m)
53    {
54        $m->setOptionalInt32(-42);
55        $m->setOptionalInt64(-43);
56        $m->setOptionalUint32(42);
57        $m->setOptionalUint64(43);
58        $m->setOptionalSint32(-44);
59        $m->setOptionalSint64(-45);
60        $m->setOptionalFixed32(46);
61        $m->setOptionalFixed64(47);
62        $m->setOptionalSfixed32(-46);
63        $m->setOptionalSfixed64(-47);
64        $m->setOptionalFloat(1.5);
65        $m->setOptionalDouble(1.6);
66        $m->setOptionalBool(true);
67        $m->setOptionalString('a');
68        $m->setOptionalBytes('bbbb');
69        $m->setOptionalEnum(TestEnum::ONE);
70        $sub = new Sub();
71        $m->setOptionalMessage($sub);
72        $m->getOptionalMessage()->SetA(33);
73
74        self::appendHelper($m, 'RepeatedInt32',    -42);
75        self::appendHelper($m, 'RepeatedInt64',    -43);
76        self::appendHelper($m, 'RepeatedUint32',    42);
77        self::appendHelper($m, 'RepeatedUint64',    43);
78        self::appendHelper($m, 'RepeatedSint32',   -44);
79        self::appendHelper($m, 'RepeatedSint64',   -45);
80        self::appendHelper($m, 'RepeatedFixed32',   46);
81        self::appendHelper($m, 'RepeatedFixed64',   47);
82        self::appendHelper($m, 'RepeatedSfixed32', -46);
83        self::appendHelper($m, 'RepeatedSfixed64', -47);
84        self::appendHelper($m, 'RepeatedFloat',    1.5);
85        self::appendHelper($m, 'RepeatedDouble',   1.6);
86        self::appendHelper($m, 'RepeatedBool',     true);
87        self::appendHelper($m, 'RepeatedString',   'a');
88        self::appendHelper($m, 'RepeatedBytes',    'bbbb');
89        self::appendHelper($m, 'RepeatedEnum',     TestEnum::ZERO);
90        self::appendHelper($m, 'RepeatedMessage',  new Sub());
91        $m->getRepeatedMessage()[0]->setA(34);
92
93        self::appendHelper($m, 'RepeatedInt32',    -52);
94        self::appendHelper($m, 'RepeatedInt64',    -53);
95        self::appendHelper($m, 'RepeatedUint32',    52);
96        self::appendHelper($m, 'RepeatedUint64',    53);
97        self::appendHelper($m, 'RepeatedSint32',   -54);
98        self::appendHelper($m, 'RepeatedSint64',   -55);
99        self::appendHelper($m, 'RepeatedFixed32',   56);
100        self::appendHelper($m, 'RepeatedFixed64',   57);
101        self::appendHelper($m, 'RepeatedSfixed32', -56);
102        self::appendHelper($m, 'RepeatedSfixed64', -57);
103        self::appendHelper($m, 'RepeatedFloat',    2.5);
104        self::appendHelper($m, 'RepeatedDouble',   2.6);
105        self::appendHelper($m, 'RepeatedBool',     false);
106        self::appendHelper($m, 'RepeatedString',   'c');
107        self::appendHelper($m, 'RepeatedBytes',    'dddd');
108        self::appendHelper($m, 'RepeatedEnum',     TestEnum::ONE);
109        self::appendHelper($m, 'RepeatedMessage',  new Sub());
110        $m->getRepeatedMessage()[1]->SetA(35);
111
112        self::kvUpdateHelper($m, 'MapInt32Int32', -62, -62);
113        self::kvUpdateHelper($m, 'MapInt64Int64', -63, -63);
114        self::kvUpdateHelper($m, 'MapUint32Uint32', 62, 62);
115        self::kvUpdateHelper($m, 'MapUint64Uint64', 63, 63);
116        self::kvUpdateHelper($m, 'MapSint32Sint32', -64, -64);
117        self::kvUpdateHelper($m, 'MapSint64Sint64', -65, -65);
118        self::kvUpdateHelper($m, 'MapFixed32Fixed32', 66, 66);
119        self::kvUpdateHelper($m, 'MapFixed64Fixed64', 67, 67);
120        self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -68, -68);
121        self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -69, -69);
122        self::kvUpdateHelper($m, 'MapInt32Float', 1, 3.5);
123        self::kvUpdateHelper($m, 'MapInt32Double', 1, 3.6);
124        self::kvUpdateHelper($m, 'MapBoolBool', true, true);
125        self::kvUpdateHelper($m, 'MapStringString', 'e', 'e');
126        self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'ffff');
127        self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::ONE);
128        self::kvUpdateHelper($m, 'MapInt32Message', 1, new Sub());
129        $m->getMapInt32Message()[1]->SetA(36);
130    }
131
132    public static function setTestMessage2(TestMessage $m)
133    {
134        $sub = new Sub();
135
136        $m->setOptionalInt32(-142);
137        $m->setOptionalInt64(-143);
138        $m->setOptionalUint32(142);
139        $m->setOptionalUint64(143);
140        $m->setOptionalSint32(-144);
141        $m->setOptionalSint64(-145);
142        $m->setOptionalFixed32(146);
143        $m->setOptionalFixed64(147);
144        $m->setOptionalSfixed32(-146);
145        $m->setOptionalSfixed64(-147);
146        $m->setOptionalFloat(11.5);
147        $m->setOptionalDouble(11.6);
148        $m->setOptionalBool(true);
149        $m->setOptionalString('aa');
150        $m->setOptionalBytes('bb');
151        $m->setOptionalEnum(TestEnum::TWO);
152        $m->setOptionalMessage($sub);
153        $m->getOptionalMessage()->SetA(133);
154
155        self::appendHelper($m, 'RepeatedInt32',    -142);
156        self::appendHelper($m, 'RepeatedInt64',    -143);
157        self::appendHelper($m, 'RepeatedUint32',    142);
158        self::appendHelper($m, 'RepeatedUint64',    143);
159        self::appendHelper($m, 'RepeatedSint32',   -144);
160        self::appendHelper($m, 'RepeatedSint64',   -145);
161        self::appendHelper($m, 'RepeatedFixed32',   146);
162        self::appendHelper($m, 'RepeatedFixed64',   147);
163        self::appendHelper($m, 'RepeatedSfixed32', -146);
164        self::appendHelper($m, 'RepeatedSfixed64', -147);
165        self::appendHelper($m, 'RepeatedFloat',    11.5);
166        self::appendHelper($m, 'RepeatedDouble',   11.6);
167        self::appendHelper($m, 'RepeatedBool',     false);
168        self::appendHelper($m, 'RepeatedString',   'aa');
169        self::appendHelper($m, 'RepeatedBytes',    'bb');
170        self::appendHelper($m, 'RepeatedEnum',     TestEnum::TWO);
171        self::appendHelper($m, 'RepeatedMessage',  new Sub());
172        $m->getRepeatedMessage()[0]->setA(134);
173
174        self::kvUpdateHelper($m, 'MapInt32Int32', -62, -162);
175        self::kvUpdateHelper($m, 'MapInt64Int64', -63, -163);
176        self::kvUpdateHelper($m, 'MapUint32Uint32', 62, 162);
177        self::kvUpdateHelper($m, 'MapUint64Uint64', 63, 163);
178        self::kvUpdateHelper($m, 'MapSint32Sint32', -64, -164);
179        self::kvUpdateHelper($m, 'MapSint64Sint64', -65, -165);
180        self::kvUpdateHelper($m, 'MapFixed32Fixed32', 66, 166);
181        self::kvUpdateHelper($m, 'MapFixed64Fixed64', 67, 167);
182        self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -68, -168);
183        self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -69, -169);
184        self::kvUpdateHelper($m, 'MapInt32Float', 1, 13.5);
185        self::kvUpdateHelper($m, 'MapInt32Double', 1, 13.6);
186        self::kvUpdateHelper($m, 'MapBoolBool', true, false);
187        self::kvUpdateHelper($m, 'MapStringString', 'e', 'ee');
188        self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'ff');
189        self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::TWO);
190        self::kvUpdateHelper($m, 'MapInt32Message', 1, new Sub());
191        $m->getMapInt32Message()[1]->SetA(136);
192
193        self::kvUpdateHelper($m, 'MapInt32Int32', -162, -162);
194        self::kvUpdateHelper($m, 'MapInt64Int64', -163, -163);
195        self::kvUpdateHelper($m, 'MapUint32Uint32', 162, 162);
196        self::kvUpdateHelper($m, 'MapUint64Uint64', 163, 163);
197        self::kvUpdateHelper($m, 'MapSint32Sint32', -164, -164);
198        self::kvUpdateHelper($m, 'MapSint64Sint64', -165, -165);
199        self::kvUpdateHelper($m, 'MapFixed32Fixed32', 166, 166);
200        self::kvUpdateHelper($m, 'MapFixed64Fixed64', 167, 167);
201        self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -168, -168);
202        self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -169, -169);
203        self::kvUpdateHelper($m, 'MapInt32Float', 2, 13.5);
204        self::kvUpdateHelper($m, 'MapInt32Double', 2, 13.6);
205        self::kvUpdateHelper($m, 'MapBoolBool', false, false);
206        self::kvUpdateHelper($m, 'MapStringString', 'ee', 'ee');
207        self::kvUpdateHelper($m, 'MapInt32Bytes', 2, 'ff');
208        self::kvUpdateHelper($m, 'MapInt32Enum', 2, TestEnum::TWO);
209        self::kvUpdateHelper($m, 'MapInt32Message', 2, new Sub());
210        $m->getMapInt32Message()[2]->SetA(136);
211    }
212
213    public static function assertTestMessage(TestMessage $m)
214    {
215        if (PHP_INT_SIZE == 4) {
216            assert('-43' === $m->getOptionalInt64());
217            assert('43'  === $m->getOptionalUint64());
218            assert('-45' === $m->getOptionalSint64());
219            assert('47'  === $m->getOptionalFixed64());
220            assert('-47' === $m->getOptionalSfixed64());
221        } else {
222            assert(-43 === $m->getOptionalInt64());
223            assert(43  === $m->getOptionalUint64());
224            assert(-45 === $m->getOptionalSint64());
225            assert(47  === $m->getOptionalFixed64());
226            assert(-47 === $m->getOptionalSfixed64());
227        }
228        assert(-42 === $m->getOptionalInt32());
229        assert(42  === $m->getOptionalUint32());
230        assert(-44 === $m->getOptionalSint32());
231        assert(46  === $m->getOptionalFixed32());
232        assert(-46 === $m->getOptionalSfixed32());
233        assert(1.5 === $m->getOptionalFloat());
234        assert(1.6 === $m->getOptionalDouble());
235        assert(true=== $m->getOptionalBool());
236        assert('a' === $m->getOptionalString());
237        assert('bbbb' === $m->getOptionalBytes());
238        assert(TestEnum::ONE === $m->getOptionalEnum());
239        assert(33  === $m->getOptionalMessage()->getA());
240
241        if (PHP_INT_SIZE == 4) {
242            assert('-43' === $m->getRepeatedInt64()[0]);
243            assert('43'  === $m->getRepeatedUint64()[0]);
244            assert('-45' === $m->getRepeatedSint64()[0]);
245            assert('47'  === $m->getRepeatedFixed64()[0]);
246            assert('-47' === $m->getRepeatedSfixed64()[0]);
247        } else {
248            assert(-43 === $m->getRepeatedInt64()[0]);
249            assert(43  === $m->getRepeatedUint64()[0]);
250            assert(-45 === $m->getRepeatedSint64()[0]);
251            assert(47  === $m->getRepeatedFixed64()[0]);
252            assert(-47 === $m->getRepeatedSfixed64()[0]);
253        }
254        assert(-42 === $m->getRepeatedInt32()[0]);
255        assert(42  === $m->getRepeatedUint32()[0]);
256        assert(-44 === $m->getRepeatedSint32()[0]);
257        assert(46  === $m->getRepeatedFixed32()[0]);
258        assert(-46 === $m->getRepeatedSfixed32()[0]);
259        assert(1.5 === $m->getRepeatedFloat()[0]);
260        assert(1.6 === $m->getRepeatedDouble()[0]);
261        assert(true=== $m->getRepeatedBool()[0]);
262        assert('a' === $m->getRepeatedString()[0]);
263        assert('bbbb' === $m->getRepeatedBytes()[0]);
264        assert(TestEnum::ZERO === $m->getRepeatedEnum()[0]);
265        assert(34  === $m->getRepeatedMessage()[0]->getA());
266
267        if (PHP_INT_SIZE == 4) {
268            assert('-53' === $m->getRepeatedInt64()[1]);
269            assert('53'  === $m->getRepeatedUint64()[1]);
270            assert('-55' === $m->getRepeatedSint64()[1]);
271            assert('57'  === $m->getRepeatedFixed64()[1]);
272            assert('-57' === $m->getRepeatedSfixed64()[1]);
273        } else {
274            assert(-53 === $m->getRepeatedInt64()[1]);
275            assert(53  === $m->getRepeatedUint64()[1]);
276            assert(-55 === $m->getRepeatedSint64()[1]);
277            assert(57  === $m->getRepeatedFixed64()[1]);
278            assert(-57 === $m->getRepeatedSfixed64()[1]);
279        }
280        assert(-52 === $m->getRepeatedInt32()[1]);
281        assert(52  === $m->getRepeatedUint32()[1]);
282        assert(-54 === $m->getRepeatedSint32()[1]);
283        assert(56  === $m->getRepeatedFixed32()[1]);
284        assert(-56 === $m->getRepeatedSfixed32()[1]);
285        assert(2.5 === $m->getRepeatedFloat()[1]);
286        assert(2.6 === $m->getRepeatedDouble()[1]);
287        assert(false === $m->getRepeatedBool()[1]);
288        assert('c' === $m->getRepeatedString()[1]);
289        assert('dddd' === $m->getRepeatedBytes()[1]);
290        assert(TestEnum::ONE === $m->getRepeatedEnum()[1]);
291        assert(35  === $m->getRepeatedMessage()[1]->getA());
292
293        if (PHP_INT_SIZE == 4) {
294            assert('-63' === $m->getMapInt64Int64()['-63']);
295            assert('63'  === $m->getMapUint64Uint64()['63']);
296            assert('-65' === $m->getMapSint64Sint64()['-65']);
297            assert('67'  === $m->getMapFixed64Fixed64()['67']);
298            assert('-69'  === $m->getMapSfixed64Sfixed64()['-69']);
299        } else {
300            assert(-63 === $m->getMapInt64Int64()[-63]);
301            assert(63  === $m->getMapUint64Uint64()[63]);
302            assert(-65 === $m->getMapSint64Sint64()[-65]);
303            assert(67  === $m->getMapFixed64Fixed64()[67]);
304            assert(-69  === $m->getMapSfixed64Sfixed64()[-69]);
305        }
306        assert(-62 === $m->getMapInt32Int32()[-62]);
307        assert(62  === $m->getMapUint32Uint32()[62]);
308        assert(-64 === $m->getMapSint32Sint32()[-64]);
309        assert(66  === $m->getMapFixed32Fixed32()[66]);
310        assert(-68  === $m->getMapSfixed32Sfixed32()[-68]);
311        assert(3.5 === $m->getMapInt32Float()[1]);
312        assert(3.6 === $m->getMapInt32Double()[1]);
313        assert(true === $m->getMapBoolBool()[true]);
314        assert('e' === $m->getMapStringString()['e']);
315        assert('ffff' === $m->getMapInt32Bytes()[1]);
316        assert(TestEnum::ONE === $m->getMapInt32Enum()[1]);
317        assert(36  === $m->getMapInt32Message()[1]->GetA());
318    }
319
320    public static function getGoldenTestMessage()
321    {
322        return hex2bin(
323            "08D6FFFFFFFFFFFFFFFF01" .
324            "10D5FFFFFFFFFFFFFFFF01" .
325            "182A" .
326            "202B" .
327            "2857" .
328            "3059" .
329            "3D2E000000" .
330            "412F00000000000000" .
331            "4DD2FFFFFF" .
332            "51D1FFFFFFFFFFFFFF" .
333            "5D0000C03F" .
334            "619A9999999999F93F" .
335            "6801" .
336            "720161" .
337            "7A0462626262" .
338            "800101" .
339            "8A01020821" .
340
341            "F801D6FFFFFFFFFFFFFFFF01" .
342            "F801CCFFFFFFFFFFFFFFFF01" .
343            "8002D5FFFFFFFFFFFFFFFF01" .
344            "8002CBFFFFFFFFFFFFFFFF01" .
345            "88022A" .
346            "880234" .
347            "90022B" .
348            "900235" .
349            "980257" .
350            "98026B" .
351            "A00259" .
352            "A0026D" .
353            "AD022E000000" .
354            "AD0238000000" .
355            "B1022F00000000000000" .
356            "B1023900000000000000" .
357            "BD02D2FFFFFF" .
358            "BD02C8FFFFFF" .
359            "C102D1FFFFFFFFFFFFFF" .
360            "C102C7FFFFFFFFFFFFFF" .
361            "CD020000C03F" .
362            "CD0200002040" .
363            "D1029A9999999999F93F" .
364            "D102CDCCCCCCCCCC0440" .
365            "D80201" .
366            "D80200" .
367            "E2020161" .
368            "E2020163" .
369            "EA020462626262" .
370            "EA020464646464" .
371            "F00200" .
372            "F00201" .
373            "FA02020822" .
374            "FA02020823" .
375
376            "BA041608C2FFFFFFFFFFFFFFFF0110C2FFFFFFFFFFFFFFFF01" .
377            "C2041608C1FFFFFFFFFFFFFFFF0110C1FFFFFFFFFFFFFFFF01" .
378            "CA0404083E103E" .
379            "D20404083F103F" .
380            "DA0404087f107F" .
381            "E20406088101108101" .
382            "EA040A0D420000001542000000" .
383            "F20412094300000000000000114300000000000000" .
384            "FA040A0DBCFFFFFF15BCFFFFFF" .
385            "82051209BBFFFFFFFFFFFFFF11BBFFFFFFFFFFFFFF" .
386            "8A050708011500006040" .
387            "92050B080111CDCCCCCCCCCC0C40" .
388            "9A050408011001" .
389            "A205060a0165120165" .
390            "AA05080801120466666666" .
391            "B2050408011001" .
392            "Ba0506080112020824"
393        );
394    }
395
396    public static function setTestPackedMessage($m)
397    {
398        self::appendHelper($m, 'RepeatedInt32', -42);
399        self::appendHelper($m, 'RepeatedInt32', -52);
400        self::appendHelper($m, 'RepeatedInt64', -43);
401        self::appendHelper($m, 'RepeatedInt64', -53);
402        self::appendHelper($m, 'RepeatedUint32', 42);
403        self::appendHelper($m, 'RepeatedUint32', 52);
404        self::appendHelper($m, 'RepeatedUint64', 43);
405        self::appendHelper($m, 'RepeatedUint64', 53);
406        self::appendHelper($m, 'RepeatedSint32', -44);
407        self::appendHelper($m, 'RepeatedSint32', -54);
408        self::appendHelper($m, 'RepeatedSint64', -45);
409        self::appendHelper($m, 'RepeatedSint64', -55);
410        self::appendHelper($m, 'RepeatedFixed32', 46);
411        self::appendHelper($m, 'RepeatedFixed32', 56);
412        self::appendHelper($m, 'RepeatedFixed64', 47);
413        self::appendHelper($m, 'RepeatedFixed64', 57);
414        self::appendHelper($m, 'RepeatedSfixed32', -46);
415        self::appendHelper($m, 'RepeatedSfixed32', -56);
416        self::appendHelper($m, 'RepeatedSfixed64', -47);
417        self::appendHelper($m, 'RepeatedSfixed64', -57);
418        self::appendHelper($m, 'RepeatedFloat', 1.5);
419        self::appendHelper($m, 'RepeatedFloat', 2.5);
420        self::appendHelper($m, 'RepeatedDouble', 1.6);
421        self::appendHelper($m, 'RepeatedDouble', 2.6);
422        self::appendHelper($m, 'RepeatedBool', true);
423        self::appendHelper($m, 'RepeatedBool', false);
424        self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE);
425        self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO);
426    }
427
428    public static function assertTestPackedMessage($m)
429    {
430        assert(2 === count($m->getRepeatedInt32()));
431        assert(2 === count($m->getRepeatedInt64()));
432        assert(2 === count($m->getRepeatedUint32()));
433        assert(2 === count($m->getRepeatedUint64()));
434        assert(2 === count($m->getRepeatedSint32()));
435        assert(2 === count($m->getRepeatedSint64()));
436        assert(2 === count($m->getRepeatedFixed32()));
437        assert(2 === count($m->getRepeatedFixed64()));
438        assert(2 === count($m->getRepeatedSfixed32()));
439        assert(2 === count($m->getRepeatedSfixed64()));
440        assert(2 === count($m->getRepeatedFloat()));
441        assert(2 === count($m->getRepeatedDouble()));
442        assert(2 === count($m->getRepeatedBool()));
443        assert(2 === count($m->getRepeatedEnum()));
444
445        assert(-42 === $m->getRepeatedInt32()[0]);
446        assert(-52 === $m->getRepeatedInt32()[1]);
447        assert(42  === $m->getRepeatedUint32()[0]);
448        assert(52  === $m->getRepeatedUint32()[1]);
449        assert(-44 === $m->getRepeatedSint32()[0]);
450        assert(-54 === $m->getRepeatedSint32()[1]);
451        assert(46  === $m->getRepeatedFixed32()[0]);
452        assert(56  === $m->getRepeatedFixed32()[1]);
453        assert(-46 === $m->getRepeatedSfixed32()[0]);
454        assert(-56 === $m->getRepeatedSfixed32()[1]);
455        assert(1.5 === $m->getRepeatedFloat()[0]);
456        assert(2.5 === $m->getRepeatedFloat()[1]);
457        assert(1.6 === $m->getRepeatedDouble()[0]);
458        assert(2.6 === $m->getRepeatedDouble()[1]);
459        assert(true  === $m->getRepeatedBool()[0]);
460        assert(false === $m->getRepeatedBool()[1]);
461        assert(TestEnum::ONE  === $m->getRepeatedEnum()[0]);
462        assert(TestEnum::ZERO === $m->getRepeatedEnum()[1]);
463        if (PHP_INT_SIZE == 4) {
464            assert('-43' === $m->getRepeatedInt64()[0]);
465            assert('-53' === $m->getRepeatedInt64()[1]);
466            assert('43'  === $m->getRepeatedUint64()[0]);
467            assert('53'  === $m->getRepeatedUint64()[1]);
468            assert('-45' === $m->getRepeatedSint64()[0]);
469            assert('-55' === $m->getRepeatedSint64()[1]);
470            assert('47'  === $m->getRepeatedFixed64()[0]);
471            assert('57'  === $m->getRepeatedFixed64()[1]);
472            assert('-47' === $m->getRepeatedSfixed64()[0]);
473            assert('-57' === $m->getRepeatedSfixed64()[1]);
474        } else {
475            assert(-43 === $m->getRepeatedInt64()[0]);
476            assert(-53 === $m->getRepeatedInt64()[1]);
477            assert(43  === $m->getRepeatedUint64()[0]);
478            assert(53  === $m->getRepeatedUint64()[1]);
479            assert(-45 === $m->getRepeatedSint64()[0]);
480            assert(-55 === $m->getRepeatedSint64()[1]);
481            assert(47  === $m->getRepeatedFixed64()[0]);
482            assert(57  === $m->getRepeatedFixed64()[1]);
483            assert(-47 === $m->getRepeatedSfixed64()[0]);
484            assert(-57 === $m->getRepeatedSfixed64()[1]);
485        }
486    }
487
488    public static function getGoldenTestPackedMessage()
489    {
490        return hex2bin(
491            "D20514D6FFFFFFFFFFFFFFFF01CCFFFFFFFFFFFFFFFF01" .
492            "DA0514D5FFFFFFFFFFFFFFFF01CBFFFFFFFFFFFFFFFF01" .
493            "E205022A34" .
494            "EA05022B35" .
495            "F20502576B" .
496            "FA0502596D" .
497            "8206082E00000038000000" .
498            "8A06102F000000000000003900000000000000" .
499            "920608D2FFFFFFC8FFFFFF" .
500            "9A0610D1FFFFFFFFFFFFFFC7FFFFFFFFFFFFFF" .
501            "A206080000C03F00002040" .
502            "AA06109A9999999999F93FCDCCCCCCCCCC0440" .
503            "B206020100" .
504            "BA06020100"
505        );
506    }
507
508    public static function getGoldenTestUnpackedMessage()
509    {
510        return hex2bin(
511            "D005D6FFFFFFFFFFFFFFFF01D005CCFFFFFFFFFFFFFFFF01" .
512            "D805D5FFFFFFFFFFFFFFFF01D805CBFFFFFFFFFFFFFFFF01" .
513            "E0052AE00534" .
514            "E8052BE80535" .
515            "F00557F0056B" .
516            "F80559F8056D" .
517            "85062E000000850638000000" .
518            "89062F0000000000000089063900000000000000" .
519            "9506D2FFFFFF9506C8FFFFFF" .
520            "9906D1FFFFFFFFFFFFFF9906C7FFFFFFFFFFFFFF" .
521            "A5060000C03FA50600002040" .
522            "A9069A9999999999F93FA906CDCCCCCCCCCC0440" .
523            "B00601B00600" .
524            "B80601B80600"
525        );
526    }
527
528    private static function appendHelper($obj, $func_suffix, $value)
529    {
530        $getter_function = 'get'.$func_suffix;
531        $setter_function = 'set'.$func_suffix;
532
533        $arr = $obj->$getter_function();
534        $arr[] = $value;
535        $obj->$setter_function($arr);
536    }
537
538    private static function kvUpdateHelper($obj, $func_suffix, $key, $value)
539    {
540        $getter_function = 'get'.$func_suffix;
541        $setter_function = 'set'.$func_suffix;
542
543        $arr = $obj->$getter_function();
544        $arr[$key] = $value;
545        $obj->$setter_function($arr);
546    }
547}
548