From e9bb4521ba0aa8f80f2b78e28351df3eef3fb95d Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:36:00 +0100 Subject: [PATCH] test rotation and invert defines --- tests/pointing/invertxy/config.h | 9 ++++ tests/pointing/invertxy/test.mk | 2 + tests/pointing/invertxy/test_invertxy.cpp | 53 ++++++++++++++++++ tests/pointing/rotate180/config.h | 8 +++ tests/pointing/rotate180/test.mk | 2 + tests/pointing/rotate180/test_rotate180.cpp | 55 +++++++++++++++++++ tests/pointing/rotate270/config.h | 8 +++ tests/pointing/rotate270/test.mk | 2 + tests/pointing/rotate270/test_rotate270.cpp | 60 +++++++++++++++++++++ tests/pointing/rotate90/config.h | 8 +++ tests/pointing/rotate90/test.mk | 2 + tests/pointing/rotate90/test_rotate90.cpp | 60 +++++++++++++++++++++ 12 files changed, 269 insertions(+) create mode 100644 tests/pointing/invertxy/config.h create mode 100644 tests/pointing/invertxy/test.mk create mode 100644 tests/pointing/invertxy/test_invertxy.cpp create mode 100644 tests/pointing/rotate180/config.h create mode 100644 tests/pointing/rotate180/test.mk create mode 100644 tests/pointing/rotate180/test_rotate180.cpp create mode 100644 tests/pointing/rotate270/config.h create mode 100644 tests/pointing/rotate270/test.mk create mode 100644 tests/pointing/rotate270/test_rotate270.cpp create mode 100644 tests/pointing/rotate90/config.h create mode 100644 tests/pointing/rotate90/test.mk create mode 100644 tests/pointing/rotate90/test_rotate90.cpp diff --git a/tests/pointing/invertxy/config.h b/tests/pointing/invertxy/config.h new file mode 100644 index 00000000000..6b29185d371 --- /dev/null +++ b/tests/pointing/invertxy/config.h @@ -0,0 +1,9 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define POINTING_DEVICE_INVERT_X +#define POINTING_DEVICE_INVERT_Y diff --git a/tests/pointing/invertxy/test.mk b/tests/pointing/invertxy/test.mk new file mode 100644 index 00000000000..ba224d74f0a --- /dev/null +++ b/tests/pointing/invertxy/test.mk @@ -0,0 +1,2 @@ +POINTING_DEVICE_ENABLE = yes +POINTING_DEVICE_DRIVER = custom diff --git a/tests/pointing/invertxy/test_invertxy.cpp b/tests/pointing/invertxy/test_invertxy.cpp new file mode 100644 index 00000000000..e8b9409007b --- /dev/null +++ b/tests/pointing/invertxy/test_invertxy.cpp @@ -0,0 +1,53 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "gtest/gtest.h" +#include "mouse_report_util.hpp" +#include "test_common.hpp" +#include "test_pointing_device_driver.h" + +using testing::_; + +struct SimpleReport { + int16_t x; + int16_t y; + int16_t h; + int16_t v; +}; + +class Pointing : public TestFixture {}; +class PointingInvertXYParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; + +TEST_P(PointingInvertXYParametrizedTestFixture, PointingMouseKeysViaPointingDriver) { + 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); + + EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); + run_one_scan_loop(); + + // EXPECT_EMPTY_MOUSE_REPORT(driver); + clear_movement(); + run_one_scan_loop(); + + EXPECT_NO_MOUSE_REPORT(driver); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} +// clang-format off +INSTANTIATE_TEST_CASE_P( + PointingInvertXYTests, + PointingInvertXYParametrizedTestFixture, + ::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}) + )); +// clang-format on diff --git a/tests/pointing/rotate180/config.h b/tests/pointing/rotate180/config.h new file mode 100644 index 00000000000..a80f5482fd4 --- /dev/null +++ b/tests/pointing/rotate180/config.h @@ -0,0 +1,8 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define POINTING_DEVICE_ROTATION_180 diff --git a/tests/pointing/rotate180/test.mk b/tests/pointing/rotate180/test.mk new file mode 100644 index 00000000000..ba224d74f0a --- /dev/null +++ b/tests/pointing/rotate180/test.mk @@ -0,0 +1,2 @@ +POINTING_DEVICE_ENABLE = yes +POINTING_DEVICE_DRIVER = custom diff --git a/tests/pointing/rotate180/test_rotate180.cpp b/tests/pointing/rotate180/test_rotate180.cpp new file mode 100644 index 00000000000..11318ef5482 --- /dev/null +++ b/tests/pointing/rotate180/test_rotate180.cpp @@ -0,0 +1,55 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "gtest/gtest.h" +#include "mouse_report_util.hpp" +#include "test_common.hpp" +#include "test_pointing_device_driver.h" + +using testing::_; + +struct SimpleReport { + int16_t x; + int16_t y; + int16_t h; + int16_t v; +}; + +class Pointing : public TestFixture {}; +class PointingRotateParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; + +TEST_P(PointingRotateParametrizedTestFixture, 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); + + EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); + run_one_scan_loop(); + + // EXPECT_EMPTY_MOUSE_REPORT(driver); + clear_movement(); + run_one_scan_loop(); + + EXPECT_NO_MOUSE_REPORT(driver); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} +// clang-format off +INSTANTIATE_TEST_CASE_P( + Rotate180Tests, + PointingRotateParametrizedTestFixture, + ::testing::Values( + // Input Expected + // Rotate Clockwise + std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // UP - DOWN + std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // DOWN - UP + std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{-1, 0, 0, 0}), // RIGHT - LEFT + std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 1, 0, 0, 0}) // LEFT - RIGHT + )); +// clang-format on diff --git a/tests/pointing/rotate270/config.h b/tests/pointing/rotate270/config.h new file mode 100644 index 00000000000..3977dd95e6c --- /dev/null +++ b/tests/pointing/rotate270/config.h @@ -0,0 +1,8 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define POINTING_DEVICE_ROTATION_270 diff --git a/tests/pointing/rotate270/test.mk b/tests/pointing/rotate270/test.mk new file mode 100644 index 00000000000..ba224d74f0a --- /dev/null +++ b/tests/pointing/rotate270/test.mk @@ -0,0 +1,2 @@ +POINTING_DEVICE_ENABLE = yes +POINTING_DEVICE_DRIVER = custom diff --git a/tests/pointing/rotate270/test_rotate270.cpp b/tests/pointing/rotate270/test_rotate270.cpp new file mode 100644 index 00000000000..f2c3548564f --- /dev/null +++ b/tests/pointing/rotate270/test_rotate270.cpp @@ -0,0 +1,60 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "gtest/gtest.h" +#include "mouse_report_util.hpp" +#include "test_common.hpp" +#include "test_pointing_device_driver.h" + +using testing::_; + +struct SimpleReport { + int16_t x; + int16_t y; + int16_t h; + int16_t v; +}; + +class Pointing : public TestFixture {}; +class PointingRotateParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; + +TEST_P(PointingRotateParametrizedTestFixture, 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); + + EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); + run_one_scan_loop(); + + // EXPECT_EMPTY_MOUSE_REPORT(driver); + clear_movement(); + run_one_scan_loop(); + + EXPECT_NO_MOUSE_REPORT(driver); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} +// clang-format off +INSTANTIATE_TEST_CASE_P( + Rotate270Tests, + PointingRotateParametrizedTestFixture, + ::testing::Values( + // Input Expected + // Actual Result - Rotate Anticlockwise + std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT + std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // DOWN - LEFT + std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // RIGHT - DOWN + std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}) // LEFT - UP + // Rotate Clockwise + // std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // UP - LEFT + // std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // DOWN - RIGHT + // std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // RIGHT - UP + // std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}) // LEFT - DOWN + )); +// clang-format on diff --git a/tests/pointing/rotate90/config.h b/tests/pointing/rotate90/config.h new file mode 100644 index 00000000000..3a18ec92e94 --- /dev/null +++ b/tests/pointing/rotate90/config.h @@ -0,0 +1,8 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define POINTING_DEVICE_ROTATION_90 diff --git a/tests/pointing/rotate90/test.mk b/tests/pointing/rotate90/test.mk new file mode 100644 index 00000000000..ba224d74f0a --- /dev/null +++ b/tests/pointing/rotate90/test.mk @@ -0,0 +1,2 @@ +POINTING_DEVICE_ENABLE = yes +POINTING_DEVICE_DRIVER = custom diff --git a/tests/pointing/rotate90/test_rotate90.cpp b/tests/pointing/rotate90/test_rotate90.cpp new file mode 100644 index 00000000000..537cdbd3eb2 --- /dev/null +++ b/tests/pointing/rotate90/test_rotate90.cpp @@ -0,0 +1,60 @@ +// Copyright 2024 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "gtest/gtest.h" +#include "mouse_report_util.hpp" +#include "test_common.hpp" +#include "test_pointing_device_driver.h" + +using testing::_; + +struct SimpleReport { + int16_t x; + int16_t y; + int16_t h; + int16_t v; +}; + +class Pointing : public TestFixture {}; +class PointingRotateParametrizedTestFixture : public ::testing::WithParamInterface>, public Pointing {}; + +TEST_P(PointingRotateParametrizedTestFixture, 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); + + EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0)); + run_one_scan_loop(); + + // EXPECT_EMPTY_MOUSE_REPORT(driver); + clear_movement(); + run_one_scan_loop(); + + EXPECT_NO_MOUSE_REPORT(driver); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} +// clang-format off +INSTANTIATE_TEST_CASE_P( + Rotate90Tests, + PointingRotateParametrizedTestFixture, + ::testing::Values( + // Input Expected + // Actual Result - Rotate Anticlockwise + std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // UP - LEFT + std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // DOWN - RIGHT + std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // RIGHT - UP + std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}) // LEFT - DOWN + // Rotate Clockwise + // std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT + // std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // DOWN - LEFT + // std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // RIGHT - DOWN + // std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}) // LEFT - UP + )); +// clang-format on