William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 1 | #include <fmt/compile.h> |
Patrick Williams | d1984dd | 2023-05-10 16:12:44 -0500 | [diff] [blame] | 2 | #include <sys/mman.h> |
| 3 | |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 4 | #include <stdplus/fd/fmt.hpp> |
| 5 | #include <stdplus/fd/managed.hpp> |
| 6 | #include <stdplus/util/cexec.hpp> |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 7 | |
William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <string_view> |
| 10 | |
Patrick Williams | d1984dd | 2023-05-10 16:12:44 -0500 | [diff] [blame] | 11 | #include <gtest/gtest.h> |
| 12 | |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 13 | namespace stdplus |
| 14 | { |
| 15 | namespace fd |
| 16 | { |
| 17 | |
William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 18 | using std::literals::string_view_literals::operator""sv; |
| 19 | |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 20 | TEST(FormatBuffer, Basic) |
| 21 | { |
| 22 | auto fd = ManagedFd(CHECK_ERRNO(memfd_create("test", 0), "memfd_create")); |
| 23 | { |
| 24 | FormatBuffer buf(fd, 4096); |
William A. Kennington III | 8bd9251 | 2023-07-24 18:09:55 -0700 | [diff] [blame^] | 25 | buf.appends("hi\n", "hi\n"sv); |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 26 | EXPECT_EQ(0, fd.lseek(0, Whence::Cur)); |
| 27 | buf.flush(); |
| 28 | |
William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 29 | EXPECT_EQ(6, fd.lseek(0, Whence::Cur)); |
| 30 | buf.append(FMT_COMPILE("{}"), std::string(2050, 'a')); |
| 31 | EXPECT_EQ(6, fd.lseek(0, Whence::Cur)); |
William A. Kennington III | 8bd9251 | 2023-07-24 18:09:55 -0700 | [diff] [blame^] | 32 | buf.append("{}", std::string(2050, 'a')); |
William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 33 | EXPECT_EQ(4106, fd.lseek(0, Whence::Cur)); |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 34 | |
William A. Kennington III | 8bd9251 | 2023-07-24 18:09:55 -0700 | [diff] [blame^] | 35 | buf.appends("hi\n"); |
William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 36 | EXPECT_EQ(4106, fd.lseek(0, Whence::Cur)); |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 37 | } |
William A. Kennington III | 74755ce | 2022-08-19 17:14:52 -0700 | [diff] [blame] | 38 | EXPECT_EQ(4109, fd.lseek(0, Whence::Cur)); |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 39 | } |
| 40 | |
William A. Kennington III | 4f5711c | 2022-08-12 17:01:53 -0700 | [diff] [blame] | 41 | } // namespace fd |
| 42 | } // namespace stdplus |