From 73028cb14942fe1b1ae0c93f16d46a22e1c0aff7 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 28 Jun 2026 20:36:32 -0400 Subject: [PATCH 1/4] Use lizardbyte-common test fixtures Replace local GoogleTest fixture implementations with `lizardbyte-common` testing support. The tests CMake now enables and links `lizardbyte::test_support`, adds the submodule when needed, and fails fast if required targets are missing. This removes duplicated fixture code in `tests/fixtures` and centralizes shared test behavior in the common submodule. --- .gitmodules | 3 - tests/CMakeLists.txt | 13 +++- tests/fixtures/fixtures.cpp | 69 ----------------- tests/fixtures/include/fixtures/fixtures.hpp | 80 +------------------- third-party/googletest | 1 - third-party/lizardbyte-common | 2 +- 6 files changed, 12 insertions(+), 156 deletions(-) delete mode 100644 tests/fixtures/fixtures.cpp delete mode 160000 third-party/googletest diff --git a/.gitmodules b/.gitmodules index 0c946a7..67e5376 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,9 +2,6 @@ path = third-party/doxyconfig url = https://github.com/LizardByte/doxyconfig.git branch = master -[submodule "third-party/googletest"] - path = third-party/googletest - url = https://github.com/google/googletest.git [submodule "third-party/lizardbyte-common"] path = third-party/lizardbyte-common url = https://github.com/LizardByte/lizardbyte-common.git diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f79f468..4802151 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,13 +9,19 @@ if(WIN32) endif() include(GoogleTest) -add_subdirectory("${PROJECT_SOURCE_DIR}/third-party/googletest" +add_subdirectory("${PROJECT_SOURCE_DIR}/third-party/lizardbyte-common/third-party/googletest" "third-party/googletest") +set(LIZARDBYTE_COMMON_BUILD_TEST_SUPPORT ON CACHE BOOL "Build lizardbyte-common GoogleTest support helpers" FORCE) +if(NOT TARGET lizardbyte::common) + add_subdirectory("${PROJECT_SOURCE_DIR}/third-party/lizardbyte-common" + "third-party/lizardbyte-common") +elseif(NOT TARGET lizardbyte::test_support) + message(FATAL_ERROR "libvirtualhid tests require lizardbyte::test_support") +endif() set(TEST_BINARY test_libvirtualhid) set(LIBVIRTUALHID_TEST_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/fixtures/fixtures.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/unit/test_gamepad_adapter.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/unit/test_gamepad_lifecycle.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/unit/test_linux_backend.cpp" @@ -55,7 +61,8 @@ target_include_directories(${TEST_BINARY} target_link_libraries(${TEST_BINARY} PRIVATE gmock_main - libvirtualhid::libvirtualhid) + libvirtualhid::libvirtualhid + lizardbyte::test_support) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries(${TEST_BINARY} diff --git a/tests/fixtures/fixtures.cpp b/tests/fixtures/fixtures.cpp deleted file mode 100644 index 75c8c55..0000000 --- a/tests/fixtures/fixtures.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @file tests/fixtures/fixtures.cpp - * @brief Shared GoogleTest fixture setup definitions. - */ - -// standard includes -#include - -// platform includes -#if defined(__linux__) - #include -#endif - -// local includes -#include "fixtures/fixtures.hpp" - -void BaseTest::SetUp() { - cout_buffer_.str({}); - cout_buffer_.clear(); - cout_streambuf_ = std::cout.rdbuf(); - std::cout.rdbuf(cout_buffer_.rdbuf()); -} - -void BaseTest::TearDown() { - if (cout_streambuf_ != nullptr) { - std::cout.rdbuf(cout_streambuf_); - cout_streambuf_ = nullptr; - } - - const auto *test_info = ::testing::UnitTest::GetInstance()->current_test_info(); - if (test_info != nullptr && test_info->result()->Failed()) { - std::cout << std::endl - << "Test failed: " << test_info->name() << std::endl - << std::endl - << "Captured cout:" << std::endl - << cout_buffer_.str() << std::endl; - } -} - -#if !defined(__linux__) -void LinuxTest::SetUp() { - GTEST_SKIP() << "Skipping, this test is for Linux only."; -} -#endif - -::testing::AssertionResult LinuxTest::HasReadableWritableDeviceNode(const char *path) { -#if defined(__linux__) - if (::access(path, R_OK | W_OK) == 0) { - return ::testing::AssertionSuccess(); - } - - return ::testing::AssertionFailure() << path << " must be readable and writable"; -#else - static_cast(path); - return ::testing::AssertionSuccess(); -#endif -} - -#if !defined(__APPLE__) || !defined(__MACH__) -void MacOSTest::SetUp() { - GTEST_SKIP() << "Skipping, this test is for macOS only."; -} -#endif - -#if !defined(_WIN32) -void WindowsTest::SetUp() { - GTEST_SKIP() << "Skipping, this test is for Windows only."; -} -#endif diff --git a/tests/fixtures/include/fixtures/fixtures.hpp b/tests/fixtures/include/fixtures/fixtures.hpp index ac0a275..388e079 100644 --- a/tests/fixtures/include/fixtures/fixtures.hpp +++ b/tests/fixtures/include/fixtures/fixtures.hpp @@ -4,83 +4,5 @@ */ #pragma once -// standard includes -#include -#include - // lib includes -#include - -/** - * @brief Base class used by default for every test. - */ -class BaseTest: public ::testing::Test { -protected: - /** - * @brief Set up the test. - */ - void SetUp() override; - - /** - * @brief Tear down the test. - */ - void TearDown() override; - -private: - std::stringstream cout_buffer_; - std::streambuf *cout_streambuf_ {nullptr}; -}; - -/** - * @brief Base class for Linux-only tests. - */ -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. - * - * @param path Device node path. - * @return GoogleTest assertion result. - */ - static ::testing::AssertionResult HasReadableWritableDeviceNode(const char *path); -}; - -/** - * @brief Base class for macOS-only tests. - */ -class MacOSTest: public BaseTest { -protected: -#if !defined(__APPLE__) || !defined(__MACH__) - /** - * @brief Set up the test. - */ - void SetUp() override; -#endif -}; - -/** - * @brief Base class for Windows-only tests. - */ -class WindowsTest: public BaseTest { -protected: -#if !defined(_WIN32) - /** - * @brief Set up the test. - */ - void SetUp() override; -#endif -}; - -// Undefine the original TEST macro. -#undef TEST // NOSONAR(cpp:S959): Tests intentionally wrap TEST to use BaseTest. - -// Redefine TEST to automatically use the shared BaseTest fixture. -#define TEST(test_case_name, test_name) \ - GTEST_TEST_(test_case_name, test_name, ::BaseTest, ::testing::internal::GetTypeId<::BaseTest>()) +#include diff --git a/third-party/googletest b/third-party/googletest deleted file mode 160000 index 52eb810..0000000 --- a/third-party/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 52eb8108c5bdec04579160ae17225d66034bd723 diff --git a/third-party/lizardbyte-common b/third-party/lizardbyte-common index 8d7dcc9..0fcde42 160000 --- a/third-party/lizardbyte-common +++ b/third-party/lizardbyte-common @@ -1 +1 @@ -Subproject commit 8d7dcc97d0795e4eb2efdb50a86f83060ed47934 +Subproject commit 0fcde420419c77fdde04ffb04ceda0b560bd1cfc From ed375c5489fd120cc6a9357369f0847973a7b205 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 28 Jun 2026 23:45:00 -0400 Subject: [PATCH 2/4] Update lizardbyte-common submodule Bumps `third-party/lizardbyte-common` from commit `0fcde42` to `d219f38` to pull in upstream changes from the shared common library. --- third-party/lizardbyte-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/lizardbyte-common b/third-party/lizardbyte-common index 0fcde42..d219f38 160000 --- a/third-party/lizardbyte-common +++ b/third-party/lizardbyte-common @@ -1 +1 @@ -Subproject commit 0fcde420419c77fdde04ffb04ceda0b560bd1cfc +Subproject commit d219f38090db20119906c80860833592a6be669a From cd0b7b59270f218670bcf5670efbf1461d341984 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 29 Jun 2026 10:22:14 -0400 Subject: [PATCH 3/4] Bump lizardbyte-common submodule Updates the `third-party/lizardbyte-common` submodule reference from `d219f38` to `60bf936` to pull in the latest upstream changes. --- third-party/lizardbyte-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/lizardbyte-common b/third-party/lizardbyte-common index d219f38..60bf936 160000 --- a/third-party/lizardbyte-common +++ b/third-party/lizardbyte-common @@ -1 +1 @@ -Subproject commit d219f38090db20119906c80860833592a6be669a +Subproject commit 60bf936e134359c65c8a044369db227f976947e5 From 4322a49783590b2e9ab1e21c0eaaa750c9bd76b6 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 29 Jun 2026 14:04:44 -0400 Subject: [PATCH 4/4] Bump lizardbyte-common submodule Update the `third-party/lizardbyte-common` submodule pointer from `60bf936` to `3f29834` to pull in the latest upstream shared changes. --- third-party/lizardbyte-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/lizardbyte-common b/third-party/lizardbyte-common index 60bf936..3f29834 160000 --- a/third-party/lizardbyte-common +++ b/third-party/lizardbyte-common @@ -1 +1 @@ -Subproject commit 60bf936e134359c65c8a044369db227f976947e5 +Subproject commit 3f29834c942d71d626f2daf67323fc61426bf524