Removed code redundancy
This commit is contained in:
parent
c662d7c590
commit
70bd5a3ea3
@ -9,13 +9,13 @@ class FsppFileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
|||||||
public:
|
public:
|
||||||
FsppFileTest() {
|
FsppFileTest() {
|
||||||
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC);
|
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("/")->createDir("mydir", this->MODE_PUBLIC);
|
||||||
this->LoadDir("/mydir")->createAndOpenFile("mynestedfile", this->MODE_PUBLIC);
|
this->LoadDir("/mydir")->createAndOpenFile("mynestedfile", this->MODE_PUBLIC);
|
||||||
file_nested = this->LoadFile("/mydir/mynestedfile");
|
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;
|
std::unique_ptr<fspp::File> file_nested;
|
||||||
|
|
||||||
void EXPECT_SIZE(uint64_t expectedSize, const fspp::File &file) {
|
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)
|
//and check that it only read the expected size (but also not less)
|
||||||
EXPECT_EQ(expectedSize, readBytes);
|
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);
|
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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
TYPED_TEST_P(FsppFileTest, Truncate_DontChange1) {
|
||||||
this->file->truncate(0);
|
this->Test_Truncate_DontChange1(this->file_root.get());
|
||||||
this->EXPECT_SIZE(0, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_DontChange1_Nested) {
|
TYPED_TEST_P(FsppFileTest, Truncate_DontChange1_Nested) {
|
||||||
this->file->truncate(0);
|
this->Test_Truncate_DontChange1(this->file_nested.get());
|
||||||
this->EXPECT_SIZE(0, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_GrowTo1) {
|
TYPED_TEST_P(FsppFileTest, Truncate_GrowTo1) {
|
||||||
this->file->truncate(1);
|
this->Test_Truncate_GrowTo1(this->file_root.get());
|
||||||
this->EXPECT_SIZE(1, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_GrowTo1_Nested) {
|
TYPED_TEST_P(FsppFileTest, Truncate_GrowTo1_Nested) {
|
||||||
this->file->truncate(1);
|
this->Test_Truncate_GrowTo1(this->file_nested.get());
|
||||||
this->EXPECT_SIZE(1, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_Grow) {
|
TYPED_TEST_P(FsppFileTest, Truncate_Grow) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_Grow(this->file_root.get());
|
||||||
this->EXPECT_SIZE(10*1024*1024, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_Grow_Nested) {
|
TYPED_TEST_P(FsppFileTest, Truncate_Grow_Nested) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_Grow(this->file_nested.get());
|
||||||
this->EXPECT_SIZE(10*1024*1024, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_DontChange2) {
|
TYPED_TEST_P(FsppFileTest, Truncate_DontChange2) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_DontChange2(this->file_root.get());
|
||||||
this->file->truncate(10*1024*1024);
|
|
||||||
this->EXPECT_SIZE(10*1024*1024, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_DontChange2_Nested) {
|
TYPED_TEST_P(FsppFileTest, Truncate_DontChange2_Nested) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_DontChange2(this->file_nested.get());
|
||||||
this->file->truncate(10*1024*1024);
|
|
||||||
this->EXPECT_SIZE(10*1024*1024, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_Shrink) {
|
TYPED_TEST_P(FsppFileTest, Truncate_Shrink) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_Shrink(this->file_root.get());
|
||||||
this->file->truncate(5*1024*1024);
|
|
||||||
this->EXPECT_SIZE(5*1024*1024, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_Shrink_Nested) {
|
TYPED_TEST_P(FsppFileTest, Truncate_Shrink_Nested) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_Shrink(this->file_nested.get());
|
||||||
this->file->truncate(5*1024*1024);
|
|
||||||
this->EXPECT_SIZE(5*1024*1024, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_ShrinkTo0) {
|
TYPED_TEST_P(FsppFileTest, Truncate_ShrinkTo0) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_ShrinkTo0(this->file_root.get());
|
||||||
this->file->truncate(0);
|
|
||||||
this->EXPECT_SIZE(0, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Truncate_ShrinkTo0_Nested) {
|
TYPED_TEST_P(FsppFileTest, Truncate_ShrinkTo0_Nested) {
|
||||||
this->file->truncate(10*1024*1024);
|
this->Test_Truncate_ShrinkTo0(this->file_nested.get());
|
||||||
this->file->truncate(0);
|
|
||||||
this->EXPECT_SIZE(0, *this->file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest, Stat_CreatedFileIsEmpty) {
|
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) {
|
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,
|
REGISTER_TYPED_TEST_CASE_P(FsppFileTest,
|
||||||
|
Loading…
Reference in New Issue
Block a user