Skip to content
Snippets Groups Projects
Commit a3774adf authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

tests: unittests: add unittest for fmt_lpad()

parent 003b71b3
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include "embUnit/embUnit.h" #include "embUnit/embUnit.h"
...@@ -275,6 +276,38 @@ static void test_scn_u32_dec(void) ...@@ -275,6 +276,38 @@ static void test_scn_u32_dec(void)
TEST_ASSERT_EQUAL_INT(val2, scn_u32_dec(string1, 5)); 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) Test *tests_fmt_tests(void)
{ {
EMB_UNIT_TESTFIXTURES(fixtures) { EMB_UNIT_TESTFIXTURES(fixtures) {
...@@ -293,6 +326,7 @@ Test *tests_fmt_tests(void) ...@@ -293,6 +326,7 @@ Test *tests_fmt_tests(void)
new_TestFixture(test_fmt_strlen), new_TestFixture(test_fmt_strlen),
new_TestFixture(test_fmt_str), new_TestFixture(test_fmt_str),
new_TestFixture(test_scn_u32_dec), new_TestFixture(test_scn_u32_dec),
new_TestFixture(test_fmt_lpad),
}; };
EMB_UNIT_TESTCALLER(fmt_tests, NULL, NULL, fixtures); EMB_UNIT_TESTCALLER(fmt_tests, NULL, NULL, fixtures);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment