2015-03-16 02:56:40 +01:00
|
|
|
#ifndef MESSMER_FSPP_FSTEST_FSPPDIRTEST_H_
|
|
|
|
#define MESSMER_FSPP_FSTEST_FSPPDIRTEST_H_
|
|
|
|
|
|
|
|
template<class ConcreteFileSystemTestFixture>
|
|
|
|
class FsppDirTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
2015-03-18 01:46:33 +01:00
|
|
|
public:
|
|
|
|
void InitDirStructure() {
|
|
|
|
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/")->createDir("myemptydir", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir")->createAndOpenFile("myfile2", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir/mysubdir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir/mysubdir")->createDir("mysubsubdir", this->MODE_PUBLIC);
|
|
|
|
}
|
2015-03-19 03:52:58 +01:00
|
|
|
|
2015-03-19 04:36:02 +01:00
|
|
|
void EXPECT_CHILDREN_ARE(const boost::filesystem::path &path, const std::initializer_list<fspp::Dir::Entry> expected) {
|
|
|
|
EXPECT_CHILDREN_ARE(*this->LoadDir(path), expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXPECT_CHILDREN_ARE(const fspp::Dir &dir, const std::initializer_list<fspp::Dir::Entry> expected) {
|
2015-03-19 04:24:43 +01:00
|
|
|
std::vector<fspp::Dir::Entry> expectedChildren = expected;
|
|
|
|
expectedChildren.push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, "."));
|
|
|
|
expectedChildren.push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, ".."));
|
2015-03-19 04:36:02 +01:00
|
|
|
EXPECT_UNORDERED_EQ(expectedChildren, *dir.children());
|
2015-03-19 03:52:58 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 04:24:43 +01:00
|
|
|
template<class Entry>
|
|
|
|
void EXPECT_UNORDERED_EQ(const std::vector<Entry> &expected, std::vector<Entry> actual) {
|
|
|
|
EXPECT_EQ(expected.size(), actual.size());
|
|
|
|
for (const Entry &expectedEntry : expected) {
|
|
|
|
removeOne(&actual, expectedEntry);
|
|
|
|
}
|
2015-03-19 03:52:58 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 04:24:43 +01:00
|
|
|
template<class Entry>
|
|
|
|
void removeOne(std::vector<Entry> *entries, const Entry &toRemove) {
|
|
|
|
for (auto iter = entries->begin(); iter != entries->end(); ++iter) {
|
|
|
|
if (iter->type == toRemove.type && iter->name == toRemove.name) {
|
|
|
|
entries->erase(iter);
|
|
|
|
return;
|
2015-03-19 03:52:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
}
|
2015-03-16 02:56:40 +01:00
|
|
|
};
|
|
|
|
TYPED_TEST_CASE_P(FsppDirTest);
|
|
|
|
|
2015-03-19 04:24:43 +01:00
|
|
|
fspp::Dir::Entry DirEntry(const std::string &name) {
|
|
|
|
return fspp::Dir::Entry(fspp::Dir::EntryType::DIR, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
fspp::Dir::Entry FileEntry(const std::string &name) {
|
|
|
|
return fspp::Dir::Entry(fspp::Dir::EntryType::FILE, name);
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) {
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/", {});
|
2015-03-16 02:56:40 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 04:36:02 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile_Directly) {
|
2015-03-16 02:56:40 +01:00
|
|
|
auto rootdir = this->LoadDir("/");
|
2015-03-16 04:53:35 +01:00
|
|
|
rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE(*rootdir, {
|
|
|
|
FileEntry("myfile")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile_AfterReloadingDir) {
|
|
|
|
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/", {
|
2015-03-19 04:24:43 +01:00
|
|
|
FileEntry("myfile")
|
|
|
|
});
|
2015-03-16 02:56:40 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 04:36:02 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir_Directly) {
|
2015-03-16 02:56:40 +01:00
|
|
|
auto rootdir = this->LoadDir("/");
|
2015-03-16 04:53:35 +01:00
|
|
|
rootdir->createDir("mydir", this->MODE_PUBLIC);
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE(*rootdir, {
|
|
|
|
DirEntry("mydir")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir_AfterReloadingDir) {
|
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/", {
|
2015-03-19 04:24:43 +01:00
|
|
|
DirEntry("mydir")
|
|
|
|
});
|
2015-03-16 02:56:40 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) {
|
|
|
|
this->InitDirStructure();
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/", {
|
2015-03-19 04:24:43 +01:00
|
|
|
FileEntry("myfile"),
|
|
|
|
DirEntry("mydir"),
|
|
|
|
DirEntry("myemptydir")
|
|
|
|
});
|
2015-03-18 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_Empty) {
|
2015-03-19 04:36:02 +01:00
|
|
|
this->LoadDir("/")->createDir("myemptydir", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/myemptydir", {});
|
2015-03-18 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) {
|
2015-03-16 04:53:35 +01:00
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
2015-03-16 04:02:45 +01:00
|
|
|
auto dir = this->LoadDir("/mydir");
|
2015-03-16 04:53:35 +01:00
|
|
|
dir->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE(*dir, {
|
2015-03-19 04:24:43 +01:00
|
|
|
FileEntry("myfile")
|
|
|
|
});
|
2015-03-16 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) {
|
2015-03-16 04:53:35 +01:00
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/mydir", {
|
2015-03-19 04:24:43 +01:00
|
|
|
FileEntry("myfile")
|
|
|
|
});
|
2015-03-16 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
|
2015-03-16 04:53:35 +01:00
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
2015-03-16 04:02:45 +01:00
|
|
|
auto dir = this->LoadDir("/mydir");
|
2015-03-16 04:53:35 +01:00
|
|
|
dir->createDir("mysubdir", this->MODE_PUBLIC);
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE(*dir, {
|
2015-03-19 04:24:43 +01:00
|
|
|
DirEntry("mysubdir")
|
|
|
|
});
|
2015-03-16 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) {
|
2015-03-16 04:53:35 +01:00
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
|
|
|
this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC);
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/mydir", {
|
2015-03-19 04:24:43 +01:00
|
|
|
DirEntry("mysubdir")
|
|
|
|
});
|
2015-03-16 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure_Empty) {
|
|
|
|
this->InitDirStructure();
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/myemptydir", {});
|
2015-03-18 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure) {
|
|
|
|
this->InitDirStructure();
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/mydir", {
|
2015-03-19 04:24:43 +01:00
|
|
|
FileEntry("myfile"),
|
|
|
|
FileEntry("myfile2"),
|
|
|
|
DirEntry("mysubdir")
|
|
|
|
});
|
2015-03-18 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, Children_Nested2_LargerStructure) {
|
|
|
|
this->InitDirStructure();
|
2015-03-19 04:36:02 +01:00
|
|
|
this->EXPECT_CHILDREN_ARE("/mydir/mysubdir", {
|
2015-03-19 04:24:43 +01:00
|
|
|
FileEntry("myfile"),
|
|
|
|
DirEntry("mysubsubdir")
|
|
|
|
});
|
2015-03-18 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 05:32:09 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_InEmptyRoot) {
|
2015-03-16 04:53:35 +01:00
|
|
|
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
2015-03-16 02:56:40 +01:00
|
|
|
this->LoadFile("/myfile");
|
|
|
|
}
|
|
|
|
|
2015-03-19 05:32:09 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_InNonemptyRoot) {
|
|
|
|
this->InitDirStructure();
|
|
|
|
this->LoadDir("/")->createAndOpenFile("mynewfile", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/", {
|
|
|
|
FileEntry("myfile"),
|
|
|
|
DirEntry("mydir"),
|
|
|
|
DirEntry("myemptydir"),
|
|
|
|
FileEntry("mynewfile")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_InEmptyNestedDir) {
|
|
|
|
this->InitDirStructure();
|
|
|
|
this->LoadDir("/myemptydir")->createAndOpenFile("mynewfile", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/myemptydir", {
|
|
|
|
FileEntry("mynewfile")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_InNonemptyNestedDir) {
|
|
|
|
this->InitDirStructure();
|
|
|
|
this->LoadDir("/mydir")->createAndOpenFile("mynewfile", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/mydir", {
|
|
|
|
FileEntry("myfile"),
|
|
|
|
FileEntry("myfile2"),
|
|
|
|
DirEntry("mysubdir"),
|
|
|
|
FileEntry("mynewfile")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_AlreadyExisting) {
|
|
|
|
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
|
|
|
//TODO Change, once we know which way of error reporting we want for such errors
|
|
|
|
EXPECT_ANY_THROW(
|
|
|
|
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-19 05:32:09 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, CreateDir_InEmptyRoot) {
|
2015-03-16 04:53:35 +01:00
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
2015-03-16 02:56:40 +01:00
|
|
|
this->LoadDir("/mydir");
|
|
|
|
}
|
|
|
|
|
2015-03-19 05:32:09 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, CreateDir_InNonemptyRoot) {
|
|
|
|
this->InitDirStructure();
|
|
|
|
this->LoadDir("/")->createDir("mynewdir", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/", {
|
|
|
|
FileEntry("myfile"),
|
|
|
|
DirEntry("mydir"),
|
|
|
|
DirEntry("myemptydir"),
|
|
|
|
DirEntry("mynewdir")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, CreateDir_InEmptyNestedDir) {
|
|
|
|
this->InitDirStructure();
|
|
|
|
this->LoadDir("/myemptydir")->createDir("mynewdir", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/myemptydir", {
|
|
|
|
DirEntry("mynewdir")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppDirTest, CreateDir_InNonemptyNestedDir) {
|
|
|
|
this->InitDirStructure();
|
|
|
|
this->LoadDir("/mydir")->createDir("mynewdir", this->MODE_PUBLIC);
|
|
|
|
this->EXPECT_CHILDREN_ARE("/mydir", {
|
|
|
|
FileEntry("myfile"),
|
|
|
|
FileEntry("myfile2"),
|
|
|
|
DirEntry("mysubdir"),
|
|
|
|
DirEntry("mynewdir")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:46:33 +01:00
|
|
|
TYPED_TEST_P(FsppDirTest, CreateDir_AlreadyExisting) {
|
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
|
|
|
//TODO Change, once we know which way of error reporting we want for such errors
|
|
|
|
EXPECT_ANY_THROW(
|
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-19 05:32:09 +01:00
|
|
|
|
|
|
|
|
2015-03-16 02:56:40 +01:00
|
|
|
REGISTER_TYPED_TEST_CASE_P(FsppDirTest,
|
2015-03-18 01:46:33 +01:00
|
|
|
Children_RootDir_Empty,
|
2015-03-19 04:36:02 +01:00
|
|
|
Children_RootDir_OneFile_Directly,
|
|
|
|
Children_RootDir_OneFile_AfterReloadingDir,
|
|
|
|
Children_RootDir_OneDir_Directly,
|
|
|
|
Children_RootDir_OneDir_AfterReloadingDir,
|
2015-03-18 01:46:33 +01:00
|
|
|
Children_RootDir_LargerStructure,
|
|
|
|
Children_Nested_Empty,
|
|
|
|
Children_Nested_OneFile_Directly,
|
|
|
|
Children_Nested_OneFile_AfterReloadingDir,
|
|
|
|
Children_Nested_OneDir_Directly,
|
|
|
|
Children_Nested_OneDir_AfterReloadingDir,
|
|
|
|
Children_Nested_LargerStructure,
|
|
|
|
Children_Nested_LargerStructure_Empty,
|
|
|
|
Children_Nested2_LargerStructure,
|
2015-03-19 05:32:09 +01:00
|
|
|
CreateAndOpenFile_InEmptyRoot,
|
|
|
|
CreateAndOpenFile_InNonemptyRoot,
|
|
|
|
CreateAndOpenFile_InEmptyNestedDir,
|
|
|
|
CreateAndOpenFile_InNonemptyNestedDir,
|
2015-03-18 01:46:33 +01:00
|
|
|
CreateAndOpenFile_AlreadyExisting,
|
2015-03-19 05:32:09 +01:00
|
|
|
CreateDir_InEmptyRoot,
|
|
|
|
CreateDir_InNonemptyRoot,
|
|
|
|
CreateDir_InEmptyNestedDir,
|
|
|
|
CreateDir_InNonemptyNestedDir,
|
2015-03-18 01:46:33 +01:00
|
|
|
CreateDir_AlreadyExisting
|
2015-03-16 02:56:40 +01:00
|
|
|
);
|
|
|
|
|
2015-03-18 02:49:11 +01:00
|
|
|
//TODO stat
|
|
|
|
//TODO access
|
|
|
|
//TODO rename
|
|
|
|
//TODO utimens
|
2015-03-16 02:56:40 +01:00
|
|
|
//TODO rmdir
|
|
|
|
|
2015-03-19 05:38:00 +01:00
|
|
|
//TODO Test permission flags
|
|
|
|
|
2015-03-16 02:56:40 +01:00
|
|
|
#endif
|