Sunshine/tests/unit/test_mouse.cpp
ns6089 764ce03520
Some checks failed
CI / GitHub Env Debug (push) Waiting to run
CI / Setup Release (push) Waiting to run
CI / Setup Flatpak Matrix (push) Waiting to run
CI / Linux Flatpak (push) Blocked by required conditions
CI / Linux ${{ matrix.type }} (--appimage-build, 22.04, AppImage) (push) Blocked by required conditions
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (macos, 12) (push) Blocked by required conditions
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (macos, 13) (push) Blocked by required conditions
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (macos, 14) (push) Blocked by required conditions
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (ubuntu, latest) (push) Blocked by required conditions
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (ubuntu, latest, true) (push) Blocked by required conditions
CI / Macports (macOS-${{ matrix.os_version }}) (12, true) (push) Blocked by required conditions
CI / Macports (macOS-${{ matrix.os_version }}) (13) (push) Blocked by required conditions
CI / Macports (macOS-${{ matrix.os_version }}) (14) (push) Blocked by required conditions
CI / Windows (push) Blocked by required conditions
CI Docker / Check Dockerfiles (push) Waiting to run
CI Docker / Setup Release (push) Blocked by required conditions
CI Docker / Lint Dockerfile${{ matrix.tag }} (push) Blocked by required conditions
CI Docker / Docker${{ matrix.tag }} (push) Blocked by required conditions
CodeQL / Get language matrix (push) Waiting to run
CodeQL / Analyze (${{ matrix.name }}) (push) Blocked by required conditions
Build GH-Pages / update_pages (push) Waiting to run
localize / Update Localization (push) Has been cancelled
feat(tests): rework tests in numerous ways (#3059)
2024-08-22 16:48:24 -04:00

121 lines
3.6 KiB
C++

/**
* @file tests/unit/test_mouse.cpp
* @brief Test src/input.*.
*/
#include <src/input.h>
#include "../tests_common.h"
struct MouseHIDTest: PlatformTestSuite, testing::WithParamInterface<util::point_t> {
void
SetUp() override {
#ifdef _WIN32
// TODO: Windows tests are failing, `get_mouse_loc` seems broken and `platf::abs_mouse` too
// the alternative `platf::abs_mouse` method seem to work better during tests,
// but I'm not sure about real work
GTEST_SKIP() << "TODO Windows";
#elif __linux__
// TODO: Inputtino waiting https://github.com/games-on-whales/inputtino/issues/6 is resolved.
GTEST_SKIP() << "TODO Inputtino";
#endif
}
void
TearDown() override {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
};
INSTANTIATE_TEST_SUITE_P(
MouseInputs,
MouseHIDTest,
testing::Values(
util::point_t { 40, 40 },
util::point_t { 70, 150 }));
// todo: add tests for hitting screen edges
TEST_P(MouseHIDTest, MoveInputTest) {
util::point_t mouse_delta = GetParam();
BOOST_LOG(tests) << "MoveInputTest:: got param: " << mouse_delta;
platf::input_t input = platf::input();
BOOST_LOG(tests) << "MoveInputTest:: init input";
BOOST_LOG(tests) << "MoveInputTest:: get current mouse loc";
auto old_loc = platf::get_mouse_loc(input);
BOOST_LOG(tests) << "MoveInputTest:: got current mouse loc: " << old_loc;
BOOST_LOG(tests) << "MoveInputTest:: move: " << mouse_delta;
platf::move_mouse(input, mouse_delta.x, mouse_delta.y);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
BOOST_LOG(tests) << "MoveInputTest:: moved: " << mouse_delta;
BOOST_LOG(tests) << "MoveInputTest:: get updated mouse loc";
auto new_loc = platf::get_mouse_loc(input);
BOOST_LOG(tests) << "MoveInputTest:: got updated mouse loc: " << new_loc;
bool has_input_moved = old_loc.x != new_loc.x && old_loc.y != new_loc.y;
if (!has_input_moved) {
BOOST_LOG(tests) << "MoveInputTest:: haven't moved";
}
else {
BOOST_LOG(tests) << "MoveInputTest:: moved";
}
EXPECT_TRUE(has_input_moved);
// Verify we moved as much as we requested
EXPECT_EQ(new_loc.x - old_loc.x, mouse_delta.x);
EXPECT_EQ(new_loc.y - old_loc.y, mouse_delta.y);
}
TEST_P(MouseHIDTest, AbsMoveInputTest) {
util::point_t mouse_pos = GetParam();
BOOST_LOG(tests) << "AbsMoveInputTest:: got param: " << mouse_pos;
platf::input_t input = platf::input();
BOOST_LOG(tests) << "AbsMoveInputTest:: init input";
BOOST_LOG(tests) << "AbsMoveInputTest:: get current mouse loc";
auto old_loc = platf::get_mouse_loc(input);
BOOST_LOG(tests) << "AbsMoveInputTest:: got current mouse loc: " << old_loc;
#ifdef _WIN32
platf::touch_port_t abs_port {
0, 0,
65535, 65535
};
#elif __linux__
platf::touch_port_t abs_port {
0, 0,
19200, 12000
};
#else
platf::touch_port_t abs_port {};
#endif
BOOST_LOG(tests) << "AbsMoveInputTest:: move: " << mouse_pos;
platf::abs_mouse(input, abs_port, mouse_pos.x, mouse_pos.y);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
BOOST_LOG(tests) << "AbsMoveInputTest:: moved: " << mouse_pos;
BOOST_LOG(tests) << "AbsMoveInputTest:: get updated mouse loc";
auto new_loc = platf::get_mouse_loc(input);
BOOST_LOG(tests) << "AbsMoveInputTest:: got updated mouse loc: " << new_loc;
bool has_input_moved = old_loc.x != new_loc.x || old_loc.y != new_loc.y;
if (!has_input_moved) {
BOOST_LOG(tests) << "AbsMoveInputTest:: haven't moved";
}
else {
BOOST_LOG(tests) << "AbsMoveInputTest:: moved";
}
EXPECT_TRUE(has_input_moved);
// Verify we moved to the absolute coordinate
EXPECT_EQ(new_loc.x, mouse_pos.x);
EXPECT_EQ(new_loc.y, mouse_pos.y);
}