Add C++ test to obs-studio-server#1706
Conversation
* Add support for Catch2 C++ test * Turn obs-server into static lib
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.
| const int iterations = 20; | ||
| std::vector<std::thread> workers; | ||
| std::vector<bool> releaseOk(iterations, false); | ||
| std::vector<ErrorCode> getPropertiesCode(iterations, ErrorCode::Error); |
| TEST_CASE("Run osn::source tests") | ||
| { | ||
| osn::tests::TestHelper::initializeOBS(); | ||
|
|
| std::vector<ipc::value> args = {ipc::value(wd)}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::SetWorkingDirectory(nullptr, 0, args, response); | ||
| CHECK(response.size() >= 2); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); | ||
| } |
| std::vector<ipc::value> args = {}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::OBS_API_destroyOBS_API(nullptr, 0, args, response); | ||
| CHECK(response.size() >= 1); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); |
| 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) | ||
| else() | ||
| target_include_directories(obs-studio-server-lib PUBLIC ${COREFOUNDATION} ${COCOA} ${IOSURF} ${GLKIT} ${AVFOUNDATION} ${IOKit} ${SECURITY_LIBRARY} ${BSM_LIBRARY}) | ||
| target_link_libraries(obs-studio-server-lib PUBLIC ${PROJECT_LIBRARIES} crashpad ${COREFOUNDATION} ${COCOA} ${IOSURF} ${GLKIT} ${AVFOUNDATION} ${IOKit} ${SECURITY_LIBRARY} ${BSM_LIBRARY}) | ||
| endif() |
| if(WIN32) | ||
| target_link_libraries(obs-studio-server-lib PUBLIC ${PROJECT_LIBRARIES} optimized crashpad strmiids) | ||
| else() | ||
| target_include_directories(obs-studio-server-lib PUBLIC ${COREFOUNDATION} ${COCOA} ${IOSURF} ${GLKIT} ${AVFOUNDATION} ${IOKit} ${SECURITY_LIBRARY} ${BSM_LIBRARY}) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| 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.
* resolves possible data race
| OBS_API::SetWorkingDirectory(nullptr, 0, args, response); | ||
| CHECK(response.size() >= 2); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); |
| OBS_API::OBS_API_initAPI(nullptr, 0, args, response); | ||
| CHECK(response.size() >= 2); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); |
| std::vector<ipc::value> args = {}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::OBS_API_destroyOBS_API(nullptr, 0, args, response); | ||
| CHECK(response.size() >= 1); |
| TEST_CASE("Run osn::source tests") | ||
| { | ||
| osn::tests::TestHelper::initializeOBS(); | ||
|
|
||
| SECTION("Get properties of browser source while releasing concurrently does not crash") |
Description
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist: