.
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | SRC_DIR = ./srcs/
2 | INC_DIR = ./includes/
3 |
4 | SRC = main.c \
5 | global/globals.c \
6 | ft_call_test.c \
7 | utils/ft_utils.c \
8 | utils/ft_print_test.c \
9 | tests/ft_test_ascii.c \
10 | tests/ft_test_strlen.c \
11 | tests/ft_test_memset.c \
12 | tests/ft_test_bzero.c \
13 | tests/ft_test_memcpy.c \
14 | tests/ft_test_memmove.c \
15 | tests/ft_test_strlcpy.c \
16 | tests/ft_test_strlcat.c \
17 | tests/ft_test_strchr.c \
18 | tests/ft_test_strrchr.c \
19 | tests/ft_test_strncmp.c \
20 | tests/ft_test_memchr.c \
21 | tests/ft_test_memcmp.c \
22 | tests/ft_test_strnstr.c \
23 | tests/ft_test_atoi.c \
24 | tests/ft_test_calloc.c \
25 | tests/ft_test_strdup.c \
26 | tests/ft_test_substr.c \
27 | tests/ft_test_strjoin.c \
28 | tests/ft_test_strtrim.c \
29 | tests/ft_test_split.c \
30 | tests/ft_test_itoa.c \
31 | tests/ft_test_strmapi.c \
32 | tests/ft_test_striteri.c \
33 | tests/ft_test_putchar_fd.c \
34 | tests/ft_test_putstr_fd.c \
35 | tests/ft_test_putendl_fd.c \
36 | tests/ft_test_putnbr_fd.c \
37 |
38 | SRC_BONUS = tests/ft_test_lstnew.c \
39 | tests/ft_test_lstadd_front.c \
40 | tests/ft_test_lstsize.c \
41 | tests/ft_test_lstlast.c \
42 | tests/ft_test_lstadd_back.c \
43 | tests/ft_test_lstdelone.c \
44 | tests/ft_test_lstclear.c \
45 | tests/ft_test_lstiter.c \
46 | tests/ft_test_lstmap.c
47 |
48 | SRCS = $(addprefix $(SRC_DIR), $(SRC))
49 | SRCS_BONUS = ${addprefix ${SRC_DIR}, ${SRC_BONUS}}
50 |
51 | OBJS = $(SRCS:.c=.o)
52 | OBJS_BONUS = ${SRCS_BONUS:.c=.o}
53 |
54 | CC = cc
55 | CFLAGS = -g -Wall -Wextra -Werror -fsanitize=address -fsanitize=undefined
56 | LFLAGS = -lbsd
57 | RM = rm -f
58 |
59 | NAME = libtest
60 |
61 | G = \e[92m
62 | X = \e[0m
63 | BAR_SIZE = 50
64 |
65 | TOTAL_FILES := $(words $(SRC))
66 | COMPILED_FILES := 0
67 |
68 | CHECK_SCRIPT = ./scripts/check_files.sh
69 | CHECK_BONUS = ./scripts/check_files.sh bonus
70 |
71 |
72 | all: $(NAME)
73 |
74 | .c.o:
75 | @$(CC) $(CFLAGS) -c -I $(INC_DIR) $< -o $(<:.c=.o)
76 | @$(eval COMPILED_FILES := $(shell echo $$(($(COMPILED_FILES)+1))))
77 | @echo -n "["
78 | @for i in `seq 1 $(shell echo "$$(($(COMPILED_FILES)*$(BAR_SIZE)/$(TOTAL_FILES)))")`; do \
79 | echo -n "$(G)▰$(X)" ; \
80 | done
81 | @for i in `seq 1 $(shell echo "$$(($(BAR_SIZE)-$(COMPILED_FILES)*$(BAR_SIZE)/$(TOTAL_FILES)))")`; do \
82 | echo -n "▱" ; \
83 | done
84 | @echo -n "] ($(shell echo "scale=2; $(COMPILED_FILES)/$(TOTAL_FILES) * 100" | bc)%) "
85 | @echo -n "["
86 | @printf "%d/%d" $(COMPILED_FILES) $(TOTAL_FILES)
87 | @echo -n "] "
88 | @printf "%s" $(notdir $<)
89 | @printf "\e[0K\r"
90 |
91 | $(NAME): mandatory
92 | @clear
93 | @echo "Compilation completed."
94 |
95 | mandatory: title check $(OBJS)
96 | @make -sC ..
97 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LFLAGS) ../libft.a
98 | @clear
99 | @echo "Mandatories successfully compiled."
100 |
101 | bonus: title check_bonus $(OBJS) $(OBJS_BONUS)
102 | @make bonus -sC ..
103 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(OBJS_BONUS) $(LFLAGS) ../libft.a
104 | @clear
105 | @echo "Mandatories & Bonus successfully compiled."
106 |
107 | ncmandatory: title $(OBJS)
108 | @make -sC ..
109 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LFLAGS) ../libft.a
110 | @clear
111 | @echo "Mandatories successfully compiled without check."
112 |
113 | ncbonus: title $(OBJS) $(OBJS_BONUS)
114 | @make bonus -sC ..
115 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(OBJS_BONUS) $(LFLAGS) ../libft.a
116 | @clear
117 | @echo "Mandatories & Bonus successfully compiled without check."
118 |
119 | clean:
120 | @make clean -sC ..
121 | @$(RM) $(OBJS) $(OBJS_BONUS)
122 | @clear
123 | @echo "Clean completed."
124 |
125 | fclean: clean
126 | @printf "\e[1A\e[0K\r"
127 | @make fclean -sC ..
128 | @$(RM) $(NAME)
129 | @clear
130 | @echo "Full clean completed."
131 |
132 | re: fclean all
133 | @clear
134 | @echo "Recompilation completed."
135 |
136 | title:
137 | @scripts/title.sh
138 | @printf "\n"
139 |
140 | check:
141 | @if ! $(CHECK_SCRIPT); then \
142 | exit 1; \
143 | fi
144 |
145 | check_bonus:
146 | @if ! $(CHECK_BONUS); then \
147 | exit 1; \
148 | fi
149 |
150 | .PHONY: all mandatory bonus ncmandatory ncbonus clean fclean re title check check_bonus
151 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | libtest is a command-line utility designed to test the functions provided in the libft library.
13 | It includes options to test mandatory and bonus functions, display available functions, and provide version information.
14 |
15 | ## Features
16 | - Check if the Makefile and libft.h exists
17 | - Check Makefile targets
18 | - Check compilation flags
19 | - Check norme errors
20 | - Check forbidden functions
21 | - Check memory leaks
22 |
23 | ## Installation
24 | - Ensure you have a Makefile in your libft containing the targets `all`, `re`, `bonus`, `clean`, and `fclean`.
25 | - Clone the repository into your libft folder using the following command:
26 | ```bash
27 | git clone git@github.com:FonWasH/libtest.git
28 | ```
29 | Make sure your environment is properly configured before proceeding with the installation steps.
30 |
31 | ## Dependencies
32 | - Norminette https://github.com/42School/norminette
33 | - bc > `sudo apt install bc`
34 | - libbsd > `sudo apt install libbsd-dev`
35 |
36 | ## Make
37 | ```bash
38 | make all # Compile mandatory functions with checks
39 | make libtest # Compile mandatory functions with checks
40 | make mandatory # Compile mandatory functions with checks
41 | make bonus # Compile bonus and mandatory functions with checks
42 | make ncmandatory # Compile mandatory functions without check
43 | make ncbonus # Compile bonus and mandatory functions without check
44 | make check # Run checks on the mandatory functions
45 | make check_bonus # Run checks on the bonus functions
46 | make clean # Remove object files
47 | make fclean # Remove all files
48 | make re # Clean and Re-compile all the files
49 | ```
50 |
51 | ## Usage
52 | ```bash
53 | libtest [OPTION/FUNCTION]...
54 |
55 | -a, --all # test all functions
56 | -f, --force # test all functions without norme and forbidden functions check
57 | -m, --mandatory # test mandatory functions
58 | -b, --bonus # test bonus functions
59 | -s, --show # display all available functions
60 | -h, --help # display help and exit
61 | -v, --version # output version information and exit
62 | ```
63 |
64 | ## Examples
65 | - `./libtest ft_atoi` Test the ft_atoi function.
66 | - `./libtest -m` Test all mandatory functions.
67 |
68 |
69 |
--------------------------------------------------------------------------------
/docs/help:
--------------------------------------------------------------------------------
1 | Usage: libtest [OPTION/FUNCTION]...
2 | libtest is a command-line utility designed to test the functions provided in the libft library.
3 |
4 | -a, --all test all functions
5 | -f, --force test all functions without norme and forbidden functions check
6 | -m, --mandatory test mandatory functions
7 | -b, --bonus test bonus functions
8 | -s, --show display all available functions
9 | -h, --help display this help and exit
10 | -v, --version output version information and exit
11 |
12 | Examples:
13 | libtest ft_atoi Test the ft_atoi.
14 | libtest -m Test all mandatory functions.
15 |
16 | Copyright © 2024 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later .
17 | This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
18 | Written by Julien Perez a.k.a. FonWasH.
19 |
--------------------------------------------------------------------------------
/docs/version:
--------------------------------------------------------------------------------
1 | libtest 1.0.0-2024
2 | Copyright (C) 2024 Free Software Foundation, Inc.
3 | License GPLv3+: GNU GPL version 3 or later .
4 | This is free software: you are free to change and redistribute it.
5 | There is NO WARRANTY, to the extent permitted by law.
6 |
7 | Written by Julien Perez a.k.a. FonWasH.
8 |
--------------------------------------------------------------------------------
/includes/libtest.h:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* libtest.h :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 08:17:48 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 15:45:26 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #ifndef LIBTEST_H
14 | # define LIBTEST_H
15 |
16 | // LIB
17 | # include "../../libft.h"
18 | # include
19 | # include
20 | # include
21 | # include
22 | # include
23 | # include
24 | # include
25 | # include
26 | # include
27 | # include
28 | # include
29 | # include
30 |
31 | // BUFFER
32 | # define BUFFER_SIZE 1024
33 |
34 | // COLOR
35 | # define R "\e[91m"
36 | # define G "\e[92m"
37 | # define B "\e[94m"
38 | # define Y "\e[33m"
39 | # define BD "\e[1m"
40 | # define DM "\e[2m\e[3m"
41 | # define X "\e[0m"
42 |
43 | // STRING
44 | # define KO R "KO\n" X
45 | # define OK G "OK\n" X
46 | # define CHEAT R "CHEAT\n" X
47 | # define ERROR R "ERROR\n" X
48 | # define GRADE_CHEAT R "-42\n" X
49 | # define FAIL R "FAIL" X " :(\n"
50 | # define SUCCESS G "SUCCESS" X " :)\n"
51 | # define NORME BD "Norminette: " X
52 | # define FOR_FUNC BD "Forbidden Functions: " X
53 | # define TEST BD "Test: " X
54 | # define TIME BD "Time: " X
55 | # define GRADE BD "Grade: " X
56 | # define INPUT BD "\tinput:\t" X "=> "
57 | # define OUTPUT BD "\toutput:\t" X "=> "
58 | # define USER "user: "
59 | # define LIBC "libc: "
60 | # define EXPECT "expected: "
61 | # define MEM DM "\t\t Fail when destination is "
62 | # define HIG "higher\n" X
63 | # define LOW "lower\n" X
64 | # define EQU "equal\n" X
65 | # define LST_SIZE DM "\t\t Wrong list size\n" X
66 | # define LST_FREE DM "\t\t Node not freed\n" X
67 | # define ERROR_HELP "\nTry '--help' for more information.\n"
68 | # define ERROR_MEM "Error: Memory allocation\n"
69 | # define LINE "--------------------------------------"
70 | # define SIZE_LINE 40
71 |
72 | // CMD
73 | # define CMD_NS "norminette -o ../"
74 | # define CMD_NE ".c > /dev/null 2>&1"
75 | # define CMD_NV "./scripts/check_norminette_version.sh"
76 | # define CMD_CS "./scripts/check_sysfunc.sh ../"
77 | # define CMD_CE ".o > /dev/null 2>&1"
78 |
79 | // PATH
80 | # define TITLE "./scripts/title.sh"
81 | # define SHOW_FUNC "./scripts/show_func.sh"
82 | # define SHOW_HELP "docs/help"
83 | # define SHOW_VERSION "docs/version"
84 |
85 | // STRUCT
86 | typedef struct s_ftest
87 | {
88 | char *name;
89 | bool (*f)(char *);
90 | } t_ftest;
91 |
92 | typedef struct s_fascii
93 | {
94 | char *name;
95 | int (*user)(int);
96 | int (*libc)(int);
97 | } t_fascii;
98 |
99 | typedef struct s_result
100 | {
101 | int input_int;
102 | size_t input_sizet;
103 | char input_chr;
104 | char *input_str1;
105 | char *input_str2;
106 | int user_int;
107 | int libc_int;
108 | size_t user_sizet;
109 | size_t libc_sizet;
110 | char user_chr;
111 | char libc_chr;
112 | char *user_str;
113 | char *libc_str;
114 | char **user_tabstr;
115 | char **libc_tabstr;
116 | } t_result;
117 |
118 | typedef struct s_presult
119 | {
120 | bool input_int;
121 | bool input_sizet;
122 | bool input_chr;
123 | bool input_str1;
124 | bool input_str2;
125 | bool output_int;
126 | bool output_sizet;
127 | bool output_chr;
128 | bool output_str;
129 | bool output_tabstr;
130 | } t_presult;
131 |
132 | // ENUM
133 | typedef enum e_ftime
134 | {
135 | RESET,
136 | USER_START,
137 | USER_END,
138 | USER_END_LIBC_START,
139 | LIBC_START,
140 | LIBC_END,
141 | PRINT
142 | } t_ftime;
143 |
144 | // GLOBALS
145 | extern t_presult g_presult;
146 | extern t_result g_result;
147 | extern int g_node_freed;
148 | extern const t_ftest g_fmandatory[];
149 | extern const t_ftest g_fbonus[];
150 | extern const char *g_str1_tests[];
151 | extern const char *g_str2_tests[];
152 | extern const char *g_nbr_tests[];
153 | extern const char *g_sortn_tests[];
154 | extern const char *g_revn_tests[];
155 | extern const char *g_lowa_tests[];
156 | extern const char *g_uppa_tests[];
157 |
158 | // UTIL FUNCTIONS
159 | void ft_print_name(char *name);
160 | void ft_print_file(char *path);
161 | bool ft_test_norminette(char *name);
162 | bool ft_check_sysfunc(char *name);
163 | void ft_time_function(t_ftime action);
164 | void ft_print_result(bool print_libc);
165 | void ft_reset_presult(void);
166 | void ft_result_input_int(int intput);
167 | void ft_result_input_sizet(size_t intput);
168 | void ft_result_input_chr(char intput);
169 | void ft_result_input_str(char *str1, char *str2);
170 | void ft_result_output_int(int user, int libc);
171 | void ft_result_output_sizet(size_t user, size_t libc);
172 | void ft_result_output_chr(char user, char libc);
173 | void ft_result_output_str(char *user, char *libc);
174 | void ft_result_output_tabstr(char **user, char **libc);
175 | void ft_grade(bool success);
176 | void ft_free_lst(t_list *lst);
177 | size_t ft_lst_size(t_list *lst);
178 | void ft_test_free(void *ptr);
179 | void ft_strtoupper(void *ptr);
180 | void *ft_duptoupper(void *ptr);
181 | // MAIN FUNCTIONS
182 | bool ft_call_test(char *name);
183 | void ft_call_all_test(bool title, bool force, const t_ftest *ftest);
184 | // TEST FUNCTIONS
185 | bool ft_test_ascii(char *name);
186 | bool ft_test_strlen(char *name);
187 | bool ft_test_memset(char *name);
188 | bool ft_test_bzero(char *name);
189 | bool ft_test_memcpy(char *name);
190 | bool ft_test_memmove(char *name);
191 | bool ft_test_strlcpy(char *name);
192 | bool ft_test_strlcat(char *name);
193 | bool ft_test_strchr(char *name);
194 | bool ft_test_strrchr(char *name);
195 | bool ft_test_strncmp(char *name);
196 | bool ft_test_memchr(char *name);
197 | bool ft_test_memcmp(char *name);
198 | bool ft_test_strnstr(char *name);
199 | bool ft_test_atoi(char *name);
200 | bool ft_test_calloc(char *name);
201 | bool ft_test_strdup(char *name);
202 | bool ft_test_substr(char *name);
203 | bool ft_test_strjoin(char *name);
204 | bool ft_test_strtrim(char *name);
205 | bool ft_test_split(char *name);
206 | bool ft_test_itoa(char *name);
207 | bool ft_test_strmapi(char *name);
208 | bool ft_test_striteri(char *name);
209 | bool ft_test_putchar_fd(char *name);
210 | bool ft_test_putstr_fd(char *name);
211 | bool ft_test_putendl_fd(char *name);
212 | bool ft_test_putnbr_fd(char *name);
213 | // TEST BONUS FUNCTIONS
214 | bool ft_test_lstnew(char *name) __attribute__((weak));
215 | bool ft_test_lstadd_front(char *name) __attribute__((weak));
216 | bool ft_test_lstsize(char *name) __attribute__((weak));
217 | bool ft_test_lstlast(char *name) __attribute__((weak));
218 | bool ft_test_lstadd_back(char *name) __attribute__((weak));
219 | bool ft_test_lstdelone(char *name) __attribute__((weak));
220 | bool ft_test_lstclear(char *name) __attribute__((weak));
221 | bool ft_test_lstiter(char *name) __attribute__((weak));
222 | bool ft_test_lstmap(char *name) __attribute__((weak));
223 |
224 | #endif
225 |
--------------------------------------------------------------------------------
/resources/000010.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/000010.gif
--------------------------------------------------------------------------------
/resources/42.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/42.gif
--------------------------------------------------------------------------------
/resources/discord.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/discord.gif
--------------------------------------------------------------------------------
/resources/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/example.gif
--------------------------------------------------------------------------------
/resources/le_xav.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/le_xav.jpg
--------------------------------------------------------------------------------
/resources/logo1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/logo1.gif
--------------------------------------------------------------------------------
/resources/logo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/logo2.gif
--------------------------------------------------------------------------------
/resources/title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/title.png
--------------------------------------------------------------------------------
/resources/xav.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/xav.gif
--------------------------------------------------------------------------------
/scripts/check_files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | R="\e[91m"
4 | G="\e[92m"
5 | Y="\e[93m"
6 | BD="\e[1m"
7 | DM="\e[2m\e[3m"
8 | X="\e[0m"
9 |
10 | dir="../"
11 | files=("libft.h" "Makefile")
12 | targets=("all" "libft.a" "clean" "fclean" "re")
13 | flags=("-Wall" "-Wextra" "-Werror")
14 |
15 | check_lib_norme() {
16 | if [[ $(./scripts/check_norminette_version.sh) -eq 0 ]]; then
17 | if ! norminette -R CheckDefine ../libft.h > /dev/null 2>&1; then
18 | echo -e "${BD}Norminette libft:${X} ${R}ERROR${X}\n"
19 | read -n 1 -s -r -p "Press any key to continue..."
20 | return 1
21 | else
22 | echo -e "${BD}Norminette libft:${X} ${G}OK${X}\n"
23 | read -n 1 -s -r -p "Press any key to continue..."
24 | return 0
25 | fi
26 | else
27 | if norminette -R CheckDefine ../libft.h > /dev/null 2>&1; then
28 | echo -e "${BD}Norminette libft:${X} ${R}ERROR${X}\n"
29 | read -n 1 -s -r -p "Press any key to continue..."
30 | return 1
31 | else
32 | echo -e "${BD}Norminette libft:${X} ${G}OK${X}\n"
33 | read -n 1 -s -r -p "Press any key to continue..."
34 | return 0
35 | fi
36 | fi
37 | }
38 |
39 | check_compile_flags() {
40 | local makefile_flags=$(make -qpC .. | awk '/^CFLAGS/{for (i=3; i<=NF; i++) print $i}')
41 |
42 | for flag in "${flags[@]}"; do
43 | found=false
44 | for make_flag in $makefile_flags; do
45 | if [[ $make_flag == "$flag"* ]]; then
46 | found=true
47 | break
48 | fi
49 | done
50 | if ! $found; then
51 | echo -e "${BD}Compilation flag:${X} ${DM}$flag${X} ${R}MISSING${X}"
52 | return 1
53 | fi
54 | done
55 | echo -e "${BD}Compilation flag:${X} ${G}OK${X}"
56 | check_lib_norme
57 | }
58 |
59 | check_targets() {
60 | local makefile_targets=$(make -qpC .. | awk -F':' '/^[^.# ][^\t]*:/{print $1}')
61 |
62 | for target in "${targets[@]}"; do
63 | found=false
64 | for make_target in $makefile_targets; do
65 | if [[ $make_target == "$target"* ]]; then
66 | found=true
67 | break
68 | fi
69 | done
70 | if ! $found; then
71 | echo -e "${BD}Makefile targets:${X} ${DM}$target${X} ${R}MISSING${X}"
72 | return 1
73 | fi
74 | done
75 | echo -e "${BD}Makefile targets:${X} ${G}OK${X}"
76 | check_compile_flags
77 | }
78 |
79 | check_files() {
80 | if [ -n "$1" ]; then
81 | targets+=("$1")
82 | fi
83 | for file in "${files[@]}"; do
84 | if [ -e "$dir/$file" ]; then
85 | echo -e "${BD}$file:${X} ${G}OK${X}"
86 | else
87 | echo -e "${BD}$file:${X} ${R}MISSING${X}"
88 | return 1
89 | fi
90 | done
91 | check_targets
92 | }
93 |
94 | check_files $1
--------------------------------------------------------------------------------
/scripts/check_hostname.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | check_hostname() {
4 | local hostname=$(hostname)
5 | local prefixes=("paul" "made" "bess")
6 |
7 | for prefix in "${prefixes[@]}"; do
8 | [[ $hostname == $prefix* ]] && return 1
9 | done
10 | return 0
11 | }
12 |
13 | check_hostname
--------------------------------------------------------------------------------
/scripts/check_norminette_version.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | check_norminette_version() {
4 | local current_version=$(norminette -v | awk '{print $2}')
5 | local base_version="3.3.51"
6 |
7 | if [[ $(echo -e "$base_version\n$current_version" | sort -V | head -n1) == $base_version ]]; then
8 | if [[ $current_version == $base_version ]]; then
9 | return 1
10 | else
11 | return 0
12 | fi
13 | else
14 | return 1
15 | fi
16 | }
17 |
18 | check_norminette_version
--------------------------------------------------------------------------------
/scripts/check_sysfunc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | declare -A executable_whitelists
4 | executable_whitelists["../ft_isalpha.o"]=""
5 | executable_whitelists["../ft_isdigit.o"]=""
6 | executable_whitelists["../ft_isalnum.o"]=""
7 | executable_whitelists["../t_isascii.o"]=""
8 | executable_whitelists["../ft_isprint.o"]=""
9 | executable_whitelists["../ft_strlen.o"]=""
10 | executable_whitelists["../ft_memset.o"]=""
11 | executable_whitelists["../ft_bzero.o"]=""
12 | executable_whitelists["../ft_memcpy.o"]=""
13 | executable_whitelists["../ft_memmove.o"]=""
14 | executable_whitelists["../ft_strlcpy.o"]=""
15 | executable_whitelists["../ft_strlcat.o"]=""
16 | executable_whitelists["../ft_tolower.o"]=""
17 | executable_whitelists["../ft_toupper.o"]=""
18 | executable_whitelists["../ft_strchr.o"]=""
19 | executable_whitelists["../ft_strrchr.o"]=""
20 | executable_whitelists["../ft_strncmp.o"]=""
21 | executable_whitelists["../ft_memchr.o"]=""
22 | executable_whitelists["../ft_memcmp.o"]=""
23 | executable_whitelists["../ft_strnstr.o"]=""
24 | executable_whitelists["../ft_atoi.o"]=""
25 | executable_whitelists["../ft_calloc.o"]="malloc"
26 | executable_whitelists["../ft_strdup.o"]="malloc"
27 | executable_whitelists["../ft_substr.o"]="malloc"
28 | executable_whitelists["../ft_strjoin.o"]="malloc"
29 | executable_whitelists["../ft_strtrim.o"]="malloc"
30 | executable_whitelists["../ft_split.o"]="malloc,free"
31 | executable_whitelists["../ft_itoa.o"]="malloc"
32 | executable_whitelists["../ft_strmapi.o"]="malloc"
33 | executable_whitelists["../ft_striteri.o"]=""
34 | executable_whitelists["../ft_putchar_fd.o"]="write"
35 | executable_whitelists["../ft_putstr_fd.o"]="write"
36 | executable_whitelists["../ft_putendl_fd.o"]="write"
37 | executable_whitelists["../ft_putnbr_fd.o"]="write"
38 | executable_whitelists["../ft_lstnew_bonus.o"]="malloc"
39 | executable_whitelists["../ft_lstadd_front_bonus.o"]=""
40 | executable_whitelists["../ft_lstsize_bonus.o"]=""
41 | executable_whitelists["../ft_lstlast_bonus.o"]=""
42 | executable_whitelists["../ft_lstadd_back_bonus.o"]=""
43 | executable_whitelists["../ft_lstdelone_bonus.o"]="free"
44 | executable_whitelists["../ft_lstclear_bonus.o"]="free"
45 | executable_whitelists["../ft_lstiter_bonus.o"]=""
46 | executable_whitelists["../ft_lstmap_bonus.o"]="malloc,free"
47 |
48 | check_sysfunc() {
49 | local file="$1"
50 | local whitelist_str="${executable_whitelists[$file]}"
51 | local whitelist=()
52 | local symbols=$(nm "$file" | grep ' U ' | awk '{print $2}')
53 | local forbidden_calls=()
54 |
55 | if [ -n "$whitelist_str" ]; then
56 | IFS=',' read -r -a whitelist <<< "$whitelist_str"
57 | fi
58 | for symbol in $symbols; do
59 | local found=0
60 | if [[ "$symbol" =~ ^(ft_|__) ]]; then
61 | continue
62 | fi
63 | for allowed_call in "${whitelist[@]}"; do
64 | if [ "$symbol" == "$allowed_call" ]; then
65 | found=1
66 | break
67 | fi
68 | done
69 | if [ $found -eq 0 ]; then
70 | forbidden_calls+=("$symbol")
71 | fi
72 | done
73 | if [ ${#forbidden_calls[@]} -eq 0 ]; then
74 | echo "Forbidden system function calls: OK"
75 | return 1
76 | else
77 | echo "Forbidden system function calls detected:"
78 | for forbidden_call in "${forbidden_calls[@]}"; do
79 | echo "- $forbidden_call"
80 | done
81 | return 0
82 | fi
83 | }
84 |
85 | check_sysfunc "$1"
--------------------------------------------------------------------------------
/scripts/show_func.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | find ../ -maxdepth 1 -type f -name 'ft_*.c' -exec basename -s .c {} \; | sort
--------------------------------------------------------------------------------
/scripts/title.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | B='\e[94m'
4 | G='\e[90m'
5 | C='\e[96m'
6 | IT='\e[3m'
7 | X='\e[0m'
8 |
9 | clear
10 | printf "\n"
11 | printf "${B}██${G}╗ ${B}██${G}╗${B}██████${G}╗ ${B}████████${G}╗${B}███████${G}╗${B}███████${G}╗${B}████████${G}╗\n"
12 | printf "${B}██${G}║ ${B}██${G}║${B}██${G}╔══${B}██${G}╗╚══${B}██${G}╔══╝${B}██${G}╔════╝${B}██${G}╔════╝╚══${B}██${G}╔══╝\n"
13 | printf "${B}██${G}║ ${B}██${G}║${B}██████${G}╔╝ ${B}██${G}║ ${B}█████${G}╗ ${B}███████${G}╗ ${B}██${G}║ \n"
14 | printf "${B}██${G}║ ${B}██${G}║${B}██${G}╔══${B}██${G}╗ ${B}██${G}║ ${B}██${G}╔══╝ ╚════${B}██${G}║ ${B}██${G}║ \n"
15 | printf "${B}███████${G}╗${B}██${G}║${B}██████${G}╔╝ ${B}██${G}║ ${B}███████${G}╗${B}███████${G}║ ${B}██${G}║ \n"
16 | printf "${G}╚══════╝╚═╝╚═════╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ${X}${IT}by ${C}FonWasH${X}\n"
--------------------------------------------------------------------------------
/srcs/ft_call_test.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_call_test.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/16 08:42:22 by juperez #+# #+# */
9 | /* Updated: 2024/05/19 14:41:16 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_check_functions(char *name, const t_ftest *ftest)
16 | {
17 | for (size_t i = 0; ftest[i].name; i++)
18 | {
19 | if (!strcmp(name, ftest[i].name) && (*ftest[i].f))
20 | {
21 | system(TITLE);
22 | printf("\n");
23 | ft_print_name(name);
24 | if (ft_test_norminette(name) && ft_check_sysfunc(name))
25 | {
26 | ft_reset_presult();
27 | ft_time_function(RESET);
28 | ft_grade((*ftest[i].f)(name));
29 | }
30 | return (true);
31 | }
32 | }
33 | return (false);
34 | }
35 |
36 | bool ft_call_test(char *name)
37 | {
38 | if (!ft_check_functions(name, g_fmandatory))
39 | if (!ft_check_functions(name, g_fbonus))
40 | return (false);
41 | return (true);
42 | }
43 |
44 | void ft_call_all_test(bool title, bool force, const t_ftest *ftest)
45 | {
46 | if (title)
47 | system(TITLE);
48 | for (size_t i = 0; ftest[i].name; i++)
49 | {
50 | if (!(*ftest[i].f))
51 | continue ;
52 | printf("\n");
53 | ft_print_name(ftest[i].name);
54 | if (force || (ft_test_norminette(ftest[i].name) && ft_check_sysfunc(ftest[i].name)))
55 | {
56 | ft_reset_presult();
57 | ft_time_function(RESET);
58 | ft_grade((*ftest[i].f)(ftest[i].name));
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/srcs/global/globals.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* globals.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/16 08:03:35 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 18:29:56 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | t_presult g_presult;
16 | t_result g_result;
17 | int g_node_freed;
18 |
19 | const t_ftest g_fmandatory[] = {
20 | {"ft_isalpha", ft_test_ascii},
21 | {"ft_isdigit", ft_test_ascii},
22 | {"ft_isalnum", ft_test_ascii},
23 | {"ft_isascii", ft_test_ascii},
24 | {"ft_isprint", ft_test_ascii},
25 | {"ft_strlen", ft_test_strlen},
26 | {"ft_memset", ft_test_memset},
27 | {"ft_bzero", ft_test_bzero},
28 | {"ft_memcpy", ft_test_memcpy},
29 | {"ft_memmove", ft_test_memmove},
30 | {"ft_strlcpy", ft_test_strlcpy},
31 | {"ft_strlcat", ft_test_strlcat},
32 | {"ft_tolower", ft_test_ascii},
33 | {"ft_toupper", ft_test_ascii},
34 | {"ft_strchr", ft_test_strchr},
35 | {"ft_strrchr", ft_test_strrchr},
36 | {"ft_strncmp", ft_test_strncmp},
37 | {"ft_memchr", ft_test_memchr},
38 | {"ft_memcmp", ft_test_memcmp},
39 | {"ft_strnstr", ft_test_strnstr},
40 | {"ft_atoi", ft_test_atoi},
41 | {"ft_calloc", ft_test_calloc},
42 | {"ft_strdup", ft_test_strdup},
43 | {"ft_substr", ft_test_substr},
44 | {"ft_strjoin", ft_test_strjoin},
45 | {"ft_strtrim", ft_test_strtrim},
46 | {"ft_split", ft_test_split},
47 | {"ft_itoa", ft_test_itoa},
48 | {"ft_strmapi", ft_test_strmapi},
49 | {"ft_striteri", ft_test_striteri},
50 | {"ft_putchar_fd", ft_test_putchar_fd},
51 | {"ft_putstr_fd", ft_test_putstr_fd},
52 | {"ft_putendl_fd", ft_test_putendl_fd},
53 | {"ft_putnbr_fd", ft_test_putnbr_fd},
54 | {NULL, NULL}
55 | };
56 |
57 | const t_ftest g_fbonus[] = {
58 | {"ft_lstnew_bonus", ft_test_lstnew},
59 | {"ft_lstadd_front_bonus", ft_test_lstadd_front},
60 | {"ft_lstsize_bonus", ft_test_lstsize},
61 | {"ft_lstlast_bonus", ft_test_lstlast},
62 | {"ft_lstadd_back_bonus", ft_test_lstadd_back},
63 | {"ft_lstdelone_bonus", ft_test_lstdelone},
64 | {"ft_lstclear_bonus", ft_test_lstclear},
65 | {"ft_lstiter_bonus", ft_test_lstiter},
66 | {"ft_lstmap_bonus", ft_test_lstmap},
67 | {NULL, NULL}
68 | };
69 |
70 | const char *g_str1_tests[] = {
71 | "\t\n\v\f\r ",
72 | "Hello World!",
73 | "abcdefghijklmnopqrstuvwxyz",
74 | "42",
75 | "#",
76 | "",
77 | NULL
78 | };
79 |
80 | const char *g_str2_tests[] = {
81 | "Hello World!",
82 | "Hello42",
83 | "abcdefghijklmnopqrstuvwxyz",
84 | "abcdefghijklmnopqrstuvwxyzABC",
85 | "abc",
86 | "abcABC",
87 | "42",
88 | "#",
89 | "",
90 | NULL
91 | };
92 |
93 | const char *g_nbr_tests[] = {
94 | "42",
95 | "-42",
96 | "0",
97 | "-2147483648",
98 | "2147483647",
99 | "-1",
100 | "1",
101 | "100",
102 | NULL
103 | };
104 |
105 | const char *g_sortn_tests[] = {
106 | "1",
107 | "2",
108 | "3",
109 | "4",
110 | "5",
111 | NULL
112 | };
113 |
114 | const char *g_revn_tests[] = {
115 | "5",
116 | "4",
117 | "3",
118 | "2",
119 | "1",
120 | NULL
121 | };
122 |
123 | const char *g_lowa_tests[] = {
124 | "a",
125 | "b",
126 | "c",
127 | "d",
128 | "e",
129 | NULL
130 | };
131 |
132 | const char *g_uppa_tests[] = {
133 | "A",
134 | "B",
135 | "C",
136 | "D",
137 | "E",
138 | NULL
139 | };
--------------------------------------------------------------------------------
/srcs/main.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* main.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/07 04:47:10 by juperez #+# #+# */
9 | /* Updated: 2024/05/07 11:20:22 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | int main(int ac, char *av[])
16 | {
17 | if (ac > 1)
18 | {
19 | if (!strcmp(av[1], "--all") || !strcmp(av[1], "-a"))
20 | {
21 | ft_call_all_test(true, false, g_fmandatory);
22 | ft_call_all_test(false, false, g_fbonus);
23 | }
24 | else if (!strcmp(av[1], "--force") || !strcmp(av[1], "-f"))
25 | {
26 | ft_call_all_test(true, true, g_fmandatory);
27 | ft_call_all_test(false, true, g_fbonus);
28 | }
29 | else if (!strcmp(av[1], "--mandatory") || !strcmp(av[1], "-m"))
30 | ft_call_all_test(true, false, g_fmandatory);
31 | else if (!strcmp(av[1], "--bonus") || !strcmp(av[1], "-b"))
32 | ft_call_all_test(true, false, g_fbonus);
33 | else if (!strcmp(av[1], "--show") || !strcmp(av[1], "-s"))
34 | system(SHOW_FUNC);
35 | else if (!strcmp(av[1], "--help") || !strcmp(av[1], "-h"))
36 | ft_print_file(SHOW_HELP);
37 | else if (!strcmp(av[1], "--version") || !strcmp(av[1], "-v"))
38 | ft_print_file(SHOW_VERSION);
39 | else if (!ft_call_test(av[1]))
40 | printf("%s: invalid argument -- '%s'%s",
41 | basename(av[0]), av[1], ERROR_HELP);
42 | }
43 | else
44 | printf("%s: requires an argument%s", basename(av[0]), ERROR_HELP);
45 | return (EXIT_SUCCESS);
46 | }
47 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_ascii.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_ascii.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 08:42:03 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:33 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static void ft_get_functions(char *name, int (**user)(int), int (**libc)(int))
16 | {
17 | const t_fascii fascii[] = {
18 | {"ft_isalnum", ft_isalnum, isalnum},
19 | {"ft_isalpha", ft_isalpha, isalpha},
20 | {"ft_isascii", ft_isascii, isascii},
21 | {"ft_isdigit", ft_isdigit, isdigit},
22 | {"ft_isprint", ft_isprint, isprint},
23 | {"ft_tolower", ft_tolower, tolower},
24 | {"ft_toupper", ft_toupper, toupper},
25 | {NULL, NULL, NULL}
26 | };
27 |
28 | for (size_t i = 0; fascii[i].name; i++)
29 | {
30 | if (!strcmp(name, fascii[i].name))
31 | {
32 | *user = fascii[i].user;
33 | *libc = fascii[i].libc;
34 | }
35 | }
36 | }
37 |
38 | static bool ft_run_test(int (*f_user)(int), int (*f_libc)(int), int c)
39 | {
40 | int user, libc;
41 |
42 | ft_time_function(USER_START);
43 | user = (*f_user)(c);
44 | ft_time_function(USER_END_LIBC_START);
45 | libc = (*f_libc)(c);
46 | ft_time_function(LIBC_END);
47 | if (!(libc == user))
48 | {
49 | ft_result_input_int(c);
50 | ft_result_output_int(user, libc);
51 | ft_print_result(true);
52 | return (false);
53 | }
54 | return (true);
55 | }
56 |
57 | static bool ft_test_irange(int (*f_user)(int), int (*f_libc)(int))
58 | {
59 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1;
60 |
61 | while (i <= UCHAR_MAX + 1)
62 | {
63 | grade += ft_run_test(f_user, f_libc, i);
64 | i++;
65 | }
66 | return (grade == i);
67 | }
68 |
69 | bool ft_test_ascii(char *name)
70 | {
71 | int (*f_user)(int), (*f_libc)(int);
72 |
73 | ft_get_functions(name, &f_user, &f_libc);
74 | return (ft_test_irange(f_user, f_libc));
75 | }
76 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_atoi.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_atoi.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 09:48:50 by juperez #+# #+# */
9 | /* Updated: 2024/05/21 16:13:20 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_atoi_str[] = {
16 | "\t\n\v\f\r +00000042",
17 | " -42a",
18 | " a42",
19 | " -+--+42",
20 | "-2147483648",
21 | "2147483647",
22 | "0",
23 | "-00",
24 | "",
25 | "999999999999999",
26 | "-999999999999999",
27 | "9999999999999999999",
28 | "-9999999999999999999",
29 | "999999999999999999999",
30 | "-999999999999999999999",
31 | "0000000000000000000042",
32 | "9223372036854775805",
33 | "9223372036854775806",
34 | "9223372036854775807",
35 | "9223372036854775808",
36 | "9223372036854775809",
37 | "-9223372036854775805",
38 | "-9223372036854775806",
39 | "-9223372036854775807",
40 | "-9223372036854775808",
41 | "-9223372036854775809",
42 | NULL
43 | };
44 |
45 | static bool ft_run_test(const char *nptr)
46 | {
47 | int user, libc;
48 |
49 | ft_time_function(USER_START);
50 | user = ft_atoi(nptr);
51 | ft_time_function(USER_END_LIBC_START);
52 | libc = atoi(nptr);
53 | ft_time_function(LIBC_END);
54 | if (!(user == libc))
55 | {
56 | ft_result_input_str((char *)nptr, NULL);
57 | ft_result_output_int(user, libc);
58 | ft_print_result(true);
59 | return (false);
60 | }
61 | return (true);
62 | }
63 |
64 | bool ft_test_atoi(char *name)
65 | {
66 | size_t i = 0, grade = 0;
67 |
68 | (void)name;
69 | while (g_atoi_str[i])
70 | {
71 | grade += ft_run_test(g_atoi_str[i]);
72 | i++;
73 | }
74 | return (grade == i);
75 | }
76 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_bzero.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_bzero.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/20 21:07:19 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:37 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(size_t n)
16 | {
17 | char user[] = "................";
18 | char libc[] = "................";
19 |
20 | ft_time_function(USER_START);
21 | ft_bzero((void *)user, n);
22 | ft_time_function(USER_END_LIBC_START);
23 | bzero((void *)libc, n);
24 | ft_time_function(LIBC_END);
25 | if (strcmp(user, libc))
26 | {
27 | ft_result_input_sizet(n);
28 | ft_result_output_str(user, libc);
29 | ft_print_result(true);
30 | return (false);
31 | }
32 | return (true);
33 | }
34 |
35 | bool ft_test_bzero(char *name)
36 | {
37 | size_t i = 0, grade = 0;
38 |
39 | (void)name;
40 | while (i < 16)
41 | {
42 | grade += ft_run_test(i);
43 | i++;
44 | }
45 | return (grade == i);
46 | }
47 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_calloc.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_calloc.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:30:43 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:38 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(size_t nmemb, size_t size)
16 | {
17 | size_t i = (nmemb && size && (SIZE_MAX / nmemb < size)) ? nmemb * size : 1;
18 | char str_nmemb[21], str_size[21];
19 | char *user, *libc;
20 |
21 | ft_time_function(USER_START);
22 | user = (char *)ft_calloc(nmemb, size);
23 | ft_time_function(USER_END_LIBC_START);
24 | libc = (char *)calloc(nmemb, size);
25 | ft_time_function(LIBC_END);
26 | memset((void *)user, '.', i);
27 | memset((void *)libc, '.', i);
28 | user[i - 1] = '\0';
29 | libc[i - 1] = '\0';
30 | if (strcmp(user, libc))
31 | {
32 | sprintf(str_nmemb, "%zu", nmemb);
33 | sprintf(str_size, "%zu", size);
34 | ft_result_input_str(str_nmemb, str_size);
35 | ft_result_output_str(user, libc);
36 | ft_print_result(true);
37 | free(user);
38 | free(libc);
39 | return (false);
40 | }
41 | free(user);
42 | free(libc);
43 | return (true);
44 | }
45 |
46 | bool ft_test_calloc(char *name)
47 | {
48 | size_t nmemb[] = {0, 10, 0, 10, 100}; //SIZE_MAX 18446744073709551615
49 | size_t size[] = {0, 0, 10, 10, 100};
50 | size_t i = 0, grade = 0, count = sizeof(size) / sizeof(size[0]);
51 |
52 | (void)name;
53 | while (i < count)
54 | {
55 | grade += ft_run_test(nmemb[i], size[i]);
56 | i++;
57 | }
58 | return (grade == i);
59 | }
60 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_itoa.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_itoa.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 09:48:58 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 19:51:01 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(char *n_str)
16 | {
17 | int n = atoi(n_str);
18 | char *user;
19 |
20 | ft_time_function(USER_START);
21 | user = ft_itoa(n);
22 | ft_time_function(USER_END);
23 | if (strcmp(user, n_str))
24 | {
25 | ft_result_input_int(n);
26 | ft_result_output_str(user, n_str);
27 | ft_print_result(false);
28 | free(user);
29 | return (false);
30 | }
31 | free(user);
32 | return (true);
33 | }
34 |
35 | bool ft_test_itoa(char *name)
36 | {
37 | size_t i = 0, grade = 0;
38 |
39 | (void)name;
40 | while (g_nbr_tests[i])
41 | {
42 | grade += ft_run_test((char *)g_nbr_tests[i]);
43 | i++;
44 | }
45 | return (grade == i);
46 | }
47 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstadd_back.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstadd_back.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:34:02 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:39:47 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *user = NULL;
18 | t_list *tmp = NULL;
19 | size_t user_size = 0, size = 0;
20 |
21 | ft_time_function(USER_START);
22 | while (g_revn_tests[size])
23 | {
24 | ft_lstadd_back(&user, ft_lstnew((void *)g_sortn_tests[size]));
25 | size++;
26 | }
27 | ft_time_function(USER_END);
28 | tmp = user;
29 | user_size = ft_lst_size(user);
30 | if (user_size != size)
31 | {
32 | ft_result_input_sizet(size);
33 | ft_result_output_sizet(user_size, size);
34 | ft_print_result(false);
35 | printf(LST_SIZE);
36 | ft_free_lst(user);
37 | return (false);
38 | }
39 | for (size_t i = 0; g_sortn_tests[i]; i++)
40 | {
41 | if (strcmp((char *)tmp->content, (char *)g_sortn_tests[i]))
42 | {
43 | ft_result_input_str((char *)g_sortn_tests[i], NULL);
44 | ft_result_output_str((char *)tmp->content, (char *)g_sortn_tests[i]);
45 | ft_print_result(false);
46 | ft_free_lst(user);
47 | return (false);
48 | }
49 | tmp = tmp->next;
50 | }
51 | ft_free_lst(user);
52 | return (true);
53 | }
54 |
55 | bool ft_test_lstadd_back(char *name)
56 | {
57 | (void)name;
58 | return (ft_run_test());
59 | }
60 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstadd_front.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstadd_front.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:33:25 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:39:41 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *user = NULL;
18 | t_list *tmp = NULL;
19 | size_t user_size = 0, size = 0;
20 |
21 | ft_time_function(USER_START);
22 | while (g_revn_tests[size])
23 | {
24 | ft_lstadd_front(&user, ft_lstnew((void *)g_revn_tests[size]));
25 | size++;
26 | }
27 | ft_time_function(USER_END);
28 | tmp = user;
29 | user_size = ft_lst_size(user);
30 | if (user_size != size)
31 | {
32 | ft_result_input_sizet(size);
33 | ft_result_output_sizet(user_size, size);
34 | ft_print_result(false);
35 | printf(LST_SIZE);
36 | ft_free_lst(user);
37 | return (false);
38 | }
39 | for (size_t i = 0; g_sortn_tests[i]; i++)
40 | {
41 | if (strcmp((char *)tmp->content, (char *)g_sortn_tests[i]))
42 | {
43 | ft_result_input_str((char *)g_sortn_tests[i], NULL);
44 | ft_result_output_str((char *)tmp->content, (char *)g_sortn_tests[i]);
45 | ft_print_result(false);
46 | ft_free_lst(user);
47 | return (false);
48 | }
49 | tmp = tmp->next;
50 | }
51 | ft_free_lst(user);
52 | return (true);
53 | }
54 |
55 | bool ft_test_lstadd_front(char *name)
56 | {
57 | (void)name;
58 | return (ft_run_test());
59 | }
60 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstclear.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstclear.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:34:28 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:37:01 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *lst = NULL;
18 |
19 | for (size_t i = 0; g_revn_tests[i]; i++)
20 | ft_lstadd_back(&lst, ft_lstnew((void *)strdup(g_revn_tests[i])));
21 | ft_time_function(USER_START);
22 | ft_lstclear(&lst, ft_test_free);
23 | ft_time_function(USER_END);
24 | if (g_node_freed != 1)
25 | {
26 | ft_print_result(false);
27 | printf(LST_FREE);
28 | return (false);
29 | }
30 | return (true);
31 | }
32 |
33 | bool ft_test_lstclear(char *name)
34 | {
35 | (void)name;
36 | g_node_freed = 0;
37 | return (ft_run_test());
38 | }
39 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstdelone.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstdelone.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:34:14 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:37:26 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *lst = NULL;
18 |
19 | lst = ft_lstnew(ft_strdup("test"));
20 | ft_time_function(USER_START);
21 | ft_lstdelone(lst, ft_test_free);
22 | ft_time_function(USER_END);
23 | if (g_node_freed != 1)
24 | {
25 | ft_print_result(false);
26 | printf(LST_FREE);
27 | return (false);
28 | }
29 | return (true);
30 | }
31 |
32 | bool ft_test_lstdelone(char *name)
33 | {
34 | (void)name;
35 | g_node_freed = 0;
36 | return (ft_run_test());
37 | }
38 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstiter.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstiter.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:34:38 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:49:46 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *lst = NULL;
18 | t_list *tmp = NULL;
19 |
20 | for (size_t i = 0; g_lowa_tests[i]; i++)
21 | ft_lstadd_back(&lst, ft_lstnew(strdup((char *)g_lowa_tests[i])));
22 | ft_time_function(USER_START);
23 | ft_lstiter(lst, ft_strtoupper);
24 | ft_time_function(USER_END);
25 | tmp = lst;
26 | for (size_t i = 0; g_uppa_tests[i]; i++)
27 | {
28 | if (strcmp((char *)tmp->content, (char *)g_uppa_tests[i]))
29 | {
30 | ft_result_input_str((char *)g_uppa_tests[i], NULL);
31 | ft_result_output_str((char *)tmp->content, (char *)g_uppa_tests[i]);
32 | ft_print_result(false);
33 | ft_lstclear(&lst, free);
34 | return (false);
35 | }
36 | tmp = tmp->next;
37 | }
38 | ft_lstclear(&lst, free);
39 | return (true);
40 | }
41 |
42 | bool ft_test_lstiter(char *name)
43 | {
44 | (void)name;
45 | return (ft_run_test());
46 | }
47 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstlast.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstlast.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:33:51 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:38:28 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *lst = NULL, *last = NULL;
18 | size_t i = 0;
19 |
20 | while (g_revn_tests[i])
21 | {
22 | ft_lstadd_front(&lst, ft_lstnew((void *)g_revn_tests[i]));
23 | i++;
24 | }
25 | ft_time_function(USER_START);
26 | last = ft_lstlast(lst);
27 | ft_time_function(USER_END);
28 | if (strcmp((char *)last->content, (char *)g_sortn_tests[i - 1]))
29 | {
30 | ft_result_input_str((char *)g_sortn_tests[i - 1], NULL);
31 | ft_result_output_str((char *)last->content, (char *)g_sortn_tests[i - 1]);
32 | ft_print_result(false);
33 | ft_free_lst(lst);
34 | return (false);
35 | }
36 | ft_free_lst(lst);
37 | return (true);
38 | }
39 |
40 | bool ft_test_lstlast(char *name)
41 | {
42 | (void)name;
43 | return (ft_run_test());
44 | }
45 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstmap.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstmap.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:34:50 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:58:06 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *lst = NULL;
18 | t_list *new = NULL;
19 | t_list *tmp = NULL;
20 |
21 | for (size_t i = 0; g_lowa_tests[i]; i++)
22 | ft_lstadd_back(&lst, ft_lstnew(strdup((char *)g_lowa_tests[i])));
23 | ft_time_function(USER_START);
24 | new = ft_lstmap(lst, ft_duptoupper, free);
25 | ft_time_function(USER_END);
26 | tmp = new;
27 | for (size_t i = 0; g_uppa_tests[i]; i++)
28 | {
29 | if (strcmp((char *)tmp->content, (char *)g_uppa_tests[i]))
30 | {
31 | ft_result_input_str((char *)g_uppa_tests[i], NULL);
32 | ft_result_output_str((char *)tmp->content, (char *)g_uppa_tests[i]);
33 | ft_print_result(false);
34 | ft_lstclear(&lst, free);
35 | ft_lstclear(&new, free);
36 | return (false);
37 | }
38 | tmp = tmp->next;
39 | }
40 | ft_lstclear(&lst, free);
41 | ft_lstclear(&new, free);
42 | return (true);
43 | }
44 |
45 | bool ft_test_lstmap(char *name)
46 | {
47 | (void)name;
48 | return (ft_run_test());
49 | }
50 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstnew.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstnew.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:33:12 by juperez #+# #+# */
9 | /* Updated: 2024/05/19 16:08:01 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void *content)
16 | {
17 | t_list *user = NULL;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_lstnew(content);
21 | ft_time_function(USER_END);
22 | if (strcmp((char *)user->content, (char *)content))
23 | {
24 | ft_result_input_str((char *)content, NULL);
25 | ft_result_output_str((char *)user->content, NULL);
26 | ft_print_result(false);
27 | free(user);
28 | return (false);
29 | }
30 | free(user);
31 | return (true);
32 | }
33 |
34 | bool ft_test_lstnew(char *name)
35 | {
36 | size_t i = 0, grade = 0;
37 |
38 | (void)name;
39 | while (g_str2_tests[i])
40 | {
41 | grade += ft_run_test((void *)g_str2_tests[i]);
42 | i++;
43 | }
44 | return (grade == i);
45 | }
46 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_lstsize.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_lstsize.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:33:39 by juperez #+# #+# */
9 | /* Updated: 2024/05/20 15:39:27 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void)
16 | {
17 | t_list *lst = NULL;
18 | size_t user_size = 0, size = 0;
19 |
20 | for (size_t i = 0; g_sortn_tests[i]; i++)
21 | ft_lstadd_front(&lst, ft_lstnew((void *)g_sortn_tests[i]));
22 | ft_time_function(USER_START);
23 | user_size = ft_lstsize(lst);
24 | ft_time_function(USER_END);
25 | size = ft_lst_size(lst);
26 | if (user_size != size)
27 | {
28 | ft_result_input_sizet(size);
29 | ft_result_output_sizet(user_size, size);
30 | ft_print_result(false);
31 | printf(LST_SIZE);
32 | ft_free_lst(lst);
33 | return (false);
34 | }
35 | ft_free_lst(lst);
36 | return (true);
37 | }
38 |
39 | bool ft_test_lstsize(char *name)
40 | {
41 | (void)name;
42 | return (ft_run_test());
43 | }
44 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_memchr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_memchr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:30:00 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:39 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const void *s, int c, size_t n)
16 | {
17 | void *user, *libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_memchr(s, c, n);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = memchr(s, c, n);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_str((char *)s, NULL);
27 | ft_result_input_int(c);
28 | ft_result_input_sizet(n);
29 | ft_result_output_str((char *)user, (char *)libc);
30 | ft_print_result(true);
31 | return (false);
32 | }
33 | return (true);
34 | }
35 |
36 | static bool ft_test_size(const void *s, int c)
37 | {
38 | size_t i = 0, grade = 0, size = strlen(s);
39 |
40 | while (i < size)
41 | {
42 | grade += ft_run_test(s, c, i);
43 | i++;
44 | }
45 | return (grade == i);
46 | }
47 |
48 | bool ft_test_memchr(char *name)
49 | {
50 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1;
51 |
52 | (void)name;
53 | while (i <= UCHAR_MAX + 1)
54 | {
55 | grade += ft_test_size((const void *)g_str1_tests[1], i);
56 | i++;
57 | }
58 | return (grade == i);
59 | }
60 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_memcmp.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_memcmp.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:30:15 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:43 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const void *s1, const void *s2, size_t n)
16 | {
17 | int user, libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_memcmp(s1, s2, n);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = memcmp(s1, s2, n);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_sizet(n);
27 | ft_result_input_str((char *)s1, (char *)s2);
28 | ft_result_output_int(user, libc);
29 | ft_print_result(true);
30 | return (false);
31 | }
32 | return (true);
33 | }
34 |
35 | static bool ft_test_size(const void *s1, const void *s2)
36 | {
37 | size_t s1_len = strlen((char *)s1), s2_len = strlen((char *)s2);
38 | size_t size = s1_len <= s2_len ? s1_len : s2_len;
39 | size_t i = 0, grade = 0;
40 |
41 | while (i < size)
42 | {
43 | grade += ft_run_test(s1, s2, i);
44 | i++;
45 | }
46 | return (grade == i);
47 | }
48 |
49 | static bool ft_test_tofind(const void *s1)
50 | {
51 | size_t i = 0, grade = 0;
52 |
53 | while (g_str2_tests[i])
54 | {
55 | grade += ft_test_size(s1, (const void *)g_str2_tests[i]);
56 | i++;
57 | }
58 | return (grade == i);
59 | }
60 |
61 | bool ft_test_memcmp(char *name)
62 | {
63 | size_t i = 0, grade = 0;
64 |
65 | (void)name;
66 | while (g_str1_tests[i])
67 | {
68 | grade += ft_test_tofind((const void *)g_str1_tests[i]);
69 | i++;
70 | }
71 | return (grade == i);
72 | }
73 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_memcpy.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_memcpy.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/20 21:39:19 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:44 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const void *src, size_t n)
16 | {
17 | char user[] = "................";
18 | char libc[] = "................";
19 |
20 | n = n > 16 ? 16 : n;
21 | ft_time_function(USER_START);
22 | ft_memcpy((void *)user, src, n);
23 | ft_time_function(USER_END_LIBC_START);
24 | memcpy((void *)libc, src, n);
25 | ft_time_function(LIBC_END);
26 | if (strcmp(user, libc))
27 | {
28 | ft_result_input_sizet(n);
29 | ft_result_input_str((char *)src, NULL);
30 | ft_result_output_str(user, libc);
31 | ft_print_result(true);
32 | }
33 | return (true);
34 | }
35 |
36 | bool ft_test_memcpy(char *name)
37 | {
38 | size_t i = 0, grade = 0;
39 |
40 | (void)name;
41 | while (g_str1_tests[i])
42 | {
43 | grade += ft_run_test((const void *)g_str1_tests[i], strlen(g_str1_tests[i]));
44 | i++;
45 | }
46 | return (grade == i);
47 | }
48 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_memmove.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_memmove.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/21 02:18:39 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 01:24:19 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(void *user_dest, const void *user_src, void *libc_dest, const void *libc_src, size_t n)
16 | {
17 | ft_time_function(USER_START);
18 | ft_memmove(user_dest, user_src, n);
19 | ft_time_function(USER_END_LIBC_START);
20 | memmove(libc_dest, libc_src, n);
21 | ft_time_function(LIBC_END);
22 | if (strcmp(user_dest, libc_dest))
23 | return (false);
24 | return (true);
25 | }
26 |
27 | static bool ft_test_ptr_pos(void *user, void *libc, size_t n, size_t *pos)
28 | {
29 | *pos = 1;
30 | if (!ft_run_test(user, (const void *)user, libc, (const void *)libc, n))
31 | return (false);
32 | *pos = 2;
33 | if (!ft_run_test(user, (const void *)user + 5, libc, (const void *)libc + 5, n))
34 | return (false);
35 | *pos = 3;
36 | if (!ft_run_test(user + 6, (const void *)user, libc + 6, (const void *)libc, n))
37 | return (false);
38 | return (true);
39 | }
40 |
41 | bool ft_test_memmove(char *name)
42 | {
43 | char user[] = "abcdefghijklmnopqrst";
44 | char libc[] = "abcdefghijklmnopqrst";
45 | size_t i = 0, grade = 0, pos;
46 | bool success;
47 |
48 | (void)name;
49 | while (i < 10)
50 | {
51 | success = ft_test_ptr_pos((void *)user, (void *)libc, i, &pos);
52 | if (!success)
53 | {
54 | ft_result_input_sizet(i);
55 | ft_result_output_str((char *)user, (char *)libc);
56 | ft_print_result(true);
57 | printf("%s%s", MEM, pos == 1 ? EQU : pos == 2 ? HIG : LOW);
58 | }
59 | grade += success;
60 | i++;
61 | }
62 | return (grade == i);
63 | }
64 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_memset.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_memset.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/19 08:06:06 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:47 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(int c, size_t n)
16 | {
17 | char user[] = "................";
18 | char libc[] = "................";
19 |
20 | ft_time_function(USER_START);
21 | ft_memset(user, c, n);
22 | ft_time_function(USER_END_LIBC_START);
23 | memset(libc, c, n);
24 | ft_time_function(LIBC_END);
25 | if (strcmp(user, libc))
26 | {
27 | ft_result_input_sizet(n);
28 | ft_result_input_int(c);
29 | ft_result_output_str(user, libc);
30 | ft_print_result(true);
31 | return (false);
32 | }
33 | return (true);
34 | }
35 |
36 | static bool ft_test_size(int c)
37 | {
38 | size_t i = 0, grade = 0;
39 |
40 | while (i < 16)
41 | {
42 | grade += ft_run_test(c, i);
43 | i++;
44 | }
45 | return (grade == i);
46 | }
47 |
48 | bool ft_test_memset(char *name)
49 | {
50 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1;
51 |
52 | (void)name;
53 | while (i <= UCHAR_MAX + 1)
54 | {
55 | grade += ft_test_size(i);
56 | i++;
57 | }
58 | return (grade == i);
59 | }
60 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_putchar_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_putchar_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:32:17 by juperez #+# #+# */
9 | /* Updated: 2024/05/21 19:19:39 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(char c)
16 | {
17 | int pipefd[2];
18 | char user[BUFFER_SIZE];
19 |
20 | memset(user, 0, sizeof(user));
21 | pipe(pipefd);
22 | ft_time_function(USER_START);
23 | ft_putchar_fd(c, pipefd[1]);
24 | ft_time_function(USER_END);
25 | read(pipefd[0], user, BUFFER_SIZE);
26 | if (!(user[0] == c))
27 | {
28 | ft_result_input_chr(c);
29 | ft_result_output_chr(user[0], c);
30 | ft_print_result(false);
31 | close(pipefd[0]);
32 | close(pipefd[1]);
33 | return (false);
34 | }
35 | close(pipefd[0]);
36 | close(pipefd[1]);
37 | return (true);
38 | }
39 |
40 | bool ft_test_putchar_fd(char *name)
41 | {
42 | size_t i = 0, grade = 0;
43 |
44 | (void)name;
45 | while (g_str1_tests[1][i])
46 | {
47 | grade += ft_run_test(g_str1_tests[1][i]);
48 | i++;
49 | }
50 | return (grade == i);
51 | }
52 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_putendl_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_putendl_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:32:43 by juperez #+# #+# */
9 | /* Updated: 2024/05/21 19:19:46 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_eputendl[] = {
16 | "\t\n\v\f\r \n",
17 | "Hello World!\n",
18 | "abcdefghijklmnopqrstuvwxyz\n",
19 | "42\n",
20 | "#\n",
21 | "\n",
22 | NULL
23 | };
24 |
25 | static bool ft_run_test(char *s, char *e)
26 | {
27 | int pipefd[2];
28 | char user[BUFFER_SIZE];
29 |
30 | memset(user, 0, sizeof(user));
31 | pipe(pipefd);
32 | ft_time_function(USER_START);
33 | ft_putendl_fd(s, pipefd[1]);
34 | ft_time_function(USER_END);
35 | read(pipefd[0], user, strlen(s) + 1);
36 | if (strcmp(user, e))
37 | {
38 | ft_result_input_str(s, NULL);
39 | ft_result_output_str(user, e);
40 | ft_print_result(false);
41 | memset(user, 0, sizeof(user));
42 | close(pipefd[0]);
43 | close(pipefd[1]);
44 | return (false);
45 | }
46 | memset(user, 0, sizeof(user));
47 | close(pipefd[0]);
48 | close(pipefd[1]);
49 | return (true);
50 | }
51 |
52 | bool ft_test_putendl_fd(char *name)
53 | {
54 | size_t i = 0, grade = 0;
55 |
56 | (void)name;
57 | while (g_str1_tests[i])
58 | {
59 | grade += ft_run_test((char *)g_str1_tests[i], (char *)g_eputendl[i]);
60 | i++;
61 | }
62 | return (grade == i);
63 | }
64 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_putnbr_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_putnbr_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:32:56 by juperez #+# #+# */
9 | /* Updated: 2024/05/21 19:19:52 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(char *n_str)
16 | {
17 | int n = atoi(n_str);
18 | int pipefd[2];
19 | char user[BUFFER_SIZE];
20 |
21 | memset(user, 0, sizeof(user));
22 | pipe(pipefd);
23 | ft_time_function(USER_START);
24 | ft_putnbr_fd(n, pipefd[1]);
25 | ft_time_function(USER_END);
26 | read(pipefd[0], user, strlen(n_str));
27 | if (strcmp(user, n_str))
28 | {
29 | ft_result_input_int(n);
30 | ft_result_output_str(user, n_str);
31 | ft_print_result(false);
32 | memset(user, 0, sizeof(user));
33 | close(pipefd[0]);
34 | close(pipefd[1]);
35 | return (false);
36 | }
37 | memset(user, 0, sizeof(user));
38 | close(pipefd[0]);
39 | close(pipefd[1]);
40 | return (true);
41 | }
42 |
43 | bool ft_test_putnbr_fd(char *name)
44 | {
45 | size_t i = 0, grade = 0;
46 |
47 | (void)name;
48 | while (g_nbr_tests[i])
49 | {
50 | grade += ft_run_test((char *)g_nbr_tests[i]);
51 | i++;
52 | }
53 | return (grade == i);
54 | }
--------------------------------------------------------------------------------
/srcs/tests/ft_test_putstr_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_putstr_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:32:29 by juperez #+# #+# */
9 | /* Updated: 2024/05/21 19:06:14 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(char *s)
16 | {
17 | int pipefd[2];
18 | char user[BUFFER_SIZE];
19 |
20 | memset(user, 0, sizeof(user));
21 | pipe(pipefd);
22 | ft_time_function(USER_START);
23 | ft_putstr_fd(s, pipefd[1]);
24 | ft_time_function(USER_END);
25 | read(pipefd[0], user, strlen(s));
26 | if (strcmp(user, s))
27 | {
28 | ft_result_input_str(s, NULL);
29 | ft_result_output_str(user, s);
30 | ft_print_result(false);
31 | memset(user, 0, sizeof(user));
32 | close(pipefd[0]);
33 | close(pipefd[1]);
34 | return (false);
35 | }
36 | memset(user, 0, sizeof(user));
37 | close(pipefd[0]);
38 | close(pipefd[1]);
39 | return (true);
40 | }
41 |
42 | bool ft_test_putstr_fd(char *name)
43 | {
44 | size_t i = 0, grade = 0;
45 |
46 | (void)name;
47 | while (g_str1_tests[i])
48 | {
49 | grade += ft_run_test((char *)g_str1_tests[i]);
50 | i++;
51 | }
52 | return (grade == i);
53 | }
54 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_split.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_split.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:31:37 by juperez #+# #+# */
9 | /* Updated: 2024/03/31 13:25:18 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_split_str[] = {
16 | " Hello World ! ",
17 | " 42 ",
18 | "42",
19 | " ",
20 | "",
21 | "a b c d e f",
22 | "abc def",
23 | NULL
24 | };
25 |
26 | const char *g_esplit[][7] = {
27 | {"Hello", "World", "!", NULL},
28 | {"42", NULL},
29 | {"42", NULL},
30 | {NULL},
31 | {NULL},
32 | {"a", "b", "c", "d", "e", "f", NULL},
33 | {"abc", "def", NULL}
34 | };
35 |
36 | static void ft_free(char **user)
37 | {
38 | for (size_t i = 0; user[i]; i++)
39 | free(user[i]);
40 | free(user);
41 | }
42 |
43 | static bool ft_check_result(char **user, char **e)
44 | {
45 | for (size_t i = 0; e[i]; i++)
46 | {
47 | if (e[i] && !user[i])
48 | return (false);
49 | if (!e[i] && user[i])
50 | return (false);
51 | if (e[i] && user[i] && strcmp(user[i], e[i]))
52 | return (false);
53 | }
54 | return (true);
55 | }
56 |
57 | static bool ft_run_test(char const *s, char c, char **e)
58 | {
59 | char **user;
60 |
61 | ft_time_function(USER_START);
62 | user = ft_split(s, c);
63 | ft_time_function(USER_END);
64 | if (!ft_check_result(user, e))
65 | {
66 | ft_result_input_str((char *)s, NULL);
67 | ft_result_input_chr(c);
68 | ft_result_output_tabstr(user, e);
69 | ft_print_result(false);
70 | ft_free(user);
71 | return (false);
72 | }
73 | ft_free(user);
74 | return (true);
75 | }
76 |
77 | bool ft_test_split(char *name)
78 | {
79 | size_t i = 0, grade = 0;
80 |
81 | (void)name;
82 | while (g_split_str[i])
83 | {
84 | grade += ft_run_test(g_split_str[i], ' ', (char **)g_esplit[i]);
85 | i++;
86 | }
87 | return (grade == i);
88 | }
89 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strchr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strchr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:26:37 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:48 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *s, int c)
16 | {
17 | char *user, *libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_strchr(s, c);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = strchr(s, c);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_str((char *)s, NULL);
27 | ft_result_input_int(c);
28 | ft_result_output_str(user, libc);
29 | ft_print_result(true);
30 | return (false);
31 | }
32 | return (true);
33 | }
34 |
35 | bool ft_test_strchr(char *name)
36 | {
37 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1;
38 |
39 | (void)name;
40 | while (i <= UCHAR_MAX + 1)
41 | {
42 | grade += ft_run_test(g_str1_tests[1], i);
43 | i++;
44 | }
45 | return (grade == i);
46 | }
47 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strdup.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strdup.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 09:49:04 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:49 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *s)
16 | {
17 | char *user, *libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_strdup(s);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = strdup(s);
23 | ft_time_function(LIBC_END);
24 | if (strcmp(user, libc))
25 | {
26 | ft_result_input_str((char *)s, NULL);
27 | ft_result_output_str(user, libc);
28 | ft_print_result(true);
29 | free(user);
30 | free(libc);
31 | return (false);
32 | }
33 | free(user);
34 | free(libc);
35 | return (true);
36 | }
37 |
38 | bool ft_test_strdup(char *name)
39 | {
40 | size_t i = 0, grade = 0;
41 |
42 | (void)name;
43 | while (g_str1_tests[i])
44 | {
45 | grade += ft_run_test(g_str1_tests[i]);
46 | i++;
47 | }
48 | return (grade == i);
49 | }
50 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_striteri.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_striteri.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:32:05 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 01:22:56 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | char *g_striteri_str[] = {
16 | "helLO WorlD!",
17 | "abcdefghijklMNOpqrstuvwXYZ",
18 | "42",
19 | "",
20 | NULL
21 | };
22 |
23 | const char *g_estriteri[] = {
24 | "Hello world!",
25 | "Abcdefghijklmnopqrstuvwxyz",
26 | "42",
27 | "",
28 | NULL
29 | };
30 |
31 | static void ft_test_function(unsigned int i, char *s)
32 | {
33 | *s = i ? tolower(*s) : toupper(*s);
34 | }
35 |
36 | static bool ft_run_test(char *s, void (*f)(unsigned int, char *), char *e)
37 | {
38 | char *user;
39 |
40 | user = strdup(s);
41 | ft_time_function(USER_START);
42 | ft_striteri(user, f);
43 | ft_time_function(USER_END);
44 | if (strcmp(user, e))
45 | {
46 | ft_result_input_str(s, NULL);
47 | ft_result_output_str(user, e);
48 | ft_print_result(false);
49 | free(user);
50 | return (false);
51 | }
52 | free(user);
53 | return (true);
54 | }
55 |
56 | bool ft_test_striteri(char *name)
57 | {
58 | size_t i = 0, grade = 0;
59 |
60 | (void)name;
61 | while (g_striteri_str[i])
62 | {
63 | grade += ft_run_test(g_striteri_str[i], ft_test_function, (char *)g_estriteri[i]);
64 | i++;
65 | }
66 | return (grade == i);
67 | }
68 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strjoin.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strjoin.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:31:09 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 01:22:40 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_strjoin_s1[] = {
16 | "Hello",
17 | "4",
18 | "",
19 | "abc",
20 | "",
21 | NULL
22 | };
23 |
24 | const char *g_strjoin_s2[] = {
25 | " World!",
26 | "2",
27 | "",
28 | "",
29 | "abc",
30 | NULL
31 | };
32 |
33 | const char *g_estrjoin[] = {
34 | "Hello World!",
35 | "42",
36 | "",
37 | "abc",
38 | "abc",
39 | NULL
40 | };
41 |
42 | static bool ft_run_test(char const *s1, char const *s2, char *e)
43 | {
44 | char *user;
45 |
46 | ft_time_function(USER_START);
47 | user = ft_strjoin(s1, s2);
48 | ft_time_function(USER_END);
49 | if (strcmp(user, e))
50 | {
51 | ft_result_input_str((char *)s1, (char *)s2);
52 | ft_result_output_str(user, e);
53 | ft_print_result(false);
54 | free(user);
55 | return (false);
56 | }
57 | free(user);
58 | return (true);
59 | }
60 |
61 | bool ft_test_strjoin(char *name)
62 | {
63 | size_t i = 0, grade = 0;
64 |
65 | (void)name;
66 | while (g_strjoin_s1[i])
67 | {
68 | grade += ft_run_test(g_strjoin_s1[i], g_strjoin_s2[i], (char *)g_estrjoin[i]);
69 | i++;
70 | }
71 | return (grade == i);
72 | }
73 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strlcat.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strlcat.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 08:48:30 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:50 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *src, size_t size)
16 | {
17 | char user_dst[] = "DEST\0............................";
18 | char libc_dst[] = "DEST\0............................";
19 | size_t user, libc;
20 |
21 | ft_time_function(USER_START);
22 | user = ft_strlcat(user_dst, src, size);
23 | ft_time_function(USER_END_LIBC_START);
24 | libc = strlcat(libc_dst, src, size);
25 | ft_time_function(LIBC_END);
26 | if (strcmp(user_dst, libc_dst) && !(user == libc))
27 | {
28 | ft_result_input_sizet(size);
29 | ft_result_input_str((char *)src, NULL);
30 | ft_result_output_sizet(user, libc);
31 | ft_result_output_str(user_dst, libc_dst);
32 | ft_print_result(true);
33 | return (false);
34 | }
35 | return (true);
36 | }
37 |
38 | bool ft_test_strlcat(char *name)
39 | {
40 | size_t size[] = {0, 1, 2, 4, 8, 16, 32};
41 | size_t i = 0, grade = 0, count = sizeof(size) / sizeof(size[0]);
42 |
43 | (void)name;
44 | while (i < count)
45 | {
46 | grade += ft_run_test(g_str1_tests[1], size[i]);
47 | i++;
48 | }
49 | return (grade == i);
50 | }
51 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strlcpy.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strlcpy.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:25:46 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:52 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *src, size_t size)
16 | {
17 | char user_dst[] = "................";
18 | char libc_dst[] = "................";
19 | size_t user, libc;
20 |
21 | ft_time_function(USER_START);
22 | user = ft_strlcpy(user_dst, src, size);
23 | ft_time_function(USER_END_LIBC_START);
24 | libc = strlcpy(libc_dst, src, size);
25 | ft_time_function(LIBC_END);
26 | if (strcmp(user_dst, libc_dst) && !(user == libc))
27 | {
28 | ft_result_input_sizet(size);
29 | ft_result_input_str((char *)src, NULL);
30 | ft_result_output_sizet(user, libc);
31 | ft_result_output_str(user_dst, libc_dst);
32 | ft_print_result(true);
33 | return (false);
34 | }
35 | return (true);
36 | }
37 |
38 | bool ft_test_strlcpy(char *name)
39 | {
40 | size_t i = 0, grade = 0;
41 |
42 | (void)name;
43 | while (i < 16)
44 | {
45 | grade += ft_run_test(g_str1_tests[1], i);
46 | i++;
47 | }
48 | return (grade == i);
49 | }
50 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strlen.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strlen.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 09:42:04 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:53 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *s)
16 | {
17 | size_t user, libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_strlen(s);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = strlen(s);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_str((char *)s, NULL);
27 | ft_result_output_sizet(user, libc);
28 | ft_print_result(true);
29 | return (false);
30 | }
31 | return (true);
32 | }
33 |
34 | bool ft_test_strlen(char *name)
35 | {
36 | size_t i = 0, grade = 0;
37 |
38 | (void)name;
39 | while (g_str1_tests[i])
40 | {
41 | grade += ft_run_test(g_str1_tests[i]);
42 | i++;
43 | }
44 | return (grade == i);
45 | }
46 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strmapi.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strmapi.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:31:51 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 01:22:26 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_strmapi_str[] = {
16 | "helLO WorlD!",
17 | "abcdefghijklMNOpqrstuvwXYZ",
18 | "42",
19 | "",
20 | NULL
21 | };
22 |
23 | const char *g_estrmapi[] = {
24 | "Hello world!",
25 | "Abcdefghijklmnopqrstuvwxyz",
26 | "42",
27 | "",
28 | NULL
29 | };
30 |
31 | static char ft_test_function(unsigned int i, char c)
32 | {
33 | return (i ? tolower(c) : toupper(c));
34 | }
35 |
36 | static bool ft_run_test(char const *s, char (*f)(unsigned int, char), char *e)
37 | {
38 | char *user;
39 |
40 | ft_time_function(USER_START);
41 | user = ft_strmapi(s, f);
42 | ft_time_function(USER_END);
43 | if (strcmp(user, e))
44 | {
45 | ft_result_input_str((char *)s, NULL);
46 | ft_result_output_str(user, e);
47 | ft_print_result(false);
48 | free(user);
49 | return (false);
50 | }
51 | free(user);
52 | return (true);
53 | }
54 |
55 | bool ft_test_strmapi(char *name)
56 | {
57 | size_t i = 0, grade = 0;
58 |
59 | (void)name;
60 | while (g_strmapi_str[i])
61 | {
62 | grade += ft_run_test(g_strmapi_str[i], ft_test_function, (char *)g_estrmapi[i]);
63 | i++;
64 | }
65 | return (grade == i);
66 | }
67 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strncmp.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strncmp.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:27:51 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:54 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *s1, const char *s2, size_t n)
16 | {
17 | int user, libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_strncmp(s1, s2, n);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = strncmp(s1, s2, n);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_sizet(n);
27 | ft_result_input_str((char *)s1, (char *)s2);
28 | ft_result_output_int(user, libc);
29 | ft_print_result(true);
30 | return (false);
31 | }
32 | return (true);
33 | }
34 |
35 | static bool ft_test_size(const char *s1, const char *s2)
36 | {
37 | size_t i = 0, grade = 0;
38 |
39 | while (i < 30)
40 | {
41 | grade += ft_run_test(s1, s2, i);
42 | i++;
43 | }
44 | return (grade == i);
45 | }
46 |
47 | static bool ft_test_str2(const char *s1)
48 | {
49 | size_t i = 0, grade = 0;
50 |
51 | while (g_str2_tests[i])
52 | {
53 | grade += ft_test_size(s1, g_str2_tests[i]);
54 | i++;
55 | }
56 | return (grade == i);
57 | }
58 |
59 | bool ft_test_strncmp(char *name)
60 | {
61 | size_t i = 0, grade = 0;
62 |
63 | (void)name;
64 | while (g_str1_tests[i])
65 | {
66 | grade += ft_test_str2(g_str1_tests[i]);
67 | i++;
68 | }
69 | return (grade == i);
70 | }
71 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strnstr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strnstr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:30:29 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:56 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *str, const char *to_find, size_t len)
16 | {
17 | char *user, *libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_strnstr(str, to_find, len);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = strnstr(str, to_find, len);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_sizet(len);
27 | ft_result_input_str((char *)str, (char *)to_find);
28 | ft_result_output_str(user, libc);
29 | ft_print_result(true);
30 | return (false);
31 | }
32 | return (true);
33 | }
34 |
35 | static bool ft_test_size(const char *str, const char *to_find)
36 | {
37 | size_t i = 0, grade = 0;
38 |
39 | while (i < 30)
40 | {
41 | grade += ft_run_test(str, to_find, i);
42 | i++;
43 | }
44 | return (grade == i);
45 | }
46 |
47 | static bool ft_test_tofind(const char *str)
48 | {
49 | size_t i = 0, grade = 0;
50 |
51 | while (g_str2_tests[i])
52 | {
53 | grade += ft_test_size(str, g_str2_tests[i]);
54 | i++;
55 | }
56 | return (grade == i);
57 | }
58 |
59 | bool ft_test_strnstr(char *name)
60 | {
61 | size_t i = 0, grade = 0;
62 |
63 | (void)name;
64 | while (g_str1_tests[i])
65 | {
66 | grade += ft_test_tofind(g_str1_tests[i]);
67 | i++;
68 | }
69 | return (grade == i);
70 | }
71 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strrchr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strrchr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:27:27 by juperez #+# #+# */
9 | /* Updated: 2024/03/30 10:26:57 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_run_test(const char *s, int c)
16 | {
17 | char *user, *libc;
18 |
19 | ft_time_function(USER_START);
20 | user = ft_strrchr(s, c);
21 | ft_time_function(USER_END_LIBC_START);
22 | libc = strrchr(s, c);
23 | ft_time_function(LIBC_END);
24 | if (!(user == libc))
25 | {
26 | ft_result_input_str((char *)s, NULL);
27 | ft_result_input_int(c);
28 | ft_result_output_str(user, libc);
29 | ft_print_result(true);
30 | return (true);
31 | }
32 | return (true);
33 | }
34 |
35 | bool ft_test_strrchr(char *name)
36 | {
37 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1;
38 |
39 | (void)name;
40 | while (i <= UCHAR_MAX + 1)
41 | {
42 | grade += ft_run_test(g_str1_tests[1], i);
43 | i++;
44 | }
45 | return (grade == i);
46 | }
47 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_strtrim.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_strtrim.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:31:22 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 01:22:12 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_strtrim_s1[] = {
16 | " Hello World! ",
17 | "eeeHello World!ooo",
18 | "Hello World!ooo",
19 | "eeeHello World!",
20 | "42",
21 | "",
22 | NULL
23 | };
24 |
25 | const char *g_strtrim_set[] = {
26 | " ",
27 | "eo",
28 | "eo",
29 | "eo",
30 | "",
31 | "42",
32 | NULL
33 | };
34 |
35 | const char *g_estrtrim[] = {
36 | "Hello World!",
37 | "Hello World!",
38 | "Hello World!",
39 | "Hello World!",
40 | "42",
41 | "",
42 | NULL
43 | };
44 |
45 | static bool ft_run_test(char const *s1, char const *set, char *e)
46 | {
47 | char *user;
48 |
49 | ft_time_function(USER_START);
50 | user = ft_strtrim(s1, set);
51 | ft_time_function(USER_END);
52 | if (strcmp(user, e))
53 | {
54 | ft_result_input_str((char *)s1, (char *)set);
55 | ft_result_output_str(user, e);
56 | ft_print_result(false);
57 | free(user);
58 | return (false);
59 | }
60 | free(user);
61 | return (true);
62 | }
63 |
64 | bool ft_test_strtrim(char *name)
65 | {
66 | size_t i = 0, grade = 0;
67 |
68 | (void)name;
69 | while (g_strtrim_s1[i])
70 | {
71 | grade += ft_run_test(g_strtrim_s1[i], g_strtrim_set[i], (char *)g_estrtrim[i]);
72 | i++;
73 | }
74 | return (grade == i);
75 | }
76 |
--------------------------------------------------------------------------------
/srcs/tests/ft_test_substr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_test_substr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/27 09:30:55 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 01:22:06 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | const char *g_esubstr[] = {
16 | "Hello",
17 | "Hello World!",
18 | "World!",
19 | "World!",
20 | "!",
21 | " ",
22 | "",
23 | NULL,
24 | };
25 |
26 | static bool ft_run_test(char const *s, unsigned int start, size_t len, char *e)
27 | {
28 | char *user;
29 |
30 | ft_time_function(USER_START);
31 | user = ft_substr(s, start, len);
32 | ft_time_function(USER_END);
33 | if (strcmp(user, e))
34 | {
35 | ft_result_input_str((char *)s, NULL);
36 | ft_result_input_int((int)start);
37 | ft_result_input_sizet(len);
38 | ft_result_output_str(user, e);
39 | ft_print_result(false);
40 | free(user);
41 | return (false);
42 | }
43 | free(user);
44 | return (true);
45 | }
46 |
47 | bool ft_test_substr(char *name)
48 | {
49 | unsigned int start[] = {0, 0, 6, 6, 11, 5, 0};
50 | size_t len[] = {5, 15, 6, 15, 1, 1, 0};
51 | size_t i = 0, grade = 0;
52 |
53 | (void)name;
54 | while (g_esubstr[i])
55 | {
56 | grade += ft_run_test(g_str1_tests[1], start[i], len[i], (char *)g_esubstr[i]);
57 | i++;
58 | }
59 | return (grade == i);
60 | }
61 |
--------------------------------------------------------------------------------
/srcs/utils/ft_print_test.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_print_test.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/18 09:19:55 by juperez #+# #+# */
9 | /* Updated: 2024/03/31 12:30:53 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static void ft_putchar_isprint(char c)
16 | {
17 | printf("%s'", DM);
18 | if (isprint(c))
19 | printf("%c", c);
20 | else
21 | printf("\\%02x", (unsigned char)c);
22 | printf("'%s ", X);
23 | }
24 |
25 | static void ft_putstr_isprint(char *str)
26 | {
27 | if (!str)
28 | printf("%sNULL%s ", DM, X);
29 | else
30 | {
31 | printf("%s\"", DM);
32 | while (*str)
33 | {
34 | if (isprint(*str))
35 | printf("%c", *str);
36 | else
37 | printf("\\%02x", (unsigned char)*str);
38 | str++;
39 | }
40 | printf("\"%s ", X);
41 | }
42 | }
43 |
44 | static void ft_puttabstr(char **str)
45 | {
46 | if (!*str)
47 | ft_putstr_isprint(*str);
48 | else
49 | {
50 | for (size_t i = 0; str[i]; i++)
51 | {
52 | ft_putstr_isprint(str[i]);
53 | printf(" ");
54 | }
55 | }
56 | }
57 |
58 | static void ft_print_intput(void)
59 | {
60 | printf("%s", INPUT);
61 | if (g_presult.input_int)
62 | printf("%s%i%s ", DM, g_result.input_int, X);
63 | if (g_presult.input_sizet)
64 | printf("%s%zu%s ", DM, g_result.input_sizet, X);
65 | if (g_presult.input_chr)
66 | ft_putchar_isprint(g_result.input_chr);
67 | if (g_presult.input_str1)
68 | ft_putstr_isprint(g_result.input_str1);
69 | if (g_presult.input_str2)
70 | ft_putstr_isprint(g_result.input_str2);
71 | printf("\n");
72 | }
73 |
74 | static void ft_print_output_user(bool print_libc)
75 | {
76 | printf("%s%s%s", OUTPUT, USER, print_libc ? "" : " ");
77 | if (g_presult.output_int)
78 | printf("%s%i%s ", DM, g_result.user_int, X);
79 | if (g_presult.output_sizet)
80 | printf("%s%zu%s ", DM, g_result.user_sizet, X);
81 | if (g_presult.output_chr)
82 | ft_putchar_isprint(g_result.user_chr);
83 | if (g_presult.output_str)
84 | ft_putstr_isprint(g_result.user_str);
85 | if (g_presult.output_tabstr)
86 | ft_puttabstr(g_result.user_tabstr);
87 | }
88 |
89 | static void ft_print_output_libc(bool print_libc)
90 | {
91 | printf("\n\t\t %s", print_libc ? LIBC : EXPECT);
92 | if (g_presult.output_int)
93 | printf("%s%i%s ", DM, g_result.libc_int, X);
94 | if (g_presult.output_sizet)
95 | printf("%s%zu%s ", DM, g_result.libc_sizet, X);
96 | if (g_presult.output_chr)
97 | ft_putchar_isprint(g_result.libc_chr);
98 | if (g_presult.output_str)
99 | ft_putstr_isprint(g_result.libc_str);
100 | if (g_presult.output_tabstr)
101 | ft_puttabstr(g_result.libc_tabstr);
102 | }
103 |
104 | void ft_print_result(bool print_libc)
105 | {
106 | printf("%s%s", TEST, KO);
107 | ft_print_intput();
108 | ft_print_output_user(print_libc);
109 | ft_print_output_libc(print_libc);
110 | printf("\n");
111 | }
112 |
113 | void ft_reset_presult(void)
114 | {
115 | g_presult.input_int = false;
116 | g_presult.input_sizet = false;
117 | g_presult.input_chr = false;
118 | g_presult.input_str1 = false;
119 | g_presult.input_str2 = false;
120 | g_presult.output_int = false;
121 | g_presult.output_sizet = false;
122 | g_presult.output_chr = false;
123 | g_presult.output_str = false;
124 | g_presult.output_tabstr = false;
125 | }
126 |
127 | void ft_result_input_int(int intput)
128 | {
129 | g_result.input_int = intput;
130 | g_presult.input_int = true;
131 | }
132 |
133 | void ft_result_input_sizet(size_t intput)
134 | {
135 | g_result.input_sizet = intput;
136 | g_presult.input_sizet = true;
137 | }
138 |
139 | void ft_result_input_chr(char intput)
140 | {
141 | g_result.input_chr = intput;
142 | g_presult.input_chr = true;
143 | }
144 |
145 | void ft_result_input_str(char *str1, char *str2)
146 | {
147 | if (str1)
148 | {
149 | g_result.input_str1 = str1;
150 | g_presult.input_str1 = true;
151 | }
152 | if (str2)
153 | {
154 | g_result.input_str2 = str2;
155 | g_presult.input_str2 = true;
156 | }
157 | }
158 |
159 | void ft_result_output_int(int user, int libc)
160 | {
161 | g_result.user_int = user;
162 | g_result.libc_int = libc;
163 | g_presult.output_int = true;
164 | }
165 |
166 | void ft_result_output_sizet(size_t user, size_t libc)
167 | {
168 | g_result.user_sizet = user;
169 | g_result.libc_sizet = libc;
170 | g_presult.output_sizet = true;
171 | }
172 |
173 | void ft_result_output_chr(char user, char libc)
174 | {
175 | g_result.user_chr = user;
176 | g_result.libc_chr = libc;
177 | g_presult.output_chr = true;
178 | }
179 |
180 | void ft_result_output_str(char *user, char *libc)
181 | {
182 | g_result.user_str = user;
183 | g_result.libc_str = libc;
184 | g_presult.output_str = true;
185 | }
186 |
187 | void ft_result_output_tabstr(char **user, char **libc)
188 | {
189 | g_result.user_tabstr = user;
190 | g_result.libc_tabstr = libc;
191 | g_presult.output_tabstr = true;
192 | }
193 |
194 | void ft_grade(bool success)
195 | {
196 | if (success)
197 | {
198 | printf("%s%s", TEST, OK);
199 | ft_time_function(PRINT);
200 | }
201 | printf("%s%s", GRADE, success ? SUCCESS : FAIL);
202 | }
203 |
--------------------------------------------------------------------------------
/srcs/utils/ft_utils.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_utils.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: juperez +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2024/03/15 08:26:25 by juperez #+# #+# */
9 | /* Updated: 2024/05/22 15:45:35 by juperez ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libtest.h"
14 |
15 | static bool ft_build_cmd(char *target, size_t len, char *cmd_start, char *cmd_end)
16 | {
17 | char *cmd;
18 | size_t cmd_len;
19 | bool success;
20 |
21 | cmd = NULL;
22 | cmd_len = strlen(cmd_start) + len + strlen(cmd_end);
23 | success = false;
24 | cmd = (char *)malloc(sizeof(char) * cmd_len + 1);
25 | if (!cmd)
26 | {
27 | fprintf(stderr, ERROR_MEM);
28 | exit(EXIT_FAILURE);
29 | }
30 | cmd[cmd_len] = '\0';
31 | snprintf(cmd, cmd_len + 1, "%s%s%s", cmd_start, target, cmd_end);
32 | success = (system(cmd));
33 | free(cmd);
34 | return (success);
35 | }
36 |
37 | void ft_print_name(char *name)
38 | {
39 | int len;
40 | int space;
41 |
42 | len = strlen(name);
43 | space = (SIZE_LINE - len - 2) / 2;
44 | printf("%.*s %s%s%s%s %.*s\n", space, LINE, B, BD, name, X, SIZE_LINE - space - len, LINE);
45 | }
46 |
47 | void ft_print_file(char *path)
48 | {
49 | FILE *file;
50 | char buffer[BUFFER_SIZE];
51 | size_t read;
52 |
53 | file = fopen(path, "r");
54 | if (!file)
55 | return ;
56 | while ((read = fread(buffer, 1, BUFFER_SIZE, file)) > 0)
57 | fwrite(buffer, 1, read, stdout);
58 | fclose(file);
59 | }
60 |
61 | bool ft_test_norminette(char *name)
62 | {
63 | size_t len;
64 | bool success;
65 | bool version_last = (system(CMD_NV));
66 |
67 | len = strlen(name);
68 | success = ft_build_cmd(name, len, CMD_NS, CMD_NE);
69 | success = !version_last ? success ? false : true : success;
70 | printf("%s%s", NORME, success ? OK : ERROR);
71 | if (!success)
72 | printf("%s%s", GRADE, FAIL);
73 | return (success);
74 | }
75 |
76 | bool ft_check_sysfunc(char *name)
77 | {
78 | bool success;
79 |
80 | success = ft_build_cmd(name, strlen(name), CMD_CS, CMD_CE);
81 | printf("%s%s", FOR_FUNC, success ? OK : CHEAT);
82 | if (!success)
83 | printf("%s%s", GRADE, GRADE_CHEAT);
84 | return (success);
85 | }
86 |
87 | void ft_time_function(t_ftime action)
88 | {
89 | static bool print_libc;
90 | static clock_t user_start, libc_start;
91 | static double user_time, libc_time;
92 |
93 | if (action == USER_END_LIBC_START)
94 | print_libc = true;
95 | else if (action == USER_END)
96 | print_libc = false;
97 | if (action == RESET)
98 | {
99 | user_time = 0;
100 | libc_time = 0;
101 | }
102 | if (action == USER_START)
103 | user_start = clock();
104 | if ((action == USER_END) || (action == USER_END_LIBC_START))
105 | user_time += ((double)(clock() - user_start)) / CLOCKS_PER_SEC;
106 | if ((action == LIBC_START) || (action == USER_END_LIBC_START))
107 | libc_start = clock();
108 | if (action == LIBC_END)
109 | libc_time += ((double)(clock() - libc_start)) / CLOCKS_PER_SEC;
110 | if (action == PRINT)
111 | {
112 | printf("%s%s%s%fs%s", TIME, USER, DM, user_time, X);
113 | if (print_libc)
114 | printf(" | %s%s%fs%s", LIBC, DM, libc_time, X);
115 | printf("\n");
116 | user_time = 0;
117 | libc_time = 0;
118 | }
119 | }
120 |
121 | void ft_free_lst(t_list *lst)
122 | {
123 | t_list *tmp;
124 |
125 | while (lst)
126 | {
127 | tmp = lst->next;
128 | free(lst);
129 | lst = tmp;
130 | }
131 | }
132 |
133 | size_t ft_lst_size(t_list *lst)
134 | {
135 | size_t size = 0;
136 |
137 | while (lst)
138 | {
139 | lst = lst->next;
140 | size++;
141 | }
142 | return (size);
143 | }
144 |
145 | void ft_test_free(void *ptr)
146 | {
147 | free(ptr);
148 | g_node_freed = 1;
149 | }
150 |
151 | void ft_strtoupper(void *ptr)
152 | {
153 | char *str = (char *)ptr;
154 |
155 | for (size_t i = 0; str[i]; i++)
156 | str[i] = toupper(str[i]);
157 | }
158 |
159 | void *ft_duptoupper(void *ptr)
160 | {
161 | char *str = strdup((char *)ptr);
162 |
163 | for (size_t i = 0; str[i]; i++)
164 | str[i] = toupper(str[i]);
165 | return ((void *)str);
166 | }
--------------------------------------------------------------------------------