2023-11-30 17:58:36 +00:00
|
|
|
#ifndef TEST_H
|
|
|
|
#define TEST_H
|
2023-11-23 19:06:22 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2023-11-30 17:35:58 +00:00
|
|
|
#define TEST_SOURCE "HeLlo world!\0It's a\tBEAUTIFUL\tday!"
|
2023-11-23 19:06:22 +00:00
|
|
|
#define TEST_SOURCE_LENGHT 35
|
2023-11-30 17:35:58 +00:00
|
|
|
#define TEST_DESTINATION "GooDBye\0and thanks _for\rall the fish!"
|
2023-11-23 19:06:22 +00:00
|
|
|
#define TEST_DESTINATION_LENGHT 38
|
2023-11-30 17:35:58 +00:00
|
|
|
#define TEST_BUF_SIZE 100
|
2023-11-30 17:58:36 +00:00
|
|
|
#define TEST_FUNC_NAME
|
|
|
|
#define TEST_RETURN_PRINTF "%p"
|
2023-11-30 17:35:58 +00:00
|
|
|
|
2023-11-30 17:58:36 +00:00
|
|
|
#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) \
|
2023-11-30 17:35:58 +00:00
|
|
|
printf( \
|
2023-11-30 17:58:36 +00:00
|
|
|
"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) \
|
2023-11-30 17:35:58 +00:00
|
|
|
);
|
2023-11-30 17:58:36 +00:00
|
|
|
|
|
|
|
#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) \
|
2023-11-30 17:35:58 +00:00
|
|
|
char s[TEST_BUF_SIZE] = TEST_SOURCE; \
|
|
|
|
char d[TEST_BUF_SIZE] = TEST_DESTINATION; \
|
|
|
|
type *r1; \
|
|
|
|
char s1[TEST_BUF_SIZE] = TEST_SOURCE; \
|
|
|
|
char d1[TEST_BUF_SIZE] = TEST_DESTINATION; \
|
|
|
|
type *r2; \
|
|
|
|
char s2[TEST_BUF_SIZE] = TEST_SOURCE; \
|
|
|
|
char d2[TEST_BUF_SIZE] = TEST_DESTINATION;
|
|
|
|
|
2023-11-23 19:06:22 +00:00
|
|
|
#define FG_WHT "\x1B[37m"
|
|
|
|
#define FG_MAG "\x1B[35m"
|
|
|
|
#define COLOR_RESET "\x1B[0m"
|
|
|
|
#endif
|
2023-11-28 15:40:55 +00:00
|
|
|
|
|
|
|
int bufcmp(char*, char*, int);
|
|
|
|
void dump(char*, int);
|