Add simple modifier test
This commit is contained in:
parent
1985f43bad
commit
cae7a9c3ec
|
@ -20,7 +20,8 @@
|
||||||
// Col2, Row 0 has to be KC_NO, because tests rely on it
|
// Col2, Row 0 has to be KC_NO, because tests rely on it
|
||||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
[0] = {
|
[0] = {
|
||||||
{KC_A, KC_B, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
// 0 1 2 3 4 5 6 7 8 9
|
||||||
|
{KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, KC_NO, KC_NO, KC_NO, KC_NO},
|
||||||
{KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
{KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
||||||
{KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
{KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
||||||
{KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
{KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
|
||||||
|
|
|
@ -69,3 +69,20 @@ TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
|
||||||
keyboard_task();
|
keyboard_task();
|
||||||
keyboard_task();
|
keyboard_task();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
|
||||||
|
TestDriver driver;
|
||||||
|
press_key(3, 0);
|
||||||
|
press_key(0, 0);
|
||||||
|
// Unfortunately modifiers are also processed in the wrong order
|
||||||
|
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
|
||||||
|
keyboard_task();
|
||||||
|
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT)));
|
||||||
|
keyboard_task();
|
||||||
|
release_key(0, 0);
|
||||||
|
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
|
||||||
|
keyboard_task();
|
||||||
|
release_key(3, 0);
|
||||||
|
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
|
||||||
|
keyboard_task();
|
||||||
|
}
|
|
@ -47,21 +47,27 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
|
std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
|
||||||
stream << "Keyboard report:" << std::endl;
|
stream << "Keyboard report:" << std::endl;
|
||||||
stream << "Mods: " << value.mods << std::endl;
|
stream << "Mods: " << (uint32_t)value.mods << std::endl;
|
||||||
|
stream << "Keys: ";
|
||||||
// TODO: This should probably print friendly names for the keys
|
// TODO: This should probably print friendly names for the keys
|
||||||
for (uint32_t k: get_keys(value)) {
|
for (uint32_t k: get_keys(value)) {
|
||||||
stream << k << std::endl;
|
stream << k << " ";
|
||||||
}
|
}
|
||||||
|
stream << std::endl;
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
|
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
|
||||||
// TODO: Support modifiers
|
|
||||||
memset(m_report.raw, 0, sizeof(m_report.raw));
|
memset(m_report.raw, 0, sizeof(m_report.raw));
|
||||||
for (auto k: keys) {
|
for (auto k: keys) {
|
||||||
|
if (IS_MOD(k)) {
|
||||||
|
m_report.mods |= MOD_BIT(k);
|
||||||
|
}
|
||||||
|
else {
|
||||||
add_key_to_report(&m_report, k);
|
add_key_to_report(&m_report, k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
|
bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
|
||||||
return m_report == report;
|
return m_report == report;
|
||||||
|
|
Loading…
Reference in New Issue