diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2017-07-01 22:25:06 +0300 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-07-08 21:59:51 -0400 |
| commit | 4e69a8bda6c4003c6b9e33de7db89fe073c970f5 (patch) | |
| tree | 8a01b6dde0195d574686fdd2f9cd1da61b3aa8dc /tests/test_common | |
| parent | a62f4496599d4a1880adc5f272f97f81be0586cb (diff) | |
| download | qmk_firmware-4e69a8bda6c4003c6b9e33de7db89fe073c970f5.tar.gz qmk_firmware-4e69a8bda6c4003c6b9e33de7db89fe073c970f5.zip | |
Add basic timing support, and SFT_T tests
Also expose some bugs...
Diffstat (limited to 'tests/test_common')
| -rw-r--r-- | tests/test_common/test_common.h | 24 | ||||
| -rw-r--r-- | tests/test_common/test_fixture.cpp | 23 | ||||
| -rw-r--r-- | tests/test_common/test_fixture.h | 2 |
3 files changed, 45 insertions, 4 deletions
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 | |||
| 9 | extern "C" { | ||
| 10 | void set_time(uint32_t t); | ||
| 11 | void advance_time(uint32_t ms); | ||
| 12 | } | ||
| 6 | 13 | ||
| 7 | using testing::_; | 14 | using testing::_; |
| 8 | using testing::AnyNumber; | 15 | using 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 | |||
| 42 | void TestFixture::run_one_scan_loop() { | ||
| 43 | keyboard_task(); | ||
| 44 | advance_time(1); | ||
| 45 | } | ||
| 46 | |||
| 47 | void 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 |
