Skip to content

Commit

Permalink
Merge pull request #20458 from Teufelchen1/chore/fmt_test_4
Browse files Browse the repository at this point in the history
tests: Cover API of scn_u32_hex in the unittest
  • Loading branch information
Teufelchen1 authored Mar 12, 2024
2 parents ed89e34 + 4917b59 commit 03c05f7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/unittests/tests-fmt/tests-fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 03c05f7

Please sign in to comment.