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
dd280cfa
Commit
dd280cfa
authored
Feb 17, 2010
by
zhanyong.wan
Browse files
Fixes a C++ standard conformance bug in gtest-param-test_test.cc.
parent
6f50ccf3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
37 deletions
+69
-37
test/gtest-param-test_test.cc
test/gtest-param-test_test.cc
+69
-37
No files found.
test/gtest-param-test_test.cc
View file @
dd280cfa
...
...
@@ -40,6 +40,8 @@
#include <algorithm>
#include <iostream>
#include <list>
#include <sstream>
#include <string>
#include <vector>
// To include gtest-internal-inl.h.
...
...
@@ -70,6 +72,57 @@ using ::std::tr1::tuple;
using
::
testing
::
internal
::
ParamGenerator
;
using
::
testing
::
internal
::
UnitTestOptions
;
// Prints a value to a string.
//
// TODO(wan@google.com): remove PrintValue() when we move matchers and
// EXPECT_THAT() from Google Mock to Google Test. At that time, we
// can write EXPECT_THAT(x, Eq(y)) to compare two tuples x and y, as
// EXPECT_THAT() and the matchers know how to print tuples.
template
<
typename
T
>
::
std
::
string
PrintValue
(
const
T
&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
value
;
return
stream
.
str
();
}
#if GTEST_HAS_COMBINE
// These overloads allow printing tuples in our tests. We cannot
// define an operator<< for tuples, as that definition needs to be in
// the std namespace in order to be picked up by Google Test via
// Argument-Dependent Lookup, yet defining anything in the std
// namespace in non-STL code is undefined behavior.
template
<
typename
T1
,
typename
T2
>
::
std
::
string
PrintValue
(
const
tuple
<
T1
,
T2
>&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
")"
;
return
stream
.
str
();
}
template
<
typename
T1
,
typename
T2
,
typename
T3
>
::
std
::
string
PrintValue
(
const
tuple
<
T1
,
T2
,
T3
>&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
", "
<<
get
<
2
>
(
value
)
<<
")"
;
return
stream
.
str
();
}
template
<
typename
T1
,
typename
T2
,
typename
T3
,
typename
T4
,
typename
T5
,
typename
T6
,
typename
T7
,
typename
T8
,
typename
T9
,
typename
T10
>
::
std
::
string
PrintValue
(
const
tuple
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
,
T7
,
T8
,
T9
,
T10
>&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
", "
<<
get
<
2
>
(
value
)
<<
", "
<<
get
<
3
>
(
value
)
<<
", "
<<
get
<
4
>
(
value
)
<<
", "
<<
get
<
5
>
(
value
)
<<
", "
<<
get
<
6
>
(
value
)
<<
", "
<<
get
<
7
>
(
value
)
<<
", "
<<
get
<
8
>
(
value
)
<<
", "
<<
get
<
9
>
(
value
)
<<
")"
;
return
stream
.
str
();
}
#endif // GTEST_HAS_COMBINE
// Verifies that a sequence generated by the generator and accessed
// via the iterator object matches the expected one using Google Test
// assertions.
...
...
@@ -80,15 +133,19 @@ void VerifyGenerator(const ParamGenerator<T>& generator,
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
ASSERT_FALSE
(
it
==
generator
.
end
())
<<
"At element "
<<
i
<<
" when accessing via an iterator "
<<
"created with the copy constructor."
<<
std
::
endl
;
EXPECT_EQ
(
expected_values
[
i
],
*
it
)
<<
"At element "
<<
i
<<
" when accessing via an iterator "
<<
"created with the copy constructor."
<<
std
::
endl
;
<<
"created with the copy constructor.
\n
"
;
// We cannot use EXPECT_EQ() here as the values may be tuples,
// which don't support <<.
EXPECT_TRUE
(
expected_values
[
i
]
==
*
it
)
<<
"where i is "
<<
i
<<
", expected_values[i] is "
<<
PrintValue
(
expected_values
[
i
])
<<
", *it is "
<<
PrintValue
(
*
it
)
<<
", and 'it' is an iterator created with the copy constructor.
\n
"
;
it
++
;
}
EXPECT_TRUE
(
it
==
generator
.
end
())
<<
"At the presumed end of sequence when accessing via an iterator "
<<
"created with the copy constructor.
"
<<
std
::
endl
;
<<
"created with the copy constructor.
\n
"
;
// Test the iterator assignment. The following lines verify that
// the sequence accessed via an iterator initialized via the
...
...
@@ -98,15 +155,17 @@ void VerifyGenerator(const ParamGenerator<T>& generator,
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
ASSERT_FALSE
(
it
==
generator
.
end
())
<<
"At element "
<<
i
<<
" when accessing via an iterator "
<<
"created with the assignment operator."
<<
std
::
endl
;
EXPECT_EQ
(
expected_values
[
i
],
*
it
)
<<
"At element "
<<
i
<<
" when accessing via an iterator "
<<
"created with the assignment operator."
<<
std
::
endl
;
<<
"created with the assignment operator.
\n
"
;
EXPECT_TRUE
(
expected_values
[
i
]
==
*
it
)
<<
"where i is "
<<
i
<<
", expected_values[i] is "
<<
PrintValue
(
expected_values
[
i
])
<<
", *it is "
<<
PrintValue
(
*
it
)
<<
", and 'it' is an iterator created with the copy constructor.
\n
"
;
it
++
;
}
EXPECT_TRUE
(
it
==
generator
.
end
())
<<
"At the presumed end of sequence when accessing via an iterator "
<<
"created with the assignment operator.
"
<<
std
::
endl
;
<<
"created with the assignment operator.
\n
"
;
}
template
<
typename
T
>
...
...
@@ -400,33 +459,6 @@ TEST(BoolTest, BoolWorks) {
#if GTEST_HAS_COMBINE
template
<
typename
T1
,
typename
T2
>
::
std
::
ostream
&
operator
<<
(
::
std
::
ostream
&
stream
,
const
tuple
<
T1
,
T2
>&
value
)
{
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
")"
;
return
stream
;
}
template
<
typename
T1
,
typename
T2
,
typename
T3
>
::
std
::
ostream
&
operator
<<
(
::
std
::
ostream
&
stream
,
const
tuple
<
T1
,
T2
,
T3
>&
value
)
{
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
", "
<<
get
<
2
>
(
value
)
<<
")"
;
return
stream
;
}
template
<
typename
T1
,
typename
T2
,
typename
T3
,
typename
T4
,
typename
T5
,
typename
T6
,
typename
T7
,
typename
T8
,
typename
T9
,
typename
T10
>
::
std
::
ostream
&
operator
<<
(
::
std
::
ostream
&
stream
,
const
tuple
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
,
T7
,
T8
,
T9
,
T10
>&
value
)
{
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
", "
<<
get
<
2
>
(
value
)
<<
", "
<<
get
<
3
>
(
value
)
<<
", "
<<
get
<
4
>
(
value
)
<<
", "
<<
get
<
5
>
(
value
)
<<
", "
<<
get
<
6
>
(
value
)
<<
", "
<<
get
<
7
>
(
value
)
<<
", "
<<
get
<
8
>
(
value
)
<<
", "
<<
get
<
9
>
(
value
)
<<
")"
;
return
stream
;
}
// Tests that Combine() with two parameters generates the expected sequence.
TEST
(
CombineTest
,
CombineWithTwoParameters
)
{
const
char
*
foo
=
"foo"
;
...
...
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