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..d219f38 160000 --- a/third-party/lizardbyte-common +++ b/third-party/lizardbyte-common @@ -1 +1 @@ -Subproject commit 8d7dcc97d0795e4eb2efdb50a86f83060ed47934 +Subproject commit d219f38090db20119906c80860833592a6be669a