From 3d8224657c85d5aea023fda64d02b661cc3528e1 Mon Sep 17 00:00:00 2001 From: Aleksei Chubukov Date: Thu, 30 Nov 2023 21:58:36 +0400 Subject: [PATCH] updated tests --- c03/ex03.c | 12 +++++------ common/tests.h | 58 +++++++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/c03/ex03.c b/c03/ex03.c index 62cba85..83efc37 100644 --- a/c03/ex03.c +++ b/c03/ex03.c @@ -6,17 +6,17 @@ /* By: achubuko +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/30 19:58:12 by achubuko #+# #+# */ -/* Updated: 2023/11/30 21:32:12 by achubuko ### ########.fr */ +/* Updated: 2023/11/30 21:51:37 by achubuko ### ########.fr */ /* */ /* ************************************************************************** */ #include -#define TESTS_RETURN_PRINTF "%p" +#define TEST_RETURN_PRINTF "%p" char *ft_strncat(char *dest, char *src, unsigned int nb); int main(void) { - TESTS_SEED(char); + TEST_SEED(char); printf("initial strings:\n"); dump(s, TEST_SOURCE_LENGHT); @@ -24,13 +24,13 @@ int main(void) r1 = strncat(d1, s1, 6); r2 = ft_strncat(d2, s2, 6); - TESTS_SYNOPSIS("strncat(d, s, 6)"); + TEST_SYNOPSIS("strncat(d, s, 6)", s, d, s1, d1, s2, d2); r1 = strncat(d1, s1, 20); r2 = ft_strncat(d2, s2, 20); - TESTS_SYNOPSIS("strncat(d, s, 20)"); + TEST_SYNOPSIS("strncat(d, s, 20)", s, d, s1, d1, s2, d2); r1 = strncat(s1, d1, 5); r2 = ft_strncat(s2, d2, 5); - TESTS_SYNOPSIS("strncat(s, d, 5)"); + TEST_SYNOPSIS("strncat(s, d, 5)", s, d, s1, d1, s2, d2); } diff --git a/common/tests.h b/common/tests.h index 56e9949..df6b22f 100644 --- a/common/tests.h +++ b/common/tests.h @@ -1,5 +1,5 @@ -#ifndef TESTS_H -#define TESTS_H +#ifndef TEST_H +#define TEST_H #include #include #define TEST_SOURCE "HeLlo world!\0It's a\tBEAUTIFUL\tday!" @@ -7,34 +7,38 @@ #define TEST_DESTINATION "GooDBye\0and thanks _for\rall the fish!" #define TEST_DESTINATION_LENGHT 38 #define TEST_BUF_SIZE 100 -#define TESTS_FUNC_NAME -#define TESTS_RETURN_PRINTF "%p" -#define TESTS_PRINT_BUFFERS(TESTS_FUNC_CASE) \ - printf("original " TESTS_FUNC_CASE "\n"); \ - dump(s1, TEST_SOURCE_LENGHT); \ - dump(d1, TEST_DESTINATION_LENGHT); \ - printf("replicated " TESTS_FUNC_CASE "\n"); \ - dump(s2, TEST_SOURCE_LENGHT); \ - dump(d2, TEST_DESTINATION_LENGHT); +#define TEST_FUNC_NAME +#define TEST_RETURN_PRINTF "%p" -#define TESTS_RESET_BUFFERS \ - memcpy(d1, d, TEST_BUF_SIZE); \ - memcpy(s1, s, TEST_BUF_SIZE); \ - memcpy(d2, d, TEST_BUF_SIZE); \ - memcpy(s2, s, TEST_BUF_SIZE); -#define TESTS_PRINT_BUFCMP(TESTS_FUNC_CASE) \ +#define TEST_PRINT_BUFFERS(TEST_FUNC_CASE, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST) \ + printf("original " TEST_FUNC_CASE "\n"); \ + dump(TEST_BUF_ORIG_SRC, TEST_SOURCE_LENGHT); \ + dump(TEST_BUF_ORIG_DEST, TEST_DESTINATION_LENGHT); \ + printf("replicated " TEST_FUNC_CASE "\n"); \ + dump(TEST_BUF_MOD_SRC, TEST_SOURCE_LENGHT); \ + dump(TEST_BUF_MOD_DEST, TEST_DESTINATION_LENGHT); + +#define TEST_RESET_BUFFERS(TEST_BUF_PRISCINE_SRC, TEST_BUF_PRISCINE_DEST, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST) \ + memcpy(TEST_BUF_ORIG_SRC, TEST_BUF_PRISCINE_DEST, TEST_BUF_SIZE); \ + memcpy(TEST_BUF_ORIG_SRC, TEST_BUF_PRISCINE_SRC, TEST_BUF_SIZE); \ + memcpy(TEST_BUF_MOD_DEST, TEST_BUF_PRISCINE_DEST, TEST_BUF_SIZE); \ + memcpy(TEST_BUF_MOD_SRC, TEST_BUF_PRISCINE_SRC, TEST_BUF_SIZE); + +#define TEST_PRINT_BUFCMP(TEST_FUNC_CASE, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST) \ printf( \ - "buffers comparison:\n " TESTS_FUNC_CASE ":\t%i\n ft_" TESTS_FUNC_CASE ":\t%i\n", \ - bufcmp(s1, s2, TEST_SOURCE_LENGHT), \ - bufcmp(d1, d2, TEST_DESTINATION_LENGHT) \ + "buffers comparison:\n " TEST_FUNC_CASE ":\t%i\n ft_" TEST_FUNC_CASE ":\t%i\n", \ + bufcmp(TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_SOURCE_LENGHT), \ + bufcmp(TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST, TEST_DESTINATION_LENGHT) \ ); -#define TESTS_PRINT_RETVALS printf("return values: orig: " TESTS_RETURN_PRINTF " ft: %p\n", r1, r2) -#define TESTS_SYNOPSIS(TESTS_FUNC_CASE) \ - TESTS_PRINT_BUFFERS(TESTS_FUNC_CASE); \ - TESTS_PRINT_BUFCMP(TESTS_FUNC_CASE); \ - TESTS_PRINT_RETVALS; \ - TESTS_RESET_BUFFERS; -#define TESTS_SEED(type) \ + +#define TEST_PRINT_RETVALS printf("return values: orig: " TEST_RETURN_PRINTF " ft: %p\n", r1, r2) + +#define TEST_SYNOPSIS(TEST_FUNC_CASE, TEST_BUF_PRISCINE_SRC, TEST_BUF_PRISCINE_DEST, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST) \ + TEST_PRINT_BUFFERS(TEST_FUNC_CASE, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST); \ + TEST_PRINT_BUFCMP(TEST_FUNC_CASE, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST); \ + TEST_PRINT_RETVALS; \ + TEST_RESET_BUFFERS(TEST_BUF_PRISCINE_SRC, TEST_BUF_PRISCINE_DEST, TEST_BUF_ORIG_SRC, TEST_BUF_ORIG_DEST, TEST_BUF_MOD_SRC, TEST_BUF_MOD_DEST); +#define TEST_SEED(type) \ char s[TEST_BUF_SIZE] = TEST_SOURCE; \ char d[TEST_BUF_SIZE] = TEST_DESTINATION; \ type *r1; \