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 <climits> | 7 #include <climits> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 int range; | 436 int range; |
437 EXPECT_TRUE(iter.ReadInt(&range)); | 437 EXPECT_TRUE(iter.ReadInt(&range)); |
438 EXPECT_EQ(10, range); | 438 EXPECT_EQ(10, range); |
439 EXPECT_TRUE(iter.ReadInt(&range)); | 439 EXPECT_TRUE(iter.ReadInt(&range)); |
440 EXPECT_EQ(100, range); | 440 EXPECT_EQ(100, range); |
441 | 441 |
442 // No more data in the pickle. | 442 // No more data in the pickle. |
443 EXPECT_FALSE(iter.SkipBytes(1)); | 443 EXPECT_FALSE(iter.SkipBytes(1)); |
444 } | 444 } |
445 | 445 |
| 446 TEST_F(HistogramTest, BadConstruction) { |
| 447 HistogramBase* histogram = Histogram::FactoryGet( |
| 448 "BadConstruction", 0, 100, 8, HistogramBase::kNoFlags); |
| 449 EXPECT_TRUE(histogram->HasConstructionArguments(1, 100, 8)); |
| 450 |
| 451 // Try to get the same histogram name with different arguments. |
| 452 HistogramBase* bad_histogram = Histogram::FactoryGet( |
| 453 "BadConstruction", 0, 100, 7, HistogramBase::kNoFlags); |
| 454 EXPECT_EQ(NULL, bad_histogram); |
| 455 bad_histogram = Histogram::FactoryGet( |
| 456 "BadConstruction", 0, 99, 8, HistogramBase::kNoFlags); |
| 457 EXPECT_EQ(NULL, bad_histogram); |
| 458 |
| 459 HistogramBase* linear_histogram = LinearHistogram::FactoryGet( |
| 460 "BadConstructionLinear", 0, 100, 8, HistogramBase::kNoFlags); |
| 461 EXPECT_TRUE(linear_histogram->HasConstructionArguments(1, 100, 8)); |
| 462 |
| 463 // Try to get the same histogram name with different arguments. |
| 464 bad_histogram = LinearHistogram::FactoryGet( |
| 465 "BadConstructionLinear", 0, 100, 7, HistogramBase::kNoFlags); |
| 466 EXPECT_EQ(NULL, bad_histogram); |
| 467 bad_histogram = LinearHistogram::FactoryGet( |
| 468 "BadConstructionLinear", 10, 100, 8, HistogramBase::kNoFlags); |
| 469 EXPECT_EQ(NULL, bad_histogram); |
| 470 } |
| 471 |
446 #if GTEST_HAS_DEATH_TEST | 472 #if GTEST_HAS_DEATH_TEST |
447 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a | 473 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a |
448 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX - | 474 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX - |
449 // 1). But we accept ranges exceeding those limits, and silently clamped to | 475 // 1). But we accept ranges exceeding those limits, and silently clamped to |
450 // those limits. This is for backwards compatibility. | 476 // those limits. This is for backwards compatibility. |
451 TEST(HistogramDeathTest, BadRangesTest) { | 477 TEST(HistogramDeathTest, BadRangesTest) { |
452 HistogramBase* histogram = Histogram::FactoryGet( | 478 HistogramBase* histogram = Histogram::FactoryGet( |
453 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8, | 479 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8, |
454 HistogramBase::kNoFlags); | 480 HistogramBase::kNoFlags); |
455 EXPECT_TRUE( | 481 EXPECT_TRUE( |
(...skipping 28 matching lines...) Expand all Loading... |
484 // CustomHistogram needs at least 1 valid range. | 510 // CustomHistogram needs at least 1 valid range. |
485 custom_ranges.clear(); | 511 custom_ranges.clear(); |
486 custom_ranges.push_back(0); | 512 custom_ranges.push_back(0); |
487 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 513 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
488 HistogramBase::kNoFlags), | 514 HistogramBase::kNoFlags), |
489 ""); | 515 ""); |
490 } | 516 } |
491 #endif | 517 #endif |
492 | 518 |
493 } // namespace base | 519 } // namespace base |
OLD | NEW |