From 59d5e9789e6af792653c7ba7002dab2cfe28c623 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 22 Oct 2022 12:03:10 +0200 Subject: [PATCH] Tests: Add a test for atoi() --- tests/libc/Makefile | 2 +- tests/libc/Test.c | 5 +++++ tests/libc/stdlib.c | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/libc/stdlib.c diff --git a/tests/libc/Makefile b/tests/libc/Makefile index dc0dd772..1ba9da60 100644 --- a/tests/libc/Makefile +++ b/tests/libc/Makefile @@ -4,7 +4,7 @@ DESTDIR := $(LUNA_ROOT)/initrd/bin build: @mkdir -p $(TESTDIR)/bin $(LUNA_ROOT)/tools/sync-libc.sh - $(CC) $(TESTDIR)/string.c $(TESTDIR)/Test.c -I$(LUNA_ROOT)/tests -o $(TESTDIR)/bin/test-libc -Wall -Wextra -Wno-stringop-overread -Werror + $(CC) $(TESTDIR)/string.c $(TESTDIR)/stdlib.c $(TESTDIR)/Test.c -I$(LUNA_ROOT)/tests -o $(TESTDIR)/bin/test-libc -Wall -Wextra -Wno-stringop-overread -Werror install: $(LUNA_ROOT)/tools/clean.sh diff --git a/tests/libc/Test.c b/tests/libc/Test.c index e62efc9c..92bf3ba9 100644 --- a/tests/libc/Test.c +++ b/tests/libc/Test.c @@ -4,10 +4,15 @@ DEFINE_TEST(strlen); DEFINE_TEST(strnlen); DEFINE_TEST(strcspn); +DEFINE_TEST(atoi); + int main() { START_TEST_CASE(string.h); RUN_TEST(strlen); RUN_TEST(strnlen); RUN_TEST(strcspn); + + START_TEST_CASE(stdlib.h); + RUN_TEST(atoi); } \ No newline at end of file diff --git a/tests/libc/stdlib.c b/tests/libc/stdlib.c new file mode 100644 index 00000000..e2ea4e52 --- /dev/null +++ b/tests/libc/stdlib.c @@ -0,0 +1,24 @@ +#include "Test.h" +#include + +DEFINE_TEST(atoi) +{ + START_TEST(atoi); + + const char* str = "42"; + int num = atoi(str); + + EXPECT_EQ(num, 42); + + str = "-56"; + num = atoi(str); + + EXPECT_EQ(num, -56); + + str = "Not a number"; + num = atoi(str); + + EXPECT_EQ(num, 0); + + TEST_SUCCESS(); +} \ No newline at end of file