summaryrefslogtreecommitdiffstats
path: root/tests/endian/endian_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/endian/endian_test.c')
-rw-r--r--tests/endian/endian_test.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/endian/endian_test.c b/tests/endian/endian_test.c
new file mode 100644
index 00000000..8737e7a4
--- /dev/null
+++ b/tests/endian/endian_test.c
@@ -0,0 +1,31 @@
+#include <osmocom/core/byteswap.h>
+#include <osmocom/core/utils.h>
+
+int main(int argc, char **argv)
+{
+ printf("Testing 16bit swappinng\n");
+ OSMO_ASSERT(osmo_swab16(0x1234) == 0x3412);
+ printf("Testing 32bit swappinng\n");
+ OSMO_ASSERT(osmo_swab32(0x12345678) == 0x78563412);
+
+ printf("Testing ntohX() and htonX()\n");
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#if OSMO_IS_LITTLE_ENDIAN == 0
+#error "Something wrong with endianness detection!"
+#endif /* IS_LITTLE_ENDIAN */
+ OSMO_ASSERT(osmo_ntohs(0x1234) == 0x3412);
+ OSMO_ASSERT(osmo_htons(0x1234) == 0x3412);
+ OSMO_ASSERT(osmo_htonl(0x12345678) == 0x78563412);
+ OSMO_ASSERT(osmo_ntohl(0x12345678) == 0x78563412);
+#else
+#if OSMO_IS_LITTLE_ENDIAN == 1
+#error "Something wrong with endianness detection!"
+#endif /* IS_LITTLE_ENDIAN */
+ OSMO_ASSERT(osmo_ntohs(0x1234) == 0x1234);
+ OSMO_ASSERT(osmo_htons(0x1234) == 0x1234);
+ OSMO_ASSERT(osmo_htonl(0x12345678) == 0x12345678);
+ OSMO_ASSERT(osmo_ntohl(0x12345678) == 0x12345678);
+#endif /* __BYTE_ORDER__ */
+
+ exit(0);
+}