mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
committed by
Konstantin Pastbin
parent
c9cbb64f12
commit
76ffc99abd
62
libs/base/base_tests/logging_test.cpp
Normal file
62
libs/base/base_tests/logging_test.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void TestLogMessage(base::LogLevel, base::SrcPoint const &, std::string const &)
|
||||
{
|
||||
}
|
||||
|
||||
bool g_SomeFunctionCalled;
|
||||
int SomeFunction()
|
||||
{
|
||||
g_SomeFunctionCalled = true;
|
||||
return 3;
|
||||
}
|
||||
|
||||
bool BoolFunction(bool result, bool & called)
|
||||
{
|
||||
called = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(Logging_Level)
|
||||
{
|
||||
base::LogLevel const logLevelSaved = base::g_LogLevel;
|
||||
base::g_LogLevel = LWARNING;
|
||||
|
||||
g_SomeFunctionCalled = false;
|
||||
base::LogMessageFn logMessageSaved = base::SetLogMessageFn(&TestLogMessage);
|
||||
|
||||
LOG(LINFO, ("This should not pass", SomeFunction()));
|
||||
TEST(!g_SomeFunctionCalled, ());
|
||||
|
||||
LOG(LWARNING, ("This should pass", SomeFunction()));
|
||||
TEST(g_SomeFunctionCalled, ());
|
||||
|
||||
base::SetLogMessageFn(logMessageSaved);
|
||||
base::g_LogLevel = logLevelSaved;
|
||||
}
|
||||
|
||||
UNIT_TEST(NullMessage)
|
||||
{
|
||||
char const * ptr = 0;
|
||||
LOG(LINFO, ("Null message test", ptr));
|
||||
}
|
||||
|
||||
UNIT_TEST(Logging_ConditionalLog)
|
||||
{
|
||||
bool isCalled = false;
|
||||
CLOG(LINFO, BoolFunction(true, isCalled), ("This should not be displayed"));
|
||||
TEST(isCalled, ());
|
||||
|
||||
isCalled = false;
|
||||
CLOG(LWARNING, BoolFunction(false, isCalled), ("This should be displayed"));
|
||||
TEST(isCalled, ());
|
||||
}
|
||||
Reference in New Issue
Block a user