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