aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_common
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-06-18 14:40:22 +0300
committerFred Sundvik <fsundvik@gmail.com>2017-06-18 21:22:22 +0300
commite85b1857968d4c0378b9778650c30b9d2bca3ea9 (patch)
treeec6de5be2bcf71e44a3ba83c87bc15363d51edc6 /tests/test_common
parent6a76192fa4bb8c5757c32cf3c65c4e7e7f6c7c3e (diff)
downloadfirmware-e85b1857968d4c0378b9778650c30b9d2bca3ea9.tar.gz
firmware-e85b1857968d4c0378b9778650c30b9d2bca3ea9.tar.bz2
firmware-e85b1857968d4c0378b9778650c30b9d2bca3ea9.zip
Test two keys pressed at once
Diffstat (limited to 'tests/test_common')
-rw-r--r--tests/test_common/keyboard_report_util.cpp30
-rw-r--r--tests/test_common/matrix.c2
2 files changed, 30 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 @@
*/
#include "keyboard_report_util.h"
+ #include <vector>
+ #include <algorithm>
using namespace testing;
+ namespace
+ {
+ std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
+ std::vector<uint8_t> result;
+ #if defined(NKRO_ENABLE)
+ #error NKRO support not implemented yet
+ #elif defined(USB_6KRO_ENABLE)
+ #error 6KRO support not implemented yet
+ #else
+ for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) {
+ if (report.keys[i]) {
+ result.emplace_back(report.keys[i]);
+ }
+ }
+ #endif
+ std::sort(result.begin(), result.end());
+ return result;
+ }
+ }
+
bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
- return memcmp(lhs.raw, rhs.raw, sizeof(lhs.raw))==0;
+ auto lhskeys = get_keys(lhs);
+ auto rhskeys = get_keys(rhs);
+ return lhs.mods == rhs.mods && lhskeys == rhskeys;
}
std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
stream << "Keyboard report:" << std::endl;
- stream << (uint32_t)value.keys[0] << std::endl;
+ for (uint32_t k: get_keys(value)) {
+ stream << k << std::endl;
+ }
return stream;
}
diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c
index 85556e2c4..5ab5bac6c 100644
--- a/tests/test_common/matrix.c
+++ b/tests/test_common/matrix.c
@@ -17,10 +17,12 @@
#include "matrix.h"
#include "test_matrix.h"
+#include <string.h>
static matrix_row_t matrix[MATRIX_ROWS] = {};
void matrix_init(void) {
+ memset(matrix, 0, sizeof(matrix));
matrix_init_quantum();
}