Tests: Add a test for atoi()

This commit is contained in:
apio 2022-10-22 12:03:10 +02:00
parent 1f5f6a5e3b
commit 59d5e9789e
3 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -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);
}

24
tests/libc/stdlib.c Normal file
View File

@ -0,0 +1,24 @@
#include "Test.h"
#include <stdlib.h>
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();
}