2015-04-27 23:09:29 +02:00
|
|
|
#include <google/gtest/gtest.h>
|
2015-07-21 18:19:34 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
2015-04-27 23:09:29 +02:00
|
|
|
#include "../../../../implementations/caching/cache/QueueMap.h"
|
|
|
|
#include "testutils/MinimalKeyType.h"
|
2015-04-28 11:56:07 +02:00
|
|
|
#include "testutils/CopyableMovableValueType.h"
|
2015-04-27 23:09:29 +02:00
|
|
|
|
|
|
|
using namespace blockstore::caching;
|
|
|
|
|
|
|
|
using ::testing::Test;
|
2015-07-21 18:19:34 +02:00
|
|
|
using cpputils::unique_ref;
|
|
|
|
using cpputils::make_unique_ref;
|
2015-04-27 23:09:29 +02:00
|
|
|
|
|
|
|
//Test that QueueMap uses a move constructor for Value if possible
|
|
|
|
class QueueMapTest_MoveConstructor: public Test {
|
|
|
|
public:
|
2015-07-21 18:19:34 +02:00
|
|
|
QueueMapTest_MoveConstructor(): map(make_unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>>()) {
|
2015-04-28 11:56:07 +02:00
|
|
|
CopyableMovableValueType::numCopyConstructorCalled = 0;
|
2015-04-27 23:09:29 +02:00
|
|
|
}
|
2015-07-21 18:19:34 +02:00
|
|
|
unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>> map;
|
2015-04-27 23:09:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
2015-05-08 02:10:56 +02:00
|
|
|
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);
|
2015-04-27 23:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2015-05-08 02:10:56 +02:00
|
|
|
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);
|
2015-04-27 23:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_CopyIntoMap) {
|
2015-04-28 11:56:07 +02:00
|
|
|
CopyableMovableValueType value(2);
|
2015-04-27 23:09:29 +02:00
|
|
|
map->push(MinimalKeyType::create(0), value);
|
2015-04-28 11:56:07 +02:00
|
|
|
CopyableMovableValueType val = map->pop().value();
|
2015-05-08 02:10:56 +02:00
|
|
|
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);
|
2015-04-27 23:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(QueueMapTest_MoveConstructor, PushingAndPoppingPerKey_CopyIntoMap) {
|
2015-04-28 11:56:07 +02:00
|
|
|
CopyableMovableValueType value(2);
|
2015-04-27 23:09:29 +02:00
|
|
|
map->push(MinimalKeyType::create(0), value);
|
2015-04-28 11:56:07 +02:00
|
|
|
CopyableMovableValueType val = map->pop(MinimalKeyType::create(0)).value();
|
2015-05-08 02:10:56 +02:00
|
|
|
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);
|
2015-04-27 23:09:29 +02:00
|
|
|
}
|