diff options
Diffstat (limited to 'test/ft_write_test.c')
| -rw-r--r-- | test/ft_write_test.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/test/ft_write_test.c b/test/ft_write_test.c index 57b1b0b..f961791 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/04/13 14:51:39 by charles ### ########.fr */ +/* Updated: 2020/05/04 16:06:28 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,17 +16,25 @@ static int ft_write_pipe[2]; static char buf[FT_WRITE_BUF_SIZE] = {0}; -static unsigned long write_ret; -static int ret; +static ssize_t write_ret; +static ssize_t write_origin_ret; +static int write_errno; +static int write_origin_errno; +static ssize_t 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); \ - write_ret = ft_write(ft_write_pipe[1], str, strlen(str)); \ + ERRNO_WRAP(write_origin_ret = write(ft_write_pipe[1], str, strlen(str)), write_origin_errno); \ + read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \ + ERRNO_WRAP(write_ret = ft_write(ft_write_pipe[1], str, strlen(str)), write_errno); \ ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \ buf[ret] = '\0'; \ - if (strcmp(buf, str) != 0 || write_ret != strlen(str)) \ + if (write_errno != write_origin_errno) \ + printf("KO: [COMPARE]: %s: expected: errno %d got: errno %d with: "#str"\n", \ + test_name, write_origin_errno, write_errno); \ + else if (strcmp(buf, str) != 0 || write_ret != write_origin_ret) \ 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 \ @@ -35,13 +43,17 @@ static int ret; close(ft_write_pipe[0]); \ } while (0); -#define FT_WRITE_EXPECT_ERROR(fd, str, size) do { \ - write_ret = ft_write(fd, str, size); \ - if ((long)write_ret != -1) \ +#define FT_WRITE_EXPECT_ERROR(fd, str, size) do { \ + ERRNO_WRAP(write_ret = ft_write(fd, str, size), write_errno); \ + ERRNO_WRAP(write_origin_ret = write(fd, str, size), write_origin_errno); \ + if ((long)write_ret != -1) \ printf("KO: [COMPARE]: %s: expected: %ld got: %ld with: %d "#str", %d\n", \ test_name, -1l, (long)write_ret, fd, size); \ - else \ - print_ok(); \ + else if (write_errno != write_origin_errno) \ + printf("KO: [COMPARE]: %s: expected: errno %d got: errno %d with: %d "#str", %d\n", \ + test_name, write_origin_errno, write_errno, fd, size); \ + else \ + print_ok(); \ } while (0); static @@ -71,7 +83,7 @@ void ft_write_test_compare(void) FT_WRITE_EXPECT(""); FT_WRITE_EXPECT("bon"); FT_WRITE_EXPECT("bonjour"); - FT_WRITE_EXPECT("%c%s%p%x%X%e%f%g"); + FT_WRITE_EXPECT("#c#s#p#x#X#e#f#g"); FT_WRITE_EXPECT("the\0hidden"); FT_WRITE_EXPECT("Lorem ipsum dolor sit amet, consectetur adipiscing\ elit. Sed in malesuada purus. Etiam a scelerisque massa. Ut non euismod elit. Aliquam\ |
