2 * Copyright © 2015, 2023 Nick Bowler
4 * Test application to verify 64-bit signed unpacking functions.
6 * License WTFPL2: Do What The Fuck You Want To Public License, version 2.
7 * This is free software: you are free to do what the fuck you want to.
8 * There is NO WARRANTY, to the extent permitted by law.
14 static const unsigned char zero
[8];
15 static const unsigned char minus_one
[8] = {
16 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
19 static const unsigned char min
[9] = {
20 0x80, 0, 0, 0, 0, 0, 0, 0, 0x80
23 static const unsigned char test_pattern
[8] = {
24 0xde, 0xad, 0xbe, 0xef, 0xf0, 0x0d, 0xca, 0xfe
27 #define test(func, pattern, expected) do { \
28 long long result__ = (func)(pattern); \
29 if (!tap_result(result__ == (expected), "%s(%s)", #func, #expected)) { \
30 tap_diag(" expected: %lld", (long long)(expected)); \
31 tap_diag(" actual: %lld", result__); \
40 test(unpack_s64_be
, zero
, 0);
41 test(unpack_s64_be
, minus_one
, -1);
42 test(unpack_s64_be
, test_pattern
, -2401053088584709378ll);
43 test(unpack_s64_be
, min
, -9223372036854775807ll-1);
45 test(unpack_s64_le
, zero
, 0);
46 test(unpack_s64_le
, minus_one
, -1);
47 test(unpack_s64_le
, test_pattern
, -87241914314740258ll);
48 test(unpack_s64_le
, min
+1, -9223372036854775807ll-1);
50 tap_skip_all("no 64-bit support");