1
0
Fork 0

Add pointing tests (#24513)

This commit is contained in:
Dasky 2024-11-23 16:34:32 +00:00 committed by GitHub
parent d189de24a0
commit 1f7d10902a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 917 additions and 0 deletions

6
tests/pointing/config.h Normal file
View file

@ -0,0 +1,6 @@
// Copyright 2024 Dasky (@daskygit)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "test_common.h"

View file

@ -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_ROTATION_90

View file

@ -0,0 +1,2 @@
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = custom

View file

@ -0,0 +1,59 @@
// 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 PointingInvertAndRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {};
TEST_P(PointingInvertAndRotateParametrized, PointingInvertAndRotateOrder) {
TestDriver driver;
SimpleReport input = GetParam().first;
SimpleReport expectations = GetParam().second;
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);
pd_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(
InvertAndRotate,
PointingInvertAndRotateParametrized,
::testing::Values(
// Input Expected // Actual Result - Rotate 90 then Invert X
std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // LEFT - DOWN
std::make_pair(SimpleReport{ 0, -1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT
std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, -1, 0, 0}), // RIGHT - UP
std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ -1, 0, 0, 0}) // DOWN - LEFT
// Input Expected // Invert X then Rotate 90
// std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, -1, 0, 0}), // LEFT - UP
// std::make_pair(SimpleReport{ 0, -1, 0, 0}, SimpleReport{ -1, 0, 0, 0}), // UP - LEFT
// std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // RIGHT - DOWN
// std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}) // DOWN - RIGHT
));
// clang-format on

View file

@ -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

View file

@ -0,0 +1,2 @@
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = custom

View file

@ -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 PointingInvertXYParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {};
TEST_P(PointingInvertXYParametrized, PointingInvertXY) {
TestDriver driver;
SimpleReport input = GetParam().first;
SimpleReport expectations = GetParam().second;
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);
pd_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(
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})
));
// clang-format on

View file

@ -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

View file

@ -0,0 +1,2 @@
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = custom

View file

@ -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 PointingRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {};
TEST_P(PointingRotateParametrized, PointingRotateXY) {
TestDriver driver;
SimpleReport input = GetParam().first;
SimpleReport expectations = GetParam().second;
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);
pd_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(
Rotate180,
PointingRotateParametrized,
::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

View file

@ -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

View file

@ -0,0 +1,2 @@
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = custom

View file

@ -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 PointingRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {};
TEST_P(PointingRotateParametrized, PointingRotateXY) {
TestDriver driver;
SimpleReport input = GetParam().first;
SimpleReport expectations = GetParam().second;
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);
pd_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(
Rotate270,
PointingRotateParametrized,
::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

View file

@ -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

View file

@ -0,0 +1,2 @@
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = custom

View file

@ -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 PointingRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {};
TEST_P(PointingRotateParametrized, PointingRotateXY) {
TestDriver driver;
SimpleReport input = GetParam().first;
SimpleReport expectations = GetParam().second;
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);
pd_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(
Rotate90,
PointingRotateParametrized,
::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

4
tests/pointing/test.mk Normal file
View file

@ -0,0 +1,4 @@
POINTING_DEVICE_ENABLE = yes
MOUSEKEY_ENABLE = no
POINTING_DEVICE_DRIVER = custom

View file

@ -0,0 +1,166 @@
// 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"
#include "mousekey.h"
using testing::_;
class Pointing : public TestFixture {};
class PointingButtonsViaMousekeysParametrized : public ::testing::WithParamInterface<std::pair<KeymapKey, uint8_t>>, public Pointing {};
TEST_F(Pointing, SendMouseIsNotCalledWithNoInput) {
TestDriver driver;
EXPECT_NO_MOUSE_REPORT(driver);
run_one_scan_loop();
}
TEST_F(Pointing, Xnegative) {
TestDriver driver;
pd_set_x(-10);
EXPECT_MOUSE_REPORT(driver, (-10, 0, 0, 0, 0));
run_one_scan_loop();
pd_clear_movement();
// EXPECT_EMPTY_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
TEST_F(Pointing, Xpositive) {
TestDriver driver;
pd_set_x(10);
EXPECT_MOUSE_REPORT(driver, (10, 0, 0, 0, 0));
run_one_scan_loop();
pd_clear_movement();
// EXPECT_EMPTY_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
TEST_F(Pointing, Ynegative) {
TestDriver driver;
pd_set_y(-20);
EXPECT_MOUSE_REPORT(driver, (0, -20, 0, 0, 0));
run_one_scan_loop();
pd_clear_movement();
// EXPECT_EMPTY_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
TEST_F(Pointing, Ypositive) {
TestDriver driver;
pd_set_y(20);
EXPECT_MOUSE_REPORT(driver, (0, 20, 0, 0, 0));
run_one_scan_loop();
pd_clear_movement();
// EXPECT_EMPTY_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
TEST_F(Pointing, XandY) {
TestDriver driver;
pd_set_x(-50);
pd_set_y(100);
EXPECT_MOUSE_REPORT(driver, (-50, 100, 0, 0, 0));
run_one_scan_loop();
pd_clear_movement();
// EXPECT_EMPTY_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
TEST_F(Pointing, CorrectButtonIsReportedWhenPressed) {
TestDriver driver;
EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, 1));
pd_press_button(POINTING_DEVICE_BUTTON1);
run_one_scan_loop();
EXPECT_EMPTY_MOUSE_REPORT(driver);
pd_release_button(POINTING_DEVICE_BUTTON1);
run_one_scan_loop();
EXPECT_NO_MOUSE_REPORT(driver);
run_one_scan_loop();
pd_clear_all_buttons();
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
TEST_F(Pointing, CorrectButtonIsReportedWhenKeyPressed) {
TestDriver driver;
auto key = KeymapKey(0, 0, 0, KC_MS_BTN1);
set_keymap({key});
EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, 1));
key.press();
run_one_scan_loop();
EXPECT_EMPTY_MOUSE_REPORT(driver);
key.release();
run_one_scan_loop();
EXPECT_NO_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
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, (0, 0, 0, 0, button_mask));
mouse_key.press();
run_one_scan_loop();
EXPECT_EMPTY_MOUSE_REPORT(driver);
mouse_key.release();
run_one_scan_loop();
EXPECT_NO_MOUSE_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
// clang-format off
INSTANTIATE_TEST_CASE_P(
ButtonsOneToEight,
PointingButtonsViaMousekeysParametrized,
::testing::Values(
// 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