Skip to content

Add C++ test to obs-studio-server#1706

Draft
sandboxcoder wants to merge 5 commits into
messages-pacing-during-congestionfrom
rno/obs-source-getproperties-test
Draft

Add C++ test to obs-studio-server#1706
sandboxcoder wants to merge 5 commits into
messages-pacing-during-congestionfrom
rno/obs-source-getproperties-test

Conversation

@sandboxcoder
Copy link
Copy Markdown
Contributor

@sandboxcoder sandboxcoder commented May 22, 2026

Description

  • Add support for Catch2 C++ obs-studio-server tests
  • Turn obs-server into static lib

Motivation and Context

How Has This Been Tested?

Types of changes

Checklist:

  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

* Add support for Catch2 C++ test
* Turn obs-server into static lib
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::Source concurrency behavior plus OBS init/teardown helpers.
  • Refactors obs-studio-server CMake to build a obs-studio-server-lib static 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.

Comment on lines +19 to +22
const int iterations = 20;
std::vector<std::thread> workers;
std::vector<bool> releaseOk(iterations, false);
std::vector<ErrorCode> getPropertiesCode(iterations, ErrorCode::Error);
Comment thread obs-studio-server/tests/test-osn-source.cpp Outdated
Comment on lines +13 to +16
TEST_CASE("Run osn::source tests")
{
osn::tests::TestHelper::initializeOBS();

Comment on lines +44 to +50
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);
}
Comment on lines +81 to +86
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);
Comment on lines +435 to +442
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comment on lines +46 to +49
OBS_API::SetWorkingDirectory(nullptr, 0, args, response);
CHECK(response.size() >= 2);
ErrorCode error = (ErrorCode)response[0].value_union.ui64;
CHECK(error == ErrorCode::Ok);
Comment on lines +66 to +69
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);
Comment on lines +14 to +18
TEST_CASE("Run osn::source tests")
{
osn::tests::TestHelper::initializeOBS();

SECTION("Get properties of browser source while releasing concurrently does not crash")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants