function test($type, $variable, $test = null) { $msgpack = new MessagePack(); if (version_compare(PHP_VERSION, '5.1.0') < 0) { $msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unpacker = new MessagePackUnpacker(); if (version_compare(PHP_VERSION, '5.1.0') < 0) { $unpacker->setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $unpacker->setOption(MessagePack::OPT_PHPONLY, false); } $length = strlen($serialized); if (rand(0, 1)) { for ($i = 0; $i < $length;) { $len = rand(1, 10); $str = substr($serialized, $i, $len); $unpacker->feed($str); if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } $i += $len; } } else { $str = ""; $offset = 0; for ($i = 0; $i < $length;) { $len = rand(1, 10); $str .= substr($serialized, $i, $len); if ($unpacker->execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = ""; $offset = 0; } $i += $len; } } if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } }
function test($type, $variable, $object, $result = null) { $msgpack = new MessagePack(); if (version_compare(PHP_VERSION, '5.1.0') <= 0) { $msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } }
function test($type, $variable, $test = null) { $msgpack = new MessagePack(); if (version_compare(PHP_VERSION, '5.1.0') < 0) { $msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized); var_dump($unserialized); if (!is_bool($test)) { echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; } else { echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; } }
function test($type, $variable, $object, $result = null) { $msgpack = new MessagePack(); $msgpack->setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } }