@ -39,7 +39,7 @@ void VirtualDeviceTest::LoadState() {
void VirtualDeviceTest : : ClearState ( ) {
output_state_ = nullptr ;
input_timestamps_ . clear ( ) ;
expected_ reports_. clear ( ) ;
expected_ keyboard_ reports_. clear ( ) ;
}
const HIDState * VirtualDeviceTest : : HIDReports ( ) const {
@ -69,77 +69,78 @@ void VirtualDeviceTest::ReleaseKey(KeyAddr addr) {
// =============================================================================
void VirtualDeviceTest : : Expect Report( Keycodes keys ,
void VirtualDeviceTest : : Expect Keyboard Report( Keycodes keys ,
std : : string description ) {
size_t report_timestamp { Runtime . millisAtCycleStart ( ) } ;
Clear Report( ) ;
Clear Keyboard Report( ) ;
for ( Key key : keys ) {
AddTo Report( key ) ;
AddTo Keyboard Report( key ) ;
}
ExpectedKeyboardReport new_report ( report_timestamp ,
current_keyboard_keycodes_ ,
description ) ;
expected_ reports_. push_back ( new_report ) ;
expected_ keyboard_ reports_. push_back ( new_report ) ;
}
// =============================================================================
void VirtualDeviceTest : : Expect Report( AddKeycodes added_keys ,
void VirtualDeviceTest : : Expect Keyboard Report( AddKeycodes added_keys ,
RemoveKeycodes removed_keys ,
std : : string description ) {
uint32_t report_timestamp = Runtime . millisAtCycleStart ( ) ;
for ( Key key : added_keys ) {
AddTo Report( key ) ;
AddTo Keyboard Report( key ) ;
}
for ( Key key : removed_keys ) {
RemoveFrom Report( key ) ;
RemoveFrom Keyboard Report( key ) ;
}
ExpectedKeyboardReport new_report ( report_timestamp ,
current_keyboard_keycodes_ ,
description ) ;
expected_ reports_. push_back ( new_report ) ;
expected_ keyboard_ reports_. push_back ( new_report ) ;
}
// -----------------------------------------------------------------------------
void VirtualDeviceTest : : Expect Report( AddKeycodes added_keys ,
void VirtualDeviceTest : : Expect Keyboard Report( AddKeycodes added_keys ,
std : : string description ) {
Expect Report( added_keys , RemoveKeycodes { } , description ) ;
Expect Keyboard Report( added_keys , RemoveKeycodes { } , description ) ;
}
void VirtualDeviceTest : : Expect Report( RemoveKeycodes removed_keys ,
void VirtualDeviceTest : : Expect Keyboard Report( RemoveKeycodes removed_keys ,
std : : string description ) {
Expect Report( AddKeycodes { } , removed_keys , description ) ;
Expect Keyboard Report( AddKeycodes { } , removed_keys , description ) ;
}
// =============================================================================
void VirtualDeviceTest : : Clear Report( ) {
void VirtualDeviceTest : : Clear Keyboard Report( ) {
current_keyboard_keycodes_ . clear ( ) ;
}
void VirtualDeviceTest : : AddTo Report( Key key ) {
void VirtualDeviceTest : : AddTo Keyboard Report( Key key ) {
current_keyboard_keycodes_ . insert ( key . getKeyCode ( ) ) ;
}
void VirtualDeviceTest : : RemoveFrom Report( Key key ) {
void VirtualDeviceTest : : RemoveFrom Keyboard Report( Key key ) {
current_keyboard_keycodes_ . erase ( key . getKeyCode ( ) ) ;
}
// =============================================================================
void VirtualDeviceTest : : CheckReports ( ) const {
int observed_ report_count = HIDReports ( ) - > Keyboard ( ) . size ( ) ;
int expected_ report_count = expecte d_reports_. size ( ) ;
int observed_ keyboard_ report_count = HIDReports ( ) - > Keyboard ( ) . size ( ) ;
int expected_ keyboard_ report_count = expecte d_keyboar d_reports_. size ( ) ;
EXPECT_EQ ( observed_ report_count, expecte d_report_count) ;
EXPECT_EQ ( observed_ keyboard_ report_count, expecte d_keyboar d_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_keycodes = observed_report . ActiveKeycodes ( ) ;
if ( i < expected_ report_count) {
auto expected_report = expected_ reports_[ i ] ;
if ( i < expected_ keyboard_ report_count) {
auto expected_report = expected_ keyboard_ reports_[ i ] ;
auto expected_keycodes = expected_report . Keycodes ( ) ;
EXPECT_THAT ( observed_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 ( ) )
< < " Report timestamps don't match (i= " < < i < < " ) " ;