summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosak@google.com <kosak@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2015-07-24 19:07:10 +0000
committerkosak@google.com <kosak@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2015-07-24 19:07:10 +0000
commitb7be629c0b272ff2b12d560ac3c92bcd9845106d (patch)
treebe2453958d84033ca83486358e0e0784c6f928a8
parentd778c261a2488fb17cf048892fd490361e6fddd2 (diff)
downloadgoogletest-b7be629c0b272ff2b12d560ac3c92bcd9845106d.tar.gz
Inject implementation of *FromGTestEnv using macros.
git-svn-id: http://googletest.googlecode.com/svn/trunk@734 861a406c-534a-0410-8894-cb66d6ee9925
-rw-r--r--src/gtest-port.cc9
-rw-r--r--test/gtest_unittest.cc4
2 files changed, 13 insertions, 0 deletions
diff --git a/src/gtest-port.cc b/src/gtest-port.cc
index cd3ac9a..3bc404b 100644
--- a/src/gtest-port.cc
+++ b/src/gtest-port.cc
@@ -1174,6 +1174,9 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
//
// The value is considered true iff it's not "0".
bool BoolFromGTestEnv(const char* flag, bool default_value) {
+#if defined(GTEST_GET_BOOL_FROM_ENV_)
+ return GTEST_GET_BOOL_FROM_ENV_(flag, default_value);
+#endif // defined(GTEST_GET_BOOL_FROM_ENV_)
const std::string env_var = FlagToEnvVar(flag);
const char* const string_value = posix::GetEnv(env_var.c_str());
return string_value == NULL ?
@@ -1184,6 +1187,9 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
// variable corresponding to the given flag; if it isn't set or
// doesn't represent a valid 32-bit integer, returns default_value.
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
+#if defined(GTEST_GET_INT32_FROM_ENV_)
+ return GTEST_GET_INT32_FROM_ENV_(flag, default_value);
+#endif // defined(GTEST_GET_INT32_FROM_ENV_)
const std::string env_var = FlagToEnvVar(flag);
const char* const string_value = posix::GetEnv(env_var.c_str());
if (string_value == NULL) {
@@ -1206,6 +1212,9 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
// Reads and returns the string environment variable corresponding to
// the given flag; if it's not set, returns default_value.
const char* StringFromGTestEnv(const char* flag, const char* default_value) {
+#if defined(GTEST_GET_STRING_FROM_ENV_)
+ return GTEST_GET_STRING_FROM_ENV_(flag, default_value);
+#endif // defined(GTEST_GET_STRING_FROM_ENV_)
const std::string env_var = FlagToEnvVar(flag);
const char* const value = posix::GetEnv(env_var.c_str());
return value == NULL ? default_value : value;
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index dd7f19f..60aed35 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -1671,6 +1671,8 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
EXPECT_EQ(10, Int32FromGTestEnv("temp", 10));
}
+# if !defined(GTEST_GET_INT32_FROM_ENV_)
+
// Tests that Int32FromGTestEnv() returns the default value when the
// environment variable overflows as an Int32.
TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
@@ -1695,6 +1697,8 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
EXPECT_EQ(50, Int32FromGTestEnv("temp", 50));
}
+# endif // !defined(GTEST_GET_INT32_FROM_ENV_)
+
// Tests that Int32FromGTestEnv() parses and returns the value of the
// environment variable when it represents a valid decimal integer in
// the range of an Int32.