Commit b2757871 authored by Andrew Solovey's avatar Andrew Solovey Committed by Commit Bot

Test histogram graphical representation methods

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

R=dcheng@chromium.org

Bug: 1006447
Test: browser_tests --gtest_filter="HistogramTest"
Change-Id: I37406b094d81171d27f7fe372424ef43ccdf20e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980609
Commit-Queue: Andrei Salavei <solovey@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734883}
parent 176121f7
......@@ -28,6 +28,7 @@
#include "base/strings/stringprintf.h"
#include "base/test/gtest_util.h"
#include "base/time/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......@@ -897,4 +898,40 @@ TEST_P(HistogramTest, ExpiredHistogramTest) {
EXPECT_EQ(2, samples->TotalCount());
}
TEST_P(HistogramTest, WriteAscii) {
HistogramBase* histogram =
LinearHistogram::FactoryGet("AsciiOut", /*minimum=*/1, /*maximum=*/10,
/*bucket_count=*/5, HistogramBase::kNoFlags);
histogram->AddCount(/*sample=*/4, /*value=*/5);
std::string output;
histogram->WriteAscii(&output);
const char kOutputFormatRe[] =
R"(Histogram: AsciiOut recorded 5 samples, mean = 4\.0.*\n)"
R"(0 \.\.\. \n)"
R"(4 -+O \(5 = 100\.0%\) \{0\.0%\}\n)"
R"(7 \.\.\. \n)";
EXPECT_THAT(output, testing::MatchesRegex(kOutputFormatRe));
}
TEST_P(HistogramTest, WriteHTMLGraph) {
HistogramBase* histogram =
LinearHistogram::FactoryGet("HTMLOut", /*minimum=*/1, /*maximum=*/10,
/*bucket_count=*/5, HistogramBase::kNoFlags);
histogram->AddCount(/*sample=*/4, /*value=*/5);
std::string output;
histogram->WriteHTMLGraph(&output);
const char kOutputFormatRe[] =
R"(<PRE>Histogram: HTMLOut recorded 5 samples, mean = 4\.0.*<br>)"
R"(0 \.\.\. <br>)"
R"(4 -+O \(5 = 100\.0%\) \{0\.0%\}<br>)"
R"(7 \.\.\. <br><\/PRE>)";
EXPECT_THAT(output, testing::MatchesRegex(kOutputFormatRe));
}
} // 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