]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Test two keys pressed at once
authorFred Sundvik <fsundvik@gmail.com>
Sun, 18 Jun 2017 11:40:22 +0000 (14:40 +0300)
committerFred Sundvik <fsundvik@gmail.com>
Sun, 18 Jun 2017 18:22:22 +0000 (21:22 +0300)
tests/basic/test.cpp
tests/test_common/keyboard_report_util.cpp
tests/test_common/matrix.c

index 804642eae6b831a3b667acddb6c58d9c7ab4e236..398063fcaa981ebdc56631a5fd268a79b27cd2ed 100644 (file)
@@ -51,6 +51,20 @@ TEST(KeyPress, CorrectKeyIsReportedWhenPressed) {
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
     keyboard_task();
 }
-    EXPECT_CALL(driver, send_keyboard_mock(_));
+
+TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
+    TestDriver driver;
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    keyboard_init();
+    press_key(1, 0);
+    press_key(0, 1);
+    EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
+    //TODO: This is a left-over from the previous test and need to be fixed
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    keyboard_task();
+    //Note that QMK only processes one key at a time
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
+    keyboard_task();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
     keyboard_task();
 }
index 70fc1c0489c5223503d3cd47fa1e99af5225dcf1..34e53cd4cdf597be6d2c9a1dd3c24d569d34ea27 100644 (file)
  */
 
  #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;
 }
 
index 85556e2c485eb0a2d79b4a404f38f22f55f123c3..5ab5bac6c91da76533451d09b6dd00011366e862 100644 (file)
 
 #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();
 }