From 2d551ec1250fda9fced7ad606e98fa01401ebf96 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Mon, 11 Feb 2019 13:16:34 +0100 Subject: [PATCH] tests/core: Add tests for little endian functions --- .../tests-core/tests-core-byteorder.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unittests/tests-core/tests-core-byteorder.c b/tests/unittests/tests-core/tests-core-byteorder.c index e7e554a37c..5ffe7cd445 100644 --- a/tests/unittests/tests-core/tests-core-byteorder.c +++ b/tests/unittests/tests-core/tests-core-byteorder.c @@ -120,6 +120,30 @@ static void test_byteorder_htobebufl(void) TEST_ASSERT_EQUAL_INT(0, memcmp(bebuf, tmp, sizeof(tmp))); } +static void test_byteorder_htols(void) +{ + static const uint16_t host = 0x1234; + le_uint16_t le = { .u8 = { 0x34, 0x12 } }; + TEST_ASSERT_EQUAL_INT(le.u16, byteorder_htols(host).u16); + TEST_ASSERT_EQUAL_INT(host, byteorder_ltohs(le)); +} + +static void test_byteorder_htoll(void) +{ + static const uint32_t host = 0x12345678ul; + le_uint32_t le = { .u8 = { 0x78, 0x56, 0x34, 0x12, } }; + TEST_ASSERT_EQUAL_INT(le.u32, byteorder_htoll(host).u32); + TEST_ASSERT_EQUAL_INT(host, byteorder_ltohl(le)); +} + +static void test_byteorder_htolll(void) +{ + static const uint64_t host = 0x123456789abcdef0ull; + le_uint64_t le = { .u8 = { 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12 } }; + TEST_ASSERT_EQUAL_INT(le.u64, byteorder_htolll(host).u64); + TEST_ASSERT_EQUAL_INT(host, byteorder_ltohll(le)); +} + Test *tests_core_byteorder_tests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { @@ -136,6 +160,9 @@ Test *tests_core_byteorder_tests(void) new_TestFixture(test_byteorder_htobebufs), new_TestFixture(test_byteorder_bebuftohl), new_TestFixture(test_byteorder_htobebufl), + new_TestFixture(test_byteorder_htols), + new_TestFixture(test_byteorder_htoll), + new_TestFixture(test_byteorder_htolll), }; EMB_UNIT_TESTCALLER(core_byteorder_tests, NULL, NULL, fixtures);