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 = Histogram::FactoryGet( |
| 329 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8, Histogram::kNoFlags); |
| 330 EXPECT_EQ(1, histogram->declared_min()); |
| 331 EXPECT_EQ(HistogramBase::kSampleType_MAX - 1, histogram->declared_max()); |
| 332 |
| 333 Histogram* linear_histogram = LinearHistogram::FactoryGet( |
| 334 "BadRangesLinear", 0, HistogramBase::kSampleType_MAX, 8, |
| 335 Histogram::kNoFlags); |
| 336 EXPECT_EQ(1, linear_histogram->declared_min()); |
| 337 EXPECT_EQ(HistogramBase::kSampleType_MAX - 1, |
| 338 linear_histogram->declared_max()); |
| 339 |
| 340 vector<int> custom_ranges; |
| 341 custom_ranges.push_back(0); |
| 342 custom_ranges.push_back(5); |
| 343 Histogram* custom_histogram1 = CustomHistogram::FactoryGet( |
| 344 "BadRangesCustom", custom_ranges, Histogram::kNoFlags); |
| 345 const BucketRanges* ranges = custom_histogram1->bucket_ranges(); |
| 346 ASSERT_EQ(3u, ranges->size()); |
| 347 EXPECT_EQ(0, ranges->range(0)); |
| 348 EXPECT_EQ(5, ranges->range(1)); |
| 349 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges->range(2)); |
| 350 |
| 351 // CustomHistogram does not accepts kSampleType_MAX as range. |
| 352 custom_ranges.push_back(HistogramBase::kSampleType_MAX); |
| 353 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom2", custom_ranges, |
| 354 Histogram::kNoFlags), |
| 355 ""); |
| 356 |
| 357 // CustomHistogram needs at least 1 valid range. |
| 358 custom_ranges.clear(); |
| 359 custom_ranges.push_back(0); |
| 360 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
| 361 Histogram::kNoFlags), |
| 362 ""); |
| 363 } |
| 364 #endif |
| 365 |
322 } // namespace base | 366 } // namespace base |
OLD | NEW |