test(strdup): adding test on strdup function

This commit is contained in:
Raphael 2026-01-13 14:03:15 +01:00
parent d287180a85
commit 93a750ca6a
No known key found for this signature in database

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/12 14:02:17 by rparodi #+# #+# */
/* Updated: 2025/12/13 13:41:58 by rparodi ### ########.fr */
/* Updated: 2026/01/13 12:12:01 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
#include "_internal_test.h"
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
@ -121,6 +122,30 @@ static void _test_strcpy(void)
putchar('\n');
}
static void _test_strdup(void)
{
printf("\n%sTesting '%sstrdup%s'%s\n", CLR_YELLOW, CLR_BLUE, CLR_YELLOW, RESET);
ft_strdup(NULL);
printf("%s✔%s ", CLR_GREEN, RESET);
for (int i = 0; strs[i]; i++)
{
char buf_orig[8192];
char buf_home[8192];
memset(buf_orig, 0, sizeof(buf_orig));
memset(buf_home, 0, sizeof(buf_home));
char *ret_orig = strdup(strs[i]);
char *ret_home = ft_strdup(strs[i]);
if (strcmp(ret_orig, ret_home) == 0 && strcmp(buf_orig, buf_home) == 0)
printf("%s✔%s", CLR_GREEN, RESET);
else
dprintf(2, "\t%s✘%s", CLR_RED, RESET);
putchar(' ');
free(ret_orig);
free(ret_home);
}
putchar('\n');
}
static void _test_write(void)
{
int original, homemade;
@ -222,6 +247,7 @@ int main(int argc, char *argv[])
_test_strcpy,
_test_write,
_test_read,
_test_strdup,
NULL
};
char *func_name[] = {
@ -230,6 +256,7 @@ int main(int argc, char *argv[])
"strcpy",
"write",
"read",
"strdup",
NULL
};