-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
452 lines (406 loc) · 16 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalliot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/16 19:19:02 by aalliot #+# #+# */
/* Updated: 2016/01/28 17:14:40 by alaulom ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/libfts.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
/* PART 1 */
void check_bzero(void)
{
char str[4] = "jui";
printf("[------] FT_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 FT_BZERO [------]\n");
}
void check_strcat(void)
{
char str[7];
str[0] = '\0';
bzero(str, 7);
printf("[------] FT_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 FT_STRCAT [------]\n");
}
void check_alpha(void)
{
printf("[------] FT_ISALPHA [------]\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 FT_ISALPHA [------]\n");
}
void check_digit(void)
{
printf("[------] FT_ISDIGIT [------]\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 FT_ISDIGIT [------]\n");
}
void check_alnum(void)
{
printf("[------] FT_ISALNUM [------]\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 FT_ISALNUM [-------]\n");
}
void check_isascii(void)
{
printf("[------] FT_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 FT_ISASCII [------]\n");
}
void check_isprint(void)
{
printf("[------] FT_ISPRINT [------]\n");
printf("[+] Test on %c : %d, return = %d [+]\n", 'a', 'a', ft_isprint('a'));
printf("[+] Test on %c : %d, return = %d [+]\n", 'z', 'z', ft_isprint('z'));
printf("[+] Test on %c : %d, return = %d [+]\n", 'A', 'A', ft_isprint('A'));
printf("[+] Test on %c : %d, return = %d [+]\n", 'Z', 'Z', ft_isprint('Z'));
printf("[+] Test on %c : %d, return = %d [+]\n", 245, 245, ft_isprint(245));
printf("[+] Test on %c : %d, return = %d [+]\n", 221, 221, ft_isprint(221));
printf("[+] Test on %c : %d, return = %d [+]\n", ' ', ' ', ft_isprint(' '));
printf("[+] Test on %c : %d, return = %d [+]\n", '+', '+', ft_isprint('+'));
printf("[+] Test on %c : %d, return = %d [+]\n", ')', ')', ft_isprint(')'));
printf("[+] Test on %c : %d, return = %d [+]\n", '>', '>', ft_isprint('>'));
printf("[+] Test on %c : %d, return = %d [+]\n", '\\', '\\', ft_isprint('\\'));
printf("[+] Test on del: %d, return = %d [+]\n", 177, ft_isprint(177));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isprint(0));
printf("[------] END OF FT_ISPRINT [------]\n");
}
void check_toupper(void)
{
printf("[------] FT_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 FT_TOUPPER [------]\n");
}
void check_tolower(void)
{
printf("[------] FT_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 FT_TOLOWER [------]\n");
}
void check_puts(void)
{
printf("[------] FT_PUTS [------]\n");
ft_puts("[+] a [+]");
ft_puts("[+] Zaz suce des poneys [+]");
ft_puts("[+] Ou plutot, les poneys sucent Zaz [+]");
ft_puts("[+] $#@#',./,~!@~=+ [+]");
printf("[-] Test with null [-]\n");
ft_puts(NULL);
printf("[------] END OF FT_PUTS [------]\n");
}
/* PART 2 */
void check_strlen(void)
{
char str[5] = "abcd";
char str2[3] = "op";
printf("[------] FT_STRLEN [------]\n");
printf("[+] %s, sized: %d [+]\n", str, (int)ft_strlen(str));
printf("[+] %s, sized: %d [+]\n", str2, (int)ft_strlen(str2));
if (strlen("djksajdklsajdklsajdklasjdklasjdklsajdklsajdklsajdklsajdklsajkldjsakldjsakldjsakldjklsajdsdhsadjhaskdhjkashdkjsahdahdkjshdkjashdkjashdkashdkjashdkjashdakjsdhaskdjhasdkjashdkajshdkajshdaksjdhsakjhdkjhasddjksajdklsajdklsajdklasjdklasjdklsajdklsajdklsajdklsajdklsajkldjsakldjsakldjsakldjklsajdsdhsadjhaskdhjkashdkjsahdahdkjshdkjashdkjashdkashdkjashdkjashdakjsdhaskdjhasdkjashdkajshdkajshdaksjdhsakjhdkjhasd") == ft_strlen("djksajdklsajdklsajdklasjdklasjdklsajdklsajdklsajdklsajdklsajkldjsakldjsakldjsakldjklsajdsdhsadjhaskdhjkashdkjsahdahdkjshdkjashdkjashdkashdkjashdkjashdakjsdhaskdjhasdkjashdkajshdkajshdaksjdhsakjhdkjhasddjksajdklsajdklsajdklasjdklasjdklsajdklsajdklsajdklsajdklsajkldjsakldjsakldjsakldjklsajdsdhsadjhaskdhjkashdkjsahdahdkjshdkjashdkjashdkashdkjashdkjashdakjsdhaskdjhasdkjashdkajshdkajshdaksjdhsakjhdkjhasd"))
puts("[+] Test long len OK. [+]");
else
puts("[+] Test long len DOWN! [+]");
if (ft_strlen("") == strlen(""))
puts("[+] Test empty string OK. [+]");
else
puts("[+] Test empty string DOWN! [+]");
printf("[+] Test with NULL [+]\n");
printf("[+] sized: %d [+]\n", (int)ft_strlen(0));
printf("[------] END OF FT_STRLEN [------]\n");
}
void check_memset(void)
{
printf("[------] FT_MEMSET [------]\n");
printf("[+] Before memset: %s [+]\n", "abcd");
printf("[+] After memset: %s [+]\n", (char*)ft_memset(ft_strdup("abcd"), 'A', 3));
printf("[------] END OF FT_MEMSET [------]\n");
}
void check_memcpy(void)
{
char str[2];
char str2[6];
ft_bzero(str, 2);
ft_bzero(str2, 6);
printf("[------] 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);
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("[-------] FT_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");
}
/* PART 3 */
void check_cat(void)
{
int fd;
fd = open("Makefile", O_RDONLY);
printf("[------] FT_CAT [------]\n");
printf("[------] Press Ctrl + D to Continue [------] \n");
ft_cat(0); // Ctrl + D to Continue !
ft_cat(open(__FILE__, O_RDONLY));
ft_cat(fd);
ft_cat(-42);
printf("[------] END OF FT_CAT [------]\n");
close(fd);
}
// /* BONUS */
//
void check_isspace(void)
{
printf("[------] FT_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 FT_ISSPACE [------]\n");
}
void check_isupper(void)
{
printf("[------] FT_ISUPPER [------]\n");
printf("[+] Test on %c, return = %d [+]\n", 'a', ft_isupper('a'));
printf("[+] Test on %c, return = %d [+]\n", 'z', ft_isupper('z'));
printf("[+] Test on %c, return = %d [+]\n", '*', ft_isupper('*'));
printf("[+] Test on %c, return = %d [+]\n", 'Z', ft_isupper('Z'));
printf("[+] Test on %c, return = %d [+]\n", 'A', ft_isupper('A'));
printf("[+] Test on %c, return = %d [+]\n", '0', ft_isupper('0'));
printf("[+] Test on %c, return = %d [+]\n", '9', ft_isupper('9'));
printf("[+] Test on %c, return = %d [+]\n", '4', ft_isupper('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_isupper(0));
printf("[------] END OF FT_ISUPPER [------]\n");
}
void check_islower(void)
{
printf("[------] FT_ISLOWER [------]\n");
printf("[+] Test on %c, return = %d [+]\n", 'a', ft_islower('a'));
printf("[+] Test on %c, return = %d [+]\n", 'z', ft_islower('z'));
printf("[+] Test on %c, return = %d [+]\n", '*', ft_islower('*'));
printf("[+] Test on %c, return = %d [+]\n", 'Z', ft_islower('Z'));
printf("[+] Test on %c, return = %d [+]\n", 'A', ft_islower('A'));
printf("[+] Test on %c, return = %d [+]\n", '0', ft_islower('0'));
printf("[+] Test on %c, return = %d [+]\n", '9', ft_islower('9'));
printf("[+] Test on %c, return = %d [+]\n", '4', ft_islower('4'));
printf("[-] Test with NULL [-]\n");
printf("[+] Test return = %d [+]\n", ft_islower(0));
printf("[------] END OF FT_ISLOWER [------]\n");
}
void check_putchar(void)
{
printf("[------] FT_PUTCHAR [------]\n");
ft_putchar('a');
ft_putchar('\n');
ft_putchar('b');
printf("\nDoit afficher : a\\nb\n");
printf("[------] END OF FT_PUTCHAR [------]\n");
}
/*void check_putchar_fd(void)
{
dprintf(2, "[------] FT_PUTCHAR_FD [------]\n");
ft_putchar_fd('a', 2);
ft_putchar_fd('\n', 2);
ft_putchar_fd('b', 2);
dprintf(2, "\nDoit afficher : a\\nb\n");
dprintf(2, "[------] END OF FT_PUTCHAR_FD [------]\n");
}
void check_puts_fd(void)
{
dprintf(2, "[------] FT_PUTS_FD [------]\n");
ft_puts_fd("[+] a [+]", 2);
ft_puts("[+] Zaz suce des poneys [+]");
ft_puts("[+] Ou plutot, les poneys sucent Zaz [+]");
ft_puts_fd("[+] $#@#',./,~!@~=+ [+]", 2);
dprintf(2, "[-] Test with null [-]\n");
ft_puts_fd(NULL, 2);
dprintf(2, "[------] END OF FT_PUTS_FD [------]\n");
}*/
void check_putstr(void)
{
printf("[------] FT_PUTSTR [------]\n");
ft_putstr("[+] a [+]\n");
ft_puts("[+] Zaz suce des poneys [+]");
ft_puts("[+] Ou plutot, les poneys sucent Zaz [+]");
ft_putstr("[+] $#@#',./,~!@~=+ [+]\n");
printf("[-] Test with null [-]\n");
ft_putstr(NULL);
printf("[------] END OF FT_PUTSTR [------]\n");
}
/*void check_putstr_fd(void)
{
dprintf(2, "[------] FT_PUTSTR_FD [------]\n");
ft_putstr_fd("[+] a [+]\n", 2);
ft_puts("[+] Zaz suce des poneys [+]");
ft_puts("[+] Ou plutot, les poneys sucent Zaz [+]");
ft_putstr_fd("[+] $#@#',./,~!@~=+ [+]\n", 2);
dprintf(2, "[-] Test with null [-]\n");
ft_putstr_fd(NULL, 2);
dprintf(2, "[------] END OF FT_PUTSTR_FD [------]\n");
}
void check_strchr(void)
{
char *str;
str = ft_strdup("Salut");
printf("[------] FT_STRCHR [------]\n");
printf("[+] Ret => %p [+]\n", ft_strchr(str, 'a'));
printf("[+] Doit Ret => %p [+]\n", strchr(str, 'a'));
printf("[-] Test with null [-]\n");
ft_putstr_fd(NULL, 1);
printf("[------] END OF FT_STRCHR [------]\n");
}*/
int main(void)
{
//PART 1
printf("[------] PART 1 [------] \n");
check_bzero();
printf("\n");
check_strcat();
printf("\n");
check_alpha();
printf("\n");
check_digit();
printf("\n");
check_alnum();
printf("\n");
check_isascii();
printf("\n");
check_isprint();
printf("\n");
check_tolower();
printf("\n");
check_toupper();
printf("\n");
check_puts();
printf("\n");
// PART 2
printf("[------] PART 2 [------] \n");
check_strlen();
printf("\n");
check_memset();
printf("\n");
check_memcpy();
printf("\n");
check_strdup();
printf("\n");
// PART 3
printf("[------] PART 3 [------] \n");
check_cat();
printf("\n");
// BONUS
printf("[------] BONUS [------] \n");
check_putchar();
printf("\n");
/* check_putchar_fd();
printf("\n");
check_puts_fd();
printf("\n");*/
check_putstr();
printf("\n");
/* check_putstr_fd();
printf("\n");
check_strchr();
printf("\n");*/
check_isspace();
printf("\n");
check_isupper();
printf("\n");
check_islower();
printf("\n");
printf("[------] END OF TESTS [------] \n");
return 0;
}