1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "testing/testing.hpp"
#include "base/logging.hpp"
#include <utility>
#include <vector>
namespace
{
void TestLogMessage(my::LogLevel, my::SrcPoint const &, std::string const &)
{
}
bool g_SomeFunctionCalled;
int SomeFunction()
{
g_SomeFunctionCalled = true;
return 3;
}
bool g_NegativeFunctionCalled;
bool NegativeFunction()
{
g_NegativeFunctionCalled = true;
return false;
}
}
UNIT_TEST(Logging_Level)
{
my::LogLevel const logLevelSaved = my::g_LogLevel;
my::g_LogLevel = LWARNING;
g_SomeFunctionCalled = false;
my::LogMessageFn logMessageSaved = my::SetLogMessageFn(&TestLogMessage);
LOG(LINFO, ("This should not pass", SomeFunction()));
TEST(!g_SomeFunctionCalled, ());
LOG(LWARNING, ("This should pass", SomeFunction()));
TEST(g_SomeFunctionCalled, ());
my::SetLogMessageFn(logMessageSaved);
my::g_LogLevel = logLevelSaved;
}
UNIT_TEST(NullMessage)
{
char const * ptr = 0;
LOG(LINFO, ("Null message test", ptr));
}
UNIT_TEST(Logging_ConditionalLog)
{
g_SomeFunctionCalled = false;
CLOG(LINFO, SomeFunction(), ("This should not pass"));
TEST(g_SomeFunctionCalled, ());
g_NegativeFunctionCalled = false;
CLOG(LWARNING, NegativeFunction(), ("This should pass"));
TEST(g_NegativeFunctionCalled, ());
}
|