diff options
author | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-10-22 01:33:11 +0000 |
---|---|---|
committer | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-10-22 01:33:11 +0000 |
commit | 25958f3e4c4097caca8347b7937f5f6fb26d6c56 (patch) | |
tree | 7a9633942ef81e21ec74834e715777e2e062fb43 | |
parent | 50f4deb1cf3ef32282c13b7cb84a81b1bf61e0d8 (diff) | |
download | googletest-25958f3e4c4097caca8347b7937f5f6fb26d6c56.tar.gz googletest-25958f3e4c4097caca8347b7937f5f6fb26d6c56.tar.bz2 googletest-25958f3e4c4097caca8347b7937f5f6fb26d6c56.zip |
Fixes compiler warning when built with -std=c++0x.
-rw-r--r-- | include/gtest/gtest-printers.h | 2 | ||||
-rw-r--r-- | include/gtest/gtest.h | 40 | ||||
-rw-r--r-- | src/gtest.cc | 4 | ||||
-rw-r--r-- | test/gtest_unittest.cc | 9 |
4 files changed, 33 insertions, 22 deletions
diff --git a/include/gtest/gtest-printers.h b/include/gtest/gtest-printers.h index 7d90f00a..a86a4a34 100644 --- a/include/gtest/gtest-printers.h +++ b/include/gtest/gtest-printers.h @@ -121,7 +121,7 @@ enum TypeKind { kProtobuf, // a protobuf type kConvertibleToInteger, // a type implicitly convertible to BiggestInt // (e.g. a named or unnamed enum type) - kOtherType, // anything else + kOtherType // anything else }; // TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index c725e4cc..6ce58d72 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -281,20 +281,33 @@ class GTEST_API_ AssertionResult { // assertion's expectation). When nothing has been streamed into the // object, returns an empty string. const char* message() const { - return message_.get() != NULL && message_->c_str() != NULL ? - message_->c_str() : ""; + return message_.get() != NULL ? message_->c_str() : ""; } // TODO(vladl@google.com): Remove this after making sure no clients use it. // Deprecated; please use message() instead. const char* failure_message() const { return message(); } // Streams a custom failure message into this object. - template <typename T> AssertionResult& operator<<(const T& value); + template <typename T> AssertionResult& operator<<(const T& value) { + AppendMessage(Message() << value); + return *this; + } + + // Allows streaming basic output manipulators such as endl or flush into + // this object. + AssertionResult& operator<<( + ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { + AppendMessage(Message() << basic_manipulator); + return *this; + } private: - // No implementation - we want AssertionResult to be - // copy-constructible but not assignable. - void operator=(const AssertionResult& other); + // Appends the contents of message to message_. + void AppendMessage(const Message& a_message) { + if (message_.get() == NULL) + message_.reset(new ::std::string); + message_->append(a_message.GetString().c_str()); + } // Stores result of the assertion predicate. bool success_; @@ -302,19 +315,10 @@ class GTEST_API_ AssertionResult { // construct is not satisfied with the predicate's outcome. // Referenced via a pointer to avoid taking too much stack frame space // with test assertions. - internal::scoped_ptr<internal::String> message_; -}; // class AssertionResult + internal::scoped_ptr< ::std::string> message_; -// Streams a custom failure message into this object. -template <typename T> -AssertionResult& AssertionResult::operator<<(const T& value) { - Message msg; - if (message_.get() != NULL) - msg << *message_; - msg << value; - message_.reset(new internal::String(msg.GetString())); - return *this; -} + GTEST_DISALLOW_ASSIGN_(AssertionResult); +}; // Makes a successful assertion result. GTEST_API_ AssertionResult AssertionSuccess(); diff --git a/src/gtest.cc b/src/gtest.cc index 0d41e465..ea3a47c5 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -945,8 +945,8 @@ Message& Message::operator <<(const ::wstring& wstr) { AssertionResult::AssertionResult(const AssertionResult& other) : success_(other.success_), message_(other.message_.get() != NULL ? - new internal::String(*other.message_) : - static_cast<internal::String*>(NULL)) { + new ::std::string(*other.message_) : + static_cast< ::std::string*>(NULL)) { } // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index cb189a30..5a93ff26 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -34,6 +34,7 @@ #include "gtest/gtest.h" #include <vector> +#include <ostream> // Verifies that the command line flag variables can be accessed // in code once <gtest/gtest.h> has been #included. @@ -4902,7 +4903,7 @@ TEST(AssertionResultTest, ConstructionWorks) { EXPECT_STREQ("ghi", r5.message()); } -// Tests that the negation fips the predicate result but keeps the message. +// Tests that the negation flips the predicate result but keeps the message. TEST(AssertionResultTest, NegationWorks) { AssertionResult r1 = AssertionSuccess() << "abc"; EXPECT_FALSE(!r1); @@ -4919,6 +4920,12 @@ TEST(AssertionResultTest, StreamingWorks) { EXPECT_STREQ("abcd0true", r.message()); } +TEST(AssertionResultTest, CanStreamOstreamManipulators) { + AssertionResult r = AssertionSuccess(); + r << "Data" << std::endl << std::flush << std::ends << "Will be visible"; + EXPECT_STREQ("Data\n\\0Will be visible", r.message()); +} + // Tests streaming a user type whose definition and operator << are // both in the global namespace. class Base { |