X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Flsolesen%2Fpel%2Ftest%2FDataWindowTest.php;fp=vendor%2Flsolesen%2Fpel%2Ftest%2FDataWindowTest.php;h=5bb06e7d13c35af96e6e7300a8ca5bdcea31e36d;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/vendor/lsolesen/pel/test/DataWindowTest.php b/vendor/lsolesen/pel/test/DataWindowTest.php new file mode 100644 index 000000000..5bb06e7d1 --- /dev/null +++ b/vendor/lsolesen/pel/test/DataWindowTest.php @@ -0,0 +1,140 @@ +assertEquals($window->getSize(), 8); + $this->assertEquals($window->getBytes(), 'abcdefgh'); + + $this->assertEquals($window->getBytes(0), 'abcdefgh'); + $this->assertEquals($window->getBytes(1), 'bcdefgh'); + $this->assertEquals($window->getBytes(7), 'h'); + // $this->assertEquals($window->getBytes(8), ''); + + $this->assertEquals($window->getBytes(- 1), 'h'); + $this->assertEquals($window->getBytes(- 2), 'gh'); + $this->assertEquals($window->getBytes(- 7), 'bcdefgh'); + $this->assertEquals($window->getBytes(- 8), 'abcdefgh'); + + $clone = $window->getClone(2, 4); + $this->assertEquals($clone->getSize(), 4); + $this->assertEquals($clone->getBytes(), 'cdef'); + + $this->assertEquals($clone->getBytes(0), 'cdef'); + $this->assertEquals($clone->getBytes(1), 'def'); + $this->assertEquals($clone->getBytes(3), 'f'); + // $this->assertEquals($clone->getBytes(4), ''); + + $this->assertEquals($clone->getBytes(- 1), 'f'); + $this->assertEquals($clone->getBytes(- 2), 'ef'); + $this->assertEquals($clone->getBytes(- 3), 'def'); + $this->assertEquals($clone->getBytes(- 4), 'cdef'); + + $caught = false; + try { + $clone->getBytes(0, 6); + } catch (PelDataWindowOffsetException $e) { + $caught = true; + } + $this->assertTrue($caught); + } + + function testReadIntegers() + { + $window = new PelDataWindow("\x01\x02\x03\x04", PelConvert::BIG_ENDIAN); + + $this->assertEquals($window->getSize(), 4); + $this->assertEquals($window->getBytes(), "\x01\x02\x03\x04"); + + $this->assertEquals($window->getByte(0), 0x01); + $this->assertEquals($window->getByte(1), 0x02); + $this->assertEquals($window->getByte(2), 0x03); + $this->assertEquals($window->getByte(3), 0x04); + + $this->assertEquals($window->getShort(0), 0x0102); + $this->assertEquals($window->getShort(1), 0x0203); + $this->assertEquals($window->getShort(2), 0x0304); + + $this->assertEquals($window->getLong(0), 0x01020304); + + $window->setByteOrder(PelConvert::LITTLE_ENDIAN); + $this->assertEquals($window->getSize(), 4); + $this->assertEquals($window->getBytes(), "\x01\x02\x03\x04"); + + $this->assertEquals($window->getByte(0), 0x01); + $this->assertEquals($window->getByte(1), 0x02); + $this->assertEquals($window->getByte(2), 0x03); + $this->assertEquals($window->getByte(3), 0x04); + + $this->assertEquals($window->getShort(0), 0x0201); + $this->assertEquals($window->getShort(1), 0x0302); + $this->assertEquals($window->getShort(2), 0x0403); + + $this->assertEquals($window->getLong(0), 0x04030201); + } + + function testReadBigIntegers() + { + $window = new PelDataWindow("\x89\xAB\xCD\xEF", PelConvert::BIG_ENDIAN); + + $this->assertEquals($window->getSize(), 4); + $this->assertEquals($window->getBytes(), "\x89\xAB\xCD\xEF"); + + $this->assertEquals($window->getByte(0), 0x89); + $this->assertEquals($window->getByte(1), 0xAB); + $this->assertEquals($window->getByte(2), 0xCD); + $this->assertEquals($window->getByte(3), 0xEF); + + $this->assertEquals($window->getShort(0), 0x89AB); + $this->assertEquals($window->getShort(1), 0xABCD); + $this->assertEquals($window->getShort(2), 0xCDEF); + + $this->assertEquals($window->getLong(0), 0x89ABCDEF); + + $window->setByteOrder(PelConvert::LITTLE_ENDIAN); + $this->assertEquals($window->getSize(), 4); + $this->assertEquals($window->getBytes(), "\x89\xAB\xCD\xEF"); + + $this->assertEquals($window->getByte(0), 0x89); + $this->assertEquals($window->getByte(1), 0xAB); + $this->assertEquals($window->getByte(2), 0xCD); + $this->assertEquals($window->getByte(3), 0xEF); + + $this->assertEquals($window->getShort(0), 0xAB89); + $this->assertEquals($window->getShort(1), 0xCDAB); + $this->assertEquals($window->getShort(2), 0xEFCD); + + $this->assertEquals($window->getLong(0), 0xEFCDAB89); + } +}