From ab0029e2b8830dd780a00a8795c32586e605474a Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Thu, 24 Oct 2024 00:08:16 +0100 Subject: [PATCH] rework pointing driver and update tests --- tests/pointing/invertxy/test_invertxy.cpp | 24 ++-- tests/pointing/rotate180/test_rotate180.cpp | 18 +-- tests/pointing/rotate270/test_rotate270.cpp | 18 +-- tests/pointing/rotate90/test_rotate90.cpp | 18 +-- tests/pointing/test_pointing.cpp | 80 ++++++------- tests/test_common/pointing_device_driver.c | 106 ++++++++++-------- .../test_common/test_pointing_device_driver.h | 24 ++-- 7 files changed, 149 insertions(+), 139 deletions(-) diff --git a/tests/pointing/invertxy/test_invertxy.cpp b/tests/pointing/invertxy/test_invertxy.cpp index e8b9409007b..014f6f3cd03 100644 --- a/tests/pointing/invertxy/test_invertxy.cpp +++ b/tests/pointing/invertxy/test_invertxy.cpp @@ -16,23 +16,23 @@ struct SimpleReport { }; class Pointing : public TestFixture {}; -class PointingInvertXYParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; +class PointingInvertXYParametrized : public ::testing::WithParamInterface>, public Pointing {}; -TEST_P(PointingInvertXYParametrizedTestFixture, PointingMouseKeysViaPointingDriver) { +TEST_P(PointingInvertXYParametrized, PointingInvertXY) { TestDriver driver; SimpleReport input = GetParam().first; SimpleReport expectations = GetParam().second; - set_x(input.x); - set_y(input.y); - set_h(input.h); - set_v(input.v); + pd_set_x(input.x); + pd_set_y(input.y); + pd_set_h(input.h); + pd_set_v(input.v); EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); run_one_scan_loop(); // EXPECT_EMPTY_MOUSE_REPORT(driver); - clear_movement(); + pd_clear_movement(); run_one_scan_loop(); EXPECT_NO_MOUSE_REPORT(driver); @@ -42,12 +42,12 @@ TEST_P(PointingInvertXYParametrizedTestFixture, PointingMouseKeysViaPointingDriv } // clang-format off INSTANTIATE_TEST_CASE_P( - PointingInvertXYTests, - PointingInvertXYParametrizedTestFixture, + X_Y_XY, + PointingInvertXYParametrized, ::testing::Values( // Input Expected - std::make_pair(SimpleReport{ 33, 0, 0, 0}, SimpleReport{ -33, 0, 0, 0}), - std::make_pair(SimpleReport{ 0, -127, 0, 0}, SimpleReport{ 0, 127, 0, 0}), - std::make_pair(SimpleReport{ 10, -20, 0, 0}, SimpleReport{ -10, 20, 0, 0}) + std::make_pair(SimpleReport{ 33, 0, 0, 0}, SimpleReport{ -33, 0, 0, 0}), + std::make_pair(SimpleReport{ 0, -127, 0, 0}, SimpleReport{ 0, 127, 0, 0}), + std::make_pair(SimpleReport{ 10, -20, 0, 0}, SimpleReport{ -10, 20, 0, 0}) )); // clang-format on diff --git a/tests/pointing/rotate180/test_rotate180.cpp b/tests/pointing/rotate180/test_rotate180.cpp index 11318ef5482..736cf9ea25c 100644 --- a/tests/pointing/rotate180/test_rotate180.cpp +++ b/tests/pointing/rotate180/test_rotate180.cpp @@ -16,23 +16,23 @@ struct SimpleReport { }; class Pointing : public TestFixture {}; -class PointingRotateParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; +class PointingRotateParametrized : public ::testing::WithParamInterface>, public Pointing {}; -TEST_P(PointingRotateParametrizedTestFixture, PointingRotateXY) { +TEST_P(PointingRotateParametrized, PointingRotateXY) { TestDriver driver; SimpleReport input = GetParam().first; SimpleReport expectations = GetParam().second; - set_x(input.x); - set_y(input.y); - set_h(input.h); - set_v(input.v); + pd_set_x(input.x); + pd_set_y(input.y); + pd_set_h(input.h); + pd_set_v(input.v); EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); run_one_scan_loop(); // EXPECT_EMPTY_MOUSE_REPORT(driver); - clear_movement(); + pd_clear_movement(); run_one_scan_loop(); EXPECT_NO_MOUSE_REPORT(driver); @@ -42,8 +42,8 @@ TEST_P(PointingRotateParametrizedTestFixture, PointingRotateXY) { } // clang-format off INSTANTIATE_TEST_CASE_P( - Rotate180Tests, - PointingRotateParametrizedTestFixture, + Rotate180, + PointingRotateParametrized, ::testing::Values( // Input Expected // Rotate Clockwise diff --git a/tests/pointing/rotate270/test_rotate270.cpp b/tests/pointing/rotate270/test_rotate270.cpp index f2c3548564f..6735f062489 100644 --- a/tests/pointing/rotate270/test_rotate270.cpp +++ b/tests/pointing/rotate270/test_rotate270.cpp @@ -16,23 +16,23 @@ struct SimpleReport { }; class Pointing : public TestFixture {}; -class PointingRotateParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; +class PointingRotateParametrized : public ::testing::WithParamInterface>, public Pointing {}; -TEST_P(PointingRotateParametrizedTestFixture, PointingRotateXY) { +TEST_P(PointingRotateParametrized, PointingRotateXY) { TestDriver driver; SimpleReport input = GetParam().first; SimpleReport expectations = GetParam().second; - set_x(input.x); - set_y(input.y); - set_h(input.h); - set_v(input.v); + pd_set_x(input.x); + pd_set_y(input.y); + pd_set_h(input.h); + pd_set_v(input.v); EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); run_one_scan_loop(); // EXPECT_EMPTY_MOUSE_REPORT(driver); - clear_movement(); + pd_clear_movement(); run_one_scan_loop(); EXPECT_NO_MOUSE_REPORT(driver); @@ -42,8 +42,8 @@ TEST_P(PointingRotateParametrizedTestFixture, PointingRotateXY) { } // clang-format off INSTANTIATE_TEST_CASE_P( - Rotate270Tests, - PointingRotateParametrizedTestFixture, + Rotate270, + PointingRotateParametrized, ::testing::Values( // Input Expected // Actual Result - Rotate Anticlockwise diff --git a/tests/pointing/rotate90/test_rotate90.cpp b/tests/pointing/rotate90/test_rotate90.cpp index 537cdbd3eb2..5c44faad0ab 100644 --- a/tests/pointing/rotate90/test_rotate90.cpp +++ b/tests/pointing/rotate90/test_rotate90.cpp @@ -16,23 +16,23 @@ struct SimpleReport { }; class Pointing : public TestFixture {}; -class PointingRotateParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; +class PointingRotateParametrized : public ::testing::WithParamInterface>, public Pointing {}; -TEST_P(PointingRotateParametrizedTestFixture, PointingRotateXY) { +TEST_P(PointingRotateParametrized, PointingRotateXY) { TestDriver driver; SimpleReport input = GetParam().first; SimpleReport expectations = GetParam().second; - set_x(input.x); - set_y(input.y); - set_h(input.h); - set_v(input.v); + pd_set_x(input.x); + pd_set_y(input.y); + pd_set_h(input.h); + pd_set_v(input.v); EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); run_one_scan_loop(); // EXPECT_EMPTY_MOUSE_REPORT(driver); - clear_movement(); + pd_clear_movement(); run_one_scan_loop(); EXPECT_NO_MOUSE_REPORT(driver); @@ -42,8 +42,8 @@ TEST_P(PointingRotateParametrizedTestFixture, PointingRotateXY) { } // clang-format off INSTANTIATE_TEST_CASE_P( - Rotate90Tests, - PointingRotateParametrizedTestFixture, + Rotate90, + PointingRotateParametrized, ::testing::Values( // Input Expected // Actual Result - Rotate Anticlockwise diff --git a/tests/pointing/test_pointing.cpp b/tests/pointing/test_pointing.cpp index 6a4067ba694..d59d0149251 100644 --- a/tests/pointing/test_pointing.cpp +++ b/tests/pointing/test_pointing.cpp @@ -9,16 +9,8 @@ using testing::_; -struct MouseKeyExpectations { - int16_t x; - int16_t y; - int16_t h; - int16_t v; - uint16_t button_mask; -}; - class Pointing : public TestFixture {}; -class PointingKeycodeButtonsParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; +class PointingButtonsViaMousekeysParametrized : public ::testing::WithParamInterface>, public Pointing {}; TEST_F(Pointing, SendMouseIsNotCalledWithNoInput) { TestDriver driver; @@ -29,12 +21,12 @@ TEST_F(Pointing, SendMouseIsNotCalledWithNoInput) { TEST_F(Pointing, Xnegative) { TestDriver driver; - set_x(-10); + pd_set_x(-10); EXPECT_MOUSE_REPORT(driver, (-10, 0, 0, 0, 0)); run_one_scan_loop(); - clear_movement(); - // EXPECT_EMPTY_MOUSE_REPORT(driver); // This should probably generate an empty report. + pd_clear_movement(); + // EXPECT_EMPTY_MOUSE_REPORT(driver); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); @@ -43,12 +35,12 @@ TEST_F(Pointing, Xnegative) { TEST_F(Pointing, Xpositive) { TestDriver driver; - set_x(10); + pd_set_x(10); EXPECT_MOUSE_REPORT(driver, (10, 0, 0, 0, 0)); run_one_scan_loop(); - clear_movement(); - // EXPECT_EMPTY_MOUSE_REPORT(driver); // This should probably generate an empty report. + pd_clear_movement(); + // EXPECT_EMPTY_MOUSE_REPORT(driver); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); @@ -57,12 +49,12 @@ TEST_F(Pointing, Xpositive) { TEST_F(Pointing, Ynegative) { TestDriver driver; - set_y(-20); + pd_set_y(-20); EXPECT_MOUSE_REPORT(driver, (0, -20, 0, 0, 0)); run_one_scan_loop(); - clear_movement(); - // EXPECT_EMPTY_MOUSE_REPORT(driver); // This should probably generate an empty report. + pd_clear_movement(); + // EXPECT_EMPTY_MOUSE_REPORT(driver); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); @@ -71,12 +63,12 @@ TEST_F(Pointing, Ynegative) { TEST_F(Pointing, Ypositive) { TestDriver driver; - set_y(20); + pd_set_y(20); EXPECT_MOUSE_REPORT(driver, (0, 20, 0, 0, 0)); run_one_scan_loop(); - clear_movement(); - // EXPECT_EMPTY_MOUSE_REPORT(driver); // This should probably generate an empty report. + pd_clear_movement(); + // EXPECT_EMPTY_MOUSE_REPORT(driver); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); @@ -85,13 +77,13 @@ TEST_F(Pointing, Ypositive) { TEST_F(Pointing, XandY) { TestDriver driver; - set_x(-50); - set_y(100); + pd_set_x(-50); + pd_set_y(100); EXPECT_MOUSE_REPORT(driver, (-50, 100, 0, 0, 0)); run_one_scan_loop(); - clear_movement(); - // EXPECT_EMPTY_MOUSE_REPORT(driver); // This should probably generate an empty report. + pd_clear_movement(); + // EXPECT_EMPTY_MOUSE_REPORT(driver); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); @@ -101,17 +93,17 @@ TEST_F(Pointing, CorrectButtonIsReportedWhenPressed) { TestDriver driver; EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, 1)); - press_button(POINTING_DEVICE_BUTTON1); + pd_press_button(POINTING_DEVICE_BUTTON1); run_one_scan_loop(); EXPECT_EMPTY_MOUSE_REPORT(driver); - release_button(POINTING_DEVICE_BUTTON1); + pd_release_button(POINTING_DEVICE_BUTTON1); run_one_scan_loop(); EXPECT_NO_MOUSE_REPORT(driver); run_one_scan_loop(); - clear_all_buttons(); + pd_clear_all_buttons(); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); @@ -136,14 +128,14 @@ TEST_F(Pointing, CorrectButtonIsReportedWhenKeyPressed) { VERIFY_AND_CLEAR(driver); } -TEST_P(PointingKeycodeButtonsParametrizedTestFixture, PointingMouseKeysViaPointingDriver) { - TestDriver driver; - KeymapKey mouse_key = GetParam().first; - MouseKeyExpectations expectations = GetParam().second; +TEST_P(PointingButtonsViaMousekeysParametrized, MouseKeysViaPointingDriver) { + TestDriver driver; + KeymapKey mouse_key = GetParam().first; + uint8_t button_mask = GetParam().second; set_keymap({mouse_key}); - EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, expectations.button_mask)); + EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, button_mask)); mouse_key.press(); run_one_scan_loop(); @@ -158,17 +150,17 @@ TEST_P(PointingKeycodeButtonsParametrizedTestFixture, PointingMouseKeysViaPointi } // clang-format off INSTANTIATE_TEST_CASE_P( - PointingMouseKeysTests, - PointingKeycodeButtonsParametrizedTestFixture, + ButtonsOneToEight, + PointingButtonsViaMousekeysParametrized, ::testing::Values( - // Key , X, Y, H, V, Buttons Mask - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_1}, MouseKeyExpectations{0, 0, 0, 0, 1}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_2}, MouseKeyExpectations{0, 0, 0, 0, 2}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_3}, MouseKeyExpectations{0, 0, 0, 0, 4}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_4}, MouseKeyExpectations{0, 0, 0, 0, 8}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_5}, MouseKeyExpectations{0, 0, 0, 0, 16}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_6}, MouseKeyExpectations{0, 0, 0, 0, 32}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_7}, MouseKeyExpectations{0, 0, 0, 0, 64}), - std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_8}, MouseKeyExpectations{0, 0, 0, 0, 128}) + // Key , Buttons Mask + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_1}, 1), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_2}, 2), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_3}, 4), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_4}, 8), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_5}, 16), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_6}, 32), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_7}, 64), + std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_8}, 128) )); // clang-format on diff --git a/tests/test_common/pointing_device_driver.c b/tests/test_common/pointing_device_driver.c index d6a46c607f7..e05a2be8ce4 100644 --- a/tests/test_common/pointing_device_driver.c +++ b/tests/test_common/pointing_device_driver.c @@ -8,86 +8,102 @@ typedef struct { bool state; bool set; -} test_buttons_t; +} pd_button_state_t; -static report_mouse_t test_report = {0}; -static uint16_t test_cpi = {0}; -static test_buttons_t test_button_events[8] = {0}; +typedef struct { + int16_t x; + int16_t y; + int16_t h; + int16_t v; + pd_button_state_t button_state[8]; + uint16_t cpi; + bool initiated; +} pd_config_t; -void pointing_device_driver_init(void) {} +static pd_config_t pd_config = {0}; + +void pointing_device_driver_init(void) { + pd_set_init(true); +} report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) { - test_report.buttons = 0; - test_report.buttons = mouse_report.buttons; // buttons must currently be preserved by pointing device driver for (uint8_t i = 0; i < 8; i++) { - if (test_button_events[i].set) { - test_button_events[i].set = false; - if (test_button_events[i].state) { - test_report.buttons |= 1 << (i); + if (pd_config.button_state[i].set) { + pd_config.button_state[i].set = false; + if (pd_config.button_state[i].state) { + mouse_report.buttons |= 1 << (i); } else { - test_report.buttons &= ~(1 << (i)); + mouse_report.buttons &= ~(1 << (i)); } } } - return test_report; + mouse_report.x = pd_config.x; + mouse_report.y = pd_config.y; + mouse_report.h = pd_config.h; + mouse_report.v = pd_config.v; + return mouse_report; } __attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) { - return test_cpi; + return pd_config.cpi; } __attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) { - test_cpi = cpi; + pd_config.cpi = cpi; } -void press_button(uint8_t btn) { - test_button_events[btn].set = true; - test_button_events[btn].state = true; +void pd_press_button(uint8_t btn) { + pd_config.button_state[btn].set = true; + pd_config.button_state[btn].state = true; } -void release_button(uint8_t btn) { - test_button_events[btn].set = true; - test_button_events[btn].state = false; +void pd_release_button(uint8_t btn) { + pd_config.button_state[btn].set = true; + pd_config.button_state[btn].state = false; } -void clear_all_buttons(void) { +void pd_clear_all_buttons(void) { for (uint8_t i = 0; i < 8; i++) { - test_button_events[i].set = true; - test_button_events[i].state = false; + pd_config.button_state[i].set = true; + pd_config.button_state[i].state = false; } } -void set_x(int16_t x) { - test_report.x = x; +void pd_set_x(int16_t x) { + pd_config.x = x; } -void clear_x(void) { - set_x(0); +void pd_clear_x(void) { + pd_set_x(0); } -void set_y(int16_t y) { - test_report.y = y; +void pd_set_y(int16_t y) { + pd_config.y = y; } -void clear_y(void) { - set_y(0); +void pd_clear_y(void) { + pd_set_y(0); } -void set_h(int16_t h) { - test_report.h = h; +void pd_set_h(int16_t h) { + pd_config.h = h; } -void clear_h(void) { - set_h(0); +void pd_clear_h(void) { + pd_set_h(0); } -void set_v(int16_t v) { - test_report.v = v; +void pd_set_v(int16_t v) { + pd_config.v = v; } -void clear_v(void) { - set_v(0); +void pd_clear_v(void) { + pd_set_v(0); } -void clear_movement(void) { - set_x(0); - set_y(0); - set_h(0); - set_v(0); +void pd_clear_movement(void) { + pd_set_x(0); + pd_set_y(0); + pd_set_h(0); + pd_set_v(0); +} + +void pd_set_init(bool success) { + pd_config.initiated = success; } diff --git a/tests/test_common/test_pointing_device_driver.h b/tests/test_common/test_pointing_device_driver.h index 5aea021b201..ae136b21cdf 100644 --- a/tests/test_common/test_pointing_device_driver.h +++ b/tests/test_common/test_pointing_device_driver.h @@ -7,23 +7,25 @@ extern "C" { #endif -void press_button(uint8_t btn); -void release_button(uint8_t btn); -void clear_all_buttons(void); +void pd_press_button(uint8_t btn); +void pd_release_button(uint8_t btn); +void pd_clear_all_buttons(void); -void set_x(int16_t x); +void pd_set_x(int16_t x); void clear_x(void); -void set_y(int16_t y); -void clear_y(void); +void pd_set_y(int16_t y); +void pd_clear_y(void); -void set_h(int16_t h); -void clear_h(void); +void pd_set_h(int16_t h); +void pd_clear_h(void); -void set_v(int16_t v); -void clear_v(void); +void pd_set_v(int16_t v); +void pd_clear_v(void); -void clear_movement(void); +void pd_clear_movement(void); + +void pd_set_init(bool success); #ifdef __cplusplus }