1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

Merge pull request #20458 from Teufelchen1/chore/fmt_test_4

tests: Cover API of scn_u32_hex in the unittest
This commit is contained in:
Teufelchen 2024-03-12 12:11:31 +00:00 committed by GitHub
commit 03c05f7fe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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)