summaryrefslogtreecommitdiff
path: root/tools/qa
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-01-14 14:55:14 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-01-16 10:21:56 +0000
commit456853e96cc37bf817410366f0b94d6890e0ba00 (patch)
tree8cfd214827066ab2a4db118d1fe5533b3c363747 /tools/qa
parenta8742cecc157a28f293107013d6b35ce8a342382 (diff)
document with unit test rather odd embedded null handling
Diffstat (limited to 'tools/qa')
-rw-r--r--tools/qa/cppunit/test_stream.cxx67
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx
index 3e7580f40377..f4647ff77a44 100644
--- a/tools/qa/cppunit/test_stream.cxx
+++ b/tools/qa/cppunit/test_stream.cxx
@@ -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);
}