Rename *Report functions to *KeyboardReport

In preparation for validation of report types other than just Keyboard, rename
these keyboard-specific functions (and variables) to have appropriately
keyboard-specific names.

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

@ -39,7 +39,7 @@ void VirtualDeviceTest::LoadState() {
void VirtualDeviceTest::ClearState() { void VirtualDeviceTest::ClearState() {
output_state_ = nullptr; output_state_ = nullptr;
input_timestamps_.clear(); input_timestamps_.clear();
expected_reports_.clear(); expected_keyboard_reports_.clear();
} }
const HIDState* VirtualDeviceTest::HIDReports() const { const HIDState* VirtualDeviceTest::HIDReports() const {
@ -69,77 +69,78 @@ void VirtualDeviceTest::ReleaseKey(KeyAddr addr) {
// ============================================================================= // =============================================================================
void VirtualDeviceTest::ExpectReport(Keycodes keys, void VirtualDeviceTest::ExpectKeyboardReport(Keycodes keys,
std::string description) { std::string description) {
size_t report_timestamp{Runtime.millisAtCycleStart()}; size_t report_timestamp{Runtime.millisAtCycleStart()};
ClearReport(); ClearKeyboardReport();
for (Key key : keys) { for (Key key : keys) {
AddToReport(key); AddToKeyboardReport(key);
} }
ExpectedKeyboardReport new_report(report_timestamp, ExpectedKeyboardReport new_report(report_timestamp,
current_keyboard_keycodes_, current_keyboard_keycodes_,
description); description);
expected_reports_.push_back(new_report); expected_keyboard_reports_.push_back(new_report);
} }
// ============================================================================= // =============================================================================
void VirtualDeviceTest::ExpectReport(AddKeycodes added_keys, void VirtualDeviceTest::ExpectKeyboardReport(AddKeycodes added_keys,
RemoveKeycodes removed_keys, RemoveKeycodes removed_keys,
std::string description) { std::string description) {
uint32_t report_timestamp = Runtime.millisAtCycleStart(); uint32_t report_timestamp = Runtime.millisAtCycleStart();
for (Key key : added_keys) { for (Key key : added_keys) {
AddToReport(key); AddToKeyboardReport(key);
} }
for (Key key : removed_keys) { for (Key key : removed_keys) {
RemoveFromReport(key); RemoveFromKeyboardReport(key);
} }
ExpectedKeyboardReport new_report(report_timestamp, ExpectedKeyboardReport new_report(report_timestamp,
current_keyboard_keycodes_, current_keyboard_keycodes_,
description); description);
expected_reports_.push_back(new_report); expected_keyboard_reports_.push_back(new_report);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void VirtualDeviceTest::ExpectReport(AddKeycodes added_keys, void VirtualDeviceTest::ExpectKeyboardReport(AddKeycodes added_keys,
std::string description) { std::string description) {
ExpectReport(added_keys, RemoveKeycodes{}, description); ExpectKeyboardReport(added_keys, RemoveKeycodes{}, description);
} }
void VirtualDeviceTest::ExpectReport(RemoveKeycodes removed_keys, void VirtualDeviceTest::ExpectKeyboardReport(RemoveKeycodes removed_keys,
std::string description) { std::string description) {
ExpectReport(AddKeycodes{}, removed_keys, description); ExpectKeyboardReport(AddKeycodes{}, removed_keys, description);
} }
// ============================================================================= // =============================================================================
void VirtualDeviceTest::ClearReport() { void VirtualDeviceTest::ClearKeyboardReport() {
current_keyboard_keycodes_.clear(); current_keyboard_keycodes_.clear();
} }
void VirtualDeviceTest::AddToReport(Key key) { void VirtualDeviceTest::AddToKeyboardReport(Key key) {
current_keyboard_keycodes_.insert(key.getKeyCode()); current_keyboard_keycodes_.insert(key.getKeyCode());
} }
void VirtualDeviceTest::RemoveFromReport(Key key) { void VirtualDeviceTest::RemoveFromKeyboardReport(Key key) {
current_keyboard_keycodes_.erase(key.getKeyCode()); current_keyboard_keycodes_.erase(key.getKeyCode());
} }
// ============================================================================= // =============================================================================
void VirtualDeviceTest::CheckReports() const { void VirtualDeviceTest::CheckReports() const {
int observed_report_count = HIDReports()->Keyboard().size(); int observed_keyboard_report_count = HIDReports()->Keyboard().size();
int expected_report_count = expected_reports_.size(); int expected_keyboard_report_count = expected_keyboard_reports_.size();
EXPECT_EQ(observed_report_count, expected_report_count); EXPECT_EQ(observed_keyboard_report_count, expected_keyboard_report_count);
int max_count = std::max(observed_report_count, expected_report_count); int max_count = std::max(observed_keyboard_report_count,
expected_keyboard_report_count);
for (int i = 0; i < observed_report_count; ++i) { for (int i = 0; i < observed_keyboard_report_count; ++i) {
auto observed_report = HIDReports()->Keyboard(i); auto observed_report = HIDReports()->Keyboard(i);
auto observed_keycodes = observed_report.ActiveKeycodes(); auto observed_keycodes = observed_report.ActiveKeycodes();
if (i < expected_report_count) { if (i < expected_keyboard_report_count) {
auto expected_report = expected_reports_[i]; auto expected_report = expected_keyboard_reports_[i];
auto expected_keycodes = expected_report.Keycodes(); auto expected_keycodes = expected_report.Keycodes();
EXPECT_THAT(observed_keycodes, EXPECT_THAT(observed_keycodes,
::testing::ElementsAreArray(expected_keycodes)) ::testing::ElementsAreArray(expected_keycodes))
<< expected_reports_[i].Message() << " (i=" << i << ")"; << expected_keyboard_reports_[i].Message() << " (i=" << i << ")";
EXPECT_EQ(observed_report.Timestamp(), expected_report.Timestamp()) EXPECT_EQ(observed_report.Timestamp(), expected_report.Timestamp())
<< "Report timestamps don't match (i=" << i << ")"; << "Report timestamps don't match (i=" << i << ")";

@ -103,22 +103,22 @@ class VirtualDeviceTest : public ::testing::Test {
// keycode changes in a single report; others only a single keycode. Some run // keycode changes in a single report; others only a single keycode. Some run
// the simulator for a specified number of milliseconds or cycles first. These // the simulator for a specified number of milliseconds or cycles first. These
// expected-value reports are all stored in a vector: // expected-value reports are all stored in a vector:
std::vector<ExpectedKeyboardReport> expected_reports_ = {}; std::vector<ExpectedKeyboardReport> expected_keyboard_reports_ = {};
void ExpectReport(AddKeycodes added_keys, void ExpectKeyboardReport(AddKeycodes added_keys,
RemoveKeycodes removed_keys, RemoveKeycodes removed_keys,
std::string description); std::string description);
void ExpectReport(Keycodes added_keys, std::string description); void ExpectKeyboardReport(Keycodes added_keys, std::string description);
void ExpectReport(AddKeycodes added_keys, std::string description); void ExpectKeyboardReport(AddKeycodes added_keys, std::string description);
void ExpectReport(RemoveKeycodes removed_keys, std::string description); void ExpectKeyboardReport(RemoveKeycodes removed_keys, std::string description);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
std::set<uint8_t> current_keyboard_keycodes_ = {}; std::set<uint8_t> current_keyboard_keycodes_ = {};
// Manage the set of keycodes expected in the next report // Manage the set of keycodes expected in the next report
void ClearReport(); void ClearKeyboardReport();
void AddToReport(Key key); void AddToKeyboardReport(Key key);
void RemoveFromReport(Key key); void RemoveFromKeyboardReport(Key key);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Compare accumulated observed and expected reports, matching both timestamps // Compare accumulated observed and expected reports, matching both timestamps

@ -422,7 +422,7 @@ sub generate_expect_report {
: ( $report->{data}->{keys} ) : ( $report->{data}->{keys} )
) )
); );
cxx( "ExpectReport(Keycodes{$codes}, \"" cxx( "ExpectKeyboardReport(Keycodes{$codes}, \""
. ( $report->{comment} || 'No explanatory comment specified' ) . ( $report->{comment} || 'No explanatory comment specified' )
. "\");" ); . "\");" );
cxx(""); cxx("");

Loading…
Cancel
Save