summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@nokia.com>2010-03-09 17:01:09 (GMT)
committerPaul Olav Tvete <paul.tvete@nokia.com>2010-03-09 17:11:50 (GMT)
commit7837de27309c958dc5a5985afc55492ec3054ee0 (patch)
tree4028c192ffec714502c659b9fced67b0f8a0155d /tests/auto
parent65dc878e857ec97c1dbccddc3809eb68ed379fc9 (diff)
downloadQt-7837de27309c958dc5a5985afc55492ec3054ee0.zip
Qt-7837de27309c958dc5a5985afc55492ec3054ee0.tar.gz
Qt-7837de27309c958dc5a5985afc55492ec3054ee0.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
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtextstream/tst_qtextstream.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp
index 9146be2..4c78ef0 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");