From 28c6425e4ed1cd2eab538e7cba08c18aa83d8af5 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 10 Sep 2025 23:57:26 +0200 Subject: Improve test coverage of io and unicode --- test/io.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'test/io.cc') diff --git a/test/io.cc b/test/io.cc index ad192ed..23c10d4 100644 --- a/test/io.cc +++ b/test/io.cc @@ -1,6 +1,7 @@ #include #include "io.hh" +#include "io_test_helper.hh" #include #include @@ -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); +} -- cgit v1.3