Add function for verification of expected mouse reports

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1120/head
Michael Richters 3 years ago
parent 0670113b66
commit 29ebffe099
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -19,6 +19,8 @@
#include "HIDReportObserver.h"
#include "testing/HIDState.h"
#include <bitset>
namespace kaleidoscope {
namespace testing {
@ -40,6 +42,7 @@ void VirtualDeviceTest::ClearState() {
output_state_ = nullptr;
input_timestamps_.clear();
expected_keyboard_reports_.clear();
expected_mouse_reports_.clear();
}
const HIDState* VirtualDeviceTest::HIDReports() const {
@ -120,9 +123,23 @@ void VirtualDeviceTest::RemoveFromKeyboardReport(Key key) {
current_keyboard_keycodes_.erase(key.getKeyCode());
}
// =============================================================================
void VirtualDeviceTest::ExpectMouseReport(uint8_t buttons,
int8_t x, int8_t y,
int8_t v, int8_t h,
std::string description) {
uint32_t report_timestamp = Runtime.millisAtCycleStart();
ExpectedMouseReport new_report(report_timestamp,
buttons, x, y, v, h,
description);
expected_mouse_reports_.push_back(new_report);
}
// =============================================================================
void VirtualDeviceTest::CheckReports() const {
CheckKeyboardReports();
CheckMouseReports();
}
void VirtualDeviceTest::CheckKeyboardReports() const {
@ -160,5 +177,47 @@ void VirtualDeviceTest::CheckKeyboardReports() const {
}
}
void VirtualDeviceTest::CheckMouseReports() const {
int observed_mouse_report_count = HIDReports()->Mouse().size();
int expected_mouse_report_count = expected_mouse_reports_.size();
EXPECT_EQ(observed_mouse_report_count, expected_mouse_report_count);
int max_count = std::max(observed_mouse_report_count,
expected_mouse_report_count);
for (int i = 0; i < observed_mouse_report_count; ++i) {
auto observed_report = HIDReports()->Mouse(i);
if (i < expected_mouse_report_count) {
auto expected_report = expected_mouse_reports_[i];
EXPECT_EQ(observed_report.Buttons(), expected_report.Buttons())
<< expected_mouse_reports_[i].Message() << " (i=" << i << ")";
EXPECT_EQ(observed_report.XAxis(), expected_report.XAxis())
<< expected_mouse_reports_[i].Message() << " (i=" << i << ")";
EXPECT_EQ(observed_report.YAxis(), expected_report.YAxis())
<< expected_mouse_reports_[i].Message() << " (i=" << i << ")";
EXPECT_EQ(observed_report.VWheel(), expected_report.VWheel())
<< expected_mouse_reports_[i].Message() << " (i=" << i << ")";
EXPECT_EQ(observed_report.HWheel(), expected_report.HWheel())
<< expected_mouse_reports_[i].Message() << " (i=" << i << ")";
EXPECT_EQ(observed_report.Timestamp(), expected_report.Timestamp())
<< "Report timestamps don't match (i=" << i << ")";
} else {
std::bitset<8> observed_buttons{observed_report.Buttons()};
std::cerr << "Unexpected mouse report at "
<< observed_report.Timestamp() << "ms: {"
<< " buttons: " << observed_buttons
<< " x: " << int(observed_report.XAxis())
<< " y: " << int(observed_report.YAxis())
<< " v: " << int(observed_report.VWheel())
<< " h: " << int(observed_report.HWheel())
<< " }" << std::endl;
}
}
}
} // namespace testing
} // namespace kaleidoscope

@ -19,6 +19,7 @@
#include <cstddef>
#include "testing/ExpectedKeyboardReport.h"
#include "testing/ExpectedMouseReport.h"
#include "testing/SimHarness.h"
#include "testing/State.h"
@ -113,6 +114,11 @@ class VirtualDeviceTest : public ::testing::Test {
void ExpectKeyboardReport(AddKeycodes added_keys, std::string description);
void ExpectKeyboardReport(RemoveKeycodes removed_keys, std::string description);
std::vector<ExpectedMouseReport> expected_mouse_reports_ = {};
void ExpectMouseReport(uint8_t buttons, int8_t x, int8_t y,
int8_t v, int8_t h, std::string description);
// ---------------------------------------------------------------------------
std::set<uint8_t> current_keyboard_keycodes_ = {};
// Manage the set of keycodes expected in the next report
@ -125,6 +131,7 @@ class VirtualDeviceTest : public ::testing::Test {
// and keycodes.
void CheckReports() const;
void CheckKeyboardReports() const;
void CheckMouseReports() const;
};

Loading…
Cancel
Save