Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
41b5b28d
Commit
41b5b28d
authored
Jul 24, 2015
by
kosak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inject implementation of *FromGTestEnv using macros.
parent
c6b9fcd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
gtest-port.cc
src/gtest-port.cc
+9
-0
gtest_unittest.cc
test/gtest_unittest.cc
+4
-0
No files found.
src/gtest-port.cc
View file @
41b5b28d
...
@@ -1174,6 +1174,9 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
...
@@ -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".
// The value is considered true iff it's not "0".
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_value
)
{
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
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
return
string_value
==
NULL
?
return
string_value
==
NULL
?
...
@@ -1184,6 +1187,9 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
...
@@ -1184,6 +1187,9 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
// variable corresponding to the given flag; if it isn't set or
// variable corresponding to the given flag; if it isn't set or
// doesn't represent a valid 32-bit integer, returns default_value.
// doesn't represent a valid 32-bit integer, returns default_value.
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
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
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
const
char
*
const
string_value
=
posix
::
GetEnv
(
env_var
.
c_str
());
if
(
string_value
==
NULL
)
{
if
(
string_value
==
NULL
)
{
...
@@ -1206,6 +1212,9 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
...
@@ -1206,6 +1212,9 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
// Reads and returns the string environment variable corresponding to
// Reads and returns the string environment variable corresponding to
// the given flag; if it's not set, returns default_value.
// the given flag; if it's not set, returns default_value.
const
char
*
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
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
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
value
=
posix
::
GetEnv
(
env_var
.
c_str
());
const
char
*
const
value
=
posix
::
GetEnv
(
env_var
.
c_str
());
return
value
==
NULL
?
default_value
:
value
;
return
value
==
NULL
?
default_value
:
value
;
...
...
test/gtest_unittest.cc
View file @
41b5b28d
...
@@ -1671,6 +1671,8 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
...
@@ -1671,6 +1671,8 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
EXPECT_EQ
(
10
,
Int32FromGTestEnv
(
"temp"
,
10
));
EXPECT_EQ
(
10
,
Int32FromGTestEnv
(
"temp"
,
10
));
}
}
# if !defined(GTEST_GET_INT32_FROM_ENV_)
// Tests that Int32FromGTestEnv() returns the default value when the
// Tests that Int32FromGTestEnv() returns the default value when the
// environment variable overflows as an Int32.
// environment variable overflows as an Int32.
TEST
(
Int32FromGTestEnvTest
,
ReturnsDefaultWhenValueOverflows
)
{
TEST
(
Int32FromGTestEnvTest
,
ReturnsDefaultWhenValueOverflows
)
{
...
@@ -1695,6 +1697,8 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
...
@@ -1695,6 +1697,8 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
EXPECT_EQ
(
50
,
Int32FromGTestEnv
(
"temp"
,
50
));
EXPECT_EQ
(
50
,
Int32FromGTestEnv
(
"temp"
,
50
));
}
}
# endif // !defined(GTEST_GET_INT32_FROM_ENV_)
// Tests that Int32FromGTestEnv() parses and returns the value of the
// Tests that Int32FromGTestEnv() parses and returns the value of the
// environment variable when it represents a valid decimal integer in
// environment variable when it represents a valid decimal integer in
// the range of an Int32.
// the range of an Int32.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment