Skip to content

Commit

Permalink
tests: added unit tests for joypads using SDL2
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Jan 24, 2024
1 parent 99ed7fe commit 12e90b3
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 54 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linux-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
libudev-dev \
libdrm-dev \
libpci-dev \
libunwind-dev
libunwind-dev \
libsdl2-dev
- name: Setup Rust
uses: ATiltedTree/setup-rust@v1
Expand Down Expand Up @@ -120,6 +121,7 @@ jobs:
libdrm-dev \
libpci-dev \
libunwind-dev \
libsdl2-dev
${{ join(matrix.other_pkgs, ' ') }}
- name: Setup Rust
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/core/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ class Joypad : public VirtualDevice {
void set_triggers(unsigned char left, unsigned char right);

enum STICK_POSITION {
R2,
L2
RS,
LS
};

void set_stick(STICK_POSITION stick_type, short x, short y);
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/platforms/linux/uinput/joypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ void Joypad::set_pressed_buttons(int newly_pressed) {

void Joypad::set_stick(Joypad::STICK_POSITION stick_type, short x, short y) {
if (auto controller = this->_state->joy.get()) {
if (stick_type == L2) {
if (stick_type == LS) {
libevdev_uinput_write_event(controller, EV_ABS, ABS_X, x);
libevdev_uinput_write_event(controller, EV_ABS, ABS_Y, -y);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/moonlight-server/control/input_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ void handle_input(const state::StreamSession &session,
Joypad::ANALOG_TRIGGERS | Joypad::RUMBLE);
}
selected_pad->set_pressed_buttons(controller_pkt->button_flags | (controller_pkt->buttonFlags2 << 16));
selected_pad->set_stick(Joypad::L2, controller_pkt->left_stick_x, controller_pkt->left_stick_y);
selected_pad->set_stick(Joypad::R2, controller_pkt->right_stick_x, controller_pkt->right_stick_y);
selected_pad->set_stick(Joypad::LS, controller_pkt->left_stick_x, controller_pkt->left_stick_y);
selected_pad->set_stick(Joypad::RS, controller_pkt->right_stick_x, controller_pkt->right_stick_y);
selected_pad->set_triggers(controller_pkt->left_trigger, controller_pkt->right_trigger);
break;
}
Expand Down
16 changes: 8 additions & 8 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ if (UNIX AND NOT APPLE)
if (TEST_NVIDIA)
list(APPEND SRC_LIST "platforms/linux/nvidia.cpp")
endif ()

option(TEST_SDL "Enabled SDL tests" OFF) # TODO: SDL does pick up my joypad but it doesn't detect gyro/acceleration
if (TEST_SDL)
find_package(SDL2 REQUIRED)
target_include_directories(wolftests PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(wolftests PRIVATE SDL2::SDL2)
list(APPEND SRC_LIST "platforms/linux/sdl-test-joypad.cpp")
endif ()
endif ()

option(TEST_DOCKER "Enable docker tests" ON)
Expand All @@ -57,6 +49,14 @@ if (TEST_EXCEPTIONS)
list(APPEND SRC_LIST testExceptions.cpp)
endif ()

option(TEST_SDL "Enabled SDL tests" ON)
if (TEST_SDL)
find_package(SDL2 REQUIRED)
target_include_directories(wolftests PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(wolftests PRIVATE SDL2::SDL2)
list(APPEND SRC_LIST "testJoypads.cpp")
endif ()

target_sources(wolftests PRIVATE ${SRC_LIST})

# I'm using C++17 in the test
Expand Down
40 changes: 0 additions & 40 deletions tests/platforms/linux/sdl-test-joypad.cpp

This file was deleted.

Loading

0 comments on commit 12e90b3

Please sign in to comment.