From 88e0df62470fa82e8d3010ef88241cd7565ebe9e Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 8 Sep 2010 05:57:37 +0000 Subject: Removes all uses of StrStream; fixes the VC projects and simplifies them by using gtest-all.cc. --- include/gtest/gtest-message.h | 25 ++++---- include/gtest/gtest.h | 8 +-- include/gtest/internal/gtest-port.h | 2 - include/gtest/internal/gtest-string.h | 4 +- msvc/gtest-md.vcproj | 113 +--------------------------------- msvc/gtest.vcproj | 113 +--------------------------------- msvc/gtest_main-md.vcproj | 36 ----------- msvc/gtest_main.vcproj | 36 ----------- src/gtest.cc | 24 ++++---- test/gtest-message_test.cc | 5 +- 10 files changed, 34 insertions(+), 332 deletions(-) diff --git a/include/gtest/gtest-message.h b/include/gtest/gtest-message.h index f135b69..e7a1188 100644 --- a/include/gtest/gtest-message.h +++ b/include/gtest/gtest-message.h @@ -58,7 +58,7 @@ namespace testing { // Typical usage: // // 1. You stream a bunch of values to a Message object. -// It will remember the text in a StrStream. +// It will remember the text in a stringstream. // 2. Then you stream the Message object to an ostream. // This causes the text in the Message to be streamed // to the ostream. @@ -74,7 +74,7 @@ namespace testing { // Message is not intended to be inherited from. In particular, its // destructor is not virtual. // -// Note that StrStream behaves differently in gcc and in MSVC. You +// Note that stringstream behaves differently in gcc and in MSVC. You // can stream a NULL char pointer to it in the former, but not in the // latter (it causes an access violation if you do). The Message // class hides this difference by treating a NULL char pointer as @@ -87,27 +87,26 @@ class GTEST_API_ Message { public: // Constructs an empty Message. - // We allocate the StrStream separately because it otherwise each use of + // We allocate the stringstream separately because otherwise each use of // ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's // stack frame leading to huge stack frames in some cases; gcc does not reuse // the stack space. - Message() : ss_(new internal::StrStream) { + Message() : ss_(new ::std::stringstream) { // By default, we want there to be enough precision when printing // a double to a Message. *ss_ << std::setprecision(std::numeric_limits::digits10 + 2); } // Copy constructor. - Message(const Message& msg) : ss_(new internal::StrStream) { // NOLINT + Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT *ss_ << msg.GetString(); } // Constructs a Message from a C-string. - explicit Message(const char* str) : ss_(new internal::StrStream) { + explicit Message(const char* str) : ss_(new ::std::stringstream) { *ss_ << str; } - ~Message() { delete ss_; } #if GTEST_OS_SYMBIAN // Streams a value (either a pointer or not) to this object. template @@ -119,7 +118,7 @@ class GTEST_API_ Message { // Streams a non-pointer value to this object. template inline Message& operator <<(const T& val) { - ::GTestStreamToHelper(ss_, val); + ::GTestStreamToHelper(ss_.get(), val); return *this; } @@ -141,7 +140,7 @@ class GTEST_API_ Message { if (pointer == NULL) { *ss_ << "(null)"; } else { - ::GTestStreamToHelper(ss_, pointer); + ::GTestStreamToHelper(ss_.get(), pointer); } return *this; } @@ -189,7 +188,7 @@ class GTEST_API_ Message { // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. internal::String GetString() const { - return internal::StrStreamToString(ss_); + return internal::StringStreamToString(ss_.get()); } private: @@ -203,17 +202,17 @@ class GTEST_API_ Message { if (pointer == NULL) { *ss_ << "(null)"; } else { - ::GTestStreamToHelper(ss_, pointer); + ::GTestStreamToHelper(ss_.get(), pointer); } } template inline void StreamHelper(internal::false_type /*dummy*/, const T& value) { - ::GTestStreamToHelper(ss_, value); + ::GTestStreamToHelper(ss_.get(), value); } #endif // GTEST_OS_SYMBIAN // We'll hold the text streamed to this object here. - internal::StrStream* const ss_; + const internal::scoped_ptr< ::std::stringstream> ss_; // We declare (but don't implement) this to prevent the compiler // from implementing the assignment operator. diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index 73f0578..41d2796 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -1517,18 +1517,18 @@ AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression, return AssertionSuccess(); } - StrStream expected_ss; + ::std::stringstream expected_ss; expected_ss << std::setprecision(std::numeric_limits::digits10 + 2) << expected; - StrStream actual_ss; + ::std::stringstream actual_ss; actual_ss << std::setprecision(std::numeric_limits::digits10 + 2) << actual; return EqFailure(expected_expression, actual_expression, - StrStreamToString(&expected_ss), - StrStreamToString(&actual_ss), + StringStreamToString(&expected_ss), + StringStreamToString(&actual_ss), false); } diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 05ee192..bf9cc8d 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -732,8 +732,6 @@ typedef ::wstring wstring; typedef ::std::wstring wstring; #endif // GTEST_HAS_GLOBAL_WSTRING -typedef ::std::stringstream StrStream; - // A helper for suppressing warnings on constant condition. It just // returns 'condition'. GTEST_API_ bool IsTrue(bool condition); diff --git a/include/gtest/internal/gtest-string.h b/include/gtest/internal/gtest-string.h index aff093d..05a1f89 100644 --- a/include/gtest/internal/gtest-string.h +++ b/include/gtest/internal/gtest-string.h @@ -329,9 +329,9 @@ inline ::std::ostream& operator<<(::std::ostream& os, const String& str) { return os; } -// Gets the content of the StrStream's buffer as a String. Each '\0' +// Gets the content of the stringstream's buffer as a String. Each '\0' // character in the buffer is replaced with "\\0". -GTEST_API_ String StrStreamToString(StrStream* stream); +GTEST_API_ String StringStreamToString(::std::stringstream* stream); // Converts a streamable value to a String. A NULL pointer is // converted to "(null)". When the input value is a ::string, diff --git a/msvc/gtest-md.vcproj b/msvc/gtest-md.vcproj index c78a4a4..1c35c3a 100644 --- a/msvc/gtest-md.vcproj +++ b/msvc/gtest-md.vcproj @@ -100,82 +100,7 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + RelativePath="..\src\gtest-all.cc"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/msvc/gtest.vcproj b/msvc/gtest.vcproj index bd2ed81..a8373ce 100644 --- a/msvc/gtest.vcproj +++ b/msvc/gtest.vcproj @@ -100,82 +100,7 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + RelativePath="..\src\gtest-all.cc"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/msvc/gtest_main-md.vcproj b/msvc/gtest_main-md.vcproj index 321667f..b5379fe 100644 --- a/msvc/gtest_main-md.vcproj +++ b/msvc/gtest_main-md.vcproj @@ -122,42 +122,6 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/msvc/gtest_main.vcproj b/msvc/gtest_main.vcproj index 13cc1d4..e8b763c 100644 --- a/msvc/gtest_main.vcproj +++ b/msvc/gtest_main.vcproj @@ -122,42 +122,6 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gtest.cc b/src/gtest.cc index 287ca88..4f0446d 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -1072,18 +1072,18 @@ AssertionResult FloatingPointLE(const char* expr1, // val2 is NaN, as the IEEE floating-point standard requires that // any predicate involving a NaN must return false. - StrStream val1_ss; + ::std::stringstream val1_ss; val1_ss << std::setprecision(std::numeric_limits::digits10 + 2) << val1; - StrStream val2_ss; + ::std::stringstream val2_ss; val2_ss << std::setprecision(std::numeric_limits::digits10 + 2) << val2; Message msg; msg << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n" - << " Actual: " << StrStreamToString(&val1_ss) << " vs " - << StrStreamToString(&val2_ss); + << " Actual: " << StringStreamToString(&val1_ss) << " vs " + << StringStreamToString(&val2_ss); return AssertionFailure(msg); } @@ -1508,7 +1508,7 @@ String WideStringToUtf8(const wchar_t* str, int num_chars) { if (num_chars == -1) num_chars = static_cast(wcslen(str)); - StrStream stream; + ::std::stringstream stream; for (int i = 0; i < num_chars; ++i) { UInt32 unicode_code_point; @@ -1525,7 +1525,7 @@ String WideStringToUtf8(const wchar_t* str, int num_chars) { char buffer[32]; // CodePointToUtf8 requires a buffer this big. stream << CodePointToUtf8(unicode_code_point, buffer); } - return StrStreamToString(&stream); + return StringStreamToString(&stream); } // Converts a wide C string to a String using the UTF-8 encoding. @@ -1733,16 +1733,16 @@ String String::Format(const char * format, ...) { } } -// Converts the buffer in a StrStream to a String, converting NUL +// Converts the buffer in a stringstream to a String, converting NUL // bytes to "\\0" along the way. -String StrStreamToString(StrStream* ss) { +String StringStreamToString(::std::stringstream* ss) { const ::std::string& str = ss->str(); const char* const start = str.c_str(); const char* const end = start + str.length(); - // We need to use a helper StrStream to do this transformation + // We need to use a helper stringstream to do this transformation // because String doesn't support push_back(). - StrStream helper; + ::std::stringstream helper; for (const char* ch = start; ch != end; ++ch) { if (*ch == '\0') { helper << "\\0"; // Replaces NUL with "\\0"; @@ -3262,9 +3262,9 @@ void XmlUnitTestResultPrinter::PrintXmlTestCase(FILE* out, "errors=\"0\" time=\"%s\">\n", FormatTimeInMillisAsSeconds(test_case.elapsed_time()).c_str()); for (int i = 0; i < test_case.total_test_count(); ++i) { - StrStream stream; + ::std::stringstream stream; OutputXmlTestInfo(&stream, test_case.name(), *test_case.GetTestInfo(i)); - fprintf(out, "%s", StrStreamToString(&stream).c_str()); + fprintf(out, "%s", StringStreamToString(&stream).c_str()); } fprintf(out, " \n"); } diff --git a/test/gtest-message_test.cc b/test/gtest-message_test.cc index e42b034..efb6ff0 100644 --- a/test/gtest-message_test.cc +++ b/test/gtest-message_test.cc @@ -38,7 +38,6 @@ namespace { using ::testing::Message; -using ::testing::internal::StrStream; // A helper function that turns a Message into a C string. const char* ToCString(const Message& msg) { @@ -154,9 +153,9 @@ TEST(MessageTest, GetString) { // Tests streaming a Message object to an ostream. TEST(MessageTest, StreamsToOStream) { Message msg("Hello"); - StrStream ss; + ::std::stringstream ss; ss << msg; - EXPECT_STREQ("Hello", testing::internal::StrStreamToString(&ss).c_str()); + EXPECT_STREQ("Hello", testing::internal::StringStreamToString(&ss).c_str()); } // Tests that a Message object doesn't take up too much stack space. -- cgit v0.12