From eebf8e639b143a2154bd53fd335fdfbd07af4065 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 7 Nov 2020 15:10:05 -0800 Subject: [PATCH] Add a variant of ExpectReport that takes an explicit list of keycodes Signed-off-by: Jesse Vincent --- testing/ExpectedKeyboardReport.cpp | 4 ++-- testing/VirtualDeviceTest.cpp | 18 ++++++++++++++++++ testing/VirtualDeviceTest.h | 10 +++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/testing/ExpectedKeyboardReport.cpp b/testing/ExpectedKeyboardReport.cpp index e962d561..152a5af5 100644 --- a/testing/ExpectedKeyboardReport.cpp +++ b/testing/ExpectedKeyboardReport.cpp @@ -20,8 +20,8 @@ namespace kaleidoscope { namespace testing { ExpectedKeyboardReport::ExpectedKeyboardReport(uint32_t timestamp, - const std::set &keycodes, - std::string message) { + const std::set &keycodes, + std::string message) { timestamp_ = timestamp; keycodes_ = std::set(keycodes); failure_message_ = message; diff --git a/testing/VirtualDeviceTest.cpp b/testing/VirtualDeviceTest.cpp index 1d209faf..4ac89a35 100644 --- a/testing/VirtualDeviceTest.cpp +++ b/testing/VirtualDeviceTest.cpp @@ -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()); } diff --git a/testing/VirtualDeviceTest.h b/testing/VirtualDeviceTest.h index b6fc22aa..592df1a9 100644 --- a/testing/VirtualDeviceTest.h +++ b/testing/VirtualDeviceTest.h @@ -43,6 +43,12 @@ class RemoveKeycodes : public std::set { RemoveKeycodes(std::initializer_list list) : std::set(list) {} }; +class Keycodes : public std::set { + public: + Keycodes(std::initializer_list list) : std::set(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 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);