chore: use lizardbyte-common in c++ (#5356)
Co-authored-by: Kishi <41839133+Kishi85@users.noreply.github.com>
This commit is contained in:
@@ -7,48 +7,6 @@
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
#include <src/platform/common.h>
|
||||
|
||||
struct SetEnvTest: ::testing::TestWithParam<std::tuple<std::string, std::string, int>> {
|
||||
protected:
|
||||
void TearDown() override {
|
||||
// Clean up environment variable after each test
|
||||
const auto &[name, value, expected] = GetParam();
|
||||
platf::unset_env(name);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(SetEnvTest, SetEnvironmentVariableTests) {
|
||||
const auto &[name, value, expected] = GetParam();
|
||||
platf::set_env(name, value);
|
||||
|
||||
const char *env_value = std::getenv(name.c_str());
|
||||
if (expected == 0 && !value.empty()) {
|
||||
ASSERT_NE(env_value, nullptr);
|
||||
ASSERT_EQ(std::string(env_value), value);
|
||||
} else {
|
||||
ASSERT_EQ(env_value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(SetEnvTest, UnsetEnvironmentVariableTests) {
|
||||
const auto &[name, value, expected] = GetParam();
|
||||
platf::unset_env(name);
|
||||
|
||||
const char *env_value = std::getenv(name.c_str());
|
||||
if (expected == 0) {
|
||||
ASSERT_EQ(env_value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
SetEnvTests,
|
||||
SetEnvTest,
|
||||
::testing::Values(
|
||||
std::make_tuple("SUNSHINE_UNIT_TEST_ENV_VAR", "test_value_0", 0),
|
||||
std::make_tuple("SUNSHINE_UNIT_TEST_ENV_VAR", "test_value_1", 0),
|
||||
std::make_tuple("", "test_value", -1)
|
||||
)
|
||||
);
|
||||
|
||||
TEST(HostnameTests, TestAsioEquality) {
|
||||
// These should be equivalent on all platforms for ASCII hostnames
|
||||
ASSERT_EQ(platf::get_host_name(), boost::asio::ip::host_name());
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
/**
|
||||
* @brief Test fixture for utf_utils namespace functions
|
||||
*/
|
||||
class UtfUtilsTest: public testing::Test {};
|
||||
class UtfUtilsTest: public BaseTest {};
|
||||
|
||||
TEST_F(UtfUtilsTest, FromUtf8WithEmptyString) {
|
||||
const std::string empty_string = "";
|
||||
|
||||
@@ -10,6 +10,7 @@ using namespace audio;
|
||||
|
||||
struct AudioTest: PlatformTestSuite, testing::WithParamInterface<std::tuple<std::basic_string_view<char>, config_t>> {
|
||||
void SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
m_config = std::get<1>(GetParam());
|
||||
m_mail = std::make_shared<safe::mail_raw_t>();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ X4wnh1bwdiidqpcgyuKossLOPxbS786WmsesaAWPnpoY6M8aija+ALwNNuWWmyMg
|
||||
*
|
||||
* This fixture creates a real server to test the actual confighttp functions.
|
||||
*/
|
||||
class ConfigHttpTest: public ::testing::Test { // NOSONAR(cpp:S3656) - protected members are intentional for test fixture subclassing
|
||||
class ConfigHttpTest: public BaseTest { // NOSONAR(cpp:S3656) - protected members are intentional for test fixture subclassing
|
||||
protected:
|
||||
std::unique_ptr<SimpleWeb::Server<SimpleWeb::HTTPS>> server;
|
||||
std::unique_ptr<SimpleWeb::Client<SimpleWeb::HTTPS>> client;
|
||||
@@ -107,6 +107,7 @@ protected:
|
||||
std::filesystem::path web_dir_test_file;
|
||||
|
||||
void SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
// Save current config
|
||||
saved_username = config::sunshine.username;
|
||||
saved_password = config::sunshine.password;
|
||||
@@ -354,6 +355,7 @@ protected:
|
||||
if (std::filesystem::exists(test_web_dir)) {
|
||||
std::filesystem::remove_all(test_web_dir);
|
||||
}
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
|
||||
static std::string create_auth_header(const std::string &username, const std::string &password) {
|
||||
@@ -1251,7 +1253,6 @@ TEST_F(BrowseDirectoryTest, IsBrowsableExecutable_LinuxGroupExecBit_ReturnsTrue)
|
||||
TEST_F(BrowseDirectoryTest, BuildBrowseEntries_TypeAny_ReturnsAllEntries) {
|
||||
const auto entries = confighttp::build_browse_entries(browse_test_dir, "any");
|
||||
ASSERT_TRUE(entries.is_array());
|
||||
// subdir_a, subdir_b, file_alpha.txt, file_beta.txt, test_exec[.exe] = 5
|
||||
ASSERT_EQ(entries.size(), 5u);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace {
|
||||
const std::string max_uint_string {std::to_string(std::numeric_limits<unsigned int>::max())};
|
||||
|
||||
template<class T>
|
||||
struct DisplayDeviceConfigTest: testing::TestWithParam<T> {};
|
||||
struct DisplayDeviceConfigTest: BaseTest, testing::WithParamInterface<T> {};
|
||||
} // namespace
|
||||
|
||||
using ParseDeviceId = DisplayDeviceConfigTest<std::pair<std::string, std::string>>;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <format>
|
||||
#include <src/file_handler.h>
|
||||
|
||||
struct FileHandlerParentDirectoryTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
|
||||
struct FileHandlerParentDirectoryTest: BaseTest, testing::WithParamInterface<std::tuple<std::string, std::string>> {};
|
||||
|
||||
TEST_P(FileHandlerParentDirectoryTest, Run) {
|
||||
auto [input, expected] = GetParam();
|
||||
@@ -24,7 +24,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
)
|
||||
);
|
||||
|
||||
struct FileHandlerMakeDirectoryTest: testing::TestWithParam<std::tuple<std::string, bool, bool>> {};
|
||||
struct FileHandlerMakeDirectoryTest: BaseTest, testing::WithParamInterface<std::tuple<std::string, bool, bool>> {};
|
||||
|
||||
TEST_P(FileHandlerMakeDirectoryTest, Run) {
|
||||
auto [input, expected, remove] = GetParam();
|
||||
@@ -52,7 +52,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
)
|
||||
);
|
||||
|
||||
struct FileHandlerTests: testing::TestWithParam<std::tuple<int, std::string>> {};
|
||||
struct FileHandlerTests: BaseTest, testing::WithParamInterface<std::tuple<int, std::string>> {};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
TestFiles,
|
||||
|
||||
@@ -76,7 +76,7 @@ X4wnh1bwdiidqpcgyuKossLOPxbS786WmsesaAWPnpoY6M8aija+ALwNNuWWmyMg
|
||||
9SVDV76xJzM36Uq7Kg3QJYTlY04WmPIdJHkCtXWf9g==
|
||||
-----END CERTIFICATE-----)";
|
||||
|
||||
struct PairingTest: testing::TestWithParam<std::tuple<pairing_input, pairing_output>> {};
|
||||
struct PairingTest: BaseTest, testing::WithParamInterface<std::tuple<pairing_input, pairing_output>> {};
|
||||
|
||||
TEST_P(PairingTest, Run) {
|
||||
auto [input, expected] = GetParam();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
// local imports
|
||||
#include <src/httpcommon.h>
|
||||
|
||||
struct UrlEscapeTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
|
||||
struct UrlEscapeTest: BaseTest, testing::WithParamInterface<std::tuple<std::string, std::string>> {};
|
||||
|
||||
TEST_P(UrlEscapeTest, Run) {
|
||||
const auto &[input, expected] = GetParam();
|
||||
@@ -28,7 +28,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
)
|
||||
);
|
||||
|
||||
struct UrlGetHostTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
|
||||
struct UrlGetHostTest: BaseTest, testing::WithParamInterface<std::tuple<std::string, std::string>> {};
|
||||
|
||||
TEST_P(UrlGetHostTest, Run) {
|
||||
const auto &[input, expected] = GetParam();
|
||||
@@ -45,7 +45,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
)
|
||||
);
|
||||
|
||||
struct DownloadFileTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
|
||||
struct DownloadFileTest: BaseTest, testing::WithParamInterface<std::tuple<std::string, std::string>> {};
|
||||
|
||||
TEST_P(DownloadFileTest, Run) {
|
||||
const auto &[url, filename] = GetParam();
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace {
|
||||
constexpr auto log_file = "test_sunshine.log";
|
||||
} // namespace
|
||||
|
||||
struct LogLevelsTest: testing::TestWithParam<decltype(log_levels)::value_type> {};
|
||||
struct LogLevelsTest: BaseTest, testing::WithParamInterface<decltype(log_levels)::value_type> {};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
Logging,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
struct MouseHIDTest: PlatformTestSuite, testing::WithParamInterface<util::point_t> {
|
||||
void SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
#ifdef _WIN32
|
||||
// TODO: Windows tests are failing, `get_mouse_loc` seems broken and `platf::abs_mouse` too
|
||||
// the alternative `platf::abs_mouse` method seem to work better during tests,
|
||||
@@ -21,6 +22,7 @@ struct MouseHIDTest: PlatformTestSuite, testing::WithParamInterface<util::point_
|
||||
|
||||
void TearDown() override {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <src/network.h>
|
||||
|
||||
struct MdnsInstanceNameTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
|
||||
struct MdnsInstanceNameTest: BaseTest, testing::WithParamInterface<std::tuple<std::string, std::string>> {};
|
||||
|
||||
TEST_P(MdnsInstanceNameTest, Run) {
|
||||
auto [input, expected] = GetParam();
|
||||
@@ -30,11 +30,12 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
/**
|
||||
* @brief Test fixture for bind_address tests with setup/teardown
|
||||
*/
|
||||
class BindAddressTest: public ::testing::Test {
|
||||
class BindAddressTest: public BaseTest {
|
||||
protected:
|
||||
std::string original_bind_address;
|
||||
|
||||
void SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
// Save the original bind_address config
|
||||
original_bind_address = config::sunshine.bind_address;
|
||||
}
|
||||
@@ -42,6 +43,7 @@ protected:
|
||||
void TearDown() override {
|
||||
// Restore the original bind_address config
|
||||
config::sunshine.bind_address = original_bind_address;
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
class ProcessPNGTest: public ::testing::Test {
|
||||
class ProcessPNGTest: public BaseTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
// Create test directory
|
||||
test_dir = fs::temp_directory_path() / "sunshine_process_png_test"; // NOSONAR(cpp:S5443) - safe for tests
|
||||
fs::create_directories(test_dir);
|
||||
@@ -27,6 +28,7 @@ protected:
|
||||
if (fs::exists(test_dir)) {
|
||||
fs::remove_all(test_dir);
|
||||
}
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
|
||||
// Helper function to create a file with specific content
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
struct EncoderTest: PlatformTestSuite, testing::WithParamInterface<video::encoder_t *> {
|
||||
void SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
auto &encoder = *GetParam();
|
||||
if (!video::validate_encoder(encoder, false)) {
|
||||
// Encoder failed validation,
|
||||
@@ -49,7 +50,7 @@ TEST_P(EncoderTest, ValidateEncoder) {
|
||||
// todo:: test something besides fixture setup
|
||||
}
|
||||
|
||||
struct FramerateX100Test: testing::TestWithParam<std::tuple<std::int32_t, AVRational>> {};
|
||||
struct FramerateX100Test: BaseTest, testing::WithParamInterface<std::tuple<std::int32_t, AVRational>> {};
|
||||
|
||||
TEST_P(FramerateX100Test, Run) {
|
||||
const auto &[x100, expected] = GetParam();
|
||||
|
||||
Reference in New Issue
Block a user