From ec9ed8deb79a9fd508a11b122453bb39d3b587a9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 23 Jul 2017 15:28:13 +0200 Subject: added snprintf and a test for it --- tests/libc/Makefile | 11 +++++++++-- tests/libc/test_sprintf.c | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/libc/test_sprintf.c (limited to 'tests') diff --git a/tests/libc/Makefile b/tests/libc/Makefile index 37c383a..c21263d 100644 --- a/tests/libc/Makefile +++ b/tests/libc/Makefile @@ -37,9 +37,15 @@ test_malloc.o: test_malloc.c ../../src/libc/stdlib.h test_printf: test_printf.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o $(LD) $(LDFLAGS) -o test_printf test_printf.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o +test_sprintf: test_sprintf.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_sprintf test_sprintf.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + test_printf.o: test_printf.c ../../src/libc/stdlib.h $(CC) $(CFLAGS) -c -o test_printf.o test_printf.c +test_sprintf.o: test_sprintf.c ../../src/libc/stdlib.h + $(CC) $(CFLAGS) -c -o test_sprintf.o test_sprintf.c + test_exit: test_exit.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o $(LD) $(LDFLAGS) -o test_exit test_exit.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o @@ -64,15 +70,16 @@ kernel_stub.o: kernel_stub.c kernel_stub_asm.o: kernel_stub.asm $(NASM) kernel_stub.asm $(NASMFLAGS) -o kernel_stub_asm.o -test: test_strlcpy test_strlcat test_itoa test_malloc test_exit test_printf +test: test_strlcpy test_strlcat test_itoa test_malloc test_exit test_printf test_sprintf ./test_strlcpy ./test_strlcat ./test_itoa ./test_malloc ./test_printf + ./test_sprintf ./test_exit clean: - -rm -f test_strlcpy test_strlcat test_itoa test_malloc test_printf test_exit + -rm -f test_strlcpy test_strlcat test_itoa test_malloc test_printf test_sprintf test_exit -rm -f ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o -rm -f *.o diff --git a/tests/libc/test_sprintf.c b/tests/libc/test_sprintf.c new file mode 100644 index 0000000..b1f25c7 --- /dev/null +++ b/tests/libc/test_sprintf.c @@ -0,0 +1,19 @@ +#include "string.h" +#include "stdlib.h" +#include "stdio.h" +#include "string.h" + +int main( void ) +{ + char *s = "test_string"; + int i = 47; + char c = 'X'; + char buf[100]; + const char *must = "string 'test_string', decimal 47, hex 0x2F, character 'X'\n"; + + snprintf( buf, 100, "string '%s', decimal %d, hex 0x%X, character '%c'\n", + s, i, i, c ); + if( strncmp( buf, must, strlen( must ) ) != 0 ) exit( 1 ); + + exit( 0 ); +} -- cgit v1.2.3-54-g00ecf