test_invertxy.cpp (1552B)
1 // Copyright 2024 Dasky (@daskygit) 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 4 #include "gtest/gtest.h" 5 #include "mouse_report_util.hpp" 6 #include "test_common.hpp" 7 #include "test_pointing_device_driver.h" 8 9 using testing::_; 10 11 struct SimpleReport { 12 int16_t x; 13 int16_t y; 14 int16_t h; 15 int16_t v; 16 }; 17 18 class Pointing : public TestFixture {}; 19 class PointingInvertXYParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {}; 20 21 TEST_P(PointingInvertXYParametrized, PointingInvertXY) { 22 TestDriver driver; 23 SimpleReport input = GetParam().first; 24 SimpleReport expectations = GetParam().second; 25 26 pd_set_x(input.x); 27 pd_set_y(input.y); 28 pd_set_h(input.h); 29 pd_set_v(input.v); 30 31 EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); 32 run_one_scan_loop(); 33 34 // EXPECT_EMPTY_MOUSE_REPORT(driver); 35 pd_clear_movement(); 36 run_one_scan_loop(); 37 38 EXPECT_NO_MOUSE_REPORT(driver); 39 run_one_scan_loop(); 40 41 VERIFY_AND_CLEAR(driver); 42 } 43 // clang-format off 44 INSTANTIATE_TEST_CASE_P( 45 X_Y_XY, 46 PointingInvertXYParametrized, 47 ::testing::Values( 48 // Input Expected 49 std::make_pair(SimpleReport{ 33, 0, 0, 0}, SimpleReport{ -33, 0, 0, 0}), 50 std::make_pair(SimpleReport{ 0, -127, 0, 0}, SimpleReport{ 0, 127, 0, 0}), 51 std::make_pair(SimpleReport{ 10, -20, 0, 0}, SimpleReport{ -10, 20, 0, 0}) 52 )); 53 // clang-format on