test(strdup): adding test on strdup function
This commit is contained in:
parent
d287180a85
commit
93a750ca6a
1 changed files with 28 additions and 1 deletions
29
test/main.c
29
test/main.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/12 14:02:17 by rparodi #+# #+# */
|
/* 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 "_internal_test.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -121,6 +122,30 @@ static void _test_strcpy(void)
|
||||||
putchar('\n');
|
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)
|
static void _test_write(void)
|
||||||
{
|
{
|
||||||
int original, homemade;
|
int original, homemade;
|
||||||
|
|
@ -222,6 +247,7 @@ int main(int argc, char *argv[])
|
||||||
_test_strcpy,
|
_test_strcpy,
|
||||||
_test_write,
|
_test_write,
|
||||||
_test_read,
|
_test_read,
|
||||||
|
_test_strdup,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
char *func_name[] = {
|
char *func_name[] = {
|
||||||
|
|
@ -230,6 +256,7 @@ int main(int argc, char *argv[])
|
||||||
"strcpy",
|
"strcpy",
|
||||||
"write",
|
"write",
|
||||||
"read",
|
"read",
|
||||||
|
"strdup",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue