|
|
@ -19,6 +19,8 @@
|
|
|
|
#include "HIDReportObserver.h"
|
|
|
|
#include "HIDReportObserver.h"
|
|
|
|
#include "testing/HIDState.h"
|
|
|
|
#include "testing/HIDState.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <bitset>
|
|
|
|
|
|
|
|
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace testing {
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
|
|
|
@ -40,6 +42,7 @@ void VirtualDeviceTest::ClearState() {
|
|
|
|
output_state_ = nullptr;
|
|
|
|
output_state_ = nullptr;
|
|
|
|
input_timestamps_.clear();
|
|
|
|
input_timestamps_.clear();
|
|
|
|
expected_keyboard_reports_.clear();
|
|
|
|
expected_keyboard_reports_.clear();
|
|
|
|
|
|
|
|
expected_mouse_reports_.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HIDState* VirtualDeviceTest::HIDReports() const {
|
|
|
|
const HIDState* VirtualDeviceTest::HIDReports() const {
|
|
|
@ -120,9 +123,23 @@ void VirtualDeviceTest::RemoveFromKeyboardReport(Key key) {
|
|
|
|
current_keyboard_keycodes_.erase(key.getKeyCode());
|
|
|
|
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 {
|
|
|
|
void VirtualDeviceTest::CheckReports() const {
|
|
|
|
CheckKeyboardReports();
|
|
|
|
CheckKeyboardReports();
|
|
|
|
|
|
|
|
CheckMouseReports();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VirtualDeviceTest::CheckKeyboardReports() const {
|
|
|
|
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 testing
|
|
|
|
} // namespace kaleidoscope
|
|
|
|
} // namespace kaleidoscope
|
|
|
|