test_housekeeping.cpp (1957B)
1 /* Copyright 2024 leep-frog 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 "keyboard_report_util.hpp" 18 #include "keycode.h" 19 #include "test_common.hpp" 20 #include "action_tapping.h" 21 #include "test_keymap_key.hpp" 22 23 using testing::_; 24 25 class HousekeepingMock { 26 public: 27 virtual ~HousekeepingMock() {} 28 29 // mock methods 30 MOCK_METHOD0(housekeeping_task_kb, void(void)); 31 MOCK_METHOD0(housekeeping_task_user, void(void)); 32 }; 33 34 class Housekeeping : public TestFixture { 35 public: 36 Housekeeping() { 37 _housekeepingMock.reset(new ::testing::NiceMock<HousekeepingMock>()); 38 } 39 virtual ~Housekeeping() { 40 _housekeepingMock.reset(); 41 } 42 43 static std::unique_ptr<HousekeepingMock> _housekeepingMock; 44 }; 45 46 std::unique_ptr<HousekeepingMock> Housekeeping::_housekeepingMock; 47 48 extern "C" { 49 void housekeeping_task_kb(void) { 50 if (Housekeeping::_housekeepingMock) { 51 Housekeeping::_housekeepingMock->housekeeping_task_kb(); 52 } 53 } 54 55 void housekeeping_task_user(void) { 56 if (Housekeeping::_housekeepingMock) { 57 Housekeeping::_housekeepingMock->housekeeping_task_user(); 58 } 59 } 60 } 61 62 TEST_F(Housekeeping, Works) { 63 TestDriver driver; 64 65 EXPECT_CALL(*_housekeepingMock, housekeeping_task_kb()).Times(1); 66 EXPECT_CALL(*_housekeepingMock, housekeeping_task_user()).Times(1); 67 run_one_scan_loop(); 68 }