]> git.donarmstrong.com Git - qmk_firmware.git/blob - tests/test_common/test_fixture.cpp
[Keymap] Jarred's Plaid keymap (#6049)
[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 #include "action_layer.h"
11 }
12
13 extern "C" {
14     void set_time(uint32_t t);
15     void advance_time(uint32_t ms);
16 }
17
18 using testing::_;
19 using testing::AnyNumber;
20 using testing::Return;
21 using testing::Between;
22
23 void TestFixture::SetUpTestCase() {
24     TestDriver driver;
25     EXPECT_CALL(driver, send_keyboard_mock(_));
26     keyboard_init();
27 }
28
29 void TestFixture::TearDownTestCase() {
30 }
31
32 TestFixture::TestFixture() {
33 }
34
35 TestFixture::~TestFixture() {
36     TestDriver driver;
37     layer_clear();
38     clear_all_keys();
39     // Run for a while to make sure all keys are completely released
40     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
41     idle_for(TAPPING_TERM + 10);
42     testing::Mock::VerifyAndClearExpectations(&driver);
43     // Verify that the matrix really is cleared
44     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1));
45 }
46
47 void TestFixture::run_one_scan_loop() {
48     keyboard_task();
49     advance_time(1);
50 }
51
52 void TestFixture::idle_for(unsigned time) {
53     for (unsigned i=0; i<time; i++) {
54         run_one_scan_loop();
55     }
56 }