diff options
-rw-r--r-- | build_full_test.mk | 3 | ||||
-rw-r--r-- | tests/basic/test.cpp | 19 | ||||
-rw-r--r-- | tests/test_common/matrix.c | 6 | ||||
-rw-r--r-- | tests/test_common/test_fixture.cpp | 38 | ||||
-rw-r--r-- | tests/test_common/test_fixture.h | 28 | ||||
-rw-r--r-- | tests/test_common/test_matrix.h | 1 |
6 files changed, 80 insertions, 15 deletions
diff --git a/build_full_test.mk b/build_full_test.mk index 67c1ca5e5..bfd89174d 100644 --- a/build_full_test.mk +++ b/build_full_test.mk | |||
@@ -23,7 +23,8 @@ $(TEST)_SRC= \ | |||
23 | $(QUANTUM_SRC) \ | 23 | $(QUANTUM_SRC) \ |
24 | tests/test_common/matrix.c \ | 24 | tests/test_common/matrix.c \ |
25 | tests/test_common/test_driver.cpp \ | 25 | tests/test_common/test_driver.cpp \ |
26 | tests/test_common/keyboard_report_util.cpp | 26 | tests/test_common/keyboard_report_util.cpp \ |
27 | tests/test_common/test_fixture.cpp | ||
27 | $(TEST)_DEFS=$(TMK_COMMON_DEFS) | 28 | $(TEST)_DEFS=$(TMK_COMMON_DEFS) |
28 | $(TEST)_CONFIG=$(TEST_PATH)/config.h | 29 | $(TEST)_CONFIG=$(TEST_PATH)/config.h |
29 | VPATH+=$(TOP_DIR)/tests/test_common | 30 | VPATH+=$(TOP_DIR)/tests/test_common |
diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 398063fca..26a09585c 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp | |||
@@ -18,10 +18,10 @@ | |||
18 | #include "gmock/gmock.h" | 18 | #include "gmock/gmock.h" |
19 | 19 | ||
20 | #include "quantum.h" | 20 | #include "quantum.h" |
21 | #include "keyboard.h" | ||
22 | #include "test_driver.h" | 21 | #include "test_driver.h" |
23 | #include "test_matrix.h" | 22 | #include "test_matrix.h" |
24 | #include "keyboard_report_util.h" | 23 | #include "keyboard_report_util.h" |
24 | #include "test_fixture.h" | ||
25 | 25 | ||
26 | using testing::_; | 26 | using testing::_; |
27 | using testing::Return; | 27 | using testing::Return; |
@@ -33,35 +33,28 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
33 | }, | 33 | }, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { | 36 | class KeyPress : public TestFixture {}; |
37 | |||
38 | TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { | ||
37 | TestDriver driver; | 39 | TestDriver driver; |
38 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
39 | keyboard_init(); | ||
40 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); | 40 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); |
41 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | 41 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); |
42 | keyboard_task(); | 42 | keyboard_task(); |
43 | } | 43 | } |
44 | 44 | ||
45 | TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { | 45 | TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { |
46 | TestDriver driver; | 46 | TestDriver driver; |
47 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
48 | keyboard_init(); | ||
49 | press_key(0, 0); | 47 | press_key(0, 0); |
50 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); | 48 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); |
51 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); | 49 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); |
52 | keyboard_task(); | 50 | keyboard_task(); |
53 | } | 51 | } |
54 | 52 | ||
55 | TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { | 53 | TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { |
56 | TestDriver driver; | 54 | TestDriver driver; |
57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
58 | keyboard_init(); | ||
59 | press_key(1, 0); | 55 | press_key(1, 0); |
60 | press_key(0, 1); | 56 | press_key(0, 1); |
61 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); | 57 | 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 | 58 | //Note that QMK only processes one key at a time |
66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); | 59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); |
67 | keyboard_task(); | 60 | keyboard_task(); |
diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 5ab5bac6c..0d9fa68b0 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c | |||
@@ -22,7 +22,7 @@ | |||
22 | static matrix_row_t matrix[MATRIX_ROWS] = {}; | 22 | static matrix_row_t matrix[MATRIX_ROWS] = {}; |
23 | 23 | ||
24 | void matrix_init(void) { | 24 | void matrix_init(void) { |
25 | memset(matrix, 0, sizeof(matrix)); | 25 | clear_all_keys(); |
26 | matrix_init_quantum(); | 26 | matrix_init_quantum(); |
27 | } | 27 | } |
28 | 28 | ||
@@ -54,3 +54,7 @@ void press_key(uint8_t col, uint8_t row) { | |||
54 | void release_key(uint8_t col, uint8_t row) { | 54 | void release_key(uint8_t col, uint8_t row) { |
55 | matrix[row] &= ~(1 << col); | 55 | matrix[row] &= ~(1 << col); |
56 | } | 56 | } |
57 | |||
58 | void clear_all_keys(void) { | ||
59 | memset(matrix, 0, sizeof(matrix)); | ||
60 | } | ||
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp new file mode 100644 index 000000000..aff518d21 --- /dev/null +++ b/tests/test_common/test_fixture.cpp | |||
@@ -0,0 +1,38 @@ | |||
1 | #include "test_fixture.h" | ||
2 | #include "gmock/gmock.h" | ||
3 | #include "test_driver.h" | ||
4 | #include "test_matrix.h" | ||
5 | #include "keyboard.h" | ||
6 | |||
7 | using testing::_; | ||
8 | using testing::AnyNumber; | ||
9 | using testing::Return; | ||
10 | using testing::Between; | ||
11 | |||
12 | void TestFixture::SetUpTestCase() { | ||
13 | TestDriver driver; | ||
14 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
15 | keyboard_init(); | ||
16 | } | ||
17 | |||
18 | void TestFixture::TearDownTestCase() { | ||
19 | } | ||
20 | |||
21 | TestFixture::TestFixture() { | ||
22 | } | ||
23 | |||
24 | TestFixture::~TestFixture() { | ||
25 | TestDriver driver; | ||
26 | clear_all_keys(); | ||
27 | // 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()); | ||
30 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); | ||
31 | for (int i=0; i<100; i++) { | ||
32 | keyboard_task(); | ||
33 | } | ||
34 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
35 | // Verify that the matrix really is cleared | ||
36 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); | ||
37 | EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); | ||
38 | } \ No newline at end of file | ||
diff --git a/tests/test_common/test_fixture.h b/tests/test_common/test_fixture.h new file mode 100644 index 000000000..a775a425a --- /dev/null +++ b/tests/test_common/test_fixture.h | |||
@@ -0,0 +1,28 @@ | |||
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 | #pragma once | ||
18 | |||
19 | #include "gtest/gtest.h" | ||
20 | |||
21 | class TestFixture : public testing::Test { | ||
22 | public: | ||
23 | TestFixture(); | ||
24 | ~TestFixture(); | ||
25 | static void SetUpTestCase(); | ||
26 | static void TearDownTestCase(); | ||
27 | |||
28 | }; \ No newline at end of file | ||
diff --git a/tests/test_common/test_matrix.h b/tests/test_common/test_matrix.h index afc65c556..174fc4f22 100644 --- a/tests/test_common/test_matrix.h +++ b/tests/test_common/test_matrix.h | |||
@@ -23,6 +23,7 @@ extern "C" { | |||
23 | 23 | ||
24 | void press_key(uint8_t col, uint8_t row); | 24 | void press_key(uint8_t col, uint8_t row); |
25 | void release_key(uint8_t col, uint8_t row); | 25 | void release_key(uint8_t col, uint8_t row); |
26 | void clear_all_keys(void); | ||
26 | 27 | ||
27 | #ifdef __cplusplus | 28 | #ifdef __cplusplus |
28 | } | 29 | } |