File: QueueMapTest_MoveConstructor.cpp

package info (click to toggle)
cryfs 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,412 kB
  • sloc: cpp: 150,187; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (50 lines) | stat: -rw-r--r-- 2,213 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <gtest/gtest.h>
#include <cpp-utils/pointer/unique_ref.h>
#include "blockstore/implementations/caching/cache/QueueMap.h"
#include "testutils/MinimalKeyType.h"
#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>>()) {
    CopyableMovableValueType::numCopyConstructorCalled = 0;
  }
  unique_ref<QueueMap<MinimalKeyType, CopyableMovableValueType>> map;
};

TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_MoveIntoMap) {
  map->push(MinimalKeyType::create(0), CopyableMovableValueType(2));
  const CopyableMovableValueType val = map->pop().value();
  val.value(); //Access it to avoid the compiler optimizing the assignment away
  EXPECT_EQ(0, CopyableMovableValueType::numCopyConstructorCalled);
}

TEST_F(QueueMapTest_MoveConstructor, PushingAndPoppingPerKey_MoveIntoMap) {
  map->push(MinimalKeyType::create(0), CopyableMovableValueType(2));
  const CopyableMovableValueType val = map->pop(MinimalKeyType::create(0)).value();
  val.value(); //Access it to avoid the compiler optimizing the assignment away
  EXPECT_EQ(0, CopyableMovableValueType::numCopyConstructorCalled);
}

TEST_F(QueueMapTest_MoveConstructor, PushingAndPopping_CopyIntoMap) {
  const CopyableMovableValueType value(2);
  map->push(MinimalKeyType::create(0), value);
  const CopyableMovableValueType val = map->pop().value();
  val.value(); //Access it to avoid the compiler optimizing the assignment away
  EXPECT_EQ(1, CopyableMovableValueType::numCopyConstructorCalled);
}

TEST_F(QueueMapTest_MoveConstructor, PushingAndPoppingPerKey_CopyIntoMap) {
  const CopyableMovableValueType value(2);
  map->push(MinimalKeyType::create(0), value);
  const CopyableMovableValueType val = map->pop(MinimalKeyType::create(0)).value();
  val.value(); //Access it to avoid the compiler optimizing the assignment away
  EXPECT_EQ(1, CopyableMovableValueType::numCopyConstructorCalled);
}