test_util.php 23 KB

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