2010-05-06 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / eglib / test / endian.c
blob3347d765ffe394e73fbe6f20f5d2f0e9935b6664
1 #include "test.h"
3 RESULT
4 test_swap ()
6 guint32 a = 0xabcdef01, res32;
7 guint64 b = (((guint64)a) << 32) | a, res64;
8 guint64 b_expect = (((guint64)0x1efcdab) << 32) | 0x01efcdab;
9 guint16 c = 0xabcd, res16;
11 res32 = GUINT32_SWAP_LE_BE (a);
12 if (res32 != 0x01efcdab)
13 return FAILED ("GUINT32_SWAP_LE_BE returned 0x%x", res32);
14 res32 = GUINT32_SWAP_LE_BE (1);
15 if (res32 != 0x1000000)
16 return FAILED ("GUINT32_SWAP_LE_BE returned 0x%x", res32);
18 res64 = GUINT64_SWAP_LE_BE(b);
19 if (res64 != b_expect)
20 return FAILED ("GUINT64_SWAP_LE_BE returned 0x%llx (had=0x%llx)", res64, b);
21 res16 = GUINT16_SWAP_LE_BE(c);
22 if (res16 != 0xcdab)
23 return FAILED ("GUINT16_SWAP_LE_BE returned 0x%x", (guint32) res16);
25 return OK;
29 * test initialization
32 static Test endian_tests [] = {
33 {"swap", test_swap},
34 {NULL, NULL}
37 DEFINE_TEST_GROUP_INIT(endian_tests_init, endian_tests)