Removed code redundancy

This commit is contained in:
Sebastian Meßmer 2015-03-19 03:24:08 +01:00
parent c662d7c590
commit 70bd5a3ea3

View File

@ -9,13 +9,13 @@ class FsppFileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
public:
FsppFileTest() {
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
file = this->LoadFile("/myfile");
file_root = this->LoadFile("/myfile");
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC);
this->LoadDir("/mydir")->createAndOpenFile("mynestedfile", this->MODE_PUBLIC);
file_nested = this->LoadFile("/mydir/mynestedfile");
}
std::unique_ptr<fspp::File> file;
std::unique_ptr<fspp::File> file_root;
std::unique_ptr<fspp::File> file_nested;
void EXPECT_SIZE(uint64_t expectedSize, const fspp::File &file) {
@ -44,108 +44,137 @@ public:
//and check that it only read the expected size (but also not less)
EXPECT_EQ(expectedSize, readBytes);
}
void Test_Open_RDONLY(fspp::File *file) {
file->open(O_RDONLY);
}
void Test_Open_WRONLY(fspp::File *file) {
file->open(O_WRONLY);
}
void Test_Open_RDWR(fspp::File *file) {
file->open(O_RDONLY);
}
void Test_Truncate_DontChange1(fspp::File *file) {
file->truncate(0);
this->EXPECT_SIZE(0, *file);
}
void Test_Truncate_GrowTo1(fspp::File *file) {
file->truncate(1);
this->EXPECT_SIZE(1, *file);
}
void Test_Truncate_Grow(fspp::File *file) {
file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, *file);
}
void Test_Truncate_DontChange2(fspp::File *file) {
file->truncate(10*1024*1024);
file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, *file);
}
void Test_Truncate_Shrink(fspp::File *file) {
file->truncate(10*1024*1024);
file->truncate(5*1024*1024);
this->EXPECT_SIZE(5*1024*1024, *file);
}
void Test_Truncate_ShrinkTo0(fspp::File *file) {
file->truncate(10*1024*1024);
file->truncate(0);
this->EXPECT_SIZE(0, *file);
}
void Test_Stat_CreatedFileIsEmpty(fspp::File *file) {
this->EXPECT_SIZE(0, *file);
}
};
TYPED_TEST_CASE_P(FsppFileTest);
//TODO Right now, each test case is there twice (normal and _Nested). Find better solution without code duplication.
TYPED_TEST_P(FsppFileTest, Open_RDONLY) {
this->file->open(O_RDONLY);
this->Test_Open_RDONLY(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Open_RDONLY_Nested) {
this->file_nested->open(O_RDONLY);
this->Test_Open_RDONLY(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Open_WRONLY) {
this->file->open(O_WRONLY);
this->Test_Open_WRONLY(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Open_WRONLY_Nested) {
this->file_nested->open(O_WRONLY);
this->Test_Open_WRONLY(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Open_RDWR) {
this->file->open(O_RDWR);
this->Test_Open_RDWR(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Open_RDWR_Nested) {
this->file_nested->open(O_RDWR);
this->Test_Open_RDWR(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_DontChange1) {
this->file->truncate(0);
this->EXPECT_SIZE(0, *this->file);
this->Test_Truncate_DontChange1(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_DontChange1_Nested) {
this->file->truncate(0);
this->EXPECT_SIZE(0, *this->file);
this->Test_Truncate_DontChange1(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_GrowTo1) {
this->file->truncate(1);
this->EXPECT_SIZE(1, *this->file);
this->Test_Truncate_GrowTo1(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_GrowTo1_Nested) {
this->file->truncate(1);
this->EXPECT_SIZE(1, *this->file);
this->Test_Truncate_GrowTo1(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_Grow) {
this->file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, *this->file);
this->Test_Truncate_Grow(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_Grow_Nested) {
this->file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, *this->file);
this->Test_Truncate_Grow(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_DontChange2) {
this->file->truncate(10*1024*1024);
this->file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, *this->file);
this->Test_Truncate_DontChange2(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_DontChange2_Nested) {
this->file->truncate(10*1024*1024);
this->file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, *this->file);
this->Test_Truncate_DontChange2(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_Shrink) {
this->file->truncate(10*1024*1024);
this->file->truncate(5*1024*1024);
this->EXPECT_SIZE(5*1024*1024, *this->file);
this->Test_Truncate_Shrink(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_Shrink_Nested) {
this->file->truncate(10*1024*1024);
this->file->truncate(5*1024*1024);
this->EXPECT_SIZE(5*1024*1024, *this->file);
this->Test_Truncate_Shrink(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_ShrinkTo0) {
this->file->truncate(10*1024*1024);
this->file->truncate(0);
this->EXPECT_SIZE(0, *this->file);
this->Test_Truncate_ShrinkTo0(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Truncate_ShrinkTo0_Nested) {
this->file->truncate(10*1024*1024);
this->file->truncate(0);
this->EXPECT_SIZE(0, *this->file);
this->Test_Truncate_ShrinkTo0(this->file_nested.get());
}
TYPED_TEST_P(FsppFileTest, Stat_CreatedFileIsEmpty) {
this->EXPECT_SIZE(0, *this->file);
this->Test_Stat_CreatedFileIsEmpty(this->file_root.get());
}
TYPED_TEST_P(FsppFileTest, Stat_CreatedFileIsEmpty_Nested) {
this->EXPECT_SIZE(0, *this->file_nested);
this->Test_Stat_CreatedFileIsEmpty(this->file_nested.get());
}
REGISTER_TYPED_TEST_CASE_P(FsppFileTest,