Skip to content

Commit

Permalink
tests: Add NULL pointer argument test for fmt_lpad/to_lower/str
Browse files Browse the repository at this point in the history
  • Loading branch information
Teufelchen1 committed Feb 6, 2024
1 parent 4d9e8a8 commit a820941
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sys/include/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ size_t fmt_str(char *out, const char *str);
*
* @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);

Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/tests-fmt/tests-fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a820941

Please sign in to comment.