diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2017-06-18 14:40:22 +0300 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2017-06-18 21:22:22 +0300 |
commit | e85b1857968d4c0378b9778650c30b9d2bca3ea9 (patch) | |
tree | ec6de5be2bcf71e44a3ba83c87bc15363d51edc6 /tests/test_common/keyboard_report_util.cpp | |
parent | 6a76192fa4bb8c5757c32cf3c65c4e7e7f6c7c3e (diff) | |
download | qmk_firmware-e85b1857968d4c0378b9778650c30b9d2bca3ea9.tar.gz qmk_firmware-e85b1857968d4c0378b9778650c30b9d2bca3ea9.zip |
Test two keys pressed at once
Diffstat (limited to 'tests/test_common/keyboard_report_util.cpp')
-rw-r--r-- | tests/test_common/keyboard_report_util.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index 70fc1c048..34e53cd4c 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp | |||
@@ -15,15 +15,41 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "keyboard_report_util.h" | 17 | #include "keyboard_report_util.h" |
18 | #include <vector> | ||
19 | #include <algorithm> | ||
18 | using namespace testing; | 20 | using namespace testing; |
19 | 21 | ||
22 | namespace | ||
23 | { | ||
24 | std::vector<uint8_t> get_keys(const report_keyboard_t& report) { | ||
25 | std::vector<uint8_t> result; | ||
26 | #if defined(NKRO_ENABLE) | ||
27 | #error NKRO support not implemented yet | ||
28 | #elif defined(USB_6KRO_ENABLE) | ||
29 | #error 6KRO support not implemented yet | ||
30 | #else | ||
31 | for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) { | ||
32 | if (report.keys[i]) { | ||
33 | result.emplace_back(report.keys[i]); | ||
34 | } | ||
35 | } | ||
36 | #endif | ||
37 | std::sort(result.begin(), result.end()); | ||
38 | return result; | ||
39 | } | ||
40 | } | ||
41 | |||
20 | bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { | 42 | bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { |
21 | return memcmp(lhs.raw, rhs.raw, sizeof(lhs.raw))==0; | 43 | auto lhskeys = get_keys(lhs); |
44 | auto rhskeys = get_keys(rhs); | ||
45 | return lhs.mods == rhs.mods && lhskeys == rhskeys; | ||
22 | } | 46 | } |
23 | 47 | ||
24 | std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { | 48 | std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { |
25 | stream << "Keyboard report:" << std::endl; | 49 | stream << "Keyboard report:" << std::endl; |
26 | stream << (uint32_t)value.keys[0] << std::endl; | 50 | for (uint32_t k: get_keys(value)) { |
51 | stream << k << std::endl; | ||
52 | } | ||
27 | return stream; | 53 | return stream; |
28 | } | 54 | } |
29 | 55 | ||