Refactor FsppDirTest

This commit is contained in:
Sebastian Meßmer 2015-03-19 04:36:02 +01:00
parent 214b268a1c
commit a0130fb73f

View File

@ -15,11 +15,15 @@ public:
this->LoadDir("/mydir/mysubdir")->createDir("mysubsubdir", this->MODE_PUBLIC); this->LoadDir("/mydir/mysubdir")->createDir("mysubsubdir", this->MODE_PUBLIC);
} }
void EXPECT_HAS_ENTRIES(const std::vector<fspp::Dir::Entry> &children, const std::initializer_list<fspp::Dir::Entry> expected) { 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) {
std::vector<fspp::Dir::Entry> expectedChildren = expected; 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, "."));
expectedChildren.push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, "..")); expectedChildren.push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, ".."));
EXPECT_UNORDERED_EQ(expectedChildren, children); EXPECT_UNORDERED_EQ(expectedChildren, *dir.children());
} }
template<class Entry> template<class Entry>
@ -52,32 +56,42 @@ fspp::Dir::Entry FileEntry(const std::string &name) {
} }
TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) { TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) {
auto children = this->LoadDir("/")->children(); this->EXPECT_CHILDREN_ARE("/", {});
this->EXPECT_HAS_ENTRIES(*children, {});
} }
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile) { TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile_Directly) {
auto rootdir = this->LoadDir("/"); auto rootdir = this->LoadDir("/");
rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC); rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto children = rootdir->children(); this->EXPECT_CHILDREN_ARE(*rootdir, {
this->EXPECT_HAS_ENTRIES(*children, {
FileEntry("myfile") FileEntry("myfile")
}); });
} }
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir) { TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile_AfterReloadingDir) {
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
this->EXPECT_CHILDREN_ARE("/", {
FileEntry("myfile")
});
}
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir_Directly) {
auto rootdir = this->LoadDir("/"); auto rootdir = this->LoadDir("/");
rootdir->createDir("mydir", this->MODE_PUBLIC); rootdir->createDir("mydir", this->MODE_PUBLIC);
auto children = rootdir->children(); this->EXPECT_CHILDREN_ARE(*rootdir, {
this->EXPECT_HAS_ENTRIES(*children, { DirEntry("mydir")
});
}
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir_AfterReloadingDir) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->EXPECT_CHILDREN_ARE("/", {
DirEntry("mydir") DirEntry("mydir")
}); });
} }
TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) { TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) {
this->InitDirStructure(); this->InitDirStructure();
auto children = this->LoadDir("/")->children(); this->EXPECT_CHILDREN_ARE("/", {
this->EXPECT_HAS_ENTRIES(*children, {
FileEntry("myfile"), FileEntry("myfile"),
DirEntry("mydir"), DirEntry("mydir"),
DirEntry("myemptydir") DirEntry("myemptydir")
@ -85,18 +99,15 @@ TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) {
} }
TYPED_TEST_P(FsppDirTest, Children_Nested_Empty) { TYPED_TEST_P(FsppDirTest, Children_Nested_Empty) {
auto rootdir = this->LoadDir("/"); this->LoadDir("/")->createDir("myemptydir", this->MODE_PUBLIC);
rootdir->createDir("myemptydir", this->MODE_PUBLIC); this->EXPECT_CHILDREN_ARE("/myemptydir", {});
auto children = this->LoadDir("/myemptydir")->children();
this->EXPECT_HAS_ENTRIES(*children, {});
} }
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) { TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC); this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir"); auto dir = this->LoadDir("/mydir");
dir->createAndOpenFile("myfile", this->MODE_PUBLIC); dir->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto children = dir->children(); this->EXPECT_CHILDREN_ARE(*dir, {
this->EXPECT_HAS_ENTRIES(*children, {
FileEntry("myfile") FileEntry("myfile")
}); });
} }
@ -104,9 +115,7 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) {
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) { TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC); this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC); this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir"); this->EXPECT_CHILDREN_ARE("/mydir", {
auto children = dir->children();
this->EXPECT_HAS_ENTRIES(*children, {
FileEntry("myfile") FileEntry("myfile")
}); });
} }
@ -115,8 +124,7 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC); this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir"); auto dir = this->LoadDir("/mydir");
dir->createDir("mysubdir", this->MODE_PUBLIC); dir->createDir("mysubdir", this->MODE_PUBLIC);
auto children = dir->children(); this->EXPECT_CHILDREN_ARE(*dir, {
this->EXPECT_HAS_ENTRIES(*children, {
DirEntry("mysubdir") DirEntry("mysubdir")
}); });
} }
@ -124,23 +132,19 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) { TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC); this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC); this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir"); this->EXPECT_CHILDREN_ARE("/mydir", {
auto children = dir->children();
this->EXPECT_HAS_ENTRIES(*children, {
DirEntry("mysubdir") DirEntry("mysubdir")
}); });
} }
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure_Empty) { TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure_Empty) {
this->InitDirStructure(); this->InitDirStructure();
auto children = this->LoadDir("/myemptydir")->children(); this->EXPECT_CHILDREN_ARE("/myemptydir", {});
this->EXPECT_HAS_ENTRIES(*children, {});
} }
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure) { TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure) {
this->InitDirStructure(); this->InitDirStructure();
auto children = this->LoadDir("/mydir")->children(); this->EXPECT_CHILDREN_ARE("/mydir", {
this->EXPECT_HAS_ENTRIES(*children, {
FileEntry("myfile"), FileEntry("myfile"),
FileEntry("myfile2"), FileEntry("myfile2"),
DirEntry("mysubdir") DirEntry("mysubdir")
@ -149,8 +153,7 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure) {
TYPED_TEST_P(FsppDirTest, Children_Nested2_LargerStructure) { TYPED_TEST_P(FsppDirTest, Children_Nested2_LargerStructure) {
this->InitDirStructure(); this->InitDirStructure();
auto children = this->LoadDir("/mydir/mysubdir")->children(); this->EXPECT_CHILDREN_ARE("/mydir/mysubdir", {
this->EXPECT_HAS_ENTRIES(*children, {
FileEntry("myfile"), FileEntry("myfile"),
DirEntry("mysubsubdir") DirEntry("mysubsubdir")
}); });
@ -184,8 +187,10 @@ TYPED_TEST_P(FsppDirTest, CreateDir_AlreadyExisting) {
REGISTER_TYPED_TEST_CASE_P(FsppDirTest, REGISTER_TYPED_TEST_CASE_P(FsppDirTest,
Children_RootDir_Empty, Children_RootDir_Empty,
Children_RootDir_OneFile, Children_RootDir_OneFile_Directly,
Children_RootDir_OneDir, Children_RootDir_OneFile_AfterReloadingDir,
Children_RootDir_OneDir_Directly,
Children_RootDir_OneDir_AfterReloadingDir,
Children_RootDir_LargerStructure, Children_RootDir_LargerStructure,
Children_Nested_Empty, Children_Nested_Empty,
Children_Nested_OneFile_Directly, Children_Nested_OneFile_Directly,