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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram_unittest.cc
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index e7a01aa5af3d54bf1973f959822b1d989bd8417a..3ffe88d27a4594ad1fef8aa14fb1727877bb4c66 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -443,6 +443,42 @@ TEST_F(HistogramTest, CustomHistogramSerializeInfo) {
EXPECT_FALSE(iter.SkipBytes(1));
}
+TEST_F(HistogramTest, BadConstruction) {
+ HistogramBase* histogram = Histogram::FactoryGet(
+ "BadConstruction", 0, 100, 8,
+ HistogramBase::kNoFlags);
+ EXPECT_TRUE(
+ histogram->HasConstructionArguments(
+ 1, 100, 8));
+
+ // Try to get the same histogram name with different arguments.
+ HistogramBase* bad_histogram = Histogram::FactoryGet(
+ "BadConstruction", 0, 100, 7,
+ HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+ bad_histogram = Histogram::FactoryGet(
+ "BadConstruction", 0, 99, 8,
+ HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+
+ HistogramBase* linear_histogram = LinearHistogram::FactoryGet(
+ "BadConstructionLinear", 0, 100, 8,
+ HistogramBase::kNoFlags);
+ EXPECT_TRUE(
+ linear_histogram->HasConstructionArguments(
+ 1, 100, 8));
+
+ // Try to get the same histogram name with different arguments.
+ bad_histogram = LinearHistogram::FactoryGet(
+ "BadConstructionLinear", 0, 100, 7,
+ HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+ bad_histogram = LinearHistogram::FactoryGet(
+ "BadConstructionLinear", 10, 100, 8,
+ HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+}
+
#if GTEST_HAS_DEATH_TEST
// For Histogram, LinearHistogram and CustomHistogram, the minimum for a
// declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX -

Powered by Google App Engine
This is Rietveld 408576698