mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-11-30 09:08:53 +00:00
refactor: resolve Sonar cpp:S5008 findings (#5909)
This commit is contained in:
1 parent
e2a56b3d17
commit
1925909fbc
41 files changed
+722
-149
No files matched your search
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file tests/unit/platform/linux/test_dynamic_loader.cpp
|
||||
* @brief Tests for opaque Linux shared-library handles and symbol loading.
|
||||
*/
|
||||
#ifdef __linux__
|
||||
|
||||
// standard includes
|
||||
#include <bit>
|
||||
|
||||
// platform includes
|
||||
#include <dlfcn.h>
|
||||
|
||||
// lib includes
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// local includes
|
||||
#include "src/platform/linux/misc.h"
|
||||
|
||||
TEST(DynamicLibraryTest, FallsBackToAnAvailableLibraryAndLoadsCallableSymbols) {
|
||||
auto *library = dyn::handle({"libsunshine-does-not-exist.so", "libc.so.6"});
|
||||
ASSERT_NE(library, nullptr);
|
||||
auto close_library = util::fail_guard([library] {
|
||||
dlclose(library);
|
||||
});
|
||||
dyn::apiproc symbol = nullptr;
|
||||
ASSERT_EQ(dyn::load(library, {{&symbol, "getpid"}}), 0);
|
||||
ASSERT_NE(symbol, nullptr);
|
||||
const auto loaded_getpid = std::bit_cast<pid_t (*)()>(symbol);
|
||||
EXPECT_EQ(loaded_getpid(), getpid());
|
||||
}
|
||||
|
||||
TEST(DynamicLibraryTest, MissingOptionalSymbolDoesNotFailLoading) {
|
||||
auto *library = dyn::handle({"libc.so.6"});
|
||||
ASSERT_NE(library, nullptr);
|
||||
auto close_library = util::fail_guard([library] {
|
||||
dlclose(library);
|
||||
});
|
||||
dyn::apiproc symbol = nullptr;
|
||||
EXPECT_EQ(dyn::load(library, {{&symbol, "sunshine_missing_symbol"}}, false), 0);
|
||||
EXPECT_EQ(symbol, nullptr);
|
||||
EXPECT_EQ(dyn::load(library, {{&symbol, "sunshine_missing_symbol"}}, true), -1);
|
||||
}
|
||||
|
||||
TEST(DynamicLibraryTest, MissingLibraryReturnsNull) {
|
||||
EXPECT_EQ(dyn::handle({"libsunshine-does-not-exist.so", "libsunshine-also-does-not-exist.so"}), nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user