2020-12-06 16:37:53 -05:00
|
|
|
#include <kernaux/printf.h>
|
|
|
|
|
2020-12-06 17:04:46 -05:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
|
|
|
|
static char buffer[BUFFER_SIZE];
|
|
|
|
static unsigned int buffer_index;
|
|
|
|
|
|
|
|
static void test_putchar(const char chr)
|
|
|
|
{
|
|
|
|
if (buffer_index >= BUFFER_SIZE) {
|
|
|
|
printf("Buffer overflow!\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[buffer_index++] = chr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test(const char *const expected, const char *const format, ...)
|
|
|
|
{
|
|
|
|
memset(buffer, '\0', sizeof(buffer));
|
|
|
|
buffer_index = 0;
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
|
|
|
kernaux_printf_va(test_putchar, format, va);
|
|
|
|
va_end(va);
|
|
|
|
assert(strcmp(expected, buffer) == 0);
|
|
|
|
}
|
|
|
|
|
2020-12-06 16:37:53 -05:00
|
|
|
int main()
|
|
|
|
{
|
2020-12-06 17:07:12 -05:00
|
|
|
memset(buffer, '\0', sizeof(buffer));
|
|
|
|
buffer_index = 0;
|
|
|
|
kernaux_printf(test_putchar, "Hello, World!");
|
|
|
|
assert(strcmp("Hello, World!", buffer) == 0);
|
|
|
|
|
2020-12-06 17:04:46 -05:00
|
|
|
test("", "");
|
|
|
|
test("Hello, World!", "Hello, World!");
|
|
|
|
|
2020-12-06 16:37:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|