mirror of
https://github.com/Rogiel/star-replay
synced 2025-12-06 06:32:46 +00:00
Initial commit
This commit is contained in:
63
tests/Parser/Header/HeaderParserTest.php
Normal file
63
tests/Parser/Header/HeaderParserTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2016, Rogiel Sulzbach
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace Rogiel\StarReplay\Tests\Parser\Header;
|
||||
|
||||
|
||||
use Rogiel\StarReplay\Parser\Header\HeaderParser;
|
||||
use Rogiel\StarReplay\Tests\AbstractTestCase;
|
||||
|
||||
class HeaderParserTest extends AbstractTestCase {
|
||||
|
||||
/**
|
||||
* 3.1.0.38215
|
||||
*/
|
||||
const SAMPLE_HEADER_3_1_0_38215 = "051000022c537461724372616674204949207265706c61791b313102050c00090202090604090006090008098ed5040a098ed5040409040609f0c3030806000a05020202204a573d3b894e57d56e3f96a77e29eb800c098ed5040e0502020220620a2cb0fb47fb61d17ab256d535531a";
|
||||
|
||||
/**
|
||||
* @var HeaderParser
|
||||
*/
|
||||
private $headerParser;
|
||||
|
||||
public function setUp() {
|
||||
$this->headerParser = new HeaderParser();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function testParsePatch3_1_0_38215() {
|
||||
$header = $this->headerParser->parse($this->createMemoryParser(hex2bin(self::SAMPLE_HEADER_3_1_0_38215)));
|
||||
$this->assertEquals(3, $header->getMajorVersion());
|
||||
$this->assertEquals(1, $header->getMinorVersion());
|
||||
$this->assertEquals(0, $header->getPatchVersion());
|
||||
$this->assertEquals(38215, $header->getBuildVersion());
|
||||
|
||||
$this->assertEquals("StarCraft II replay\e11", (string)$header->getMagicString());
|
||||
}
|
||||
|
||||
}
|
||||
123
tests/Parser/Serializer/DefaultSerializerTest.php
Normal file
123
tests/Parser/Serializer/DefaultSerializerTest.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2016, Rogiel Sulzbach
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace Rogiel\StarReplay\Tests;
|
||||
|
||||
use Rogiel\StarReplay\Parser\Serializer\DefaultSerializer;
|
||||
use Rogiel\StarReplay\Parser\Serializer\Serializer;
|
||||
|
||||
class DefaultSerializerTest extends AbstractTestCase {
|
||||
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
public function setUp() {
|
||||
$this->serializer = new DefaultSerializer();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function testVariableLengthInteger() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"09". /* variable integer type */
|
||||
"AC01" /* 86 */
|
||||
)));
|
||||
$this->assertEquals(86, $result);
|
||||
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"09". /* variable integer type */
|
||||
"0A" /* 5 */
|
||||
)));
|
||||
$this->assertEquals(5, $result);
|
||||
}
|
||||
|
||||
public function testUnserializeString() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"02". /* string type */
|
||||
"2C". /* string length (variable length int) */
|
||||
"48656c6c6f20576f726c64" /* "Hello World" */
|
||||
)));
|
||||
$this->assertEquals("Hello World", $result);
|
||||
}
|
||||
|
||||
public function testUnserializeNonEmptyArray() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"04". /* array type */
|
||||
"0100". /* non empty */
|
||||
"04". /* 2 items */
|
||||
"0902". /* integer 1 */
|
||||
"0904" /* integer 2 */
|
||||
)));
|
||||
$this->assertEquals(array(1, 2), $result);
|
||||
}
|
||||
|
||||
public function testUnserializeEmptyArray() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"04". /* array type */
|
||||
"00" /* empty */
|
||||
)));
|
||||
$this->assertEquals(NULL, $result);
|
||||
}
|
||||
|
||||
public function testUnserializeIndexedArray() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"05". /* indexed array type */
|
||||
"04". /* 2 items */
|
||||
"020914". /* 1 => 10 */
|
||||
"04090A" /* 2 => 5 */
|
||||
)));
|
||||
$this->assertEquals(array(1 => 10, 2 => 5), $result);
|
||||
}
|
||||
|
||||
public function testUnserializeEmptyIndexedArray() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"05". /* indexed array type */
|
||||
"00" /* 0 items */
|
||||
)));
|
||||
$this->assertEquals(array(), $result);
|
||||
}
|
||||
|
||||
public function testUnserializeByte() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"06". /* byte type */
|
||||
"FF" /* 0 items */
|
||||
)));
|
||||
$this->assertEquals(0xFF, $result);
|
||||
}
|
||||
|
||||
public function testUnserializeUInt32() {
|
||||
$result = $this->serializer->unserialize($this->createMemoryParser(hex2bin(
|
||||
"07". /* UInt32 type */
|
||||
"BEEF0000" /* 0 items */
|
||||
)));
|
||||
$this->assertEquals(0x0000EFBE, $result);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user