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

Side by Side Diff: base/containers/scoped_ptr_hash_map_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/containers/scoped_ptr_hash_map.h ('k') | base/debug/asan_invalid_access.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/containers/scoped_ptr_hash_map.h" 5 #include "base/containers/scoped_ptr_hash_map.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include <memory>
8
9 #include "base/memory/ptr_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 namespace base { 12 namespace base {
11 namespace { 13 namespace {
12 14
13 namespace namespace_with_ignore_result { 15 namespace namespace_with_ignore_result {
14 16
15 class Value {}; 17 class Value {};
16 18
17 template <typename T> 19 template <typename T>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 51
50 int CountingDeleter::g_deleter_call_count = 0; 52 int CountingDeleter::g_deleter_call_count = 0;
51 53
52 TEST(ScopedPtrHashMapTest, CustomDeleter) { 54 TEST(ScopedPtrHashMapTest, CustomDeleter) {
53 int key = 123; 55 int key = 123;
54 56
55 // Test dtor. 57 // Test dtor.
56 DeleteCounter::ResetCounter(); 58 DeleteCounter::ResetCounter();
57 CountingDeleter::ResetCounter(); 59 CountingDeleter::ResetCounter();
58 { 60 {
59 ScopedPtrHashMap<int, scoped_ptr<DeleteCounter, CountingDeleter>> map; 61 ScopedPtrHashMap<int, std::unique_ptr<DeleteCounter, CountingDeleter>> map;
60 map.set(key, scoped_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter)); 62 map.set(key,
63 std::unique_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter));
61 } 64 }
62 EXPECT_EQ(1, DeleteCounter::delete_count()); 65 EXPECT_EQ(1, DeleteCounter::delete_count());
63 EXPECT_EQ(1, CountingDeleter::count()); 66 EXPECT_EQ(1, CountingDeleter::count());
64 67
65 // Test set and erase. 68 // Test set and erase.
66 DeleteCounter::ResetCounter(); 69 DeleteCounter::ResetCounter();
67 CountingDeleter::ResetCounter(); 70 CountingDeleter::ResetCounter();
68 { 71 {
69 ScopedPtrHashMap<int, scoped_ptr<DeleteCounter, CountingDeleter>> map; 72 ScopedPtrHashMap<int, std::unique_ptr<DeleteCounter, CountingDeleter>> map;
70 map.erase(map.set( 73 map.erase(map.set(key, std::unique_ptr<DeleteCounter, CountingDeleter>(
71 key, scoped_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter))); 74 new DeleteCounter)));
72 EXPECT_EQ(1, DeleteCounter::delete_count()); 75 EXPECT_EQ(1, DeleteCounter::delete_count());
73 EXPECT_EQ(1, CountingDeleter::count()); 76 EXPECT_EQ(1, CountingDeleter::count());
74 } 77 }
75 EXPECT_EQ(1, DeleteCounter::delete_count()); 78 EXPECT_EQ(1, DeleteCounter::delete_count());
76 EXPECT_EQ(1, CountingDeleter::count()); 79 EXPECT_EQ(1, CountingDeleter::count());
77 80
78 // Test set more than once. 81 // Test set more than once.
79 DeleteCounter::ResetCounter(); 82 DeleteCounter::ResetCounter();
80 CountingDeleter::ResetCounter(); 83 CountingDeleter::ResetCounter();
81 { 84 {
82 ScopedPtrHashMap<int, scoped_ptr<DeleteCounter, CountingDeleter>> map; 85 ScopedPtrHashMap<int, std::unique_ptr<DeleteCounter, CountingDeleter>> map;
83 map.set(key, scoped_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter)); 86 map.set(key,
84 map.set(key, scoped_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter)); 87 std::unique_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter));
85 map.set(key, scoped_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter)); 88 map.set(key,
89 std::unique_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter));
90 map.set(key,
91 std::unique_ptr<DeleteCounter, CountingDeleter>(new DeleteCounter));
86 EXPECT_EQ(2, DeleteCounter::delete_count()); 92 EXPECT_EQ(2, DeleteCounter::delete_count());
87 EXPECT_EQ(2, CountingDeleter::count()); 93 EXPECT_EQ(2, CountingDeleter::count());
88 } 94 }
89 EXPECT_EQ(3, DeleteCounter::delete_count()); 95 EXPECT_EQ(3, DeleteCounter::delete_count());
90 EXPECT_EQ(3, CountingDeleter::count()); 96 EXPECT_EQ(3, CountingDeleter::count());
91 } 97 }
92 98
93 // Test that using a value type from a namespace containing an ignore_result 99 // Test that using a value type from a namespace containing an ignore_result
94 // function compiles correctly. 100 // function compiles correctly.
95 TEST(ScopedPtrHashMapTest, IgnoreResultCompile) { 101 TEST(ScopedPtrHashMapTest, IgnoreResultCompile) {
96 ScopedPtrHashMap<int, scoped_ptr<namespace_with_ignore_result::Value>> 102 ScopedPtrHashMap<int, std::unique_ptr<namespace_with_ignore_result::Value>>
97 scoped_map; 103 scoped_map;
98 scoped_map.add(1, make_scoped_ptr(new namespace_with_ignore_result::Value)); 104 scoped_map.add(1, WrapUnique(new namespace_with_ignore_result::Value));
99 } 105 }
100 106
101 } // namespace 107 } // namespace
102 } // namespace base 108 } // namespace base
OLDNEW
« no previous file with comments | « base/containers/scoped_ptr_hash_map.h ('k') | base/debug/asan_invalid_access.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698