From 40bf372046ca82491a1d63b5a96b42d967a0a515 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:49:03 -0400 Subject: [PATCH] fix lint warnings --- tests/ci/test_docs.cpp | 20 +- tests/conftest.cpp | 604 +++++++++++++++++++------------------- tests/unit/test_video.cpp | 29 +- tests/utils.cpp | 3 +- tests/utils.h | 3 +- 5 files changed, 338 insertions(+), 321 deletions(-) diff --git a/tests/ci/test_docs.cpp b/tests/ci/test_docs.cpp index bfab2ea5f30..70ab2bb5fc6 100644 --- a/tests/ci/test_docs.cpp +++ b/tests/ci/test_docs.cpp @@ -1,10 +1,12 @@ #include -class DocsTests : public DocsTestFixture, public ::testing::WithParamInterface> {}; -INSTANTIATE_TEST_SUITE_P(DocFormats, DocsTests, ::testing::Values( +class DocsTests: public DocsTestFixture, public ::testing::WithParamInterface> {}; +INSTANTIATE_TEST_SUITE_P( + DocFormats, + DocsTests, + ::testing::Values( std::make_tuple("html", "index.html"), - std::make_tuple("epub", "Sunshine.epub") -)); + std::make_tuple("epub", "Sunshine.epub"))); TEST_P(DocsTests, MakeDocs) { auto params = GetParam(); std::string format = std::get<0>(params); @@ -19,11 +21,13 @@ TEST_P(DocsTests, MakeDocs) { EXPECT_TRUE(std::filesystem::exists(expected_file)); } -class DocsRstTests : public DocsPythonVenvTest, public ::testing::WithParamInterface {}; -INSTANTIATE_TEST_SUITE_P(RstFiles, DocsRstTests, ::testing::Values( +class DocsRstTests: public DocsPythonVenvTest, public ::testing::WithParamInterface {}; +INSTANTIATE_TEST_SUITE_P( + RstFiles, + DocsRstTests, + ::testing::Values( std::filesystem::path(TESTS_DOCS_DIR), - std::filesystem::path(TESTS_SOURCE_DIR) / "README.rst" -)); + std::filesystem::path(TESTS_SOURCE_DIR) / "README.rst")); TEST_P(DocsRstTests, RstCheckDocs) { std::filesystem::path docs_dir = GetParam(); std::string command = "rstcheck -r " + docs_dir.string(); diff --git a/tests/conftest.cpp b/tests/conftest.cpp index 4644b79dc5d..0f2da8eecc6 100644 --- a/tests/conftest.cpp +++ b/tests/conftest.cpp @@ -1,15 +1,15 @@ -#include #include +#include #include -#include #include #include #include +#include #include -#include #include +#include #include @@ -20,9 +20,9 @@ namespace sinks = logging::sinks; #undef TEST // Redefine TEST to use our BaseTest class, to automatically use our BaseTest fixture -#define TEST(test_case_name, test_name)\ +#define TEST(test_case_name, test_name) \ GTEST_TEST_(test_case_name, test_name, ::BaseTest, \ - ::testing::internal::GetTypeId< ::BaseTest >()) + ::testing::internal::GetTypeId<::BaseTest>()) /** * @brief Base class for tests. @@ -33,343 +33,353 @@ namespace sinks = logging::sinks; * * @todo Retain the color of the original output. */ -class BaseTest : public ::testing::Test { - protected: - // https://stackoverflow.com/a/58369622/11214013 - - // we can possibly use some internal googletest functions to capture stdout and stderr, but I have not tested this - // https://stackoverflow.com/a/33186201/11214013 - - // Add a member variable to store the sink - boost::shared_ptr> test_sink; +class BaseTest: public ::testing::Test { +protected: + // https://stackoverflow.com/a/58369622/11214013 - BaseTest() : sbuf{nullptr}, pipe_stdout{nullptr}, pipe_stderr{nullptr} { - // intentionally empty - } - - ~BaseTest() override = default; - - void SetUp() override { - // todo: only run this one time, instead of every time a test is run - // see: https://stackoverflow.com/questions/2435277/googletest-accessing-the-environment-from-a-test - // get command line args from the test executable - testArgs = ::testing::internal::GetArgvs(); - - // then get the directory of the test executable - //std::string path = ::testing::internal::GetArgvs()[0]; - testBinary = testArgs[0]; + // we can possibly use some internal googletest functions to capture stdout and stderr, but I have not tested this + // https://stackoverflow.com/a/33186201/11214013 - // get the directory of the test executable - testBinaryDir = std::filesystem::path(testBinary).parent_path(); + // Add a member variable to store the sink + boost::shared_ptr> test_sink; - // If testBinaryDir is empty or `.` then set it to the current directory - // maybe some better options here: https://stackoverflow.com/questions/875249/how-to-get-current-directory - if (testBinaryDir.empty() || testBinaryDir.string() == ".") { - testBinaryDir = std::filesystem::current_path(); - } + BaseTest(): + sbuf { nullptr }, pipe_stdout { nullptr }, pipe_stderr { nullptr } { + // intentionally empty + } - // Create a sink that writes to our stringstream (BOOST_LOG) - typedef sinks::synchronous_sink test_text_sink; - test_sink = boost::make_shared(); + ~BaseTest() override = default; - // Set the stringstream as the target of the sink (BOOST_LOG) - boost::shared_ptr< std::ostream > stream(&boost_log_buffer, [](std::ostream*) {}); - test_sink->locked_backend()->add_stream(stream); + void + SetUp() override { + // todo: only run this one time, instead of every time a test is run + // see: https://stackoverflow.com/questions/2435277/googletest-accessing-the-environment-from-a-test + // get command line args from the test executable + testArgs = ::testing::internal::GetArgvs(); - // Register the sink in the logging core (BOOST_LOG) - logging::core::get()->add_sink(test_sink); + // then get the directory of the test executable + // std::string path = ::testing::internal::GetArgvs()[0]; + testBinary = testArgs[0]; - sbuf = std::cout.rdbuf(); // save cout buffer (std::cout) - std::cout.rdbuf( cout_buffer.rdbuf() ); // redirect cout to buffer (std::cout) + // get the directory of the test executable + testBinaryDir = std::filesystem::path(testBinary).parent_path(); - // todo: do this only once - // setup a mail object - mail::man = std::make_shared(); + // If testBinaryDir is empty or `.` then set it to the current directory + // maybe some better options here: https://stackoverflow.com/questions/875249/how-to-get-current-directory + if (testBinaryDir.empty() || testBinaryDir.string() == ".") { + testBinaryDir = std::filesystem::current_path(); } - void TearDown() override { - std::cout.rdbuf( sbuf ); // restore cout buffer - - // get test info - const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); - - if (test_info->result()->Failed()) { - std::cout << std::endl - << "Test failed: " << test_info->name() << std::endl << std::endl - << "Captured boost log:" << std::endl - << boost_log_buffer.str() << std::endl - << "Captured cout:" << std::endl - << cout_buffer.str() << std::endl - << "Captured stdout:" << std::endl - << stdout_buffer.str() << std::endl - << "Captured stderr:" << std::endl - << stderr_buffer.str() << std::endl; - } - - sbuf = nullptr; // clear sbuf - if (pipe_stdout) { - pclose(pipe_stdout); - pipe_stdout = nullptr; - } - if (pipe_stderr) { - pclose(pipe_stderr); - pipe_stderr = nullptr; - } - - // Remove the sink from the logging core (BOOST_LOG) - logging::core::get()->remove_sink(test_sink); - test_sink.reset(); + // Create a sink that writes to our stringstream (BOOST_LOG) + typedef sinks::synchronous_sink test_text_sink; + test_sink = boost::make_shared(); + + // Set the stringstream as the target of the sink (BOOST_LOG) + boost::shared_ptr stream(&boost_log_buffer, [](std::ostream *) {}); + test_sink->locked_backend()->add_stream(stream); + + // Register the sink in the logging core (BOOST_LOG) + logging::core::get()->add_sink(test_sink); + + sbuf = std::cout.rdbuf(); // save cout buffer (std::cout) + std::cout.rdbuf(cout_buffer.rdbuf()); // redirect cout to buffer (std::cout) + + // todo: do this only once + // setup a mail object + mail::man = std::make_shared(); + } + + void + TearDown() override { + std::cout.rdbuf(sbuf); // restore cout buffer + + // get test info + const ::testing::TestInfo *const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); + + if (test_info->result()->Failed()) { + std::cout << std::endl + << "Test failed: " << test_info->name() << std::endl + << std::endl + << "Captured boost log:" << std::endl + << boost_log_buffer.str() << std::endl + << "Captured cout:" << std::endl + << cout_buffer.str() << std::endl + << "Captured stdout:" << std::endl + << stdout_buffer.str() << std::endl + << "Captured stderr:" << std::endl + << stderr_buffer.str() << std::endl; } - // functions and variables - std::vector testArgs; // CLI arguments used - std::filesystem::path testBinary; // full path of this binary - std::filesystem::path testBinaryDir; // full directory of this binary - std::stringstream boost_log_buffer; // declare boost_log_buffer - std::stringstream cout_buffer; // declare cout_buffer - std::stringstream stdout_buffer; // declare stdout_buffer - std::stringstream stderr_buffer; // declare stderr_buffer - std::streambuf* sbuf; - FILE* pipe_stdout; - FILE* pipe_stderr; - - int exec(const char* cmd) { - std::array buffer{}; - pipe_stdout = popen((std::string(cmd) + " 2>&1").c_str(), "r"); - pipe_stderr = popen((std::string(cmd) + " 2>&1").c_str(), "r"); - if (!pipe_stdout || !pipe_stderr) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer.data(), buffer.size(), pipe_stdout) != nullptr) { - stdout_buffer << buffer.data(); - } - while (fgets(buffer.data(), buffer.size(), pipe_stderr) != nullptr) { - stderr_buffer << buffer.data(); - } - int returnCode = pclose(pipe_stdout); + sbuf = nullptr; // clear sbuf + if (pipe_stdout) { + pclose(pipe_stdout); pipe_stdout = nullptr; - if (returnCode != 0) { - std::cout << "Error: " << stderr_buffer.str() << std::endl << "Return code: " << returnCode << std::endl; - } - return returnCode; } -}; - -class PlatformInitBase : public virtual BaseTest { - protected: - - void SetUp() override{ - std::cout << "PlatformInitTest:: starting Fixture SetUp" << std::endl; - - // initialize the platform - auto deinit_guard = platf::init(); - if (!deinit_guard) { - FAIL() << "Platform failed to initialize"; - } - - std::cout << "PlatformInitTest:: finished Fixture SetUp" << std::endl; + if (pipe_stderr) { + pclose(pipe_stderr); + pipe_stderr = nullptr; } - void TearDown() override{ - std::cout << "PlatformInitTest:: starting Fixture TearDown" << std::endl; - std::cout << "PlatformInitTest:: finished Fixture TearDown" << std::endl; + // Remove the sink from the logging core (BOOST_LOG) + logging::core::get()->remove_sink(test_sink); + test_sink.reset(); + } + + // functions and variables + std::vector testArgs; // CLI arguments used + std::filesystem::path testBinary; // full path of this binary + std::filesystem::path testBinaryDir; // full directory of this binary + std::stringstream boost_log_buffer; // declare boost_log_buffer + std::stringstream cout_buffer; // declare cout_buffer + std::stringstream stdout_buffer; // declare stdout_buffer + std::stringstream stderr_buffer; // declare stderr_buffer + std::streambuf *sbuf; + FILE *pipe_stdout; + FILE *pipe_stderr; + + int + exec(const char *cmd) { + std::array buffer {}; + pipe_stdout = popen((std::string(cmd) + " 2>&1").c_str(), "r"); + pipe_stderr = popen((std::string(cmd) + " 2>&1").c_str(), "r"); + if (!pipe_stdout || !pipe_stderr) { + throw std::runtime_error("popen() failed!"); } + while (fgets(buffer.data(), buffer.size(), pipe_stdout) != nullptr) { + stdout_buffer << buffer.data(); + } + while (fgets(buffer.data(), buffer.size(), pipe_stderr) != nullptr) { + stderr_buffer << buffer.data(); + } + int returnCode = pclose(pipe_stdout); + pipe_stdout = nullptr; + if (returnCode != 0) { + std::cout << "Error: " << stderr_buffer.str() << std::endl + << "Return code: " << returnCode << std::endl; + } + return returnCode; + } }; -class DocsPythonVenvBase : public virtual BaseTest { - protected: +class PlatformInitBase: public virtual BaseTest { +protected: + void + SetUp() override { + std::cout << "PlatformInitTest:: starting Fixture SetUp" << std::endl; - void - SetUp() override{ - #if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 0 - GTEST_SKIP_("TESTS_ENABLE_VENV_TESTS is disabled by CMake"); - #else - std::cout << "DocsPythonVenvTest:: starting Fixture SetUp" << std::endl; + // initialize the platform + auto deinit_guard = platf::init(); + if (!deinit_guard) { + FAIL() << "Platform failed to initialize"; + } - std::string pythonBinDirArray[] = {"bin", "Scripts"}; - std::filesystem::path pythonPath = "python"; - std::string binPath; - std::string command; - int exit_code; + std::cout << "PlatformInitTest:: finished Fixture SetUp" << std::endl; + } - std::filesystem::path venvPath = ".venv"; - std::filesystem::path fullVenvPath = BaseTest::testBinaryDir / venvPath; + void + TearDown() override { + std::cout << "PlatformInitTest:: starting Fixture TearDown" << std::endl; + std::cout << "PlatformInitTest:: finished Fixture TearDown" << std::endl; + } +}; - // check for existence of venv, and create it if necessary - std::cout << "DocsPythonVenvTest:: checking for venv" << std::endl; +class DocsPythonVenvBase: public virtual BaseTest { +protected: + void + SetUp() override { +#if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 0 + GTEST_SKIP_("TESTS_ENABLE_VENV_TESTS is disabled by CMake"); +#else + std::cout << "DocsPythonVenvTest:: starting Fixture SetUp" << std::endl; + + std::string pythonBinDirArray[] = { "bin", "Scripts" }; + std::filesystem::path pythonPath = "python"; + std::string binPath; + std::string command; + int exit_code; + + std::filesystem::path venvPath = ".venv"; + std::filesystem::path fullVenvPath = BaseTest::testBinaryDir / venvPath; + + // check for existence of venv, and create it if necessary + std::cout << "DocsPythonVenvTest:: checking for venv" << std::endl; + if (!std::filesystem::exists(fullVenvPath)) { + std::cout << "DocsPythonVenvTest:: venv not found" << std::endl; + + // create the venv + command = "\"" TESTS_PYTHON_EXECUTABLE "\" -m venv " + fullVenvPath.string(); + std::cout << "DocsPythonVenvTest:: trying to create venv with command: " << command << std::endl; + exit_code = BaseTest::exec(command.c_str()); + if (exit_code != 0) { if (!std::filesystem::exists(fullVenvPath)) { - std::cout << "DocsPythonVenvTest:: venv not found" << std::endl; - - // create the venv - command = "\"" TESTS_PYTHON_EXECUTABLE "\" -m venv " + fullVenvPath.string(); - std::cout << "DocsPythonVenvTest:: trying to create venv with command: " << command << std::endl; - exit_code = BaseTest::exec(command.c_str()); - if (exit_code != 0) { - if (!std::filesystem::exists(fullVenvPath)) { - FAIL() << "Command failed: " << command << " with exit code: " << exit_code; - } - else { - // venv command will randomly complain that some files already exist... - std::cout << "DocsPythonVenvTest:: exit code (" << exit_code << ") indicates venv creation failed, but venv exists" << std::endl; - } - } - } - - // determine if bin directory is `bin` (Unix) or `Scripts` (Windows) - // cannot assume `Scripts` on Windows, as it could be `bin` if using MSYS2, cygwin, etc. - std::cout << "DocsPythonVenvTest:: checking structure of venv" << std::endl; - for (const std::string& binDir : pythonBinDirArray) { - // check if bin directory exists - if (std::filesystem::exists(fullVenvPath / binDir)) { - binPath = binDir; - std::cout << "DocsPythonVenvTest:: found binPath: " << binPath << std::endl; - break; - } - } - - if (binPath.empty()) { - FAIL() << "Python venv not found"; + FAIL() << "Command failed: " << command << " with exit code: " << exit_code; } - - // set fullPythonPath and fullPythonBinPath - fullPythonPath = fullVenvPath / binPath / pythonPath; - fullPythonBinPath = fullVenvPath / binPath; - - std::cout << "DocsPythonVenvTest:: fullPythonPath: " << fullPythonPath << std::endl; - std::cout << "DocsPythonVenvTest:: fullPythonBinPath: " << fullPythonBinPath << std::endl; - - std::filesystem::path requirements_path = std::filesystem::path(TESTS_DOCS_DIR) / "requirements.txt"; - - // array of commands to run - std::string CommandArray[] = { - "\"" + fullPythonPath.string() + "\" -m pip install -r " + requirements_path.string(), - }; - - for (const std::string& _command : CommandArray) { - std::cout << "DocsPythonVenvTest:: running command: " << _command << std::endl; - exit_code = BaseTest::exec(_command.c_str()); - if (exit_code != 0) { - FAIL() << "Command failed: " << command << " with exit code: " << exit_code; - } + else { + // venv command will randomly complain that some files already exist... + std::cout << "DocsPythonVenvTest:: exit code (" << exit_code << ") indicates venv creation failed, but venv exists" << std::endl; } - - // Save the original PATH - originalEnvPath = std::getenv("PATH") ? std::getenv("PATH") : ""; - std::cout << "DocsPythonVenvTest:: originalEnvPath: " << originalEnvPath << std::endl; - - // Set the temporary PATH - std::string tempPath; - std::string envPathSep; - - #ifdef _WIN32 - envPathSep = ";"; - #else - envPathSep = ":"; - #endif - tempPath = fullPythonBinPath.string() + envPathSep + originalEnvPath; - std::cout << "DocsPythonVenvTest:: tempPath: " << tempPath << std::endl; - setEnv("PATH", tempPath); - - std::cout << "DocsPythonVenvTest:: finished Fixture SetUp" << std::endl; - #endif - } - - void - TearDown() override{ - std::cout << "DocsPythonVenvTest:: starting Fixture TearDown" << std::endl; - - // Restore the original PATH - if (!originalEnvPath.empty()) { - std::cout << "DocsPythonVenvTest:: restoring originalEnvPath: " << originalEnvPath << std::endl; - setEnv("PATH", originalEnvPath); } - - std::cout << "DocsPythonVenvTest:: finished Fixture TearDown" << std::endl; } - // functions and variables - std::filesystem::path fullPythonPath; - std::filesystem::path fullPythonBinPath; - std::string originalEnvPath; -}; - -class DocsPythonVenvTest : public virtual BaseTest, public DocsPythonVenvBase { - protected: - - void SetUp() override { - BaseTest::SetUp(); - DocsPythonVenvBase::SetUp(); + // determine if bin directory is `bin` (Unix) or `Scripts` (Windows) + // cannot assume `Scripts` on Windows, as it could be `bin` if using MSYS2, cygwin, etc. + std::cout << "DocsPythonVenvTest:: checking structure of venv" << std::endl; + for (const std::string &binDir : pythonBinDirArray) { + // check if bin directory exists + if (std::filesystem::exists(fullVenvPath / binDir)) { + binPath = binDir; + std::cout << "DocsPythonVenvTest:: found binPath: " << binPath << std::endl; + break; + } } - void TearDown() override { - DocsPythonVenvBase::TearDown(); - BaseTest::TearDown(); + if (binPath.empty()) { + FAIL() << "Python venv not found"; } -}; -class DocsWorkingDirectoryBase : public virtual BaseTest { - protected: + // set fullPythonPath and fullPythonBinPath + fullPythonPath = fullVenvPath / binPath / pythonPath; + fullPythonBinPath = fullVenvPath / binPath; - void SetUp() override{ - #if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 1 - std::cout << "DocsWorkingDirectoryTest:: starting Fixture SetUp" << std::endl; + std::cout << "DocsPythonVenvTest:: fullPythonPath: " << fullPythonPath << std::endl; + std::cout << "DocsPythonVenvTest:: fullPythonBinPath: " << fullPythonBinPath << std::endl; - temp_dir = TESTS_DOCS_DIR; - std::cout << "DocsWorkingDirectoryTest:: temp_dir: " << temp_dir << std::endl; + std::filesystem::path requirements_path = std::filesystem::path(TESTS_DOCS_DIR) / "requirements.txt"; - // change directory to `docs` - original_dir = std::filesystem::current_path(); // save original directory - std::cout << "DocsWorkingDirectoryTest:: original_dir: " << original_dir << std::endl; - std::filesystem::current_path(temp_dir); - std::cout << "DocsWorkingDirectoryTest:: working directory set to: " << std::filesystem::current_path() << std::endl; + // array of commands to run + std::string CommandArray[] = { + "\"" + fullPythonPath.string() + "\" -m pip install -r " + requirements_path.string(), + }; - std::cout << "DocsWorkingDirectoryTest:: finished Fixture SetUp" << std::endl; - #endif + for (const std::string &_command : CommandArray) { + std::cout << "DocsPythonVenvTest:: running command: " << _command << std::endl; + exit_code = BaseTest::exec(_command.c_str()); + if (exit_code != 0) { + FAIL() << "Command failed: " << command << " with exit code: " << exit_code; + } } - void TearDown() override{ - #if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 1 - std::cout << "DocsWorkingDirectoryTest:: starting Fixture TearDown" << std::endl; - - // change directory back to original - std::filesystem::current_path(original_dir); - std::cout << "DocsWorkingDirectoryTest:: working directory set to: " << std::filesystem::current_path() << std::endl; - - std::cout << "DocsWorkingDirectoryTest:: finished Fixture TearDown" << std::endl; - #endif + // Save the original PATH + originalEnvPath = std::getenv("PATH") ? std::getenv("PATH") : ""; + std::cout << "DocsPythonVenvTest:: originalEnvPath: " << originalEnvPath << std::endl; + + // Set the temporary PATH + std::string tempPath; + std::string envPathSep; + + #ifdef _WIN32 + envPathSep = ";"; + #else + envPathSep = ":"; + #endif + tempPath = fullPythonBinPath.string() + envPathSep + originalEnvPath; + std::cout << "DocsPythonVenvTest:: tempPath: " << tempPath << std::endl; + setEnv("PATH", tempPath); + + std::cout << "DocsPythonVenvTest:: finished Fixture SetUp" << std::endl; +#endif + } + + void + TearDown() override { + std::cout << "DocsPythonVenvTest:: starting Fixture TearDown" << std::endl; + + // Restore the original PATH + if (!originalEnvPath.empty()) { + std::cout << "DocsPythonVenvTest:: restoring originalEnvPath: " << originalEnvPath << std::endl; + setEnv("PATH", originalEnvPath); } - // functions and variables - std::filesystem::path original_dir; - std::filesystem::path temp_dir; -}; - -class DocsWorkingDirectoryTest : public virtual BaseTest, public DocsWorkingDirectoryBase { - protected: + std::cout << "DocsPythonVenvTest:: finished Fixture TearDown" << std::endl; + } - void SetUp() override { - BaseTest::SetUp(); - DocsWorkingDirectoryBase::SetUp(); - } + // functions and variables + std::filesystem::path fullPythonPath; + std::filesystem::path fullPythonBinPath; + std::string originalEnvPath; +}; - void TearDown() override { - DocsWorkingDirectoryBase::TearDown(); - BaseTest::TearDown(); - } +class DocsPythonVenvTest: public virtual BaseTest, public DocsPythonVenvBase { +protected: + void + SetUp() override { + BaseTest::SetUp(); + DocsPythonVenvBase::SetUp(); + } + + void + TearDown() override { + DocsPythonVenvBase::TearDown(); + BaseTest::TearDown(); + } }; -class DocsTestFixture : public virtual BaseTest, public DocsPythonVenvBase, public DocsWorkingDirectoryBase{ - protected: +class DocsWorkingDirectoryBase: public virtual BaseTest { +protected: + void + SetUp() override { +#if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 1 + std::cout << "DocsWorkingDirectoryTest:: starting Fixture SetUp" << std::endl; + + temp_dir = TESTS_DOCS_DIR; + std::cout << "DocsWorkingDirectoryTest:: temp_dir: " << temp_dir << std::endl; + + // change directory to `docs` + original_dir = std::filesystem::current_path(); // save original directory + std::cout << "DocsWorkingDirectoryTest:: original_dir: " << original_dir << std::endl; + std::filesystem::current_path(temp_dir); + std::cout << "DocsWorkingDirectoryTest:: working directory set to: " << std::filesystem::current_path() << std::endl; + + std::cout << "DocsWorkingDirectoryTest:: finished Fixture SetUp" << std::endl; +#endif + } + + void + TearDown() override { +#if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 1 + std::cout << "DocsWorkingDirectoryTest:: starting Fixture TearDown" << std::endl; + + // change directory back to original + std::filesystem::current_path(original_dir); + std::cout << "DocsWorkingDirectoryTest:: working directory set to: " << std::filesystem::current_path() << std::endl; + + std::cout << "DocsWorkingDirectoryTest:: finished Fixture TearDown" << std::endl; +#endif + } + + // functions and variables + std::filesystem::path original_dir; + std::filesystem::path temp_dir; +}; - void SetUp() override { - BaseTest::SetUp(); - DocsPythonVenvBase::SetUp(); - DocsWorkingDirectoryBase::SetUp(); - } +class DocsWorkingDirectoryTest: public virtual BaseTest, public DocsWorkingDirectoryBase { +protected: + void + SetUp() override { + BaseTest::SetUp(); + DocsWorkingDirectoryBase::SetUp(); + } + + void + TearDown() override { + DocsWorkingDirectoryBase::TearDown(); + BaseTest::TearDown(); + } +}; - void TearDown() override { - DocsWorkingDirectoryBase::TearDown(); - DocsPythonVenvBase::TearDown(); - BaseTest::TearDown(); - } +class DocsTestFixture: public virtual BaseTest, public DocsPythonVenvBase, public DocsWorkingDirectoryBase { +protected: + void + SetUp() override { + BaseTest::SetUp(); + DocsPythonVenvBase::SetUp(); + DocsWorkingDirectoryBase::SetUp(); + } + + void + TearDown() override { + DocsWorkingDirectoryBase::TearDown(); + DocsPythonVenvBase::TearDown(); + BaseTest::TearDown(); + } }; diff --git a/tests/unit/test_video.cpp b/tests/unit/test_video.cpp index 7e793ac966f..b1a664f74ef 100644 --- a/tests/unit/test_video.cpp +++ b/tests/unit/test_video.cpp @@ -6,10 +6,10 @@ #include - -class EncoderTest : public virtual BaseTest, public PlatformInitBase, public ::testing::WithParamInterface, video::encoder_t*>> { +class EncoderTest: public virtual BaseTest, public PlatformInitBase, public ::testing::WithParamInterface, video::encoder_t *>> { protected: - void SetUp() override { + void + SetUp() override { BaseTest::SetUp(); PlatformInitBase::SetUp(); @@ -17,7 +17,7 @@ class EncoderTest : public virtual BaseTest, public PlatformInitBase, public ::t std::cout << "EncoderTest(" << p_name << "):: starting Fixture SetUp" << std::endl; std::cout << "EncoderTest(" << p_name << "):: validating encoder" << std::endl; - video::encoder_t* encoder = std::get<1>(GetParam()); + video::encoder_t *encoder = std::get<1>(GetParam()); bool isEncoderValid; isEncoderValid = video::validate_encoder(*encoder, false); @@ -39,29 +39,30 @@ class EncoderTest : public virtual BaseTest, public PlatformInitBase, public ::t } } - void TearDown() override { + void + TearDown() override { PlatformInitBase::TearDown(); BaseTest::TearDown(); } }; -INSTANTIATE_TEST_SUITE_P(EncoderVariants, EncoderTest, ::testing::Values( +INSTANTIATE_TEST_SUITE_P( + EncoderVariants, + EncoderTest, + ::testing::Values( // todo: all encoders crash on windows, probably due to platf not being initialized (which also crashes) #if !defined(__APPLE__) - std::make_tuple(video::nvenc.name, &video::nvenc), + std::make_tuple(video::nvenc.name, &video::nvenc), #endif #ifdef _WIN32 - std::make_tuple(video::amdvce.name, &video::amdvce), - std::make_tuple(video::quicksync.name, &video::quicksync), + std::make_tuple(video::amdvce.name, &video::amdvce), std::make_tuple(video::quicksync.name, &video::quicksync), #endif #ifdef __linux__ - std::make_tuple(video::vaapi.name, &video::vaapi), + std::make_tuple(video::vaapi.name, &video::vaapi), #endif #ifdef __APPLE__ - std::make_tuple(video::videotoolbox.name, &video::videotoolbox), + std::make_tuple(video::videotoolbox.name, &video::videotoolbox), #endif - std::make_tuple(video::software.name, &video::software) -) -); + std::make_tuple(video::software.name, &video::software))); TEST_P(EncoderTest, ValidateEncoder) { // todo:: test something besides fixture setup } diff --git a/tests/utils.cpp b/tests/utils.cpp index c4846a3ba6a..2ff1bfd6ecd 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -11,7 +11,8 @@ * @param value Value of the environment variable * @return 0 on success, non-zero error code on failure */ -int setEnv(const std::string& name, const std::string& value) { +int +setEnv(const std::string &name, const std::string &value) { #ifdef _WIN32 return _putenv_s(name.c_str(), value.c_str()); #else diff --git a/tests/utils.h b/tests/utils.h index f3eee0e73c7..f82de91944c 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -7,4 +7,5 @@ #include -int setEnv(const std::string& name, const std::string& value); +int +setEnv(const std::string &name, const std::string &value);