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

Merge pull request #20344 from Teufelchen1/chore/fmt_test_3

tests: Add NULL pointer argument test for fmt_lpad/to_lower/str
This commit is contained in:
mguetschow 2024-02-09 10:41:17 +00:00 committed by GitHub
commit de1efc6772
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -393,8 +393,13 @@ size_t fmt_str(char *out, const char *str);
/**
* @brief Copy null-terminated string to a lowercase string (excluding terminating \0)
*
* If @p out is NULL, will only return the number of characters that would have
* been written.
*
* @param[out] out Pointer to output buffer, or NULL
* @param[in] str Pointer to null-terminated source string
*
* @return nr of characters written to (or needed in) @p out
*/
size_t fmt_to_lower(char *out, const char *str);

View File

@ -814,6 +814,7 @@ static void test_fmt_str(void)
const char *string1 = "string1";
char string2[] = "StRiNg2";
TEST_ASSERT_EQUAL_INT(7, fmt_str(NULL, string1));
TEST_ASSERT_EQUAL_INT(fmt_strlen(string1), fmt_str(&string2[0], string1));
TEST_ASSERT_EQUAL_STRING(string1, &string2[0]);
}
@ -833,6 +834,7 @@ static void test_fmt_to_lower(void)
const char string_up[] = "AbCdeFGHijkLM";
char string[] = "zzzzzzzzzzzzzzz";
TEST_ASSERT_EQUAL_INT(fmt_strlen(string_up), fmt_to_lower(NULL, string_up));
TEST_ASSERT_EQUAL_INT(fmt_strlen(string_up), fmt_to_lower(string, string_up));
string[fmt_strlen(string_up)] = '\0';
TEST_ASSERT_EQUAL_STRING("abcdefghijklm", &string[0]);
@ -866,6 +868,8 @@ static void test_fmt_lpad(void)
strcpy(string, base);
TEST_ASSERT_EQUAL_INT(8, fmt_lpad(NULL, 4, 8, ' '));
fmt_lpad(string, 4, 8, ' ');
TEST_ASSERT_EQUAL_STRING(" abcd", (char*)string);