1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-23 13:36:25 +00:00
ext-encoding/tests/write-triad.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

34 lines
828 B
PHP

--TEST--
Test that writing triads works as expected
--DESCRIPTION--
Triads require special implementation due to not being a power-of-two size. This opens avenues for extra bugs that must be tested for.
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\BE;
use pmmp\encoding\LE;
$buffer = new ByteBuffer();
BE::writeSignedTriad($buffer, -65536);
var_dump($buffer->toString() === "\xff\x00\x00");
$buffer = new ByteBuffer();
LE::writeSignedTriad($buffer, -65536);
var_dump($buffer->toString() === "\x00\x00\xff");
$buffer = new ByteBuffer();
BE::writeUnsignedTriad($buffer, -65536);
var_dump($buffer->toString() === "\xff\x00\x00");
$buffer = new ByteBuffer();
LE::writeUnsignedTriad($buffer, -65536);
var_dump($buffer->toString() === "\x00\x00\xff");
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)