-
Notifications
You must be signed in to change notification settings - Fork 113
Add C++ test to obs-studio-server #1706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9f370fe
Add C++ test to obs-studio-server
sandboxcoder e1fb8e5
remove unused headers
sandboxcoder c42cd1c
Potential fix for pull request finding
sandboxcoder 16e14aa
fix crashManager lifetime
sandboxcoder d1708af
fix syntax error
sandboxcoder 3ac94a7
Potential fix for pull request finding
sandboxcoder 6d4fdc0
use osn::Source::Release which calls source_remove
sandboxcoder 466006d
Potential fix for pull request finding
sandboxcoder a7ff50e
crashmanager lifetime fix
sandboxcoder 0faa5c0
crashmanager lifetime fix
sandboxcoder 060ddef
Revert "fix crashManager lifetime"
sandboxcoder 2685e36
run clang-format
sandboxcoder 6b427a1
Apply suggestions from code review
sandboxcoder 886ac17
Remove redundant StackWalker link from executable target
Copilot 97ff876
Fix uninitialized state and worker in UtilObjCInt constructor
Copilot 175f316
remove extra #endif
sandboxcoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include <catch2/catch_test_macros.hpp> | ||
| #include "nodeobs_api.h" | ||
| #include "osn-error.hpp" | ||
| #include <obs.h> | ||
| #include "shared.hpp" | ||
| #include <string> | ||
| #include "obs-setup.hpp" | ||
| #include <vector> | ||
|
|
||
| namespace osn::tests { | ||
|
|
||
| void setWorkingFolder(const std::string &wd) | ||
| { | ||
| std::vector<ipc::value> args = {ipc::value(wd)}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::SetWorkingDirectory(nullptr, 0, args, response); | ||
| REQUIRE(response.size() >= 2); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); | ||
|
sandboxcoder marked this conversation as resolved.
|
||
| } | ||
|
sandboxcoder marked this conversation as resolved.
|
||
|
|
||
| void setupApi() | ||
| { | ||
| #if defined(__APPLE__) | ||
| if (g_util_osx) { | ||
| delete g_util_osx; | ||
| g_util_osx = nullptr; | ||
| } | ||
| g_util_osx = new UtilInt(); | ||
| g_util_osx->init(); | ||
| // Workaround normal app startup where "browser_source" plugin is initialized | ||
| CHECK(!g_util_osx->hasInitApi()); | ||
| g_util_osx->nextState(); | ||
| CHECK(g_util_osx->hasInitApi()); | ||
|
sandboxcoder marked this conversation as resolved.
sandboxcoder marked this conversation as resolved.
|
||
| #endif | ||
| const std::string appPath = std::string(OSN_SOURCE_DIR) + "/tests/osn-tests/osnData/slobs-client"; | ||
| std::vector<ipc::value> args = {ipc::value(appPath), ipc::value("en-US"), ipc::value("0.00.00-preview.0"), ipc::value("")}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::OBS_API_initAPI(nullptr, 0, args, response); | ||
| REQUIRE(response.size() >= 2); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); | ||
|
sandboxcoder marked this conversation as resolved.
|
||
| } | ||
|
|
||
| ObsSetup::ObsSetup() | ||
| { | ||
| setWorkingFolder(OSN_TEST_WD); | ||
| setupApi(); | ||
| } | ||
|
|
||
| ObsSetup::~ObsSetup() | ||
| { | ||
| std::vector<ipc::value> args = {}; | ||
| std::vector<ipc::value> response; | ||
| OBS_API::OBS_API_destroyOBS_API(nullptr, 0, args, response); | ||
| CHECK(response.size() >= 1); | ||
| if (response.size() >= 1) { | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| CHECK(error == ErrorCode::Ok); | ||
| } | ||
|
|
||
| #if defined(__APPLE__) | ||
| delete g_util_osx; | ||
| g_util_osx = nullptr; | ||
| #endif | ||
| } | ||
|
sandboxcoder marked this conversation as resolved.
|
||
|
|
||
| } // namespace osn::tests | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #pragma once | ||
|
|
||
| namespace osn::tests { | ||
| // This helper object uses RAII pattern to initialize & destroy OBS API | ||
| class ObsSetup { | ||
| public: | ||
| ObsSetup(); | ||
| ~ObsSetup(); | ||
| }; | ||
| } // namespace osn::tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #include <catch2/catch_test_macros.hpp> | ||
| #include "nodeobs_api.h" | ||
| #include "osn-error.hpp" | ||
| #include "osn-input.hpp" | ||
| #include "osn-source.hpp" | ||
| #include <obs.h> | ||
| #include "shared.hpp" | ||
| #include <cstdint> | ||
| #include <string> | ||
| #include "obs-setup.hpp" | ||
| #include <thread> | ||
| #include <utility> | ||
| #include <vector> | ||
|
sandboxcoder marked this conversation as resolved.
|
||
|
|
||
| // Since we do not use C++ 20 (std::jthread), defining a scoped thread. | ||
| struct joining_thread { | ||
| std::thread t; | ||
| explicit joining_thread(std::thread t_) : t(std::move(t_)) {} | ||
| joining_thread(joining_thread &&) = default; | ||
| joining_thread &operator=(joining_thread &&) = default; | ||
| joining_thread(const joining_thread &) = delete; | ||
| joining_thread &operator=(const joining_thread &) = delete; | ||
| ~joining_thread() | ||
| { | ||
| if (t.joinable()) | ||
| t.join(); | ||
| } | ||
| }; | ||
|
|
||
| TEST_CASE("Run osn::source tests") | ||
| { | ||
| osn::tests::ObsSetup setupOBS; | ||
|
|
||
|
sandboxcoder marked this conversation as resolved.
|
||
| SECTION("Get properties of browser source while releasing concurrently does not crash") | ||
|
sandboxcoder marked this conversation as resolved.
|
||
| { | ||
| auto sourceCount = osn::Source::Manager::GetInstance().size(); | ||
| const int iterations = 20; | ||
| std::vector<joining_thread> workers; | ||
| std::vector<uint8_t> releaseOk(iterations, 0); | ||
| std::vector<ErrorCode> getPropertiesCode(iterations, ErrorCode::Error); | ||
|
sandboxcoder marked this conversation as resolved.
|
||
|
|
||
| for (int i = 0; i < iterations; i++) { | ||
| const std::string sourceName = "test-input-" + std::to_string(i); | ||
| std::vector<ipc::value> args = {ipc::value("browser_source"), ipc::value(sourceName)}; | ||
| std::vector<ipc::value> response; | ||
|
|
||
| osn::Input::Create(nullptr, 0, args, response); | ||
| REQUIRE(response.size() >= 2); | ||
| ErrorCode error = (ErrorCode)response[0].value_union.ui64; | ||
| REQUIRE(error == ErrorCode::Ok); | ||
|
|
||
| uint64_t sourceId = response[1].value_union.ui64; | ||
|
|
||
| workers.push_back(joining_thread(std::thread([sourceId, i, &getPropertiesCode]() { | ||
| std::vector<ipc::value> propArgs = {ipc::value(sourceId)}; | ||
| std::vector<ipc::value> propResponse; | ||
| osn::Source::GetProperties(nullptr, 0, propArgs, propResponse); | ||
| if (propResponse.size() >= 1) { | ||
| getPropertiesCode[i] = (ErrorCode)propResponse[0].value_union.ui64; | ||
| } | ||
| }))); | ||
|
|
||
| workers.push_back(joining_thread(std::thread([sourceId, i, &releaseOk]() { | ||
| std::vector<ipc::value> propArgs = {ipc::value(sourceId)}; | ||
| std::vector<ipc::value> propResponse; | ||
| osn::Source::Release(nullptr, 0, propArgs, propResponse); | ||
| // Capture result for checking on the main thread after join. | ||
| if (propResponse.size() >= 1) { | ||
| releaseOk[i] = ((ErrorCode)propResponse[0].value_union.ui64 == ErrorCode::Ok); | ||
| } | ||
| }))); | ||
|
sandboxcoder marked this conversation as resolved.
|
||
| } | ||
|
|
||
| workers.clear(); | ||
| // Check release results on the main thread where Catch2 is safe to use. | ||
| for (int i = 0; i < iterations; i++) { | ||
| CHECK(releaseOk[i]); | ||
| // ErrorCode::InvalidReference is possible if the source was deleted before we could acquire the source | ||
| bool expectedErrorCode = getPropertiesCode[i] == ErrorCode::Ok || getPropertiesCode[i] == ErrorCode::InvalidReference; | ||
| CHECK(expectedErrorCode); | ||
| } | ||
|
|
||
| CHECK(sourceCount == osn::Source::Manager::GetInstance().size()); // Check to see if all objects released. | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.