summaryrefslogtreecommitdiffstats
path: root/base/move_unittest.cc
blob: 1f4ce84cb6af4f1aac736704b271fea1b6fc4b19 (plain)
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
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/move.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace {

class MoveOnly {
  MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(MoveOnly)

 public:
  MoveOnly() {}

  MoveOnly(MoveOnly&& other) {}
  MoveOnly& operator=(MoveOnly&& other) { return *this; }
};

class Container {
 public:
  Container() = default;
  Container(const Container& other) = default;
  Container& operator=(const Container& other) = default;

  Container(Container&& other) { value_ = other.value_.Pass(); }

  Container& operator=(Container&& other) {
    value_ = other.value_.Pass();
    return *this;
  }

 private:
  MoveOnly value_;
};

Container GetContainerRvalue() {
  Container x;
  return x;
}

TEST(MoveTest, CopyableContainerCanBeMoved) {
  // Container should be move-constructible and move-assignable.
  Container y = GetContainerRvalue();
  y = GetContainerRvalue();
}

}  // namespace