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

Side by Side Diff: base/win/scoped_comptr_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/win/registry.h ('k') | base/win/win_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/scoped_comptr.h" 5 #include "base/win/scoped_comptr.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include <memory>
10
10 #include "base/win/scoped_com_initializer.h" 11 #include "base/win/scoped_com_initializer.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace base { 14 namespace base {
14 namespace win { 15 namespace win {
15 16
16 namespace { 17 namespace {
17 18
18 struct Dummy { 19 struct Dummy {
19 Dummy() : adds(0), releases(0) { } 20 Dummy() : adds(0), releases(0) { }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 unk.Release(); 78 unk.Release();
78 EXPECT_TRUE(unk.get() == NULL); 79 EXPECT_TRUE(unk.get() == NULL);
79 EXPECT_TRUE(unk.IsSameObject(copy1.get())); // both are NULL 80 EXPECT_TRUE(unk.IsSameObject(copy1.get())); // both are NULL
80 } 81 }
81 82
82 TEST(ScopedComPtrTest, ScopedComPtrVector) { 83 TEST(ScopedComPtrTest, ScopedComPtrVector) {
83 // Verify we don't get error C2558. 84 // Verify we don't get error C2558.
84 typedef ScopedComPtr<Dummy, &dummy_iid> Ptr; 85 typedef ScopedComPtr<Dummy, &dummy_iid> Ptr;
85 std::vector<Ptr> bleh; 86 std::vector<Ptr> bleh;
86 87
87 scoped_ptr<Dummy> p(new Dummy); 88 std::unique_ptr<Dummy> p(new Dummy);
88 { 89 {
89 Ptr p2(p.get()); 90 Ptr p2(p.get());
90 EXPECT_EQ(p->adds, 1); 91 EXPECT_EQ(p->adds, 1);
91 EXPECT_EQ(p->releases, 0); 92 EXPECT_EQ(p->releases, 0);
92 Ptr p3 = p2; 93 Ptr p3 = p2;
93 EXPECT_EQ(p->adds, 2); 94 EXPECT_EQ(p->adds, 2);
94 EXPECT_EQ(p->releases, 0); 95 EXPECT_EQ(p->releases, 0);
95 p3 = p2; 96 p3 = p2;
96 EXPECT_EQ(p->adds, 3); 97 EXPECT_EQ(p->adds, 3);
97 EXPECT_EQ(p->releases, 1); 98 EXPECT_EQ(p->releases, 1);
98 // To avoid hitting a reallocation. 99 // To avoid hitting a reallocation.
99 bleh.reserve(1); 100 bleh.reserve(1);
100 bleh.push_back(p2); 101 bleh.push_back(p2);
101 EXPECT_EQ(p->adds, 4); 102 EXPECT_EQ(p->adds, 4);
102 EXPECT_EQ(p->releases, 1); 103 EXPECT_EQ(p->releases, 1);
103 EXPECT_EQ(bleh[0].get(), p.get()); 104 EXPECT_EQ(bleh[0].get(), p.get());
104 bleh.pop_back(); 105 bleh.pop_back();
105 EXPECT_EQ(p->adds, 4); 106 EXPECT_EQ(p->adds, 4);
106 EXPECT_EQ(p->releases, 2); 107 EXPECT_EQ(p->releases, 2);
107 } 108 }
108 EXPECT_EQ(p->adds, 4); 109 EXPECT_EQ(p->adds, 4);
109 EXPECT_EQ(p->releases, 4); 110 EXPECT_EQ(p->releases, 4);
110 } 111 }
111 112
112 } // namespace win 113 } // namespace win
113 } // namespace base 114 } // namespace base
OLDNEW
« no previous file with comments | « base/win/registry.h ('k') | base/win/win_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698