]> git.draconx.ca Git - dxcommon.git/blob - t/packtests64.c
Import integer packing library.
[dxcommon.git] / t / packtests64.c
1 #include "pack.h"
2 #include "tap.h"
3
4 static const unsigned char zero[8];
5 static const unsigned char minus_one[8] = {
6         0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7 };
8
9 static const unsigned char min[9] = {
10         0x80, 0, 0, 0, 0, 0, 0, 0, 0x80
11 };
12
13 static const unsigned char test_pattern[8] = {
14         0xde, 0xad, 0xbe, 0xef, 0xf0, 0x0d, 0xca, 0xfe
15 };
16
17 #define test(func, pattern, expected) do { \
18         long long result__ = (func)(pattern); \
19         if (!tap_result(result__ == (expected), "%s(%s)", #func, #expected)) { \
20                 tap_diag("  expected: %ld", (long long)(expected)); \
21                 tap_diag("  actual:   %ld", result__); \
22         } \
23 } while (0)
24
25 int main(void)
26 {
27 #if PACK_HAVE_64BIT
28         tap_plan(8);
29
30         test(unpack_s64_be, zero,          0);
31         test(unpack_s64_be, minus_one,    -1);
32         test(unpack_s64_be, test_pattern, -2401053088584709378);
33         test(unpack_s64_be, min,          -9223372036854775807-1);
34
35         test(unpack_s64_le, zero,          0);
36         test(unpack_s64_le, minus_one,    -1);
37         test(unpack_s64_le, test_pattern, -87241914314740258);
38         test(unpack_s64_le, min+1,        -9223372036854775807-1);
39 #else
40         tap_skip_all("no 64-bit support");
41 #endif
42
43         tap_done();
44 }