fuse unit tests and fixes
This commit is contained in:
parent
54b70f99cc
commit
0b7a9c6a56
@ -118,8 +118,8 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
|||||||
|
|
||||||
auto is_create_op = ((file_info->flags & O_CREAT) == O_CREAT);
|
auto is_create_op = ((file_info->flags & O_CREAT) == O_CREAT);
|
||||||
auto is_directory_op = ((file_info->flags & O_DIRECTORY) == O_DIRECTORY);
|
auto is_directory_op = ((file_info->flags & O_DIRECTORY) == O_DIRECTORY);
|
||||||
auto is_truncate_op = ((file_info->flags & O_TRUNC) == O_TRUNC);
|
|
||||||
auto is_exclusive = ((file_info->flags & O_EXCL) == O_EXCL);
|
auto is_exclusive = ((file_info->flags & O_EXCL) == O_EXCL);
|
||||||
|
auto is_truncate_op = ((file_info->flags & O_TRUNC) == O_TRUNC);
|
||||||
|
|
||||||
if (((file_info->flags & O_WRONLY) != 0) ||
|
if (((file_info->flags & O_WRONLY) != 0) ||
|
||||||
((file_info->flags & O_RDWR) != 0)) {
|
((file_info->flags & O_RDWR) != 0)) {
|
||||||
|
@ -378,6 +378,97 @@ TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) {
|
|||||||
|
|
||||||
this->unlink_file_and_test(file_path);
|
this->unlink_file_and_test(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. O_CREAT-Failure: ENOENT (No such file or directory) if the parent
|
||||||
|
// directory doesn’t exist.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_if_parent_does_not_exist) {
|
||||||
|
std::string file_name{"no_dir/create_test"};
|
||||||
|
auto file_path = this->create_file_path(file_name);
|
||||||
|
|
||||||
|
auto handle = open(file_path.c_str(), O_CREAT, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(ENOENT, errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. O_CREAT-Failure: EISDIR (Is a directory) if a directory exists instead of
|
||||||
|
// a file.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_if_path_is_directory) {
|
||||||
|
std::string dir_name{"create_test"};
|
||||||
|
auto dir_path = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto handle = open(dir_path.c_str(), O_CREAT, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(EISDIR, errno);
|
||||||
|
|
||||||
|
this->rmdir_and_test(dir_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. O_CREAT|O_TRUNC-Failure: ENOENT (No such file or directory) if the parent
|
||||||
|
// directory doesn’t exist.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_with_trunc_if_parent_does_not_exist) {
|
||||||
|
std::string file_name{"no_dir/create_test"};
|
||||||
|
auto file_path = this->create_file_path(file_name);
|
||||||
|
|
||||||
|
auto handle = open(file_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(ENOENT, errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. O_CREAT|O_TRUNC-Failure: EISDIR (Is a directory) if a directory exists
|
||||||
|
// instead of a file.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_with_trunc_if_path_is_directory) {
|
||||||
|
std::string dir_name{"create_test"};
|
||||||
|
auto dir_path = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto handle = open(dir_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(EISDIR, errno);
|
||||||
|
|
||||||
|
this->rmdir_and_test(dir_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. O_CREAT|O_EXCL-Failure: ENOENT (No such file or directory) if the parent
|
||||||
|
// directory doesn’t exist.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_with_excl_if_parent_does_not_exist) {
|
||||||
|
std::string file_name{"no_dir/create_test"};
|
||||||
|
auto file_path = this->create_file_path(file_name);
|
||||||
|
|
||||||
|
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(ENOENT, errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. O_CREAT|O_EXCL-Failure: EEXIST (File exists) if the file already exists.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_with_excl_if_file_exists) {
|
||||||
|
std::string file_name{"create_test"};
|
||||||
|
auto file_path = this->create_file_and_test(file_name);
|
||||||
|
|
||||||
|
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(EEXIST, errno);
|
||||||
|
|
||||||
|
this->unlink_file_and_test(file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. O_CREAT|O_EXCL-Failure: EISDIR (Is a directory) if a directory exists
|
||||||
|
// instead of a file.
|
||||||
|
TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) {
|
||||||
|
std::string dir_name{"create_test"};
|
||||||
|
auto dir_path = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto handle = open(dir_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
|
||||||
|
EXPECT_EQ(-1, handle);
|
||||||
|
|
||||||
|
EXPECT_EQ(EISDIR, errno);
|
||||||
|
|
||||||
|
this->rmdir_and_test(dir_path);
|
||||||
|
}
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
#endif // !defined(_WIN32)
|
#endif // !defined(_WIN32)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user