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 // Test of Histogram class | 5 // Test of Histogram class |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 // Show that two simple changes don't offset each other | 312 // Show that two simple changes don't offset each other |
313 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1); | 313 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1); |
314 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, | 314 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, |
315 histogram->FindCorruption(snapshot)); | 315 histogram->FindCorruption(snapshot)); |
316 | 316 |
317 // Repair histogram so that destructor won't DCHECK(). | 317 // Repair histogram so that destructor won't DCHECK(). |
318 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1); | 318 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1); |
319 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1); | 319 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1); |
320 } | 320 } |
321 | 321 |
322 #if GTEST_HAS_DEATH_TEST | |
323 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a | |
324 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX - | |
325 // 1). But we accept ranges exceeding those limits, and silently clamped to | |
326 // those limits. This is for backwards compatibility. | |
327 TEST(HistogramDeathTest, BadRangesTest) { | |
328 Histogram* histogram = | |
329 Histogram::FactoryGet("BadRanges", 0, HistogramBase::kSampleType_MAX, 8, | |
330 Histogram::kNoFlags); | |
jar (doing other things)
2012/08/03 21:53:42
nit: consider wrapping on only two lines.
kaiwang
2012/08/03 22:15:53
Done.
| |
331 EXPECT_EQ(1, histogram->declared_min()); | |
332 EXPECT_EQ(HistogramBase::kSampleType_MAX - 1, histogram->declared_max()); | |
333 | |
334 Histogram* linear_histogram = | |
335 LinearHistogram::FactoryGet("BadRangesLinear", 0, | |
336 HistogramBase::kSampleType_MAX, 8, | |
337 Histogram::kNoFlags); | |
338 EXPECT_EQ(1, linear_histogram->declared_min()); | |
339 EXPECT_EQ(HistogramBase::kSampleType_MAX - 1, | |
340 linear_histogram->declared_max()); | |
341 | |
342 vector<int> custom_ranges; | |
343 custom_ranges.push_back(0); | |
344 custom_ranges.push_back(5); | |
345 Histogram* custom_histogram1 = | |
346 CustomHistogram::FactoryGet("BadRangesCustom", custom_ranges, | |
347 Histogram::kNoFlags); | |
348 const BucketRanges* ranges = custom_histogram1->bucket_ranges(); | |
349 ASSERT_EQ(3u, ranges->size()); | |
350 EXPECT_EQ(0, ranges->range(0)); | |
351 EXPECT_EQ(5, ranges->range(1)); | |
352 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges->range(2)); | |
353 | |
354 // CustomHistogram does not accepts kSampleType_MAX as range. | |
355 custom_ranges.push_back(HistogramBase::kSampleType_MAX); | |
356 EXPECT_DEATH( | |
357 CustomHistogram::FactoryGet("BadRangesCustom2", custom_ranges, | |
358 Histogram::kNoFlags), | |
359 ""); | |
360 | |
361 // CustomHistogram needs at least 1 valid range. | |
362 custom_ranges.clear(); | |
363 custom_ranges.push_back(0); | |
364 EXPECT_DEATH( | |
365 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | |
366 Histogram::kNoFlags), | |
367 ""); | |
jar (doing other things)
2012/08/03 21:53:42
nit: Suggest:
EXPECT_DEATH(CustomHistogram::Facto
kaiwang
2012/08/03 22:15:53
Done.
| |
368 } | |
369 #endif | |
370 | |
322 } // namespace base | 371 } // namespace base |
OLD | NEW |