From d0b54cede8d8ea0b8431c64abb51d0cd1a71327b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 27 Nov 2015 13:28:45 +0100 Subject: Ensure QTextStream doesn't modify the Text flag on the underlying iodevice An empty read or a failed write on the underlying QIODevice of the text stream would lead to an early return where we wouldn't correctly restore the QIODevice::Text flag of the io device. Change-Id: I5b632f45dea6ede3f408113556c3dad1b96574e2 Task-number: QTBUG-47176 Reviewed-by: Marc Mutz Reviewed-by: Simon Hausmann --- tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 3ab53848d8..a0348f3c54 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -228,6 +228,8 @@ private slots: void alignAccountingStyle(); void setCodec(); + void textModeOnEmptyRead(); + private: void generateLineData(bool for_QString); void generateAllData(bool for_QString); @@ -3045,6 +3047,21 @@ void tst_QTextStream::int_write_with_locale() QCOMPARE(result, output); } +void tst_QTextStream::textModeOnEmptyRead() +{ + const QString filename("textmodetest.txt"); + QFile::remove(filename); // Remove file if exists + + + QFile file(filename); + QVERIFY(file.open(QIODevice::ReadWrite | QIODevice::Text)); + QTextStream stream(&file); + QVERIFY(file.isTextModeEnabled()); + QString emptyLine = stream.readLine(); // Text mode flag cleared here + QVERIFY(file.isTextModeEnabled()); +} + + // ------------------------------------------------------------------------------ QTEST_MAIN(tst_QTextStream) -- cgit v1.2.3