#include #include "../headers/libasm.h" #include "string.h" #include #include void test_size_t(size_t expected_value, size_t value) { if (expected_value != value) printf("[FAILED] %zu != %zu", expected_value, value); else printf("[OK]"); } void test_int(int expected_value, int value) { if (expected_value != value) printf("[FAILED] %d != %d", expected_value, value); else printf("[OK]"); } void test_str(const char *expected_value, const char *value) { if (strcmp(expected_value, value)) printf("[FAILED] %s != %s", expected_value, value); else printf("[OK]"); } void multiple_test_int(size_t (*normal_func)(const char*), size_t (*own_func)(const char*), const char **values) { for (size_t i = 0; values[i] != NULL; i++) { printf("test: %s ", values[i]); test_int(normal_func(values[i]), own_func(values[i])); printf("\n"); } } void multiple_test_int_2(int (*normal_func)(const char *, const char *), int (*own_func)(const char *, const char *), const char *values[][2]) { for (size_t i = 0; values[i][0] != NULL; i++) { printf("test: %s==%s", values[i][0], values[i][1]); test_int(normal_func(values[i][0], values[i][1]), own_func(values[i][0], values[i][1])); printf("\n"); } } void multiple_test_strcpy(char *(*own_func)(char *, const char *), const char * const *values) { char tmp[4096]; for (size_t i = 0; values[i] != NULL; i++) { printf("test: %s", values[i]); test_size_t((size_t) strcpy(tmp, values[i]), (size_t) own_func(tmp, values[i])); test_str(values[i], tmp); printf("\n"); } } void multiple_test_atoi_base(char *(*own_func)(char *, const char *), const char * const *values[2]) { char tmp[4096]; for (size_t i = 0; values[i] != NULL; i++) { printf("test: %s", values[i]); printf("\n"); } } void multiple_test_strdup(const char * const *values) { char *tmp; for (size_t i = 0; values[i] != NULL; i++) { tmp = ft_strdup(values[i]); test_str(tmp, values[i]); free(tmp); printf("\n"); } } int main() { printf("STRLEN\n"); const char *strlen_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL}; multiple_test_int(strlen, ft_strlen, strlen_tests); printf("\n"); printf("STRCMP\n"); const char *strcmp_tests[][2] = {{"w", "z"}, {"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, NULL}; multiple_test_int_2(strcmp, ft_strcmp, strcmp_tests); printf("\n"); printf("STRCPY\n"); const char *strcpy_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL}; multiple_test_strcpy(ft_strcpy, strcpy_tests); printf("\n"); printf("STRDUP\n"); const char *strdup_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL}; multiple_test_strdup(strdup_tests); printf("\n"); }