Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: third_party/base/nonstd_unique_ptr_unittest.cpp

Issue 1358163002: Add nonstd::unique_ptr move assigment operator. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: reset(that.release()) and same for []s. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« pdfium.gyp ('K') | « third_party/base/nonstd_unique_ptr.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <sstream>
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "macros.h"
9 #include "nonstd_unique_ptr.h"
10
11 using nonstd::unique_ptr;
12
13 namespace {
14
15 // Used to test depth subtyping.
16 class CtorDtorLoggerParent {
17 public:
18 virtual ~CtorDtorLoggerParent() {}
19
20 virtual void SetPtr(int* ptr) = 0;
21
22 virtual int SomeMeth(int x) const = 0;
23 };
24
25 class CtorDtorLogger : public CtorDtorLoggerParent {
26 public:
27 CtorDtorLogger() : ptr_(nullptr) {}
28 explicit CtorDtorLogger(int* ptr) { SetPtr(ptr); }
29 ~CtorDtorLogger() override { --*ptr_; }
30
31 void SetPtr(int* ptr) override {
32 ptr_ = ptr;
33 ++*ptr_;
34 }
35
36 int SomeMeth(int x) const override { return x; }
37
38 private:
39 int* ptr_;
40
41 // Disallow evil constructors.
42 CtorDtorLogger(const CtorDtorLogger&) = delete;
43 void operator=(const CtorDtorLogger&) = delete;
44 };
45
46 struct CountingDeleter {
47 explicit CountingDeleter(int* count) : count_(count) {}
48 inline void operator()(double* ptr) const { (*count_)++; }
49 int* count_;
50 };
51
52 // Do not delete this function! It's existence is to test that you can
53 // return a temporarily constructed version of the scoper.
54 unique_ptr<CtorDtorLogger> TestReturnOfType(int* constructed) {
55 return unique_ptr<CtorDtorLogger>(new CtorDtorLogger(constructed));
56 }
57
58 } // namespace
59
60 TEST(UniquePtrTest, MoveTest) {
61 int constructed = 0;
62 int constructed4 = 0;
63 {
64 unique_ptr<CtorDtorLogger> ptr1(new CtorDtorLogger(&constructed));
65 EXPECT_EQ(1, constructed);
66 EXPECT_TRUE(ptr1);
67
68 unique_ptr<CtorDtorLogger> ptr2(nonstd::move(ptr1));
69 EXPECT_EQ(1, constructed);
70 EXPECT_FALSE(ptr1);
71 EXPECT_TRUE(ptr2);
72
73 unique_ptr<CtorDtorLogger> ptr3;
74 ptr3 = nonstd::move(ptr2);
75 EXPECT_EQ(1, constructed);
76 EXPECT_FALSE(ptr2);
77 EXPECT_TRUE(ptr3);
78
79 unique_ptr<CtorDtorLogger> ptr4(new CtorDtorLogger(&constructed4));
80 EXPECT_EQ(1, constructed4);
81 ptr4 = nonstd::move(ptr3);
82 EXPECT_EQ(0, constructed4);
83 EXPECT_FALSE(ptr3);
84 EXPECT_TRUE(ptr4);
85 }
86 EXPECT_EQ(0, constructed);
87 }
OLDNEW
« pdfium.gyp ('K') | « third_party/base/nonstd_unique_ptr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698