Add C++ test to obs-studio-server#1706
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Catch2-based C++ unit-test executable for obs-studio-server and restructures the server build so the core code can be linked into tests (and the main server executable) via a new static library.
Changes:
- Introduces new Catch2 test(s) for
osn::Sourceconcurrency behavior plus OBS init/teardown helpers. - Refactors
obs-studio-serverCMake to build aobs-studio-server-libstatic library and link both the server executable and unit tests against it. - Updates CI unit-test runner to execute both client and server Catch2 test suites.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| obs-studio-server/tests/test-osn-source.cpp | Adds a Catch2 test exercising concurrent GetProperties / Release on browser sources. |
| obs-studio-server/tests/test-helper.hpp | Declares a small helper for initializing/finalizing OBS for tests. |
| obs-studio-server/tests/test-helper.cpp | Implements OBS initialization/teardown and runtime parsing of test working directory. |
| obs-studio-server/source/nodeobs_api.cpp | Guards crash-manager server callback registration behind a g_server null check. |
| obs-studio-server/CMakeLists.txt | Builds server core as a static lib and adds a Catch2 unit-test executable with test discovery. |
| ci/run-unit-tests.js | Runs both obs-studio-client and obs-studio-server CTest-discovered Catch2 suites in CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| target_include_directories(obs-studio-server-lib PUBLIC ${PROJECT_INCLUDE_PATHS}) | ||
|
|
||
| if(WIN32) | ||
| target_link_libraries(obs-studio-server-lib PUBLIC ${PROJECT_LIBRARIES} optimized crashpad strmiids) |
There was a problem hiding this comment.
Now that most server sources are compiled into obs-studio-server-lib, the Windows compile definitions below (WIN32_LEAN_AND_MEAN, NOMINMAX, UNICODE, _UNICODE) no longer apply to those sources because they are still scoped only to ${PROJECT_NAME}. ${PROJECT_NAME} now compiles just main.cpp, so the actual server implementation may build with different Windows/Unicode macro state than before. Please move or duplicate the Windows target_compile_definitions onto obs-studio-server-lib.
There was a problem hiding this comment.
This has been addressed thanks
* Add support for Catch2 C++ test * Turn obs-server into a static lib * Add osn-source test
f24f68f to
99d1c4d
Compare
| std::vector<ipc::value> args = {}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::OBS_API_destroyOBS_API(nullptr, 0, args, response); | ||
| REQUIRE(response.size() >= 1); |
There was a problem hiding this comment.
https://catch2-temp.readthedocs.io/en/latest/configuration.html#disabling-exceptions
By default, Catch2 uses exceptions to signal errors and to abort tests when an assertion from the REQUIRE family of assertions fails.
| { | ||
| auto sourceCount = osn::Source::Manager::GetInstance().size(); | ||
| const int iterations = 20; | ||
| std::vector<std::thread> workers; |
There was a problem hiding this comment.
If a later REQUIRE aborts after earlier iterations started threads, workers will be destroyed while still joinable and terminate the process. Please add an RAII join guard or create all inputs before starting worker threads.
| "$<TARGET_FILE_DIR:Catch2::Catch2>" | ||
| "$<TARGET_FILE_DIR:Catch2::Catch2WithMain>" | ||
| "$<TARGET_FILE_DIR:libcurl>" | ||
| if(APPLE) |
There was a problem hiding this comment.
CMake does not parse if() blocks recursively inside another command’s parentheses.
In CMake, this is a command invocation:
catch_discover_tests(
obs_studio_server_unit_tests
DL_PATHS
...
if(APPLE)
...
endif()
)Everything between catch_discover_tests( and its matching ) is parsed as that command’s argument list. The if(APPLE) there is not treated as the start of a conditional block; it is just an unquoted argument/token inside the catch_discover_tests call.
Description
g_serverinobs-studio-server/source/nodeobs_api.cppsince we do not need ipc server running during these testsMotivation and Context
There are some tests that we can run much more easily from C++. We can get better code coverage from these tests in certain cases.
How Has This Been Tested?
Types of changes
Checklist: