blob: dd0697a9a041c77a92db0efd069aca7232a1454c [file] [log] [blame]
Harald Welte3318c652017-05-15 12:07:51 +02001#include <osmocom/core/byteswap.h>
2#include <osmocom/core/utils.h>
Neels Hofmeyrb2600392018-11-16 00:20:39 +01003#include <osmocom/core/endian.h>
Harald Welte3318c652017-05-15 12:07:51 +02004
5int main(int argc, char **argv)
6{
7 printf("Testing 16bit swappinng\n");
8 OSMO_ASSERT(osmo_swab16(0x1234) == 0x3412);
9 printf("Testing 32bit swappinng\n");
10 OSMO_ASSERT(osmo_swab32(0x12345678) == 0x78563412);
11
12 printf("Testing ntohX() and htonX()\n");
13#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
14#if OSMO_IS_LITTLE_ENDIAN == 0
15#error "Something wrong with endianness detection!"
16#endif /* IS_LITTLE_ENDIAN */
17 OSMO_ASSERT(osmo_ntohs(0x1234) == 0x3412);
18 OSMO_ASSERT(osmo_htons(0x1234) == 0x3412);
19 OSMO_ASSERT(osmo_htonl(0x12345678) == 0x78563412);
20 OSMO_ASSERT(osmo_ntohl(0x12345678) == 0x78563412);
21#else
22#if OSMO_IS_LITTLE_ENDIAN == 1
23#error "Something wrong with endianness detection!"
24#endif /* IS_LITTLE_ENDIAN */
25 OSMO_ASSERT(osmo_ntohs(0x1234) == 0x1234);
26 OSMO_ASSERT(osmo_htons(0x1234) == 0x1234);
27 OSMO_ASSERT(osmo_htonl(0x12345678) == 0x12345678);
28 OSMO_ASSERT(osmo_ntohl(0x12345678) == 0x12345678);
29#endif /* __BYTE_ORDER__ */
30
31 exit(0);
32}