Skip to content

Commit

Permalink
ci(tests): add test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Sep 5, 2023
1 parent da4bd6c commit 0783a97
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@
path = third-party/ffmpeg-linux-powerpc64le
url = https://github.com/LizardByte/build-deps
branch = ffmpeg-linux-powerpc64le
[submodule "third-party/googletest"]
path = third-party/googletest
url = https://github.com/google/googletest/
branch = main
4 changes: 4 additions & 0 deletions cmake/compile_definitions/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ elseif(UNIX)
endif()
endif()

# tests
add_subdirectory(tests)
enable_testing()

include_directories(SYSTEM third-party/nv-codec-headers/include)
file(GLOB NVENC_SOURCES CONFIGURE_DEPENDS "src/nvenc/*.cpp" "src/nvenc/*.h")
list(APPEND PLATFORM_TARGET_FILES ${NVENC_SOURCES})
Expand Down
3 changes: 3 additions & 0 deletions cmake/dependencies/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# this file will also load platform specific dependencies

# submodules
# testing
add_subdirectory(third-party/googletest)

# moonlight common library
add_subdirectory(third-party/moonlight-common-c/enet)

Expand Down
14 changes: 14 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(BINARY ${CMAKE_PROJECT_NAME}_test)

set(TEST_SOURCES
main.cpp
test_main.cpp
)

add_executable(${BINARY} ${TEST_SOURCES})

add_test(NAME ${BINARY} COMMAND ${BINARY})

target_link_libraries(${BINARY} PUBLIC gtest)

# target_include_directories(${BINARY} PRIVATE ${CMAKE_SOURCE_DIR}/third-party/googletest/googletest/include)
7 changes: 7 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "gtest/gtest.h"

int
main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
19 changes: 19 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file tests/test_main.cpp
* @brief Test src/main.*.
*/

#include "../src/main.h"
#include "gtest/gtest.h"

TEST(MainTestSuite, WriteFileTest) {
EXPECT_EQ(write_file("write_file_test.txt", "test"), 0);
}

TEST(MainTestSuite, ReadFileTest) {
// read file from WriteFileTest
EXPECT_EQ(read_file("write_file_test.txt"), "test");

// read missing file
EXPECT_EQ(read_file("non-existing-file.txt"), "");
}
1 change: 1 addition & 0 deletions third-party/googletest
Submodule googletest added at f8d7d7
1 change: 0 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ target_link_libraries(ddprobe
d3d11
${PLATFORM_LIBRARIES})
target_compile_options(ddprobe PRIVATE ${SUNSHINE_COMPILE_OPTIONS})

0 comments on commit 0783a97

Please sign in to comment.