fix(logging): add logging namespace and create logging::init method (#2336)
This commit is contained in:
75
tests/unit/test_logging.cpp
Normal file
75
tests/unit/test_logging.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @file tests/test_logging.cpp
|
||||
* @brief Test src/logging.*.
|
||||
*/
|
||||
#include <fstream>
|
||||
|
||||
#include <src/logging.h>
|
||||
|
||||
#include <tests/conftest.cpp>
|
||||
|
||||
class LoggerInitTest: public virtual BaseTest, public ::testing::WithParamInterface<int> {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
};
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
LogLevel,
|
||||
LoggerInitTest,
|
||||
::testing::Values(
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5));
|
||||
TEST_P(LoggerInitTest, InitLogging) {
|
||||
int logLevel = GetParam();
|
||||
std::string logFilePath = "test_log_" + std::to_string(logLevel) + ".log";
|
||||
|
||||
// deinit the BaseTest logger
|
||||
BaseTest::deinit_guard.reset();
|
||||
|
||||
auto log_deinit = logging::init(logLevel, logFilePath);
|
||||
if (!log_deinit) {
|
||||
FAIL() << "Failed to initialize logging";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LogFlushTest, CheckLogFile) {
|
||||
// Write a log message
|
||||
BOOST_LOG(info) << "Test message";
|
||||
|
||||
// Call log_flush
|
||||
logging::log_flush();
|
||||
|
||||
// Check the contents of the log file
|
||||
std::ifstream log_file("test.log");
|
||||
std::string line;
|
||||
bool found = false;
|
||||
while (std::getline(log_file, line)) {
|
||||
if (line.find("Test message") != std::string::npos) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(found);
|
||||
}
|
||||
|
||||
TEST(PrintHelpTest, CheckOutput) {
|
||||
std::string name = "test";
|
||||
logging::print_help(name.c_str());
|
||||
|
||||
std::string output = cout_buffer.str();
|
||||
|
||||
EXPECT_NE(output.find("Usage: " + name), std::string::npos);
|
||||
EXPECT_NE(output.find("--help"), std::string::npos);
|
||||
}
|
||||
@@ -21,10 +21,6 @@ protected:
|
||||
bool isEncoderValid;
|
||||
isEncoderValid = video::validate_encoder(*encoder, false);
|
||||
|
||||
// todo: av logging is not redirected to boost so it will be visible whether the test passes or fails
|
||||
// move this code to logging
|
||||
// https://github.com/LizardByte/Sunshine/blob/5606840c8983b714a0e442c42d887a49807715e1/src/main.cpp#L118
|
||||
|
||||
if (!isEncoderValid) {
|
||||
// if encoder is software fail, otherwise skip
|
||||
if (encoder == &video::software && std::string(TESTS_SOFTWARE_ENCODER_UNAVAILABLE) == "fail") {
|
||||
@@ -49,7 +45,6 @@ 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),
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user