Index: base/metrics/histogram_unittest.cc |
=================================================================== |
--- base/metrics/histogram_unittest.cc (revision 106341) |
+++ base/metrics/histogram_unittest.cc (working copy) |
@@ -387,25 +387,26 @@ |
EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0); |
EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption. |
- std::swap(histogram->ranges_[1], histogram->ranges_[2]); |
+ CachedRanges* cached_ranges = histogram->cached_ranges(); |
+ std::swap(cached_ranges->ranges_[1], cached_ranges->ranges_[2]); |
EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR, |
histogram->FindCorruption(snapshot)); |
- std::swap(histogram->ranges_[1], histogram->ranges_[2]); |
+ std::swap(cached_ranges->ranges_[1], cached_ranges->ranges_[2]); |
EXPECT_EQ(0, histogram->FindCorruption(snapshot)); |
- ++histogram->ranges_[3]; |
+ ++cached_ranges->ranges_[3]; |
EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, |
histogram->FindCorruption(snapshot)); |
// Show that two simple changes don't offset each other |
- --histogram->ranges_[4]; |
+ --cached_ranges->ranges_[4]; |
EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, |
histogram->FindCorruption(snapshot)); |
// Repair histogram so that destructor won't DCHECK(). |
- --histogram->ranges_[3]; |
- ++histogram->ranges_[4]; |
+ --cached_ranges->ranges_[3]; |
+ ++cached_ranges->ranges_[4]; |
} |
// Table was generated similarly to sample code for CRC-32 given on: |
@@ -424,4 +425,29 @@ |
} |
} |
+// RangeTest, CustomRangeTest and CorruptBucketBounds test CachedRanges class. |
+// The following tests sharing of CachedRanges object. |
+TEST(HistogramTest, CachedRangesTest) { |
+ StatisticsRecorder recorder; |
+ StatisticsRecorder::Histograms histograms; |
+ |
+ recorder.GetHistograms(&histograms); |
+ EXPECT_EQ(0U, histograms.size()); |
+ |
+ Histogram* histogram1(Histogram::FactoryGet( |
+ "Histogram", 1, 64, 8, Histogram::kNoFlags)); |
+ |
+ Histogram* histogram2(Histogram::FactoryGet( |
+ "Histogram2", 1, 64, 8, Histogram::kNoFlags)); |
+ |
+ Histogram* histogram3(Histogram::FactoryGet( |
+ "Histogram3", 1, 64, 16, Histogram::kNoFlags)); |
+ |
+ CachedRanges* cached_ranges1 = histogram1->cached_ranges(); |
+ CachedRanges* cached_ranges2 = histogram2->cached_ranges(); |
+ CachedRanges* cached_ranges3 = histogram3->cached_ranges(); |
+ EXPECT_TRUE(cached_ranges1->Equals(cached_ranges2)); |
+ EXPECT_FALSE(cached_ranges1->Equals(cached_ranges3)); |
+} |
+ |
} // namespace base |