From 98803a76b3a423cad8e0287337d5cfc5f8aae58c Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 11 Jun 2012 13:32:17 +0200 Subject: Fix QIODevice warning when running rcc. When opening a QFile on stdout, for example, we must not call seek as it is a sequential device. This has been flagged as a warning since commit Ie3a96d3a and has resulted in spurious warnings being emitted. In the case of opening a QFile in Append mode, QIODevice::open already sets the position marker, so calling seek is redundant. This is also true for the file engine's open function (called through openExternalFile()), which also ensures the handle or descriptor is repositioned appropriately. Task-number: QTBUG-26104 Change-Id: I71040c399efe54e7538f54433368b432e959e08d Reviewed-by: Kent Hansen Reviewed-by: Joerg Bornemann --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index ae80159e88..bb280100b9 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -3065,6 +3065,40 @@ static qint64 streamCurrentPosition(FILE *f) return 0; } +class MessageHandler { +public: + MessageHandler(QtMessageHandler messageHandler = handler) + { + ok = true; + oldMessageHandler = qInstallMessageHandler(messageHandler); + } + + ~MessageHandler() + { + qInstallMessageHandler(oldMessageHandler); + } + + static bool testPassed() + { + return ok; + } +protected: + static void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg) + { + if (msg == QString::fromLatin1("QIODevice::seek: Cannot call seek on a sequential device")) + ok = false; + // Defer to old message handler. + if (oldMessageHandler) + oldMessageHandler(type, context, msg); + } + + static QtMessageHandler oldMessageHandler; + static bool ok; +}; + +bool MessageHandler::ok = true; +QtMessageHandler MessageHandler::oldMessageHandler = 0; + void tst_QFile::openStandardStreamsFileDescriptors() { #ifdef Q_OS_WINCE @@ -3074,6 +3108,9 @@ void tst_QFile::openStandardStreamsFileDescriptors() QSKIP("Opening standard streams on Windows CE via descriptor not implemented"); #endif + // Check that QIODevice::seek() isn't called when opening a sequential device (QFile). + MessageHandler msgHandler; + { QFile in; in.open(STDIN_FILENO, QIODevice::ReadOnly); @@ -3094,6 +3131,8 @@ void tst_QFile::openStandardStreamsFileDescriptors() QCOMPARE( err.pos(), streamCurrentPosition(STDERR_FILENO) ); QCOMPARE( err.size(), streamExpectedSize(STDERR_FILENO) ); } + + QVERIFY(msgHandler.testPassed()); } void tst_QFile::openStandardStreamsBufferedStreams() @@ -3101,6 +3140,9 @@ void tst_QFile::openStandardStreamsBufferedStreams() #ifdef Q_OS_WINCE QSKIP("Not tested on Windows CE."); #endif + // Check that QIODevice::seek() isn't called when opening a sequential device (QFile). + MessageHandler msgHandler; + // Using streams { QFile in; @@ -3122,6 +3164,8 @@ void tst_QFile::openStandardStreamsBufferedStreams() QCOMPARE( err.pos(), streamCurrentPosition(stderr) ); QCOMPARE( err.size(), streamExpectedSize(QT_FILENO(stderr)) ); } + + QVERIFY(msgHandler.testPassed()); } void tst_QFile::writeNothing() -- cgit v1.2.3