diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-12-14 22:52:07 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-12-15 12:22:49 +0000 |
commit | 66c3655a07e109d88183002192410bcc9866c0f2 (patch) | |
tree | 019188e9165edc40641dd5a6836e94a64529c5d7 /tools/qa/cppunit | |
parent | ace8398c5782caf6c5d9066b8e67afa652448954 (diff) |
convert ReadCString from ByteString to OString
Nobody ever checked the return value anyway, so just return the string
and use the stream state bits if necessary to find failures.
Doesn't need to be a member, make a standalone function
Rename it to read_zeroTerminated_uInt8s_AsO[U]String, stupid perhaps,
but *shrug*, unambiguous.
Drop misleading overloaded String variants use:
read_zeroTerminated_uInt8s_AsOString or
read_zeroTerminated_uInt8s_AsOUString
added a unit test, valgrinded it, found and fixed invalid read
in original implementation.
Diffstat (limited to 'tools/qa/cppunit')
-rw-r--r-- | tools/qa/cppunit/test_stream.cxx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx index dc80c7d5c02a..77c2b9ed75ae 100644 --- a/tools/qa/cppunit/test_stream.cxx +++ b/tools/qa/cppunit/test_stream.cxx @@ -46,10 +46,12 @@ namespace public: void test_stdstream(); void test_fastostring(); + void test_read_cstring(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(test_stdstream); CPPUNIT_TEST(test_fastostring); + CPPUNIT_TEST(test_read_cstring); CPPUNIT_TEST_SUITE_END(); }; @@ -146,6 +148,25 @@ namespace CPPUNIT_ASSERT(aFour.equalsL(RTL_CONSTASCII_STRINGPARAM(foo))); } + void Test::test_read_cstring() + { + char foo[] = "foobar"; + SvMemoryStream aMemStream(RTL_CONSTASCII_STRINGPARAM(foo), STREAM_READ); + + rtl::OString aOne = read_zeroTerminated_uInt8s_AsOString(aMemStream); + CPPUNIT_ASSERT(aOne.equalsL(RTL_CONSTASCII_STRINGPARAM("foobar"))); + CPPUNIT_ASSERT(!aMemStream.good()); + CPPUNIT_ASSERT(!aMemStream.bad()); + CPPUNIT_ASSERT(aMemStream.eof()); + + aMemStream.Seek(0); + foo[3] = 0; + rtl::OString aTwo = read_zeroTerminated_uInt8s_AsOString(aMemStream); + CPPUNIT_ASSERT(aTwo.equalsL(RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT(aMemStream.good()); + } + + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } |