]> git.draconx.ca Git - dxcommon.git/blob - t/packtests.c
Import integer packing library.
[dxcommon.git] / t / packtests.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 result__ = (func)(pattern); \
19         if (!tap_result(result__ == (expected), "%s(%s)", #func, #expected)) { \
20                 tap_diag("  expected: %ld", (long)(expected)); \
21                 tap_diag("  actual:   %ld", result__); \
22         } \
23 } while (0)
24
25 int main(void)
26 {
27         tap_plan(16);
28
29         test(unpack_s16_be, zero,          0);
30         test(unpack_s16_be, minus_one,    -1);
31         test(unpack_s16_be, test_pattern, -8531);
32         test(unpack_s16_be, min,          -32767-1);
33         test(unpack_s32_be, zero,          0);
34         test(unpack_s32_be, minus_one,    -1);
35         test(unpack_s32_be, test_pattern, -559038737);
36         test(unpack_s32_be, min,          -2147483647-1);
37
38         test(unpack_s16_le, zero,          0);
39         test(unpack_s16_le, minus_one,    -1);
40         test(unpack_s16_le, test_pattern, -21026);
41         test(unpack_s16_le, min+7,        -32767-1);
42         test(unpack_s32_le, zero,          0);
43         test(unpack_s32_le, minus_one,    -1);
44         test(unpack_s32_le, test_pattern, -272716322);
45         test(unpack_s32_le, min+5,        -2147483647-1);
46
47         tap_done();
48 }