| | |
| |
|
| | #include <gtest/gtest.h> |
| |
|
| | #ifdef _MSC_VER |
| | # pragma warning(disable : 4996) |
| | #endif |
| |
|
| | #include "Base/Stream.h" |
| |
|
| |
|
| | class TextOutputStreamTest: public ::testing::Test |
| | { |
| | protected: |
| | void SetUp() override |
| | {} |
| |
|
| | void TearDown() override |
| | {} |
| | }; |
| |
|
| | TEST_F(TextOutputStreamTest, singleLineCharStar) |
| | { |
| | |
| | const std::string testString("Single line const char *"); |
| | std::ostringstream ss; |
| | Base::TextOutputStream tos(ss); |
| |
|
| | |
| | tos << testString; |
| |
|
| | |
| | EXPECT_EQ(std::string("0:") + testString + "\n", ss.str()); |
| | } |
| |
|
| | TEST_F(TextOutputStreamTest, multiLineCharStar) |
| | { |
| | |
| | const std::string testString("Multi-line\nconst char *"); |
| | std::ostringstream ss; |
| | Base::TextOutputStream tos(ss); |
| |
|
| | |
| | tos << testString; |
| |
|
| | |
| | EXPECT_EQ(std::string("1:") + testString + "\n", ss.str()); |
| | } |
| |
|
| | TEST_F(TextOutputStreamTest, singleLineCharStarWithCarriageReturns) |
| | { |
| | |
| | const std::string testString("Single-line\rconst char *"); |
| | std::ostringstream ss; |
| | Base::TextOutputStream tos(ss); |
| |
|
| | |
| | tos << testString; |
| |
|
| | |
| | |
| | EXPECT_EQ(std::string("0:") + testString + "\n", ss.str()); |
| | } |
| |
|
| | TEST_F(TextOutputStreamTest, multiLineCharStarWithCarriageReturnsAndNewlines) |
| | { |
| | |
| | const std::string testString("Multi-line\r\nconst char *"); |
| | const std::string testStringWithoutCR("Multi-line\nconst char *"); |
| | std::ostringstream ss; |
| | Base::TextOutputStream tos(ss); |
| |
|
| | |
| | tos << testString; |
| |
|
| | |
| | |
| | EXPECT_EQ(std::string("1:") + testStringWithoutCR + "\n", ss.str()); |
| | } |
| |
|
| |
|
| | class TextStreamIntegrationTest: public ::testing::Test |
| | { |
| | protected: |
| | void SetUp() override |
| | {} |
| |
|
| | void TearDown() override |
| | {} |
| | }; |
| |
|
| | TEST_F(TextStreamIntegrationTest, OutputThenInputSimpleMultiLine) |
| | { |
| | |
| | std::string multiLineString("One\nTwo\nThree"); |
| |
|
| | |
| | std::ostringstream ssO; |
| | Base::TextOutputStream tos(ssO); |
| | tos << multiLineString; |
| | std::istringstream ssI(ssO.str()); |
| | Base::TextInputStream tis(ssI); |
| | std::string result; |
| | tis >> result; |
| |
|
| | |
| | EXPECT_EQ(multiLineString, result); |
| | } |
| |
|
| | TEST_F(TextStreamIntegrationTest, OutputThenInputMultiLineWithCarriageReturns) |
| | { |
| | |
| | std::string multiLineString("One\r\nTwo\r\nThree"); |
| | std::string multiLineStringResult("One\nTwo\nThree"); |
| |
|
| | |
| | std::ostringstream ssO; |
| | Base::TextOutputStream tos(ssO); |
| | tos << multiLineString; |
| | std::istringstream ssI(ssO.str()); |
| | Base::TextInputStream tis(ssI); |
| | std::string result; |
| | tis >> result; |
| |
|
| | |
| | EXPECT_EQ(multiLineStringResult, result); |
| | } |
| |
|