Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand Down
69 changes: 0 additions & 69 deletions tests/fixtures/fixtures.cpp

This file was deleted.

80 changes: 1 addition & 79 deletions tests/fixtures/include/fixtures/fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,5 @@
*/
#pragma once

// standard includes
#include <sstream>
#include <streambuf>

// lib includes
#include <gtest/gtest.h>

/**
* @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 <lizardbyte/common/testing.h>
1 change: 0 additions & 1 deletion third-party/googletest
Submodule googletest deleted from 52eb81
Loading