]> git.draconx.ca Git - dxcommon.git/blob - t/packtestu.c
Import integer packing library.
[dxcommon.git] / t / packtestu.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 result__ = (func)(pattern); \
15         if (!tap_result(result__ == (expected), "%s(%s)", #func, #expected)) { \
16                 tap_diag("  expected: %lu", (unsigned long)(expected)); \
17                 tap_diag("  actual:   %lu", result__); \
18         } \
19 } while (0)
20
21 int main(void)
22 {
23         tap_plan(12);
24
25         test(unpack_16_be, zero,         0);
26         test(unpack_16_be, minus_one,    0xffff);
27         test(unpack_16_be, test_pattern, 0xdead);
28         test(unpack_32_be, zero,         0);
29         test(unpack_32_be, minus_one,    0xffffffff);
30         test(unpack_32_be, test_pattern, 0xdeadbeef);
31
32         test(unpack_16_le, zero,         0);
33         test(unpack_16_le, minus_one,    0xffff);
34         test(unpack_16_le, test_pattern, 0xadde);
35         test(unpack_32_le, zero,         0);
36         test(unpack_32_le, minus_one,    0xffffffff);
37         test(unpack_32_le, test_pattern, 0xefbeadde);
38
39         tap_done();
40 }