Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: base/metrics/histogram_unittest.cc

Issue 141393002: Return a NULL histogram pointer on construction error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework, return NULL instead Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
454 // Try to get the same histogram name with different arguments.
455 HistogramBase* bad_histogram = Histogram::FactoryGet(
456 "BadConstruction", 0, 100, 7,
457 HistogramBase::kNoFlags);
458 EXPECT_EQ(NULL, bad_histogram);
459 bad_histogram = Histogram::FactoryGet(
460 "BadConstruction", 0, 99, 8,
461 HistogramBase::kNoFlags);
462 EXPECT_EQ(NULL, bad_histogram);
463
464 HistogramBase* linear_histogram = LinearHistogram::FactoryGet(
465 "BadConstructionLinear", 0, 100, 8,
466 HistogramBase::kNoFlags);
467 EXPECT_TRUE(
468 linear_histogram->HasConstructionArguments(
469 1, 100, 8));
470
471 // Try to get the same histogram name with different arguments.
472 bad_histogram = LinearHistogram::FactoryGet(
473 "BadConstructionLinear", 0, 100, 7,
474 HistogramBase::kNoFlags);
475 EXPECT_EQ(NULL, bad_histogram);
476 bad_histogram = LinearHistogram::FactoryGet(
477 "BadConstructionLinear", 10, 100, 8,
478 HistogramBase::kNoFlags);
479 EXPECT_EQ(NULL, bad_histogram);
480 }
481
446 #if GTEST_HAS_DEATH_TEST 482 #if GTEST_HAS_DEATH_TEST
447 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a 483 // For Histogram, LinearHistogram and CustomHistogram, the minimum for a
448 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX - 484 // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX -
449 // 1). But we accept ranges exceeding those limits, and silently clamped to 485 // 1). But we accept ranges exceeding those limits, and silently clamped to
450 // those limits. This is for backwards compatibility. 486 // those limits. This is for backwards compatibility.
451 TEST(HistogramDeathTest, BadRangesTest) { 487 TEST(HistogramDeathTest, BadRangesTest) {
452 HistogramBase* histogram = Histogram::FactoryGet( 488 HistogramBase* histogram = Histogram::FactoryGet(
453 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8, 489 "BadRanges", 0, HistogramBase::kSampleType_MAX, 8,
454 HistogramBase::kNoFlags); 490 HistogramBase::kNoFlags);
455 EXPECT_TRUE( 491 EXPECT_TRUE(
(...skipping 28 matching lines...) Expand all
484 // CustomHistogram needs at least 1 valid range. 520 // CustomHistogram needs at least 1 valid range.
485 custom_ranges.clear(); 521 custom_ranges.clear();
486 custom_ranges.push_back(0); 522 custom_ranges.push_back(0);
487 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, 523 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges,
488 HistogramBase::kNoFlags), 524 HistogramBase::kNoFlags),
489 ""); 525 "");
490 } 526 }
491 #endif 527 #endif
492 528
493 } // namespace base 529 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698