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 "FA0114D6FFFFFFFFFFFFFFFF01CCFFFFFFFFFFFFFFFF01" . 342 "820214D5FFFFFFFFFFFFFFFF01CBFFFFFFFFFFFFFFFF01" . 343 "8A02022A34" . 344 "9202022B35" . 345 "9A0202576B" . 346 "A20202596D" . 347 "AA02082E00000038000000" . 348 "B202102F000000000000003900000000000000" . 349 "BA0208D2FFFFFFC8FFFFFF" . 350 "C20210D1FFFFFFFFFFFFFFC7FFFFFFFFFFFFFF" . 351 "CA02080000C03F00002040" . 352 "D202109A9999999999F93FCDCCCCCCCCCC0440" . 353 "DA02020100" . 354 "E2020161" . 355 "E2020163" . 356 "EA020462626262" . 357 "EA020464646464" . 358 "F202020001" . 359 "FA02020822" . 360 "FA02020823" . 361 362 "BA041608C2FFFFFFFFFFFFFFFF0110C2FFFFFFFFFFFFFFFF01" . 363 "C2041608C1FFFFFFFFFFFFFFFF0110C1FFFFFFFFFFFFFFFF01" . 364 "CA0404083E103E" . 365 "D20404083F103F" . 366 "DA0404087f107F" . 367 "E20406088101108101" . 368 "EA040A0D420000001542000000" . 369 "F20412094300000000000000114300000000000000" . 370 "FA040A0DBCFFFFFF15BCFFFFFF" . 371 "82051209BBFFFFFFFFFFFFFF11BBFFFFFFFFFFFFFF" . 372 "8A050708011500006040" . 373 "92050B080111CDCCCCCCCCCC0C40" . 374 "9A050408011001" . 375 "A205060a0165120165" . 376 "AA05080801120466666666" . 377 "B2050408011001" . 378 "Ba0506080112020824" 379 ); 380 } 381 382 public static function setTestPackedMessage($m) 383 { 384 self::appendHelper($m, 'RepeatedInt32', -42); 385 self::appendHelper($m, 'RepeatedInt32', -52); 386 self::appendHelper($m, 'RepeatedInt64', -43); 387 self::appendHelper($m, 'RepeatedInt64', -53); 388 self::appendHelper($m, 'RepeatedUint32', 42); 389 self::appendHelper($m, 'RepeatedUint32', 52); 390 self::appendHelper($m, 'RepeatedUint64', 43); 391 self::appendHelper($m, 'RepeatedUint64', 53); 392 self::appendHelper($m, 'RepeatedSint32', -44); 393 self::appendHelper($m, 'RepeatedSint32', -54); 394 self::appendHelper($m, 'RepeatedSint64', -45); 395 self::appendHelper($m, 'RepeatedSint64', -55); 396 self::appendHelper($m, 'RepeatedFixed32', 46); 397 self::appendHelper($m, 'RepeatedFixed32', 56); 398 self::appendHelper($m, 'RepeatedFixed64', 47); 399 self::appendHelper($m, 'RepeatedFixed64', 57); 400 self::appendHelper($m, 'RepeatedSfixed32', -46); 401 self::appendHelper($m, 'RepeatedSfixed32', -56); 402 self::appendHelper($m, 'RepeatedSfixed64', -47); 403 self::appendHelper($m, 'RepeatedSfixed64', -57); 404 self::appendHelper($m, 'RepeatedFloat', 1.5); 405 self::appendHelper($m, 'RepeatedFloat', 2.5); 406 self::appendHelper($m, 'RepeatedDouble', 1.6); 407 self::appendHelper($m, 'RepeatedDouble', 2.6); 408 self::appendHelper($m, 'RepeatedBool', true); 409 self::appendHelper($m, 'RepeatedBool', false); 410 self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE); 411 self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO); 412 } 413 414 public static function assertTestPackedMessage($m) 415 { 416 assert(2 === count($m->getRepeatedInt32())); 417 assert(2 === count($m->getRepeatedInt64())); 418 assert(2 === count($m->getRepeatedUint32())); 419 assert(2 === count($m->getRepeatedUint64())); 420 assert(2 === count($m->getRepeatedSint32())); 421 assert(2 === count($m->getRepeatedSint64())); 422 assert(2 === count($m->getRepeatedFixed32())); 423 assert(2 === count($m->getRepeatedFixed64())); 424 assert(2 === count($m->getRepeatedSfixed32())); 425 assert(2 === count($m->getRepeatedSfixed64())); 426 assert(2 === count($m->getRepeatedFloat())); 427 assert(2 === count($m->getRepeatedDouble())); 428 assert(2 === count($m->getRepeatedBool())); 429 assert(2 === count($m->getRepeatedEnum())); 430 431 assert(-42 === $m->getRepeatedInt32()[0]); 432 assert(-52 === $m->getRepeatedInt32()[1]); 433 assert(42 === $m->getRepeatedUint32()[0]); 434 assert(52 === $m->getRepeatedUint32()[1]); 435 assert(-44 === $m->getRepeatedSint32()[0]); 436 assert(-54 === $m->getRepeatedSint32()[1]); 437 assert(46 === $m->getRepeatedFixed32()[0]); 438 assert(56 === $m->getRepeatedFixed32()[1]); 439 assert(-46 === $m->getRepeatedSfixed32()[0]); 440 assert(-56 === $m->getRepeatedSfixed32()[1]); 441 assert(1.5 === $m->getRepeatedFloat()[0]); 442 assert(2.5 === $m->getRepeatedFloat()[1]); 443 assert(1.6 === $m->getRepeatedDouble()[0]); 444 assert(2.6 === $m->getRepeatedDouble()[1]); 445 assert(true === $m->getRepeatedBool()[0]); 446 assert(false === $m->getRepeatedBool()[1]); 447 assert(TestEnum::ONE === $m->getRepeatedEnum()[0]); 448 assert(TestEnum::ZERO === $m->getRepeatedEnum()[1]); 449 if (PHP_INT_SIZE == 4) { 450 assert('-43' === $m->getRepeatedInt64()[0]); 451 assert('-53' === $m->getRepeatedInt64()[1]); 452 assert('43' === $m->getRepeatedUint64()[0]); 453 assert('53' === $m->getRepeatedUint64()[1]); 454 assert('-45' === $m->getRepeatedSint64()[0]); 455 assert('-55' === $m->getRepeatedSint64()[1]); 456 assert('47' === $m->getRepeatedFixed64()[0]); 457 assert('57' === $m->getRepeatedFixed64()[1]); 458 assert('-47' === $m->getRepeatedSfixed64()[0]); 459 assert('-57' === $m->getRepeatedSfixed64()[1]); 460 } else { 461 assert(-43 === $m->getRepeatedInt64()[0]); 462 assert(-53 === $m->getRepeatedInt64()[1]); 463 assert(43 === $m->getRepeatedUint64()[0]); 464 assert(53 === $m->getRepeatedUint64()[1]); 465 assert(-45 === $m->getRepeatedSint64()[0]); 466 assert(-55 === $m->getRepeatedSint64()[1]); 467 assert(47 === $m->getRepeatedFixed64()[0]); 468 assert(57 === $m->getRepeatedFixed64()[1]); 469 assert(-47 === $m->getRepeatedSfixed64()[0]); 470 assert(-57 === $m->getRepeatedSfixed64()[1]); 471 } 472 } 473 474 public static function getGoldenTestPackedMessage() 475 { 476 return hex2bin( 477 "D20514D6FFFFFFFFFFFFFFFF01CCFFFFFFFFFFFFFFFF01" . 478 "DA0514D5FFFFFFFFFFFFFFFF01CBFFFFFFFFFFFFFFFF01" . 479 "E205022A34" . 480 "EA05022B35" . 481 "F20502576B" . 482 "FA0502596D" . 483 "8206082E00000038000000" . 484 "8A06102F000000000000003900000000000000" . 485 "920608D2FFFFFFC8FFFFFF" . 486 "9A0610D1FFFFFFFFFFFFFFC7FFFFFFFFFFFFFF" . 487 "A206080000C03F00002040" . 488 "AA06109A9999999999F93FCDCCCCCCCCCC0440" . 489 "B206020100" . 490 "BA06020100" 491 ); 492 } 493 494 public static function getGoldenTestUnpackedMessage() 495 { 496 return hex2bin( 497 "D005D6FFFFFFFFFFFFFFFF01D005CCFFFFFFFFFFFFFFFF01" . 498 "D805D5FFFFFFFFFFFFFFFF01D805CBFFFFFFFFFFFFFFFF01" . 499 "E0052AE00534" . 500 "E8052BE80535" . 501 "F00557F0056B" . 502 "F80559F8056D" . 503 "85062E000000850638000000" . 504 "89062F0000000000000089063900000000000000" . 505 "9506D2FFFFFF9506C8FFFFFF" . 506 "9906D1FFFFFFFFFFFFFF9906C7FFFFFFFFFFFFFF" . 507 "A5060000C03FA50600002040" . 508 "A9069A9999999999F93FA906CDCCCCCCCCCC0440" . 509 "B00601B00600" . 510 "B80601B80600" 511 ); 512 } 513 514 private static function appendHelper($obj, $func_suffix, $value) 515 { 516 $getter_function = 'get'.$func_suffix; 517 $setter_function = 'set'.$func_suffix; 518 519 $arr = $obj->$getter_function(); 520 $arr[] = $value; 521 $obj->$setter_function($arr); 522 } 523 524 private static function kvUpdateHelper($obj, $func_suffix, $key, $value) 525 { 526 $getter_function = 'get'.$func_suffix; 527 $setter_function = 'set'.$func_suffix; 528 529 $arr = $obj->$getter_function(); 530 $arr[$key] = $value; 531 $obj->$setter_function($arr); 532 } 533} 534