/** * test serializing packets */ public function testSerializingPackets() { $testData = new AmfTestData(); /* template //Packet with $serializer = new AmfSerializerWrapper($testData->d); $serialized = $serializer->serialize(); $expectedSerialized = $testData->s; $this->assertEquals(bin2hex($expectedSerialized), bin2hex($serialized)); */ //Packet with null header $serializer = new AmfSerializerWrapper($testData->dNullHeaderPacket); $serialized = $serializer->serialize($testData->dNullHeaderPacket); $expectedSerialized = $testData->sNullHeaderPacket; $this->assertEquals(bin2hex($expectedSerialized), bin2hex($serialized)); //Packet with string header $serializer = new AmfSerializerWrapper($testData->dStringHeaderPacket); $serialized = $serializer->serialize($testData->dStringHeaderPacket); $expectedSerialized = $testData->sStringHeaderPacket; $this->assertEquals(bin2hex($expectedSerialized), bin2hex($serialized)); //Packet with null Message $serializer = new AmfSerializerWrapper($testData->dNullMessagePacket); $serialized = $serializer->serialize($testData->dNullMessagePacket); $expectedSerialized = $testData->sNullMessagePacket; $this->assertEquals(bin2hex($expectedSerialized), bin2hex($serialized)); //Packet with string Message $serializer = new AmfSerializerWrapper($testData->dStringMessagePacket); $serialized = $serializer->serialize($testData->dStringMessagePacket); $expectedSerialized = $testData->sStringMessagePacket; $this->assertEquals(bin2hex($expectedSerialized), bin2hex($serialized)); //Packet with 2 headers and 2 Messages $serializer = new AmfSerializerWrapper($testData->d2Headers2MessagesPacket); $serialized = $serializer->serialize($testData->d2Headers2MessagesPacket); $expectedSerialized = $testData->s2Headers2MessagesPacket; $this->assertEquals(bin2hex($expectedSerialized), bin2hex($serialized)); }
/** * test basic methods */ public function testBasicMethods() { $testData = new Amf3TestData(); $emptyPacket = new Amfphp_Core_Amf_Packet(); $emptyPacket->amfVersion = Amfphp_Core_Amf_Constants::AMF3_ENCODING; /* template //write $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->write($testData->d); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->s; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); */ //undefined $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Undefined(); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sUndefined; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //null $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Null(); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sNull; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //false $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Bool(false); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sFalse; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //true $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Bool(true); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sTrue; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //integer $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Number($testData->dInt1); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sInt1; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Number($testData->dInt2); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sInt2; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //double $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Number($testData->dDouble); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sDouble; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //string $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3String($testData->dEmptyString); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sEmptyString; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3String($testData->dString); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sString; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3String($testData->dString); $serializer->writeAmf3String($testData->dString); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sStringTwice; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //xml $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Xml($testData->dXml); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sXml; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //xml document $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3XmlDocument($testData->dXmlDocument); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sXmlDocument; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //date $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Date($testData->dDate); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sDate; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //array $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Array($testData->dEmptyArray); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sEmptyArray; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Array($testData->dDenseArray); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sDenseArray; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3Array($testData->dMixedArray); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sMixedArray; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //object $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3TypedObject($testData->dObject); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sObject; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //ByteArray $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAmf3ByteArray($testData->dByteArray); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sByteArray; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //Vector int $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAMF3Vector($testData->dVectorInt); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sVectorInt; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //Vector uint $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAMF3Vector($testData->dVectorUint); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sVectorUint; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //Vector double $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAMF3Vector($testData->dVectorDouble); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sVectorDouble; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //Vector object $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAMF3Vector($testData->dVectorObject); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sVectorObject; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); //dictionary /* not supported. $serializer = new AmfSerializerWrapper($emptyPacket); $serializer->writeAMF3Dictionary($testData->dDictionary); $serialized = $serializer->getOutput(); $expectedSerialized = $testData->sDictionary; $this->assertEquals(bin2hex($serialized), bin2hex($expectedSerialized)); * */ }