Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Aug 21, 2024
1 parent 6250d2b commit 7ee49ba
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 56 deletions.
5 changes: 3 additions & 2 deletions src/Console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ void Console::SetVerbosity(const int _level)
return;
}

verbosity = _level;
switch (_level)
{
case 0:
Expand All @@ -166,8 +165,10 @@ void Console::SetVerbosity(const int _level)
default:
Console::Root().RawLogger().log(spdlog::level::info,
"Unknown verbosity level. Values should be between 0 and 5. Ignoring it");
break;
return;
}

verbosity = _level;
}

//////////////////////////////////////////////////
Expand Down
109 changes: 55 additions & 54 deletions src/Console_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,60 +485,61 @@ TEST_F(Console_TEST, ColorErr)
EXPECT_TRUE(logContent.find(logString) != std::string::npos);
}

// /////////////////////////////////////////////////
// /// \brief Test Console::Verbosity
// TEST_F(Console_TEST, Verbosity)
// {
// EXPECT_EQ(common::Console::Verbosity(), 1);

// common::Console::SetVerbosity(2);
// EXPECT_EQ(common::Console::Verbosity(), 2);

// common::Console::SetVerbosity(-1);
// EXPECT_EQ(common::Console::Verbosity(), -1);
// }

// /////////////////////////////////////////////////
// /// \brief Test Console::Prefix
// TEST_F(Console_TEST, Prefix)
// {
// // Max verbosity
// common::Console::SetVerbosity(4);

// // Path to log file
// auto path = common::uuid();

// gzLogInit(path, "test.log");
// std::string logPath = common::joinPaths(path, "test.log");

// // Check default prefix
// EXPECT_EQ(common::Console::Prefix(), "");

// // Set new prefix
// common::Console::SetPrefix("**test** ");
// EXPECT_EQ(common::Console::Prefix(), "**test** ");

// // Use the console
// gzerr << "error" << std::endl;
// gzwarn << "warning" << std::endl;
// gzmsg << "message" << std::endl;
// gzdbg << "debug" << std::endl;

// common::Console::Root().RawLogger().flush();

// // Get the logged content
// std::string logContent = GetLogContent(logPath);

// // Check
// EXPECT_TRUE(logContent.find("**test** [Err]") != std::string::npos);
// EXPECT_TRUE(logContent.find("**test** [Wrn]") != std::string::npos);
// EXPECT_TRUE(logContent.find("**test** [Msg]") != std::string::npos);
// EXPECT_TRUE(logContent.find("**test** [Dbg]") != std::string::npos);

// // Reset
// common::Console::SetPrefix("");
// EXPECT_EQ(common::Console::Prefix(), "");
// }
/////////////////////////////////////////////////
/// \brief Test Console::Verbosity
TEST_F(Console_TEST, Verbosity)
{
common::Console::SetVerbosity(2);
EXPECT_EQ(2, common::Console::Verbosity());

common::Console::SetVerbosity(-1);
EXPECT_EQ(2, common::Console::Verbosity());

common::Console::SetVerbosity(1000);
EXPECT_EQ(2, common::Console::Verbosity());
}

/////////////////////////////////////////////////
/// \brief Test Console::Prefix
TEST_F(Console_TEST, Prefix)
{
// Max verbosity
common::Console::SetVerbosity(4);

// Path to log file
auto path = common::uuid();

gzLogInit(path, "test.log");
std::string logPath = common::joinPaths(path, "test.log");

// Check default prefix
EXPECT_EQ(common::Console::Prefix(), "");

// Set new prefix
common::Console::SetPrefix("**test** ");
EXPECT_EQ(common::Console::Prefix(), "**test** ");

// Use the console
gzerr << "error" << std::endl;
gzwarn << "warning" << std::endl;
gzmsg << "message" << std::endl;
gzdbg << "debug" << std::endl;

common::Console::Root().RawLogger().flush();

// Get the logged content
std::string logContent = GetLogContent(logPath);

// Check
EXPECT_TRUE(logContent.find("**test** error") != std::string::npos);
EXPECT_TRUE(logContent.find("**test** warning") != std::string::npos);
EXPECT_TRUE(logContent.find("**test** message") != std::string::npos);
EXPECT_TRUE(logContent.find("**test** debug") != std::string::npos);

// Reset
common::Console::SetPrefix("");
EXPECT_EQ(common::Console::Prefix(), "");
}

/////////////////////////////////////////////////
/// \brief Test Console::LogDirectory
Expand Down

0 comments on commit 7ee49ba

Please sign in to comment.