diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-09-10 23:57:26 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-09-10 23:57:26 +0200 |
| commit | 28c6425e4ed1cd2eab538e7cba08c18aa83d8af5 (patch) | |
| tree | 311d9745ecc7f9ef8f95c2705c44530d0330c26b /test/io.cc | |
| parent | ac878281d42b9e5291f96204283c65229c8f392a (diff) | |
Improve test coverage of io and unicode
Diffstat (limited to 'test/io.cc')
| -rw-r--r-- | test/io.cc | 60 |
1 files changed, 59 insertions, 1 deletions
@@ -1,6 +1,7 @@ #include <gtest/gtest.h> #include "io.hh" +#include "io_test_helper.hh" #include <cstdlib> #include <cerrno> @@ -105,7 +106,7 @@ class IoTest : public testing::Test { } private: - int dirfd_; + int dirfd_{-1}; std::string tmpdir_; }; @@ -128,6 +129,16 @@ TEST_F(IoTest, read_empty) { EXPECT_EQ(0, ret2.value()); } +TEST_F(IoTest, skip_empty) { + touch("test"); + + auto ret = io::openat(dirfd(), "test"); + ASSERT_TRUE(ret.has_value()); + auto ret2 = ret.value()->skip(10); + ASSERT_TRUE(ret2.has_value()); + EXPECT_EQ(0, ret2.value()); +} + TEST_F(IoTest, read) { touch("test", "hello world"); @@ -140,3 +151,50 @@ TEST_F(IoTest, read) { tmp.resize(ret2.value()); EXPECT_EQ("hello world", tmp); } + +TEST_F(IoTest, skip) { + touch("test", "hello world"); + + auto ret = io::openat(dirfd(), "test"); + ASSERT_TRUE(ret.has_value()); + auto ret2 = ret.value()->repeat_skip(6); + ASSERT_TRUE(ret2.has_value()); + EXPECT_EQ(6, ret2.value()); + std::string tmp(12, ' '); + auto ret3 = ret.value()->repeat_read(tmp); + ASSERT_TRUE(ret3.has_value()); + EXPECT_EQ(5, ret3.value()); + tmp.resize(ret3.value()); + EXPECT_EQ("world", tmp); +} + +TEST_F(IoTest, read_block) { + touch("test", "hello world"); + + auto ret = io::openat(dirfd(), "test"); + ASSERT_TRUE(ret.has_value()); + auto ret2 = io_make_max_block(std::move(ret.value()), 2); + std::string tmp(12, ' '); + auto ret3 = ret2->repeat_read(tmp); + ASSERT_TRUE(ret3.has_value()); + EXPECT_EQ(11, ret3.value()); + tmp.resize(ret3.value()); + EXPECT_EQ("hello world", tmp); +} + +TEST_F(IoTest, skip_block) { + touch("test", "hello world"); + + auto ret = io::openat(dirfd(), "test"); + ASSERT_TRUE(ret.has_value()); + auto ret2 = io_make_max_block(std::move(ret.value()), 2); + auto ret3 = ret2->repeat_skip(6); + ASSERT_TRUE(ret3.has_value()); + EXPECT_EQ(6, ret3.value()); + std::string tmp(12, ' '); + auto ret4 = ret2->repeat_read(tmp); + ASSERT_TRUE(ret4.has_value()); + EXPECT_EQ(5, ret4.value()); + tmp.resize(ret4.value()); + EXPECT_EQ("world", tmp); +} |
