diff --git a/Makefile b/Makefile index f1e9645..0955987 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ LIBFT_A = $(LIBFT_DIR)/libft.a SRC = libunit_util.c libunit_util2.c libunit.c main.c SRC += real_tests/ft_strlen/00_launcher.c real_tests/ft_strlen/01_basic.c real_tests/ft_strlen/02_null.c +SRC += real_tests/ft_atoi/00_launcher.c real_tests/ft_atoi/01_ok.c real_tests/ft_atoi/02_ko.c real_tests/ft_atoi/03_sigsegv.c real_tests/ft_atoi/04_sigbus.c SRC += tests/libunit/00_launcher.c tests/libunit/01_ok.c tests/libunit/02_ko.c tests/libunit/03_sigsegv.c tests/libunit/04_sigbus.c OBJ = $(SRC:.c=.o) diff --git a/libunit.c b/libunit.c index 9efa341..b0b3a8c 100644 --- a/libunit.c +++ b/libunit.c @@ -22,7 +22,14 @@ static size_t interpret_status(int status, const char *fn_name ft_putstr_fd(" : ", 1); ft_putstr_fd(test_name, 1); ft_putstr_fd(" : ", 1); - if (WIFEXITED(status)) + if (WIFSIGNALED(status)) + { + if (WTERMSIG(status) == 11) + ft_putstr_fd("[SIGSEGV]\n", 1); + else if (WTERMSIG(status) == 10) + ft_putstr_fd("[SIGBUS]\n", 1); + } + else if (WIFEXITED(status)) { if (WEXITSTATUS(status)) ft_putstr_fd("[KO]\n", 1); @@ -32,13 +39,6 @@ static size_t interpret_status(int status, const char *fn_name return (1); } } - else if (WIFSIGNALED(status)) - { - if (WTERMSIG(status) == 11) - ft_putstr_fd("[SIGSEGV]\n", 1); - else if (WTERMSIG(status) == 10) - ft_putstr_fd("[SIGBUS]\n", 1); - } return (0); } @@ -47,7 +47,7 @@ static void print_passed_test(size_t ok_tests, t_unit_test *test_list) ft_putnbr_fd(ok_tests, 1); ft_putchar_fd('/', 1); ft_putnbr_fd((int)count_tests(test_list), 1); - ft_putstr_fd(" tests checked", 1); + ft_putstr_fd(" tests checked\n", 1); } int launch_tests(t_unit_test *test_list, const char *fn_name) diff --git a/libunit.h b/libunit.h index 17e7d3e..166ad06 100644 --- a/libunit.h +++ b/libunit.h @@ -67,7 +67,8 @@ int launch_tests(t_unit_test *test_list, const char *fn_name); // LAUNCHERS -int strlen_launcher(void); -int libunit_launcher(void); +int strlen_launcher(void); +int libunit_launcher(void); +int atoi_launcher(void); #endif // !UTIL_UNIT_H diff --git a/main.c b/main.c index 21ca363..9cdf324 100644 --- a/main.c +++ b/main.c @@ -16,4 +16,5 @@ int main(void) { libunit_launcher(); strlen_launcher(); + atoi_launcher(); } diff --git a/real_tests/ft_atoi/00_launcher.c b/real_tests/ft_atoi/00_launcher.c new file mode 100644 index 0000000..53b2fa5 --- /dev/null +++ b/real_tests/ft_atoi/00_launcher.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 00_launcher.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dgaillet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 16:22:35 by dgaillet #+# #+# */ +/* Updated: 2026/01/24 16:22:36 by dgaillet ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include "../tests.h" + +int atoi_launcher(void) +{ + t_unit_test *testlist; + size_t res; + + testlist = NULL; + load_test(&testlist, "OK test", &atoi_ok_test); + load_test(&testlist, "KO test", &atoi_ko_test); + load_test(&testlist, "SIGSEGV test", &atoi_sigsegv_test); + load_test(&testlist, "SIGBUS test", &atoi_sigbus_test); + res = launch_tests(testlist, "atoi"); + clear_tests(&testlist); + return (res); +} diff --git a/real_tests/ft_atoi/01_ok.c b/real_tests/ft_atoi/01_ok.c new file mode 100644 index 0000000..f9d909c --- /dev/null +++ b/real_tests/ft_atoi/01_ok.c @@ -0,0 +1,7 @@ +#include "../tests.h" +#include "libft.h" + +int atoi_ok_test(void) +{ + return (ft_atoi("10") == 10); +} diff --git a/real_tests/ft_atoi/02_ko.c b/real_tests/ft_atoi/02_ko.c new file mode 100644 index 0000000..b8dd86e --- /dev/null +++ b/real_tests/ft_atoi/02_ko.c @@ -0,0 +1,6 @@ +#include "../tests.h" + +int atoi_ko_test(void) +{ + return (ft_atoi("30") == 10); +} diff --git a/real_tests/ft_atoi/03_sigsegv.c b/real_tests/ft_atoi/03_sigsegv.c new file mode 100644 index 0000000..e561d2f --- /dev/null +++ b/real_tests/ft_atoi/03_sigsegv.c @@ -0,0 +1,7 @@ +#include "../tests.h" +#include + +int atoi_sigsegv_test(void) +{ + return (ft_atoi(NULL)); +} diff --git a/real_tests/ft_atoi/04_sigbus.c b/real_tests/ft_atoi/04_sigbus.c new file mode 100644 index 0000000..4af0489 --- /dev/null +++ b/real_tests/ft_atoi/04_sigbus.c @@ -0,0 +1,6 @@ +#include "../tests.h" + +int atoi_sigbus_test(void) +{ + return (ft_atoi((void *) -2147483648)); +} diff --git a/real_tests/tests.h b/real_tests/tests.h index 33785ba..92f8d6d 100644 --- a/real_tests/tests.h +++ b/real_tests/tests.h @@ -19,4 +19,11 @@ int test_basic(void); int test_null(void); +// atoi +int atoi_ok_test(void); +int atoi_ko_test(void); +int atoi_sigsegv_test(void); +int atoi_sigbus_test(void); + + #endif // !TESTS_H