Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
7cc548dc
Commit
7cc548dc
authored
May 16, 2017
by
Billy Donahue
Committed by
GitHub
May 16, 2017
Browse files
Merge pull request #1089 from nico/stdstring
Use std::string and ::string explicitly in gtest and gmock code.
parents
078d5d93
09fd5b3e
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
69 deletions
+63
-69
googletest/src/gtest-death-test.cc
googletest/src/gtest-death-test.cc
+3
-4
googletest/src/gtest-internal-inl.h
googletest/src/gtest-internal-inl.h
+15
-15
googletest/src/gtest-port.cc
googletest/src/gtest-port.cc
+2
-2
googletest/src/gtest.cc
googletest/src/gtest.cc
+14
-16
googletest/test/gtest-death-test_test.cc
googletest/test/gtest-death-test_test.cc
+1
-1
googletest/test/gtest-printers_test.cc
googletest/test/gtest-printers_test.cc
+25
-27
googletest/test/gtest_unittest.cc
googletest/test/gtest_unittest.cc
+3
-4
No files found.
googletest/src/gtest-death-test.cc
View file @
7cc548dc
...
...
@@ -883,11 +883,10 @@ class ExecDeathTest : public ForkingDeathTest {
ForkingDeathTest
(
a_statement
,
a_regex
),
file_
(
file
),
line_
(
line
)
{
}
virtual
TestRole
AssumeRole
();
private:
static
::
std
::
vector
<
testing
::
internal
::
string
>
GetArgvsForDeathTestChildProcess
()
{
::
std
::
vector
<
testing
::
internal
::
string
>
args
=
GetInjectableArgvs
();
static
::
std
::
vector
<
std
::
string
>
GetArgvsForDeathTestChildProcess
()
{
::
std
::
vector
<
std
::
string
>
args
=
GetInjectableArgvs
();
# if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
::
std
::
vector
<
testing
::
internal
::
string
>
extra_args
=
::
std
::
vector
<
std
::
string
>
extra_args
=
GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_
();
args
.
insert
(
args
.
end
(),
extra_args
.
begin
(),
extra_args
.
end
());
# endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
...
...
googletest/src/gtest-internal-inl.h
View file @
7cc548dc
...
...
@@ -426,7 +426,7 @@ class OsStackTraceGetterInterface {
// in the trace.
// skip_count - the number of top frames to be skipped; doesn't count
// against max_depth.
virtual
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
=
0
;
virtual
std
::
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
=
0
;
// UponLeavingGTest() should be called immediately before Google Test calls
// user code. It saves some information about the current stack that
...
...
@@ -446,7 +446,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
public:
OsStackTraceGetter
()
{}
virtual
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
);
virtual
std
::
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
);
virtual
void
UponLeavingGTest
();
private:
...
...
@@ -1040,21 +1040,19 @@ class GTEST_API_ StreamingListener : public EmptyTestEventListener {
virtual
~
AbstractSocketWriter
()
{}
// Sends a string to the socket.
virtual
void
Send
(
const
string
&
message
)
=
0
;
virtual
void
Send
(
const
std
::
string
&
message
)
=
0
;
// Closes the socket.
virtual
void
CloseConnection
()
{}
// Sends a string and a newline to the socket.
void
SendLn
(
const
string
&
message
)
{
Send
(
message
+
"
\n
"
);
}
void
SendLn
(
const
std
::
string
&
message
)
{
Send
(
message
+
"
\n
"
);
}
};
// Concrete class for actually writing strings to a socket.
class
SocketWriter
:
public
AbstractSocketWriter
{
public:
SocketWriter
(
const
string
&
host
,
const
string
&
port
)
SocketWriter
(
const
std
::
string
&
host
,
const
std
::
string
&
port
)
:
sockfd_
(
-
1
),
host_name_
(
host
),
port_num_
(
port
)
{
MakeConnection
();
}
...
...
@@ -1065,7 +1063,7 @@ class GTEST_API_ StreamingListener : public EmptyTestEventListener {
}
// Sends a string to the socket.
virtual
void
Send
(
const
string
&
message
)
{
virtual
void
Send
(
const
std
::
string
&
message
)
{
GTEST_CHECK_
(
sockfd_
!=
-
1
)
<<
"Send() can be called only when there is a connection."
;
...
...
@@ -1091,17 +1089,19 @@ class GTEST_API_ StreamingListener : public EmptyTestEventListener {
}
int
sockfd_
;
// socket file descriptor
const
string
host_name_
;
const
string
port_num_
;
const
std
::
string
host_name_
;
const
std
::
string
port_num_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
SocketWriter
);
};
// class SocketWriter
// Escapes '=', '&', '%', and '\n' characters in str as "%xx".
static
string
UrlEncode
(
const
char
*
str
);
static
std
::
string
UrlEncode
(
const
char
*
str
);
StreamingListener
(
const
string
&
host
,
const
string
&
port
)
:
socket_writer_
(
new
SocketWriter
(
host
,
port
))
{
Start
();
}
StreamingListener
(
const
std
::
string
&
host
,
const
std
::
string
&
port
)
:
socket_writer_
(
new
SocketWriter
(
host
,
port
))
{
Start
();
}
explicit
StreamingListener
(
AbstractSocketWriter
*
socket_writer
)
:
socket_writer_
(
socket_writer
)
{
Start
();
}
...
...
@@ -1162,13 +1162,13 @@ class GTEST_API_ StreamingListener : public EmptyTestEventListener {
private:
// Sends the given message and a newline to the socket.
void
SendLn
(
const
string
&
message
)
{
socket_writer_
->
SendLn
(
message
);
}
void
SendLn
(
const
std
::
string
&
message
)
{
socket_writer_
->
SendLn
(
message
);
}
// Called at the start of streaming to notify the receiver what
// protocol we are using.
void
Start
()
{
SendLn
(
"gtest_streaming_protocol_version=1.0"
);
}
string
FormatBool
(
bool
value
)
{
return
value
?
"1"
:
"0"
;
}
std
::
string
FormatBool
(
bool
value
)
{
return
value
?
"1"
:
"0"
;
}
const
scoped_ptr
<
AbstractSocketWriter
>
socket_writer_
;
...
...
googletest/src/gtest-port.cc
View file @
7cc548dc
...
...
@@ -93,7 +93,7 @@ const int kStdErrFileno = STDERR_FILENO;
namespace
{
template
<
typename
T
>
T
ReadProcFileField
(
const
string
&
filename
,
int
field
)
{
T
ReadProcFileField
(
const
std
::
string
&
filename
,
int
field
)
{
std
::
string
dummy
;
std
::
ifstream
file
(
filename
.
c_str
());
while
(
field
--
>
0
)
{
...
...
@@ -107,7 +107,7 @@ T ReadProcFileField(const string& filename, int field) {
// Returns the number of active threads, or 0 when there is an error.
size_t
GetThreadCount
()
{
const
string
filename
=
const
std
::
string
filename
=
(
Message
()
<<
"/proc/"
<<
getpid
()
<<
"/stat"
).
GetString
();
return
ReadProcFileField
<
int
>
(
filename
,
19
);
}
...
...
googletest/src/gtest.cc
View file @
7cc548dc
...
...
@@ -633,7 +633,7 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
const
char
*
/* substr_expr */
,
const
TestPartResultArray
&
results
,
TestPartResult
::
Type
type
,
const
string
&
substr
)
{
const
std
::
string
&
substr
)
{
const
std
::
string
expected
(
type
==
TestPartResult
::
kFatalFailure
?
"1 fatal failure"
:
"1 non-fatal failure"
);
...
...
@@ -667,13 +667,10 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
// The constructor of SingleFailureChecker remembers where to look up
// test part results, what type of failure we expect, and what
// substring the failure message should contain.
SingleFailureChecker
::
SingleFailureChecker
(
const
TestPartResultArray
*
results
,
TestPartResult
::
Type
type
,
const
string
&
substr
)
:
results_
(
results
),
type_
(
type
),
substr_
(
substr
)
{}
SingleFailureChecker
::
SingleFailureChecker
(
const
TestPartResultArray
*
results
,
TestPartResult
::
Type
type
,
const
std
::
string
&
substr
)
:
results_
(
results
),
type_
(
type
),
substr_
(
substr
)
{}
// The destructor of SingleFailureChecker verifies that the given
// TestPartResultArray contains exactly one failure that has the given
...
...
@@ -3654,13 +3651,14 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
if
(
++
failures
==
1
)
{
*
stream
<<
">
\n
"
;
}
const
string
location
=
internal
::
FormatCompilerIndependentFileLocation
(
part
.
file_name
(),
part
.
line_number
());
const
string
summary
=
location
+
"
\n
"
+
part
.
summary
();
const
std
::
string
location
=
internal
::
FormatCompilerIndependentFileLocation
(
part
.
file_name
(),
part
.
line_number
());
const
std
::
string
summary
=
location
+
"
\n
"
+
part
.
summary
();
*
stream
<<
" <failure message=
\"
"
<<
EscapeXmlAttribute
(
summary
.
c_str
())
<<
"
\"
type=
\"\"
>"
;
const
string
detail
=
location
+
"
\n
"
+
part
.
message
();
const
std
::
string
detail
=
location
+
"
\n
"
+
part
.
message
();
OutputXmlCDataSection
(
stream
,
RemoveInvalidXmlCharacters
(
detail
).
c_str
());
*
stream
<<
"</failure>
\n
"
;
}
...
...
@@ -3759,8 +3757,8 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
// example, replaces "=" with "%3D". This algorithm is O(strlen(str))
// in both time and space -- important as the input str may contain an
// arbitrarily long test failure message and stack trace.
string
StreamingListener
::
UrlEncode
(
const
char
*
str
)
{
string
result
;
std
::
string
StreamingListener
::
UrlEncode
(
const
char
*
str
)
{
std
::
string
result
;
result
.
reserve
(
strlen
(
str
)
+
1
);
for
(
char
ch
=
*
str
;
ch
!=
'\0'
;
ch
=
*++
str
)
{
switch
(
ch
)
{
...
...
@@ -3848,8 +3846,8 @@ ScopedTrace::~ScopedTrace()
const
char
*
const
OsStackTraceGetterInterface
::
kElidedFramesMarker
=
"... "
GTEST_NAME_
" internal frames ..."
;
string
OsStackTraceGetter
::
CurrentStackTrace
(
int
/*max_depth*/
,
int
/*skip_count*/
)
{
std
::
string
OsStackTraceGetter
::
CurrentStackTrace
(
int
/*max_depth*/
,
int
/*skip_count*/
)
{
return
""
;
}
...
...
googletest/test/gtest-death-test_test.cc
View file @
7cc548dc
...
...
@@ -505,7 +505,7 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
# if GTEST_HAS_GLOBAL_STRING
const
string
regex_str
(
regex_c_str
);
const
::
string
regex_str
(
regex_c_str
);
EXPECT_DEATH
(
GlobalFunction
(),
regex_str
);
# endif // GTEST_HAS_GLOBAL_STRING
...
...
googletest/test/gtest-printers_test.cc
View file @
7cc548dc
...
...
@@ -236,7 +236,7 @@ using ::stdext::hash_multiset;
// Prints a value to a string using the universal value printer. This
// is a helper for testing UniversalPrinter<T>::Print() for various types.
template
<
typename
T
>
string
Print
(
const
T
&
value
)
{
std
::
string
Print
(
const
T
&
value
)
{
::
std
::
stringstream
ss
;
UniversalPrinter
<
T
>::
Print
(
value
,
&
ss
);
return
ss
.
str
();
...
...
@@ -246,7 +246,7 @@ string Print(const T& value) {
// value printer. This is a helper for testing
// UniversalPrinter<T&>::Print() for various types.
template
<
typename
T
>
string
PrintByRef
(
const
T
&
value
)
{
std
::
string
PrintByRef
(
const
T
&
value
)
{
::
std
::
stringstream
ss
;
UniversalPrinter
<
T
&>::
Print
(
value
,
&
ss
);
return
ss
.
str
();
...
...
@@ -383,7 +383,7 @@ TEST(PrintBuiltInTypeTest, FloatingPoints) {
// Since ::std::stringstream::operator<<(const void *) formats the pointer
// output differently with different compilers, we have to create the expected
// output first and use it as our expectation.
static
string
PrintPointer
(
const
void
*
p
)
{
static
std
::
string
PrintPointer
(
const
void
*
p
)
{
::
std
::
stringstream
expected_result_stream
;
expected_result_stream
<<
p
;
return
expected_result_stream
.
str
();
...
...
@@ -596,7 +596,7 @@ TEST(PrintPointerTest, MemberFunctionPointer) {
// The difference between this and Print() is that it ensures that the
// argument is a reference to an array.
template
<
typename
T
,
size_t
N
>
string
PrintArrayHelper
(
T
(
&
a
)[
N
])
{
std
::
string
PrintArrayHelper
(
T
(
&
a
)[
N
])
{
return
Print
(
a
);
}
...
...
@@ -649,7 +649,7 @@ TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
// Array of objects.
TEST
(
PrintArrayTest
,
ObjectArray
)
{
string
a
[
3
]
=
{
"Hi"
,
"Hello"
,
"Ni hao"
};
std
::
string
a
[
3
]
=
{
"Hi"
,
"Hello"
,
"Ni hao"
};
EXPECT_EQ
(
"{
\"
Hi
\"
,
\"
Hello
\"
,
\"
Ni hao
\"
}"
,
PrintArrayHelper
(
a
));
}
...
...
@@ -831,7 +831,7 @@ TEST(PrintStlContainerTest, HashMultiMap) {
map1
.
insert
(
make_pair
(
5
,
false
));
// Elements of hash_multimap can be printed in any order.
const
string
result
=
Print
(
map1
);
const
std
::
string
result
=
Print
(
map1
);
EXPECT_TRUE
(
result
==
"{ (5, true), (5, false) }"
||
result
==
"{ (5, false), (5, true) }"
)
<<
" where Print(map1) returns
\"
"
<<
result
<<
"
\"
."
;
...
...
@@ -842,9 +842,9 @@ TEST(PrintStlContainerTest, HashMultiMap) {
#if GTEST_HAS_HASH_SET_
TEST
(
PrintStlContainerTest
,
HashSet
)
{
hash_set
<
str
in
g
>
set1
;
set1
.
insert
(
"hello"
);
EXPECT_EQ
(
"{
\"
hello
\"
}"
,
Print
(
set1
));
hash_set
<
in
t
>
set1
;
set1
.
insert
(
1
);
EXPECT_EQ
(
"{
1
}"
,
Print
(
set1
));
}
TEST
(
PrintStlContainerTest
,
HashMultiSet
)
{
...
...
@@ -853,8 +853,8 @@ TEST(PrintStlContainerTest, HashMultiSet) {
hash_multiset
<
int
>
set1
(
a
,
a
+
kSize
);
// Elements of hash_multiset can be printed in any order.
const
string
result
=
Print
(
set1
);
const
string
expected_pattern
=
"{ d, d, d, d, d }"
;
// d means a digit.
const
std
::
string
result
=
Print
(
set1
);
const
std
::
string
expected_pattern
=
"{ d, d, d, d, d }"
;
// d means a digit.
// Verifies the result matches the expected pattern; also extracts
// the numbers in the result.
...
...
@@ -879,11 +879,8 @@ TEST(PrintStlContainerTest, HashMultiSet) {
#endif // GTEST_HAS_HASH_SET_
TEST
(
PrintStlContainerTest
,
List
)
{
const
string
a
[]
=
{
"hello"
,
"world"
};
const
list
<
string
>
strings
(
a
,
a
+
2
);
const
std
::
string
a
[]
=
{
"hello"
,
"world"
};
const
list
<
std
::
string
>
strings
(
a
,
a
+
2
);
EXPECT_EQ
(
"{
\"
hello
\"
,
\"
world
\"
}"
,
Print
(
strings
));
}
...
...
@@ -1039,9 +1036,10 @@ TEST(PrintTr1TupleTest, VariousSizes) {
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
// an explicit type cast of NULL to be used.
::
std
::
tr1
::
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
string
>
t10
(
false
,
'a'
,
3
,
4
,
5
,
1.5
F
,
-
2.5
,
str
,
ImplicitCast_
<
void
*>
(
NULL
),
"10"
);
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
std
::
string
>
t10
(
false
,
'a'
,
3
,
4
,
5
,
1.5
F
,
-
2.5
,
str
,
ImplicitCast_
<
void
*>
(
NULL
),
"10"
);
EXPECT_EQ
(
"(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
Print
(
t10
));
...
...
@@ -1098,9 +1096,10 @@ TEST(PrintStdTupleTest, VariousSizes) {
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
// an explicit type cast of NULL to be used.
::
std
::
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
string
>
t10
(
false
,
'a'
,
3
,
4
,
5
,
1.5
F
,
-
2.5
,
str
,
ImplicitCast_
<
void
*>
(
NULL
),
"10"
);
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
std
::
string
>
t10
(
false
,
'a'
,
3
,
4
,
5
,
1.5
F
,
-
2.5
,
str
,
ImplicitCast_
<
void
*>
(
NULL
),
"10"
);
EXPECT_EQ
(
"(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
Print
(
t10
));
...
...
@@ -1204,13 +1203,13 @@ TEST(PrintReferenceTest, PrintsAddressAndValue) {
// reference.
TEST
(
PrintReferenceTest
,
HandlesFunctionPointer
)
{
void
(
*
fp
)(
int
n
)
=
&
MyFunction
;
const
string
fp_pointer_string
=
const
std
::
string
fp_pointer_string
=
PrintPointer
(
reinterpret_cast
<
const
void
*>
(
&
fp
));
// We cannot directly cast &MyFunction to const void* because the
// standard disallows casting between pointers to functions and
// pointers to objects, and some compilers (e.g. GCC 3.4) enforce
// this limitation.
const
string
fp_string
=
PrintPointer
(
reinterpret_cast
<
const
void
*>
(
const
std
::
string
fp_string
=
PrintPointer
(
reinterpret_cast
<
const
void
*>
(
reinterpret_cast
<
internal
::
BiggestInt
>
(
fp
)));
EXPECT_EQ
(
"@"
+
fp_pointer_string
+
" "
+
fp_string
,
PrintByRef
(
fp
));
...
...
@@ -1542,12 +1541,12 @@ TEST(UniversalPrintTest, WorksForCString) {
const
char
*
s1
=
"abc"
;
::
std
::
stringstream
ss1
;
UniversalPrint
(
s1
,
&
ss1
);
EXPECT_EQ
(
PrintPointer
(
s1
)
+
" pointing to
\"
abc
\"
"
,
string
(
ss1
.
str
()));
EXPECT_EQ
(
PrintPointer
(
s1
)
+
" pointing to
\"
abc
\"
"
,
std
::
string
(
ss1
.
str
()));
char
*
s2
=
const_cast
<
char
*>
(
s1
);
::
std
::
stringstream
ss2
;
UniversalPrint
(
s2
,
&
ss2
);
EXPECT_EQ
(
PrintPointer
(
s2
)
+
" pointing to
\"
abc
\"
"
,
string
(
ss2
.
str
()));
EXPECT_EQ
(
PrintPointer
(
s2
)
+
" pointing to
\"
abc
\"
"
,
std
::
string
(
ss2
.
str
()));
const
char
*
s3
=
NULL
;
::
std
::
stringstream
ss3
;
...
...
@@ -1636,4 +1635,3 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
}
// namespace gtest_printers_test
}
// namespace testing
googletest/test/gtest_unittest.cc
View file @
7cc548dc
...
...
@@ -86,9 +86,9 @@ class StreamingListenerTest : public Test {
class FakeSocketWriter : public StreamingListener::AbstractSocketWriter {
public:
// Sends a string to the socket.
virtual
void
Send
(
const
string
&
message
)
{
output_
+=
message
;
}
virtual void Send(const
std::
string& message) { output_ += message; }
string
output_
;
std::
string output_;
};
StreamingListenerTest()
...
...
@@ -98,7 +98,7 @@ class StreamingListenerTest : public Test {
CodeLocation(__FILE__, __LINE__), 0, NULL) {}
protected:
string
*
output
()
{
return
&
(
fake_sock_writer_
->
output_
);
}
std::
string* output() { return &(fake_sock_writer_->output_); }
FakeSocketWriter* const fake_sock_writer_;
StreamingListener streamer_;
...
...
@@ -7703,4 +7703,3 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
EXPECT_FALSE(SkipPrefix("world!", &p));
EXPECT_EQ(str, p);
}
Prev
1
2
Next
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