6
6
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2020/02/08 03:07:48 by cacharle #+# #+# */
9
- /* Updated: 2020/04/13 14:51:39 by charles ### ########.fr */
9
+ /* Updated: 2020/05/01 10:09:41 by charles ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
17
17
static int ft_write_pipe [2 ];
18
18
static char buf [FT_WRITE_BUF_SIZE ] = {0 };
19
19
static unsigned long write_ret ;
20
+ static unsigned long write_origin_ret ;
21
+ static unsigned long write_errno ;
22
+ static unsigned long write_origin_errno ;
20
23
static int ret ;
21
24
22
25
#define FT_WRITE_EXPECT (str ) do { \
23
26
if (pipe(ft_write_pipe) < 0) \
24
27
exit(EXIT_FAILURE); \
25
28
fcntl(ft_write_pipe[0], F_SETFL, O_NONBLOCK); \
29
+ write_origin_errno = 0; \
30
+ write_origin_ret = write(ft_write_pipe[1], str, strlen(str)); \
31
+ write_origin_errno = errno; \
32
+ ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \
33
+ write_errno = 0; \
26
34
write_ret = ft_write(ft_write_pipe[1], str, strlen(str)); \
35
+ write_errno = errno; \
27
36
ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \
28
37
buf[ret] = '\0'; \
29
- if (strcmp(buf, str) != 0 || write_ret != strlen(str)) \
38
+ if (write_errno != write_origin_errno) \
39
+ printf("KO: [COMPARE]: %s: expected: errno %ld got: errno %ld with: "#str"\n", \
40
+ test_name, write_origin_errno, write_errno); \
41
+ else if (strcmp(buf, str) != 0 || write_ret != strlen(str)) \
30
42
printf("KO: [COMPARE]: %s: expected: %lu \"%s\" got: %lu \"%s\" with: %d, \"%s\", %zu \n", \
31
43
test_name, strlen(str), str, write_ret, buf, ft_write_pipe[0], buf, strlen(str)); \
32
44
else \
@@ -36,10 +48,18 @@ static int ret;
36
48
} while (0);
37
49
38
50
#define FT_WRITE_EXPECT_ERROR (fd , str , size ) do { \
51
+ write_errno = 0; \
39
52
write_ret = ft_write(fd, str, size); \
53
+ write_errno = errno; \
54
+ write_origin_errno = 0; \
55
+ write_origin_ret = write(fd, str, size); \
56
+ write_origin_errno = errno; \
40
57
if ((long)write_ret != -1) \
41
58
printf("KO: [COMPARE]: %s: expected: %ld got: %ld with: %d "#str", %d\n", \
42
59
test_name, -1l, (long)write_ret, fd, size); \
60
+ else if (write_errno != write_origin_errno) \
61
+ printf("KO: [COMPARE]: %s: expected: errno %ld got: errno %ld with: %d "#str", %d\n", \
62
+ test_name, write_origin_errno, write_errno, fd, size); \
43
63
else \
44
64
print_ok(); \
45
65
} while (0);
@@ -71,7 +91,7 @@ void ft_write_test_compare(void)
71
91
FT_WRITE_EXPECT ("" );
72
92
FT_WRITE_EXPECT ("bon" );
73
93
FT_WRITE_EXPECT ("bonjour" );
74
- FT_WRITE_EXPECT ("%c%s%p%x%X%e%f% g" );
94
+ FT_WRITE_EXPECT ("#c#s#p#x#X#e#f# g" );
75
95
FT_WRITE_EXPECT ("the\0hidden" );
76
96
FT_WRITE_EXPECT ("Lorem ipsum dolor sit amet, consectetur adipiscing\
77
97
elit. Sed in malesuada purus. Etiam a scelerisque massa. Ut non euismod elit. Aliquam\
0 commit comments