public function testOneofField()
 {
     $m = new TestMessage();
     $m->setOneofInt32(1);
     $this->assertSame(1, $m->getOneofInt32());
     $this->assertSame(0.0, $m->getOneofFloat());
     $this->assertSame('', $m->getOneofString());
     $this->assertSame(NULL, $m->getOneofMessage());
     $m->setOneofFloat(2.0);
     $this->assertSame(0, $m->getOneofInt32());
     $this->assertSame(2.0, $m->getOneofFloat());
     $this->assertSame('', $m->getOneofString());
     $this->assertSame(NULL, $m->getOneofMessage());
     $m->setOneofString('abc');
     $this->assertSame(0, $m->getOneofInt32());
     $this->assertSame(0.0, $m->getOneofFloat());
     $this->assertSame('abc', $m->getOneofString());
     $this->assertSame(NULL, $m->getOneofMessage());
     $sub_m = new TestMessage_Sub();
     $sub_m->setA(1);
     $m->setOneofMessage($sub_m);
     $this->assertSame(0, $m->getOneofInt32());
     $this->assertSame(0.0, $m->getOneofFloat());
     $this->assertSame('', $m->getOneofString());
     $this->assertSame(1, $m->getOneofMessage()->getA());
 }
$n->decode($data);
assert(1 === $n->getOneofInt32());
$m->setOneofFloat(2.0);
assert(0 === $m->getOneofInt32());
assert(2.0 === $m->getOneofFloat());
assert('' === $m->getOneofString());
assert(NULL === $m->getOneofMessage());
$data = $m->encode();
$n = new TestMessage();
$n->decode($data);
assert(2.0 === $n->getOneofFloat());
$m->setOneofString('abc');
assert(0 === $m->getOneofInt32());
assert(0.0 === $m->getOneofFloat());
assert('abc' === $m->getOneofString());
assert(NULL === $m->getOneofMessage());
$data = $m->encode();
$n = new TestMessage();
$n->decode($data);
assert('abc' === $n->getOneofString());
$sub_m = new TestMessage_Sub();
$sub_m->setA(1);
$m->setOneofMessage($sub_m);
assert(0 === $m->getOneofInt32());
assert(0.0 === $m->getOneofFloat());
assert('' === $m->getOneofString());
assert(1 === $m->getOneofMessage()->getA());
$data = $m->encode();
$n = new TestMessage();
$n->decode($data);
assert(1 === $n->getOneofMessage()->getA());
Beispiel #3
0
 public function expectEmptyFields(TestMessage $m)
 {
     $this->assertSame(0, $m->getOptionalInt32());
     $this->assertSame(0, $m->getOptionalUint32());
     $this->assertSame(0, $m->getOptionalInt64());
     $this->assertSame(0, $m->getOptionalUint64());
     $this->assertSame(0, $m->getOptionalSint32());
     $this->assertSame(0, $m->getOptionalSint64());
     $this->assertSame(0, $m->getOptionalFixed32());
     $this->assertSame(0, $m->getOptionalFixed64());
     $this->assertSame(0, $m->getOptionalSfixed32());
     $this->assertSame(0, $m->getOptionalSfixed64());
     $this->assertSame(0.0, $m->getOptionalFloat());
     $this->assertSame(0.0, $m->getOptionalDouble());
     $this->assertSame(false, $m->getOptionalBool());
     $this->assertSame('', $m->getOptionalString());
     $this->assertSame('', $m->getOptionalBytes());
     $this->assertNull($m->getOptionalMessage());
 }
Beispiel #4
0
 public static function assertTestMessage(TestMessage $m)
 {
     if (PHP_INT_SIZE == 4) {
         assert('-43' === $m->getOptionalInt64());
         assert('43' === $m->getOptionalUint64());
         assert('-45' === $m->getOptionalSint64());
         assert('47' === $m->getOptionalFixed64());
         assert('-47' === $m->getOptionalSfixed64());
     } else {
         assert(-43 === $m->getOptionalInt64());
         assert(43 === $m->getOptionalUint64());
         assert(-45 === $m->getOptionalSint64());
         assert(47 === $m->getOptionalFixed64());
         assert(-47 === $m->getOptionalSfixed64());
     }
     assert(-42 === $m->getOptionalInt32());
     assert(42 === $m->getOptionalUint32());
     assert(-44 === $m->getOptionalSint32());
     assert(46 === $m->getOptionalFixed32());
     assert(-46 === $m->getOptionalSfixed32());
     assert(1.5 === $m->getOptionalFloat());
     assert(1.6 === $m->getOptionalDouble());
     assert(true === $m->getOptionalBool());
     assert('a' === $m->getOptionalString());
     assert('b' === $m->getOptionalBytes());
     assert(TestEnum::ONE === $m->getOptionalEnum());
     assert(33 === $m->getOptionalMessage()->getA());
     if (PHP_INT_SIZE == 4) {
         assert('-43' === $m->getRepeatedInt64()[0]);
         assert('43' === $m->getRepeatedUint64()[0]);
         assert('-45' === $m->getRepeatedSint64()[0]);
         assert('47' === $m->getRepeatedFixed64()[0]);
         assert('-47' === $m->getRepeatedSfixed64()[0]);
     } else {
         assert(-43 === $m->getRepeatedInt64()[0]);
         assert(43 === $m->getRepeatedUint64()[0]);
         assert(-45 === $m->getRepeatedSint64()[0]);
         assert(47 === $m->getRepeatedFixed64()[0]);
         assert(-47 === $m->getRepeatedSfixed64()[0]);
     }
     assert(-42 === $m->getRepeatedInt32()[0]);
     assert(42 === $m->getRepeatedUint32()[0]);
     assert(-44 === $m->getRepeatedSint32()[0]);
     assert(46 === $m->getRepeatedFixed32()[0]);
     assert(-46 === $m->getRepeatedSfixed32()[0]);
     assert(1.5 === $m->getRepeatedFloat()[0]);
     assert(1.6 === $m->getRepeatedDouble()[0]);
     assert(true === $m->getRepeatedBool()[0]);
     assert('a' === $m->getRepeatedString()[0]);
     assert('b' === $m->getRepeatedBytes()[0]);
     assert(TestEnum::ZERO === $m->getRepeatedEnum()[0]);
     assert(34 === $m->getRepeatedMessage()[0]->getA());
     if (PHP_INT_SIZE == 4) {
         assert('-53' === $m->getRepeatedInt64()[1]);
         assert('53' === $m->getRepeatedUint64()[1]);
         assert('-55' === $m->getRepeatedSint64()[1]);
         assert('57' === $m->getRepeatedFixed64()[1]);
         assert('-57' === $m->getRepeatedSfixed64()[1]);
     } else {
         assert(-53 === $m->getRepeatedInt64()[1]);
         assert(53 === $m->getRepeatedUint64()[1]);
         assert(-55 === $m->getRepeatedSint64()[1]);
         assert(57 === $m->getRepeatedFixed64()[1]);
         assert(-57 === $m->getRepeatedSfixed64()[1]);
     }
     assert(-52 === $m->getRepeatedInt32()[1]);
     assert(52 === $m->getRepeatedUint32()[1]);
     assert(-54 === $m->getRepeatedSint32()[1]);
     assert(56 === $m->getRepeatedFixed32()[1]);
     assert(-56 === $m->getRepeatedSfixed32()[1]);
     assert(2.5 === $m->getRepeatedFloat()[1]);
     assert(2.6 === $m->getRepeatedDouble()[1]);
     assert(false === $m->getRepeatedBool()[1]);
     assert('c' === $m->getRepeatedString()[1]);
     assert('d' === $m->getRepeatedBytes()[1]);
     assert(TestEnum::ONE === $m->getRepeatedEnum()[1]);
     assert(35 === $m->getRepeatedMessage()[1]->getA());
     if (PHP_INT_SIZE == 4) {
         assert('-63' === $m->getMapInt64Int64()['-63']);
         assert('63' === $m->getMapUint64Uint64()['63']);
         assert('-65' === $m->getMapSint64Sint64()['-65']);
         assert('67' === $m->getMapFixed64Fixed64()['67']);
     } else {
         assert(-63 === $m->getMapInt64Int64()[-63]);
         assert(63 === $m->getMapUint64Uint64()[63]);
         assert(-65 === $m->getMapSint64Sint64()[-65]);
         assert(67 === $m->getMapFixed64Fixed64()[67]);
     }
     assert(-62 === $m->getMapInt32Int32()[-62]);
     assert(62 === $m->getMapUint32Uint32()[62]);
     assert(-64 === $m->getMapSint32Sint32()[-64]);
     assert(66 === $m->getMapFixed32Fixed32()[66]);
     assert(3.5 === $m->getMapInt32Float()[1]);
     assert(3.6 === $m->getMapInt32Double()[1]);
     assert(true === $m->getMapBoolBool()[true]);
     assert('e' === $m->getMapStringString()['e']);
     assert('f' === $m->getMapInt32Bytes()[1]);
     assert(TestEnum::ONE === $m->getMapInt32Enum()[1]);
     assert(36 === $m->getMapInt32Message()[1]->GetA());
 }
 public function testDecode()
 {
     $m = new TestMessage();
     $m->decode(TestUtil::getGoldenTestMessage());
     TestUtil::assertTestMessage($m);
 }