Improve FsppDirTest:

* They expect the filesystem to return . and .. as dir entries
 * The test case allows the file system to return the entries in an arbitrary order
This commit is contained in:
Sebastian Meßmer 2015-03-19 03:52:58 +01:00
parent 70bd5a3ea3
commit 24a60d6cb3
3 changed files with 65 additions and 43 deletions

View File

@ -3,6 +3,7 @@
[requirements]
google/gmock: 2
google/gtest: 10
messmer/blockstore: 1
messmer/cmake: 3
messmer/cpp-utils: 2
messmer/tempfile: 4

View File

@ -14,50 +14,71 @@ public:
this->LoadDir("/mydir/mysubdir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
this->LoadDir("/mydir/mysubdir")->createDir("mysubsubdir", this->MODE_PUBLIC);
}
void EXPECT_HAS_DEFAULT_ENTRIES(const std::vector<fspp::Dir::Entry> &children) {
EXPECT_HAS_DIR_ENTRY(".", children);
EXPECT_HAS_DIR_ENTRY("..", children);
}
void EXPECT_HAS_DIR_ENTRY(const std::string &name, const std::vector<fspp::Dir::Entry> &children) {
EXPECT_HAS_ENTRY(fspp::Dir::EntryType::DIR, name, children);
}
void EXPECT_HAS_FILE_ENTRY(const std::string &name, const std::vector<fspp::Dir::Entry> &children) {
EXPECT_HAS_ENTRY(fspp::Dir::EntryType::FILE, name, children);
}
void EXPECT_HAS_ENTRY(fspp::Dir::EntryType type, const std::string &name, const std::vector<fspp::Dir::Entry> &children) {
for (const auto &child : children) {
if (child.type == type && child.name == name) {
return;
}
}
EXPECT_TRUE(false);
}
};
TYPED_TEST_CASE_P(FsppDirTest);
TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) {
auto children = this->LoadDir("/")->children();
EXPECT_EQ(0, children->size());
EXPECT_EQ(2, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
}
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile) {
auto rootdir = this->LoadDir("/");
rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto children = rootdir->children();
EXPECT_EQ(1, children->size());
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
EXPECT_EQ("myfile", (*children)[0].name);
EXPECT_EQ(3, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
}
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir) {
auto rootdir = this->LoadDir("/");
rootdir->createDir("mydir", this->MODE_PUBLIC);
auto children = rootdir->children();
EXPECT_EQ(1, children->size());
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
EXPECT_EQ("mydir", (*children)[0].name);
EXPECT_EQ(3, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_DIR_ENTRY("mydir", *children);
}
TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) {
this->InitDirStructure();
auto children = this->LoadDir("/")->children();
EXPECT_EQ(3, children->size());
//TODO Ignore order
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
EXPECT_EQ("myfile", (*children)[0].name);
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[1].type);
EXPECT_EQ("mydir", (*children)[1].name);
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[2].type);
EXPECT_EQ("myemptydir", (*children)[2].name);
EXPECT_EQ(5, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
this->EXPECT_HAS_DIR_ENTRY("mydir", *children);
this->EXPECT_HAS_DIR_ENTRY("myemptydir", *children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_Empty) {
auto rootdir = this->LoadDir("/");
rootdir->createDir("myemptydir", this->MODE_PUBLIC);
auto children = this->LoadDir("/myemptydir")->children();
EXPECT_EQ(0, children->size());
EXPECT_EQ(2, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) {
@ -65,9 +86,9 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) {
auto dir = this->LoadDir("/mydir");
dir->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto children = dir->children();
EXPECT_EQ(1, children->size());
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
EXPECT_EQ("myfile", (*children)[0].name);
EXPECT_EQ(3, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) {
@ -75,9 +96,9 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) {
this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir");
auto children = dir->children();
EXPECT_EQ(1, children->size());
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
EXPECT_EQ("myfile", (*children)[0].name);
EXPECT_EQ(3, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
@ -85,9 +106,9 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
auto dir = this->LoadDir("/mydir");
dir->createDir("mysubdir", this->MODE_PUBLIC);
auto children = dir->children();
EXPECT_EQ(1, children->size());
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
EXPECT_EQ("mysubdir", (*children)[0].name);
EXPECT_EQ(3, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_DIR_ENTRY("mysubdir", *children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) {
@ -95,39 +116,35 @@ TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) {
this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir");
auto children = dir->children();
EXPECT_EQ(1, children->size());
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
EXPECT_EQ("mysubdir", (*children)[0].name);
EXPECT_EQ(3, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_DIR_ENTRY("mysubdir", *children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure_Empty) {
this->InitDirStructure();
auto children = this->LoadDir("/myemptydir")->children();
EXPECT_EQ(0, children->size());
EXPECT_EQ(2, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure) {
this->InitDirStructure();
auto children = this->LoadDir("/mydir")->children();
EXPECT_EQ(3, children->size());
//TODO Ignore order
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
EXPECT_EQ("myfile", (*children)[0].name);
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[1].type);
EXPECT_EQ("myfile2", (*children)[1].name);
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[2].type);
EXPECT_EQ("mysubdir", (*children)[2].name);
EXPECT_EQ(5, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
this->EXPECT_HAS_FILE_ENTRY("myfile2", *children);
this->EXPECT_HAS_DIR_ENTRY("mysubdir", *children);
}
TYPED_TEST_P(FsppDirTest, Children_Nested2_LargerStructure) {
this->InitDirStructure();
auto children = this->LoadDir("/mydir/mysubdir")->children();
EXPECT_EQ(2, children->size());
//TODO Ignore order
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
EXPECT_EQ("myfile", (*children)[0].name);
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[1].type);
EXPECT_EQ("mysubsubdir", (*children)[1].name);
EXPECT_EQ(4, children->size());
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
this->EXPECT_HAS_DIR_ENTRY("mysubsubdir", *children);
}
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_LoadAfterwards) {

View File

@ -4,6 +4,10 @@
#include <sys/fcntl.h>
#include <sys/stat.h>
//TODO I don't really want a dependency fspp -> blockstore. I probably should take the blockstore::Data class
// (which is the only reason for the dependency here) and put it into a different package (cpp-utils?)
#include <messmer/blockstore/utils/Data.h>
template<class ConcreteFileSystemTestFixture>
class FsppFileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
public: