From a50f1a8369c909a835a21d54d3facfb4a628205f Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Tue, 5 Jun 2018 11:25:47 +0200 Subject: test(test_suite): modified fctprintf() test case Renamed 'user' to 'arg' --- README.md | 4 ++-- printf.c | 10 +++++----- printf.h | 2 +- test/test_suite.cpp | 9 ++++++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8420a5b..1cad181 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ int sprintf(char* buffer, const char* format, ...); int snprintf(char* buffer, size_t count, const char* format, ...); int vsnprintf(char* buffer, size_t count, const char* format, va_list va); -// call output function (instead of buffer) -int fctprintf(void (*out)(char character, void* user), void* user, const char* format, ...); +// use output function (instead of buffer) for streamlike interface +int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); ``` diff --git a/printf.c b/printf.c index dec4555..01021a0 100644 --- a/printf.c +++ b/printf.c @@ -77,10 +77,10 @@ typedef void (*out_fct_type)(char character, char* buffer, size_t idx, size_t maxlen); -// wrapper used as buffer +// wrapper (used as buffer) for output function type typedef struct { - void (*fct)(char character, void* user); - void* user; + void (*fct)(char character, void* arg); + void* arg; } out_fct_wrap_type; @@ -696,11 +696,11 @@ int vsnprintf(char* buffer, size_t count, const char* format, va_list va) } -int fctprintf(void (*out)(char character, void* user), void* user, const char* format, ...) +int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...) { va_list va; va_start(va, format); - const out_fct_wrap_type out_fct_wrap = { out, user }; + const out_fct_wrap_type out_fct_wrap = { out, arg }; const int ret = _vsnprintf(_out_fct, (char*)&out_fct_wrap, (size_t)-1, format, va); va_end(va); return ret; diff --git a/printf.h b/printf.h index 8b8e76e..33592c6 100644 --- a/printf.h +++ b/printf.h @@ -88,7 +88,7 @@ int vsnprintf(char* buffer, size_t count, const char* format, va_list va); * \param format A string that specifies the format of the output * \return The number of characters that are sent to the output function, not counting the terminating null character */ -int fctprintf(void (*out)(char character, void* user), void* user, const char* format, ...); +int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); #ifdef __cplusplus diff --git a/test/test_suite.cpp b/test/test_suite.cpp index 4bc773a..8aaf67a 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -42,11 +42,18 @@ namespace test { // dummy putchar static char printf_buffer[100]; static size_t printf_idx = 0U; + void test::_putchar(char character) { printf_buffer[printf_idx++] = character; } +void _out_fct(char character, void* arg) +{ + (void)arg; + printf_buffer[printf_idx++] = character; +} + TEST_CASE("printf", "[]" ) { @@ -60,7 +67,7 @@ TEST_CASE("printf", "[]" ) { TEST_CASE("fctprintf", "[]" ) { printf_idx = 0U; memset(printf_buffer, 0xCC, 100U); - test::fctprintf(&test::_putchar, "This is a test of %X", 0x12EFU); + test::fctprintf(&_out_fct, nullptr, "This is a test of %X", 0x12EFU); REQUIRE(!strcmp(printf_buffer, "This is a test of 12EF")); } -- cgit v1.2.3