googletest-message-test.cc (googletest-release-1.11.0) | : | googletest-message-test.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
// | // | |||
// Tests for the Message class. | // Tests for the Message class. | |||
#include "gtest/gtest-message.h" | #include "gtest/gtest-message.h" | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
namespace { | namespace { | |||
using ::testing::Message; | using ::testing::Message; | |||
// Tests the testing::Message class | // Tests the testing::Message class | |||
// Tests the default constructor. | // Tests the default constructor. | |||
TEST(MessageTest, DefaultConstructor) { | TEST(MessageTest, DefaultConstructor) { | |||
skipping to change at line 72 | skipping to change at line 71 | |||
// Tests streaming a float. | // Tests streaming a float. | |||
TEST(MessageTest, StreamsFloat) { | TEST(MessageTest, StreamsFloat) { | |||
const std::string s = (Message() << 1.23456F << " " << 2.34567F).GetString(); | const std::string s = (Message() << 1.23456F << " " << 2.34567F).GetString(); | |||
// Both numbers should be printed with enough precision. | // Both numbers should be printed with enough precision. | |||
EXPECT_PRED_FORMAT2(testing::IsSubstring, "1.234560", s.c_str()); | EXPECT_PRED_FORMAT2(testing::IsSubstring, "1.234560", s.c_str()); | |||
EXPECT_PRED_FORMAT2(testing::IsSubstring, " 2.345669", s.c_str()); | EXPECT_PRED_FORMAT2(testing::IsSubstring, " 2.345669", s.c_str()); | |||
} | } | |||
// Tests streaming a double. | // Tests streaming a double. | |||
TEST(MessageTest, StreamsDouble) { | TEST(MessageTest, StreamsDouble) { | |||
const std::string s = (Message() << 1260570880.4555497 << " " | const std::string s = | |||
<< 1260572265.1954534).GetString(); | (Message() << 1260570880.4555497 << " " << 1260572265.1954534) | |||
.GetString(); | ||||
// Both numbers should be printed with enough precision. | // Both numbers should be printed with enough precision. | |||
EXPECT_PRED_FORMAT2(testing::IsSubstring, "1260570880.45", s.c_str()); | EXPECT_PRED_FORMAT2(testing::IsSubstring, "1260570880.45", s.c_str()); | |||
EXPECT_PRED_FORMAT2(testing::IsSubstring, " 1260572265.19", s.c_str()); | EXPECT_PRED_FORMAT2(testing::IsSubstring, " 1260572265.19", s.c_str()); | |||
} | } | |||
// Tests streaming a non-char pointer. | // Tests streaming a non-char pointer. | |||
TEST(MessageTest, StreamsPointer) { | TEST(MessageTest, StreamsPointer) { | |||
int n = 0; | int n = 0; | |||
int* p = &n; | int* p = &n; | |||
EXPECT_NE("(null)", (Message() << p).GetString()); | EXPECT_NE("(null)", (Message() << p).GetString()); | |||
skipping to change at line 111 | skipping to change at line 111 | |||
} | } | |||
// Tests streaming std::string. | // Tests streaming std::string. | |||
TEST(MessageTest, StreamsString) { | TEST(MessageTest, StreamsString) { | |||
const ::std::string str("Hello"); | const ::std::string str("Hello"); | |||
EXPECT_EQ("Hello", (Message() << str).GetString()); | EXPECT_EQ("Hello", (Message() << str).GetString()); | |||
} | } | |||
// Tests that we can output strings containing embedded NULs. | // Tests that we can output strings containing embedded NULs. | |||
TEST(MessageTest, StreamsStringWithEmbeddedNUL) { | TEST(MessageTest, StreamsStringWithEmbeddedNUL) { | |||
const char char_array_with_nul[] = | const char char_array_with_nul[] = "Here's a NUL\0 and some more string"; | |||
"Here's a NUL\0 and some more string"; | ||||
const ::std::string string_with_nul(char_array_with_nul, | const ::std::string string_with_nul(char_array_with_nul, | |||
sizeof(char_array_with_nul) - 1); | sizeof(char_array_with_nul) - 1); | |||
EXPECT_EQ("Here's a NUL\\0 and some more string", | EXPECT_EQ("Here's a NUL\\0 and some more string", | |||
(Message() << string_with_nul).GetString()); | (Message() << string_with_nul).GetString()); | |||
} | } | |||
// Tests streaming a NUL char. | // Tests streaming a NUL char. | |||
TEST(MessageTest, StreamsNULChar) { | TEST(MessageTest, StreamsNULChar) { | |||
EXPECT_EQ("\\0", (Message() << '\0').GetString()); | EXPECT_EQ("\\0", (Message() << '\0').GetString()); | |||
} | } | |||
// Tests streaming int. | // Tests streaming int. | |||
TEST(MessageTest, StreamsInt) { | TEST(MessageTest, StreamsInt) { | |||
EXPECT_EQ("123", (Message() << 123).GetString()); | EXPECT_EQ("123", (Message() << 123).GetString()); | |||
} | } | |||
// Tests that basic IO manipulators (endl, ends, and flush) can be | // Tests that basic IO manipulators (endl, ends, and flush) can be | |||
// streamed to Message. | // streamed to Message. | |||
TEST(MessageTest, StreamsBasicIoManip) { | TEST(MessageTest, StreamsBasicIoManip) { | |||
EXPECT_EQ("Line 1.\nA NUL char \\0 in line 2.", | EXPECT_EQ( | |||
(Message() << "Line 1." << std::endl | "Line 1.\nA NUL char \\0 in line 2.", | |||
<< "A NUL char " << std::ends << std::flush | (Message() << "Line 1." << std::endl | |||
<< " in line 2.").GetString()); | << "A NUL char " << std::ends << std::flush << " in line 2.") | |||
.GetString()); | ||||
} | } | |||
// Tests Message::GetString() | // Tests Message::GetString() | |||
TEST(MessageTest, GetString) { | TEST(MessageTest, GetString) { | |||
Message msg; | Message msg; | |||
msg << 1 << " lamb"; | msg << 1 << " lamb"; | |||
EXPECT_EQ("1 lamb", msg.GetString()); | EXPECT_EQ("1 lamb", msg.GetString()); | |||
} | } | |||
// Tests streaming a Message object to an ostream. | // Tests streaming a Message object to an ostream. | |||
End of changes. 4 change blocks. | ||||
9 lines changed or deleted | 9 lines changed or added |