Add a variant of ExpectReport that takes an explicit list of keycodes

Signed-off-by: Jesse Vincent <jesse@keyboard.io>
pull/966/head
Jesse Vincent 4 years ago
parent 78e9ec4291
commit eebf8e639b
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -20,8 +20,8 @@ namespace kaleidoscope {
namespace testing {
ExpectedKeyboardReport::ExpectedKeyboardReport(uint32_t timestamp,
const std::set<uint8_t> &keycodes,
std::string message) {
const std::set<uint8_t> &keycodes,
std::string message) {
timestamp_ = timestamp;
keycodes_ = std::set<uint8_t>(keycodes);
failure_message_ = message;

@ -67,6 +67,21 @@ void VirtualDeviceTest::ReleaseKey(KeyAddr addr) {
input_timestamps_.push_back(Runtime.millisAtCycleStart());
}
// =============================================================================
void VirtualDeviceTest::ExpectReport(Keycodes keys,
std::string description) {
Millis report_timestamp{Runtime.millisAtCycleStart()};
ClearReport();
for (Key key : keys) {
AddToReport(key);
}
ExpectedKeyboardReport new_report(report_timestamp,
current_keyboard_keycodes_,
description);
expected_reports_.push_back(new_report);
}
// =============================================================================
void VirtualDeviceTest::ExpectReport(AddKeycodes added_keys,
RemoveKeycodes removed_keys,
@ -95,6 +110,9 @@ void VirtualDeviceTest::ExpectReport(RemoveKeycodes removed_keys,
}
// =============================================================================
void VirtualDeviceTest::ClearReport() {
current_keyboard_keycodes_.clear();
}
void VirtualDeviceTest::AddToReport(Key key) {
current_keyboard_keycodes_.insert(key.getKeyCode());
}

@ -43,6 +43,12 @@ class RemoveKeycodes : public std::set<Key> {
RemoveKeycodes(std::initializer_list<Key> list) : std::set<Key>(list) {}
};
class Keycodes : public std::set<Key> {
public:
Keycodes(std::initializer_list<Key> list) : std::set<Key>(list) {}
};
// -----------------------------------------------------------------------------
// The base class for testcases
class VirtualDeviceTest : public ::testing::Test {
@ -102,12 +108,14 @@ class VirtualDeviceTest : public ::testing::Test {
RemoveKeycodes removed_keys,
std::string description);
void ExpectReport(Keycodes added_keys, std::string description);
void ExpectReport(AddKeycodes added_keys, std::string description);
void ExpectReport(RemoveKeycodes removed_keys, std::string description);
// ---------------------------------------------------------------------------
std::set<uint8_t> current_keyboard_keycodes_ = {};
// Add to/remove from the set of keycodes expected in the next report
// Manage the set of keycodes expected in the next report
void ClearReport();
void AddToReport(Key key);
void RemoveFromReport(Key key);

Loading…
Cancel
Save