diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-03-09 17:01:09 (GMT) |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 10:05:07 (GMT) |
commit | 0c5d0fbc9f15c2b0f59851d64584a8183f8b4ff5 (patch) | |
tree | 65aa6f5589585077fe9d7f61fcd7f4311dc02362 /tests/auto | |
parent | 291962a745bc38c744400f2dd9b6c960d130a8e6 (diff) | |
download | Qt-0c5d0fbc9f15c2b0f59851d64584a8183f8b4ff5.zip Qt-0c5d0fbc9f15c2b0f59851d64584a8183f8b4ff5.tar.gz Qt-0c5d0fbc9f15c2b0f59851d64584a8183f8b4ff5.tar.bz2 |
Don't write byte-order-mark after seek()
Ideally, we should write a BOM after seek(0) if setGenerateByteOrderMark
has been called, but we don't store that information. This commit is an
improvement for the default case when generateByteOrderMark is false, and
also when seeking to any other position than 0.
Task-number: QTBUG-6295
Reviewed-by: Olivier
(cherry picked from commit 7837de27309c958dc5a5985afc55492ec3054ee0)
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qtextstream/tst_qtextstream.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp index 7c72fb7..d9ee460 100644 --- a/tests/auto/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/qtextstream/tst_qtextstream.cpp @@ -221,6 +221,7 @@ private slots: void nanInf(); void utf8IncompleteAtBufferBoundary_data(); void utf8IncompleteAtBufferBoundary(); + void writeSeekWriteNoBOM(); // status void status_real_read_data(); @@ -1847,6 +1848,63 @@ void tst_QTextStream::utf8IncompleteAtBufferBoundary() } // ------------------------------------------------------------------------------ + +// Make sure we don't write a BOM after seek()ing + +void tst_QTextStream::writeSeekWriteNoBOM() +{ + + //First with the default codec (normally either latin-1 or UTF-8) + + QBuffer out; + out.open(QIODevice::WriteOnly); + QTextStream stream(&out); + + int number = 0; + QString sizeStr = QLatin1String("Size=") + + QString::number(number).rightJustified(10, QLatin1Char('0')); + stream << sizeStr << endl; + stream << "Version=" << QString::number(14) << endl; + stream << "blah blah blah" << endl; + stream.flush(); + + QCOMPARE(out.buffer().constData(), "Size=0000000000\nVersion=14\nblah blah blah\n"); + + // Now overwrite the size header item + number = 42; + stream.seek(0); + sizeStr = QLatin1String("Size=") + + QString::number(number).rightJustified(10, QLatin1Char('0')); + stream << sizeStr << endl; + stream.flush(); + + // Check buffer is still OK + QCOMPARE(out.buffer().constData(), "Size=0000000042\nVersion=14\nblah blah blah\n"); + + + //Then UTF-16 + + QBuffer out16; + out16.open(QIODevice::WriteOnly); + QTextStream stream16(&out16); + stream16.setCodec("UTF-16"); + + stream16 << "one" << "two" << QLatin1String("three"); + stream16.flush(); + + // save that output + QByteArray first = out16.buffer(); + + stream16.seek(0); + stream16 << "one"; + stream16.flush(); + + QCOMPARE(out16.buffer(), first); +} + + + +// ------------------------------------------------------------------------------ void tst_QTextStream::generateOperatorCharData(bool for_QString) { QTest::addColumn<QByteArray>("input"); |