From 8f7853f01aaa5a271e7c2dc45b73ca05971ea75e Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Mon, 27 Apr 2015 16:38:09 +0200 Subject: [PATCH] Add basic test case for cryfs --- src/CryDevice.cpp | 2 ++ src/CryDevice.h | 6 ++---- test/CryFsTest.cpp | 35 +++++++++++++++++++++++++++++++++++ test/FileSystemTest.cpp | 4 ++-- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 test/CryFsTest.cpp diff --git a/src/CryDevice.cpp b/src/CryDevice.cpp index 46118f80..550c7c66 100644 --- a/src/CryDevice.cpp +++ b/src/CryDevice.cpp @@ -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; diff --git a/src/CryDevice.h b/src/CryDevice.h index 25c67501..0363bcf8 100644 --- a/src/CryDevice.h +++ b/src/CryDevice.h @@ -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 LoadBlob(const blockstore::Key &key); void RemoveBlob(const blockstore::Key &key); - std::unique_ptr Load(const bf::path &path) override; + std::unique_ptr Load(const boost::filesystem::path &path) override; - std::unique_ptr LoadDirBlob(const bf::path &path); + std::unique_ptr LoadDirBlob(const boost::filesystem::path &path); private: blockstore::Key GetOrCreateRootKey(CryConfig *config); diff --git a/test/CryFsTest.cpp b/test/CryFsTest.cpp new file mode 100644 index 00000000..ea41f0a8 --- /dev/null +++ b/test/CryFsTest.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#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(config.path()), make_unique(rootdir.path())); + dev.Load(bf::path("/")); + } + CryDevice dev(make_unique(config.path()), make_unique(rootdir.path())); + dev.Load(bf::path("/")); +} diff --git a/test/FileSystemTest.cpp b/test/FileSystemTest.cpp index 28a5ed91..4e8f12b9 100644 --- a/test/FileSystemTest.cpp +++ b/test/FileSystemTest.cpp @@ -20,8 +20,8 @@ public: : configFile(false) {} unique_ptr createDevice() override { - auto blockStore = make_unique(); - auto config = make_unique(configFile.path()); + auto blockStore = make_unique(); + auto config = make_unique(configFile.path()); return make_unique(std::move(config), std::move(blockStore)); }