From 34820dc5641bf98dec3339fd9b92c06fe631f7f7 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 24 Mar 2019 16:15:59 +0300 Subject: [PATCH] skips of tests on x32 CPUs added --- tests/APILengthCoDecTest.php | 35 +++++++++++++++++++++++++++++++- tests/Helpers/BinaryStringHelperTest.php | 22 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/tests/APILengthCoDecTest.php b/tests/APILengthCoDecTest.php index 5339591..3ccfbef 100644 --- a/tests/APILengthCoDecTest.php +++ b/tests/APILengthCoDecTest.php @@ -62,7 +62,26 @@ class APILengthCoDecTest extends TestCase [0xE0200000, 0x200000], // Low limit value for 4 bytes encoded length [0xE5AD736B, 0x5AD736B], // Arbitrary median value for 4 bytes encoded length [0xEFFFFFFF, 0xFFFFFFF], // High limit value for 4 bytes encoded length + ]; + } + + /** + * @dataProvider encodedLengthProvider64 + * @covers ::encodeLength + */ + public function test__encodeLength64($expected, $length) + { + if (PHP_INT_SIZE < 8) { + $this->markTestSkipped('Available only on x64 CPUs'); + } + + $this->assertEquals(BinaryStringHelper::IntegerToNBOBinaryString((int) $expected), APILengthCoDec::encodeLength($length)); + } + public function encodedLengthProvider64(): array + { + // [encoded length value, length value] + return [ [0xF010000000, 0x10000000], // Low limit value for 5 bytes encoded length [0xF10D4EF9C3, 0x10D4EF9C3], // Arbitrary median value for 5 bytes encoded length [0xF7FFFFFFFF, 0x7FFFFFFFF], // High limit value for 5 bytes encoded length @@ -73,7 +92,6 @@ class APILengthCoDecTest extends TestCase * @dataProvider encodedLengthProvider * @covers ::decodeLength */ - public function test__decodeLength($encodedLength, $expected) { // We have to provide $encodedLength as a "bytes" stream @@ -82,6 +100,21 @@ class APILengthCoDecTest extends TestCase } /** + * @dataProvider encodedLengthProvider64 + * @covers ::decodeLength + */ + public function test__decodeLength64($encodedLength, $expected) + { + if (PHP_INT_SIZE < 8) { + $this->markTestSkipped('Available only on x64 CPUs'); + } + + // We have to provide $encodedLength as a "bytes" stream + $stream = new StringStream(BinaryStringHelper::IntegerToNBOBinaryString($encodedLength)); + $this->assertEquals($expected, APILengthCoDec::decodeLength($stream)); + } + + /** * @dataProvider decodeLengthControlWordProvider * @covers ::decodeLength * @expectedException \UnexpectedValueException diff --git a/tests/Helpers/BinaryStringHelperTest.php b/tests/Helpers/BinaryStringHelperTest.php index b45b921..ad57101 100644 --- a/tests/Helpers/BinaryStringHelperTest.php +++ b/tests/Helpers/BinaryStringHelperTest.php @@ -42,4 +42,26 @@ class BinaryStringHelperTest extends TestCase [0x390DDD99, chr(0x39) . chr(0x0D) . chr(0xDD) . chr(0x99)], ]; } + + /** + * @dataProvider IntegerToNBOBinaryStringProvider64 + * @covers ::IntegerToNBOBinaryString + */ + public function test__IntegerToNBOBinaryString64($value, $expected) + { + if (PHP_INT_SIZE < 8) { + $this->markTestSkipped('Available only on x64 CPUs'); + } + + $this->assertEquals($expected, BinaryStringHelper::IntegerToNBOBinaryString($value)); + } + + public function IntegerToNBOBinaryStringProvider64(): array + { + return [ + // -1 is encoded with 0xFFFFFFF..... + // 64 bits maximal value (on a 64 bits system only) + [-1, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF)], // 64 bits upper boundary value + ]; + } }