diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ft_list_push_front_test.c | 49 | ||||
| -rw-r--r-- | test/ft_list_size_test.c | 44 | ||||
| -rw-r--r-- | test/ft_read_test.c | 27 | ||||
| -rw-r--r-- | test/ft_write_test.c | 28 |
4 files changed, 116 insertions, 32 deletions
diff --git a/test/ft_list_push_front_test.c b/test/ft_list_push_front_test.c index 411194e..2f9cf59 100644 --- a/test/ft_list_push_front_test.c +++ b/test/ft_list_push_front_test.c @@ -1,17 +1,60 @@ #include "libasm_test.h" +static t_list *tmp; +static t_list *expected; +static t_list *actual; + +#define FT_LIST_PUSH_FRONT_EXPECT(fmt, push) do { \ + 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); \ +} while (0); + 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)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3 4 10"); ft_list_push_front(&tmp, create_data_elem(1)); list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("111234 1234 1112"); ft_list_push_front(&tmp, create_data_elem(7)); list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2"); ft_list_push_front(&tmp, create_data_elem(0)); list_destroy(tmp)); + TEST_ASM_FUNCTION( + tmp = list_from_format("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"); + ft_list_push_front(tmp, create_data_elem(4)); + ft_list_push_front(tmp, create_data_elem(4)); + ft_list_push_front(tmp, create_data_elem(4)); + ft_list_push_front(tmp, create_data_elem(4)); + list_destroy(tmp); + ); } + static void ft_list_push_front_compare(void) { - + FT_LIST_PUSH_FRONT_EXPECT("", 0); + FT_LIST_PUSH_FRONT_EXPECT("", 1); + FT_LIST_PUSH_FRONT_EXPECT("0", 1); + FT_LIST_PUSH_FRONT_EXPECT("1 2 3", 4); + FT_LIST_PUSH_FRONT_EXPECT("1 2 3", -1); + 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) { - + test_name = "ft_list_push_front.s"; + ft_list_push_front_segfault(); + if (!signaled) + ft_list_push_front_compare(); } diff --git a/test/ft_list_size_test.c b/test/ft_list_size_test.c index 80394d7..5c36095 100644 --- a/test/ft_list_size_test.c +++ b/test/ft_list_size_test.c @@ -1,17 +1,55 @@ #include "libasm_test.h" +static t_list *tmp; +static int expected; +static int actual; + +#define FT_LIST_SIZE_EXPECT(fmt) do { \ + tmp = list_from_format(fmt); \ + expected = ref_ft_list_size(tmp); \ + actual = ft_list_size(tmp); \ + if (expected != actual) { \ + printf("KO: [COMPARE]: %s: expected: %d ", \ + test_name, expected); \ + list_print(tmp); \ + printf(" got: %d\n", actual); \ + } else \ + print_ok(); \ + list_destroy(tmp); \ +} while (0); + 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)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3 4 10"); ft_list_size(tmp); list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("111234 1234 1112"); ft_list_size(tmp); list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2"); ft_list_size(tmp); list_destroy(tmp)); + TEST_ASM_FUNCTION( + tmp = list_from_format("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"); + ft_list_size(tmp); + list_destroy(tmp) + ); } + static void ft_list_size_compare(void) { - + FT_LIST_SIZE_EXPECT("1 2 3"); + FT_LIST_SIZE_EXPECT(""); + FT_LIST_SIZE_EXPECT("1 2 3 4 10"); + FT_LIST_SIZE_EXPECT("19879 123 12344"); + FT_LIST_SIZE_EXPECT("1"); + FT_LIST_SIZE_EXPECT("1 2"); + 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) { - + test_name = "ft_list_size.s"; + ft_list_size_segfault(); + if (!signaled) + ft_list_size_compare(); } diff --git a/test/ft_read_test.c b/test/ft_read_test.c index 50a85bd..5b29803 100644 --- a/test/ft_read_test.c +++ b/test/ft_read_test.c @@ -6,19 +6,20 @@ static int ft_read_pipe[2]; static char buf[FT_READ_BUF_SIZE]; static int ret; -#define FT_READ_EXPECT(str) do { \ - if (pipe(ft_read_pipe) < 0) \ - exit(EXIT_FAILURE); \ - fcntl(ft_read_pipe[0], F_SETFL, O_NONBLOCK); \ - write(ft_read_pipe[1], str, strlen(str)); \ - ret = ft_read(ft_read_pipe[0], buf, FT_READ_BUF_SIZE); \ - buf[ret] = '\0'; \ - if (strcmp(buf, str) != 0) \ - printf("KO: [COMPARE]: %s: expected: \"%s\" got: \"%s\"\n", test_name, str, buf); \ - else \ - print_ok(); \ - close(ft_read_pipe[1]); \ - close(ft_read_pipe[0]); \ +#define FT_READ_EXPECT(str) do { \ + if (pipe(ft_read_pipe) < 0) \ + exit(EXIT_FAILURE); \ + fcntl(ft_read_pipe[0], F_SETFL, O_NONBLOCK); \ + write(ft_read_pipe[1], str, strlen(str)); \ + 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); \ + else \ + print_ok(); \ + close(ft_read_pipe[1]); \ + close(ft_read_pipe[0]); \ } while (0); void diff --git a/test/ft_write_test.c b/test/ft_write_test.c index 1c14244..c44625e 100644 --- a/test/ft_write_test.c +++ b/test/ft_write_test.c @@ -4,21 +4,23 @@ static int ft_write_pipe[2]; static char buf[FT_WRITE_BUF_SIZE]; +static unsigned long write_ret; static int ret; -#define FT_WRITE_EXPECT(str) do { \ - if (pipe(ft_write_pipe) < 0) \ - exit(EXIT_FAILURE); \ - fcntl(ft_write_pipe[0], F_SETFL, O_NONBLOCK); \ - ft_write(ft_write_pipe[1], str, strlen(str)); \ - ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \ - buf[ret] = '\0'; \ - if (strcmp(buf, str) != 0) \ - printf("KO: [COMPARE]: %s: expected: \"%s\" got: \"%s\"\n", test_name, str, buf); \ - else \ - print_ok(); \ - close(ft_write_pipe[1]); \ - close(ft_write_pipe[0]); \ +#define FT_WRITE_EXPECT(str) do { \ + if (pipe(ft_write_pipe) < 0) \ + exit(EXIT_FAILURE); \ + fcntl(ft_write_pipe[0], F_SETFL, O_NONBLOCK); \ + write_ret = ft_write(ft_write_pipe[1], str, strlen(str)); \ + 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); \ + else \ + print_ok(); \ + close(ft_write_pipe[1]); \ + close(ft_write_pipe[0]); \ } while (0); void |
