Skip to content

Commit

Permalink
add test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Oct 16, 2024
1 parent 02ea25d commit 22abcdf
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ jobs:

- name: Run tests
id: test
if: false
working-directory: build/tests
run: |
./test_moonlight-xboxog --gtest_color=yes
./test_moonlight --gtest_color=yes
- name: Generate gcov report
# any except canceled or skipped
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "third-party/googletest"]
path = third-party/googletest
url = https://github.com/google/googletest.git
branch = main
[submodule "third-party/moonlight-common-c"]
path = third-party/moonlight-common-c
url = https://github.com/moonlight-stream/moonlight-common-c.git
Expand Down
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ set(XBOX_XBE_DIR "${CMAKE_CURRENT_BINARY_DIR}/xbe")
set(XBOX_ISO "${CMAKE_PROJECT_NAME}.iso")
message(STATUS "XBOX_ISO: ${XBOX_ISO}")

#
# Options
#
option(BUILD_TESTS "Build tests" ON)

# create the xbe directory if it doesn't exist
file(MAKE_DIRECTORY ${XBOX_XBE_DIR})

Expand All @@ -30,15 +35,27 @@ add_definitions(-DXBOX -DNXDK)
set(MOONLIGHT_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp"
)
set(MOONLIGHT_EXTERNAL_LIBRARIES
"${NXDK_DIR}/lib/libpbkit.lib"
)

add_executable(${CMAKE_PROJECT_NAME}
${MOONLIGHT_SOURCES}
)
include_directories("${NXDK_DIR}/lib")
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC ${NXDK_DIR}/lib/libpbkit.lib)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
${MOONLIGHT_EXTERNAL_LIBRARIES}
)

target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "")

#
# tests
#
if(BUILD_TESTS)
add_subdirectory(tests)
endif()

# Post-build exe to xbe conversion
add_custom_target(cxbe_convert ALL
VERBATIM COMMAND "${CMAKE_COMMAND}" -E env ./tools/cxbe/cxbe -OUT:${XBOX_XBE_DIR}/default.xbe -TITLE:${XBE_TITLE} ${CMAKE_CURRENT_BINARY_DIR}/${XBE_TITLE}.exe
Expand Down
53 changes: 53 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.13)
# https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md#foundational-c-support

project(test_moonlight)

include_directories("${CMAKE_SOURCE_DIR}")

enable_testing()

# Add GoogleTest directory to the project
set(GTEST_SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/googletest")
set(INSTALL_GTEST OFF)
set(INSTALL_GMOCK OFF)
add_subdirectory("${GTEST_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/googletest")
include_directories("${GTEST_SOURCE_DIR}/googletest/include" "${GTEST_SOURCE_DIR}")

# coverage
# https://gcovr.com/en/stable/guide/compiling.html#compiler-options
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0")
set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0")

# if windows
if (WIN32)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # cmake-lint: disable=C0103
endif ()

file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS
${CMAKE_SOURCE_DIR}/tests/*.h
${CMAKE_SOURCE_DIR}/tests/*.cpp)

# remove main.cpp from the list of sources
# TODO
# list(REMOVE_ITEM MOONLIGHT_SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp)

add_executable(${PROJECT_NAME}
${TEST_SOURCES}
${MOONLIGHT_SOURCES})

foreach(dep ${MOONLIGHT_TARGET_DEPENDENCIES})
add_dependencies(${PROJECT_NAME} ${dep}) # compile these before Moonlight
endforeach()

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME}
${MOONLIGHT_EXTERNAL_LIBRARIES}
gtest
gtest_main) # if we use this we don't need our own main function
target_compile_definitions(${PROJECT_NAME} PUBLIC ${MOONLIGHT_DEFINITIONS} ${TEST_DEFINITIONS})
target_compile_options(${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${MOONLIGHT_COMPILE_OPTIONS}>)
target_link_options(${PROJECT_NAME} PRIVATE)

add_test(NAME ${PROJECT_NAME} COMMAND moonlight_test)
1 change: 1 addition & 0 deletions third-party/googletest
Submodule googletest added at b514bd

0 comments on commit 22abcdf

Please sign in to comment.