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:
parent
70bd5a3ea3
commit
24a60d6cb3
@ -3,6 +3,7 @@
|
|||||||
[requirements]
|
[requirements]
|
||||||
google/gmock: 2
|
google/gmock: 2
|
||||||
google/gtest: 10
|
google/gtest: 10
|
||||||
|
messmer/blockstore: 1
|
||||||
messmer/cmake: 3
|
messmer/cmake: 3
|
||||||
messmer/cpp-utils: 2
|
messmer/cpp-utils: 2
|
||||||
messmer/tempfile: 4
|
messmer/tempfile: 4
|
||||||
|
@ -14,50 +14,71 @@ public:
|
|||||||
this->LoadDir("/mydir/mysubdir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
this->LoadDir("/mydir/mysubdir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
||||||
this->LoadDir("/mydir/mysubdir")->createDir("mysubsubdir", 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_CASE_P(FsppDirTest);
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) {
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) {
|
||||||
auto children = this->LoadDir("/")->children();
|
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) {
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile) {
|
||||||
auto rootdir = this->LoadDir("/");
|
auto rootdir = this->LoadDir("/");
|
||||||
rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
||||||
auto children = rootdir->children();
|
auto children = rootdir->children();
|
||||||
EXPECT_EQ(1, children->size());
|
EXPECT_EQ(3, children->size());
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir) {
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir) {
|
||||||
auto rootdir = this->LoadDir("/");
|
auto rootdir = this->LoadDir("/");
|
||||||
rootdir->createDir("mydir", this->MODE_PUBLIC);
|
rootdir->createDir("mydir", this->MODE_PUBLIC);
|
||||||
auto children = rootdir->children();
|
auto children = rootdir->children();
|
||||||
EXPECT_EQ(1, children->size());
|
EXPECT_EQ(3, children->size());
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ("mydir", (*children)[0].name);
|
this->EXPECT_HAS_DIR_ENTRY("mydir", *children);
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) {
|
TYPED_TEST_P(FsppDirTest, Children_RootDir_LargerStructure) {
|
||||||
this->InitDirStructure();
|
this->InitDirStructure();
|
||||||
auto children = this->LoadDir("/")->children();
|
auto children = this->LoadDir("/")->children();
|
||||||
EXPECT_EQ(3, children->size());
|
EXPECT_EQ(5, children->size());
|
||||||
//TODO Ignore order
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
this->EXPECT_HAS_DIR_ENTRY("mydir", *children);
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[1].type);
|
this->EXPECT_HAS_DIR_ENTRY("myemptydir", *children);
|
||||||
EXPECT_EQ("mydir", (*children)[1].name);
|
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[2].type);
|
|
||||||
EXPECT_EQ("myemptydir", (*children)[2].name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_Nested_Empty) {
|
TYPED_TEST_P(FsppDirTest, Children_Nested_Empty) {
|
||||||
auto rootdir = this->LoadDir("/");
|
auto rootdir = this->LoadDir("/");
|
||||||
rootdir->createDir("myemptydir", this->MODE_PUBLIC);
|
rootdir->createDir("myemptydir", this->MODE_PUBLIC);
|
||||||
auto children = this->LoadDir("/myemptydir")->children();
|
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) {
|
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");
|
auto dir = this->LoadDir("/mydir");
|
||||||
dir->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
dir->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
||||||
auto children = dir->children();
|
auto children = dir->children();
|
||||||
EXPECT_EQ(1, children->size());
|
EXPECT_EQ(3, children->size());
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) {
|
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);
|
this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
||||||
auto dir = this->LoadDir("/mydir");
|
auto dir = this->LoadDir("/mydir");
|
||||||
auto children = dir->children();
|
auto children = dir->children();
|
||||||
EXPECT_EQ(1, children->size());
|
EXPECT_EQ(3, children->size());
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
|
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");
|
auto dir = this->LoadDir("/mydir");
|
||||||
dir->createDir("mysubdir", this->MODE_PUBLIC);
|
dir->createDir("mysubdir", this->MODE_PUBLIC);
|
||||||
auto children = dir->children();
|
auto children = dir->children();
|
||||||
EXPECT_EQ(1, children->size());
|
EXPECT_EQ(3, children->size());
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ("mysubdir", (*children)[0].name);
|
this->EXPECT_HAS_DIR_ENTRY("mysubdir", *children);
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) {
|
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);
|
this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC);
|
||||||
auto dir = this->LoadDir("/mydir");
|
auto dir = this->LoadDir("/mydir");
|
||||||
auto children = dir->children();
|
auto children = dir->children();
|
||||||
EXPECT_EQ(1, children->size());
|
EXPECT_EQ(3, children->size());
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ("mysubdir", (*children)[0].name);
|
this->EXPECT_HAS_DIR_ENTRY("mysubdir", *children);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
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) {
|
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure) {
|
||||||
this->InitDirStructure();
|
this->InitDirStructure();
|
||||||
auto children = this->LoadDir("/mydir")->children();
|
auto children = this->LoadDir("/mydir")->children();
|
||||||
EXPECT_EQ(3, children->size());
|
EXPECT_EQ(5, children->size());
|
||||||
//TODO Ignore order
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
this->EXPECT_HAS_FILE_ENTRY("myfile2", *children);
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[1].type);
|
this->EXPECT_HAS_DIR_ENTRY("mysubdir", *children);
|
||||||
EXPECT_EQ("myfile2", (*children)[1].name);
|
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[2].type);
|
|
||||||
EXPECT_EQ("mysubdir", (*children)[2].name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
auto children = this->LoadDir("/mydir/mysubdir")->children();
|
||||||
EXPECT_EQ(2, children->size());
|
EXPECT_EQ(4, children->size());
|
||||||
//TODO Ignore order
|
this->EXPECT_HAS_DEFAULT_ENTRIES(*children);
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
this->EXPECT_HAS_FILE_ENTRY("myfile", *children);
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
this->EXPECT_HAS_DIR_ENTRY("mysubsubdir", *children);
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[1].type);
|
|
||||||
EXPECT_EQ("mysubsubdir", (*children)[1].name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_LoadAfterwards) {
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_LoadAfterwards) {
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/stat.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>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppFileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
class FsppFileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user