‎Testen von Binärdaten

Test::BinaryData

is_binary
    "\x00 A",
    "\x00 B",
    'binary data';

Test::BinaryData (ref)

is_binary
    "\x00 A",
    [ qw( 00 20 42 ) ],
    'binary data (ref)';

Test::BinaryData beschränken

is_binary
    'AA' x 512,
    'AB' x 512,
    'binary data (attr)',
    {
        columns   => 79,
        max_diffs => 2,
    };

Test::Bits

bits_is
    "\x01\x02",
    [ qw( 0b1 0b11 ) ],
    'bits';
not ok 4 - bits
#   Failed test 'bits'
#   at ...
# Binary data begins differing at byte 1.
#   Got:    00000010
#   Expect: 00000011

Test::HexString

is_hexstr
    "\x01ABC",
    "\x01ABCD",
    'hex string';

Test::HexDifferences

eq_or_dump_diff
    "\x01ABC",
    "\x01ABCD",
    'diff';

Test::HexDifferences

dumped_eq_dump_or_diff
    "\x01ABC",
    <<'EOT',
0000 : 01414243 : .ABC
0004 : 44       : D
EOT
    'diff dump';

Test::HexDifferences Optionen 1/2

eq_or_dump_diff
    "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
    . "\x01\x23\x45\x67"
    . "\x89\xAB\xCD\xEF",
    "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
    . "\x01\x23\x45\x67"
    . "\x89\xAB\xCD\xEF"
    . "\xFF",
    {
        address => 0x4000,
        format  => <<"EOT",
%a : %N %4C : %d\n%1x%
%a : %n %2C : %d\n%*x
EOT
    },
    'diff format';

Test::HexDifferences Optionen 2/2

Test::HexDifferences Default-Format

"%a : %4C : %d\n"

oder komplett geschrieben

"%a : %4C : %d\n%*x"

Wenn die Daten länger als das Format sind, greift wieder das default Format.

Test::HexDifferences Daten-Format

%C  - unsigned char
%S  - unsigned 16-bit, endian depends on machine
%S< - unsigned 16-bit, little-endian
%S> - unsigned 16-bit, big-endian
%v  - unsigned 16-bit, little-endian
%n  - unsigned 16-bit, big-endian
%L  - unsigned 32-bit, endian depends on machine
%L< - unsigned 32-bit, little-endian
%L> - unsigned 32-bit, big-endian
%V  - unsigned 32-bit, little-endian
%N  - unsigned 32-bit, big-endian
%Q  - unsigned 64-bit, endian depends on machine
%Q< - unsigned 64-bit, little-endian
%Q> - unsigned 64-bit, big-endian

Test::HexDifferences Adress-Format

%a  - 16 bit address
%4a - 16 bit address
%8a - 32 bit address

Test::HexDifferences ASCII-Format

%d - ASCII anzeigen, was nicht geht als .

Test::HexDifferences Wiederholung

%*x - endlos
%1x - 1 Mal
%2x - 2 Mal
...

Test::HexDifferences \n

%\n - ignore \n

Ende