diff --git a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp index 03a453c6..ed184b42 100644 --- a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp @@ -469,6 +469,139 @@ TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) { this->rmdir_and_test(dir_path); } + +// 4. O_CREAT | O_APPEND-Failure: ENOENT (No such file or directory) if the +// parent directory doesn’t exist. +TYPED_TEST(fuse_test, create_fails_with_append_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_APPEND, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(ENOENT, errno); +} + +// 4. O_CREAT | O_APPEND-Failure: EISDIR (Is a directory) if a directory exists +// instead of a file. +TYPED_TEST(fuse_test, create_fails_with_append_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_APPEND, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EISDIR, errno); + + this->rmdir_and_test(dir_path); +} + +// 5. O_CREAT | O_RDWR-Failure: ENOENT (No such file or directory) if the +// parent directory doesn’t exist. +TYPED_TEST(fuse_test, create_fails_with_rdrw_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_RDWR, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(ENOENT, errno); +} + +// 5. O_CREAT | O_RDWR-Failure: EISDIR (Is a directory) if a directory exists +// instead of a file. +TYPED_TEST(fuse_test, create_fails_with_rdrw_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_RDWR, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EISDIR, errno); + + this->rmdir_and_test(dir_path); +} + +// 6. O_CREAT | O_WRONLY-Failure: ENOENT (No such file or directory) if the +// parent directory doesn’t exist. +TYPED_TEST(fuse_test, create_fails_with_wo_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_WRONLY, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(ENOENT, errno); +} + +// 6. O_CREAT | O_WRONLY-Failure: EISDIR (Is a directory) if a directory exists +// instead of a file. +TYPED_TEST(fuse_test, create_fails_with_wo_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_WRONLY, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EISDIR, errno); + + this->rmdir_and_test(dir_path); +} + +// 7. O_CREAT | O_TRUNC | O_WRONLY-Failure: ENOENT (No such file or directory) +// if the parent directory doesn’t exist. +TYPED_TEST(fuse_test, create_fails_with_trunc_wo_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 | O_WRONLY, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(ENOENT, errno); +} + +// 7. O_CREAT | O_TRUNC | O_WRONLY-Failure: EISDIR (Is a directory) if a +// directory exists instead of a file. +TYPED_TEST(fuse_test, create_fails_with_trunc_wo_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 | O_WRONLY, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EISDIR, errno); + + this->rmdir_and_test(dir_path); +} + +// 8. O_CREAT | O_TRUNC | O_RDWR-Failure: ENOENT (No such file or directory) +// if the parent directory doesn’t exist. +TYPED_TEST(fuse_test, create_fails_with_trunc_rw_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 | O_RDWR, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(ENOENT, errno); +} + +// 8. O_CREAT | O_TRUNC | O_RDWR-Failure: EISDIR (Is a directory) if a +// directory exists instead of a file. +TYPED_TEST(fuse_test, create_fails_with_trunc_rw_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 | O_RDWR, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EISDIR, errno); + + this->rmdir_and_test(dir_path); +} } // namespace repertory #endif // !defined(_WIN32)