Finished migrating to unique_ref instead of unique_ptr

This commit is contained in:
Sebastian Messmer 2015-07-21 18:19:34 +02:00
parent f4d9d271ea
commit 37bdbd907a
32 changed files with 69 additions and 104 deletions

View File

@ -1,7 +1,6 @@
#include "CachedBlock.h" #include "CachedBlock.h"
#include "CachingBlockStore.h" #include "CachingBlockStore.h"
using std::unique_ptr;
using cpputils::unique_ref; using cpputils::unique_ref;
namespace blockstore { namespace blockstore {

View File

@ -6,8 +6,6 @@
#include <algorithm> #include <algorithm>
#include <messmer/cpp-utils/pointer/cast.h> #include <messmer/cpp-utils/pointer/cast.h>
using std::unique_ptr;
using std::make_unique;
using cpputils::dynamic_pointer_move; using cpputils::dynamic_pointer_move;
using cpputils::Data; using cpputils::Data;
using boost::optional; using boost::optional;
@ -18,7 +16,7 @@ using boost::none;
namespace blockstore { namespace blockstore {
namespace caching { namespace caching {
CachingBlockStore::CachingBlockStore(std::unique_ptr<BlockStore> baseBlockStore) CachingBlockStore::CachingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore)
:_baseBlockStore(std::move(baseBlockStore)), _cache(), _numNewBlocks(0) { :_baseBlockStore(std::move(baseBlockStore)), _cache(), _numNewBlocks(0) {
} }

View File

@ -11,7 +11,7 @@ namespace caching {
//TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel) //TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel)
class CachingBlockStore: public BlockStore { class CachingBlockStore: public BlockStore {
public: public:
explicit CachingBlockStore(std::unique_ptr<BlockStore> baseBlockStore); explicit CachingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore);
Key createKey() override; Key createKey() override;
boost::optional<cpputils::unique_ref<Block>> tryCreate(const Key &key, cpputils::Data data) override; boost::optional<cpputils::unique_ref<Block>> tryCreate(const Key &key, cpputils::Data data) override;
@ -25,7 +25,7 @@ public:
void removeFromBaseStore(cpputils::unique_ref<Block> block); void removeFromBaseStore(cpputils::unique_ref<Block> block);
private: private:
std::unique_ptr<BlockStore> _baseBlockStore; cpputils::unique_ref<BlockStore> _baseBlockStore;
Cache<Key, cpputils::unique_ref<Block>> _cache; Cache<Key, cpputils::unique_ref<Block>> _cache;
uint32_t _numNewBlocks; uint32_t _numNewBlocks;

View File

@ -1,7 +1,6 @@
#include "NewBlock.h" #include "NewBlock.h"
#include "CachingBlockStore.h" #include "CachingBlockStore.h"
using std::unique_ptr;
using cpputils::Data; using cpputils::Data;
using boost::none; using boost::none;

View File

@ -14,7 +14,7 @@ namespace encrypted {
template<class Cipher> template<class Cipher>
class EncryptedBlockStore: public BlockStore { class EncryptedBlockStore: public BlockStore {
public: public:
EncryptedBlockStore(std::unique_ptr<BlockStore> baseBlockStore, const typename Cipher::EncryptionKey &encKey); EncryptedBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const typename Cipher::EncryptionKey &encKey);
//TODO Are createKey() tests included in generic BlockStoreTest? If not, add it! //TODO Are createKey() tests included in generic BlockStoreTest? If not, add it!
Key createKey() override; Key createKey() override;
@ -27,7 +27,7 @@ public:
void __setKey(const typename Cipher::EncryptionKey &encKey); void __setKey(const typename Cipher::EncryptionKey &encKey);
private: private:
std::unique_ptr<BlockStore> _baseBlockStore; cpputils::unique_ref<BlockStore> _baseBlockStore;
typename Cipher::EncryptionKey _encKey; typename Cipher::EncryptionKey _encKey;
DISALLOW_COPY_AND_ASSIGN(EncryptedBlockStore); DISALLOW_COPY_AND_ASSIGN(EncryptedBlockStore);
@ -36,7 +36,7 @@ private:
template<class Cipher> template<class Cipher>
EncryptedBlockStore<Cipher>::EncryptedBlockStore(std::unique_ptr<BlockStore> baseBlockStore, const typename Cipher::EncryptionKey &encKey) EncryptedBlockStore<Cipher>::EncryptedBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const typename Cipher::EncryptionKey &encKey)
: _baseBlockStore(std::move(baseBlockStore)), _encKey(encKey) { : _baseBlockStore(std::move(baseBlockStore)), _encKey(encKey) {
} }

View File

@ -2,7 +2,6 @@
#include "InMemoryBlockStore.h" #include "InMemoryBlockStore.h"
#include <cstring> #include <cstring>
using std::unique_ptr;
using std::make_shared; using std::make_shared;
using std::istream; using std::istream;
using std::ostream; using std::ostream;

View File

@ -2,7 +2,6 @@
#include "InMemoryBlockStore.h" #include "InMemoryBlockStore.h"
#include <memory> #include <memory>
using std::unique_ptr;
using std::make_unique; using std::make_unique;
using std::string; using std::string;
using std::mutex; using std::mutex;
@ -43,7 +42,7 @@ optional<unique_ref<Block>> InMemoryBlockStore::load(const Key &key) {
void InMemoryBlockStore::remove(unique_ref<Block> block) { void InMemoryBlockStore::remove(unique_ref<Block> block) {
Key key = block->key(); Key key = block->key();
cpputils::to_unique_ptr(std::move(block)).reset(); // Call destructor cpputils::destruct(std::move(block));
int numRemoved = _blocks.erase(key.ToString()); int numRemoved = _blocks.erase(key.ToString());
assert(1==numRemoved); assert(1==numRemoved);
} }

View File

@ -5,8 +5,6 @@
#include "OnDiskBlockStore.h" #include "OnDiskBlockStore.h"
#include "../../utils/FileDoesntExistException.h" #include "../../utils/FileDoesntExistException.h"
using std::unique_ptr;
using std::make_unique;
using std::istream; using std::istream;
using std::ostream; using std::ostream;
using std::ifstream; using std::ifstream;

View File

@ -1,8 +1,6 @@
#include "OnDiskBlock.h" #include "OnDiskBlock.h"
#include "OnDiskBlockStore.h" #include "OnDiskBlockStore.h"
using std::unique_ptr;
using std::make_unique;
using std::string; using std::string;
using cpputils::Data; using cpputils::Data;
using cpputils::unique_ref; using cpputils::unique_ref;
@ -32,7 +30,7 @@ optional<unique_ref<Block>> OnDiskBlockStore::load(const Key &key) {
void OnDiskBlockStore::remove(unique_ref<Block> block) { void OnDiskBlockStore::remove(unique_ref<Block> block) {
Key key = block->key(); Key key = block->key();
cpputils::to_unique_ptr(std::move(block)).reset(); // Call destructor cpputils::destruct(std::move(block));
OnDiskBlock::RemoveFromDisk(_rootdir, key); OnDiskBlock::RemoveFromDisk(_rootdir, key);
} }

View File

@ -4,9 +4,6 @@
#include <cassert> #include <cassert>
#include <messmer/cpp-utils/pointer/cast.h> #include <messmer/cpp-utils/pointer/cast.h>
using std::unique_ptr;
using std::make_unique;
using std::string; using std::string;
using std::mutex; using std::mutex;
using std::lock_guard; using std::lock_guard;

View File

@ -2,7 +2,6 @@
#include "FakeBlockStore.h" #include "FakeBlockStore.h"
#include <cstring> #include <cstring>
using std::unique_ptr;
using std::shared_ptr; using std::shared_ptr;
using std::istream; using std::istream;
using std::ostream; using std::ostream;

View File

@ -1,8 +1,6 @@
#include "FakeBlock.h" #include "FakeBlock.h"
#include "FakeBlockStore.h" #include "FakeBlockStore.h"
using std::unique_ptr;
using std::make_unique;
using std::make_shared; using std::make_shared;
using std::string; using std::string;
using std::mutex; using std::mutex;
@ -42,7 +40,7 @@ optional<unique_ref<Block>> FakeBlockStore::load(const Key &key) {
void FakeBlockStore::remove(unique_ref<Block> block) { void FakeBlockStore::remove(unique_ref<Block> block) {
Key key = block->key(); Key key = block->key();
cpputils::to_unique_ptr(std::move(block)).reset(); // Call destructor cpputils::destruct(std::move(block));
int numRemoved = _blocks.erase(key.ToString()); int numRemoved = _blocks.erase(key.ToString());
assert(numRemoved == 1); assert(numRemoved == 1);
} }

View File

@ -7,14 +7,13 @@
using blockstore::BlockStore; using blockstore::BlockStore;
using blockstore::caching::CachingBlockStore; using blockstore::caching::CachingBlockStore;
using blockstore::testfake::FakeBlockStore; using blockstore::testfake::FakeBlockStore;
using cpputils::unique_ref;
using std::unique_ptr; using cpputils::make_unique_ref;
using std::make_unique;
class CachingBlockStoreTestFixture: public BlockStoreTestFixture { class CachingBlockStoreTestFixture: public BlockStoreTestFixture {
public: public:
unique_ptr<BlockStore> createBlockStore() override { unique_ref<BlockStore> createBlockStore() override {
return make_unique<CachingBlockStore>(make_unique<FakeBlockStore>()); return make_unique_ref<CachingBlockStore>(make_unique_ref<FakeBlockStore>());
} }
}; };

View File

@ -1,23 +1,22 @@
#include <google/gtest/gtest.h> #include <google/gtest/gtest.h>
#include <memory> #include <messmer/cpp-utils/pointer/unique_ref.h>
#include "../../../../implementations/caching/cache/Cache.h" #include "../../../../implementations/caching/cache/Cache.h"
#include "testutils/MinimalKeyType.h" #include "testutils/MinimalKeyType.h"
#include "testutils/CopyableMovableValueType.h" #include "testutils/CopyableMovableValueType.h"
using namespace blockstore::caching; using namespace blockstore::caching;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using ::testing::Test; using ::testing::Test;
using std::unique_ptr;
using std::make_unique;
//Test that Cache uses a move constructor for Value if possible //Test that Cache uses a move constructor for Value if possible
class CacheTest_MoveConstructor: public Test { class CacheTest_MoveConstructor: public Test {
public: public:
CacheTest_MoveConstructor() { CacheTest_MoveConstructor(): cache(make_unique_ref<Cache<MinimalKeyType, CopyableMovableValueType>>()) {
CopyableMovableValueType::numCopyConstructorCalled = 0; CopyableMovableValueType::numCopyConstructorCalled = 0;
cache = make_unique<Cache<MinimalKeyType, CopyableMovableValueType>>();
} }
unique_ptr<Cache<MinimalKeyType, CopyableMovableValueType>> cache; unique_ref<Cache<MinimalKeyType, CopyableMovableValueType>> cache;
}; };
TEST_F(CacheTest_MoveConstructor, MoveIntoCache) { TEST_F(CacheTest_MoveConstructor, MoveIntoCache) {

View File

@ -1,5 +1,5 @@
#include <google/gtest/gtest.h> #include <google/gtest/gtest.h>
#include <memory> #include <messmer/cpp-utils/pointer/unique_ref.h>
#include "../../../../implementations/caching/cache/QueueMap.h" #include "../../../../implementations/caching/cache/QueueMap.h"
#include "testutils/MinimalKeyType.h" #include "testutils/MinimalKeyType.h"
#include "testutils/CopyableMovableValueType.h" #include "testutils/CopyableMovableValueType.h"
@ -7,17 +7,16 @@
using namespace blockstore::caching; using namespace blockstore::caching;
using ::testing::Test; using ::testing::Test;
using std::unique_ptr; using cpputils::unique_ref;
using std::make_unique; using cpputils::make_unique_ref;
//Test that QueueMap uses a move constructor for Value if possible //Test that QueueMap uses a move constructor for Value if possible
class QueueMapTest_MoveConstructor: public Test { class QueueMapTest_MoveConstructor: public Test {
public: public:
QueueMapTest_MoveConstructor() { QueueMapTest_MoveConstructor(): map(make_unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>>()) {
CopyableMovableValueType::numCopyConstructorCalled = 0; CopyableMovableValueType::numCopyConstructorCalled = 0;
map = make_unique<QueueMap<MinimalKeyType, CopyableMovableValueType>>();
} }
unique_ptr<QueueMap<MinimalKeyType, CopyableMovableValueType>> map; unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>> map;
}; };
TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_MoveIntoMap) { TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_MoveIntoMap) {

View File

@ -1,13 +1,12 @@
#include "QueueMapTest.h" #include "QueueMapTest.h"
QueueMapTest::QueueMapTest() { QueueMapTest::QueueMapTest(): _map(cpputils::make_unique_ref<blockstore::caching::QueueMap<MinimalKeyType, MinimalValueType>>()) {
MinimalKeyType::instances = 0; MinimalKeyType::instances = 0;
MinimalValueType::instances = 0; MinimalValueType::instances = 0;
_map = std::make_unique<blockstore::caching::QueueMap<MinimalKeyType, MinimalValueType>>();
} }
QueueMapTest::~QueueMapTest() { QueueMapTest::~QueueMapTest() {
_map.reset(); cpputils::destruct(std::move(_map));
EXPECT_EQ(0, MinimalKeyType::instances); EXPECT_EQ(0, MinimalKeyType::instances);
EXPECT_EQ(0, MinimalValueType::instances); EXPECT_EQ(0, MinimalValueType::instances);
} }

View File

@ -3,7 +3,7 @@
#define BLOCKS_MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_CACHING_CACHE_TESTUTILS_QUEUEMAPTEST_H_ #define BLOCKS_MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_CACHING_CACHE_TESTUTILS_QUEUEMAPTEST_H_
#include <google/gtest/gtest.h> #include <google/gtest/gtest.h>
#include <memory> #include <messmer/cpp-utils/pointer/unique_ref.h>
#include "../../../../../implementations/caching/cache/QueueMap.h" #include "../../../../../implementations/caching/cache/QueueMap.h"
#include "MinimalKeyType.h" #include "MinimalKeyType.h"
#include "MinimalValueType.h" #include "MinimalValueType.h"
@ -24,9 +24,8 @@ public:
int size(); int size();
private: private:
std::unique_ptr<blockstore::caching::QueueMap<MinimalKeyType, MinimalValueType>> _map; cpputils::unique_ref<blockstore::caching::QueueMap<MinimalKeyType, MinimalValueType>> _map;
}; };
#endif #endif

View File

@ -15,17 +15,16 @@ using blockstore::testfake::FakeBlockStore;
using blockstore::encrypted::AES256_GCM; using blockstore::encrypted::AES256_GCM;
using blockstore::encrypted::AES256_CFB; using blockstore::encrypted::AES256_CFB;
using std::unique_ptr;
using std::make_unique;
using cpputils::Data; using cpputils::Data;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::make_unique_ref;
using cpputils::unique_ref;
template<class Cipher> template<class Cipher>
class EncryptedBlockStoreTestFixture: public BlockStoreTestFixture { class EncryptedBlockStoreTestFixture: public BlockStoreTestFixture {
public: public:
unique_ptr<BlockStore> createBlockStore() override { unique_ref<BlockStore> createBlockStore() override {
return make_unique<EncryptedBlockStore<Cipher>>(make_unique<FakeBlockStore>(), createKeyFixture()); return make_unique_ref<EncryptedBlockStore<Cipher>>(make_unique_ref<FakeBlockStore>(), createKeyFixture());
} }
private: private:

View File

@ -7,11 +7,10 @@
using ::testing::Test; using ::testing::Test;
using std::unique_ptr;
using std::make_unique;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::Data; using cpputils::Data;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using blockstore::testfake::FakeBlockStore; using blockstore::testfake::FakeBlockStore;
@ -21,14 +20,12 @@ class EncryptedBlockStoreTest: public Test {
public: public:
static constexpr unsigned int BLOCKSIZE = 1024; static constexpr unsigned int BLOCKSIZE = 1024;
EncryptedBlockStoreTest(): EncryptedBlockStoreTest():
_baseBlockStore(make_unique<FakeBlockStore>()), baseBlockStore(new FakeBlockStore),
baseBlockStore(_baseBlockStore.get()), blockStore(make_unique_ref<EncryptedBlockStore<FakeAuthenticatedCipher>>(std::move(cpputils::nullcheck(std::unique_ptr<FakeBlockStore>(baseBlockStore)).value()), FakeAuthenticatedCipher::Key1())),
blockStore(make_unique<EncryptedBlockStore<FakeAuthenticatedCipher>>(std::move(_baseBlockStore), FakeAuthenticatedCipher::Key1())),
data(DataFixture::generate(BLOCKSIZE)) { data(DataFixture::generate(BLOCKSIZE)) {
} }
unique_ptr<FakeBlockStore> _baseBlockStore;
FakeBlockStore *baseBlockStore; FakeBlockStore *baseBlockStore;
unique_ptr<EncryptedBlockStore<FakeAuthenticatedCipher>> blockStore; unique_ref<EncryptedBlockStore<FakeAuthenticatedCipher>> blockStore;
Data data; Data data;
blockstore::Key CreateBlockDirectlyWithFixtureAndReturnKey() { blockstore::Key CreateBlockDirectlyWithFixtureAndReturnKey() {

View File

@ -9,14 +9,13 @@
using blockstore::BlockStore; using blockstore::BlockStore;
using blockstore::BlockStoreWithRandomKeys; using blockstore::BlockStoreWithRandomKeys;
using blockstore::inmemory::InMemoryBlockStore; using blockstore::inmemory::InMemoryBlockStore;
using cpputils::unique_ref;
using std::unique_ptr; using cpputils::make_unique_ref;
using std::make_unique;
class InMemoryBlockStoreTestFixture: public BlockStoreTestFixture { class InMemoryBlockStoreTestFixture: public BlockStoreTestFixture {
public: public:
unique_ptr<BlockStore> createBlockStore() override { unique_ref<BlockStore> createBlockStore() override {
return make_unique<InMemoryBlockStore>(); return make_unique_ref<InMemoryBlockStore>();
} }
}; };
@ -24,8 +23,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(InMemory, BlockStoreTest, InMemoryBlockStoreTestFi
class InMemoryBlockStoreWithRandomKeysTestFixture: public BlockStoreWithRandomKeysTestFixture { class InMemoryBlockStoreWithRandomKeysTestFixture: public BlockStoreWithRandomKeysTestFixture {
public: public:
unique_ptr<BlockStoreWithRandomKeys> createBlockStore() override { unique_ref<BlockStoreWithRandomKeys> createBlockStore() override {
return make_unique<InMemoryBlockStore>(); return make_unique_ref<InMemoryBlockStore>();
} }
}; };

View File

@ -11,15 +11,14 @@ using blockstore::BlockStore;
using blockstore::BlockStoreWithRandomKeys; using blockstore::BlockStoreWithRandomKeys;
using blockstore::ondisk::OnDiskBlockStore; using blockstore::ondisk::OnDiskBlockStore;
using std::unique_ptr;
using std::make_unique;
using cpputils::TempDir; using cpputils::TempDir;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
class OnDiskBlockStoreTestFixture: public BlockStoreTestFixture { class OnDiskBlockStoreTestFixture: public BlockStoreTestFixture {
public: public:
unique_ptr<BlockStore> createBlockStore() override { unique_ref<BlockStore> createBlockStore() override {
return make_unique<OnDiskBlockStore>(tempdir.path()); return make_unique_ref<OnDiskBlockStore>(tempdir.path());
} }
private: private:
TempDir tempdir; TempDir tempdir;
@ -29,8 +28,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(OnDisk, BlockStoreTest, OnDiskBlockStoreTestFixtur
class OnDiskBlockStoreWithRandomKeysTestFixture: public BlockStoreWithRandomKeysTestFixture { class OnDiskBlockStoreWithRandomKeysTestFixture: public BlockStoreWithRandomKeysTestFixture {
public: public:
unique_ptr<BlockStoreWithRandomKeys> createBlockStore() override { unique_ref<BlockStoreWithRandomKeys> createBlockStore() override {
return make_unique<OnDiskBlockStore>(tempdir.path()); return make_unique_ref<OnDiskBlockStore>(tempdir.path());
} }
private: private:
TempDir tempdir; TempDir tempdir;

View File

@ -7,8 +7,6 @@
using ::testing::Test; using ::testing::Test;
using ::testing::WithParamInterface; using ::testing::WithParamInterface;
using ::testing::Values; using ::testing::Values;
using std::unique_ptr;
using cpputils::Data; using cpputils::Data;
using cpputils::TempFile; using cpputils::TempFile;
using cpputils::TempDir; using cpputils::TempDir;

View File

@ -9,7 +9,6 @@ using ::testing::Test;
using ::testing::WithParamInterface; using ::testing::WithParamInterface;
using ::testing::Values; using ::testing::Values;
using std::unique_ptr;
using cpputils::Data; using cpputils::Data;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::TempFile; using cpputils::TempFile;

View File

@ -14,7 +14,6 @@ using ::testing::WithParamInterface;
using ::testing::Values; using ::testing::Values;
using std::ofstream; using std::ofstream;
using std::unique_ptr;
using std::ios; using std::ios;
using cpputils::Data; using cpputils::Data;
using cpputils::DataFixture; using cpputils::DataFixture;

View File

@ -8,14 +8,13 @@ using blockstore::BlockStore;
using blockstore::parallelaccess::ParallelAccessBlockStore; using blockstore::parallelaccess::ParallelAccessBlockStore;
using blockstore::testfake::FakeBlockStore; using blockstore::testfake::FakeBlockStore;
using std::unique_ptr;
using std::make_unique;
using cpputils::make_unique_ref; using cpputils::make_unique_ref;
using cpputils::unique_ref;
class ParallelAccessBlockStoreTestFixture: public BlockStoreTestFixture { class ParallelAccessBlockStoreTestFixture: public BlockStoreTestFixture {
public: public:
unique_ptr<BlockStore> createBlockStore() override { unique_ref<BlockStore> createBlockStore() override {
return make_unique<ParallelAccessBlockStore>(make_unique_ref<FakeBlockStore>()); return make_unique_ref<ParallelAccessBlockStore>(make_unique_ref<FakeBlockStore>());
} }
}; };

View File

@ -8,14 +8,13 @@
using blockstore::BlockStore; using blockstore::BlockStore;
using blockstore::BlockStoreWithRandomKeys; using blockstore::BlockStoreWithRandomKeys;
using blockstore::testfake::FakeBlockStore; using blockstore::testfake::FakeBlockStore;
using cpputils::unique_ref;
using std::unique_ptr; using cpputils::make_unique_ref;
using std::make_unique;
class FakeBlockStoreTestFixture: public BlockStoreTestFixture { class FakeBlockStoreTestFixture: public BlockStoreTestFixture {
public: public:
unique_ptr<BlockStore> createBlockStore() override { unique_ref<BlockStore> createBlockStore() override {
return make_unique<FakeBlockStore>(); return make_unique_ref<FakeBlockStore>();
} }
}; };
@ -23,8 +22,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(TestFake, BlockStoreTest, FakeBlockStoreTestFixtur
class FakeBlockStoreWithRandomKeysTestFixture: public BlockStoreWithRandomKeysTestFixture { class FakeBlockStoreWithRandomKeysTestFixture: public BlockStoreWithRandomKeysTestFixture {
public: public:
unique_ptr<BlockStoreWithRandomKeys> createBlockStore() override { unique_ref<BlockStoreWithRandomKeys> createBlockStore() override {
return make_unique<FakeBlockStore>(); return make_unique_ref<FakeBlockStore>();
} }
}; };

View File

@ -11,8 +11,6 @@ using ::testing::Eq;
using ::testing::ByRef; using ::testing::ByRef;
using std::string; using std::string;
using std::unique_ptr;
using std::make_unique;
using cpputils::Data; using cpputils::Data;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::unique_ref; using cpputils::unique_ref;
@ -23,11 +21,11 @@ using namespace blockstore;
class BlockStoreWithRandomKeysMock: public BlockStoreWithRandomKeys { class BlockStoreWithRandomKeysMock: public BlockStoreWithRandomKeys {
public: public:
optional<unique_ref<Block>> tryCreate(const Key &key, Data data) { optional<unique_ref<Block>> tryCreate(const Key &key, Data data) {
return cpputils::nullcheck(unique_ptr<Block>(do_create(key, data))); return cpputils::nullcheck(std::unique_ptr<Block>(do_create(key, data)));
} }
MOCK_METHOD2(do_create, Block*(const Key &, const Data &data)); MOCK_METHOD2(do_create, Block*(const Key &, const Data &data));
optional<unique_ref<Block>> load(const Key &key) { optional<unique_ref<Block>> load(const Key &key) {
return cpputils::nullcheck(unique_ptr<Block>(do_load(key))); return cpputils::nullcheck(std::unique_ptr<Block>(do_load(key)));
} }
MOCK_METHOD1(do_load, Block*(const Key &)); MOCK_METHOD1(do_load, Block*(const Key &));
void remove(unique_ref<Block> block) {UNUSED(block);} void remove(unique_ref<Block> block) {UNUSED(block);}

View File

@ -8,7 +8,7 @@
class BlockStoreTestFixture { class BlockStoreTestFixture {
public: public:
virtual std::unique_ptr<blockstore::BlockStore> createBlockStore() = 0; virtual cpputils::unique_ref<blockstore::BlockStore> createBlockStore() = 0;
}; };
template<class ConcreteBlockStoreTestFixture> template<class ConcreteBlockStoreTestFixture>

View File

@ -8,7 +8,7 @@ struct DataRange {
class BlockStoreDataParametrizedTest { class BlockStoreDataParametrizedTest {
public: public:
BlockStoreDataParametrizedTest(std::unique_ptr<blockstore::BlockStore> blockStore_, const DataRange &testData_) BlockStoreDataParametrizedTest(cpputils::unique_ref<blockstore::BlockStore> blockStore_, const DataRange &testData_)
: blockStore(std::move(blockStore_)), : blockStore(std::move(blockStore_)),
testData(testData_), testData(testData_),
foregroundData(cpputils::DataFixture::generate(testData.count, 0)), foregroundData(cpputils::DataFixture::generate(testData.count, 0)),
@ -40,7 +40,7 @@ public:
} }
private: private:
std::unique_ptr<blockstore::BlockStore> blockStore; cpputils::unique_ref<blockstore::BlockStore> blockStore;
DataRange testData; DataRange testData;
cpputils::Data foregroundData; cpputils::Data foregroundData;
cpputils::Data backgroundData; cpputils::Data backgroundData;

View File

@ -5,7 +5,7 @@
class BlockStoreSizeParameterizedTest { class BlockStoreSizeParameterizedTest {
public: public:
BlockStoreSizeParameterizedTest(std::unique_ptr<blockstore::BlockStore> blockStore_, size_t size_): blockStore(std::move(blockStore_)), size(size_) {} BlockStoreSizeParameterizedTest(cpputils::unique_ref<blockstore::BlockStore> blockStore_, size_t size_): blockStore(std::move(blockStore_)), size(size_) {}
void TestCreatedBlockHasCorrectSize() { void TestCreatedBlockHasCorrectSize() {
auto block = CreateBlock(); auto block = CreateBlock();
@ -93,7 +93,7 @@ public:
private: private:
const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972"); const blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
std::unique_ptr<blockstore::BlockStore> blockStore; cpputils::unique_ref<blockstore::BlockStore> blockStore;
size_t size; size_t size;
cpputils::Data ZEROES(size_t size) { cpputils::Data ZEROES(size_t size) {

View File

@ -8,7 +8,7 @@
class BlockStoreWithRandomKeysTestFixture { class BlockStoreWithRandomKeysTestFixture {
public: public:
virtual std::unique_ptr<blockstore::BlockStoreWithRandomKeys> createBlockStore() = 0; virtual cpputils::unique_ref<blockstore::BlockStoreWithRandomKeys> createBlockStore() = 0;
}; };
template<class ConcreteBlockStoreWithRandomKeysTestFixture> template<class ConcreteBlockStoreWithRandomKeysTestFixture>

View File

@ -9,10 +9,10 @@ using ::testing::Test;
using ::testing::WithParamInterface; using ::testing::WithParamInterface;
using ::testing::Values; using ::testing::Values;
using std::make_unique;
using std::unique_ptr;
using cpputils::Data; using cpputils::Data;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using namespace blockstore; using namespace blockstore;
using namespace blockstore::utils; using namespace blockstore::utils;
@ -25,13 +25,13 @@ public:
BlockStoreUtilsTest(): BlockStoreUtilsTest():
ZEROES(SIZE), ZEROES(SIZE),
dataFixture(DataFixture::generate(SIZE)), dataFixture(DataFixture::generate(SIZE)),
blockStore(make_unique<FakeBlockStore>()) { blockStore(make_unique_ref<FakeBlockStore>()) {
ZEROES.FillWithZeroes(); ZEROES.FillWithZeroes();
} }
Data ZEROES; Data ZEROES;
Data dataFixture; Data dataFixture;
unique_ptr<BlockStore> blockStore; unique_ref<BlockStore> blockStore;
}; };
TEST_F(BlockStoreUtilsTest, FillWithZeroes) { TEST_F(BlockStoreUtilsTest, FillWithZeroes) {