libcryfs/test/blockstore/implementations/caching/cache/QueueMapTest_MoveConstructor.cpp

51 lines
2.1 KiB
C++
Raw Normal View History

#include <google/gtest/gtest.h>
#include <messmer/cpp-utils/pointer/unique_ref.h>
#include "../../../../implementations/caching/cache/QueueMap.h"
#include "testutils/MinimalKeyType.h"
2015-04-28 11:56:07 +02:00
#include "testutils/CopyableMovableValueType.h"
using namespace blockstore::caching;
using ::testing::Test;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
//Test that QueueMap uses a move constructor for Value if possible
class QueueMapTest_MoveConstructor: public Test {
public:
QueueMapTest_MoveConstructor(): map(make_unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>>()) {
2015-04-28 11:56:07 +02:00
CopyableMovableValueType::numCopyConstructorCalled = 0;
}
unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>> map;
};
TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_MoveIntoMap) {
2015-04-28 11:56:07 +02:00
map->push(MinimalKeyType::create(0), CopyableMovableValueType(2));
CopyableMovableValueType val = map->pop().value();
val.value(); //Access it to avoid the compiler optimizing the assignment away
2015-04-28 11:56:07 +02:00
EXPECT_EQ(0, CopyableMovableValueType::numCopyConstructorCalled);
}
TEST_F(QueueMapTest_MoveConstructor, PushingAndPoppingPerKey_MoveIntoMap) {
2015-04-28 11:56:07 +02:00
map->push(MinimalKeyType::create(0), CopyableMovableValueType(2));
CopyableMovableValueType val = map->pop(MinimalKeyType::create(0)).value();
val.value(); //Access it to avoid the compiler optimizing the assignment away
2015-04-28 11:56:07 +02:00
EXPECT_EQ(0, CopyableMovableValueType::numCopyConstructorCalled);
}
TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_CopyIntoMap) {
2015-04-28 11:56:07 +02:00
CopyableMovableValueType value(2);
map->push(MinimalKeyType::create(0), value);
2015-04-28 11:56:07 +02:00
CopyableMovableValueType val = map->pop().value();
val.value(); //Access it to avoid the compiler optimizing the assignment away
2015-04-28 11:56:07 +02:00
EXPECT_EQ(1, CopyableMovableValueType::numCopyConstructorCalled);
}
TEST_F(QueueMapTest_MoveConstructor, PushingAndPoppingPerKey_CopyIntoMap) {
2015-04-28 11:56:07 +02:00
CopyableMovableValueType value(2);
map->push(MinimalKeyType::create(0), value);
2015-04-28 11:56:07 +02:00
CopyableMovableValueType val = map->pop(MinimalKeyType::create(0)).value();
val.value(); //Access it to avoid the compiler optimizing the assignment away
2015-04-28 11:56:07 +02:00
EXPECT_EQ(1, CopyableMovableValueType::numCopyConstructorCalled);
}