Add basic test case for cryfs

This commit is contained in:
Sebastian Messmer 2015-04-27 16:38:09 +02:00
parent 74e9ffb9f4
commit 8f7853f01a
4 changed files with 41 additions and 6 deletions

View File

@ -28,6 +28,8 @@ using blobstore::onblocks::BlobStoreOnBlocks;
using blobstore::onblocks::BlobOnBlocks;
using blockstore::caching::CachingBlockStore;
namespace bf = boost::filesystem;
namespace cryfs {
constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;

View File

@ -15,8 +15,6 @@
namespace cryfs {
class DirBlob;
namespace bf = boost::filesystem;
class CryDevice: public fspp::Device {
public:
static constexpr uint32_t BLOCKSIZE_BYTES = 32 * 1024;
@ -32,9 +30,9 @@ public:
std::unique_ptr<blobstore::Blob> LoadBlob(const blockstore::Key &key);
void RemoveBlob(const blockstore::Key &key);
std::unique_ptr<fspp::Node> Load(const bf::path &path) override;
std::unique_ptr<fspp::Node> Load(const boost::filesystem::path &path) override;
std::unique_ptr<DirBlob> LoadDirBlob(const bf::path &path);
std::unique_ptr<DirBlob> LoadDirBlob(const boost::filesystem::path &path);
private:
blockstore::Key GetOrCreateRootKey(CryConfig *config);

35
test/CryFsTest.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <google/gtest/gtest.h>
#include <messmer/cpp-utils/tempfile/TempDir.h>
#include <messmer/cpp-utils/tempfile/TempFile.h>
#include <messmer/cpp-utils/pointer.h>
#include <messmer/blockstore/implementations/ondisk/OnDiskBlockStore.h>
#include "../src/CryDevice.h"
#include "../src/CryDir.h"
//TODO (whole project) Make constructors explicit when implicit construction not needed
using ::testing::Test;
using cpputils::TempDir;
using cpputils::TempFile;
using cpputils::dynamic_pointer_move;
using std::make_unique;
using blockstore::ondisk::OnDiskBlockStore;
namespace bf = boost::filesystem;
using namespace cryfs;
class CryFsTest: public Test {
public:
CryFsTest(): rootdir(), config(false) {}
TempDir rootdir;
TempFile config;
};
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
{
CryDevice dev(make_unique<CryConfig>(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
dev.Load(bf::path("/"));
}
CryDevice dev(make_unique<CryConfig>(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
dev.Load(bf::path("/"));
}

View File

@ -20,8 +20,8 @@ public:
: configFile(false) {}
unique_ptr<Device> createDevice() override {
auto blockStore = make_unique<FakeBlockStore>();
auto config = make_unique<CryConfig>(configFile.path());
auto blockStore = make_unique<FakeBlockStore>();
auto config = make_unique<CryConfig>(configFile.path());
return make_unique<CryDevice>(std::move(config), std::move(blockStore));
}