summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfile/tst_qfile.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-06-11 13:32:17 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-26 19:30:00 +0200
commit98803a76b3a423cad8e0287337d5cfc5f8aae58c (patch)
treebfc6a4757b244a8e530b4193dc73e1d80b123832 /tests/auto/corelib/io/qfile/tst_qfile.cpp
parent003d294cd6cd0567a24cddb7e27ba5880fd2a599 (diff)
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 <kent.hansen@nokia.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
Diffstat (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp44
1 files changed, 44 insertions, 0 deletions
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()