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

Side by Side Diff: base/metrics/persistent_sample_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/metrics/persistent_sample_map.cc ('k') | base/metrics/sample_map.h » ('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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/metrics/persistent_sample_map.h" 5 #include "base/metrics/persistent_sample_map.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include <memory>
8
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace base { 11 namespace base {
11 namespace { 12 namespace {
12 13
13 TEST(PersistentSampleMapTest, AccumulateTest) { 14 TEST(PersistentSampleMapTest, AccumulateTest) {
14 LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB 15 LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB
15 16
16 HistogramSamples::Metadata* meta = 17 HistogramSamples::Metadata* meta =
17 allocator.GetAsObject<HistogramSamples::Metadata>( 18 allocator.GetAsObject<HistogramSamples::Metadata>(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 130
130 HistogramSamples::Metadata* meta = 131 HistogramSamples::Metadata* meta =
131 allocator.GetAsObject<HistogramSamples::Metadata>( 132 allocator.GetAsObject<HistogramSamples::Metadata>(
132 allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); 133 allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0);
133 PersistentSampleMap samples(1, &allocator, meta); 134 PersistentSampleMap samples(1, &allocator, meta);
134 samples.Accumulate(1, 100); 135 samples.Accumulate(1, 100);
135 samples.Accumulate(2, 200); 136 samples.Accumulate(2, 200);
136 samples.Accumulate(4, -300); 137 samples.Accumulate(4, -300);
137 samples.Accumulate(5, 0); 138 samples.Accumulate(5, 0);
138 139
139 scoped_ptr<SampleCountIterator> it = samples.Iterator(); 140 std::unique_ptr<SampleCountIterator> it = samples.Iterator();
140 141
141 HistogramBase::Sample min; 142 HistogramBase::Sample min;
142 HistogramBase::Sample max; 143 HistogramBase::Sample max;
143 HistogramBase::Count count; 144 HistogramBase::Count count;
144 145
145 it->Get(&min, &max, &count); 146 it->Get(&min, &max, &count);
146 EXPECT_EQ(1, min); 147 EXPECT_EQ(1, min);
147 EXPECT_EQ(2, max); 148 EXPECT_EQ(2, max);
148 EXPECT_EQ(100, count); 149 EXPECT_EQ(100, count);
149 EXPECT_FALSE(it->GetBucketIndex(NULL)); 150 EXPECT_FALSE(it->GetBucketIndex(NULL));
(...skipping 30 matching lines...) Expand all
180 HistogramSamples::Metadata* meta2 = 181 HistogramSamples::Metadata* meta2 =
181 allocator.GetAsObject<HistogramSamples::Metadata>( 182 allocator.GetAsObject<HistogramSamples::Metadata>(
182 allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); 183 allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0);
183 PersistentSampleMap samples2(2, &allocator, meta2); 184 PersistentSampleMap samples2(2, &allocator, meta2);
184 samples2.Accumulate(5, 1); 185 samples2.Accumulate(5, 1);
185 samples2.Accumulate(20, 4); 186 samples2.Accumulate(20, 4);
186 samples2.Accumulate(25, 5); 187 samples2.Accumulate(25, 5);
187 188
188 samples.Subtract(samples2); 189 samples.Subtract(samples2);
189 190
190 scoped_ptr<SampleCountIterator> it = samples.Iterator(); 191 std::unique_ptr<SampleCountIterator> it = samples.Iterator();
191 EXPECT_FALSE(it->Done()); 192 EXPECT_FALSE(it->Done());
192 193
193 HistogramBase::Sample min; 194 HistogramBase::Sample min;
194 HistogramBase::Sample max; 195 HistogramBase::Sample max;
195 HistogramBase::Count count; 196 HistogramBase::Count count;
196 197
197 it->Get(&min, &max, &count); 198 it->Get(&min, &max, &count);
198 EXPECT_EQ(10, min); 199 EXPECT_EQ(10, min);
199 EXPECT_EQ(11, max); 200 EXPECT_EQ(11, max);
200 EXPECT_EQ(2, count); 201 EXPECT_EQ(2, count);
(...skipping 13 matching lines...) Expand all
214 // Only run this test on builds that support catching a DCHECK crash. 215 // Only run this test on builds that support catching a DCHECK crash.
215 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST 216 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST
216 TEST(PersistentSampleMapIteratorDeathTest, IterateDoneTest) { 217 TEST(PersistentSampleMapIteratorDeathTest, IterateDoneTest) {
217 LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB 218 LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB
218 219
219 HistogramSamples::Metadata* meta = 220 HistogramSamples::Metadata* meta =
220 allocator.GetAsObject<HistogramSamples::Metadata>( 221 allocator.GetAsObject<HistogramSamples::Metadata>(
221 allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); 222 allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0);
222 PersistentSampleMap samples(1, &allocator, meta); 223 PersistentSampleMap samples(1, &allocator, meta);
223 224
224 scoped_ptr<SampleCountIterator> it = samples.Iterator(); 225 std::unique_ptr<SampleCountIterator> it = samples.Iterator();
225 226
226 EXPECT_TRUE(it->Done()); 227 EXPECT_TRUE(it->Done());
227 228
228 HistogramBase::Sample min; 229 HistogramBase::Sample min;
229 HistogramBase::Sample max; 230 HistogramBase::Sample max;
230 HistogramBase::Count count; 231 HistogramBase::Count count;
231 EXPECT_DEATH(it->Get(&min, &max, &count), ""); 232 EXPECT_DEATH(it->Get(&min, &max, &count), "");
232 233
233 EXPECT_DEATH(it->Next(), ""); 234 EXPECT_DEATH(it->Next(), "");
234 235
235 samples.Accumulate(1, 100); 236 samples.Accumulate(1, 100);
236 it = samples.Iterator(); 237 it = samples.Iterator();
237 EXPECT_FALSE(it->Done()); 238 EXPECT_FALSE(it->Done());
238 } 239 }
239 #endif 240 #endif
240 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST 241 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST
241 242
242 } // namespace 243 } // namespace
243 } // namespace base 244 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_sample_map.cc ('k') | base/metrics/sample_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698