diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-06-27 10:42:09 +0300 |
---|---|---|
committer | Ilya Zverev <ilya@zverev.info> | 2017-06-28 19:41:05 +0300 |
commit | c878b6a37dd87f57c9db8754a9e30e2ea713220c (patch) | |
tree | 4e71afec05aea4e299a59168e4761d6133d9e6a1 /base | |
parent | 5ec098db10080525bc57f304e2ca9f5aed3dcb63 (diff) |
review fixes
Diffstat (limited to 'base')
-rw-r--r-- | base/base_tests/logging_test.cpp | 18 | ||||
-rw-r--r-- | base/logging.hpp | 8 |
2 files changed, 26 insertions, 0 deletions
diff --git a/base/base_tests/logging_test.cpp b/base/base_tests/logging_test.cpp index ff5e50ad16..365db44668 100644 --- a/base/base_tests/logging_test.cpp +++ b/base/base_tests/logging_test.cpp @@ -18,6 +18,13 @@ namespace g_SomeFunctionCalled = true; return 3; } + + bool g_NegativeFunctionCalled; + bool NegativeFunction() + { + g_NegativeFunctionCalled = true; + return false; + } } UNIT_TEST(Logging_Level) @@ -43,3 +50,14 @@ 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, ()); +} diff --git a/base/logging.hpp b/base/logging.hpp index 163041e0fb..147958938a 100644 --- a/base/logging.hpp +++ b/base/logging.hpp @@ -87,3 +87,11 @@ using ::my::LCRITICAL; if ((level) >= ::my::g_LogLevel) \ ::my::LogMessage(level, my::SrcPoint(), ::my::impl::Message msg); \ } while (false) + +// Conditional log. Logs @msg with level @level in case when @X returns false. +#define CLOG(level, X, msg) \ + do \ + { \ + if (!X) \ + LOG(level, (SRC(), "CLOG(" #X ")", ::my::impl::Message msg)); \ + } while (false) |