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 <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
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 "base/test/gtest_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 namespace { | 19 namespace { |
19 | 20 |
20 TEST(SampleVectorTest, AccumulateTest) { | 21 TEST(SampleVectorTest, AccumulateTest) { |
21 // Custom buckets: [1, 5) [5, 10) | 22 // Custom buckets: [1, 5) [5, 10) |
22 BucketRanges ranges(3); | 23 BucketRanges ranges(3); |
23 ranges.set_range(0, 1); | 24 ranges.set_range(0, 1); |
24 ranges.set_range(1, 5); | 25 ranges.set_range(1, 5); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 EXPECT_EQ(i + 1, max); | 254 EXPECT_EQ(i + 1, max); |
254 EXPECT_EQ(i, count); | 255 EXPECT_EQ(i, count); |
255 | 256 |
256 size_t index; | 257 size_t index; |
257 EXPECT_TRUE(it2->GetBucketIndex(&index)); | 258 EXPECT_TRUE(it2->GetBucketIndex(&index)); |
258 EXPECT_EQ(static_cast<size_t>(i), index); | 259 EXPECT_EQ(static_cast<size_t>(i), index); |
259 } | 260 } |
260 EXPECT_EQ(4, i); | 261 EXPECT_EQ(4, i); |
261 } | 262 } |
262 | 263 |
263 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | |
264 | |
265 TEST(SampleVectorIteratorDeathTest, IterateDoneTest) { | 264 TEST(SampleVectorIteratorDeathTest, IterateDoneTest) { |
266 BucketRanges ranges(5); | 265 BucketRanges ranges(5); |
267 ranges.set_range(0, 0); | 266 ranges.set_range(0, 0); |
268 ranges.set_range(1, 1); | 267 ranges.set_range(1, 1); |
269 ranges.set_range(2, 2); | 268 ranges.set_range(2, 2); |
270 ranges.set_range(3, 3); | 269 ranges.set_range(3, 3); |
271 ranges.set_range(4, INT_MAX); | 270 ranges.set_range(4, INT_MAX); |
272 SampleVector samples(1, &ranges); | 271 SampleVector samples(1, &ranges); |
273 | 272 |
274 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); | 273 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
275 | 274 |
276 EXPECT_TRUE(it->Done()); | 275 EXPECT_TRUE(it->Done()); |
277 | 276 |
278 HistogramBase::Sample min; | 277 HistogramBase::Sample min; |
279 HistogramBase::Sample max; | 278 HistogramBase::Sample max; |
280 HistogramBase::Count count; | 279 HistogramBase::Count count; |
281 EXPECT_DEATH(it->Get(&min, &max, &count), ""); | 280 EXPECT_DCHECK_DEATH(it->Get(&min, &max, &count), ""); |
282 | 281 |
283 EXPECT_DEATH(it->Next(), ""); | 282 EXPECT_DCHECK_DEATH(it->Next(), ""); |
284 | 283 |
285 samples.Accumulate(2, 100); | 284 samples.Accumulate(2, 100); |
286 it = samples.Iterator(); | 285 it = samples.Iterator(); |
287 EXPECT_FALSE(it->Done()); | 286 EXPECT_FALSE(it->Done()); |
288 } | 287 } |
289 | 288 |
290 #endif | |
291 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | |
292 | |
293 } // namespace | 289 } // namespace |
294 } // namespace base | 290 } // namespace base |
OLD | NEW |