From b4196550be9ab0fcbf800385885a13ce4feb1093 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 13 Dec 2025 13:35:04 +0100 Subject: [PATCH] refactor(test): modifying test to be easier to read --- test/main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/main.c b/test/main.c index a0404e0..60ffeea 100644 --- a/test/main.c +++ b/test/main.c @@ -93,6 +93,32 @@ static void _test_strcmp() 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) { int original, homemade; @@ -191,6 +217,7 @@ int main(int argc, char *argv[]) t_test_func tests[] = { _test_strlen, _test_strcmp, + _test_strcpy, _test_write, _test_read, NULL @@ -198,6 +225,7 @@ int main(int argc, char *argv[]) char *func_name[] = { "strlen", "strcmp", + "strcpy", "write", "read", NULL