summary refs log tree commit diff
path: root/tests/basic
diff options
context:
space:
mode:
authorFabian Topfstedt <topfstedt@schneevonmorgen.com>2017-07-20 08:22:44 +0200
committerFabian Topfstedt <topfstedt@schneevonmorgen.com>2017-07-20 08:22:44 +0200
commitee43856ff7ba37ea89d1a8a4700efba4e4f69571 (patch)
treeb0ed5b538396b0b2b027e69ad8ceac443c067c79 /tests/basic
parent99b6e918eab31d4f53cabc04a995da945335ac7f (diff)
parent14c5160b1a94d5dc416002791b3c207ba0dca789 (diff)
Merge https://github.com/qmk/qmk_firmware
Diffstat (limited to 'tests/basic')
-rw-r--r--tests/basic/config.h5
-rw-r--r--tests/basic/keymap.c46
-rw-r--r--tests/basic/test.cpp60
-rw-r--r--tests/basic/test_keypress.cpp124
-rw-r--r--tests/basic/test_macro.cpp99
-rw-r--r--tests/basic/test_tapping.cpp97
6 files changed, 368 insertions, 63 deletions
diff --git a/tests/basic/config.h b/tests/basic/config.h
index 4da8d04253..e5d018a32a 100644
--- a/tests/basic/config.h
+++ b/tests/basic/config.h
@@ -17,8 +17,7 @@
 #ifndef TESTS_BASIC_CONFIG_H_
 #define TESTS_BASIC_CONFIG_H_
 
-#define MATRIX_ROWS 2
-#define MATRIX_COLS 2
-
+#define MATRIX_ROWS 4
+#define MATRIX_COLS 10
 
 #endif /* TESTS_BASIC_CONFIG_H_ */
diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c
new file mode 100644
index 0000000000..3f97c0a0ee
--- /dev/null
+++ b/tests/basic/keymap.c
@@ -0,0 +1,46 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "quantum.h"
+
+// Don't rearrange keys as existing tests might rely on the order
+// Col2, Row 0 has to be KC_NO, because tests rely on it
+
+#define COMBO1 RSFT(LCTL(KC_O))
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+    [0] = {
+        // 0    1      2      3        4        5        6       7            8      9
+        {KC_A,  KC_B,  KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0),  KC_NO},
+        {KC_NO, KC_NO, KC_NO, KC_NO,   KC_NO,   KC_NO,   KC_NO,  KC_NO,       KC_NO, KC_NO},
+        {KC_NO, KC_NO, KC_NO, KC_NO,   KC_NO,   KC_NO,   KC_NO,  KC_NO,       KC_NO, KC_NO},
+        {KC_C,  KC_D,  KC_NO, KC_NO,   KC_NO,   KC_NO,   KC_NO,  KC_NO,       KC_NO, KC_NO},
+    },
+};
+
+const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
+    if (record->event.pressed) {
+        switch(id) {
+        case 0:
+            return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), 
+            D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END);
+        }
+    }
+    return MACRO_NONE;
+};
+
+void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
+}
\ No newline at end of file
diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp
deleted file mode 100644
index 1bd5c2762d..0000000000
--- a/tests/basic/test.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Copyright 2017 Fred Sundvik
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gtest/gtest.h"
-#include "gmock/gmock.h"
-
-#include "quantum.h"
-#include "test_driver.h"
-#include "test_matrix.h"
-#include "keyboard_report_util.h"
-#include "test_fixture.h"
-
-using testing::_;
-using testing::Return;
-
-const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
-	[0] = {
-	    {KC_A, KC_B},
-	    {KC_C, KC_D}
-	},
-};
-
-class KeyPress : public TestFixture {};
-
-TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
-    TestDriver driver;
-    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
-    keyboard_task();
-}
-
-TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
-    TestDriver driver;
-    press_key(0, 0);
-    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
-    keyboard_task();
-}
-
-TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
-    TestDriver driver;
-    press_key(1, 0);
-    press_key(0, 1);
-    //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();
-}
diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp
new file mode 100644
index 0000000000..194b1745b1
--- /dev/null
+++ b/tests/basic/test_keypress.cpp
@@ -0,0 +1,124 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test_common.hpp"
+
+using testing::_;
+using testing::Return;
+
+class KeyPress : public TestFixture {};
+
+TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
+    TestDriver driver;
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+    keyboard_task();
+}
+
+TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
+    TestDriver driver;
+    press_key(0, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
+    keyboard_task();
+    release_key(0, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    keyboard_task();
+}
+
+TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
+    TestDriver driver;
+    press_key(1, 0);
+    press_key(0, 3);
+    //Note that QMK only processes one key at a time
+    //See issue #1476 for more information
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
+    keyboard_task();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
+    keyboard_task();
+    release_key(1, 0);
+    release_key(0, 3);
+    //Note that the first key released is the first one in the matrix order
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
+    keyboard_task();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    keyboard_task();
+}
+
+TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
+    TestDriver driver;
+    press_key(2, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+    keyboard_task();
+    keyboard_task();
+}
+
+TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
+    TestDriver driver;
+    press_key(3, 0);
+    press_key(0, 0);
+    // Unfortunately modifiers are also processed in the wrong order
+    // See issue #1476 for more information
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
+    keyboard_task();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT)));
+    keyboard_task();
+    release_key(0, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
+    keyboard_task();
+    release_key(3, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    keyboard_task();
+}
+
+TEST_F(KeyPress, PressLeftShiftAndControl) {
+    TestDriver driver;
+    press_key(3, 0);
+    press_key(5, 0);
+    // Unfortunately modifiers are also processed in the wrong order
+    // See issue #1476 for more information
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
+    keyboard_task();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL)));
+    keyboard_task();
+}
+
+TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) {
+    TestDriver driver;
+    press_key(3, 0);
+    press_key(4, 0);
+    // Unfortunately modifiers are also processed in the wrong order
+    // See issue #1476 for more information
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
+    keyboard_task();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT)));
+    keyboard_task();
+}
+
+TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
+    TestDriver driver;
+    press_key(6, 0);
+    // BUG: The press is split into two reports
+    // BUG: It reports RSFT instead of LSFT
+    // See issue #524 for more information
+    // The underlying cause is that we use only one bit to represent the right hand
+    // modifiers.
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O)));
+    keyboard_task();
+    release_key(6, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    keyboard_task();
+}
\ No newline at end of file
diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp
new file mode 100644
index 0000000000..80676d5153
--- /dev/null
+++ b/tests/basic/test_macro.cpp
@@ -0,0 +1,99 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test_common.hpp"
+#include "time.h"
+
+using testing::InSequence;
+using testing::InvokeWithoutArgs;
+
+class Macro : public TestFixture {};
+
+#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() {EXPECT_EQ(timer_elapsed32(current_time), t);}))
+
+TEST_F(Macro, PlayASimpleMacro) {
+    TestDriver driver;
+    InSequence s;
+    press_key(8, 0);
+    uint32_t current_time = timer_read32();
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_H)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)))
+        .AT_TIME(0);
+    // The macro system could actually skip these empty keyboard reports
+    // it should be enough to just send a report with the next key down
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE)))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
+        .AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_W)))
+        .AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
+        .AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(100);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
+    // BUG: The timer should not really have advanced 10 ms here
+    // See issue #1477
+        .AT_TIME(110);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+    // BUG: The timer should not advance on both keydown and key-up
+    // See issue #1477
+        .AT_TIME(120);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)))
+        .AT_TIME(130);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(140);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
+        .AT_TIME(150);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(160);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D)))
+        .AT_TIME(170);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(180);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
+        .AT_TIME(190);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_1)))
+        .AT_TIME(200);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
+        .AT_TIME(210);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
+        .AT_TIME(220);
+    run_one_scan_loop();
+}
\ No newline at end of file
diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp
new file mode 100644
index 0000000000..30d032e9fd
--- /dev/null
+++ b/tests/basic/test_tapping.cpp
@@ -0,0 +1,97 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test_common.hpp"
+#include "action_tapping.h"
+
+using testing::_;
+using testing::InSequence;
+
+class Tapping : public TestFixture {};
+
+TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
+    TestDriver driver;
+    InSequence s;
+
+    press_key(7, 0);
+    // Tapping keys does nothing on press
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+    run_one_scan_loop();
+    release_key(7, 0);
+    // First we get the key press
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
+    // Then the release
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    run_one_scan_loop();
+}
+
+TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
+    TestDriver driver;
+    InSequence s;
+
+    press_key(7, 0);
+    // Tapping keys does nothing on press
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+    idle_for(TAPPING_TERM);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
+    run_one_scan_loop();
+}
+
+TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
+    // See issue #1478 for more information
+    TestDriver driver;
+    InSequence s;
+
+    press_key(7, 0);
+    // Tapping keys does nothing on press
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+    run_one_scan_loop();
+    release_key(7, 0);
+    // First we get the key press
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
+    // Then the release
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    run_one_scan_loop();
+
+    // This sends KC_P, even if it should do nothing
+    press_key(7, 0);
+    // This test should not succed if everything works correctly
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
+    run_one_scan_loop();
+    release_key(7, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    idle_for(TAPPING_TERM + 1);
+
+    // On the other hand, nothing is sent if we are outside the tapping term
+    press_key(7, 0);
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+    run_one_scan_loop();
+    release_key(7, 0);
+
+    // First we get the key press
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
+    // Then the release
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
+    idle_for(TAPPING_TERM + 1);
+
+    // Now we are geting into strange territory, as the hold registers too early here
+    // But the stranges part is:
+    // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't
+    press_key(7, 0);
+    // Shouldn't be called here really
+    EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1);
+    idle_for(TAPPING_TERM);
+}