gen-strtab.awk: Work around IRIX 6.2 nawk bug.
[dxcommon.git] / t / packtests.c
blob308acb32cf1a5e47ec01a48ed389f8b4255225d3
1 /*
2 * Copyright © 2015 Nick Bowler
4 * Test application to verify 16 and 32-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.
9 */
11 #include "pack.h"
12 #include "tap.h"
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 result__ = (func)(pattern); \
29 if (!tap_result(result__ == (expected), "%s(%s)", #func, #expected)) { \
30 tap_diag(" expected: %ld", (long)(expected)); \
31 tap_diag(" actual: %ld", result__); \
32 } \
33 } while (0)
35 int main(void)
37 tap_plan(16);
39 test(unpack_s16_be, zero, 0);
40 test(unpack_s16_be, minus_one, -1);
41 test(unpack_s16_be, test_pattern, -8531);
42 test(unpack_s16_be, min, -32767-1);
43 test(unpack_s32_be, zero, 0);
44 test(unpack_s32_be, minus_one, -1);
45 test(unpack_s32_be, test_pattern, -559038737);
46 test(unpack_s32_be, min, -2147483647-1);
48 test(unpack_s16_le, zero, 0);
49 test(unpack_s16_le, minus_one, -1);
50 test(unpack_s16_le, test_pattern, -21026);
51 test(unpack_s16_le, min+7, -32767-1);
52 test(unpack_s32_le, zero, 0);
53 test(unpack_s32_le, minus_one, -1);
54 test(unpack_s32_le, test_pattern, -272716322);
55 test(unpack_s32_le, min+5, -2147483647-1);
57 tap_done();