[unit test] Complete FUSE unit tests #22
This commit is contained in:
@@ -547,6 +547,20 @@ public:
|
|||||||
<< ") failed: " << std::strerror(errno);
|
<< ") failed: " << std::strerror(errno);
|
||||||
return st_unix.st_size;
|
return st_unix.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static auto read_dirnames(DIR *dir) -> std::set<std::string> {
|
||||||
|
std::set<std::string> names;
|
||||||
|
while (auto *entry = ::readdir(dir)) {
|
||||||
|
const auto *name = entry->d_name;
|
||||||
|
if (std::strcmp(name, ".") == 0 || std::strcmp(name, "..") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
names.emplace(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(_WIN32)
|
#endif // !defined(_WIN32)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
118
repertory/repertory_test/src/fuse_drive_directory_test.cpp
Normal file
118
repertory/repertory_test/src/fuse_drive_directory_test.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
|
||||||
|
#include "fixtures/drive_fixture.hpp"
|
||||||
|
|
||||||
|
namespace repertory {
|
||||||
|
TYPED_TEST_SUITE(fuse_test, platform_provider_types);
|
||||||
|
|
||||||
|
TYPED_TEST(fuse_test, directory_can_read_empty_directory) {
|
||||||
|
std::string dir_name{"directory"};
|
||||||
|
auto dir = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto *dir_ptr = ::opendir(dir.c_str());
|
||||||
|
ASSERT_NE(dir_ptr, nullptr);
|
||||||
|
|
||||||
|
auto names = this->read_dirnames(dir_ptr);
|
||||||
|
EXPECT_TRUE(names.empty());
|
||||||
|
|
||||||
|
EXPECT_EQ(0, ::closedir(dir_ptr));
|
||||||
|
this->rmdir_and_test(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(fuse_test, directory_can_read_populated_directory) {
|
||||||
|
std::string dir_name{"directory"};
|
||||||
|
auto dir = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto file_name_1{dir_name + "/file_a"};
|
||||||
|
auto src_1 = this->create_file_and_test(file_name_1);
|
||||||
|
|
||||||
|
auto file_name_2{dir_name + "/file_b"};
|
||||||
|
auto src_2 = this->create_file_and_test(file_name_2);
|
||||||
|
|
||||||
|
auto sub_dir_name{dir_name + "/subdir_a"};
|
||||||
|
auto sub_dir = this->create_directory_and_test(sub_dir_name);
|
||||||
|
|
||||||
|
auto *dir_ptr = ::opendir(dir.c_str());
|
||||||
|
ASSERT_NE(dir_ptr, nullptr);
|
||||||
|
|
||||||
|
auto names = this->read_dirnames(dir_ptr);
|
||||||
|
|
||||||
|
EXPECT_TRUE(names.contains(utils::path::strip_to_file_name(src_1)));
|
||||||
|
EXPECT_TRUE(names.contains(utils::path::strip_to_file_name(src_2)));
|
||||||
|
EXPECT_TRUE(names.contains(utils::path::strip_to_file_name(sub_dir)));
|
||||||
|
|
||||||
|
::rewinddir(dir_ptr);
|
||||||
|
auto names2 = this->read_dirnames(dir_ptr);
|
||||||
|
EXPECT_EQ(names, names2);
|
||||||
|
|
||||||
|
EXPECT_EQ(0, ::closedir(dir_ptr));
|
||||||
|
|
||||||
|
this->unlink_file_and_test(src_1);
|
||||||
|
this->unlink_file_and_test(src_2);
|
||||||
|
this->rmdir_and_test(sub_dir);
|
||||||
|
this->rmdir_and_test(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(fuse_test, directory_opendir_fails_for_file) {
|
||||||
|
std::string file_name{"directory"};
|
||||||
|
auto src = this->create_file_and_test(file_name);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
auto *dir_ptr = ::opendir(src.c_str());
|
||||||
|
EXPECT_EQ(dir_ptr, nullptr);
|
||||||
|
EXPECT_EQ(errno, ENOTDIR);
|
||||||
|
|
||||||
|
this->unlink_file_and_test(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(fuse_test, directory_opendir_fails_if_directory_does_not_exist) {
|
||||||
|
std::string file_name{"directory"};
|
||||||
|
auto dir = this->create_file_path(file_name);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
auto *dir_ptr = ::opendir(dir.c_str());
|
||||||
|
EXPECT_EQ(dir_ptr, nullptr);
|
||||||
|
EXPECT_EQ(errno, ENOENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(fuse_test, directory_can_opendir_after_closedir) {
|
||||||
|
std::string dir_name{"directory"};
|
||||||
|
auto dir = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto *dir_ptr = ::opendir(dir.c_str());
|
||||||
|
ASSERT_NE(dir_ptr, nullptr);
|
||||||
|
|
||||||
|
(void)this->read_dirnames(dir_ptr);
|
||||||
|
|
||||||
|
EXPECT_EQ(0, ::closedir(dir_ptr));
|
||||||
|
|
||||||
|
dir_ptr = ::opendir(dir.c_str());
|
||||||
|
ASSERT_NE(dir_ptr, nullptr);
|
||||||
|
EXPECT_EQ(0, ::closedir(dir_ptr));
|
||||||
|
|
||||||
|
this->rmdir_and_test(dir);
|
||||||
|
}
|
||||||
|
} // namespace repertory
|
||||||
|
|
||||||
|
#endif // !defined(_WIN32)
|
||||||
@@ -105,6 +105,11 @@ TYPED_TEST(fuse_test, fallocate_then_ftruncate_makes_size_visible) {
|
|||||||
EXPECT_EQ(0, ::ftruncate(desc, len));
|
EXPECT_EQ(0, ::ftruncate(desc, len));
|
||||||
#else // !defined(__APPLE__)
|
#else // !defined(__APPLE__)
|
||||||
auto res = ::posix_fallocate(desc, 0, len);
|
auto res = ::posix_fallocate(desc, 0, len);
|
||||||
|
if (res == EOPNOTSUPP) {
|
||||||
|
::close(desc);
|
||||||
|
this->unlink_file_and_test(src);
|
||||||
|
return;
|
||||||
|
}
|
||||||
EXPECT_EQ(0, res);
|
EXPECT_EQ(0, res);
|
||||||
EXPECT_EQ(0, ::ftruncate(desc, len / 2));
|
EXPECT_EQ(0, ::ftruncate(desc, len / 2));
|
||||||
EXPECT_EQ(0, ::ftruncate(desc, len));
|
EXPECT_EQ(0, ::ftruncate(desc, len));
|
||||||
|
|||||||
Reference in New Issue
Block a user