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

tests: Cover API of scn_u32_hex in the unittest

This commit is contained in:
Teufelchen1 2024-03-12 11:46:07 +01:00
parent 4d2b2f7ade
commit 4917b59005

View File

@ -852,13 +852,18 @@ static void test_scn_u32_dec(void)
static void test_scn_u32_hex(void)
{
const char *string1 = "aB12cE4F";
uint32_t val1 = 0xab12ce4f;
uint32_t val2 = 0xab1;
/* ´x´ is not a valid hexadecimal character */
TEST_ASSERT_EQUAL_INT(0x0, scn_u32_hex("0xABCD", 4));
/* so are these: */
TEST_ASSERT_EQUAL_INT(0x9, scn_u32_hex("9 ABCD", 4));
TEST_ASSERT_EQUAL_INT(0x9, scn_u32_hex("9-ABCD", 4));
TEST_ASSERT_EQUAL_INT(0x9, scn_u32_hex("9+ABCD", 4));
TEST_ASSERT_EQUAL_INT(0xab, scn_u32_hex("AB_CD", 4));
TEST_ASSERT_EQUAL_INT(val1, scn_u32_hex(string1, 8));
TEST_ASSERT_EQUAL_INT(val2, scn_u32_hex(string1, 3));
TEST_ASSERT_EQUAL_INT(val1, scn_u32_hex(string1, 9));
/* Stop on the length argument or on the null terminator */
TEST_ASSERT_EQUAL_INT(0xab12ce4f, scn_u32_hex("aB12cE4F", 8));
TEST_ASSERT_EQUAL_INT(0xab1, scn_u32_hex("aB12cE4F", 3));
TEST_ASSERT_EQUAL_INT(0xab12ce4f, scn_u32_hex("aB12cE4F", 9));
}
static void test_fmt_lpad(void)