|
|
|
@ -11,6 +11,7 @@ use RouterOS\Helpers\BinaryStringHelper; |
|
|
|
|
|
|
|
/** |
|
|
|
* Limit code coverage to the class |
|
|
|
* |
|
|
|
* @coversDefaultClass \RouterOS\APILengthCoDec |
|
|
|
*/ |
|
|
|
class APILengthCoDecTest extends TestCase |
|
|
|
@ -25,7 +26,7 @@ class APILengthCoDecTest extends TestCase |
|
|
|
APILengthCoDec::encodeLength($length); |
|
|
|
} |
|
|
|
|
|
|
|
public function encodeLengthNegativeProvider() |
|
|
|
public function encodeLengthNegativeProvider(): array |
|
|
|
{ |
|
|
|
return [ |
|
|
|
[-1], |
|
|
|
@ -39,10 +40,10 @@ class APILengthCoDecTest extends TestCase |
|
|
|
*/ |
|
|
|
public function test__encodeLength($expected, $length) |
|
|
|
{ |
|
|
|
$this->assertEquals(BinaryStringHelper::IntegerToNBOBinaryString($expected), APILengthCoDec::encodeLength($length)); |
|
|
|
$this->assertEquals(BinaryStringHelper::IntegerToNBOBinaryString((int) $expected), APILengthCoDec::encodeLength($length)); |
|
|
|
} |
|
|
|
|
|
|
|
public function encodedLengthProvider() |
|
|
|
public function encodedLengthProvider(): array |
|
|
|
{ |
|
|
|
// [encoded length value, length value]
|
|
|
|
return [ |
|
|
|
@ -54,7 +55,7 @@ class APILengthCoDecTest extends TestCase |
|
|
|
[0x9C42, 0x1C42], // Arbitrary median value for 2 bytes encoded length
|
|
|
|
[0xBFFF, 0x3FFF], // High limit value for 2 bytes encoded length
|
|
|
|
|
|
|
|
[0xC04000, 0x4000], // Low limit value for 3 bytesv
|
|
|
|
[0xC04000, 0x4000], // Low limit value for 3 bytes
|
|
|
|
[0xCAD73B, 0xAD73B], // Arbitrary median value for 3 bytes encoded length
|
|
|
|
[0xDFFFFF, 0x1FFFFF], // High limit value for 3 bytes encoded length
|
|
|
|
|
|
|
|
@ -83,19 +84,19 @@ class APILengthCoDecTest extends TestCase |
|
|
|
/** |
|
|
|
* @dataProvider decodeLengthControlWordProvider |
|
|
|
* @covers ::decodeLength |
|
|
|
* @expectedException UnexpectedValueException |
|
|
|
* @expectedException \UnexpectedValueException |
|
|
|
*/ |
|
|
|
public function test_decodeLengthControlWord(string $encodedLength) |
|
|
|
{ |
|
|
|
APILengthCoDec::decodeLength(new StringStream($encodedLength)); |
|
|
|
} |
|
|
|
|
|
|
|
public function decodeLengthControlWordProvider() |
|
|
|
public function decodeLengthControlWordProvider(): array |
|
|
|
{ |
|
|
|
// Control bytes : 5 most signficants its sets to 1
|
|
|
|
// Control bytes: 5 most significance its sets to 1
|
|
|
|
return [ |
|
|
|
[chr(0xF8)], // minimum
|
|
|
|
[chr(0xFC)], // arbitraty value
|
|
|
|
[chr(0xFC)], // arbitrary value
|
|
|
|
[chr(0xFF)], // maximum
|
|
|
|
]; |
|
|
|
} |
|
|
|
|