William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame^] | 1 | #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 | |
| 8 | namespace stdplus |
| 9 | { |
| 10 | namespace fd |
| 11 | { |
| 12 | |
| 13 | TEST(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 |