diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-13 15:03:29 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-13 15:03:29 +0200 |
| commit | 4388cc2d74f1ee8930ca1baaeeea67da925f8a2c (patch) | |
| tree | 5feee2181fc8875d22ccb1dacdc0710f23bd9169 | |
| parent | 1eb2d4832a590c809e38840f970b4506661c89cf (diff) | |
| download | libasm_test-4388cc2d74f1ee8930ca1baaeeea67da925f8a2c.tar.gz libasm_test-4388cc2d74f1ee8930ca1baaeeea67da925f8a2c.tar.bz2 libasm_test-4388cc2d74f1ee8930ca1baaeeea67da925f8a2c.zip | |
Added argument precsion in error message for all function but ft_strdup, Changed function prototype style
| -rw-r--r-- | functions_reference/ref_ft_atoi_base.c | 9 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_push_front.c | 5 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_remove_if.c | 7 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_size.c | 5 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_sort.c | 9 | ||||
| -rw-r--r-- | helper.c | 9 | ||||
| -rw-r--r-- | libasm_test.h | 116 | ||||
| -rw-r--r-- | main.c | 5 | ||||
| -rw-r--r-- | test/ft_atoi_base_test.c | 14 | ||||
| -rw-r--r-- | test/ft_list_push_front_test.c | 44 | ||||
| -rw-r--r-- | test/ft_list_remove_if_test.c | 26 | ||||
| -rw-r--r-- | test/ft_list_size_test.c | 16 | ||||
| -rw-r--r-- | test/ft_list_sort_test.c | 25 | ||||
| -rw-r--r-- | test/ft_read_test.c | 23 | ||||
| -rw-r--r-- | test/ft_strcmp_test.c | 13 | ||||
| -rw-r--r-- | test/ft_strcpy_test.c | 31 | ||||
| -rw-r--r-- | test/ft_strdup_test.c | 14 | ||||
| -rw-r--r-- | test/ft_strlen_test.c | 13 | ||||
| -rw-r--r-- | test/ft_write_test.c | 25 |
19 files changed, 184 insertions, 225 deletions
diff --git a/functions_reference/ref_ft_atoi_base.c b/functions_reference/ref_ft_atoi_base.c index 6bd7052..1599163 100644 --- a/functions_reference/ref_ft_atoi_base.c +++ b/functions_reference/ref_ft_atoi_base.c @@ -6,15 +6,15 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:20:16 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:20:18 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:00:33 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include <ctype.h> #include "libasm_test.h" -static bool -valid_base(char *base) +static +bool valid_base(char *base) { if (strlen(base) < 2) return false; @@ -30,8 +30,7 @@ valid_base(char *base) return true; } -int -ref_ft_atoi_base(char *str, char *base) +int ref_ft_atoi_base(char *str, char *base) { long int nb; int radix; diff --git a/functions_reference/ref_ft_list_push_front.c b/functions_reference/ref_ft_list_push_front.c index 78b0877..9f796a4 100644 --- a/functions_reference/ref_ft_list_push_front.c +++ b/functions_reference/ref_ft_list_push_front.c @@ -6,14 +6,13 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:20:23 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:20:24 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:01:09 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -void -ref_ft_list_push_front(t_list **begin_list, void *data) +void ref_ft_list_push_front(t_list **begin_list, void *data) { if (begin_list == NULL) return ; diff --git a/functions_reference/ref_ft_list_remove_if.c b/functions_reference/ref_ft_list_remove_if.c index c99cbea..90bd1cc 100644 --- a/functions_reference/ref_ft_list_remove_if.c +++ b/functions_reference/ref_ft_list_remove_if.c @@ -6,15 +6,14 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:20:03 by cacharle #+# #+# */ -/* Updated: 2020/02/08 20:02:25 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:01:02 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -void -ref_ft_list_remove_if(t_list **begin_list, void *data_ref, - int (*cmp)(), void (*free_fct)(void *)) +void ref_ft_list_remove_if(t_list **begin_list, void *data_ref, + int (*cmp)(), void (*free_fct)(void *)) { t_list *saved_next; diff --git a/functions_reference/ref_ft_list_size.c b/functions_reference/ref_ft_list_size.c index c6348ba..c403732 100644 --- a/functions_reference/ref_ft_list_size.c +++ b/functions_reference/ref_ft_list_size.c @@ -6,14 +6,13 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:20:11 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:20:12 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:00:42 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -int -ref_ft_list_size(t_list *begin_list) +int ref_ft_list_size(t_list *begin_list) { int counter; diff --git a/functions_reference/ref_ft_list_sort.c b/functions_reference/ref_ft_list_sort.c index e770fa0..d203231 100644 --- a/functions_reference/ref_ft_list_sort.c +++ b/functions_reference/ref_ft_list_sort.c @@ -6,14 +6,14 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 02:49:28 by cacharle #+# #+# */ -/* Updated: 2020/02/08 02:49:29 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:00:52 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -static t_list* -merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*)) +static +t_list* merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*)) { t_list *merged = 0x0; @@ -34,8 +34,7 @@ merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*)) return merged; } -void -ref_ft_list_sort(t_list **begin_list, int (*cmp)(void *, void*)) +void ref_ft_list_sort(t_list **begin_list, int (*cmp)(void *, void*)) { if (begin_list == 0x0 || *begin_list == 0x0 || (*begin_list)->next == 0x0) @@ -6,22 +6,19 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:07 by cacharle #+# #+# */ -/* Updated: 2020/04/12 20:05:58 by charles ### ########.fr */ +/* Updated: 2020/04/13 15:01:20 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" - -void -print_ok(void) +void print_ok(void) { printf("OK: %s\n", test_name); fflush(stdout); } -void -print_signaled_ko(void) +void print_signaled_ko(void) { printf("KO: [SEGFAULT]: %s\n", test_name); fflush(stdout); diff --git a/libasm_test.h b/libasm_test.h index acc2b41..362d91a 100644 --- a/libasm_test.h +++ b/libasm_test.h @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:19 by cacharle #+# #+# */ -/* Updated: 2020/04/12 20:06:05 by charles ### ########.fr */ +/* Updated: 2020/04/13 14:41:40 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,24 +32,17 @@ /* * mandatory */ -int -ft_strlen(char *str); -char* -ft_strcpy(char *dst, const char *src); -int -ft_strcmp(const char *s1, const char *s2); -int -ft_write(int fildes, const void *buf, size_t buf_size); -int -ft_read(int fildes, void *buf, size_t buf_size); -char* -ft_strdup(const char *str); +int ft_strlen(char *str); +char* ft_strcpy(char *dst, const char *src); +int ft_strcmp(const char *s1, const char *s2); +int ft_write(int fildes, const void *buf, size_t buf_size); +int ft_read(int fildes, void *buf, size_t buf_size); +char* ft_strdup(const char *str); /* * bonus */ -int -ft_atoi_base(const char *str, const char *base); +int ft_atoi_base(const char *str, const char *base); typedef struct s_list { @@ -57,80 +50,51 @@ typedef struct s_list struct s_list *next; } t_list; -void -ft_list_push_front(t_list **begin_list, void *data); -int -ft_list_size(t_list *begin_list); -void -ft_list_sort(t_list **begin_list, int (*cmp)()); -void -ft_list_remove_if(t_list **begin_list, void *data_ref, +void ft_list_push_front(t_list **begin_list, void *data); +int ft_list_size(t_list *begin_list); +void ft_list_sort(t_list **begin_list, int (*cmp)()); +void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *)); /* * test_functions */ -void -ft_strlen_test(void); -void -ft_strcpy_test(void); -void -ft_strcmp_test(void); -void -ft_write_test(void); -void -ft_read_test(void); -void -ft_strdup_test(void); - -void -ft_atoi_base_test(void); -void -ft_list_push_front_test(void); -void -ft_list_size_test(void); -void -ft_list_sort_test(void); -void -ft_list_remove_if_test(void); +void ft_strlen_test(void); +void ft_strcpy_test(void); +void ft_strcmp_test(void); +void ft_write_test(void); +void ft_read_test(void); +void ft_strdup_test(void); + +void ft_atoi_base_test(void); +void ft_list_push_front_test(void); +void ft_list_size_test(void); +void ft_list_sort_test(void); +void ft_list_remove_if_test(void); /* * helpers */ -void -print_ok(void); -void -print_signaled_ko(void); - -int* -create_data_elem(int data); -t_list* -create_elem(int data); -t_list* -list_from_format(char *fmt); -t_list* -list_dup(t_list *list); -int -list_cmp(t_list *l1, t_list *l2); -void -list_print(t_list *list); -void -list_destroy(t_list *list); +void print_ok(void); +void print_signaled_ko(void); + +int* create_data_elem(int data); +t_list* create_elem(int data); +t_list* list_from_format(char *fmt); +t_list* list_dup(t_list *list); +int list_cmp(t_list *l1, t_list *l2); +void list_print(t_list *list); +void list_destroy(t_list *list); /* * function of reference */ -int -ref_ft_atoi_base(char *str, char *base); -void -ref_ft_list_push_front(t_list **begin_list, void *data); -int -ref_ft_list_size(t_list *begin_list); -void -ref_ft_list_sort(t_list **begin_list, int (*cmp)()); -void -ref_ft_list_remove_if(t_list **begin_list, void *data_ref, +int ref_ft_atoi_base(char *str, char *base); +void ref_ft_list_push_front(t_list **begin_list, void *data); +int ref_ft_list_size(t_list *begin_list); +void ref_ft_list_sort(t_list **begin_list, int (*cmp)()); +void ref_ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *)); /* @@ -161,4 +125,4 @@ char *test_name; print_ok(); \ } while(0); -#endif /* LIBASM_TEST_H */ +#endif @@ -6,14 +6,13 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:06:45 by cacharle #+# #+# */ -/* Updated: 2020/02/08 20:58:13 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:01:24 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -int -main(void) +int main(void) { ft_strlen_test(); ft_strcpy_test(); diff --git a/test/ft_atoi_base_test.c b/test/ft_atoi_base_test.c index 974fa0c..dfb8671 100644 --- a/test/ft_atoi_base_test.c +++ b/test/ft_atoi_base_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:27 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:07:38 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:52:28 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ static int expected_ret; static int actual_ret; - /* asm("movq $0xffffffffffffffff, %rax"); \ */ #define FT_ATOI_BASE_EXPECT(str, base) do { \ actual_ret = ft_atoi_base(str, base); \ expected_ret = ref_ft_atoi_base(str, base); \ @@ -26,8 +25,8 @@ static int actual_ret; print_ok(); \ } while (0); -static void -ft_atoi_base_segfault(void) +static +void ft_atoi_base_segfault(void) { TEST_ASM_FUNCTION(ft_atoi_base("", "")); TEST_ASM_FUNCTION(ft_atoi_base("10", "")); @@ -83,8 +82,8 @@ ft_atoi_base_segfault(void) TEST_ASM_FUNCTION(ft_atoi_base(TO_STRING(INT_MIN), "0123456789")); } -static void -ft_atoi_base_compare(void) +static +void ft_atoi_base_compare(void) { FT_ATOI_BASE_EXPECT("", ""); FT_ATOI_BASE_EXPECT("10", ""); @@ -140,8 +139,7 @@ ft_atoi_base_compare(void) FT_ATOI_BASE_EXPECT(TO_STRING(INT_MIN), "0123456789"); } -void -ft_atoi_base_test(void) +void ft_atoi_base_test(void) { test_name = "ft_atoi_base.s"; diff --git a/test/ft_list_push_front_test.c b/test/ft_list_push_front_test.c index 00b8c13..55d0b4f 100644 --- a/test/ft_list_push_front_test.c +++ b/test/ft_list_push_front_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:24 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:08:25 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:57:14 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,26 +15,31 @@ static t_list *tmp; static t_list *expected; static t_list *actual; +static t_list *from; -#define FT_LIST_PUSH_FRONT_EXPECT(fmt, push) do { \ - expected = list_from_format(fmt); \ - actual = list_from_format(fmt); \ +#define FT_LIST_PUSH_FRONT_EXPECT(fmt, push) do { \ + from = list_from_format(fmt); \ + expected = list_from_format(fmt); \ + actual = list_from_format(fmt); \ ref_ft_list_push_front(&expected, create_data_elem(push)); \ ft_list_push_front(&actual, create_data_elem(push)); \ - if (list_cmp(expected, actual) != 0) { \ - printf("KO: [COMPARE]: %s: expected: ", test_name); \ - list_print(expected); \ - printf(" got: "); \ - list_print(actual); \ - putchar('\n'); \ - } else \ - print_ok(); \ - list_destroy(expected); \ - list_destroy(actual); \ + if (list_cmp(expected, actual) != 0) { \ + printf("KO: [COMPARE]: %s: expected: ", test_name); \ + list_print(expected); \ + printf(" got: "); \ + list_print(actual); \ + printf(" with: "); \ + list_print(from); \ + putchar('\n'); \ + } else \ + print_ok(); \ + list_destroy(from); \ + list_destroy(expected); \ + list_destroy(actual); \ } while (0); -static void -ft_list_push_front_segfault(void) +static +void ft_list_push_front_segfault(void) { TEST_ASM_FUNCTION(tmp = NULL; ft_list_push_front(&tmp, malloc(1));list_destroy(tmp)); TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); ft_list_push_front(&tmp, create_data_elem(34)); list_destroy(tmp)); @@ -51,8 +56,8 @@ ft_list_push_front_segfault(void) ); } -static void -ft_list_push_front_compare(void) +static +void ft_list_push_front_compare(void) { FT_LIST_PUSH_FRONT_EXPECT("", 0); FT_LIST_PUSH_FRONT_EXPECT("", 1); @@ -62,8 +67,7 @@ ft_list_push_front_compare(void) FT_LIST_PUSH_FRONT_EXPECT("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", 7); } -void -ft_list_push_front_test(void) +void ft_list_push_front_test(void) { test_name = "ft_list_push_front.s"; ft_list_push_front_segfault(); diff --git a/test/ft_list_remove_if_test.c b/test/ft_list_remove_if_test.c index fb762eb..bca0a19 100644 --- a/test/ft_list_remove_if_test.c +++ b/test/ft_list_remove_if_test.c @@ -6,20 +6,20 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:42 by cacharle #+# #+# */ -/* Updated: 2020/02/08 20:52:06 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:59:22 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -static int -compar(void *a, void *ref) +static +int compar(void *a, void *ref) { return *(int*)a - *(int*)ref; } -static void -free_fct(void *data) +static +void free_fct(void *data) { free(data); } @@ -31,8 +31,10 @@ static int i3 = 3; static t_list *tmp; static t_list *expected; static t_list *actual; +static t_list *from; #define FT_LIST_REMOVE_IF_EXPECT(fmt, ref) do { \ + from = list_from_format(fmt); \ expected = list_from_format(fmt); \ actual = list_from_format(fmt); \ ref_ft_list_remove_if(&expected, ref, compar, free_fct); \ @@ -42,15 +44,18 @@ static t_list *actual; list_print(expected); \ printf(" got: "); \ list_print(actual); \ + printf(" with: "); \ + list_print(from); \ putchar('\n'); \ } else \ print_ok(); \ + list_destroy(from); \ list_destroy(expected); \ list_destroy(actual); \ } while (0); -static void -ft_list_remove_if_segfault(void) +static +void ft_list_remove_if_segfault(void) { TEST_ASM_FUNCTION(tmp = list_from_format(""); ft_list_remove_if(&tmp, &i0, compar, free_fct); @@ -81,8 +86,8 @@ ft_list_remove_if_segfault(void) list_destroy(tmp)); } -static void -ft_list_remove_if_compare(void) +static +void ft_list_remove_if_compare(void) { FT_LIST_REMOVE_IF_EXPECT("", &i0); FT_LIST_REMOVE_IF_EXPECT("1 2", &i3); @@ -95,8 +100,7 @@ ft_list_remove_if_compare(void) FT_LIST_REMOVE_IF_EXPECT("1 2 1 2 1 2 1 2", &i2); } -void -ft_list_remove_if_test(void) +void ft_list_remove_if_test(void) { test_name = "ft_list_remove_if.s"; ft_list_remove_if_segfault(); diff --git a/test/ft_list_size_test.c b/test/ft_list_size_test.c index a6cf23a..e1f6f8c 100644 --- a/test/ft_list_size_test.c +++ b/test/ft_list_size_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:20 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:08:21 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:54:33 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,15 +23,16 @@ static int actual; if (expected != actual) { \ printf("KO: [COMPARE]: %s: expected: %d ", \ test_name, expected); \ + printf("got: %d with:", actual); \ list_print(tmp); \ - printf(" got: %d\n", actual); \ + putchar('\n'); \ } else \ print_ok(); \ list_destroy(tmp); \ } while (0); -static void -ft_list_size_segfault(void) +static +void ft_list_size_segfault(void) { TEST_ASM_FUNCTION(tmp = list_from_format(""); ft_list_size(tmp); list_destroy(tmp)); TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); ft_list_size(tmp); list_destroy(tmp)); @@ -45,8 +46,8 @@ ft_list_size_segfault(void) ); } -static void -ft_list_size_compare(void) +static +void ft_list_size_compare(void) { FT_LIST_SIZE_EXPECT("1 2 3"); FT_LIST_SIZE_EXPECT(""); @@ -57,8 +58,7 @@ ft_list_size_compare(void) FT_LIST_SIZE_EXPECT("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"); } -void -ft_list_size_test(void) +void ft_list_size_test(void) { test_name = "ft_list_size.s"; ft_list_size_segfault(); diff --git a/test/ft_list_sort_test.c b/test/ft_list_sort_test.c index 658abaf..82e60cc 100644 --- a/test/ft_list_sort_test.c +++ b/test/ft_list_sort_test.c @@ -6,14 +6,14 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:15 by cacharle #+# #+# */ -/* Updated: 2020/02/08 20:39:51 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:00:02 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -static int -compar_int(void *a, void *b) +static +int compar_int(void *a, void *b) { return *(int*)a - *(int*)b; } @@ -21,8 +21,10 @@ compar_int(void *a, void *b) static t_list *tmp; static t_list *expected; static t_list *actual; +static t_list *from; #define FT_LIST_SORT_EXPECT(fmt) do { \ + from = list_from_format(fmt); \ expected = list_from_format(fmt); \ actual = list_from_format(fmt); \ ref_ft_list_sort(&expected, compar_int); \ @@ -32,18 +34,18 @@ static t_list *actual; list_print(expected); \ printf(" got: "); \ list_print(actual); \ + printf(" with: "); \ + list_print(from); \ putchar('\n'); \ } else \ print_ok(); \ + list_destroy(from); \ list_destroy(expected); \ list_destroy(actual); \ } while (0); -/* t_list* */ -/* st_merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*)); */ - -static void -ft_list_sort_segfault(void) +static +void ft_list_sort_segfault(void) { TEST_ASM_FUNCTION(tmp = list_from_format(""); ft_list_sort(&tmp, compar_int); list_destroy(tmp)); TEST_ASM_FUNCTION(tmp = list_from_format("1"); ft_list_sort(&tmp, compar_int); list_destroy(tmp)); @@ -54,8 +56,8 @@ ft_list_sort_segfault(void) TEST_ASM_FUNCTION(tmp = list_from_format("12 45 1 -1 232 34 23 87879"); ft_list_sort(&tmp, compar_int); list_destroy(tmp)); } -static void -ft_list_sort_compare(void) +static +void ft_list_sort_compare(void) { FT_LIST_SORT_EXPECT(""); FT_LIST_SORT_EXPECT("1"); @@ -66,8 +68,7 @@ ft_list_sort_compare(void) FT_LIST_SORT_EXPECT("12 45 1 -1 232 34 23 87879"); } -void -ft_list_sort_test(void) +void ft_list_sort_test(void) { test_name = "ft_list_sort.s"; ft_list_sort_segfault(); diff --git a/test/ft_read_test.c b/test/ft_read_test.c index 0914cf7..c175489 100644 --- a/test/ft_read_test.c +++ b/test/ft_read_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:44 by cacharle #+# #+# */ -/* Updated: 2020/02/23 06:28:39 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:52:41 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ #define FT_READ_BUF_SIZE (1 << 12) static int ft_read_pipe[2]; -static char buf[FT_READ_BUF_SIZE]; +static char buf[FT_READ_BUF_SIZE] = {0}; static int ret; #define FT_READ_EXPECT(str) do { \ @@ -26,8 +26,8 @@ static int ret; ret = ft_read(ft_read_pipe[0], buf, strlen(str)); \ buf[ret] = '\0'; \ if (strcmp(buf, str) != 0 || ret != strlen(str)) \ - printf("KO: [COMPARE]: %s: expected: %lu \"%s\" got: %d \"%s\"\n", \ - test_name, strlen(str), str, ret, buf); \ + printf("KO: [COMPARE]: %s: expected: %lu \"%s\" got: %d \"%s\" with: %d, \"%s\", %zu \n", \ + test_name, strlen(str), str, ret, buf, ft_read_pipe[0], buf, strlen(str)); \ else \ print_ok(); \ close(ft_read_pipe[1]); \ @@ -37,14 +37,14 @@ static int ret; #define FT_READ_EXPECT_ERROR(fd, str, size) do { \ ret = ft_read(fd, str, size); \ if ((long)ret != -1) \ - printf("KO: [COMPARE]: %s: expected: %ld got: %ld\n", \ - test_name, -1l, (long)ret); \ + printf("KO: [COMPARE]: %s: expected: %ld got: %ld with: %d "#str" %d\n", \ + test_name, -1l, (long)ret, fd, size); \ else \ print_ok(); \ } while (0); -void -ft_read_test_segfault(void) +static +void ft_read_test_segfault(void) { int tmp[2]; if (pipe(tmp) < 0) @@ -64,8 +64,8 @@ ft_read_test_segfault(void) TEST_ASM_FUNCTION(ft_read(OPEN_MAX + 1, "tt", 2)); } -void -ft_read_test_compare(void) +static +void ft_read_test_compare(void) { FT_READ_EXPECT(""); FT_READ_EXPECT("bon"); @@ -88,8 +88,7 @@ tortor, sit amet consequat amet."); FT_READ_EXPECT_ERROR(42, NULL, 7); } -void -ft_read_test(void) +void ft_read_test(void) { test_name = "ft_read.s"; diff --git a/test/ft_strcmp_test.c b/test/ft_strcmp_test.c index 13b69e7..b9b3520 100644 --- a/test/ft_strcmp_test.c +++ b/test/ft_strcmp_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:03 by cacharle #+# #+# */ -/* Updated: 2020/04/12 20:08:08 by charles ### ########.fr */ +/* Updated: 2020/04/13 14:44:18 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,8 @@ int strcmp_actual; strcmp_expected, strcmp_actual); \ } while (0); -static void -ft_strcmp_test_segfault(void) +static +void ft_strcmp_test_segfault(void) { TEST_ASM_FUNCTION(ft_strcmp("", "")); TEST_ASM_FUNCTION(ft_strcmp("bon", "bon")); @@ -51,8 +51,8 @@ ac tortor et lectus fermentum lobortis eu at mauris. Vestibulum sit amet posuere tortor, sit amet consequat amet.")); } -static void -ft_strcmp_test_compare(void) +static +void ft_strcmp_test_compare(void) { FT_STRCMP_EXPECT("", ""); FT_STRCMP_EXPECT("bon", ""); @@ -115,8 +115,7 @@ tortor, sit amet consequat amet."); FT_STRCMP_EXPECT("\xfe", "\xfe\xff"); } -void -ft_strcmp_test(void) +void ft_strcmp_test(void) { test_name = "ft_strcmp.s"; diff --git a/test/ft_strcpy_test.c b/test/ft_strcpy_test.c index 7929b2f..6b038bb 100644 --- a/test/ft_strcpy_test.c +++ b/test/ft_strcpy_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:58 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:07:59 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:02:13 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,19 +16,23 @@ static char expected_buf[FT_STRCPY_BUF_SIZE] = {0}; static char actual_buf[FT_STRCPY_BUF_SIZE] = {0}; +static char pre_expected_buf[FT_STRCPY_BUF_SIZE] = {0}; +static char pre_actual_buf[FT_STRCPY_BUF_SIZE] = {0}; -#define FT_STRCPY_EXPECT(str) do { \ - strcpy(expected_buf, str); \ - ft_strcpy(actual_buf, str); \ +#define FT_STRCPY_EXPECT(str) do { \ + strcpy(pre_expected_buf, expected_buf); \ + strcpy(pre_actual_buf, actual_buf); \ + strcpy(expected_buf, str); \ + ft_strcpy(actual_buf, str); \ if (strcmp(expected_buf, actual_buf) != 0) \ - printf("KO: [COMPARE]: %s: expected: \"%s\" got: \"%s\"\n", test_name, expected_buf, actual_buf); \ - else \ - print_ok(); \ + printf("KO: [COMPARE]: %s: expected: \"%s\" got: \"%s\" with: \"%s\", \"%s\"\n",\ + test_name, expected_buf, actual_buf, pre_expected_buf, pre_actual_buf); \ + else \ + print_ok(); \ } while (0); - -static void -ft_strcpy_test_segfault(void) +static +void ft_strcpy_test_segfault(void) { char buf[FT_STRCPY_BUF_SIZE] = {0}; @@ -45,8 +49,8 @@ ac tortor et lectus fermentum lobortis eu at mauris. Vestibulum sit amet posuere tortor, sit amet consequat amet.")); } -static void -ft_strcpy_test_compare(void) +static +void ft_strcpy_test_compare(void) { FT_STRCPY_EXPECT(""); FT_STRCPY_EXPECT("abc"); @@ -63,8 +67,7 @@ tortor, sit amet consequat amet."); FT_STRCPY_EXPECT("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0b\x0c\x0d\x0e\x0f"); } -void -ft_strcpy_test(void) +void ft_strcpy_test(void) { test_name = "ft_strcpy.s"; diff --git a/test/ft_strdup_test.c b/test/ft_strdup_test.c index f15dedd..a53e58f 100644 --- a/test/ft_strdup_test.c +++ b/test/ft_strdup_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:06 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:08:07 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:45:00 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,8 @@ static char *tmp; free(tmp); \ } while (0); -static void -ft_strdup_test_segfault(void) +static +void ft_strdup_test_segfault(void) { char *tmp2 = NULL; char a; @@ -51,8 +51,8 @@ tortor, sit amet consequat amet.")); TEST_ASM_FUNCTION(a = *tmp2); } -static void -ft_strdup_test_compare(void) +static +void ft_strdup_test_compare(void) { FT_STRDUP_EXPECT(""); FT_STRDUP_EXPECT("abc"); @@ -69,9 +69,7 @@ tortor, sit amet consequat amet."); FT_STRDUP_EXPECT("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0b\x0c\x0d\x0e\x0f"); } - -void -ft_strdup_test(void) +void ft_strdup_test(void) { test_name = "ft_strdup.s"; diff --git a/test/ft_strlen_test.c b/test/ft_strlen_test.c index e92f668..06796b4 100644 --- a/test/ft_strlen_test.c +++ b/test/ft_strlen_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:53 by cacharle #+# #+# */ -/* Updated: 2020/04/12 20:08:55 by charles ### ########.fr */ +/* Updated: 2020/04/13 14:41:19 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,8 @@ int expected; print_ok(); \ } while (0); -static void -ft_strlen_test_segfault(void) +static +void ft_strlen_test_segfault(void) { TEST_ASM_FUNCTION(ft_strlen("")); TEST_ASM_FUNCTION(ft_strlen("bon")); @@ -42,8 +42,8 @@ ac tortor et lectus fermentum lobortis eu at mauris. Vestibulum sit amet posuere tortor, sit amet consequat amet.")); } -static void -ft_strlen_test_compare(void) +static +void ft_strlen_test_compare(void) { FT_STRLEN_EXPECT(""); FT_STRLEN_EXPECT("bon"); @@ -59,8 +59,7 @@ ac tortor et lectus fermentum lobortis eu at mauris. Vestibulum sit amet posuere tortor, sit amet consequat amet."); } -void -ft_strlen_test(void) +void ft_strlen_test(void) { test_name = "ft_strlen.s"; ft_strlen_test_segfault(); diff --git a/test/ft_write_test.c b/test/ft_write_test.c index d3847e8..57b1b0b 100644 --- a/test/ft_write_test.c +++ b/test/ft_write_test.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:07:48 by cacharle #+# #+# */ -/* Updated: 2020/02/23 06:24:55 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:51:39 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ #define FT_WRITE_BUF_SIZE (1 << 12) static int ft_write_pipe[2]; -static char buf[FT_WRITE_BUF_SIZE]; +static char buf[FT_WRITE_BUF_SIZE] = {0}; static unsigned long write_ret; static int ret; @@ -27,8 +27,8 @@ static int ret; ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \ buf[ret] = '\0'; \ if (strcmp(buf, str) != 0 || write_ret != strlen(str)) \ - printf("KO: [COMPARE]: %s: expected: %lu \"%s\" got: %lu \"%s\"\n", \ - test_name, strlen(str), str, write_ret, buf); \ + printf("KO: [COMPARE]: %s: expected: %lu \"%s\" got: %lu \"%s\" with: %d, \"%s\", %zu \n", \ + test_name, strlen(str), str, write_ret, buf, ft_write_pipe[0], buf, strlen(str)); \ else \ print_ok(); \ close(ft_write_pipe[1]); \ @@ -38,14 +38,14 @@ static int ret; #define FT_WRITE_EXPECT_ERROR(fd, str, size) do { \ write_ret = ft_write(fd, str, size); \ if ((long)write_ret != -1) \ - printf("KO: [COMPARE]: %s: expected: %ld got: %ld\n", \ - test_name, -1l, (long)write_ret); \ + printf("KO: [COMPARE]: %s: expected: %ld got: %ld with: %d "#str", %d\n", \ + test_name, -1l, (long)write_ret, fd, size); \ else \ print_ok(); \ } while (0); -void -ft_write_test_segfault(void) +static +void ft_write_test_segfault(void) { int tmp[2]; if (pipe(tmp) < 0) @@ -65,8 +65,8 @@ ft_write_test_segfault(void) TEST_ASM_FUNCTION(ft_write(OPEN_MAX + 1, "tt", 2)); } -void -ft_write_test_compare(void) +static +void ft_write_test_compare(void) { FT_WRITE_EXPECT(""); FT_WRITE_EXPECT("bon"); @@ -80,7 +80,7 @@ volutpat, eros eget rhoncus rhoncus, diam augue egestas dolor, vitae rutrum nisi felis sed purus. Mauris magna ex, mollis non suscipit eu, lacinia ac turpis. Phasellus\ ac tortor et lectus fermentum lobortis eu at mauris. Vestibulum sit amet posuere\ tortor, sit amet consequat amet."); - + FT_WRITE_EXPECT_ERROR(STDOUT_FILENO, NULL, 3); FT_WRITE_EXPECT_ERROR(-1, "bonjour", 7); FT_WRITE_EXPECT_ERROR(42, "bonjour", 7); @@ -89,8 +89,7 @@ tortor, sit amet consequat amet."); FT_WRITE_EXPECT_ERROR(42, NULL, 7); } -void -ft_write_test(void) +void ft_write_test(void) { test_name = "ft_write.s"; |
