Kaydet (Commit) 456853e9 authored tarafından Caolán McNamara's avatar Caolán McNamara

document with unit test rather odd embedded null handling

üst a8742cec
......@@ -48,12 +48,14 @@ namespace
void test_fastostring();
void test_read_cstring();
void test_read_pstring();
void test_readline();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(test_stdstream);
CPPUNIT_TEST(test_fastostring);
CPPUNIT_TEST(test_read_cstring);
CPPUNIT_TEST(test_read_pstring);
CPPUNIT_TEST(test_readline);
CPPUNIT_TEST_SUITE_END();
};
......@@ -210,6 +212,71 @@ namespace
CPPUNIT_ASSERT(!aMemStream.eof());
}
void Test::test_readline()
{
char foo[] = "foo\nbar\n\n";
SvMemoryStream aMemStream(RTL_CONSTASCII_STRINGPARAM(foo), STREAM_READ);
rtl::OString aFoo;
sal_Bool bRet;
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(bRet);
CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("foo")));
CPPUNIT_ASSERT(aMemStream.good());
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(bRet);
CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("bar")));
CPPUNIT_ASSERT(aMemStream.good());
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(bRet);
CPPUNIT_ASSERT(aFoo.isEmpty());
CPPUNIT_ASSERT(aMemStream.good());
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(!bRet);
CPPUNIT_ASSERT(aFoo.isEmpty());
CPPUNIT_ASSERT(aMemStream.eof());
foo[3] = 0; //test reading embedded nulls
aMemStream.Seek(0);
bRet = aMemStream.ReadLine(aFoo);
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(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(iss.good());
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(bRet);
CPPUNIT_ASSERT(aFoo.isEmpty());
CPPUNIT_ASSERT(aMemStream.good());
std::getline(iss, sStr, '\n');
CPPUNIT_ASSERT(sStr.empty());
CPPUNIT_ASSERT(iss.good());
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(!bRet);
CPPUNIT_ASSERT(aFoo.isEmpty());
CPPUNIT_ASSERT(aMemStream.eof() && !aMemStream.bad());
std::getline(iss, sStr, '\n');
CPPUNIT_ASSERT(sStr.empty());
CPPUNIT_ASSERT(iss.eof() && !iss.bad());
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment