Tests: Add a test for atoi()
This commit is contained in:
parent
1f5f6a5e3b
commit
59d5e9789e
@ -4,7 +4,7 @@ DESTDIR := $(LUNA_ROOT)/initrd/bin
|
|||||||
build:
|
build:
|
||||||
@mkdir -p $(TESTDIR)/bin
|
@mkdir -p $(TESTDIR)/bin
|
||||||
$(LUNA_ROOT)/tools/sync-libc.sh
|
$(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:
|
install:
|
||||||
$(LUNA_ROOT)/tools/clean.sh
|
$(LUNA_ROOT)/tools/clean.sh
|
||||||
|
@ -4,10 +4,15 @@ DEFINE_TEST(strlen);
|
|||||||
DEFINE_TEST(strnlen);
|
DEFINE_TEST(strnlen);
|
||||||
DEFINE_TEST(strcspn);
|
DEFINE_TEST(strcspn);
|
||||||
|
|
||||||
|
DEFINE_TEST(atoi);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
START_TEST_CASE(string.h);
|
START_TEST_CASE(string.h);
|
||||||
RUN_TEST(strlen);
|
RUN_TEST(strlen);
|
||||||
RUN_TEST(strnlen);
|
RUN_TEST(strnlen);
|
||||||
RUN_TEST(strcspn);
|
RUN_TEST(strcspn);
|
||||||
|
|
||||||
|
START_TEST_CASE(stdlib.h);
|
||||||
|
RUN_TEST(atoi);
|
||||||
}
|
}
|
24
tests/libc/stdlib.c
Normal file
24
tests/libc/stdlib.c
Normal 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user