aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/gtest-param-test_test.cc106
1 files changed, 69 insertions, 37 deletions
diff --git a/test/gtest-param-test_test.cc b/test/gtest-param-test_test.cc
index e718ffb4..0288b6a7 100644
--- a/test/gtest-param-test_test.cc
+++ b/test/gtest-param-test_test.cc
@@ -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";