1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
// Copyright (c) Signal Estimator authors
// Licensed under MIT
#include "reports/TextReporter.hpp"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <memory>
#include <string>
using namespace signal_estimator;
namespace {
Config makeConfig(bool show_device_names, bool diff_inputs) {
Config config;
config.show_device_names = show_device_names;
config.diff_inputs = diff_inputs;
return config;
}
DevInfo makeDevInfo(const std::string& short_name) {
DevInfo info;
info.short_name = short_name;
return info;
}
struct MockConsole : Console {
void write(const char* str) override {
buffer += str;
}
void flush() override {
}
std::string buffer;
};
struct TextReporterParam {
Config config;
DevInfo dev_info;
std::string expected_result;
};
struct TextReporterSuite : testing::TestWithParam<TextReporterParam> { };
TEST_P(TextReporterSuite, LatencyReport) {
const auto& [config, dev_info, expected_result] = GetParam();
MockConsole console;
{
TextPrinter printer(console);
TextReporter reporter(config, dev_info, printer);
LatencyReport latency_report;
latency_report.sw_hw = 1.2345;
latency_report.hw = -2.3456;
latency_report.hw_avg = 3.4567;
reporter.report(latency_report);
}
EXPECT_THAT(console.buffer, testing::StrEq(expected_result));
}
INSTANTIATE_TEST_SUITE_P(TextReporterTest, TextReporterSuite,
testing::Values(
TextReporterParam {
makeConfig(/* show_device_names */ false, /* diff_inputs */ true),
makeDevInfo(""),
// expected_result:
"latency: sw+hw +1.23ms hw -2.35ms hw_avg5 +3.46ms\n",
},
TextReporterParam {
makeConfig(/* show_device_names */ false, /* diff_inputs */ false),
makeDevInfo(""),
// expected_result:
"latency: sw+hw 1.23ms hw -2.35ms hw_avg5 3.46ms\n",
},
TextReporterParam {
makeConfig(/* show_device_names */ false, /* diff_inputs */ false),
makeDevInfo("Test Device"),
// expected_result:
"latency: sw+hw 1.23ms hw -2.35ms hw_avg5 3.46ms\n",
},
TextReporterParam {
makeConfig(/* show_device_names */ true, /* diff_inputs */ false),
makeDevInfo("Test Device"),
// expected_result:
"latency[Test Device]: sw+hw 1.23ms hw -2.35ms hw_avg5 3.46ms\n",
}));
} // namespace
|