diff options
Diffstat (limited to 'tests/pointing')
| -rw-r--r-- | tests/pointing/config.h | 6 | ||||
| -rw-r--r-- | tests/pointing/invertandrotate/config.h | 9 | ||||
| -rw-r--r-- | tests/pointing/invertandrotate/test.mk | 2 | ||||
| -rw-r--r-- | tests/pointing/invertandrotate/test_invertandrotate.cpp | 59 | ||||
| -rw-r--r-- | tests/pointing/invertxy/config.h | 9 | ||||
| -rw-r--r-- | tests/pointing/invertxy/test.mk | 2 | ||||
| -rw-r--r-- | tests/pointing/invertxy/test_invertxy.cpp | 53 | ||||
| -rw-r--r-- | tests/pointing/rotate180/config.h | 8 | ||||
| -rw-r--r-- | tests/pointing/rotate180/test.mk | 2 | ||||
| -rw-r--r-- | tests/pointing/rotate180/test_rotate180.cpp | 55 | ||||
| -rw-r--r-- | tests/pointing/rotate270/config.h | 8 | ||||
| -rw-r--r-- | tests/pointing/rotate270/test.mk | 2 | ||||
| -rw-r--r-- | tests/pointing/rotate270/test_rotate270.cpp | 60 | ||||
| -rw-r--r-- | tests/pointing/rotate90/config.h | 8 | ||||
| -rw-r--r-- | tests/pointing/rotate90/test.mk | 2 | ||||
| -rw-r--r-- | tests/pointing/rotate90/test_rotate90.cpp | 60 | ||||
| -rw-r--r-- | tests/pointing/test.mk | 4 | ||||
| -rw-r--r-- | tests/pointing/test_pointing.cpp | 166 |
18 files changed, 515 insertions, 0 deletions
diff --git a/tests/pointing/config.h b/tests/pointing/config.h new file mode 100644 index 0000000000..76bbbe8dae --- /dev/null +++ b/tests/pointing/config.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | // Copyright 2024 Dasky (@daskygit) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "test_common.h" | ||
diff --git a/tests/pointing/invertandrotate/config.h b/tests/pointing/invertandrotate/config.h new file mode 100644 index 0000000000..a3f3df7a54 --- /dev/null +++ b/tests/pointing/invertandrotate/config.h | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | // Copyright 2024 Dasky (@daskygit) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "test_common.h" | ||
| 7 | |||
| 8 | #define POINTING_DEVICE_INVERT_X | ||
| 9 | #define POINTING_DEVICE_ROTATION_90 | ||
diff --git a/tests/pointing/invertandrotate/test.mk b/tests/pointing/invertandrotate/test.mk new file mode 100644 index 0000000000..ba224d74f0 --- /dev/null +++ b/tests/pointing/invertandrotate/test.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | POINTING_DEVICE_ENABLE = yes | ||
| 2 | POINTING_DEVICE_DRIVER = custom | ||
diff --git a/tests/pointing/invertandrotate/test_invertandrotate.cpp b/tests/pointing/invertandrotate/test_invertandrotate.cpp new file mode 100644 index 0000000000..b47739f415 --- /dev/null +++ b/tests/pointing/invertandrotate/test_invertandrotate.cpp | |||
| @@ -0,0 +1,59 @@ | |||
| 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 PointingInvertAndRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {}; | ||
| 20 | |||
| 21 | TEST_P(PointingInvertAndRotateParametrized, PointingInvertAndRotateOrder) { | ||
| 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 | InvertAndRotate, | ||
| 46 | PointingInvertAndRotateParametrized, | ||
| 47 | ::testing::Values( | ||
| 48 | // Input Expected // Actual Result - Rotate 90 then Invert X | ||
| 49 | std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // LEFT - DOWN | ||
| 50 | std::make_pair(SimpleReport{ 0, -1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT | ||
| 51 | std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, -1, 0, 0}), // RIGHT - UP | ||
| 52 | std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ -1, 0, 0, 0}) // DOWN - LEFT | ||
| 53 | // Input Expected // Invert X then Rotate 90 | ||
| 54 | // std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, -1, 0, 0}), // LEFT - UP | ||
| 55 | // std::make_pair(SimpleReport{ 0, -1, 0, 0}, SimpleReport{ -1, 0, 0, 0}), // UP - LEFT | ||
| 56 | // std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // RIGHT - DOWN | ||
| 57 | // std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}) // DOWN - RIGHT | ||
| 58 | )); | ||
| 59 | // clang-format on | ||
diff --git a/tests/pointing/invertxy/config.h b/tests/pointing/invertxy/config.h new file mode 100644 index 0000000000..6b29185d37 --- /dev/null +++ b/tests/pointing/invertxy/config.h | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | // Copyright 2024 Dasky (@daskygit) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "test_common.h" | ||
| 7 | |||
| 8 | #define POINTING_DEVICE_INVERT_X | ||
| 9 | #define POINTING_DEVICE_INVERT_Y | ||
diff --git a/tests/pointing/invertxy/test.mk b/tests/pointing/invertxy/test.mk new file mode 100644 index 0000000000..ba224d74f0 --- /dev/null +++ b/tests/pointing/invertxy/test.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | POINTING_DEVICE_ENABLE = yes | ||
| 2 | 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 0000000000..014f6f3cd0 --- /dev/null +++ b/tests/pointing/invertxy/test_invertxy.cpp | |||
| @@ -0,0 +1,53 @@ | |||
| 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 | ||
diff --git a/tests/pointing/rotate180/config.h b/tests/pointing/rotate180/config.h new file mode 100644 index 0000000000..a80f5482fd --- /dev/null +++ b/tests/pointing/rotate180/config.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | // Copyright 2024 Dasky (@daskygit) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "test_common.h" | ||
| 7 | |||
| 8 | #define POINTING_DEVICE_ROTATION_180 | ||
diff --git a/tests/pointing/rotate180/test.mk b/tests/pointing/rotate180/test.mk new file mode 100644 index 0000000000..ba224d74f0 --- /dev/null +++ b/tests/pointing/rotate180/test.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | POINTING_DEVICE_ENABLE = yes | ||
| 2 | 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 0000000000..736cf9ea25 --- /dev/null +++ b/tests/pointing/rotate180/test_rotate180.cpp | |||
| @@ -0,0 +1,55 @@ | |||
| 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 PointingRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {}; | ||
| 20 | |||
| 21 | TEST_P(PointingRotateParametrized, PointingRotateXY) { | ||
| 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 | Rotate180, | ||
| 46 | PointingRotateParametrized, | ||
| 47 | ::testing::Values( | ||
| 48 | // Input Expected | ||
| 49 | // Rotate Clockwise | ||
| 50 | std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // UP - DOWN | ||
| 51 | std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // DOWN - UP | ||
| 52 | std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{-1, 0, 0, 0}), // RIGHT - LEFT | ||
| 53 | std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 1, 0, 0, 0}) // LEFT - RIGHT | ||
| 54 | )); | ||
| 55 | // clang-format on | ||
diff --git a/tests/pointing/rotate270/config.h b/tests/pointing/rotate270/config.h new file mode 100644 index 0000000000..3977dd95e6 --- /dev/null +++ b/tests/pointing/rotate270/config.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | // Copyright 2024 Dasky (@daskygit) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "test_common.h" | ||
| 7 | |||
| 8 | #define POINTING_DEVICE_ROTATION_270 | ||
diff --git a/tests/pointing/rotate270/test.mk b/tests/pointing/rotate270/test.mk new file mode 100644 index 0000000000..ba224d74f0 --- /dev/null +++ b/tests/pointing/rotate270/test.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | POINTING_DEVICE_ENABLE = yes | ||
| 2 | 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 0000000000..6735f06248 --- /dev/null +++ b/tests/pointing/rotate270/test_rotate270.cpp | |||
| @@ -0,0 +1,60 @@ | |||
| 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 PointingRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {}; | ||
| 20 | |||
| 21 | TEST_P(PointingRotateParametrized, PointingRotateXY) { | ||
| 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 | Rotate270, | ||
| 46 | PointingRotateParametrized, | ||
| 47 | ::testing::Values( | ||
| 48 | // Input Expected | ||
| 49 | // Actual Result - Rotate Anticlockwise | ||
| 50 | std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT | ||
| 51 | std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // DOWN - LEFT | ||
| 52 | std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // RIGHT - DOWN | ||
| 53 | std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}) // LEFT - UP | ||
| 54 | // Rotate Clockwise | ||
| 55 | // std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // UP - LEFT | ||
| 56 | // std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // DOWN - RIGHT | ||
| 57 | // std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // RIGHT - UP | ||
| 58 | // std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}) // LEFT - DOWN | ||
| 59 | )); | ||
| 60 | // clang-format on | ||
diff --git a/tests/pointing/rotate90/config.h b/tests/pointing/rotate90/config.h new file mode 100644 index 0000000000..3a18ec92e9 --- /dev/null +++ b/tests/pointing/rotate90/config.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | // Copyright 2024 Dasky (@daskygit) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "test_common.h" | ||
| 7 | |||
| 8 | #define POINTING_DEVICE_ROTATION_90 | ||
diff --git a/tests/pointing/rotate90/test.mk b/tests/pointing/rotate90/test.mk new file mode 100644 index 0000000000..ba224d74f0 --- /dev/null +++ b/tests/pointing/rotate90/test.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | POINTING_DEVICE_ENABLE = yes | ||
| 2 | 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 0000000000..5c44faad0a --- /dev/null +++ b/tests/pointing/rotate90/test_rotate90.cpp | |||
| @@ -0,0 +1,60 @@ | |||
| 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 PointingRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {}; | ||
| 20 | |||
| 21 | TEST_P(PointingRotateParametrized, PointingRotateXY) { | ||
| 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 | Rotate90, | ||
| 46 | PointingRotateParametrized, | ||
| 47 | ::testing::Values( | ||
| 48 | // Input Expected | ||
| 49 | // Actual Result - Rotate Anticlockwise | ||
| 50 | std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // UP - LEFT | ||
| 51 | std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // DOWN - RIGHT | ||
| 52 | std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // RIGHT - UP | ||
| 53 | std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}) // LEFT - DOWN | ||
| 54 | // Rotate Clockwise | ||
| 55 | // std::make_pair(SimpleReport{ 0,-1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT | ||
| 56 | // std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{-1, 0, 0, 0}), // DOWN - LEFT | ||
| 57 | // std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0,-1, 0, 0}), // RIGHT - DOWN | ||
| 58 | // std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}) // LEFT - UP | ||
| 59 | )); | ||
| 60 | // clang-format on | ||
diff --git a/tests/pointing/test.mk b/tests/pointing/test.mk new file mode 100644 index 0000000000..95fde21cb9 --- /dev/null +++ b/tests/pointing/test.mk | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | POINTING_DEVICE_ENABLE = yes | ||
| 2 | MOUSEKEY_ENABLE = no | ||
| 3 | POINTING_DEVICE_DRIVER = custom | ||
| 4 | |||
diff --git a/tests/pointing/test_pointing.cpp b/tests/pointing/test_pointing.cpp new file mode 100644 index 0000000000..d59d014925 --- /dev/null +++ b/tests/pointing/test_pointing.cpp | |||
| @@ -0,0 +1,166 @@ | |||
| 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 | #include "mousekey.h" | ||
| 9 | |||
| 10 | using testing::_; | ||
| 11 | |||
| 12 | class Pointing : public TestFixture {}; | ||
| 13 | class PointingButtonsViaMousekeysParametrized : public ::testing::WithParamInterface<std::pair<KeymapKey, uint8_t>>, public Pointing {}; | ||
| 14 | |||
| 15 | TEST_F(Pointing, SendMouseIsNotCalledWithNoInput) { | ||
| 16 | TestDriver driver; | ||
| 17 | EXPECT_NO_MOUSE_REPORT(driver); | ||
| 18 | run_one_scan_loop(); | ||
| 19 | } | ||
| 20 | |||
| 21 | TEST_F(Pointing, Xnegative) { | ||
| 22 | TestDriver driver; | ||
| 23 | |||
| 24 | pd_set_x(-10); | ||
| 25 | EXPECT_MOUSE_REPORT(driver, (-10, 0, 0, 0, 0)); | ||
| 26 | run_one_scan_loop(); | ||
| 27 | |||
| 28 | pd_clear_movement(); | ||
| 29 | // EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 30 | run_one_scan_loop(); | ||
| 31 | |||
| 32 | VERIFY_AND_CLEAR(driver); | ||
| 33 | } | ||
| 34 | |||
| 35 | TEST_F(Pointing, Xpositive) { | ||
| 36 | TestDriver driver; | ||
| 37 | |||
| 38 | pd_set_x(10); | ||
| 39 | EXPECT_MOUSE_REPORT(driver, (10, 0, 0, 0, 0)); | ||
| 40 | run_one_scan_loop(); | ||
| 41 | |||
| 42 | pd_clear_movement(); | ||
| 43 | // EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 44 | run_one_scan_loop(); | ||
| 45 | |||
| 46 | VERIFY_AND_CLEAR(driver); | ||
| 47 | } | ||
| 48 | |||
| 49 | TEST_F(Pointing, Ynegative) { | ||
| 50 | TestDriver driver; | ||
| 51 | |||
| 52 | pd_set_y(-20); | ||
| 53 | EXPECT_MOUSE_REPORT(driver, (0, -20, 0, 0, 0)); | ||
| 54 | run_one_scan_loop(); | ||
| 55 | |||
| 56 | pd_clear_movement(); | ||
| 57 | // EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 58 | run_one_scan_loop(); | ||
| 59 | |||
| 60 | VERIFY_AND_CLEAR(driver); | ||
| 61 | } | ||
| 62 | |||
| 63 | TEST_F(Pointing, Ypositive) { | ||
| 64 | TestDriver driver; | ||
| 65 | |||
| 66 | pd_set_y(20); | ||
| 67 | EXPECT_MOUSE_REPORT(driver, (0, 20, 0, 0, 0)); | ||
| 68 | run_one_scan_loop(); | ||
| 69 | |||
| 70 | pd_clear_movement(); | ||
| 71 | // EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 72 | run_one_scan_loop(); | ||
| 73 | |||
| 74 | VERIFY_AND_CLEAR(driver); | ||
| 75 | } | ||
| 76 | |||
| 77 | TEST_F(Pointing, XandY) { | ||
| 78 | TestDriver driver; | ||
| 79 | |||
| 80 | pd_set_x(-50); | ||
| 81 | pd_set_y(100); | ||
| 82 | EXPECT_MOUSE_REPORT(driver, (-50, 100, 0, 0, 0)); | ||
| 83 | run_one_scan_loop(); | ||
| 84 | |||
| 85 | pd_clear_movement(); | ||
| 86 | // EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 87 | run_one_scan_loop(); | ||
| 88 | |||
| 89 | VERIFY_AND_CLEAR(driver); | ||
| 90 | } | ||
| 91 | |||
| 92 | TEST_F(Pointing, CorrectButtonIsReportedWhenPressed) { | ||
| 93 | TestDriver driver; | ||
| 94 | |||
| 95 | EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, 1)); | ||
| 96 | pd_press_button(POINTING_DEVICE_BUTTON1); | ||
| 97 | run_one_scan_loop(); | ||
| 98 | |||
| 99 | EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 100 | pd_release_button(POINTING_DEVICE_BUTTON1); | ||
| 101 | run_one_scan_loop(); | ||
| 102 | |||
| 103 | EXPECT_NO_MOUSE_REPORT(driver); | ||
| 104 | run_one_scan_loop(); | ||
| 105 | |||
| 106 | pd_clear_all_buttons(); | ||
| 107 | run_one_scan_loop(); | ||
| 108 | |||
| 109 | VERIFY_AND_CLEAR(driver); | ||
| 110 | } | ||
| 111 | |||
| 112 | TEST_F(Pointing, CorrectButtonIsReportedWhenKeyPressed) { | ||
| 113 | TestDriver driver; | ||
| 114 | auto key = KeymapKey(0, 0, 0, KC_MS_BTN1); | ||
| 115 | set_keymap({key}); | ||
| 116 | |||
| 117 | EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, 1)); | ||
| 118 | key.press(); | ||
| 119 | run_one_scan_loop(); | ||
| 120 | |||
| 121 | EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 122 | key.release(); | ||
| 123 | run_one_scan_loop(); | ||
| 124 | |||
| 125 | EXPECT_NO_MOUSE_REPORT(driver); | ||
| 126 | run_one_scan_loop(); | ||
| 127 | |||
| 128 | VERIFY_AND_CLEAR(driver); | ||
| 129 | } | ||
| 130 | |||
| 131 | TEST_P(PointingButtonsViaMousekeysParametrized, MouseKeysViaPointingDriver) { | ||
| 132 | TestDriver driver; | ||
| 133 | KeymapKey mouse_key = GetParam().first; | ||
| 134 | uint8_t button_mask = GetParam().second; | ||
| 135 | |||
| 136 | set_keymap({mouse_key}); | ||
| 137 | |||
| 138 | EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, button_mask)); | ||
| 139 | mouse_key.press(); | ||
| 140 | run_one_scan_loop(); | ||
| 141 | |||
| 142 | EXPECT_EMPTY_MOUSE_REPORT(driver); | ||
| 143 | mouse_key.release(); | ||
| 144 | run_one_scan_loop(); | ||
| 145 | |||
| 146 | EXPECT_NO_MOUSE_REPORT(driver); | ||
| 147 | run_one_scan_loop(); | ||
| 148 | |||
| 149 | VERIFY_AND_CLEAR(driver); | ||
| 150 | } | ||
| 151 | // clang-format off | ||
| 152 | INSTANTIATE_TEST_CASE_P( | ||
| 153 | ButtonsOneToEight, | ||
| 154 | PointingButtonsViaMousekeysParametrized, | ||
| 155 | ::testing::Values( | ||
| 156 | // Key , Buttons Mask | ||
| 157 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_1}, 1), | ||
| 158 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_2}, 2), | ||
| 159 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_3}, 4), | ||
| 160 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_4}, 8), | ||
| 161 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_5}, 16), | ||
| 162 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_6}, 32), | ||
| 163 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_7}, 64), | ||
| 164 | std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_8}, 128) | ||
| 165 | )); | ||
| 166 | // clang-format on | ||
