Add test cases for rename
This commit is contained in:
parent
1f96474e01
commit
03ccead85b
@ -62,7 +62,7 @@ void CryNode::rename(const bf::path &to) {
|
|||||||
if (old == boost::none) {
|
if (old == boost::none) {
|
||||||
throw FuseErrnoException(EIO);
|
throw FuseErrnoException(EIO);
|
||||||
}
|
}
|
||||||
std::string oldName = old->name(); // Store, because the next line invalidates the 'old' object
|
std::string oldName = old->name(); // Store, because if targetDir == *_parent, then the 'old' object will be invalidated after we add something to targetDir
|
||||||
if (oldName != to.filename().native()) {
|
if (oldName != to.filename().native()) {
|
||||||
targetDir->AddChild(to.filename().native(), old->key(), old->type(), old->mode(), old->uid(), old->gid(),
|
targetDir->AddChild(to.filename().native(), old->key(), old->type(), old->mode(), old->uid(), old->gid(),
|
||||||
old->lastAccessTime(), old->lastModificationTime());
|
old->lastAccessTime(), old->lastModificationTime());
|
||||||
|
@ -25,6 +25,20 @@ public:
|
|||||||
EXPECT_NE(boost::none, this->device->Load("/oldname"));
|
EXPECT_NE(boost::none, this->device->Load("/oldname"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Test_Rename_TargetParentDirIsFile() {
|
||||||
|
auto node = CreateNode("/oldname");
|
||||||
|
CreateFile("/somefile");
|
||||||
|
try {
|
||||||
|
node->rename("/somefile/newname");
|
||||||
|
EXPECT_TRUE(false); // Expect it throws an exception
|
||||||
|
} catch (const fspp::fuse::FuseErrnoException &e) {
|
||||||
|
EXPECT_EQ(ENOTDIR, e.getErrno());
|
||||||
|
}
|
||||||
|
//Files should still exist
|
||||||
|
EXPECT_NE(boost::none, this->device->Load("/oldname"));
|
||||||
|
EXPECT_NE(boost::none, this->device->Load("/somefile"));
|
||||||
|
}
|
||||||
|
|
||||||
void Test_Rename_InRoot() {
|
void Test_Rename_InRoot() {
|
||||||
auto node = CreateNode("/oldname");
|
auto node = CreateNode("/oldname");
|
||||||
node->rename("/newname");
|
node->rename("/newname");
|
||||||
@ -71,10 +85,24 @@ public:
|
|||||||
EXPECT_NE(boost::none, this->device->Load("/oldname"));
|
EXPECT_NE(boost::none, this->device->Load("/oldname"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Test_Rename_RootDir() {
|
||||||
|
auto root = this->LoadDir("/");
|
||||||
|
try {
|
||||||
|
root->rename("/newname");
|
||||||
|
EXPECT_TRUE(false); // expect throws
|
||||||
|
} catch (const fspp::fuse::FuseErrnoException &e) {
|
||||||
|
EXPECT_EQ(EBUSY, e.getErrno());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateDir(const boost::filesystem::path &path) {
|
void CreateDir(const boost::filesystem::path &path) {
|
||||||
this->LoadDir(path.parent_path())->createDir(path.filename().native(), this->MODE_PUBLIC, 0, 0);
|
this->LoadDir(path.parent_path())->createDir(path.filename().native(), this->MODE_PUBLIC, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreateFile(const boost::filesystem::path &path) {
|
||||||
|
this->LoadDir(path.parent_path())->createAndOpenFile(path.filename().native(), this->MODE_PUBLIC, 0, 0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
@ -124,12 +152,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
REGISTER_NODE_TEST_CASES(
|
REGISTER_NODE_TEST_CASES(
|
||||||
Rename_TargetParentDirDoesntExist,
|
Rename_TargetParentDirDoesntExist,
|
||||||
|
Rename_TargetParentDirIsFile,
|
||||||
Rename_InRoot,
|
Rename_InRoot,
|
||||||
Rename_InNested,
|
Rename_InNested,
|
||||||
Rename_RootToNested,
|
Rename_RootToNested,
|
||||||
Rename_NestedToRoot,
|
Rename_NestedToRoot,
|
||||||
Rename_NestedToNested,
|
Rename_NestedToNested,
|
||||||
Rename_ToItself
|
Rename_ToItself,
|
||||||
|
Rename_RootDir
|
||||||
);
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user