-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathputnbr_fd.cpp
More file actions
105 lines (86 loc) · 2.7 KB
/
Copy pathputnbr_fd.cpp
File metadata and controls
105 lines (86 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putnbr_fd.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjurkows <kjurkows@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/18 21:32:51 by kjurkows #+# #+# */
/* Updated: 2026/07/03 13:54:54 by kjurkows ### ########.fr */
/* */
/* ************************************************************************** */
#include "_main.hpp"
#include <fcntl.h>
#include <unistd.h>
TEST(putnbr_fd, 42)
{
int n = 42;
int fd = open("/tmp/tests/putnbr_fd_42.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ft_putnbr_fd(n, fd);
close(fd);
char out[10] = {0};
fd = open("/tmp/tests/putnbr_fd_42.txt", O_RDONLY);
read(fd, out, 9);
close(fd);
ASSERT_STREQ(out, "42");
}
TEST(putnbr_fd, 0)
{
int n = 0;
int fd = open("/tmp/tests/putnbr_fd_0.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ft_putnbr_fd(n, fd);
close(fd);
char out[10] = {0};
fd = open("/tmp/tests/putnbr_fd_0.txt", O_RDONLY);
read(fd, out, 9);
close(fd);
ASSERT_STREQ(out, "0");
}
TEST(putnbr_fd, neg1)
{
int n = -1;
int fd = open("/tmp/tests/putnbr_fd_neg.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ft_putnbr_fd(n, fd);
close(fd);
char out[10] = {0};
fd = open("/tmp/tests/putnbr_fd_neg.txt", O_RDONLY);
read(fd, out, 9);
close(fd);
ASSERT_STREQ(out, "-1");
}
TEST(putnbr_fd, neg42)
{
int n = -42;
int fd = open("/tmp/tests/putnbr_fd_neg42.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ft_putnbr_fd(n, fd);
close(fd);
char out[10] = {0};
fd = open("/tmp/tests/putnbr_fd_neg42.txt", O_RDONLY);
read(fd, out, 9);
close(fd);
ASSERT_STREQ(out, "-42");
}
TEST(putnbr_fd, int_min)
{
int n = -2147483648;
int fd = open("/tmp/tests/putnbr_fd_int_min.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ft_putnbr_fd(n, fd);
close(fd);
char out[20] = {0};
fd = open("/tmp/tests/putnbr_fd_int_min.txt", O_RDONLY);
read(fd, out, 19);
close(fd);
ASSERT_STREQ(out, "-2147483648");
}
TEST(putnbr_fd, int_max)
{
int n = 2147483647;
int fd = open("/tmp/tests/putnbr_fd_int_max.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ft_putnbr_fd(n, fd);
close(fd);
char out[20] = {0};
fd = open("/tmp/tests/putnbr_fd_int_max.txt", O_RDONLY);
read(fd, out, 19);
close(fd);
ASSERT_STREQ(out, "2147483647");
}