| 1 | // |
|---|---|
| 2 | // TeeStreamTest.cpp |
| 3 | // |
| 4 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
| 5 | // and Contributors. |
| 6 | // |
| 7 | // SPDX-License-Identifier: BSL-1.0 |
| 8 | // |
| 9 | |
| 10 | |
| 11 | #include "TeeStreamTest.h" |
| 12 | #include "Poco/CppUnit/TestCaller.h" |
| 13 | #include "Poco/CppUnit/TestSuite.h" |
| 14 | #include "Poco/TeeStream.h" |
| 15 | #include <sstream> |
| 16 | |
| 17 | |
| 18 | using Poco::TeeInputStream; |
| 19 | using Poco::TeeOutputStream; |
| 20 | |
| 21 | |
| 22 | TeeStreamTest::TeeStreamTest(const std::string& rName): CppUnit::TestCase(rName) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | |
| 27 | TeeStreamTest::~TeeStreamTest() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | |
| 32 | void TeeStreamTest::testTeeInputStream() |
| 33 | { |
| 34 | std::istringstream istr("foo"); |
| 35 | std::ostringstream ostr; |
| 36 | TeeInputStream tis(istr); |
| 37 | tis.addStream(ostr); |
| 38 | std::string s; |
| 39 | tis >> s; |
| 40 | assertTrue (ostr.str() == "foo"); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | void TeeStreamTest::testTeeOutputStream() |
| 45 | { |
| 46 | std::ostringstream ostr1; |
| 47 | std::ostringstream ostr2; |
| 48 | TeeOutputStream tos(ostr1); |
| 49 | tos.addStream(ostr2); |
| 50 | tos << "bar"<< std::flush; |
| 51 | assertTrue (ostr1.str() == "bar"); |
| 52 | assertTrue (ostr2.str() == "bar"); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | void TeeStreamTest::setUp() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void TeeStreamTest::tearDown() |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | |
| 66 | CppUnit::Test* TeeStreamTest::suite() |
| 67 | { |
| 68 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TeeStreamTest"); |
| 69 | |
| 70 | CppUnit_addTest(pSuite, TeeStreamTest, testTeeInputStream); |
| 71 | CppUnit_addTest(pSuite, TeeStreamTest, testTeeOutputStream); |
| 72 | |
| 73 | return pSuite; |
| 74 | } |
| 75 |