aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/basic/test.cpp16
-rw-r--r--tests/test_common/keyboard_report_util.cpp30
-rw-r--r--tests/test_common/matrix.c2
3 files changed, 45 insertions, 3 deletions
diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp
index 804642eae..398063fca 100644
--- a/tests/basic/test.cpp
+++ b/tests/basic/test.cpp
@@ -51,6 +51,20 @@ TEST(KeyPress, CorrectKeyIsReportedWhenPressed) {
51 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); 51 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
52 keyboard_task(); 52 keyboard_task();
53} 53}
54 EXPECT_CALL(driver, send_keyboard_mock(_)); 54
55TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
56 TestDriver driver;
57 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
58 keyboard_init();
59 press_key(1, 0);
60 press_key(0, 1);
61 EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
62 //TODO: This is a left-over from the previous test and need to be fixed
63 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
64 keyboard_task();
65 //Note that QMK only processes one key at a time
66 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
67 keyboard_task();
68 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
55 keyboard_task(); 69 keyboard_task();
56} 70}
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
20bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { 42bool 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
24std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { 48std::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
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 @@
17 17
18#include "matrix.h" 18#include "matrix.h"
19#include "test_matrix.h" 19#include "test_matrix.h"
20#include <string.h>
20 21
21static matrix_row_t matrix[MATRIX_ROWS] = {}; 22static matrix_row_t matrix[MATRIX_ROWS] = {};
22 23
23void matrix_init(void) { 24void matrix_init(void) {
25 memset(matrix, 0, sizeof(matrix));
24 matrix_init_quantum(); 26 matrix_init_quantum();
25} 27}
26 28