summaryrefslogtreecommitdiffstats
path: root/test/gtest-message_test.cc
diff options
context:
space:
mode:
authorjgm <jgm@google.com>2012-11-15 15:47:38 (GMT)
committerjgm <jgm@google.com>2012-11-15 15:47:38 (GMT)
commit87fdda2cf24d953f3cbec1e0c266b2db9928f406 (patch)
tree640cd727bab672105c57f563091dc58b7a81a1be /test/gtest-message_test.cc
parent78bf6d5724e733cce313228856e18d5c372b4fb3 (diff)
downloadgoogletest-87fdda2cf24d953f3cbec1e0c266b2db9928f406.zip
googletest-87fdda2cf24d953f3cbec1e0c266b2db9928f406.tar.gz
googletest-87fdda2cf24d953f3cbec1e0c266b2db9928f406.tar.bz2
Unfortunately, the svn repo is a bit out of date. This commit contains 8
changes that haven't made it to svn. The descriptions of each change are listed below. - Fixes some python shebang lines. - Add ElementsAreArray overloads to gmock. ElementsAreArray now makes a copy of its input elements before the conversion to a Matcher. ElementsAreArray can now take a vector as input. ElementsAreArray can now take an iterator pair as input. - Templatize MatchAndExplain to allow independent string types for the matcher and matchee. I also templatized the ConstCharPointer version of MatchAndExplain to avoid calls with "char*" from using the new templated MatchAndExplain. - Fixes the bug where the constructor of the return type of ElementsAre() saves a reference instead of a copy of the arguments. - Extends ElementsAre() to accept arrays whose sizes aren't known. - Switches gTest's internal FilePath class from testing::internal::String to std::string. testing::internal::String was introduced when gTest couldn't depend on std::string. It's now deprecated. - Switches gTest & gMock from using testing::internal::String objects to std::string. Some static methods of String are still in use. We may be able to remove some but not all of them. In particular, String::Format() should eventually be removed as it truncates the result at 4096 characters, often causing problems.
Diffstat (limited to 'test/gtest-message_test.cc')
-rw-r--r--test/gtest-message_test.cc55
1 files changed, 24 insertions, 31 deletions
diff --git a/test/gtest-message_test.cc b/test/gtest-message_test.cc
index c09c6a8..175238e 100644
--- a/test/gtest-message_test.cc
+++ b/test/gtest-message_test.cc
@@ -39,79 +39,72 @@ namespace {
using ::testing::Message;
-// A helper function that turns a Message into a C string.
-const char* ToCString(const Message& msg) {
- static testing::internal::String result;
- result = msg.GetString();
- return result.c_str();
-}
-
// Tests the testing::Message class
// Tests the default constructor.
TEST(MessageTest, DefaultConstructor) {
const Message msg;
- EXPECT_STREQ("", ToCString(msg));
+ EXPECT_EQ("", msg.GetString());
}
// Tests the copy constructor.
TEST(MessageTest, CopyConstructor) {
const Message msg1("Hello");
const Message msg2(msg1);
- EXPECT_STREQ("Hello", ToCString(msg2));
+ EXPECT_EQ("Hello", msg2.GetString());
}
// Tests constructing a Message from a C-string.
TEST(MessageTest, ConstructsFromCString) {
Message msg("Hello");
- EXPECT_STREQ("Hello", ToCString(msg));
+ EXPECT_EQ("Hello", msg.GetString());
}
// Tests streaming a float.
TEST(MessageTest, StreamsFloat) {
- const char* const s = ToCString(Message() << 1.23456F << " " << 2.34567F);
+ const std::string s = (Message() << 1.23456F << " " << 2.34567F).GetString();
// Both numbers should be printed with enough precision.
- EXPECT_PRED_FORMAT2(testing::IsSubstring, "1.234560", s);
- EXPECT_PRED_FORMAT2(testing::IsSubstring, " 2.345669", s);
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, "1.234560", s.c_str());
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, " 2.345669", s.c_str());
}
// Tests streaming a double.
TEST(MessageTest, StreamsDouble) {
- const char* const s = ToCString(Message() << 1260570880.4555497 << " "
- << 1260572265.1954534);
+ const std::string s = (Message() << 1260570880.4555497 << " "
+ << 1260572265.1954534).GetString();
// Both numbers should be printed with enough precision.
- EXPECT_PRED_FORMAT2(testing::IsSubstring, "1260570880.45", s);
- EXPECT_PRED_FORMAT2(testing::IsSubstring, " 1260572265.19", s);
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, "1260570880.45", s.c_str());
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, " 1260572265.19", s.c_str());
}
// Tests streaming a non-char pointer.
TEST(MessageTest, StreamsPointer) {
int n = 0;
int* p = &n;
- EXPECT_STRNE("(null)", ToCString(Message() << p));
+ EXPECT_NE("(null)", (Message() << p).GetString());
}
// Tests streaming a NULL non-char pointer.
TEST(MessageTest, StreamsNullPointer) {
int* p = NULL;
- EXPECT_STREQ("(null)", ToCString(Message() << p));
+ EXPECT_EQ("(null)", (Message() << p).GetString());
}
// Tests streaming a C string.
TEST(MessageTest, StreamsCString) {
- EXPECT_STREQ("Foo", ToCString(Message() << "Foo"));
+ EXPECT_EQ("Foo", (Message() << "Foo").GetString());
}
// Tests streaming a NULL C string.
TEST(MessageTest, StreamsNullCString) {
char* p = NULL;
- EXPECT_STREQ("(null)", ToCString(Message() << p));
+ EXPECT_EQ("(null)", (Message() << p).GetString());
}
// Tests streaming std::string.
TEST(MessageTest, StreamsString) {
const ::std::string str("Hello");
- EXPECT_STREQ("Hello", ToCString(Message() << str));
+ EXPECT_EQ("Hello", (Message() << str).GetString());
}
// Tests that we can output strings containing embedded NULs.
@@ -120,34 +113,34 @@ TEST(MessageTest, StreamsStringWithEmbeddedNUL) {
"Here's a NUL\0 and some more string";
const ::std::string string_with_nul(char_array_with_nul,
sizeof(char_array_with_nul) - 1);
- EXPECT_STREQ("Here's a NUL\\0 and some more string",
- ToCString(Message() << string_with_nul));
+ EXPECT_EQ("Here's a NUL\\0 and some more string",
+ (Message() << string_with_nul).GetString());
}
// Tests streaming a NUL char.
TEST(MessageTest, StreamsNULChar) {
- EXPECT_STREQ("\\0", ToCString(Message() << '\0'));
+ EXPECT_EQ("\\0", (Message() << '\0').GetString());
}
// Tests streaming int.
TEST(MessageTest, StreamsInt) {
- EXPECT_STREQ("123", ToCString(Message() << 123));
+ EXPECT_EQ("123", (Message() << 123).GetString());
}
// Tests that basic IO manipulators (endl, ends, and flush) can be
// streamed to Message.
TEST(MessageTest, StreamsBasicIoManip) {
- EXPECT_STREQ("Line 1.\nA NUL char \\0 in line 2.",
- ToCString(Message() << "Line 1." << std::endl
+ EXPECT_EQ("Line 1.\nA NUL char \\0 in line 2.",
+ (Message() << "Line 1." << std::endl
<< "A NUL char " << std::ends << std::flush
- << " in line 2."));
+ << " in line 2.").GetString());
}
// Tests Message::GetString()
TEST(MessageTest, GetString) {
Message msg;
msg << 1 << " lamb";
- EXPECT_STREQ("1 lamb", msg.GetString().c_str());
+ EXPECT_EQ("1 lamb", msg.GetString());
}
// Tests streaming a Message object to an ostream.
@@ -155,7 +148,7 @@ TEST(MessageTest, StreamsToOStream) {
Message msg("Hello");
::std::stringstream ss;
ss << msg;
- EXPECT_STREQ("Hello", testing::internal::StringStreamToString(&ss).c_str());
+ EXPECT_EQ("Hello", testing::internal::StringStreamToString(&ss));
}
// Tests that a Message object doesn't take up too much stack space.