From 82f64763beb04aea58fce457d0b569ff3b2be42a Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 20 Jun 2026 00:09:34 -0400 Subject: [PATCH] refactor(sonar): grouped fixes --- src/core/runtime.cpp | 22 ++++++---- src/core/types.cpp | 3 +- src/include/libvirtualhid/runtime.hpp | 4 +- src/platform/linux/uhid_backend.cpp | 25 ++++++------ tests/fixtures/fixtures.cpp | 15 +++---- tests/fixtures/include/fixtures/fixtures.hpp | 6 +++ .../fixtures/linux_backend_test_hooks.hpp | 7 ++-- tests/fixtures/linux_backend_test_hooks.cpp | 40 ++++++++++--------- tests/unit/test_gamepad_lifecycle.cpp | 2 +- tests/unit/test_linux_backend.cpp | 3 +- tests/unit/test_linux_consumers.cpp | 23 +++++++---- tests/unit/test_report.cpp | 13 +++--- tests/unit/test_runtime.cpp | 2 +- 13 files changed, 92 insertions(+), 73 deletions(-) diff --git a/src/core/runtime.cpp b/src/core/runtime.cpp index fcf7d19..fa3f3ab 100644 --- a/src/core/runtime.cpp +++ b/src/core/runtime.cpp @@ -374,9 +374,9 @@ namespace lvh { }); } - void Gamepad::set_output_callback(OutputCallback callback) { + void Gamepad::set_output_callback(const OutputCallback &callback) { with_device(device_, [&callback](auto &device) { - device.output_callback = std::move(callback); + device.output_callback = callback; if (device.backend) { device.backend->set_output_callback(device.output_callback); } @@ -999,7 +999,8 @@ namespace lvh { state_->gamepads.emplace_back(device); }); - return {OperationStatus::success(), std::make_unique(detail::RuntimeConstructionToken {}, std::move(device))}; + auto gamepad = std::make_unique(detail::RuntimeConstructionToken {}, std::move(device)); + return {OperationStatus::success(), std::move(gamepad)}; } KeyboardCreationResult Runtime::create_keyboard() { @@ -1027,7 +1028,8 @@ namespace lvh { state_->keyboards.emplace_back(device); }); - return {OperationStatus::success(), std::make_unique(detail::RuntimeConstructionToken {}, std::move(device))}; + auto keyboard = std::make_unique(detail::RuntimeConstructionToken {}, std::move(device)); + return {OperationStatus::success(), std::move(keyboard)}; } MouseCreationResult Runtime::create_mouse() { @@ -1055,7 +1057,8 @@ namespace lvh { state_->mice.emplace_back(device); }); - return {OperationStatus::success(), std::make_unique(detail::RuntimeConstructionToken {}, std::move(device))}; + auto mouse = std::make_unique(detail::RuntimeConstructionToken {}, std::move(device)); + return {OperationStatus::success(), std::move(mouse)}; } TouchscreenCreationResult Runtime::create_touchscreen() { @@ -1083,7 +1086,8 @@ namespace lvh { state_->touchscreens.emplace_back(device); }); - return {OperationStatus::success(), std::make_unique(detail::RuntimeConstructionToken {}, std::move(device))}; + auto touchscreen = std::make_unique(detail::RuntimeConstructionToken {}, std::move(device)); + return {OperationStatus::success(), std::move(touchscreen)}; } TrackpadCreationResult Runtime::create_trackpad() { @@ -1111,7 +1115,8 @@ namespace lvh { state_->trackpads.emplace_back(device); }); - return {OperationStatus::success(), std::make_unique(detail::RuntimeConstructionToken {}, std::move(device))}; + auto trackpad = std::make_unique(detail::RuntimeConstructionToken {}, std::move(device)); + return {OperationStatus::success(), std::move(trackpad)}; } PenTabletCreationResult Runtime::create_pen_tablet() { @@ -1139,7 +1144,8 @@ namespace lvh { state_->pen_tablets.emplace_back(device); }); - return {OperationStatus::success(), std::make_unique(detail::RuntimeConstructionToken {}, std::move(device))}; + auto pen_tablet = std::make_unique(detail::RuntimeConstructionToken {}, std::move(device)); + return {OperationStatus::success(), std::move(pen_tablet)}; } std::size_t Runtime::active_device_count() const { diff --git a/src/core/types.cpp b/src/core/types.cpp index 42f32b4..077e735 100644 --- a/src/core/types.cpp +++ b/src/core/types.cpp @@ -12,8 +12,7 @@ namespace lvh { OperationStatus::OperationStatus(): - code_ {ErrorCode::ok}, - message_ {} {} + code_ {ErrorCode::ok} {} OperationStatus::OperationStatus(ErrorCode code, std::string message): code_ {code}, diff --git a/src/include/libvirtualhid/runtime.hpp b/src/include/libvirtualhid/runtime.hpp index bd4bced..5be54d2 100644 --- a/src/include/libvirtualhid/runtime.hpp +++ b/src/include/libvirtualhid/runtime.hpp @@ -170,9 +170,9 @@ namespace lvh { /** * @brief Register a callback for backend output events. * - * @param callback Output callback. Passing an empty callback clears it. + * @param callback Output callback copied into the handle. Passing an empty callback clears it. */ - void set_output_callback(OutputCallback callback); + void set_output_callback(const OutputCallback &callback); /** * @brief Dispatch an output event to the registered callback. diff --git a/src/platform/linux/uhid_backend.cpp b/src/platform/linux/uhid_backend.cpp index e8d4e6a..ce24e4c 100644 --- a/src/platform/linux/uhid_backend.cpp +++ b/src/platform/linux/uhid_backend.cpp @@ -338,14 +338,14 @@ namespace lvh::detail { } template - void copy_string(__u8 (&destination)[Size], const std::string &source) { + void copy_string(__u8 (&destination)[Size], std::string_view source) { const auto length = std::min(source.size(), Size - 1); std::memcpy(destination, source.data(), length); destination[length] = 0; } template - void copy_string(char (&destination)[Size], const std::string &source) { + void copy_string(char (&destination)[Size], std::string_view source) { const auto length = std::min(source.size(), Size - 1); std::memcpy(destination, source.data(), length); destination[length] = 0; @@ -373,7 +373,7 @@ namespace lvh::detail { nodes.push_back({.kind = kind, .path = path.string()}); } - bool hidraw_name_matches(const std::filesystem::path &uevent_path, const std::string &name) { + bool hidraw_name_matches(const std::filesystem::path &uevent_path, std::string_view name) { std::ifstream file {uevent_path}; if (!file) { return false; @@ -381,9 +381,9 @@ namespace lvh::detail { std::string line; while (std::getline(file, line)) { - constexpr auto key = "HID_NAME="; + constexpr std::string_view key {"HID_NAME="}; if (line.starts_with(key)) { - return line.substr(std::char_traits::length(key)) == name; + return line.size() == key.size() + name.size() && line.ends_with(name); } } @@ -1451,7 +1451,7 @@ namespace lvh::detail { } const auto slot = slot_for_contact(contact.id); - if (!slot) { + if (!slot.has_value()) { return OperationStatus::failure(ErrorCode::invalid_argument, "too many active touch contacts"); } @@ -2398,17 +2398,17 @@ namespace lvh::detail { event.u.get_report_reply.err = 0; switch (report_number) { case dualsense_calibration_report: - copy_get_report_payload(event, dualsense_calibration_info, sizeof(dualsense_calibration_info)); + copy_get_report_payload(event, dualsense_calibration_info); break; case dualsense_pairing_report: - copy_get_report_payload(event, dualsense_pairing_info, sizeof(dualsense_pairing_info)); + copy_get_report_payload(event, dualsense_pairing_info); for (std::size_t index = 0; index < dualsense_mac_address_.size(); ++index) { event.u.get_report_reply.data[1U + index] = dualsense_mac_address_[dualsense_mac_address_.size() - 1U - index]; } break; case dualsense_firmware_report: - copy_get_report_payload(event, dualsense_firmware_info, sizeof(dualsense_firmware_info)); + copy_get_report_payload(event, dualsense_firmware_info); break; default: event.u.get_report_reply.err = EINVAL; @@ -2429,10 +2429,9 @@ namespace lvh::detail { static_cast(write_event(event)); } - template - void copy_get_report_payload(uhid_event &event, const std::uint8_t (&payload)[Size], std::size_t payload_size) { - event.u.get_report_reply.size = static_cast(std::min(payload_size, UHID_DATA_MAX)); - std::memcpy(event.u.get_report_reply.data, payload, event.u.get_report_reply.size); + static void copy_get_report_payload(uhid_event &event, std::span payload) { + event.u.get_report_reply.size = static_cast(std::min(payload.size(), UHID_DATA_MAX)); + std::memcpy(event.u.get_report_reply.data, payload.data(), event.u.get_report_reply.size); } void send_set_report_reply(std::uint32_t id, std::uint16_t error) { diff --git a/tests/fixtures/fixtures.cpp b/tests/fixtures/fixtures.cpp index cb5279a..75c8c55 100644 --- a/tests/fixtures/fixtures.cpp +++ b/tests/fixtures/fixtures.cpp @@ -37,12 +37,11 @@ void BaseTest::TearDown() { } } -void LinuxTest::SetUp() { #if !defined(__linux__) +void LinuxTest::SetUp() { GTEST_SKIP() << "Skipping, this test is for Linux only."; -#endif - BaseTest::SetUp(); } +#endif ::testing::AssertionResult LinuxTest::HasReadableWritableDeviceNode(const char *path) { #if defined(__linux__) @@ -57,16 +56,14 @@ ::testing::AssertionResult LinuxTest::HasReadableWritableDeviceNode(const char * #endif } -void MacOSTest::SetUp() { #if !defined(__APPLE__) || !defined(__MACH__) +void MacOSTest::SetUp() { GTEST_SKIP() << "Skipping, this test is for macOS only."; -#endif - BaseTest::SetUp(); } +#endif -void WindowsTest::SetUp() { #if !defined(_WIN32) +void WindowsTest::SetUp() { GTEST_SKIP() << "Skipping, this test is for Windows only."; -#endif - BaseTest::SetUp(); } +#endif diff --git a/tests/fixtures/include/fixtures/fixtures.hpp b/tests/fixtures/include/fixtures/fixtures.hpp index 0b3a7de..ac0a275 100644 --- a/tests/fixtures/include/fixtures/fixtures.hpp +++ b/tests/fixtures/include/fixtures/fixtures.hpp @@ -36,10 +36,12 @@ class BaseTest: public ::testing::Test { */ class LinuxTest: public BaseTest { protected: +#if !defined(__linux__) /** * @brief Set up the test. */ void SetUp() override; +#endif /** * @brief Check that a Linux device node is readable and writable. @@ -55,10 +57,12 @@ class LinuxTest: public BaseTest { */ class MacOSTest: public BaseTest { protected: +#if !defined(__APPLE__) || !defined(__MACH__) /** * @brief Set up the test. */ void SetUp() override; +#endif }; /** @@ -66,10 +70,12 @@ class MacOSTest: public BaseTest { */ class WindowsTest: public BaseTest { protected: +#if !defined(_WIN32) /** * @brief Set up the test. */ void SetUp() override; +#endif }; // Undefine the original TEST macro. diff --git a/tests/fixtures/include/fixtures/linux_backend_test_hooks.hpp b/tests/fixtures/include/fixtures/linux_backend_test_hooks.hpp index ed0275f..3a93655 100644 --- a/tests/fixtures/include/fixtures/linux_backend_test_hooks.hpp +++ b/tests/fixtures/include/fixtures/linux_backend_test_hooks.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include // local includes @@ -418,7 +419,7 @@ namespace lvh::detail::test { * @param expected Expected first line. * @return `true` when the first line exists and matches. */ - bool linux_first_line_matches(const std::string &path, const std::string &expected); + bool linux_first_line_matches(std::string_view path, std::string_view expected); /** * @brief Check whether reading the first line of a file fails. @@ -426,7 +427,7 @@ namespace lvh::detail::test { * @param path File path to read. * @return `true` when no first line could be read. */ - bool linux_first_line_missing(const std::string &path); + bool linux_first_line_missing(std::string_view path); /** * @brief Check whether a hidraw uevent file advertises the expected HID name. @@ -435,7 +436,7 @@ namespace lvh::detail::test { * @param name Expected HID name. * @return `true` when the HID name matches. */ - bool linux_hidraw_name_matches(const std::string &path, const std::string &name); + bool linux_hidraw_name_matches(std::string_view path, std::string_view name); /** * @brief Discover Linux input nodes for a device name. diff --git a/tests/fixtures/linux_backend_test_hooks.cpp b/tests/fixtures/linux_backend_test_hooks.cpp index 74f145f..01886cc 100644 --- a/tests/fixtures/linux_backend_test_hooks.cpp +++ b/tests/fixtures/linux_backend_test_hooks.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -347,20 +348,20 @@ extern "C" libevdev *lvh_linux_test_libevdev_new() { return nullptr; } auto fake_device = std::make_unique(); - auto *device = fake_device.get(); + auto *created_device = fake_device.get(); lvh::detail::test::active_test_syscalls->owned_libevdev_devices.push_back(std::move(fake_device)); - return lvh::detail::test::libevdev_handle(device); + return lvh::detail::test::libevdev_handle(created_device); } return ::libevdev_new(); } extern "C" void lvh_linux_test_libevdev_free(libevdev *device) { if (lvh::detail::test::active_test_syscalls != nullptr && lvh::detail::test::active_test_syscalls->override_libevdev) { - auto *fake_device = lvh::detail::test::fake_libevdev_device(device); + auto *fake_device_handle = lvh::detail::test::fake_libevdev_device(device); static_cast(std::erase_if( lvh::detail::test::active_test_syscalls->owned_libevdev_devices, - [fake_device](const auto &owned_device) { - return owned_device.get() == fake_device; + [fake_device_handle](const auto &owned_device) { + return owned_device.get() == fake_device_handle; } )); return; @@ -470,11 +471,12 @@ extern "C" int lvh_linux_test_libevdev_uinput_create_from_device( return -EIO; } - const auto &fake_device = *lvh::detail::test::fake_libevdev_device(device); - lvh::detail::test::active_test_syscalls->libevdev_devices.push_back(fake_device); - auto fake_uinput_device = std::make_unique(lvh::detail::test::FakeLibevdevUinput {fake_device}); - auto *created_uinput_device = fake_uinput_device.get(); - lvh::detail::test::active_test_syscalls->owned_libevdev_uinput_devices.push_back(std::move(fake_uinput_device)); + const auto &source_device = *lvh::detail::test::fake_libevdev_device(device); + lvh::detail::test::active_test_syscalls->libevdev_devices.push_back(source_device); + auto owned_uinput_device = + std::make_unique(lvh::detail::test::FakeLibevdevUinput {source_device}); + auto *created_uinput_device = owned_uinput_device.get(); + lvh::detail::test::active_test_syscalls->owned_libevdev_uinput_devices.push_back(std::move(owned_uinput_device)); *uinput_device = lvh::detail::test::libevdev_uinput_handle(created_uinput_device); return 0; } @@ -484,11 +486,11 @@ extern "C" int lvh_linux_test_libevdev_uinput_create_from_device( extern "C" void lvh_linux_test_libevdev_uinput_destroy(libevdev_uinput *uinput_device) { if (lvh::detail::test::active_test_syscalls != nullptr && lvh::detail::test::active_test_syscalls->override_libevdev) { ++lvh::detail::test::active_test_syscalls->libevdev_destroy_count; - auto *fake_uinput_device = lvh::detail::test::fake_libevdev_uinput(uinput_device); + auto *fake_uinput_handle = lvh::detail::test::fake_libevdev_uinput(uinput_device); static_cast(std::erase_if( lvh::detail::test::active_test_syscalls->owned_libevdev_uinput_devices, - [fake_uinput_device](const auto &owned_device) { - return owned_device.get() == fake_uinput_device; + [fake_uinput_handle](const auto &owned_device) { + return owned_device.get() == fake_uinput_handle; } )); return; @@ -859,17 +861,17 @@ namespace lvh::detail::test { return format_mac_address(parse_mac_address(stable_id).value_or(generated_mac_address(id))); } - bool linux_first_line_matches(const std::string &path, const std::string &expected) { - const auto line = read_first_line(path); + bool linux_first_line_matches(std::string_view path, std::string_view expected) { + const auto line = read_first_line(std::filesystem::path {std::string {path}}); return line && *line == expected; } - bool linux_first_line_missing(const std::string &path) { - return !read_first_line(path); + bool linux_first_line_missing(std::string_view path) { + return !read_first_line(std::filesystem::path {std::string {path}}); } - bool linux_hidraw_name_matches(const std::string &path, const std::string &name) { - return hidraw_name_matches(path, name); + bool linux_hidraw_name_matches(std::string_view path, std::string_view name) { + return hidraw_name_matches(std::filesystem::path {std::string {path}}, name); } std::vector linux_discover_nodes_by_name(const std::string &name) { diff --git a/tests/unit/test_gamepad_lifecycle.cpp b/tests/unit/test_gamepad_lifecycle.cpp index b362656..b81baa1 100644 --- a/tests/unit/test_gamepad_lifecycle.cpp +++ b/tests/unit/test_gamepad_lifecycle.cpp @@ -32,7 +32,7 @@ TEST(GamepadLifecycleTest, ExercisesArrivalUpdateFeedbackAndRemoval) { EXPECT_TRUE(created.gamepad->profile().capabilities.supports_touchpad); bool feedback_received = false; - created.gamepad->set_output_callback([&](const lvh::GamepadOutput &output) { + created.gamepad->set_output_callback([&feedback_received](const lvh::GamepadOutput &output) { feedback_received = output.kind == lvh::GamepadOutputKind::rumble && output.low_frequency_rumble == 0x4000 && output.high_frequency_rumble == 0x2000; diff --git a/tests/unit/test_linux_backend.cpp b/tests/unit/test_linux_backend.cpp index e0fb6ac..b03b1e4 100644 --- a/tests/unit/test_linux_backend.cpp +++ b/tests/unit/test_linux_backend.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -660,7 +661,7 @@ TEST_F(LinuxBackendTest, FakeUinputConstructionCoversCapabilitiesAndFailureBranc const auto it = std::ranges::find_if(result.event_codes, [type, code](const auto &event_code) { return event_code.type == type && event_code.code == code; }); - return it == result.event_codes.end() ? nullptr : &(*it); + return it == result.event_codes.end() ? nullptr : std::to_address(it); }; const auto keyboard = lvh::detail::test::linux_uinput_create_fake_libevdev_device(lvh::DeviceType::keyboard); diff --git a/tests/unit/test_linux_consumers.cpp b/tests/unit/test_linux_consumers.cpp index 387618e..d48f65f 100644 --- a/tests/unit/test_linux_consumers.cpp +++ b/tests/unit/test_linux_consumers.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -82,8 +83,14 @@ namespace { /** * @brief Execute the cleanup function. */ - ~ScopeExit() { - function_(); + ~ScopeExit() noexcept { + try { + function_(); + } catch (const std::exception &exception) { + ADD_FAILURE() << "Scope-exit cleanup failed: " << exception.what(); + } catch (...) { + ADD_FAILURE() << "Scope-exit cleanup failed with an unknown exception."; + } } ScopeExit(const ScopeExit &) = delete; @@ -322,9 +329,9 @@ namespace { SDL_SetHint("SDL_JOYSTICK_HIDAPI_PS5", "1"); } - lvh::GamepadCreationResult create_sdl_gamepad(lvh::Runtime &runtime, SdlGamepadConsumerCase test_case) { + lvh::GamepadCreationResult create_sdl_gamepad(lvh::Runtime &runtime, const SdlGamepadConsumerCase &test_case) { lvh::CreateGamepadOptions options; - options.profile = std::move(test_case.profile); + options.profile = test_case.profile; options.profile.name = unique_device_name(test_case.name_suffix); options.metadata.stable_id = std::string {test_case.stable_id}; @@ -346,7 +353,7 @@ namespace { } } - void run_sdl_uhid_joystick_test(SdlGamepadConsumerCase test_case) { + void run_sdl_uhid_joystick_test(const SdlGamepadConsumerCase &test_case) { configure_sdl_hidapi_hints(); ASSERT_EQ(SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_EVENTS), 0) << SDL_GetError(); ScopeExit sdl_quit {[]() { @@ -370,7 +377,7 @@ namespace { const auto joystick_index = wait_for_sdl_joystick(expected_profile); ASSERT_GE(joystick_index, 0); - SdlJoystick joystick {SDL_JoystickOpen(joystick_index), SDL_JoystickClose}; + SdlJoystick joystick {SDL_JoystickOpen(joystick_index), &SDL_JoystickClose}; ASSERT_NE(joystick.get(), nullptr) << SDL_GetError(); expect_sdl_joystick_profile( joystick.get(), @@ -387,7 +394,7 @@ namespace { EXPECT_TRUE(wait_for_sdl_gamepad_input(joystick.get())) << describe_sdl_state(joystick.get()); } - void run_sdl_dualsense_controller_test(SdlGamepadConsumerCase test_case) { + void run_sdl_dualsense_controller_test(const SdlGamepadConsumerCase &test_case) { configure_sdl_hidapi_hints(); ASSERT_EQ(SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS), 0) << SDL_GetError(); ScopeExit sdl_quit {[]() { @@ -412,7 +419,7 @@ namespace { ASSERT_GE(joystick_index, 0); ASSERT_EQ(SDL_IsGameController(joystick_index), SDL_TRUE) << SDL_GetError(); - SdlGameController controller {SDL_GameControllerOpen(joystick_index), SDL_GameControllerClose}; + SdlGameController controller {SDL_GameControllerOpen(joystick_index), &SDL_GameControllerClose}; ASSERT_NE(controller.get(), nullptr) << SDL_GetError(); auto *joystick = SDL_GameControllerGetJoystick(controller.get()); diff --git a/tests/unit/test_report.cpp b/tests/unit/test_report.cpp index 7b71174..ebe58ca 100644 --- a/tests/unit/test_report.cpp +++ b/tests/unit/test_report.cpp @@ -5,6 +5,7 @@ // standard includes #include +#include #include // local includes @@ -14,10 +15,10 @@ #include namespace { - std::uint32_t test_crc32(const std::uint8_t *buffer, std::size_t length, std::uint32_t seed = 0) { + std::uint32_t test_crc32(std::span buffer, std::uint32_t seed = 0) { auto crc = seed ^ 0xFFFFFFFFU; - for (std::size_t index = 0; index < length; ++index) { - crc ^= buffer[index]; + for (const auto byte : buffer) { + crc ^= byte; for (auto bit = 0; bit < 8; ++bit) { const auto mask = 0U - (crc & 1U); crc = (crc >> 1U) ^ (0xEDB88320U & mask); @@ -27,7 +28,7 @@ namespace { } std::uint32_t test_dualsense_crc_seed(std::uint8_t seed) { - return test_crc32(&seed, 1U); + return test_crc32(std::span {&seed, 1U}); } std::uint32_t read_u32_le(const std::vector &bytes, std::size_t offset) { @@ -146,7 +147,7 @@ TEST(ReportTest, PacksDualSenseBluetoothReportWithCrc) { EXPECT_EQ(report[55], 0x0C); const auto crc_offset = report.size() - 4U; - const auto expected_crc = test_crc32(report.data(), crc_offset, test_dualsense_crc_seed(0xA1)); + const auto expected_crc = test_crc32(std::span {report}.first(crc_offset), test_dualsense_crc_seed(0xA1)); EXPECT_EQ(read_u32_le(report, crc_offset), expected_crc); } @@ -213,7 +214,7 @@ TEST(ReportTest, ParsesDualSenseBluetoothOutputReportEvents) { report[47] = 0x22; report[48] = 0x33; const auto crc_offset = report.size() - 4U; - const auto crc = test_crc32(report.data(), crc_offset, test_dualsense_crc_seed(0xA2)); + const auto crc = test_crc32(std::span {report}.first(crc_offset), test_dualsense_crc_seed(0xA2)); report[crc_offset] = static_cast(crc & 0xFFU); report[crc_offset + 1U] = static_cast((crc >> 8U) & 0xFFU); report[crc_offset + 2U] = static_cast((crc >> 16U) & 0xFFU); diff --git a/tests/unit/test_runtime.cpp b/tests/unit/test_runtime.cpp index 1ff34a2..bb012de 100644 --- a/tests/unit/test_runtime.cpp +++ b/tests/unit/test_runtime.cpp @@ -83,7 +83,7 @@ TEST(RuntimeTest, DispatchesOutputCallback) { lvh::GamepadOutput received; bool was_called = false; - created.gamepad->set_output_callback([&](const lvh::GamepadOutput &output) { + created.gamepad->set_output_callback([&received, &was_called](const lvh::GamepadOutput &output) { received = output; was_called = true; });