From 4917b59005578b8613822c5ec39de3d65ae9028f Mon Sep 17 00:00:00 2001 From: Teufelchen1 Date: Tue, 12 Mar 2024 11:46:07 +0100 Subject: [PATCH] tests: Cover API of scn_u32_hex in the unittest --- tests/unittests/tests-fmt/tests-fmt.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/unittests/tests-fmt/tests-fmt.c b/tests/unittests/tests-fmt/tests-fmt.c index 108989776207..f90a7e142600 100644 --- a/tests/unittests/tests-fmt/tests-fmt.c +++ b/tests/unittests/tests-fmt/tests-fmt.c @@ -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; - - 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)); + /* ´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)); + + /* 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)