refactor(test): modifying test to be easier to read
This commit is contained in:
parent
6faf9d51a4
commit
b4196550be
1 changed files with 28 additions and 0 deletions
28
test/main.c
28
test/main.c
|
|
@ -93,6 +93,32 @@ static void _test_strcmp()
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _test_strcpy(void)
|
||||||
|
{
|
||||||
|
printf("\n%sTesting '%sstrcpy%s'%s\n", CLR_YELLOW, CLR_BLUE, CLR_YELLOW, RESET);
|
||||||
|
ft_strcpy(NULL, "a");
|
||||||
|
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||||
|
ft_strcpy("a", NULL);
|
||||||
|
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||||
|
ft_strcpy(NULL, 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 = strcpy(buf_orig, strs[i]);
|
||||||
|
char *ret_home = ft_strcpy(buf_home, strs[i]);
|
||||||
|
if (strcmp(buf_orig, buf_home) == 0 && ret_orig == buf_orig && ret_home == buf_home)
|
||||||
|
printf("%s✔%s", CLR_GREEN, RESET);
|
||||||
|
else
|
||||||
|
dprintf(2, "\t%s✘%s", CLR_RED, RESET);
|
||||||
|
putchar(' ');
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
|
||||||
static void _test_write(void)
|
static void _test_write(void)
|
||||||
{
|
{
|
||||||
int original, homemade;
|
int original, homemade;
|
||||||
|
|
@ -191,6 +217,7 @@ int main(int argc, char *argv[])
|
||||||
t_test_func tests[] = {
|
t_test_func tests[] = {
|
||||||
_test_strlen,
|
_test_strlen,
|
||||||
_test_strcmp,
|
_test_strcmp,
|
||||||
|
_test_strcpy,
|
||||||
_test_write,
|
_test_write,
|
||||||
_test_read,
|
_test_read,
|
||||||
NULL
|
NULL
|
||||||
|
|
@ -198,6 +225,7 @@ int main(int argc, char *argv[])
|
||||||
char *func_name[] = {
|
char *func_name[] = {
|
||||||
"strlen",
|
"strlen",
|
||||||
"strcmp",
|
"strcmp",
|
||||||
|
"strcpy",
|
||||||
"write",
|
"write",
|
||||||
"read",
|
"read",
|
||||||
NULL
|
NULL
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue