diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-01-15 20:41:19 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-01-16 10:21:56 +0000 |
commit | 9790e4457f14950b83a0746e00f986d76cf1ca36 (patch) | |
tree | af0ea04adc8a7162fdc7ec2e726bf1114cd29c0b /tools | |
parent | 67270ddc7c0b203c774a3d78e48d07535c54c0da (diff) |
document with unit test rather suspicious eof handling
ReadLine differs from std::getline with respect to final lines
that end at EOF with no EOL.
i.e. see Export::ConvertLineEnds in l10ntools/source/export2.cxx
which doesn't make a massive amount of sense the way things currently are.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qa/cppunit/test_stream.cxx | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx index f4647ff77a44..107d1c1047c4 100644 --- a/tools/qa/cppunit/test_stream.cxx +++ b/tools/qa/cppunit/test_stream.cxx @@ -130,6 +130,25 @@ namespace CPPUNIT_ASSERT(tools_a == 'f'); //failbit is rather subtle wrt e.g seeks + + char buffer[1024]; + + iss.clear(); + iss.seekg(0); + CPPUNIT_ASSERT(iss.good()); + iss.read(buffer, sizeof(buffer)); + CPPUNIT_ASSERT(iss.gcount() == 3); + CPPUNIT_ASSERT(!iss.good()); + CPPUNIT_ASSERT(!iss.bad()); + CPPUNIT_ASSERT(iss.eof()); + + aMemStream.Seek(0); + CPPUNIT_ASSERT(aMemStream.good()); + sal_Size nRet = aMemStream.Read(buffer, sizeof(buffer)); + CPPUNIT_ASSERT(nRet == 3); + CPPUNIT_ASSERT(!aMemStream.good()); + CPPUNIT_ASSERT(!aMemStream.bad()); + CPPUNIT_ASSERT(aMemStream.eof()); } void Test::test_fastostring() @@ -247,14 +266,14 @@ namespace CPPUNIT_ASSERT(bRet); //This is the weird current behavior where an embedded null is read but //discarded - CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("foobar"))); + CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("foobar"))); //<--diff A CPPUNIT_ASSERT(aMemStream.good()); std::string sStr(RTL_CONSTASCII_STRINGPARAM(foo)); std::istringstream iss(sStr, std::istringstream::in); std::getline(iss, sStr, '\n'); //embedded null read as expected - CPPUNIT_ASSERT(sStr.size() == 7 && sStr[3] == 0); + CPPUNIT_ASSERT(sStr.size() == 7 && sStr[3] == 0); //<--diff A CPPUNIT_ASSERT(iss.good()); bRet = aMemStream.ReadLine(aFoo); @@ -275,7 +294,18 @@ namespace CPPUNIT_ASSERT(sStr.empty()); CPPUNIT_ASSERT(iss.eof() && !iss.bad()); - } + char bar[] = "foo"; + SvMemoryStream aMemStreamB(RTL_CONSTASCII_STRINGPARAM(bar), STREAM_READ); + bRet = aMemStreamB.ReadLine(aFoo); + CPPUNIT_ASSERT(bRet); + CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT(!aMemStreamB.eof()); //<-- diff B + + std::istringstream issB(bar, std::istringstream::in); + std::getline(issB, sStr, '\n'); + CPPUNIT_ASSERT(sStr == "foo"); + CPPUNIT_ASSERT(issB.eof()); //<-- diff B + } CPPUNIT_TEST_SUITE_REGISTRATION(Test); } |