]> git.donarmstrong.com Git - qmk_firmware.git/blob - tests/test_common/test_fixture.cpp
Extended the hint of the programmer to link to the relevant README part instead of...
[qmk_firmware.git] / tests / test_common / test_fixture.cpp
1 #include "test_fixture.hpp"
2 #include "gmock/gmock.h"
3 #include "test_driver.hpp"
4 #include "test_matrix.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 }
13
14 using testing::_;
15 using testing::AnyNumber;
16 using testing::Return;
17 using testing::Between;
18
19 void TestFixture::SetUpTestCase() {
20     TestDriver driver;
21     EXPECT_CALL(driver, send_keyboard_mock(_));
22     keyboard_init();
23 }
24
25 void TestFixture::TearDownTestCase() {
26 }
27
28 TestFixture::TestFixture() {
29 }
30
31 TestFixture::~TestFixture() {
32     TestDriver driver;
33     clear_all_keys();
34     // Run for a while to make sure all keys are completely released
35     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
36     idle_for(TAPPING_TERM + 10);
37     testing::Mock::VerifyAndClearExpectations(&driver); 
38     // Verify that the matrix really is cleared
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(unsigned time) {
48     for (unsigned i=0; i<time; i++) {
49         run_one_scan_loop();
50     }
51 }