aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basic/config.h1
-rw-r--r--tests/basic/keymap.c10
-rw-r--r--tests/basic/keypress.cpp9
-rw-r--r--tests/basic/tapping.cpp96
-rw-r--r--tests/test_common/test_common.h24
-rw-r--r--tests/test_common/test_fixture.cpp23
-rw-r--r--tests/test_common/test_fixture.h2
7 files changed, 147 insertions, 18 deletions
diff --git a/tests/basic/config.h b/tests/basic/config.h
index a52d8a4fa..e5d018a32 100644
--- a/tests/basic/config.h
+++ b/tests/basic/config.h
@@ -20,5 +20,4 @@
20#define MATRIX_ROWS 4 20#define MATRIX_ROWS 4
21#define MATRIX_COLS 10 21#define MATRIX_COLS 10
22 22
23
24#endif /* TESTS_BASIC_CONFIG_H_ */ 23#endif /* TESTS_BASIC_CONFIG_H_ */
diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c
index e3a60ccc4..358cbdb59 100644
--- a/tests/basic/keymap.c
+++ b/tests/basic/keymap.c
@@ -23,10 +23,10 @@
23 23
24const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 24const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
25 [0] = { 25 [0] = {
26 // 0 1 2 3 4 5 6 7 8 9 26 // 0 1 2 3 4 5 6 7 8 9
27 {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, KC_NO, KC_NO, KC_NO}, 27 {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), KC_NO, KC_NO},
28 {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, 28 {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
29 {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, 29 {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
30 {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, 30 {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
31 }, 31 },
32}; 32};
diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp
index 2bb029d88..2323b7cb4 100644
--- a/tests/basic/keypress.cpp
+++ b/tests/basic/keypress.cpp
@@ -14,14 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16 16
17#include "gtest/gtest.h" 17#include "test_common.h"
18#include "gmock/gmock.h"
19
20#include "quantum.h"
21#include "test_driver.h"
22#include "test_matrix.h"
23#include "keyboard_report_util.h"
24#include "test_fixture.h"
25 18
26using testing::_; 19using testing::_;
27using testing::Return; 20using testing::Return;
diff --git a/tests/basic/tapping.cpp b/tests/basic/tapping.cpp
new file mode 100644
index 000000000..c158e1718
--- /dev/null
+++ b/tests/basic/tapping.cpp
@@ -0,0 +1,96 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "test_common.h"
18#include "action_tapping.h"
19
20using testing::_;
21using testing::InSequence;
22
23class Tapping : public TestFixture {};
24
25TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
26 TestDriver driver;
27 InSequence s;
28
29 press_key(7, 0);
30 // Tapping keys does nothing on press
31 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
32 run_one_scan_loop();
33 release_key(7, 0);
34 // First we get the key press
35 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
36 // Then the release
37 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
38 run_one_scan_loop();
39}
40
41TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
42 TestDriver driver;
43 InSequence s;
44
45 press_key(7, 0);
46 // Tapping keys does nothing on press
47 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
48 idle_for(TAPPING_TERM);
49 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
50 run_one_scan_loop();
51}
52
53TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
54 TestDriver driver;
55 InSequence s;
56
57 press_key(7, 0);
58 // Tapping keys does nothing on press
59 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
60 run_one_scan_loop();
61 release_key(7, 0);
62 // First we get the key press
63 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
64 // Then the release
65 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
66 run_one_scan_loop();
67
68 // This sends KC_P, even if it should do nothing
69 press_key(7, 0);
70 // This test should not succed if everything works correctly
71 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
72 run_one_scan_loop();
73 release_key(7, 0);
74 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
75 idle_for(TAPPING_TERM + 1);
76
77 // On the other hand, nothing is sent if we are outside the tapping term
78 press_key(7, 0);
79 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
80 run_one_scan_loop();
81 release_key(7, 0);
82
83 // First we get the key press
84 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
85 // Then the release
86 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
87 idle_for(TAPPING_TERM + 1);
88
89 // Now we are geting into strange territory, as the hold registers too early here
90 // But the stranges part is:
91 // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't
92 press_key(7, 0);
93 // Shouldn't be called here really
94 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1);
95 idle_for(TAPPING_TERM);
96}
diff --git a/tests/test_common/test_common.h b/tests/test_common/test_common.h
new file mode 100644
index 000000000..38eb0ed93
--- /dev/null
+++ b/tests/test_common/test_common.h
@@ -0,0 +1,24 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "gtest/gtest.h"
18#include "gmock/gmock.h"
19
20#include "quantum.h"
21#include "test_driver.h"
22#include "test_matrix.h"
23#include "keyboard_report_util.h"
24#include "test_fixture.h" \ No newline at end of file
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp
index eef9b854b..5ca5247db 100644
--- a/tests/test_common/test_fixture.cpp
+++ b/tests/test_common/test_fixture.cpp
@@ -3,6 +3,13 @@
3#include "test_driver.h" 3#include "test_driver.h"
4#include "test_matrix.h" 4#include "test_matrix.h"
5#include "keyboard.h" 5#include "keyboard.h"
6#include "action.h"
7#include "action_tapping.h"
8
9extern "C" {
10 void set_time(uint32_t t);
11 void advance_time(uint32_t ms);
12}
6 13
7using testing::_; 14using testing::_;
8using testing::AnyNumber; 15using testing::AnyNumber;
@@ -25,12 +32,20 @@ TestFixture::~TestFixture() {
25 TestDriver driver; 32 TestDriver driver;
26 clear_all_keys(); 33 clear_all_keys();
27 // Run for a while to make sure all keys are completely released 34 // Run for a while to make sure all keys are completely released
28 // Should probably wait until tapping term etc, has timed out
29 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); 35 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
30 for (int i=0; i<100; i++) { 36 idle_for(TAPPING_TERM + 10);
31 keyboard_task();
32 }
33 testing::Mock::VerifyAndClearExpectations(&driver); 37 testing::Mock::VerifyAndClearExpectations(&driver);
34 // Verify that the matrix really is cleared 38 // Verify that the matrix really is cleared
35 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); 39 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1));
40}
41
42void TestFixture::run_one_scan_loop() {
43 keyboard_task();
44 advance_time(1);
45}
46
47void TestFixture::idle_for(uint time) {
48 for (uint i=0; i<time; i++) {
49 run_one_scan_loop();
50 }
36} \ No newline at end of file 51} \ No newline at end of file
diff --git a/tests/test_common/test_fixture.h b/tests/test_common/test_fixture.h
index a775a425a..4146b682b 100644
--- a/tests/test_common/test_fixture.h
+++ b/tests/test_common/test_fixture.h
@@ -25,4 +25,6 @@ public:
25 static void SetUpTestCase(); 25 static void SetUpTestCase();
26 static void TearDownTestCase(); 26 static void TearDownTestCase();
27 27
28 void run_one_scan_loop();
29 void idle_for(uint ms);
28}; \ No newline at end of file 30}; \ No newline at end of file