#ifdef HAVE_CONFIG_H #include "config.h" #endif #include #ifdef WITH_IO #include #endif #include #include #include #include #define BUFFER_SIZE 1024 static char buffer[BUFFER_SIZE]; static size_t buffer_index; #ifdef WITH_IO static const char *const data = "foobar"; static void test_putchar(const char chr, void *const arg) { assert(arg == data); if (buffer_index >= BUFFER_SIZE) { printf("Buffer overflow!\n"); abort(); } buffer[buffer_index++] = chr; } #endif // WITH_IO static void test(const char *const expected, const char *const format, ...) { va_list va; int result; #ifdef WITH_IO memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; va_start(va, format); struct KernAux_OldFile file = KernAux_OldFile_create(test_putchar); result = kernaux_vfprintf(&file, (char*)data, format, va); va_end(va); assert((size_t)result == strlen(expected)); assert(strcmp(expected, buffer) == 0); #endif memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; va_start(va, format); result = kernaux_vsnprintf(buffer, sizeof(buffer), format, va); va_end(va); assert((size_t)result == strlen(expected)); assert(strcmp(expected, buffer) == 0); } void test_main() { #ifdef WITH_IO memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; struct KernAux_OldFile file = KernAux_OldFile_create(test_putchar); kernaux_fprintf(&file, (char*)data, "Hello, World!"); assert(strcmp("Hello, World!", buffer) == 0); #endif {% for case in cases %} {% if case.float %} #ifdef ENABLE_FLOAT {% endif %} printf("%s\n", {{ escape_str(case.result) }}); test({{ escape_str(case.result) }}, {{ escape_str(fmt(case.args)) }}{{ values(case.args) }}); {% if case.float %} #endif {% endif %} {% endfor %} }