| Index: base/metrics/histogram_unittest.cc
|
| diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
|
| index e7a01aa5af3d54bf1973f959822b1d989bd8417a..fa0c0e680a83e420919d57a91cf950d30293f13d 100644
|
| --- a/base/metrics/histogram_unittest.cc
|
| +++ b/base/metrics/histogram_unittest.cc
|
| @@ -46,6 +46,8 @@ class HistogramTest : public testing::Test {
|
| StatisticsRecorder* statistics_recorder_;
|
| };
|
|
|
| +typedef HistogramTest HistogramDeathTest;
|
| +
|
| // Check for basic syntax and use.
|
| TEST_F(HistogramTest, BasicTest) {
|
| // Try basic construction
|
| @@ -443,12 +445,81 @@ 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));
|
| + histogram->Add(10);
|
| +
|
| + // Try to get the same histogram name with different arguments.
|
| + HistogramBase* dummy_histogram = Histogram::FactoryGet(
|
| + "BadConstruction", 0, 100, 7,
|
| + HistogramBase::kNoFlags, HistogramBase::kAllowBadConstruction);
|
| + dummy_histogram->Add(80);
|
| + dummy_histogram = Histogram::FactoryGet(
|
| + "BadConstruction", 0, 99, 8,
|
| + HistogramBase::kNoFlags, HistogramBase::kAllowBadConstruction);
|
| + dummy_histogram->Add(80);
|
| +
|
| + scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
|
| + EXPECT_EQ(1, samples->TotalCount());
|
| + EXPECT_EQ(1, samples->GetCount(10));
|
| + EXPECT_EQ(0, samples->GetCount(80));
|
| +
|
| + HistogramBase* linear_histogram = LinearHistogram::FactoryGet(
|
| + "BadConstructionLinear", 0, 100, 8,
|
| + HistogramBase::kNoFlags);
|
| + EXPECT_TRUE(
|
| + linear_histogram->HasConstructionArguments(
|
| + 1, 100, 8));
|
| + linear_histogram->Add(10);
|
| +
|
| + // Try to get the same histogram name with different arguments.
|
| + dummy_histogram = LinearHistogram::FactoryGet(
|
| + "BadConstructionLinear", 0, 100, 7,
|
| + HistogramBase::kNoFlags, HistogramBase::kAllowBadConstruction);
|
| + dummy_histogram->Add(80);
|
| + dummy_histogram = LinearHistogram::FactoryGet(
|
| + "BadConstructionLinear", 10, 100, 8,
|
| + HistogramBase::kNoFlags, HistogramBase::kAllowBadConstruction);
|
| + dummy_histogram->Add(80);
|
| +
|
| + scoped_ptr<HistogramSamples> l_samples = linear_histogram->SnapshotSamples();
|
| + EXPECT_EQ(1, l_samples->TotalCount());
|
| + EXPECT_EQ(1, l_samples->GetCount(10));
|
| + EXPECT_EQ(0, l_samples->GetCount(80));
|
| +}
|
| +
|
| #if GTEST_HAS_DEATH_TEST
|
| +TEST_F(HistogramDeathTest, BadConstructionFatal) {
|
| + HistogramBase* histogram = Histogram::FactoryGet(
|
| + "BadConstruction", 0, 100, 8,
|
| + HistogramBase::kNoFlags);
|
| + EXPECT_TRUE(
|
| + histogram->HasConstructionArguments(
|
| + 1, 100, 8));
|
| + EXPECT_DEATH(Histogram::FactoryGet("BadConstruction", 0, 100, 7,
|
| + HistogramBase::kNoFlags),
|
| + "");
|
| + HistogramBase* linear_histogram = LinearHistogram::FactoryGet(
|
| + "BadConstructionLinear", 0, 100, 8,
|
| + HistogramBase::kNoFlags);
|
| + EXPECT_TRUE(
|
| + linear_histogram->HasConstructionArguments(
|
| + 1, 100, 8));
|
| + EXPECT_DEATH(LinearHistogram::FactoryGet("BadConstructionLinear", 10, 100, 8,
|
| + HistogramBase::kNoFlags),
|
| + "");
|
| +}
|
| +
|
| // For Histogram, LinearHistogram and CustomHistogram, the minimum for a
|
| // declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX -
|
| // 1). But we accept ranges exceeding those limits, and silently clamped to
|
| // those limits. This is for backwards compatibility.
|
| -TEST(HistogramDeathTest, BadRangesTest) {
|
| +TEST_F(HistogramDeathTest, BadRangesTest) {
|
| HistogramBase* histogram = Histogram::FactoryGet(
|
| "BadRanges", 0, HistogramBase::kSampleType_MAX, 8,
|
| HistogramBase::kNoFlags);
|
|
|