libcryfs/fstest/testutils/FileSystemTest.h

54 lines
1.7 KiB
C
Raw Normal View History

2015-03-16 02:56:40 +01:00
#ifndef MESSMER_FSPP_FSTEST_TESTUTILS_FILESYSTEMTEST_H_
#define MESSMER_FSPP_FSTEST_TESTUTILS_FILESYSTEMTEST_H_
#include <google/gtest/gtest.h>
#include <type_traits>
#include <boost/static_assert.hpp>
2015-06-21 17:44:30 +02:00
#include <messmer/cpp-utils/pointer/unique_ref.h>
#include <messmer/cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
2015-03-16 02:56:40 +01:00
#include "../../fs_interface/Device.h"
#include "../../fs_interface/Dir.h"
#include "../../fs_interface/File.h"
#include "../../fs_interface/OpenFile.h"
class FileSystemTestFixture {
public:
virtual cpputils::unique_ref<fspp::Device> createDevice() = 0;
2015-03-16 02:56:40 +01:00
};
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;
cpputils::unique_ref<fspp::Device> device;
2015-03-16 02:56:40 +01:00
static constexpr mode_t MODE_PUBLIC = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
cpputils::unique_ref<fspp::Dir> LoadDir(const boost::filesystem::path &path) {
2015-03-16 02:56:40 +01:00
auto loaded = device->Load(path);
EXPECT_NE(boost::none, loaded);
auto dir = cpputils::dynamic_pointer_move<fspp::Dir>(*loaded);
EXPECT_NE(boost::none, dir);
return std::move(*dir);
2015-03-16 02:56:40 +01:00
}
cpputils::unique_ref<fspp::File> LoadFile(const boost::filesystem::path &path) {
2015-03-16 02:56:40 +01:00
auto loaded = device->Load(path);
EXPECT_NE(boost::none, loaded);
auto file = cpputils::dynamic_pointer_move<fspp::File>(*loaded);
EXPECT_NE(boost::none, file);
return std::move(*file);
2015-03-16 02:56:40 +01:00
}
};
#endif