mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:52:44 +01:00
tests: Add NULL pointer argument test for fmt_lpad/to_lower/str
This commit is contained in:
parent
4d9e8a8dde
commit
dbcfa1bdc8
@ -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)
|
* @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[out] out Pointer to output buffer, or NULL
|
||||||
* @param[in] str Pointer to null-terminated source string
|
* @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);
|
size_t fmt_to_lower(char *out, const char *str);
|
||||||
|
|
||||||
|
@ -814,6 +814,7 @@ static void test_fmt_str(void)
|
|||||||
const char *string1 = "string1";
|
const char *string1 = "string1";
|
||||||
char string2[] = "StRiNg2";
|
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_INT(fmt_strlen(string1), fmt_str(&string2[0], string1));
|
||||||
TEST_ASSERT_EQUAL_STRING(string1, &string2[0]);
|
TEST_ASSERT_EQUAL_STRING(string1, &string2[0]);
|
||||||
}
|
}
|
||||||
@ -833,6 +834,7 @@ static void test_fmt_to_lower(void)
|
|||||||
const char string_up[] = "AbCdeFGHijkLM";
|
const char string_up[] = "AbCdeFGHijkLM";
|
||||||
char string[] = "zzzzzzzzzzzzzzz";
|
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));
|
TEST_ASSERT_EQUAL_INT(fmt_strlen(string_up), fmt_to_lower(string, string_up));
|
||||||
string[fmt_strlen(string_up)] = '\0';
|
string[fmt_strlen(string_up)] = '\0';
|
||||||
TEST_ASSERT_EQUAL_STRING("abcdefghijklm", &string[0]);
|
TEST_ASSERT_EQUAL_STRING("abcdefghijklm", &string[0]);
|
||||||
@ -866,6 +868,8 @@ static void test_fmt_lpad(void)
|
|||||||
|
|
||||||
strcpy(string, base);
|
strcpy(string, base);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(8, fmt_lpad(NULL, 4, 8, ' '));
|
||||||
|
|
||||||
fmt_lpad(string, 4, 8, ' ');
|
fmt_lpad(string, 4, 8, ' ');
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_STRING(" abcd", (char*)string);
|
TEST_ASSERT_EQUAL_STRING(" abcd", (char*)string);
|
||||||
|
Loading…
Reference in New Issue
Block a user