Add atoi tests
This commit is contained in:
1
Makefile
1
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)
|
||||
|
||||
|
||||
18
libunit.c
18
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
1
main.c
1
main.c
@@ -16,4 +16,5 @@ int main(void)
|
||||
{
|
||||
libunit_launcher();
|
||||
strlen_launcher();
|
||||
atoi_launcher();
|
||||
}
|
||||
|
||||
28
real_tests/ft_atoi/00_launcher.c
Normal file
28
real_tests/ft_atoi/00_launcher.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 00_launcher.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
7
real_tests/ft_atoi/01_ok.c
Normal file
7
real_tests/ft_atoi/01_ok.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "../tests.h"
|
||||
#include "libft.h"
|
||||
|
||||
int atoi_ok_test(void)
|
||||
{
|
||||
return (ft_atoi("10") == 10);
|
||||
}
|
||||
6
real_tests/ft_atoi/02_ko.c
Normal file
6
real_tests/ft_atoi/02_ko.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "../tests.h"
|
||||
|
||||
int atoi_ko_test(void)
|
||||
{
|
||||
return (ft_atoi("30") == 10);
|
||||
}
|
||||
7
real_tests/ft_atoi/03_sigsegv.c
Normal file
7
real_tests/ft_atoi/03_sigsegv.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "../tests.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int atoi_sigsegv_test(void)
|
||||
{
|
||||
return (ft_atoi(NULL));
|
||||
}
|
||||
6
real_tests/ft_atoi/04_sigbus.c
Normal file
6
real_tests/ft_atoi/04_sigbus.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "../tests.h"
|
||||
|
||||
int atoi_sigbus_test(void)
|
||||
{
|
||||
return (ft_atoi((void *) -2147483648));
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user