Added more test cases to FsppDirTest

This commit is contained in:
Sebastian Messmer 2015-03-18 01:46:33 +01:00
parent 7fdbc9f629
commit 17ac638e41

View File

@ -3,16 +3,26 @@
template<class ConcreteFileSystemTestFixture>
class FsppDirTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
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);
}
};
TYPED_TEST_CASE_P(FsppDirTest);
TYPED_TEST_P(FsppDirTest, Children_EmptyRootDir) {
auto rootdir = this->LoadDir("/");
auto children = rootdir->children();
TYPED_TEST_P(FsppDirTest, Children_RootDir_Empty) {
auto children = this->LoadDir("/")->children();
EXPECT_EQ(0, children->size());
}
TYPED_TEST_P(FsppDirTest, Children_OneFileInRootDir) {
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneFile) {
auto rootdir = this->LoadDir("/");
rootdir->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto children = rootdir->children();
@ -21,7 +31,7 @@ TYPED_TEST_P(FsppDirTest, Children_OneFileInRootDir) {
EXPECT_EQ("myfile", (*children)[0].name);
}
TYPED_TEST_P(FsppDirTest, Children_OneDirInRootDir) {
TYPED_TEST_P(FsppDirTest, Children_RootDir_OneDir) {
auto rootdir = this->LoadDir("/");
rootdir->createDir("mydir", this->MODE_PUBLIC);
auto children = rootdir->children();
@ -30,7 +40,27 @@ TYPED_TEST_P(FsppDirTest, Children_OneDirInRootDir) {
EXPECT_EQ("mydir", (*children)[0].name);
}
TYPED_TEST_P(FsppDirTest, Children_OneFileInNestedDir_Directly) {
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);
}
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());
}
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_Directly) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir");
dir->createAndOpenFile("myfile", this->MODE_PUBLIC);
@ -40,7 +70,7 @@ TYPED_TEST_P(FsppDirTest, Children_OneFileInNestedDir_Directly) {
EXPECT_EQ("myfile", (*children)[0].name);
}
TYPED_TEST_P(FsppDirTest, Children_OneFileInNestedDir_AfterReloadingDir) {
TYPED_TEST_P(FsppDirTest, Children_Nested_OneFile_AfterReloadingDir) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->LoadDir("/mydir")->createAndOpenFile("myfile", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir");
@ -50,7 +80,7 @@ TYPED_TEST_P(FsppDirTest, Children_OneFileInNestedDir_AfterReloadingDir) {
EXPECT_EQ("myfile", (*children)[0].name);
}
TYPED_TEST_P(FsppDirTest, Children_OneDirInNestedDir_Directly) {
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_Directly) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir");
dir->createDir("mysubdir", this->MODE_PUBLIC);
@ -60,7 +90,7 @@ TYPED_TEST_P(FsppDirTest, Children_OneDirInNestedDir_Directly) {
EXPECT_EQ("mysubdir", (*children)[0].name);
}
TYPED_TEST_P(FsppDirTest, Children_OneDirInNestedDir_AfterReloadingDir) {
TYPED_TEST_P(FsppDirTest, Children_Nested_OneDir_AfterReloadingDir) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->LoadDir("/mydir")->createDir("mysubdir", this->MODE_PUBLIC);
auto dir = this->LoadDir("/mydir");
@ -70,30 +100,80 @@ TYPED_TEST_P(FsppDirTest, Children_OneDirInNestedDir_AfterReloadingDir) {
EXPECT_EQ("mysubdir", (*children)[0].name);
}
TYPED_TEST_P(FsppDirTest, Children_Nested_LargerStructure_Empty) {
this->InitDirStructure();
auto children = this->LoadDir("/myemptydir")->children();
EXPECT_EQ(0, children->size());
}
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);
}
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);
}
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_LoadAfterwards) {
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
this->LoadFile("/myfile");
}
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);
);
}
TYPED_TEST_P(FsppDirTest, CreateDir_LoadAfterwards) {
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->LoadDir("/mydir");
}
REGISTER_TYPED_TEST_CASE_P(FsppDirTest,
Children_EmptyRootDir,
Children_OneFileInRootDir,
Children_OneDirInRootDir,
Children_OneFileInNestedDir_Directly,
Children_OneFileInNestedDir_AfterReloadingDir,
Children_OneDirInNestedDir_Directly,
Children_OneDirInNestedDir_AfterReloadingDir,
CreateAndOpenFile_LoadAfterwards,
CreateDir_LoadAfterwards
);
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);
);
}
//TODO Build dir structure with more than one entry
//TODO createDir/createAndOpenFile for already existing
REGISTER_TYPED_TEST_CASE_P(FsppDirTest,
Children_RootDir_Empty,
Children_RootDir_OneFile,
Children_RootDir_OneDir,
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,
CreateAndOpenFile_LoadAfterwards,
CreateAndOpenFile_AlreadyExisting,
CreateDir_LoadAfterwards,
CreateDir_AlreadyExisting
);
//TODO rmdir