]> git.draconx.ca Git - dxcommon.git/blob - t/packtestu64.c
Import integer packing library.
[dxcommon.git] / t / packtestu64.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 test_pattern[8] = {
10         0xde, 0xad, 0xbe, 0xef, 0xf0, 0x0d, 0xca, 0xfe
11 };
12
13 #define test(func, pattern, expected) do { \
14         unsigned long long result__ = (func)(pattern); \
15         if (!tap_result(result__ == (expected), "%s(%s)", #func, #expected)) { \
16                 tap_diag("  expected: %llu", (unsigned long long)(expected)); \
17                 tap_diag("  actual:   %llu", result__); \
18         } \
19 } while (0)
20
21 int main(void)
22 {
23 #if PACK_HAVE_64BIT
24         tap_plan(6);
25
26         test(unpack_64_be, zero,         0);
27         test(unpack_64_be, minus_one,    0xffffffffffffffff);
28         test(unpack_64_be, test_pattern, 0xdeadbeeff00dcafe);
29         test(unpack_64_le, zero,         0);
30         test(unpack_64_le, minus_one,    0xffffffffffffffff);
31         test(unpack_64_le, test_pattern, 0xfeca0df0efbeadde);
32 #else
33         tap_skip_all("no 64-bit support");
34 #endif
35
36         tap_done();
37 }