-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
306 lines (278 loc) · 10.2 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlechapt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/08 18:23:08 by rlechapt #+# #+# */
/* Updated: 2015/04/01 05:33:39 by rlechapt ### ########.fr */
/* */
/* ************************************************************************** */
#include "libfts.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
void check_alnum(void)
{
printf("[-] ALNUM [-]\n");
printf("[+] Test on %c, return = %d [+]\n", 'a', ft_isalnum('a'));
printf("[+] Test on %c, return = %d [+]\n", 'z', ft_isalnum('z'));
printf("[+] Test on %c, return = %d [+]\n", '*', ft_isalnum('*'));
printf("[+] Test on %c, return = %d [+]\n", 'Z', ft_isalnum('Z'));
printf("[+] Test on %c, return = %d [+]\n", 'A', ft_isalnum('A'));
printf("[+] Test on %c, return = %d [+]\n", '0', ft_isalnum('0'));
printf("[+] Test on %c, return = %d [+]\n", '9', ft_isalnum('9'));
printf("[+] Test on %c, return = %d [+]\n", '4', ft_isalnum('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isalnum(0));
printf("[-] END OF ALNUM [-]\n");
}
void check_digit(void)
{
printf("[-] DIGIT [-]\n");
printf("[+] Test on %c, return = %d [+]\n", 'a', ft_isdigit('a'));
printf("[+] Test on %c, return = %d [+]\n", 'z', ft_isdigit('z'));
printf("[+] Test on %c, return = %d [+]\n", '*', ft_isdigit('*'));
printf("[+] Test on %c, return = %d [+]\n", 'Z', ft_isdigit('Z'));
printf("[+] Test on %c, return = %d [+]\n", 'A', ft_isdigit('A'));
printf("[+] Test on %c, return = %d [+]\n", '0', ft_isdigit('0'));
printf("[+] Test on %c, return = %d [+]\n", '9', ft_isdigit('9'));
printf("[+] Test on %c, return = %d [+]\n", '4', ft_isdigit('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isdigit(0));
printf("[-] END OF DIGIT [-]\n");
}
void check_alpha(void)
{
printf("[-] ALPHA [-]\n");
printf("[+] Test on %c, return = %d [+]\n", 'a', ft_isalpha('a'));
printf("[+] Test on %c, return = %d [+]\n", 'z', ft_isalpha('z'));
printf("[+] Test on %c, return = %d [+]\n", '*', ft_isalpha('*'));
printf("[+] Test on %c, return = %d [+]\n", 'Z', ft_isalpha('Z'));
printf("[+] Test on %c, return = %d [+]\n", 'A', ft_isalpha('A'));
printf("[+] Test on %c, return = %d [+]\n", '0', ft_isalpha('0'));
printf("[+] Test on %c, return = %d [+]\n", '9', ft_isalpha('9'));
printf("[+] Test on %c, return = %d [+]\n", '4', ft_isalpha('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isalpha(0));
printf("[-] END OF ALPHA [-]\n");
}
void check_tolower(void)
{
printf("[-] TOLOWER [-]\n");
printf("[+] Test on %c, return = %c [+]\n", 'a', ft_tolower('a'));
printf("[+] Test on %c, return = %c [+]\n", 'z', ft_tolower('z'));
printf("[+] Test on %c, return = %c [+]\n", '*', ft_tolower('*'));
printf("[+] Test on %c, return = %c [+]\n", 'Z', ft_tolower('Z'));
printf("[+] Test on %c, return = %c [+]\n", 'A', ft_tolower('A'));
printf("[+] Test on %c, return = %c [+]\n", '0', ft_tolower('0'));
printf("[+] Test on %c, return = %c [+]\n", '9', ft_tolower('9'));
printf("[+] Test on %c, return = %c [+]\n", '4', ft_tolower('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %c [+]\n", ft_tolower(0));
printf("[-] END OF TOLOWER [-]\n");
}
void check_toupper(void)
{
printf("[-] TOUPPER [-]\n");
printf("[+] Test on %c, return = %c [+]\n", 'a', ft_toupper('a'));
printf("[+] Test on %c, return = %c [+]\n", 'z', ft_toupper('z'));
printf("[+] Test on %c, return = %c [+]\n", '*', ft_toupper('*'));
printf("[+] Test on %c, return = %c [+]\n", 'Z', ft_toupper('Z'));
printf("[+] Test on %c, return = %c [+]\n", 'A', ft_toupper('A'));
printf("[+] Test on %c, return = %c [+]\n", '0', ft_toupper('0'));
printf("[+] Test on %c, return = %c [+]\n", '9', ft_toupper('9'));
printf("[+] Test on %c, return = %c [+]\n", '4', ft_toupper('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %c [+]\n", ft_toupper(0));
printf("[-] END OF TOUPPER [-]\n");
}
void check_isascii(void)
{
printf("[-] ISASCII [-]\n");
printf("[+] Test on %c : %d, return = %d [+]\n", 'a', 'a', ft_isascii('a'));
printf("[+] Test on %c : %d, return = %d [+]\n", 'z', 'z', ft_isascii('z'));
printf("[+] Test on %c : %d, return = %d [+]\n", 'A', 'A', ft_isascii('A'));
printf("[+] Test on %c : %d, return = %d [+]\n", 'Z', 'Z', ft_isascii('Z'));
printf("[+] Test on %c : %d, return = %d [+]\n", 245, 245, ft_isascii(245));
printf("[+] Test on %c : %d, return = %d [+]\n", 221, 221, ft_isascii(221));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isascii(0));
printf("[-] END OF ISASCII [-]\n");
}
void check_strlen(void)
{
char str[5] = "abcd";
char str2[3] = "op";
printf("[+] STRLEN [+]\n");
printf("[-] %s, sized: %d [-]\n", str, (int)ft_strlen(str));
printf("[-] %s, sized: %d [-]\n", str2, (int)ft_strlen(str2));
printf("[-] Test with NULL [-]\n");
printf("[-] sized: %d [-]\n", (int)ft_strlen(0));
printf("[+] END OF STRLEN [+]\n");
}
void check_puts(void)
{
printf("[+] PUTS [+]\n");
ft_puts("[-] a [-]");
ft_puts("[-] $#@#',./,~!@~=+ [-]");
printf("[+] Test with null [+]\n");
ft_puts(NULL);
printf("[+] END OF PUTS [+]\n");
}
void check_strcat(void)
{
char str[5];
str[0] = '\0';
printf("[+] STRCAT [+]\n");
printf("[-] Str init with empy char : %s [-]\n", ft_strcat(str, ""));
printf("[-] Str: %s [-]\n", ft_strcat(str, "h"));
printf("[-] Str: %s [-]\n", ft_strcat(str, "ello"));
printf("[-] Str: %s [-]\n", ft_strcat(str, "!"));
printf("[+] END OF STRCAT [+]\n");
}
void check_bzero(void)
{
char str[4] = "jui";
printf("[-] BZERO [-]\n");
printf("[+] str[0] = %d = %c [+]\n", str[0], str[0]);
printf("[+] str[1] = %d = %c [+]\n", str[1], str[1]);
printf("[+] str[2] = %d = %c [+]\n", str[2], str[2]);
printf("[-] FT_BZERO DONE [-]\n");
ft_bzero(str, 3);
printf("[+] str[0] = %d = %c [+]\n", str[0], str[0]);
printf("[+] str[1] = %d = %c [+]\n", str[1], str[1]);
printf("[+] str[2] = %d = %c [+]\n", str[2], str[2]);
printf("[-] Test with NULL [-]\n");
ft_bzero(NULL, 0);
printf("[-] END OF BZERO [-]\n");
}
void check_memset(void)
{
printf("[+] MEMSET [+]\n");
printf("[-] Befor memset: %s [-]\n", "abcd");
printf("[-] After memset: %s [-]\n", (char*)ft_memset(ft_strdup("abcd"),
'A', 3));
printf("[+] END OF MEMSET [+]\n");
}
void check_memcpy(void)
{
char str[2];
char str2[6];
ft_bzero(str, 2);
ft_bzero(str2, 6);
printf("[+] MEMCPY [+]\n");
printf("[-] Str1 size: %d, Content: %s [-]\n", (int)ft_strlen(str), str);
printf("[-] Str2 size: %d, Content: %s [-]\n", (int)ft_strlen(str2), str2);
ft_memcpy((void*)str, (void*)"a", 1);
ft_memcpy((void*)str2, (void*)"hello", 5);
printf("[+] Using ft_memcpy [+]\n");
printf("[-] Str1 size: %d, Content: %s [-]\n", (int)ft_strlen(str), str);
printf("[-] Str2 size: %d, Content: %s [-]\n", (int)ft_strlen(str2), str2);
printf("[+] END OF MEMCPY [+]\n");
}
void check_strdup(void)
{
char *str;
char f[] = "h";
char s[] = "hello";
char t[] = "";
printf("[+] STRDUP [+]\n");
printf("[-] Str init [-]\n");
str = ft_strdup(f);
printf("[-] Str after strdup (\"%s\") %d [-]\n", str, (int)ft_strlen(str));
str = ft_strdup(s);
printf("[-] Str after strdup (\"%s\") %d [-]\n", str, (int)ft_strlen(str));
str = ft_strdup(t);
printf("[-] Str after strdup (\"%s\") %d [-]\n", str, (int)ft_strlen(str));
printf("[+] END OF STRDUP [+]\n");
}
void check_cat(void)
{
int i;
i = open("ft_cat.s", O_RDONLY);
printf("[+] CAT [+]\n");
printf("[-] File for cat : ft_cat.s\n");
printf("[-] Cat for file : \n");
ft_cat(i);
close(i);
printf("\n[+] END OF CAT [+]\n");
}
void check_strcpy(void)
{
char src[] = "salut";
char dst[] = "cava?";
char *str;
printf("[+] STRCPY [+]\n");
printf("[-] Dst after strcpy [-]\n");
printf("[-] Dst: %s [-]\n", ft_strcpy((void*)dst, (void*)src));
printf("[+] END OF STRCPY [+]\n");
}
void check_isspace(void)
{
printf("[-] ISSPACE [-]\n");
printf("[+] Test on %c, return = %d [+]\n", 'a', ft_isspace('a'));
printf("[+] Test on %c, return = %d [+]\n", 'Z', ft_isspace('Z'));
printf("[+] Test on %c, return = %d [+]\n", '*', ft_isspace('*'));
printf("[+] Test on %c, return = %d [+]\n", ' ', ft_isspace(' '));
printf("[+] Test on \\n, return = %d [+]\n", ft_isspace('\n'));
printf("[+] Test on \\t, return = %d [+]\n", ft_isspace('\t'));
printf("[+] Test on \\v, return = %d [+]\n", ft_isspace('\v'));
printf("[+] Test on \\f, return = %d [+]\n", ft_isspace('\f'));
printf("[+] Test on \\r, return = %d [+]\n", ft_isspace('\r'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isspace(0));
printf("[-] END OF ISSPACE [-]\n");
}
void check_abs(void)
{
printf("[-] ABS [-]\n");
printf("[+] Test on %d, return = %d [+]\n", 0, ft_abs(0));
printf("[+] Test on %d, return = %d [+]\n", 1, ft_abs(1));
printf("[+] Test on %d, return = %d [+]\n", 10, ft_abs(10));
printf("[+] Test on %d, return = %d [+]\n", -1, ft_abs(-1));
printf("[+] Test on %d, return = %d [+]\n", -5, ft_abs(-5));
printf("[+] Test on %d, return = %d [+]\n", -20, ft_abs(-20));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_abs(0));
printf("[-] END OF ABS [-]\n");
}
int main(void)
{
check_digit();
printf("\n");
check_alpha();
printf("\n");
check_alnum();
printf("\n");
check_tolower();
printf("\n");
check_toupper();
printf("\n");
check_puts();
printf("\n");
check_isascii();
printf("\n");
check_bzero();
printf("\n");
check_strlen();
printf("\n");
check_strdup();
printf("\n");
check_memset();
printf("\n");
check_memcpy();
printf("\n");
check_strcat();
printf("\n");
check_cat();
printf("\n");
check_strcpy();
printf("\n");
check_isspace();
printf("\n");
check_abs();
printf("\n");
return 0;
}