libcryfs/test/filesystem/CryFsTest.cpp

65 lines
2.2 KiB
C++
Raw Normal View History

2015-04-27 16:38:09 +02:00
#include <google/gtest/gtest.h>
#include <messmer/cpp-utils/tempfile/TempDir.h>
#include <messmer/cpp-utils/tempfile/TempFile.h>
2015-06-21 17:44:45 +02:00
#include <messmer/cpp-utils/pointer/cast.h>
2015-04-27 16:38:09 +02:00
#include <messmer/blockstore/implementations/ondisk/OnDiskBlockStore.h>
2015-09-12 20:16:13 +02:00
#include "../../src/filesystem/CryDevice.h"
#include "../../src/filesystem/CryDir.h"
#include "../../src/filesystem/CryFile.h"
#include "../../src/filesystem/CryOpenFile.h"
2015-10-22 18:48:04 +02:00
#include "../testutils/MockConsole.h"
2015-04-27 16:38:09 +02:00
//TODO (whole project) Make constructors explicit when implicit construction not needed
using ::testing::Test;
2015-10-22 18:48:04 +02:00
using ::testing::Return;
using ::testing::_;
2015-04-27 16:38:09 +02:00
using cpputils::TempDir;
using cpputils::TempFile;
using cpputils::dynamic_pointer_move;
2015-07-21 18:22:03 +02:00
using cpputils::make_unique_ref;
using cpputils::unique_ref;
2015-09-12 20:16:13 +02:00
using cpputils::Console;
2015-04-27 16:38:09 +02:00
using blockstore::ondisk::OnDiskBlockStore;
namespace bf = boost::filesystem;
using namespace cryfs;
class CryFsTest: public Test {
public:
2015-10-22 18:48:04 +02:00
CryFsTest(): rootdir(), config(false) {
}
unique_ref<MockConsole> mockConsole() {
auto console = make_unique_ref<MockConsole>();
EXPECT_CALL(*console, ask(_, _)).WillRepeatedly(Return(0));
EXPECT_CALL(*console, askYesNo(_)).WillRepeatedly(Return(true));
return console;
}
2015-04-27 16:38:09 +02:00
TempDir rootdir;
TempFile config;
};
2015-10-22 18:48:04 +02:00
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing_1) {
2015-06-17 12:28:18 +02:00
{
2015-10-22 18:48:04 +02:00
CryDevice dev(
CryConfigLoader(mockConsole(), cpputils::Random::PseudoRandom())
.createNew(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path())
);
2015-06-17 12:28:18 +02:00
}
2015-10-19 14:22:01 +02:00
CryDevice dev(CryConfigFile::load(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
2015-06-17 12:28:18 +02:00
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root.get()).get()->children();
2015-06-17 12:28:18 +02:00
}
2015-10-22 18:48:04 +02:00
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing_2) {
2015-06-17 12:28:18 +02:00
{
2015-10-22 18:48:04 +02:00
CryDevice dev(
CryConfigLoader(mockConsole(), cpputils::Random::PseudoRandom())
.loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path())
);
2015-06-17 12:28:18 +02:00
}
CryDevice dev(CryConfigLoader().loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root.get()).get()->children();
2015-04-27 16:38:09 +02:00
}