1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/core: Add tests for little endian functions

This commit is contained in:
Koen Zandberg 2019-02-11 13:16:34 +01:00 committed by Benjamin Valentin
parent 374d032b82
commit 2d551ec125

View File

@ -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);