Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "gtest/gtest-message.h"
00035
00036 #include "gtest/gtest.h"
00037
00038 namespace {
00039
00040 using ::testing::Message;
00041
00042
00043
00044
00045 TEST(MessageTest, DefaultConstructor) {
00046 const Message msg;
00047 EXPECT_EQ("", msg.GetString());
00048 }
00049
00050
00051 TEST(MessageTest, CopyConstructor) {
00052 const Message msg1("Hello");
00053 const Message msg2(msg1);
00054 EXPECT_EQ("Hello", msg2.GetString());
00055 }
00056
00057
00058 TEST(MessageTest, ConstructsFromCString) {
00059 Message msg("Hello");
00060 EXPECT_EQ("Hello", msg.GetString());
00061 }
00062
00063
00064 TEST(MessageTest, StreamsFloat) {
00065 const std::string s = (Message() << 1.23456F << " " << 2.34567F).GetString();
00066
00067 EXPECT_PRED_FORMAT2(testing::IsSubstring, "1.234560", s.c_str());
00068 EXPECT_PRED_FORMAT2(testing::IsSubstring, " 2.345669", s.c_str());
00069 }
00070
00071
00072 TEST(MessageTest, StreamsDouble) {
00073 const std::string s = (Message() << 1260570880.4555497 << " "
00074 << 1260572265.1954534).GetString();
00075
00076 EXPECT_PRED_FORMAT2(testing::IsSubstring, "1260570880.45", s.c_str());
00077 EXPECT_PRED_FORMAT2(testing::IsSubstring, " 1260572265.19", s.c_str());
00078 }
00079
00080
00081 TEST(MessageTest, StreamsPointer) {
00082 int n = 0;
00083 int* p = &n;
00084 EXPECT_NE("(null)", (Message() << p).GetString());
00085 }
00086
00087
00088 TEST(MessageTest, StreamsNullPointer) {
00089 int* p = NULL;
00090 EXPECT_EQ("(null)", (Message() << p).GetString());
00091 }
00092
00093
00094 TEST(MessageTest, StreamsCString) {
00095 EXPECT_EQ("Foo", (Message() << "Foo").GetString());
00096 }
00097
00098
00099 TEST(MessageTest, StreamsNullCString) {
00100 char* p = NULL;
00101 EXPECT_EQ("(null)", (Message() << p).GetString());
00102 }
00103
00104
00105 TEST(MessageTest, StreamsString) {
00106 const ::std::string str("Hello");
00107 EXPECT_EQ("Hello", (Message() << str).GetString());
00108 }
00109
00110
00111 TEST(MessageTest, StreamsStringWithEmbeddedNUL) {
00112 const char char_array_with_nul[] =
00113 "Here's a NUL\0 and some more string";
00114 const ::std::string string_with_nul(char_array_with_nul,
00115 sizeof(char_array_with_nul) - 1);
00116 EXPECT_EQ("Here's a NUL\\0 and some more string",
00117 (Message() << string_with_nul).GetString());
00118 }
00119
00120
00121 TEST(MessageTest, StreamsNULChar) {
00122 EXPECT_EQ("\\0", (Message() << '\0').GetString());
00123 }
00124
00125
00126 TEST(MessageTest, StreamsInt) {
00127 EXPECT_EQ("123", (Message() << 123).GetString());
00128 }
00129
00130
00131
00132 TEST(MessageTest, StreamsBasicIoManip) {
00133 EXPECT_EQ("Line 1.\nA NUL char \\0 in line 2.",
00134 (Message() << "Line 1." << std::endl
00135 << "A NUL char " << std::ends << std::flush
00136 << " in line 2.").GetString());
00137 }
00138
00139
00140 TEST(MessageTest, GetString) {
00141 Message msg;
00142 msg << 1 << " lamb";
00143 EXPECT_EQ("1 lamb", msg.GetString());
00144 }
00145
00146
00147 TEST(MessageTest, StreamsToOStream) {
00148 Message msg("Hello");
00149 ::std::stringstream ss;
00150 ss << msg;
00151 EXPECT_EQ("Hello", testing::internal::StringStreamToString(&ss));
00152 }
00153
00154
00155 TEST(MessageTest, DoesNotTakeUpMuchStackSpace) {
00156 EXPECT_LE(sizeof(Message), 16U);
00157 }
00158
00159 }