| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sample_vector.h" | 5 #include "base/metrics/sample_vector.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/metrics/bucket_ranges.h" | 13 #include "base/metrics/bucket_ranges.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 TEST(SampleVectorTest, AccumulateTest) { | 20 TEST(SampleVectorTest, AccumulateTest) { |
| 21 // Custom buckets: [1, 5) [5, 10) | 21 // Custom buckets: [1, 5) [5, 10) |
| 22 BucketRanges ranges(3); | 22 BucketRanges ranges(3); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 it.Next(); | 238 it.Next(); |
| 239 EXPECT_TRUE(it.Done()); | 239 EXPECT_TRUE(it.Done()); |
| 240 | 240 |
| 241 // Create iterator from SampleVector. | 241 // Create iterator from SampleVector. |
| 242 SampleVector samples(1, &ranges); | 242 SampleVector samples(1, &ranges); |
| 243 samples.Accumulate(0, 0); | 243 samples.Accumulate(0, 0); |
| 244 samples.Accumulate(1, 1); | 244 samples.Accumulate(1, 1); |
| 245 samples.Accumulate(2, 2); | 245 samples.Accumulate(2, 2); |
| 246 samples.Accumulate(3, 3); | 246 samples.Accumulate(3, 3); |
| 247 scoped_ptr<SampleCountIterator> it2 = samples.Iterator(); | 247 std::unique_ptr<SampleCountIterator> it2 = samples.Iterator(); |
| 248 | 248 |
| 249 int i; | 249 int i; |
| 250 for (i = 1; !it2->Done(); i++, it2->Next()) { | 250 for (i = 1; !it2->Done(); i++, it2->Next()) { |
| 251 it2->Get(&min, &max, &count); | 251 it2->Get(&min, &max, &count); |
| 252 EXPECT_EQ(i, min); | 252 EXPECT_EQ(i, min); |
| 253 EXPECT_EQ(i + 1, max); | 253 EXPECT_EQ(i + 1, max); |
| 254 EXPECT_EQ(i, count); | 254 EXPECT_EQ(i, count); |
| 255 | 255 |
| 256 size_t index; | 256 size_t index; |
| 257 EXPECT_TRUE(it2->GetBucketIndex(&index)); | 257 EXPECT_TRUE(it2->GetBucketIndex(&index)); |
| 258 EXPECT_EQ(static_cast<size_t>(i), index); | 258 EXPECT_EQ(static_cast<size_t>(i), index); |
| 259 } | 259 } |
| 260 EXPECT_EQ(4, i); | 260 EXPECT_EQ(4, i); |
| 261 } | 261 } |
| 262 | 262 |
| 263 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 263 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
| 264 | 264 |
| 265 TEST(SampleVectorIteratorDeathTest, IterateDoneTest) { | 265 TEST(SampleVectorIteratorDeathTest, IterateDoneTest) { |
| 266 BucketRanges ranges(5); | 266 BucketRanges ranges(5); |
| 267 ranges.set_range(0, 0); | 267 ranges.set_range(0, 0); |
| 268 ranges.set_range(1, 1); | 268 ranges.set_range(1, 1); |
| 269 ranges.set_range(2, 2); | 269 ranges.set_range(2, 2); |
| 270 ranges.set_range(3, 3); | 270 ranges.set_range(3, 3); |
| 271 ranges.set_range(4, INT_MAX); | 271 ranges.set_range(4, INT_MAX); |
| 272 SampleVector samples(1, &ranges); | 272 SampleVector samples(1, &ranges); |
| 273 | 273 |
| 274 scoped_ptr<SampleCountIterator> it = samples.Iterator(); | 274 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 275 | 275 |
| 276 EXPECT_TRUE(it->Done()); | 276 EXPECT_TRUE(it->Done()); |
| 277 | 277 |
| 278 HistogramBase::Sample min; | 278 HistogramBase::Sample min; |
| 279 HistogramBase::Sample max; | 279 HistogramBase::Sample max; |
| 280 HistogramBase::Count count; | 280 HistogramBase::Count count; |
| 281 EXPECT_DEATH(it->Get(&min, &max, &count), ""); | 281 EXPECT_DEATH(it->Get(&min, &max, &count), ""); |
| 282 | 282 |
| 283 EXPECT_DEATH(it->Next(), ""); | 283 EXPECT_DEATH(it->Next(), ""); |
| 284 | 284 |
| 285 samples.Accumulate(2, 100); | 285 samples.Accumulate(2, 100); |
| 286 it = samples.Iterator(); | 286 it = samples.Iterator(); |
| 287 EXPECT_FALSE(it->Done()); | 287 EXPECT_FALSE(it->Done()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 #endif | 290 #endif |
| 291 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 291 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
| 292 | 292 |
| 293 } // namespace | 293 } // namespace |
| 294 } // namespace base | 294 } // namespace base |
| OLD | NEW |