Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorArsentiy Milchakov <milcars@mapswithme.com>2017-06-27 10:42:09 +0300
committerIlya Zverev <ilya@zverev.info>2017-06-28 19:41:05 +0300
commitc878b6a37dd87f57c9db8754a9e30e2ea713220c (patch)
tree4e71afec05aea4e299a59168e4761d6133d9e6a1 /base
parent5ec098db10080525bc57f304e2ca9f5aed3dcb63 (diff)
review fixes
Diffstat (limited to 'base')
-rw-r--r--base/base_tests/logging_test.cpp18
-rw-r--r--base/logging.hpp8
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)