aboutsummaryrefslogtreecommitdiffstats
path: root/test/gtest_unittest.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-07-21 22:15:17 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-07-21 22:15:17 +0000
commite2a7f03b80fc0e9e6a6f36acb43776509486a6d4 (patch)
tree650c7033b14cd54fa03d46100e314ef141a3f492 /test/gtest_unittest.cc
parent447ed6474deca82844b211e57503579ab1c560f0 (diff)
downloadgoogletest-e2a7f03b80fc0e9e6a6f36acb43776509486a6d4.tar.gz
googletest-e2a7f03b80fc0e9e6a6f36acb43776509486a6d4.tar.bz2
googletest-e2a7f03b80fc0e9e6a6f36acb43776509486a6d4.zip
Allows EXPECT_EQ to accept arguments that don't have operator << (by Zhanyong Wan).
Allows a user to customize how the universal printer prints a pointer of a specific type by overloading << (by Zhanyong Wan). Works around a bug in Cymbian's C++ compiler (by Vlad Losev).
Diffstat (limited to 'test/gtest_unittest.cc')
-rw-r--r--test/gtest_unittest.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index a65ce922..e11b6a66 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -4652,6 +4652,65 @@ TEST(EqAssertionTest, OtherPointer) {
"0x1234");
}
+// A class that supports binary comparison operators but not streaming.
+class UnprintableChar {
+ public:
+ explicit UnprintableChar(char ch) : char_(ch) {}
+
+ bool operator==(const UnprintableChar& rhs) const {
+ return char_ == rhs.char_;
+ }
+ bool operator!=(const UnprintableChar& rhs) const {
+ return char_ != rhs.char_;
+ }
+ bool operator<(const UnprintableChar& rhs) const {
+ return char_ < rhs.char_;
+ }
+ bool operator<=(const UnprintableChar& rhs) const {
+ return char_ <= rhs.char_;
+ }
+ bool operator>(const UnprintableChar& rhs) const {
+ return char_ > rhs.char_;
+ }
+ bool operator>=(const UnprintableChar& rhs) const {
+ return char_ >= rhs.char_;
+ }
+
+ private:
+ char char_;
+};
+
+// Tests that ASSERT_EQ() and friends don't require the arguments to
+// be printable.
+TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
+ const UnprintableChar x('x'), y('y');
+ ASSERT_EQ(x, x);
+ EXPECT_NE(x, y);
+ ASSERT_LT(x, y);
+ EXPECT_LE(x, y);
+ ASSERT_GT(y, x);
+ EXPECT_GE(x, x);
+
+ EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), "1-byte object <78>");
+ EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), "1-byte object <79>");
+ EXPECT_NONFATAL_FAILURE(EXPECT_LT(y, y), "1-byte object <79>");
+ EXPECT_NONFATAL_FAILURE(EXPECT_GT(x, y), "1-byte object <78>");
+ EXPECT_NONFATAL_FAILURE(EXPECT_GT(x, y), "1-byte object <79>");
+
+ // Code tested by EXPECT_FATAL_FAILURE cannot reference local
+ // variables, so we have to write UnprintableChar('x') instead of x.
+ EXPECT_FATAL_FAILURE(ASSERT_NE(UnprintableChar('x'), UnprintableChar('x')),
+ "1-byte object <78>");
+ EXPECT_FATAL_FAILURE(ASSERT_LE(UnprintableChar('y'), UnprintableChar('x')),
+ "1-byte object <78>");
+ EXPECT_FATAL_FAILURE(ASSERT_LE(UnprintableChar('y'), UnprintableChar('x')),
+ "1-byte object <79>");
+ EXPECT_FATAL_FAILURE(ASSERT_GE(UnprintableChar('x'), UnprintableChar('y')),
+ "1-byte object <78>");
+ EXPECT_FATAL_FAILURE(ASSERT_GE(UnprintableChar('x'), UnprintableChar('y')),
+ "1-byte object <79>");
+}
+
// Tests the FRIEND_TEST macro.
// This class has a private member we want to test. We will test it