Don't pay a static initializer for expected_assertion_ when it's not used.
BUG=none
TEST=none
Review URL: https://codereview.appspot.com/5883056
git-svn-id: http://rlz.googlecode.com/svn/trunk@112 10bc0f33-e4bf-9a86-80cf-af638054f0c4
diff --git a/lib/assert.cc b/lib/assert.cc
index 1aa5260..44b74c8 100644
--- a/lib/assert.cc
+++ b/lib/assert.cc
@@ -8,6 +8,8 @@
namespace rlz_lib {
+#ifdef MUTE_EXPECTED_ASSERTS
std::string expected_assertion_;
+#endif
} // namespace rlz_lib
diff --git a/lib/assert.h b/lib/assert.h
index 83cbadd..a31a69f 100644
--- a/lib/assert.h
+++ b/lib/assert.h
@@ -21,7 +21,7 @@
do { \
std::string expr_string(expr); \
if (rlz_lib::expected_assertion_ != expr_string) { \
- LOG_IF(FATAL, FALSE) << (expr); \
+ LOG_IF(FATAL, false) << (expr); \
} \
} while (0)
#endif
@@ -37,7 +37,17 @@
#endif
namespace rlz_lib {
- extern std::string expected_assertion_;
-};
+
+#ifdef MUTE_EXPECTED_ASSERTS
+extern std::string expected_assertion_;
+#endif
+
+inline void SetExpectedAssertion(const char* s) {
+#ifdef MUTE_EXPECTED_ASSERTS
+ expected_assertion_ = s;
+#endif
+}
+
+} // rlz_lib
#endif // RLZ_LIB_ASSERT_H_
diff --git a/lib/lib_values_unittest.cc b/lib/lib_values_unittest.cc
index 6cd5e0b..62f55b4 100644
--- a/lib/lib_values_unittest.cc
+++ b/lib/lib_values_unittest.cc
@@ -10,9 +10,9 @@
#include "testing/gtest/include/gtest/gtest.h"
TEST(LibValuesUnittest, GetAccessPointFromName) {
- rlz_lib::expected_assertion_ = "GetAccessPointFromName: point is NULL";
+ rlz_lib::SetExpectedAssertion("GetAccessPointFromName: point is NULL");
EXPECT_FALSE(rlz_lib::GetAccessPointFromName("", NULL));
- rlz_lib::expected_assertion_ = "";
+ rlz_lib::SetExpectedAssertion("");
rlz_lib::AccessPoint point;
EXPECT_FALSE(rlz_lib::GetAccessPointFromName(NULL, &point));
@@ -36,9 +36,9 @@
TEST(LibValuesUnittest, GetEventFromName) {
- rlz_lib::expected_assertion_ = "GetEventFromName: event is NULL";
+ rlz_lib::SetExpectedAssertion("GetEventFromName: event is NULL");
EXPECT_FALSE(rlz_lib::GetEventFromName("", NULL));
- rlz_lib::expected_assertion_ = "";
+ rlz_lib::SetExpectedAssertion("");
rlz_lib::Event event;
EXPECT_FALSE(rlz_lib::GetEventFromName(NULL, &event));
diff --git a/lib/string_utils_unittest.cc b/lib/string_utils_unittest.cc
index 9e7e8c4..4a12bf0 100644
--- a/lib/string_utils_unittest.cc
+++ b/lib/string_utils_unittest.cc
@@ -14,7 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
TEST(StringUtilsUnittest, IsAscii) {
- rlz_lib::expected_assertion_ = "";
+ rlz_lib::SetExpectedAssertion("");
char bad_letters[] = {'\x80', '\xA0', '\xFF'};
for (int i = 0; i < arraysize(bad_letters); ++i)
@@ -26,10 +26,10 @@
}
TEST(StringUtilsUnittest, HexStringToInteger) {
- rlz_lib::expected_assertion_ = "HexStringToInteger: text is NULL.";
+ rlz_lib::SetExpectedAssertion("HexStringToInteger: text is NULL.");
EXPECT_EQ(0, rlz_lib::HexStringToInteger(NULL));
- rlz_lib::expected_assertion_ = "";
+ rlz_lib::SetExpectedAssertion("");
EXPECT_EQ(0, rlz_lib::HexStringToInteger(""));
EXPECT_EQ(0, rlz_lib::HexStringToInteger(" "));
EXPECT_EQ(0, rlz_lib::HexStringToInteger(" 0x "));
@@ -43,15 +43,15 @@
EXPECT_EQ(0xa34Ed0, rlz_lib::HexStringToInteger(" 0x000a34Ed0 "));
EXPECT_EQ(0xa34Ed0, rlz_lib::HexStringToInteger(" 000a34Ed0 "));
- rlz_lib::expected_assertion_ =
- "HexStringToInteger: text contains non-hex characters.";
+ rlz_lib::SetExpectedAssertion(
+ "HexStringToInteger: text contains non-hex characters.");
EXPECT_EQ(0x12ff, rlz_lib::HexStringToInteger("12ffg"));
EXPECT_EQ(0x12f, rlz_lib::HexStringToInteger("12f 121"));
EXPECT_EQ(0x12f, rlz_lib::HexStringToInteger("12f 121"));
EXPECT_EQ(0, rlz_lib::HexStringToInteger("g12f"));
EXPECT_EQ(0, rlz_lib::HexStringToInteger(" 0x0 \n"));
- rlz_lib::expected_assertion_ = "";
+ rlz_lib::SetExpectedAssertion("");
}
TEST(StringUtilsUnittest, TestBytesToString) {