blob: 726b5e532226f65334f48f59f1d36d9a38cc189f [file] [log] [blame]
William A. Kennington III4f5711c2022-08-12 17:01:53 -07001#include <gtest/gtest.h>
2
3#include <stdplus/fd/fmt.hpp>
4#include <stdplus/fd/managed.hpp>
5#include <stdplus/util/cexec.hpp>
6#include <sys/mman.h>
7
8namespace stdplus
9{
10namespace fd
11{
12
13TEST(FormatBuffer, Basic)
14{
15 auto fd = ManagedFd(CHECK_ERRNO(memfd_create("test", 0), "memfd_create"));
16 {
17 FormatBuffer buf(fd, 4096);
18 buf.append("hi\n");
19 EXPECT_EQ(0, fd.lseek(0, Whence::Cur));
20 buf.flush();
21
22 EXPECT_EQ(3, fd.lseek(0, Whence::Cur));
23 buf.append("{}", std::string(2050, 'a'));
24 EXPECT_EQ(3, fd.lseek(0, Whence::Cur));
25 buf.append("{}", std::string(2050, 'a'));
26 EXPECT_EQ(4103, fd.lseek(0, Whence::Cur));
27
28 buf.append("hi\n");
29 EXPECT_EQ(4103, fd.lseek(0, Whence::Cur));
30 }
31 EXPECT_EQ(4106, fd.lseek(0, Whence::Cur));
32}
33
34} // namespace fd
35} // namespace stdplus