Commit 6fd94799 authored by Andrew Solovey's avatar Andrew Solovey Committed by Commit Bot

Test sparse histogram graphical output methods

Add tests to check output format of the |WriteAscii| and
|WriteHTMLGraph| methods for |SparseHistogram| class. Tests check that
all components of the graph graphical representation are on there
places: graph header, newline symbols, graph pillars with value
description.

Bug: 1006447
Test: browser_tests --gtest_filter="SparseHistogramTest"
Change-Id: I6ab33d7848a105c1c3353d1c3b5852fbb2456a71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980729Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Andrei Salavei <solovey@google.com>
Cr-Commit-Position: refs/heads/master@{#735378}
parent 559cf5d0
...@@ -385,4 +385,38 @@ TEST_P(SparseHistogramTest, HistogramNameHash) { ...@@ -385,4 +385,38 @@ TEST_P(SparseHistogramTest, HistogramNameHash) {
EXPECT_EQ(histogram->name_hash(), HashMetricName(kName)); EXPECT_EQ(histogram->name_hash(), HashMetricName(kName));
} }
TEST_P(SparseHistogramTest, WriteAscii) {
HistogramBase* histogram =
SparseHistogram::FactoryGet("AsciiOut", HistogramBase::kNoFlags);
histogram->AddCount(/*sample=*/4, /*value=*/5);
histogram->AddCount(/*sample=*/10, /*value=*/15);
std::string output;
histogram->WriteAscii(&output);
const char kOutputFormatRe[] =
R"(Histogram: AsciiOut recorded 20 samples.*\n)"
R"(4 -+O +\(5 = 25.0%\)\n)"
R"(10 -+O +\(15 = 75.0%\)\n)";
EXPECT_THAT(output, testing::MatchesRegex(kOutputFormatRe));
}
TEST_P(SparseHistogramTest, WriteHTMLGraph) {
HistogramBase* histogram =
SparseHistogram::FactoryGet("HTMLOut", HistogramBase::kNoFlags);
histogram->AddCount(/*sample=*/4, /*value=*/5);
histogram->AddCount(/*sample=*/10, /*value=*/15);
std::string output;
histogram->WriteHTMLGraph(&output);
const char kOutputFormatRe[] =
R"(<PRE>Histogram: HTMLOut recorded 20 samples.*<br>)"
R"(4 -+O +\(5 = 25.0%\)<br>)"
R"(10 -+O +\(15 = 75.0%\)<br><\/PRE>)";
EXPECT_THAT(output, testing::MatchesRegex(kOutputFormatRe));
}
} // namespace base } // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment