Refactor FsTest
This commit is contained in:
parent
6b1bd62975
commit
cf8dfbd884
114
fstest/FsTest.h
114
fstest/FsTest.h
@ -1,116 +1,14 @@
|
|||||||
#ifndef MESSMER_FSPP_FSTEST_FSTEST_H_
|
#ifndef MESSMER_FSPP_FSTEST_FSTEST_H_
|
||||||
#define MESSMER_FSPP_FSTEST_FSTEST_H_
|
#define MESSMER_FSPP_FSTEST_FSTEST_H_
|
||||||
|
|
||||||
#include <memory>
|
#include "testutils/FileSystemTest.h"
|
||||||
#include <google/gtest/gtest.h>
|
#include "FsppDeviceTest.h"
|
||||||
#include <boost/static_assert.hpp>
|
#include "FsppDirTest.h"
|
||||||
#include <type_traits>
|
|
||||||
#include <messmer/cpp-utils/pointer.h>
|
|
||||||
|
|
||||||
#include "../fs_interface/Device.h"
|
#define FSPP_ADD_FILESYTEM_TESTS(FS_NAME, FIXTURE) \
|
||||||
#include "../fs_interface/Dir.h"
|
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDeviceTest, FIXTURE); \
|
||||||
#include "../fs_interface/File.h"
|
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDirTest, FIXTURE);
|
||||||
#include "../fs_interface/OpenFile.h"
|
|
||||||
|
|
||||||
class FileSystemTestFixture {
|
|
||||||
public:
|
|
||||||
virtual std::unique_ptr<fspp::Device> createDevice() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
|
||||||
class FileSystemTest: public ::testing::Test {
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_ASSERT_MSG(
|
|
||||||
(std::is_base_of<FileSystemTestFixture, ConcreteFileSystemTestFixture>::value),
|
|
||||||
"Given test fixture for instantiating the (type parameterized) FileSystemTest must inherit from FileSystemTestFixture"
|
|
||||||
);
|
|
||||||
|
|
||||||
FileSystemTest(): fixture(), device(fixture.createDevice()) {}
|
|
||||||
|
|
||||||
ConcreteFileSystemTestFixture fixture;
|
|
||||||
std::unique_ptr<fspp::Device> device;
|
|
||||||
|
|
||||||
std::unique_ptr<fspp::Dir> LoadDir(const boost::filesystem::path &path) {
|
|
||||||
auto loaded = device->Load(path);
|
|
||||||
auto dir = cpputils::dynamic_pointer_move<fspp::Dir>(loaded);
|
|
||||||
EXPECT_NE(nullptr, dir.get());
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<fspp::File> LoadFile(const boost::filesystem::path &path) {
|
|
||||||
auto loaded = device->Load(path);
|
|
||||||
auto file = cpputils::dynamic_pointer_move<fspp::File>(loaded);
|
|
||||||
EXPECT_NE(nullptr, file.get());
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TYPED_TEST_CASE_P(FileSystemTest);
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, InitFilesystem) {
|
|
||||||
//fixture->createDevice() is called in the FileSystemTest constructor
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, LoadRootDir) {
|
|
||||||
this->LoadDir("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, LoadEntriesOfEmptyRootDir) {
|
|
||||||
auto rootdir = this->LoadDir("/");
|
|
||||||
auto children = rootdir->children();
|
|
||||||
EXPECT_EQ(0, children->size());
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, AddFileToRootDirAndLoadEntries) {
|
|
||||||
auto rootdir = this->LoadDir("/");
|
|
||||||
rootdir->createAndOpenFile("myfile", 0);
|
|
||||||
auto children = rootdir->children();
|
|
||||||
EXPECT_EQ(1, children->size());
|
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
|
||||||
EXPECT_EQ("myfile", (*children)[0].name);
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, AddFileToRootDirAndLoadIt) {
|
|
||||||
this->LoadDir("/")->createAndOpenFile("myfile", 0);
|
|
||||||
this->LoadFile("/myfile");
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, AddDirToRootDirAndLoadEntries) {
|
|
||||||
auto rootdir = this->LoadDir("/");
|
|
||||||
rootdir->createDir("mydir", 0);
|
|
||||||
auto children = rootdir->children();
|
|
||||||
EXPECT_EQ(1, children->size());
|
|
||||||
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
|
|
||||||
EXPECT_EQ("mydir", (*children)[0].name);
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPED_TEST_P(FileSystemTest, AddDirToRootDirAndLoadIt) {
|
|
||||||
this->LoadDir("/")->createDir("mydir", 0);
|
|
||||||
this->LoadDir("/mydir");
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO Group test cases to fspp functions (e.g. AddFileToRootDirAndLoadEntries to Dir::children(). AddFileToRootDirAndLoadIt to Device::Load and to Dir::createAndOpenFile.
|
|
||||||
|
|
||||||
//TODO Add File/Dir to subdir and check entries
|
|
||||||
//TODO Add File/Dir to subdir and load it using path
|
|
||||||
//TODO Add File/Dir to subsubdir and check entries
|
|
||||||
//TODO Add File/Dir to subsubdir and load it using path
|
|
||||||
//TODO Build dir structure with more than one entry
|
|
||||||
|
|
||||||
//TODO ...
|
//TODO ...
|
||||||
|
|
||||||
|
|
||||||
//TODO statfs
|
|
||||||
|
|
||||||
REGISTER_TYPED_TEST_CASE_P(FileSystemTest,
|
|
||||||
InitFilesystem,
|
|
||||||
LoadRootDir,
|
|
||||||
LoadEntriesOfEmptyRootDir,
|
|
||||||
AddFileToRootDirAndLoadEntries,
|
|
||||||
AddFileToRootDirAndLoadIt,
|
|
||||||
AddDirToRootDirAndLoadEntries,
|
|
||||||
AddDirToRootDirAndLoadIt
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
39
fstest/FsppDeviceTest.h
Normal file
39
fstest/FsppDeviceTest.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef MESSMER_FSPP_FSTEST_FSPPDEVICETEST_H_
|
||||||
|
#define MESSMER_FSPP_FSTEST_FSPPDEVICETEST_H_
|
||||||
|
|
||||||
|
template<class ConcreteFileSystemTestFixture>
|
||||||
|
class FsppDeviceTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
||||||
|
};
|
||||||
|
|
||||||
|
TYPED_TEST_CASE_P(FsppDeviceTest);
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDeviceTest, InitFilesystem) {
|
||||||
|
//fixture->createDevice() is called in the FileSystemTest constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDeviceTest, LoadRootDir) {
|
||||||
|
this->LoadDir("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDeviceTest, LoadFileFromRootDir) {
|
||||||
|
this->LoadDir("/")->createAndOpenFile("myfile", 0);
|
||||||
|
this->LoadFile("/myfile");
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDeviceTest, LoadDirFromRootDir) {
|
||||||
|
this->LoadDir("/")->createDir("mydir", 0);
|
||||||
|
this->LoadDir("/mydir");
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO Load file/dir which is more nested
|
||||||
|
//TODO Load from dir structure with more than one entry per dir
|
||||||
|
//TODO statfs
|
||||||
|
|
||||||
|
REGISTER_TYPED_TEST_CASE_P(FsppDeviceTest,
|
||||||
|
InitFilesystem,
|
||||||
|
LoadRootDir,
|
||||||
|
LoadFileFromRootDir,
|
||||||
|
LoadDirFromRootDir
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
56
fstest/FsppDirTest.h
Normal file
56
fstest/FsppDirTest.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#ifndef MESSMER_FSPP_FSTEST_FSPPDIRTEST_H_
|
||||||
|
#define MESSMER_FSPP_FSTEST_FSPPDIRTEST_H_
|
||||||
|
|
||||||
|
template<class ConcreteFileSystemTestFixture>
|
||||||
|
class FsppDirTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
||||||
|
};
|
||||||
|
TYPED_TEST_CASE_P(FsppDirTest);
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDirTest, Children_EmptyRootDir) {
|
||||||
|
auto rootdir = this->LoadDir("/");
|
||||||
|
auto children = rootdir->children();
|
||||||
|
EXPECT_EQ(0, children->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDirTest, Children_OneFileInRootDir) {
|
||||||
|
auto rootdir = this->LoadDir("/");
|
||||||
|
rootdir->createAndOpenFile("myfile", 0);
|
||||||
|
auto children = rootdir->children();
|
||||||
|
EXPECT_EQ(1, children->size());
|
||||||
|
EXPECT_EQ(fspp::Dir::EntryType::FILE, (*children)[0].type);
|
||||||
|
EXPECT_EQ("myfile", (*children)[0].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDirTest, Children_OneDirInRootDir) {
|
||||||
|
auto rootdir = this->LoadDir("/");
|
||||||
|
rootdir->createDir("mydir", 0);
|
||||||
|
auto children = rootdir->children();
|
||||||
|
EXPECT_EQ(1, children->size());
|
||||||
|
EXPECT_EQ(fspp::Dir::EntryType::DIR, (*children)[0].type);
|
||||||
|
EXPECT_EQ("mydir", (*children)[0].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDirTest, CreateAndOpenFile_LoadAfterwards) {
|
||||||
|
this->LoadDir("/")->createAndOpenFile("myfile", 0);
|
||||||
|
this->LoadFile("/myfile");
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST_P(FsppDirTest, CreateDir_LoadAfterwards) {
|
||||||
|
this->LoadDir("/")->createDir("mydir", 0);
|
||||||
|
this->LoadDir("/mydir");
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_TYPED_TEST_CASE_P(FsppDirTest,
|
||||||
|
Children_EmptyRootDir,
|
||||||
|
Children_OneFileInRootDir,
|
||||||
|
Children_OneDirInRootDir,
|
||||||
|
CreateAndOpenFile_LoadAfterwards,
|
||||||
|
CreateDir_LoadAfterwards
|
||||||
|
);
|
||||||
|
|
||||||
|
//TODO Add File/Dir to subdir/subsubdir and check entries
|
||||||
|
//TODO Build dir structure with more than one entry
|
||||||
|
|
||||||
|
//TODO rmdir
|
||||||
|
|
||||||
|
#endif
|
50
fstest/testutils/FileSystemTest.h
Normal file
50
fstest/testutils/FileSystemTest.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef MESSMER_FSPP_FSTEST_TESTUTILS_FILESYSTEMTEST_H_
|
||||||
|
#define MESSMER_FSPP_FSTEST_TESTUTILS_FILESYSTEMTEST_H_
|
||||||
|
|
||||||
|
#include <google/gtest/gtest.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <messmer/cpp-utils/pointer.h>
|
||||||
|
|
||||||
|
#include "../../fs_interface/Device.h"
|
||||||
|
#include "../../fs_interface/Dir.h"
|
||||||
|
#include "../../fs_interface/File.h"
|
||||||
|
#include "../../fs_interface/OpenFile.h"
|
||||||
|
|
||||||
|
class FileSystemTestFixture {
|
||||||
|
public:
|
||||||
|
virtual std::unique_ptr<fspp::Device> createDevice() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class ConcreteFileSystemTestFixture>
|
||||||
|
class FileSystemTest: public ::testing::Test {
|
||||||
|
public:
|
||||||
|
BOOST_STATIC_ASSERT_MSG(
|
||||||
|
(std::is_base_of<FileSystemTestFixture, ConcreteFileSystemTestFixture>::value),
|
||||||
|
"Given test fixture for instantiating the (type parameterized) FileSystemTest must inherit from FileSystemTestFixture"
|
||||||
|
);
|
||||||
|
|
||||||
|
FileSystemTest(): fixture(), device(fixture.createDevice()) {}
|
||||||
|
|
||||||
|
ConcreteFileSystemTestFixture fixture;
|
||||||
|
std::unique_ptr<fspp::Device> device;
|
||||||
|
|
||||||
|
std::unique_ptr<fspp::Dir> LoadDir(const boost::filesystem::path &path) {
|
||||||
|
auto loaded = device->Load(path);
|
||||||
|
auto dir = cpputils::dynamic_pointer_move<fspp::Dir>(loaded);
|
||||||
|
EXPECT_NE(nullptr, dir.get());
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<fspp::File> LoadFile(const boost::filesystem::path &path) {
|
||||||
|
auto loaded = device->Load(path);
|
||||||
|
auto file = cpputils::dynamic_pointer_move<fspp::File>(loaded);
|
||||||
|
EXPECT_NE(nullptr, file.get());
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user