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, |
| 449 HistogramBase::kNoFlags); |
| 450 EXPECT_TRUE( |
| 451 histogram->HasConstructionArguments( |
| 452 1, 100, 8)); |
| 453 histogram->Add(10); |
| 454 |
| 455 // Try to get the same histogram name with different arguments. |
| 456 HistogramBase* dummy_histogram = Histogram::FactoryGet( |
| 457 "BadConstruction", 0, 100, 7, |
| 458 HistogramBase::kNoFlags); |
| 459 dummy_histogram->Add(80); |
| 460 dummy_histogram = Histogram::FactoryGet( |
| 461 "BadConstruction", 0, 99, 8, |
| 462 HistogramBase::kNoFlags); |
| 463 dummy_histogram->Add(80); |
| 464 |
| 465 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
| 466 EXPECT_EQ(1, samples->TotalCount()); |
| 467 EXPECT_EQ(1, samples->GetCount(10)); |
| 468 EXPECT_EQ(0, samples->GetCount(80)); |
| 469 |
| 470 HistogramBase* linear_histogram = LinearHistogram::FactoryGet( |
| 471 "BadConstructionLinear", 0, 100, 8, |
| 472 HistogramBase::kNoFlags); |
| 473 EXPECT_TRUE( |
| 474 linear_histogram->HasConstructionArguments( |
| 475 1, 100, 8)); |
| 476 linear_histogram->Add(10); |
| 477 |
| 478 // Try to get the same histogram name with different arguments. |
| 479 dummy_histogram = LinearHistogram::FactoryGet( |
| 480 "BadConstructionLinear", 0, 100, 7, |
| 481 HistogramBase::kNoFlags); |
| 482 dummy_histogram->Add(80); |
| 483 dummy_histogram = LinearHistogram::FactoryGet( |
| 484 "BadConstructionLinear", 10, 100, 8, |
| 485 HistogramBase::kNoFlags); |
| 486 dummy_histogram->Add(80); |
| 487 |
| 488 scoped_ptr<HistogramSamples> l_samples = linear_histogram->SnapshotSamples(); |
| 489 EXPECT_EQ(1, l_samples->TotalCount()); |
| 490 EXPECT_EQ(1, l_samples->GetCount(10)); |
| 491 EXPECT_EQ(0, l_samples->GetCount(80)); |
| 492 } |
| 493 |
446 #if GTEST_HAS_DEATH_TEST | 494 #if GTEST_HAS_DEATH_TEST |
447 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a | 495 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a |
448 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX - | 496 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX - |
449 // 1). But we accept ranges exceeding those limits, and silently clamped to | 497 // 1). But we accept ranges exceeding those limits, and silently clamped to |
450 // those limits. This is for backwards compatibility. | 498 // those limits. This is for backwards compatibility. |
451 TEST(HistogramDeathTest, BadRangesTest) { | 499 TEST(HistogramDeathTest, BadRangesTest) { |
452 HistogramBase* histogram = Histogram::FactoryGet( | 500 HistogramBase* histogram = Histogram::FactoryGet( |
453 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8, | 501 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8, |
454 HistogramBase::kNoFlags); | 502 HistogramBase::kNoFlags); |
455 EXPECT_TRUE( | 503 EXPECT_TRUE( |
(...skipping 28 matching lines...) Expand all Loading... |
484 // CustomHistogram needs at least 1 valid range. | 532 // CustomHistogram needs at least 1 valid range. |
485 custom_ranges.clear(); | 533 custom_ranges.clear(); |
486 custom_ranges.push_back(0); | 534 custom_ranges.push_back(0); |
487 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 535 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
488 HistogramBase::kNoFlags), | 536 HistogramBase::kNoFlags), |
489 ""); | 537 ""); |
490 } | 538 } |
491 #endif | 539 #endif |
492 | 540 |
493 } // namespace base | 541 } // namespace base |
OLD | NEW |