mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests: unittests: add unittest for fmt_lpad()
This commit is contained in:
parent
003b71b323
commit
a3774adfaf
@ -13,6 +13,7 @@
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
@ -275,6 +276,38 @@ static void test_scn_u32_dec(void)
|
||||
TEST_ASSERT_EQUAL_INT(val2, scn_u32_dec(string1, 5));
|
||||
}
|
||||
|
||||
static void test_fmt_lpad(void)
|
||||
{
|
||||
const char base[] = "abcd";
|
||||
char string[9] = {0};
|
||||
|
||||
strcpy(string, base);
|
||||
|
||||
fmt_lpad(string, 4, 8, ' ');
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(" abcd", (char*)string);
|
||||
|
||||
fmt_lpad(string, 0, 0, '1');
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(" abcd", (char*)string);
|
||||
|
||||
fmt_lpad(string, 4, 0, '2');
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(" abcd", (char*)string);
|
||||
|
||||
fmt_lpad(string, 0, 4, '3');
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("3333abcd", (char*)string);
|
||||
|
||||
fmt_lpad(string, 8, 8, '4');
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("3333abcd", (char*)string);
|
||||
|
||||
fmt_lpad(string, 4, 8, 'x');
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING((char*)string, "xxxx3333");
|
||||
}
|
||||
|
||||
Test *tests_fmt_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
@ -293,6 +326,7 @@ Test *tests_fmt_tests(void)
|
||||
new_TestFixture(test_fmt_strlen),
|
||||
new_TestFixture(test_fmt_str),
|
||||
new_TestFixture(test_scn_u32_dec),
|
||||
new_TestFixture(test_fmt_lpad),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(fmt_tests, NULL, NULL, fixtures);
|
||||
|
Loading…
Reference in New Issue
Block a user