-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
87 lines (80 loc) · 2.9 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/16 15:57:20 by apuchill #+# #+# */
/* Updated: 2021/03/06 11:32:21 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h"
void test_suit(char *ft_name, int total, int result)
{
printf("\n%s=> Tests %s: ", C_BOLD, ft_name);
if (result < total)
printf("%s%i failed%s, ",
C_ERROR, total - result, C_END);
if (result > 0)
printf("%s%i passed%s, ",
C_SUIT_OK, result, C_END);
printf("%i total\n", total);
}
void test_str(char *argv, int (*test)(char *), char *ft_name)
{
int total;
int result;
char long_str[1024];
print_ft_title(ft_name);
total = 7;
result = 0;
memset(long_str, '.', 1024);
long_str[1023] = '\0';
result += test("Hello, world!");
result += test("");
result += test(long_str);
result += test("Some special characters 你好世界!");
result += test("\ttabulation");
result += test("\0");
result += test("42\0this should not be here");
test_suit(ft_name, total, result);
if (!strcmp(argv, "all"))
print_continue();
}
static void print_welcome(char *argv)
{
char buff[1024];
printf("\nBienvenue !\n");
if (!strcmp(argv, "all"))
{
printf("%s\nPress ENTER to continue\n%s", C_WARNING, C_END);
read(0, buff, 1024);
}
}
int main(int argc, char *argv[])
{
if (argc == 2 && (!strcmp(argv[1], "all") ||
!strcmp(argv[1], "ft_read") || !strcmp(argv[1], "ft_write") ||
!strcmp(argv[1], "ft_strcpy") || !strcmp(argv[1], "ft_strcmp") ||
!strcmp(argv[1], "ft_strlen") || !strcmp(argv[1], "ft_strdup")))
{
print_welcome(argv[1]);
if (!strcmp(argv[1], "ft_strlen") || !strcmp(argv[1], "all"))
test_str(argv[1], test_strlen, "ft_strlen");
if (!strcmp(argv[1], "ft_strdup") || !strcmp(argv[1], "all"))
test_str(argv[1], test_strdup, "ft_strdup");
if (!strcmp(argv[1], "ft_strcpy") || !strcmp(argv[1], "all"))
test_str(argv[1], test_strcpy, "ft_strcpy");
if (!strcmp(argv[1], "ft_strcmp") || !strcmp(argv[1], "all"))
test_strcmp(argv[1]);
if (!strcmp(argv[1], "ft_write") || !strcmp(argv[1], "all"))
test_write(argv[1]);
if (!strcmp(argv[1], "ft_read") || !strcmp(argv[1], "all"))
test_read();
printf("\n");
}
else
printf("\n%sERROR:%s %s\n\n", C_ERROR, C_END, ERR_MSG);
return (0);
}