1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-23 13:36:25 +00:00
ext-encoding/tests/not-enough-bytes-fixed-size.phpt
Dylan K. Taylor 56673dd789
Split Types class into several new classes
the main benefit of this is the increased difficulty of accidentally
using the wrong byte order due to auto complete - now choosing byte
order is decided by the first character typed.

however, it also reduces the verbosity of the API, though I'm not sure
about the 'LE' and 'BE' class names.
2024-04-10 16:34:24 +01:00

92 lines
3.6 KiB
PHP

--TEST--
read*() for fixed-size type must throw DataDecodeException when not enough bytes are available
--EXTENSIONS--
encoding
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\DataDecodeException;
$functions = require __DIR__ . '/fixed-size-types.inc';
$test = str_repeat("\x00", 16);
foreach($functions as [$function, $buf]){
try{
$buffer = new ByteBuffer("\x00");
$function($buffer);
}catch(DataDecodeException $e){
$reflect = new \ReflectionFunction($function);
echo $reflect->getClosureScopeClass()->getShortName() . "::" . $reflect->getName() . " no offset: " . $e->getMessage() . "\n";
}
try{
$buffer = new ByteBuffer($test);
$buffer->setReadOffset(15);
$function($buffer);
}catch(DataDecodeException $e){
$reflect = new \ReflectionFunction($function);
echo $reflect->getClosureScopeClass()->getShortName() . "::" . $reflect->getName() . " with offset: " . $e->getMessage() . "\n";
}
echo "\n";
}
?>
--EXPECT--
LE::readUnsignedShort no offset: Need at least 2 bytes, but only have 1 bytes
LE::readUnsignedShort with offset: Need at least 2 bytes, but only have 1 bytes
LE::readSignedShort no offset: Need at least 2 bytes, but only have 1 bytes
LE::readSignedShort with offset: Need at least 2 bytes, but only have 1 bytes
BE::readUnsignedShort no offset: Need at least 2 bytes, but only have 1 bytes
BE::readUnsignedShort with offset: Need at least 2 bytes, but only have 1 bytes
BE::readSignedShort no offset: Need at least 2 bytes, but only have 1 bytes
BE::readSignedShort with offset: Need at least 2 bytes, but only have 1 bytes
LE::readUnsignedInt no offset: Need at least 4 bytes, but only have 1 bytes
LE::readUnsignedInt with offset: Need at least 4 bytes, but only have 1 bytes
LE::readSignedInt no offset: Need at least 4 bytes, but only have 1 bytes
LE::readSignedInt with offset: Need at least 4 bytes, but only have 1 bytes
LE::readFloat no offset: Need at least 4 bytes, but only have 1 bytes
LE::readFloat with offset: Need at least 4 bytes, but only have 1 bytes
BE::readUnsignedInt no offset: Need at least 4 bytes, but only have 1 bytes
BE::readUnsignedInt with offset: Need at least 4 bytes, but only have 1 bytes
BE::readSignedInt no offset: Need at least 4 bytes, but only have 1 bytes
BE::readSignedInt with offset: Need at least 4 bytes, but only have 1 bytes
BE::readFloat no offset: Need at least 4 bytes, but only have 1 bytes
BE::readFloat with offset: Need at least 4 bytes, but only have 1 bytes
LE::readSignedLong no offset: Need at least 8 bytes, but only have 1 bytes
LE::readSignedLong with offset: Need at least 8 bytes, but only have 1 bytes
BE::readSignedLong no offset: Need at least 8 bytes, but only have 1 bytes
BE::readSignedLong with offset: Need at least 8 bytes, but only have 1 bytes
LE::readDouble no offset: Need at least 8 bytes, but only have 1 bytes
LE::readDouble with offset: Need at least 8 bytes, but only have 1 bytes
BE::readDouble no offset: Need at least 8 bytes, but only have 1 bytes
BE::readDouble with offset: Need at least 8 bytes, but only have 1 bytes
BE::readUnsignedTriad no offset: Need at least 3 bytes, but only have 1 bytes
BE::readUnsignedTriad with offset: Need at least 3 bytes, but only have 1 bytes
LE::readUnsignedTriad no offset: Need at least 3 bytes, but only have 1 bytes
LE::readUnsignedTriad with offset: Need at least 3 bytes, but only have 1 bytes
BE::readSignedTriad no offset: Need at least 3 bytes, but only have 1 bytes
BE::readSignedTriad with offset: Need at least 3 bytes, but only have 1 bytes
LE::readSignedTriad no offset: Need at least 3 bytes, but only have 1 bytes
LE::readSignedTriad with offset: Need at least 3 bytes, but only have 1 bytes