From 7deaa5e3a148c143b1f9dd0f485b0200890ba87f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 10 Jun 2017 21:29:21 +0200 Subject: also moved tests into tests/libc --- tests/Makefile | 31 ------------------------------- tests/libc/Makefile | 31 +++++++++++++++++++++++++++++++ tests/libc/test_itoa.c | 34 ++++++++++++++++++++++++++++++++++ tests/libc/test_strlcpy.c | 15 +++++++++++++++ tests/test_itoa.c | 34 ---------------------------------- tests/test_strlcpy.c | 15 --------------- 6 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 tests/Makefile create mode 100644 tests/libc/Makefile create mode 100644 tests/libc/test_itoa.c create mode 100644 tests/libc/test_strlcpy.c delete mode 100644 tests/test_itoa.c delete mode 100644 tests/test_strlcpy.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 6b91c9b..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -CC := gcc -CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror -INCLUDES = -I../src -LD := ld - -all: test - -test_strlcpy: test_strlcpy.o ../src/string.o - $(CC) -o test_strlcpy test_strlcpy.o ../src/string.o - -test_strlcpy.o: test_strlcpy.c - $(CC) $(CFLAGS) $(INCLUDES) -c -o test_strlcpy.o test_strlcpy.c - -test_itoa: test_itoa.o ../src/stdlib.o ../src/string.o - $(CC) -o test_itoa test_itoa.o ../src/stdlib.o ../src/string.o - -test_itoa.o: test_itoa.c ../src/stdlib.o - $(CC) $(CFLAGS) $(INCLUDES) -c -o test_itoa.o test_itoa.c - -../src/string.o: ../src/string.c - $(CC) $(CFLAGS) -c -o ../src/string.o ../src/string.c - -../src/stdlib.o: ../src/stdlib.c - $(CC) $(CFLAGS) -c -o ../src/stdlib.o ../src/stdlib.c - -test: test_strlcpy test_itoa - ./test_strlcpy - ./test_itoa - -clean: - -rm -f test_strlcpy test_itoa *.o diff --git a/tests/libc/Makefile b/tests/libc/Makefile new file mode 100644 index 0000000..6b91c9b --- /dev/null +++ b/tests/libc/Makefile @@ -0,0 +1,31 @@ +CC := gcc +CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror +INCLUDES = -I../src +LD := ld + +all: test + +test_strlcpy: test_strlcpy.o ../src/string.o + $(CC) -o test_strlcpy test_strlcpy.o ../src/string.o + +test_strlcpy.o: test_strlcpy.c + $(CC) $(CFLAGS) $(INCLUDES) -c -o test_strlcpy.o test_strlcpy.c + +test_itoa: test_itoa.o ../src/stdlib.o ../src/string.o + $(CC) -o test_itoa test_itoa.o ../src/stdlib.o ../src/string.o + +test_itoa.o: test_itoa.c ../src/stdlib.o + $(CC) $(CFLAGS) $(INCLUDES) -c -o test_itoa.o test_itoa.c + +../src/string.o: ../src/string.c + $(CC) $(CFLAGS) -c -o ../src/string.o ../src/string.c + +../src/stdlib.o: ../src/stdlib.c + $(CC) $(CFLAGS) -c -o ../src/stdlib.o ../src/stdlib.c + +test: test_strlcpy test_itoa + ./test_strlcpy + ./test_itoa + +clean: + -rm -f test_strlcpy test_itoa *.o diff --git a/tests/libc/test_itoa.c b/tests/libc/test_itoa.c new file mode 100644 index 0000000..837b77a --- /dev/null +++ b/tests/libc/test_itoa.c @@ -0,0 +1,34 @@ +#include "stdlib.h" +#include "string.h" +#include "limits.h" + +int main( void ) +{ + char *res; + char buf[12]; + + // simple conversion without sign + res = itoa( 568876, buf, 10 ); + if( strcmp( buf, "568876" ) ) return 1; + + // test if the returned pointer points to the buffer + if( strcmp( res, buf ) ) return 1; + + // conversion with sign + res = itoa( -568876, buf, 10 ); + if( strcmp( buf, "-568876" ) ) return 1; + + // convert upper limit + res = itoa( INT_MAX, buf, 10 ); + if( strcmp( buf, "2147483647" ) ) return 1; + + // convert lower limit + res = itoa( INT_MIN+1, buf, 10 ); + if( strcmp( buf, "-2147483647" ) ) return 1; + + // convert to hex + res = itoa( 568876, buf, 16 ); + if( strcmp( buf, "8AE2C" ) ) return 1; + + return 0; +} diff --git a/tests/libc/test_strlcpy.c b/tests/libc/test_strlcpy.c new file mode 100644 index 0000000..a23a5bc --- /dev/null +++ b/tests/libc/test_strlcpy.c @@ -0,0 +1,15 @@ +#include "string.h" + +int main( void ) +{ + char *s = "test_string"; + char d[8]; + size_t n; + + // copy into too small string + n = strlcpy( d, s, 4 ); + if( n != 11 ) return 1; + if( strcmp( d, "tes" ) ) return 1; + + return 0; +} diff --git a/tests/test_itoa.c b/tests/test_itoa.c deleted file mode 100644 index 837b77a..0000000 --- a/tests/test_itoa.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "stdlib.h" -#include "string.h" -#include "limits.h" - -int main( void ) -{ - char *res; - char buf[12]; - - // simple conversion without sign - res = itoa( 568876, buf, 10 ); - if( strcmp( buf, "568876" ) ) return 1; - - // test if the returned pointer points to the buffer - if( strcmp( res, buf ) ) return 1; - - // conversion with sign - res = itoa( -568876, buf, 10 ); - if( strcmp( buf, "-568876" ) ) return 1; - - // convert upper limit - res = itoa( INT_MAX, buf, 10 ); - if( strcmp( buf, "2147483647" ) ) return 1; - - // convert lower limit - res = itoa( INT_MIN+1, buf, 10 ); - if( strcmp( buf, "-2147483647" ) ) return 1; - - // convert to hex - res = itoa( 568876, buf, 16 ); - if( strcmp( buf, "8AE2C" ) ) return 1; - - return 0; -} diff --git a/tests/test_strlcpy.c b/tests/test_strlcpy.c deleted file mode 100644 index a23a5bc..0000000 --- a/tests/test_strlcpy.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "string.h" - -int main( void ) -{ - char *s = "test_string"; - char d[8]; - size_t n; - - // copy into too small string - n = strlcpy( d, s, 4 ); - if( n != 11 ) return 1; - if( strcmp( d, "tes" ) ) return 1; - - return 0; -} -- cgit v1.2.3-54-g00ecf