Treat SystemControlReport like a container in tests.

Signed-off-by: Eric Paniagua <epaniagua@google.com>
pull/898/head
Eric Paniagua 4 years ago
parent 54f2dfb070
commit 0cab1494b5

@ -25,6 +25,7 @@ SystemControlReport::SystemControlReport(const void* data) {
const ReportData& report_data =
*static_cast<const ReportData*>(data);
memcpy(&report_data_, &report_data, sizeof(report_data_));
this->push_back(report_data_.key);
}
uint8_t SystemControlReport::Key() const {

@ -24,7 +24,7 @@
namespace kaleidoscope {
namespace testing {
class SystemControlReport {
class SystemControlReport : public std::vector<uint8_t> {
public:
typedef HID_SystemControlReport_Data_t ReportData;

@ -17,6 +17,7 @@
#pragma once
#include "kaleidoscope/key_defs.h"
#include "testing/common/SystemControlReport.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for
// gtest and gmock.
@ -26,6 +27,31 @@
namespace kaleidoscope {
namespace testing {
MATCHER_P(Contains, key, negation ? "does not contain" : "contains") {
return arg.Key() == key.getKeyCode();
}
class SystemControlReportIsNullMatcher
: public ::testing::MatcherInterface<SystemControlReport> {
public:
bool MatchAndExplain(SystemControlReport report,
::testing::MatchResultListener* /* ignored */) const override {
return report.Key() == 0;
}
void DescribeTo(std::ostream* os) const override {
*os << "is empty";
}
void DescribeNegationTo(std::ostream* os) const override {
*os << "is not empty";
}
};
::testing::Matcher<SystemControlReport> IsNull() {
return ::testing::MakeMatcher(new SystemControlReportIsNullMatcher);
}
auto Contains(Key key) { return ::testing::Contains(key.getKeyCode()); }
} // namespace testing

@ -42,30 +42,24 @@ TEST_F(Issue840, HasNotRegressed) {
auto state = RunCycle();
ASSERT_EQ(state->SystemControlReports().size(), 1);
EXPECT_EQ(
state->SystemControlReports(0).Key(),
System_PowerDown.getKeyCode());
EXPECT_THAT(state->SystemControlReports(0), Contains(System_PowerDown));
sim_.Press(3, 5); // Press System_Sleep
state = RunCycle();
ASSERT_EQ(state->SystemControlReports().size(), 1);
EXPECT_EQ(
state->SystemControlReports(0).Key(),
System_Sleep.getKeyCode());
EXPECT_THAT(state->SystemControlReports(0), Contains(System_Sleep));
sim_.Release(2, 1); // Release System_PowerDown
state = RunCycle();
ASSERT_EQ(state->SystemControlReports().size(), 0);
EXPECT_EQ(state->SystemControlReports().size(), 0);
sim_.Release(3, 5); // Release System_Sleep
state = RunCycle();
ASSERT_EQ(state->SystemControlReports().size(), 1);
EXPECT_EQ(
state->SystemControlReports(0).Key(),
0 /* null report */);
EXPECT_THAT(state->SystemControlReports(0), IsNull());
state = RunCycle();
@ -77,33 +71,25 @@ TEST_F(Issue840, HasNotRegressed) {
// auto state = RunCycle();
//
// ASSERT_EQ(state->SystemControlReports().size(), 1);
// EXPECT_EQ(
// state->SystemControlReports(0).Key(),
// System_PowerDown.getKeyCode());
// EXPECT_THAT(state->SystemControlReports(0), Contains(System_PowerDown));
//
// sim_.Press(3, 5); // Press System_Sleep
// state = RunCycle();
//
// ASSERT_EQ(state->SystemControlReports().size(), 1);
// EXPECT_EQ(
// state->SystemControlReports(0).Key(),
// System_Sleep.getKeyCode());
// EXPECT_THAT(state->SystemControlReports(0), Contains(System_Sleep));
//
// sim_.Release(2, 1); // Release System_PowerDown
// state = RunCycle();
//
// ASSERT_EQ(state->SystemControlReports().size(), 1);
// EXPECT_EQ(
// state->SystemControlReports(0).Key(),
// 0 /* null report */);
// EXPECT_THAT(state->SystemControlReports(0), IsNull());
//
// sim_.Release(3, 5); // Release System_Sleep
// state = RunCycle();
//
// ASSERT_EQ(state->SystemControlReports().size(), 1);
// EXPECT_EQ(
// state->SystemControlReports(0).Key(),
// 0 /* null report */);
// EXPECT_THAT(state->SystemControlReports(0), IsNull());
//
// state = RunCycle();
//

Loading…
Cancel
Save