summaryrefslogtreecommitdiffstats
path: root/tests/test_common/keyboard_report_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_common/keyboard_report_util.cpp')
-rw-r--r--tests/test_common/keyboard_report_util.cpp45
1 files changed, 39 insertions, 6 deletions
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp
index 7908e64f7f..2de1af2301 100644
--- a/tests/test_common/keyboard_report_util.cpp
+++ b/tests/test_common/keyboard_report_util.cpp
@@ -15,11 +15,16 @@
*/
#include "keyboard_report_util.hpp"
+#include <cstdint>
#include <vector>
#include <algorithm>
+
using namespace testing;
+extern std::map<uint16_t, std::string> KEYCODE_ID_TABLE;
+
namespace {
+
std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
std::vector<uint8_t> result;
#if defined(NKRO_ENABLE)
@@ -36,6 +41,19 @@ std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
std::sort(result.begin(), result.end());
return result;
}
+
+std::vector<uint8_t> get_mods(const report_keyboard_t& report) {
+ std::vector<uint8_t> result;
+ for (size_t i = 0; i < 8; i++) {
+ if (report.mods & (1 << i)) {
+ uint8_t code = KC_LEFT_CTRL + i;
+ result.emplace_back(code);
+ }
+ }
+ std::sort(result.begin(), result.end());
+ return result;
+}
+
} // namespace
bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
@@ -44,21 +62,36 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
return lhs.mods == rhs.mods && lhskeys == rhskeys;
}
-std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& report) {
+std::ostream& operator<<(std::ostream& os, const report_keyboard_t& report) {
auto keys = get_keys(report);
+ auto mods = get_mods(report);
- // TODO: This should probably print friendly names for the keys
- stream << "Keyboard Report: Mods (" << (uint32_t)report.mods << ") Keys (";
+ os << std::setw(10) << std::left << "report: ";
+
+ if (!keys.size() && !mods.size()) {
+ return os << "empty" << std::endl;
+ }
+ os << "(";
for (auto key = keys.cbegin(); key != keys.cend();) {
- stream << +(*key);
+ os << KEYCODE_ID_TABLE.at(*key);
key++;
if (key != keys.cend()) {
- stream << ",";
+ os << ", ";
+ }
+ }
+
+ os << ") [";
+
+ for (auto mod = mods.cbegin(); mod != mods.cend();) {
+ os << KEYCODE_ID_TABLE.at(*mod);
+ mod++;
+ if (mod != mods.cend()) {
+ os << ", ";
}
}
- return stream << ")" << std::endl;
+ return os << "]" << std::endl;
}
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {