iss.seekg(0, std::ios_base::end); //seeking to end doesn't set eof, reading past eof does
CPPUNIT_ASSERT(!iss.eof());
CPPUNIT_ASSERT(iss.good());
aMemStream.Seek(STREAM_SEEK_TO_END); //seeking to end doesn't set eof, reading past eof does
CPPUNIT_ASSERT(!aMemStream.eof());
CPPUNIT_ASSERT(aMemStream.good());
std_a = 78;
iss >> std_a; //so, now eof is set
CPPUNIT_ASSERT(iss.eof()); //a failed read doesn't change the data, it remains unchanged
CPPUNIT_ASSERT_EQUAL(static_cast<char>(78), std_a); //nothing wrong with the stream, so not bad
CPPUNIT_ASSERT(!iss.bad()); //yet, the read didn't succeed
CPPUNIT_ASSERT(!iss.good());
CPPUNIT_ASSERT_EQUAL((std::ios::failbit|std::ios::eofbit), iss.rdstate());
tools_a = 78;
aMemStream.ReadChar( tools_a ); //so, now eof is set
CPPUNIT_ASSERT(aMemStream.eof()); //a failed read doesn't change the data, it remains unchanged
CPPUNIT_ASSERT_EQUAL(static_cast<char>(78), tools_a); //nothing wrong with the stream, so not bad
CPPUNIT_ASSERT(!aMemStream.bad()); //yet, the read didn't succeed
CPPUNIT_ASSERT(!aMemStream.good());
//set things up so that there is only one byte available on an attempt //to read a two-byte sal_uInt16. The byte should be consumed, but the //operation should fail, and tools_b should remain unchanged,
sal_uInt16 tools_b = 0x1122;
aMemStream.SeekRel(-1);
CPPUNIT_ASSERT(!aMemStream.eof());
CPPUNIT_ASSERT(aMemStream.good());
aMemStream.ReadUInt16( tools_b );
CPPUNIT_ASSERT(!aMemStream.good());
CPPUNIT_ASSERT(aMemStream.eof());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0x1122), tools_b);
iss.clear();
iss.seekg(0);
CPPUNIT_ASSERT(iss.good());
iss >> std_a;
CPPUNIT_ASSERT_EQUAL('f', std_a);
aMemStream.ResetError(); // Check that seeking past the end doesn't resize a read-only stream. // This apparently doesn't set an error, but at least it shouldn't // change the size.
aMemStream.Seek(1024LL*1024*1024*3);
CPPUNIT_ASSERT_EQUAL(sal_uInt64(8), aMemStream.GetSize());
void Test::test_write_unicode()
{ static constexpr OUString write(u"abc"_ustr);
utl::TempFileNamed aTempFile(u"test_write_unicode");
aTempFile.EnableKillingFile();
{
SvStream& s = *aTempFile.GetStream(StreamMode::WRITE);
s.SetEndian(SvStreamEndian::BIG); if (!s.IsEndianSwap())
s.SetEndian(SvStreamEndian::LITTLE);
CPPUNIT_ASSERT(s.IsEndianSwap()); // StartWritingUnicodeText must switch to no endian swapping and write 0xfeff
s.StartWritingUnicodeText(); // Without the fix in place, this would fail
CPPUNIT_ASSERT(!s.IsEndianSwap());
s.WriteUnicodeOrByteText(write, RTL_TEXTENCODING_UNICODE);
aTempFile.CloseStream();
}
{
SvStream& s = *aTempFile.GetStream(StreamMode::READ);
s.SetEndian(SvStreamEndian::BIG); if (!s.IsEndianSwap())
s.SetEndian(SvStreamEndian::LITTLE);
CPPUNIT_ASSERT(s.IsEndianSwap());
s.StartReadingUnicodeText(RTL_TEXTENCODING_DONTKNOW);
CPPUNIT_ASSERT(!s.IsEndianSwap());
CPPUNIT_ASSERT_EQUAL(sal_uInt64(2), s.Tell()); // after BOM
OUString read;
CPPUNIT_ASSERT(s.ReadUniOrByteStringLine(read, RTL_TEXTENCODING_UNICODE)); // Without the fix in place, this would fail with // - Expected: abc // - Actual : 愀戀挀
CPPUNIT_ASSERT_EQUAL(write, read);
aTempFile.CloseStream();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.