diff options
author | Marco Paland <marco@paland.com> | 2018-05-13 02:05:40 +0200 |
---|---|---|
committer | Marco Paland <marco@paland.com> | 2018-05-13 02:05:40 +0200 |
commit | d12e52be4c207bb3b8a35f512b2cddf8deb3ceaf (patch) | |
tree | 0592f0bb0ad263e22eb4672fb097772ad6d80e5b /test | |
parent | a6e81f9c598e722571b9ae115fda6ef770a57e66 (diff) | |
download | printf-d12e52be4c207bb3b8a35f512b2cddf8deb3ceaf.tar.gz printf-d12e52be4c207bb3b8a35f512b2cddf8deb3ceaf.tar.bz2 printf-d12e52be4c207bb3b8a35f512b2cddf8deb3ceaf.zip |
fix(printf): pass dummy buffer for printf to _vsnprintf instead of NULL
Fixes #15
Diffstat (limited to 'test')
-rw-r--r-- | test/test_suite.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/test/test_suite.cpp b/test/test_suite.cpp index a5c087c..9a02b1e 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -40,23 +40,38 @@ namespace test { // dummy putchar
-void test::_putchar(char)
-{ }
+static char printf_buffer[100];
+static size_t printf_idx = 0U;
+void test::_putchar(char character)
+{
+ printf_buffer[printf_idx++] = character;
+}
TEST_CASE("printf", "[]" ) {
- char buffer[100] ;
+ char buffer[100];
+ printf_idx = 0U;
+ memset(printf_buffer, 0xCC, 100U);
REQUIRE(test::printf("% d", 4232) == 5);
+ REQUIRE(!strcmp(printf_buffer, " 4232"));
+}
+
+
+TEST_CASE("snprintf", "[]" ) {
+ char buffer[100];
test::snprintf(buffer, 100U, "%d", -1000);
REQUIRE(!strcmp(buffer, "-1000"));
+
+ test::snprintf(buffer, 3U, "%d", -1000);
+ REQUIRE(!strcmp(buffer, "-1"));
}
TEST_CASE("space flag", "[]" ) {
- char buffer[100] ;
+ char buffer[100];
test::sprintf(buffer, "% d", 42);
REQUIRE(!strcmp(buffer, " 42"));
@@ -130,7 +145,7 @@ TEST_CASE("space flag", "[]" ) { TEST_CASE("+ flag", "[]" ) {
- char buffer[100] ;
+ char buffer[100];
test::sprintf(buffer, "%+d", 42);
REQUIRE(!strcmp(buffer, "+42"));
@@ -195,7 +210,7 @@ TEST_CASE("+ flag", "[]" ) { TEST_CASE("0 flag", "[]" ) {
- char buffer[100] ;
+ char buffer[100];
test::sprintf(buffer, "%0d", 42);
REQUIRE(!strcmp(buffer, "42"));
|