diff options
Diffstat (limited to 'tests/auto/corelib/io')
14 files changed, 736 insertions, 178 deletions
diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index a6d76ea7b6..a477d6bc6c 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -270,7 +270,9 @@ static int NColorRoles[] = { QPalette::ToolTipText + 1, // Qt_5_0 QPalette::ToolTipText + 1, // Qt_5_1 QPalette::ToolTipText + 1, // Qt_5_2 - 0 // add the correct value for Qt_5_3 here later + QPalette::ToolTipText + 1, // Qt_5_3 + QPalette::ToolTipText + 1, // Qt_5_4 + 0 // add the correct value for Qt_5_5 here later }; // Testing get/set functions diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 99c4ee7edc..764c928d76 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -56,11 +56,16 @@ private slots: void criticalWithoutDebug() const; void debugWithBool() const; void debugSpaceHandling() const; + void debugNoQuotes() const; void stateSaver() const; void veryLongWarningMessage() const; + void qDebugQChar() const; void qDebugQStringRef() const; void qDebugQLatin1String() const; + void qDebugQByteArray() const; + void qDebugQFlags() const; void textStreamModifiers() const; + void resetFormat() const; void defaultMessagehandler() const; void threadSafety() const; }; @@ -167,7 +172,8 @@ public: QDebug operator<< (QDebug s, const MyPoint& point) { const QDebugStateSaver saver(s); - return s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")"; + s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")"; + return s; } class MyLine @@ -203,10 +209,45 @@ void tst_QDebug::debugSpaceHandling() const d << 1 << 2; MyLine line(MyPoint(10, 11), MyPoint (12, 13)); d << line; + d << "bar"; // With the old implementation of MyPoint doing dbg.nospace() << ...; dbg.space() we ended up with // MyLine(MyPoint(10, 11) , MyPoint(12, 13) ) } - QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13))")); + QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13)) bar")); + + QVERIFY(qDebug().autoInsertSpaces()); + qDebug() << QPoint(21, 22) << QRect(23, 24, 25, 26) << QLine(27, 28, 29, 30); + QCOMPARE(s_msg, QString::fromLatin1("QPoint(21,22) QRect(23,24 25x26) QLine(QPoint(27,28),QPoint(29,30))")); + qDebug() << QPointF(21, 22) << QRectF(23, 24, 25, 26) << QLineF(27, 28, 29, 30); + QCOMPARE(s_msg, QString::fromLatin1("QPointF(21,22) QRectF(23,24 25x26) QLineF(QPointF(27,28),QPointF(29,30))")); + qDebug() << QMimeType() << QMimeDatabase().mimeTypeForName("application/pdf") << "foo"; + QCOMPARE(s_msg, QString::fromLatin1("QMimeType(invalid) QMimeType(\"application/pdf\") foo")); +} + +void tst_QDebug::debugNoQuotes() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QStringLiteral("Hello"); + d.noquote(); + d << QStringLiteral("Hello"); + d.quote(); + d << QStringLiteral("Hello"); + } + QCOMPARE(s_msg, QString::fromLatin1("\"Hello\" Hello \"Hello\"")); + + { + QDebug d = qDebug(); + d << QChar('H'); + d << QLatin1String("Hello"); + d << QByteArray("Hello"); + d.noquote(); + d << QChar('H'); + d << QLatin1String("Hello"); + d << QByteArray("Hello"); + } + QCOMPARE(s_msg, QString::fromLatin1("'H' \"Hello\" \"Hello\" H Hello Hello")); } void tst_QDebug::stateSaver() const @@ -214,13 +255,46 @@ void tst_QDebug::stateSaver() const MessageHandlerSetter mhs(myMessageHandler); { QDebug d = qDebug(); + d << 42; + { + QDebugStateSaver saver(d); + d << 43; + } + d << 44; + } + QCOMPARE(s_msg, QString::fromLatin1("42 43 44")); + + { + QDebug d = qDebug(); { QDebugStateSaver saver(d); d.nospace() << hex << right << qSetFieldWidth(3) << qSetPadChar('0') << 42; } - d.space() << 42; + d << 42; } QCOMPARE(s_msg, QString::fromLatin1("02a 42")); + + { + QDebug d = qDebug(); + { + QDebugStateSaver saver(d); + d.nospace().noquote() << QStringLiteral("Hello"); + } + d << QStringLiteral("World"); + } + QCOMPARE(s_msg, QString::fromLatin1("Hello \"World\"")); + + { + QDebug d = qDebug(); + d.noquote().nospace() << QStringLiteral("Hello") << hex << 42; + { + QDebugStateSaver saver(d); + d.resetFormat(); + d << QStringLiteral("World") << 42; + } + d << QStringLiteral("!") << 42; + } + QCOMPARE(s_msg, QString::fromLatin1("Hello2a\"World\" 42!2a")); } void tst_QDebug::veryLongWarningMessage() const @@ -241,6 +315,23 @@ void tst_QDebug::veryLongWarningMessage() const QCOMPARE(QString::fromLatin1(s_function), function); } +void tst_QDebug::qDebugQChar() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QChar('f'); + d.nospace().noquote() << QChar('o') << QChar('o'); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("'f' oo")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); + +} + void tst_QDebug::qDebugQStringRef() const { /* Use a basic string. */ @@ -276,13 +367,55 @@ void tst_QDebug::qDebugQStringRef() const void tst_QDebug::qDebugQLatin1String() const { MessageHandlerSetter mhs(myMessageHandler); - { qDebug() << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); } + { + QDebug d = qDebug(); + d << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); + d.nospace().noquote() << QLatin1String("baz"); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" baz")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); +} + +void tst_QDebug::qDebugQByteArray() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QByteArrayLiteral("foo") << QByteArrayLiteral("") << QByteArray("barbaz", 3); + d.nospace().noquote() << QByteArrayLiteral("baz"); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" baz")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); +} + +enum TestEnum { + Flag1 = 0x1, + Flag2 = 0x10 +}; + +Q_DECLARE_FLAGS(TestFlags, TestEnum) + +void tst_QDebug::qDebugQFlags() const +{ + QFlags<TestEnum> flags(Flag1 | Flag2); + + MessageHandlerSetter mhs(myMessageHandler); + { qDebug() << flags; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\"")); + QCOMPARE(s_msg, QString::fromLatin1("QFlags(0x1|0x10)")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); + } void tst_QDebug::textStreamModifiers() const @@ -297,6 +430,22 @@ void tst_QDebug::textStreamModifiers() const QCOMPARE(QString::fromLatin1(s_function), function); } +void tst_QDebug::resetFormat() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d.nospace().noquote() << hex << int(0xf); + d.resetFormat() << int(0xf) << QStringLiteral("foo"); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("f15 \"foo\"")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); +} + void tst_QDebug::defaultMessagehandler() const { MessageHandlerSetter mhs(0); // set 0, should set default handler diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 60d1517ed3..9ce931d78a 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -3028,17 +3028,21 @@ void tst_QFile::mapResource() void tst_QFile::mapOpenMode_data() { QTest::addColumn<int>("openMode"); + QTest::addColumn<int>("flags"); - QTest::newRow("ReadOnly") << int(QIODevice::ReadOnly); + QTest::newRow("ReadOnly") << int(QIODevice::ReadOnly) << int(QFileDevice::NoOptions); //QTest::newRow("WriteOnly") << int(QIODevice::WriteOnly); // this doesn't make sense - QTest::newRow("ReadWrite") << int(QIODevice::ReadWrite); - QTest::newRow("ReadOnly,Unbuffered") << int(QIODevice::ReadOnly | QIODevice::Unbuffered); - QTest::newRow("ReadWrite,Unbuffered") << int(QIODevice::ReadWrite | QIODevice::Unbuffered); + QTest::newRow("ReadWrite") << int(QIODevice::ReadWrite) << int(QFileDevice::NoOptions); + QTest::newRow("ReadOnly,Unbuffered") << int(QIODevice::ReadOnly | QIODevice::Unbuffered) << int(QFileDevice::NoOptions); + QTest::newRow("ReadWrite,Unbuffered") << int(QIODevice::ReadWrite | QIODevice::Unbuffered) << int(QFileDevice::NoOptions); + QTest::newRow("ReadOnly + MapPrivate") << int(QIODevice::ReadOnly) << int(QFileDevice::MapPrivateOption); + QTest::newRow("ReadWrite + MapPrivate") << int(QIODevice::ReadWrite) << int(QFileDevice::MapPrivateOption); } void tst_QFile::mapOpenMode() { QFETCH(int, openMode); + QFETCH(int, flags); static const qint64 fileSize = 4096; QByteArray pattern(fileSize, 'A'); @@ -3060,11 +3064,15 @@ void tst_QFile::mapOpenMode() // open according to our mode QVERIFY(file.open(QIODevice::OpenMode(openMode))); - uchar *memory = file.map(0, fileSize); + uchar *memory = file.map(0, fileSize, QFileDevice::MemoryMapFlags(flags)); +#if defined(Q_OS_WINCE) + QEXPECT_FAIL("ReadOnly + MapPrivate" , "Windows CE does not support MapPrivateOption.", Abort); + QEXPECT_FAIL("ReadWrite + MapPrivate", "Windows CE does not support MapPrivateOption.", Abort); +#endif QVERIFY(memory); QVERIFY(memcmp(memory, pattern, fileSize) == 0); - if (openMode & QIODevice::WriteOnly) { + if ((openMode & QIODevice::WriteOnly) || (flags & QFileDevice::MapPrivateOption)) { // try to write to the file *memory = 'a'; file.unmap(memory); @@ -3073,7 +3081,7 @@ void tst_QFile::mapOpenMode() file.seek(0); char c; QVERIFY(file.getChar(&c)); - QCOMPARE(c, 'a'); + QCOMPARE(c, (flags & QFileDevice::MapPrivateOption) ? 'A' : 'a'); } file.close(); diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 8174cd942f..37cb296ebb 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -78,9 +78,79 @@ #define Q_NO_SYMLINKS #endif -QT_BEGIN_NAMESPACE -extern Q_AUTOTEST_EXPORT bool qIsLikelyToBeNfs(int /* handle */); -QT_END_NAMESPACE + +#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) +inline bool qt_isEvilFsTypeName(const char *name) +{ + return (qstrncmp(name, "nfs", 3) == 0 + || qstrncmp(name, "autofs", 6) == 0 + || qstrncmp(name, "cachefs", 7) == 0); +} + +#if defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD) +# include <sys/param.h> +# include <sys/mount.h> + +bool qIsLikelyToBeNfs(int handle) +{ + struct statfs buf; + if (fstatfs(handle, &buf) != 0) + return false; + return qt_isEvilFsTypeName(buf.f_fstypename); +} + +#elif defined(Q_OS_LINUX) || defined(Q_OS_HURD) + +# include <sys/vfs.h> +# ifdef QT_LINUXBASE + // LSB 3.2 has fstatfs in sys/statfs.h, sys/vfs.h is just an empty dummy header +# include <sys/statfs.h> +# endif + +# ifndef NFS_SUPER_MAGIC +# define NFS_SUPER_MAGIC 0x00006969 +# endif +# ifndef AUTOFS_SUPER_MAGIC +# define AUTOFS_SUPER_MAGIC 0x00000187 +# endif +# ifndef AUTOFSNG_SUPER_MAGIC +# define AUTOFSNG_SUPER_MAGIC 0x7d92b1a0 +# endif + +bool qIsLikelyToBeNfs(int handle) +{ + struct statfs buf; + if (fstatfs(handle, &buf) != 0) + return false; + return buf.f_type == NFS_SUPER_MAGIC + || buf.f_type == AUTOFS_SUPER_MAGIC + || buf.f_type == AUTOFSNG_SUPER_MAGIC; +} + +#elif defined(Q_OS_SOLARIS) || defined(Q_OS_IRIX) || defined(Q_OS_AIX) || defined(Q_OS_HPUX) \ + || defined(Q_OS_OSF) || defined(Q_OS_QNX) || defined(Q_OS_SCO) \ + || defined(Q_OS_UNIXWARE) || defined(Q_OS_RELIANT) || defined(Q_OS_NETBSD) + +# include <sys/statvfs.h> + +bool qIsLikelyToBeNfs(int handle) +{ + struct statvfs buf; + if (fstatvfs(handle, &buf) != 0) + return false; +#if defined(Q_OS_NETBSD) + return qt_isEvilFsTypeName(buf.f_fstypename); +#else + return qt_isEvilFsTypeName(buf.f_basetype); +#endif +} +#else +inline bool qIsLikelyToBeNfs(int /* handle */) +{ + return false; +} +#endif +#endif class tst_QFileInfo : public QObject { diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index e06af5a799..7e04fa5957 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -140,7 +140,7 @@ void tst_QFileSystemWatcher::basicTest() watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend); QVERIFY(watcher.addPath(testFile.fileName())); - QSignalSpy changedSpy(&watcher, SIGNAL(fileChanged(QString))); + QSignalSpy changedSpy(&watcher, &QFileSystemWatcher::fileChanged); QVERIFY(changedSpy.isValid()); QEventLoop eventLoop; QTimer timer; @@ -278,7 +278,7 @@ void tst_QFileSystemWatcher::watchDirectory() watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend); QVERIFY(watcher.addPath(testDir.absolutePath())); - QSignalSpy changedSpy(&watcher, SIGNAL(directoryChanged(QString))); + QSignalSpy changedSpy(&watcher, &QFileSystemWatcher::directoryChanged); QVERIFY(changedSpy.isValid()); QEventLoop eventLoop; QTimer timer; @@ -441,8 +441,8 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QVERIFY(watcher.addPath(testDir.absolutePath())); QVERIFY(watcher.addPath(testFileName)); - QSignalSpy fileChangedSpy(&watcher, SIGNAL(fileChanged(QString))); - QSignalSpy dirChangedSpy(&watcher, SIGNAL(directoryChanged(QString))); + QSignalSpy fileChangedSpy(&watcher, &QFileSystemWatcher::fileChanged); + QSignalSpy dirChangedSpy(&watcher, &QFileSystemWatcher::directoryChanged); QVERIFY(fileChangedSpy.isValid()); QVERIFY(dirChangedSpy.isValid()); QEventLoop eventLoop; @@ -601,7 +601,7 @@ void tst_QFileSystemWatcher::QTBUG2331() QVERIFY(watcher.addPath(temporaryDirectory.path())); // watch signal - QSignalSpy changedSpy(&watcher, SIGNAL(directoryChanged(QString))); + QSignalSpy changedSpy(&watcher, &QFileSystemWatcher::directoryChanged); QVERIFY(changedSpy.isValid()); // remove directory, we should get one change signal, and we should no longer @@ -680,7 +680,7 @@ void tst_QFileSystemWatcher::signalsEmittedAfterFileMoved() connect(&watcher, SIGNAL(fileChanged(QString)), &signalReceiver, SLOT(fileChanged(QString))); // watch signals - QSignalSpy changedSpy(&watcher, SIGNAL(fileChanged(QString))); + QSignalSpy changedSpy(&watcher, &QFileSystemWatcher::fileChanged); QVERIFY(changedSpy.isValid()); // move files to second directory diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp index b0d7a76f0f..6d49238e51 100644 --- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp +++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -44,7 +44,6 @@ #include <QLoggingCategory> Q_LOGGING_CATEGORY(TST_LOG, "tst.log") -Q_LOGGING_CATEGORY(TST_LOG1, "tst.log1") Q_LOGGING_CATEGORY(Digia_Oslo_Office_com, "Digia.Oslo.Office.com") Q_LOGGING_CATEGORY(Digia_Oulu_Office_com, "Digia.Oulu.Office.com") Q_LOGGING_CATEGORY(Digia_Berlin_Office_com, "Digia.Berlin.Office.com") @@ -278,6 +277,14 @@ private slots: QCOMPARE(customCategory.isCriticalEnabled(), true); QCOMPARE(customCategory.isEnabled(QtCriticalMsg), true); + QLoggingCategory onlyWarningsCategory("withType", QtWarningMsg); + QCOMPARE(onlyWarningsCategory.isDebugEnabled(), false); + QCOMPARE(onlyWarningsCategory.isEnabled(QtDebugMsg), false); + QCOMPARE(onlyWarningsCategory.isWarningEnabled(), true); + QCOMPARE(onlyWarningsCategory.isEnabled(QtWarningMsg), true); + QCOMPARE(onlyWarningsCategory.isCriticalEnabled(), true); + QCOMPARE(onlyWarningsCategory.isEnabled(QtCriticalMsg), true); + // make sure nothing has printed warnings QVERIFY(logMessage.isEmpty()); } @@ -367,6 +374,35 @@ private slots: QCOMPARE(logMessage, buf); } + Q_LOGGING_CATEGORY(TST_MACRO_1, "tst.macro.1") +#ifdef Q_COMPILER_VARIADIC_MACROS + Q_LOGGING_CATEGORY(TST_MACRO_2, "tst.macro.2", QtDebugMsg) + Q_LOGGING_CATEGORY(TST_MACRO_3, "tst.macro.3", QtFatalMsg) +#endif + + void QLoggingCategoryMacro() + { + const QLoggingCategory &cat1 = TST_MACRO_1(); + QCOMPARE(cat1.categoryName(), "tst.macro.1"); + QCOMPARE(cat1.isDebugEnabled(), true); + QCOMPARE(cat1.isWarningEnabled(), true); + QCOMPARE(cat1.isCriticalEnabled(), true); + +#ifdef Q_COMPILER_VARIADIC_MACROS + const QLoggingCategory &cat2 = TST_MACRO_2(); + QCOMPARE(cat2.categoryName(), "tst.macro.2"); + QCOMPARE(cat2.isDebugEnabled(), true); + QCOMPARE(cat2.isWarningEnabled(), true); + QCOMPARE(cat2.isCriticalEnabled(), true); + + const QLoggingCategory &cat3 = TST_MACRO_3(); + QCOMPARE(cat3.categoryName(), "tst.macro.3"); + QCOMPARE(cat3.isDebugEnabled(), false); + QCOMPARE(cat3.isWarningEnabled(), false); + QCOMPARE(cat3.isCriticalEnabled(), false); +#endif + } + void qCDebugMacros() { QString buf; diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 82a0f3f832..1d6418cbc0 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -259,7 +259,7 @@ void tst_QProcess::simpleStart() qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); process = new QProcess; - QSignalSpy spy(process, SIGNAL(stateChanged(QProcess::ProcessState))); + QSignalSpy spy(process, &QProcess::stateChanged); QVERIFY(spy.isValid()); connect(process, SIGNAL(readyRead()), this, SLOT(readFromProcess())); @@ -351,7 +351,7 @@ void tst_QProcess::crashTest() { qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); process = new QProcess; - QSignalSpy stateSpy(process, SIGNAL(stateChanged(QProcess::ProcessState))); + QSignalSpy stateSpy(process, &QProcess::stateChanged); QVERIFY(stateSpy.isValid()); process->start("testProcessCrash/testProcessCrash"); QVERIFY(process->waitForStarted(5000)); @@ -359,8 +359,8 @@ void tst_QProcess::crashTest() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, SIGNAL(error(QProcess::ProcessError))); - QSignalSpy spy2(process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); @@ -394,8 +394,8 @@ void tst_QProcess::crashTest2() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, SIGNAL(error(QProcess::ProcessError))); - QSignalSpy spy2(process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); @@ -503,8 +503,8 @@ void tst_QProcess::echoTest2() QCOMPARE(process->error(), QProcess::Timedout); process->write("Hello"); - QSignalSpy spy1(process, SIGNAL(readyReadStandardOutput())); - QSignalSpy spy2(process, SIGNAL(readyReadStandardError())); + QSignalSpy spy1(process, &QProcess::readyReadStandardOutput); + QSignalSpy spy2(process, &QProcess::readyReadStandardError); QVERIFY(spy1.isValid()); QVERIFY(spy2.isValid()); @@ -685,7 +685,7 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(process->error(), QProcess::Timedout); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(process, SIGNAL(error(QProcess::ProcessError))); + QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QVERIFY(spy.isValid()); process->kill(); @@ -887,7 +887,7 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() QProcess proc; connect(&proc, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); - QSignalSpy spy(&proc, SIGNAL(readyRead())); + QSignalSpy spy(&proc, &QProcess::readyRead); QVERIFY(spy.isValid()); proc.start("testProcessEcho/testProcessEcho"); @@ -1283,7 +1283,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() process->start("testProcessEcho/testProcessEcho"); QVERIFY(process->waitForStarted(5000)); - QSignalSpy spy(process, SIGNAL(readyRead())); + QSignalSpy spy(process, &QProcess::readyRead); QVERIFY(spy.isValid()); process->write("foo"); QTestEventLoop::instance().enterLoop(30); @@ -1323,7 +1323,7 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() process->start("testProcessEcho/testProcessEcho"); QVERIFY(process->waitForStarted(5000)); - QSignalSpy spy(process, SIGNAL(bytesWritten(qint64))); + QSignalSpy spy(process, &QProcess::bytesWritten); QVERIFY(spy.isValid()); process->write("f"); QTestEventLoop::instance().enterLoop(30); @@ -1538,10 +1538,10 @@ void tst_QProcess::failToStart() qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); QProcess process; - QSignalSpy stateSpy(&process, SIGNAL(stateChanged(QProcess::ProcessState))); - QSignalSpy errorSpy(&process, SIGNAL(error(QProcess::ProcessError))); - QSignalSpy finishedSpy(&process, SIGNAL(finished(int))); - QSignalSpy finishedSpy2(&process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy stateSpy(&process, &QProcess::stateChanged); + QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(stateSpy.isValid()); QVERIFY(errorSpy.isValid()); @@ -1605,9 +1605,9 @@ void tst_QProcess::failToStartWithWait() QProcess process; QEventLoop loop; - QSignalSpy errorSpy(&process, SIGNAL(error(QProcess::ProcessError))); - QSignalSpy finishedSpy(&process, SIGNAL(finished(int))); - QSignalSpy finishedSpy2(&process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); QVERIFY(finishedSpy.isValid()); @@ -1632,9 +1632,9 @@ void tst_QProcess::failToStartWithEventLoop() QProcess process; QEventLoop loop; - QSignalSpy errorSpy(&process, SIGNAL(error(QProcess::ProcessError))); - QSignalSpy finishedSpy(&process, SIGNAL(finished(int))); - QSignalSpy finishedSpy2(&process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); QVERIFY(finishedSpy.isValid()); @@ -1864,9 +1864,9 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); QProcess process; - QSignalSpy errorSpy(&process, SIGNAL(error(QProcess::ProcessError))); - QSignalSpy finishedSpy1(&process, SIGNAL(finished(int))); - QSignalSpy finishedSpy2(&process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy finishedSpy1(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); QVERIFY(finishedSpy1.isValid()); @@ -2202,7 +2202,7 @@ void tst_QProcess::invalidProgramString() QProcess process; qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(&process, SIGNAL(error(QProcess::ProcessError))); + QSignalSpy spy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QVERIFY(spy.isValid()); process.start(programString); @@ -2218,8 +2218,8 @@ void tst_QProcess::onlyOneStartedSignal() qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); QProcess process; - QSignalSpy spyStarted(&process, SIGNAL(started())); - QSignalSpy spyFinished(&process, SIGNAL(finished(int,QProcess::ExitStatus))); + QSignalSpy spyStarted(&process, &QProcess::started); + QSignalSpy spyFinished(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spyStarted.isValid()); QVERIFY(spyFinished.isValid()); diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 515a10426c..230030d5cd 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -47,6 +47,9 @@ class tst_QResourceEngine: public QObject { Q_OBJECT +public: + tst_QResourceEngine() : m_runtimeResourceRcc(QFINDTESTDATA("runtime_resource.rcc")) {} + private slots: void initTestCase(); void cleanupTestCase(); @@ -59,20 +62,24 @@ private slots: void searchPath(); void doubleSlashInRoot(); void setLocale(); + +private: + const QString m_runtimeResourceRcc; }; void tst_QResourceEngine::initTestCase() { - QVERIFY(QResource::registerResource(QFINDTESTDATA("runtime_resource.rcc"))); - QVERIFY(QResource::registerResource(QFINDTESTDATA("runtime_resource.rcc"), "/secondary_root/")); + QVERIFY(!m_runtimeResourceRcc.isEmpty()); + QVERIFY(QResource::registerResource(m_runtimeResourceRcc)); + QVERIFY(QResource::registerResource(m_runtimeResourceRcc, "/secondary_root/")); } void tst_QResourceEngine::cleanupTestCase() { // make sure we don't leak memory - QVERIFY(QResource::unregisterResource(QFINDTESTDATA("runtime_resource.rcc"))); - QVERIFY(QResource::unregisterResource(QFINDTESTDATA("runtime_resource.rcc"), "/secondary_root/")); + QVERIFY(QResource::unregisterResource(m_runtimeResourceRcc)); + QVERIFY(QResource::unregisterResource(m_runtimeResourceRcc, "/secondary_root/")); } void tst_QResourceEngine::checkStructure_data() diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp index 87bcfe572d..08b943ba72 100644 --- a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp +++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp @@ -93,6 +93,8 @@ private slots: void transactionalWriteNoPermissionsOnFile(); void transactionalWriteCanceled(); void transactionalWriteErrorRenaming(); + void symlink(); + void directory(); }; static inline QByteArray msgCannotOpen(const QFileDevice &f) @@ -340,5 +342,142 @@ void tst_QSaveFile::transactionalWriteErrorRenaming() QCOMPARE(file.error(), QFile::RenameError); } +void tst_QSaveFile::symlink() +{ +#ifdef Q_OS_UNIX + QByteArray someData = "some data"; + QTemporaryDir dir; + QVERIFY(dir.isValid()); + + const QString targetFile = dir.path() + QLatin1String("/outfile"); + const QString linkFile = dir.path() + QLatin1String("/linkfile"); + { + QFile file(targetFile); + QVERIFY2(file.open(QIODevice::WriteOnly), msgCannotOpen(file).constData()); + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + file.close(); + } + + QVERIFY(QFile::link(targetFile, linkFile)); + + QString canonical = QFileInfo(linkFile).canonicalFilePath(); + QCOMPARE(canonical, QFileInfo(targetFile).canonicalFilePath()); + + // Try saving into it + { + QSaveFile saveFile(linkFile); + QVERIFY(saveFile.open(QIODevice::WriteOnly)); + QCOMPARE(saveFile.write(someData), someData.size()); + saveFile.commit(); + + //Check that the linkFile is still a link and still has the same canonical path + QFileInfo info(linkFile); + QVERIFY(info.isSymLink()); + QCOMPARE(QFileInfo(linkFile).canonicalFilePath(), canonical); + + QFile file(targetFile); + QVERIFY2(file.open(QIODevice::ReadOnly), msgCannotOpen(file).constData()); + QCOMPARE(file.readAll(), someData); + file.remove(); + } + + // Save into a symbolic link that point to a removed file + someData = "more stuff"; + { + QSaveFile saveFile(linkFile); + QVERIFY(saveFile.open(QIODevice::WriteOnly)); + QCOMPARE(saveFile.write(someData), someData.size()); + saveFile.commit(); + + QFileInfo info(linkFile); + QVERIFY(info.isSymLink()); + QCOMPARE(QFileInfo(linkFile).canonicalFilePath(), canonical); + + QFile file(targetFile); + QVERIFY2(file.open(QIODevice::ReadOnly), msgCannotOpen(file).constData()); + QCOMPARE(file.readAll(), someData); + } + + // link to a link in another directory + QTemporaryDir dir2; + QVERIFY(dir2.isValid()); + + const QString linkFile2 = dir2.path() + QLatin1String("/linkfile"); + QVERIFY(QFile::link(linkFile, linkFile2)); + QCOMPARE(QFileInfo(linkFile2).canonicalFilePath(), canonical); + + + someData = "hello everyone"; + + { + QSaveFile saveFile(linkFile2); + QVERIFY(saveFile.open(QIODevice::WriteOnly)); + QCOMPARE(saveFile.write(someData), someData.size()); + saveFile.commit(); + + QFile file(targetFile); + QVERIFY2(file.open(QIODevice::ReadOnly), msgCannotOpen(file).constData()); + QCOMPARE(file.readAll(), someData); + } + + //cyclic link + const QString cyclicLink = dir.path() + QLatin1String("/cyclic"); + QVERIFY(QFile::link(cyclicLink, cyclicLink)); + { + QSaveFile saveFile(cyclicLink); + QVERIFY(saveFile.open(QIODevice::WriteOnly)); + QCOMPARE(saveFile.write(someData), someData.size()); + saveFile.commit(); + + QFile file(cyclicLink); + QVERIFY2(file.open(QIODevice::ReadOnly), msgCannotOpen(file).constData()); + QCOMPARE(file.readAll(), someData); + } + + //cyclic link2 + QVERIFY(QFile::link(cyclicLink + QLatin1Char('1'), cyclicLink + QLatin1Char('2'))); + QVERIFY(QFile::link(cyclicLink + QLatin1Char('2'), cyclicLink + QLatin1Char('1'))); + + { + QSaveFile saveFile(cyclicLink + QLatin1Char('1')); + QVERIFY(saveFile.open(QIODevice::WriteOnly)); + QCOMPARE(saveFile.write(someData), someData.size()); + saveFile.commit(); + + // the explicit file becomes a file instead of a link + QVERIFY(!QFileInfo(cyclicLink + QLatin1Char('1')).isSymLink()); + QVERIFY(QFileInfo(cyclicLink + QLatin1Char('2')).isSymLink()); + + QFile file(cyclicLink + QLatin1Char('1')); + QVERIFY2(file.open(QIODevice::ReadOnly), msgCannotOpen(file).constData()); + QCOMPARE(file.readAll(), someData); + } +#endif +} + +void tst_QSaveFile::directory() +{ + QTemporaryDir dir; + QVERIFY(dir.isValid()); + + const QString subdir = dir.path() + QLatin1String("/subdir"); + QVERIFY(QDir(dir.path()).mkdir(QStringLiteral("subdir"))); + { + QFile sf(subdir); + QVERIFY(!sf.open(QIODevice::WriteOnly)); + } + +#ifdef Q_OS_UNIX + //link to a directory + const QString linkToDir = dir.path() + QLatin1String("/linkToDir"); + QVERIFY(QFile::link(subdir, linkToDir)); + + { + QFile sf(linkToDir); + QVERIFY(!sf.open(QIODevice::WriteOnly)); + } +#endif +} + QTEST_MAIN(tst_QSaveFile) #include "tst_qsavefile.moc" diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 7247b02498..c373e80408 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -56,7 +56,7 @@ #define Q_XDG_PLATFORM #endif -static const int MaxStandardLocation = QStandardPaths::GenericConfigLocation; +static const int MaxStandardLocation = QStandardPaths::AppDataLocation; class tst_qstandardpaths : public QObject { @@ -129,7 +129,8 @@ static const char * const enumNames[MaxStandardLocation + 1 - int(QStandardPaths "ConfigLocation", "DownloadLocation", "GenericCacheLocation", - "GenericConfigLocation" + "GenericConfigLocation", + "AppDataLocation" }; void tst_qstandardpaths::dump() @@ -238,7 +239,8 @@ void tst_qstandardpaths::enableTestMode() // Check this for locations where test programs typically write. Not desktop, download, music etc... typedef QHash<QStandardPaths::StandardLocation, QString> LocationHash; LocationHash testLocations; - testLocations.insert(QStandardPaths::DataLocation, QStandardPaths::writableLocation(QStandardPaths::DataLocation)); + testLocations.insert(QStandardPaths::AppDataLocation, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + testLocations.insert(QStandardPaths::AppLocalDataLocation, QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); testLocations.insert(QStandardPaths::GenericDataLocation, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); testLocations.insert(QStandardPaths::ConfigLocation, QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); testLocations.insert(QStandardPaths::GenericConfigLocation, QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)); @@ -294,18 +296,18 @@ void tst_qstandardpaths::testDataLocation() // applications are sandboxed. #if !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_ANDROID) && !defined(Q_OS_WINRT) const QString base = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); - QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::DataLocation), base + "/tst_qstandardpaths"); + QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation), base + "/tst_qstandardpaths"); QCoreApplication::instance()->setOrganizationName("Qt"); - QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::DataLocation), base + "/Qt/tst_qstandardpaths"); + QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation), base + "/Qt/tst_qstandardpaths"); QCoreApplication::instance()->setApplicationName("QtTest"); - QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::DataLocation), base + "/Qt/QtTest"); + QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation), base + "/Qt/QtTest"); #endif #ifdef Q_XDG_PLATFORM setDefaultLocations(); const QString expectedAppDataDir = QDir::homePath() + QString::fromLatin1("/.local/share/Qt/QtTest"); - QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::DataLocation), expectedAppDataDir); - const QStringList appDataDirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation), expectedAppDataDir); + const QStringList appDataDirs = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation); QCOMPARE(appDataDirs.count(), 3); QCOMPARE(appDataDirs.at(0), expectedAppDataDir); QCOMPARE(appDataDirs.at(1), QString::fromLatin1("/usr/local/share/Qt/QtTest")); @@ -463,7 +465,7 @@ void tst_qstandardpaths::testAllWritableLocations_data() QTest::newRow("PicturesLocation") << QStandardPaths::PicturesLocation; QTest::newRow("TempLocation") << QStandardPaths::TempLocation; QTest::newRow("HomeLocation") << QStandardPaths::HomeLocation; - QTest::newRow("DataLocation") << QStandardPaths::DataLocation; + QTest::newRow("AppLocalDataLocation") << QStandardPaths::AppLocalDataLocation; QTest::newRow("DownloadLocation") << QStandardPaths::DownloadLocation; } diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 5ad798ae1f..74220d7f97 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -251,6 +251,11 @@ void tst_QTemporaryFile::autoRemove() QTemporaryFile file("tempXXXXXX"); QVERIFY(file.open()); fileName = file.fileName(); + // QTBUG-39976, file mappings should be cleared as well. + QVERIFY(file.write("test")); + QVERIFY(file.flush()); + uchar *mapped = file.map(0, file.size()); + QVERIFY(mapped); file.close(); } QVERIFY(!QFile::exists(fileName)); @@ -441,13 +446,15 @@ void tst_QTemporaryFile::rename() void tst_QTemporaryFile::renameFdLeak() { #ifdef Q_OS_UNIX + const QByteArray sourceFile = QFile::encodeName(QFINDTESTDATA(__FILE__)); + QVERIFY(!sourceFile.isEmpty()); // Test this on Unix only // Open a bunch of files to force the fd count to go up static const int count = 10; int bunch_of_files[count]; for (int i = 0; i < count; ++i) { - bunch_of_files[i] = ::open(qPrintable(QFINDTESTDATA("tst_qtemporaryfile.cpp")), O_RDONLY); + bunch_of_files[i] = ::open(sourceFile.constData(), O_RDONLY); QVERIFY(bunch_of_files[i] != -1); } @@ -642,8 +649,10 @@ void tst_QTemporaryFile::createNativeFile_data() QTest::addColumn<bool>("valid"); QTest::addColumn<QByteArray>("content"); - QTest::newRow("nativeFile") << QFINDTESTDATA("resources/test.txt") << (qint64)-1 << false << QByteArray(); - QTest::newRow("nativeFileWithPos") << QFINDTESTDATA("resources/test.txt") << (qint64)5 << false << QByteArray(); + const QString nativeFilePath = QFINDTESTDATA("resources/test.txt"); + + QTest::newRow("nativeFile") << nativeFilePath << (qint64)-1 << false << QByteArray(); + QTest::newRow("nativeFileWithPos") << nativeFilePath << (qint64)5 << false << QByteArray(); QTest::newRow("resourceFile") << ":/resources/test.txt" << (qint64)-1 << true << QByteArray("This is a test"); QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test"); } diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 2ae085cb0b..f402421165 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -245,6 +245,8 @@ private: QTemporaryDir tempDir; QString testFileName; + const QString m_rfc3261FilePath; + const QString m_shiftJisFilePath; }; void runOnExit() @@ -256,11 +258,16 @@ Q_DESTRUCTOR_FUNCTION(runOnExit) tst_QTextStream::tst_QTextStream() : tempDir(QDir::tempPath() + "/tst_qtextstream.XXXXXX") + , m_rfc3261FilePath(QFINDTESTDATA("rfc3261.txt")) + , m_shiftJisFilePath(QFINDTESTDATA("shift-jis.txt")) { } void tst_QTextStream::initTestCase() { + QVERIFY(!m_rfc3261FilePath.isEmpty()); + QVERIFY(!m_shiftJisFilePath.isEmpty()); + testFileName = tempDir.path() + "/testfile"; // chdir into the testdata dir and refer to our helper apps with relative paths @@ -768,7 +775,7 @@ void tst_QTextStream::generateAllData(bool for_QString) // ------------------------------------------------------------------------------ void tst_QTextStream::readLineUntilNull() { - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); QTextStream stream(&file); @@ -887,7 +894,7 @@ void tst_QTextStream::lineCount_data() QTest::newRow("buffersize+1 line") << QByteArray(16384, '\n') << 16384; QTest::newRow("buffersize+2 line") << QByteArray(16385, '\n') << 16385; - QFile file(QFINDTESTDATA("rfc3261.txt")); file.open(QFile::ReadOnly); + QFile file(m_rfc3261FilePath); file.open(QFile::ReadOnly); QTest::newRow("rfc3261") << file.readAll() << 15067; } @@ -923,7 +930,7 @@ void tst_QTextStream::performance() stopWatch.restart(); int nlines1 = 0; - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); while (!file.atEnd()) { @@ -935,7 +942,7 @@ void tst_QTextStream::performance() stopWatch.restart(); int nlines2 = 0; - QFile file2(QFINDTESTDATA("rfc3261.txt")); + QFile file2(m_rfc3261FilePath); QVERIFY(file2.open(QFile::ReadOnly)); QTextStream stream(&file2); @@ -1155,7 +1162,7 @@ void tst_QTextStream::readNewlines() // ------------------------------------------------------------------------------ void tst_QTextStream::seek() { - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); QTextStream stream(&file); @@ -1248,7 +1255,7 @@ void tst_QTextStream::pos() } { // Latin1 device - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QIODevice::ReadOnly)); QTextStream stream(&file); @@ -1280,7 +1287,7 @@ void tst_QTextStream::pos() { // Shift-JIS device for (int i = 0; i < 2; ++i) { - QFile file(QFINDTESTDATA("shift-jis.txt")); + QFile file(m_shiftJisFilePath); if (i == 0) QVERIFY(file.open(QIODevice::ReadOnly)); else @@ -1788,8 +1795,6 @@ void tst_QTextStream::writeSeekWriteNoBOM() QCOMPARE(out16.buffer(), first); } - - // ------------------------------------------------------------------------------ void tst_QTextStream::generateOperatorCharData(bool for_QString) { @@ -2142,14 +2147,36 @@ void tst_QTextStream::byteArray_read_operator_FromDevice() { \ QFETCH(qulonglong, number); \ QFETCH(QByteArray, data); \ + QFETCH(QByteArray, dataWithSeparators); \ \ QBuffer buffer; \ buffer.open(QBuffer::WriteOnly); \ QTextStream stream(&buffer); \ + stream.setLocale(QLocale::c()); \ stream << (type)number; \ stream.flush(); \ + QCOMPARE(buffer.data().constData(), data.constData()); \ \ + QLocale locale("en-US"); \ + buffer.reset(); buffer.buffer().clear(); \ + stream.setLocale(locale); \ + stream << (type)number; \ + stream.flush(); \ + QCOMPARE(buffer.data(), dataWithSeparators); \ + \ + locale.setNumberOptions(QLocale::OmitGroupSeparator); \ + buffer.reset(); buffer.buffer().clear(); \ + stream.setLocale(locale); \ + stream << (type)number; \ + stream.flush(); \ QCOMPARE(buffer.data().constData(), data.constData()); \ + \ + locale = QLocale("de-DE"); \ + buffer.reset(); buffer.buffer().clear(); \ + stream.setLocale(locale); \ + stream << (type)number; \ + stream.flush(); \ + QCOMPARE(buffer.data(), dataWithSeparators.replace(',', '.')); \ } // ------------------------------------------------------------------------------ @@ -2157,16 +2184,17 @@ void tst_QTextStream::signedShort_write_operator_ToDevice_data() { QTest::addColumn<qulonglong>("number"); QTest::addColumn<QByteArray>("data"); - - QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0"); - QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1"); - QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767"); - QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("-32768"); - QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("-32767"); - QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("-1"); - QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("0"); - QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("1"); + QTest::addColumn<QByteArray>("dataWithSeparators"); + + QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); + QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); + QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); + QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("-32768") << QByteArray("-32,768"); + QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("-32767") << QByteArray("-32,767"); + QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("0") << QByteArray("0"); + QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("1") << QByteArray("1"); } IMPLEMENT_STREAM_LEFT_INT_OPERATOR_TEST(signedShort, signed short) ; @@ -2176,16 +2204,17 @@ void tst_QTextStream::unsignedShort_write_operator_ToDevice_data() { QTest::addColumn<qulonglong>("number"); QTest::addColumn<QByteArray>("data"); - - QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0"); - QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("65535"); - QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767"); - QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768"); - QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769"); - QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535"); - QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("0"); - QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("1"); + QTest::addColumn<QByteArray>("dataWithSeparators"); + + QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); + QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); + QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); + QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); + QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); + QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("0") << QByteArray("0"); + QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("1") << QByteArray("1"); } IMPLEMENT_STREAM_LEFT_INT_OPERATOR_TEST(unsignedShort, unsigned short) ; @@ -2195,22 +2224,23 @@ void tst_QTextStream::signedInt_write_operator_ToDevice_data() { QTest::addColumn<qulonglong>("number"); QTest::addColumn<QByteArray>("data"); - - QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0"); - QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1"); - QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767"); - QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768"); - QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769"); - QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535"); - QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536"); - QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537"); - QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647"); - QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("-2147483648"); - QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("-2147483647"); - QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("-1"); - QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("0"); - QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("1"); + QTest::addColumn<QByteArray>("dataWithSeparators"); + + QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); + QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); + QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); + QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); + QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); + QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536") << QByteArray("65,536"); + QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537") << QByteArray("65,537"); + QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647") << QByteArray("2,147,483,647"); + QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("-2147483648") << QByteArray("-2,147,483,648"); + QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("-2147483647") << QByteArray("-2,147,483,647"); + QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("0") << QByteArray("0"); + QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("1") << QByteArray("1"); } IMPLEMENT_STREAM_LEFT_INT_OPERATOR_TEST(signedInt, signed int) ; @@ -2220,22 +2250,23 @@ void tst_QTextStream::unsignedInt_write_operator_ToDevice_data() { QTest::addColumn<qulonglong>("number"); QTest::addColumn<QByteArray>("data"); - - QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0"); - QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("4294967295"); - QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767"); - QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768"); - QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769"); - QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535"); - QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536"); - QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537"); - QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647"); - QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("2147483648"); - QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("2147483649"); - QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("4294967295"); - QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("0"); - QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("1"); + QTest::addColumn<QByteArray>("dataWithSeparators"); + + QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); + QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); + QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("4294967295") << QByteArray("4,294,967,295"); + QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); + QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); + QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); + QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536") << QByteArray("65,536"); + QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537") << QByteArray("65,537"); + QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647") << QByteArray("2,147,483,647"); + QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("2147483648") << QByteArray("2,147,483,648"); + QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("2147483649") << QByteArray("2,147,483,649"); + QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("4294967295") << QByteArray("4,294,967,295"); + QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("0") << QByteArray("0"); + QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("1") << QByteArray("1"); } IMPLEMENT_STREAM_LEFT_INT_OPERATOR_TEST(unsignedInt, unsigned int) ; @@ -2245,26 +2276,27 @@ void tst_QTextStream::qlonglong_write_operator_ToDevice_data() { QTest::addColumn<qulonglong>("number"); QTest::addColumn<QByteArray>("data"); - - QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0"); - QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1"); - QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767"); - QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768"); - QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769"); - QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535"); - QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536"); - QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537"); - QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647"); - QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("2147483648"); - QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("2147483649"); - QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("4294967295"); - QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("4294967296"); - QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("4294967297"); - QTest::newRow("9223372036854775807") << Q_UINT64_C(9223372036854775807) << QByteArray("9223372036854775807"); - QTest::newRow("9223372036854775808") << Q_UINT64_C(9223372036854775808) << QByteArray("-9223372036854775808"); - QTest::newRow("9223372036854775809") << Q_UINT64_C(9223372036854775809) << QByteArray("-9223372036854775807"); - QTest::newRow("18446744073709551615") << Q_UINT64_C(18446744073709551615) << QByteArray("-1"); + QTest::addColumn<QByteArray>("dataWithSeparators"); + + QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); + QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); + QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); + QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); + QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); + QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536") << QByteArray("65,536"); + QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537") << QByteArray("65,537"); + QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647") << QByteArray("2,147,483,647"); + QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("2147483648") << QByteArray("2,147,483,648"); + QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("2147483649") << QByteArray("2,147,483,649"); + QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("4294967295") << QByteArray("4,294,967,295"); + QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("4294967296") << QByteArray("4,294,967,296"); + QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("4294967297") << QByteArray("4,294,967,297"); + QTest::newRow("9223372036854775807") << Q_UINT64_C(9223372036854775807) << QByteArray("9223372036854775807") << QByteArray("9,223,372,036,854,775,807"); + QTest::newRow("9223372036854775808") << Q_UINT64_C(9223372036854775808) << QByteArray("-9223372036854775808") << QByteArray("-9,223,372,036,854,775,808"); + QTest::newRow("9223372036854775809") << Q_UINT64_C(9223372036854775809) << QByteArray("-9223372036854775807") << QByteArray("-9,223,372,036,854,775,807"); + QTest::newRow("18446744073709551615") << Q_UINT64_C(18446744073709551615) << QByteArray("-1") << QByteArray("-1"); } IMPLEMENT_STREAM_LEFT_INT_OPERATOR_TEST(qlonglong, qlonglong) ; @@ -2274,26 +2306,27 @@ void tst_QTextStream::qulonglong_write_operator_ToDevice_data() { QTest::addColumn<qulonglong>("number"); QTest::addColumn<QByteArray>("data"); - - QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0"); - QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("18446744073709551615"); - QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767"); - QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768"); - QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769"); - QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535"); - QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536"); - QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537"); - QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647"); - QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("2147483648"); - QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("2147483649"); - QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("4294967295"); - QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("4294967296"); - QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("4294967297"); - QTest::newRow("9223372036854775807") << Q_UINT64_C(9223372036854775807) << QByteArray("9223372036854775807"); - QTest::newRow("9223372036854775808") << Q_UINT64_C(9223372036854775808) << QByteArray("9223372036854775808"); - QTest::newRow("9223372036854775809") << Q_UINT64_C(9223372036854775809) << QByteArray("9223372036854775809"); - QTest::newRow("18446744073709551615") << Q_UINT64_C(18446744073709551615) << QByteArray("18446744073709551615"); + QTest::addColumn<QByteArray>("dataWithSeparators"); + + QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); + QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); + QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("18446744073709551615") << QByteArray("18,446,744,073,709,551,615"); + QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); + QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); + QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); + QTest::newRow("65535") << Q_UINT64_C(65535) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("65536") << Q_UINT64_C(65536) << QByteArray("65536") << QByteArray("65,536"); + QTest::newRow("65537") << Q_UINT64_C(65537) << QByteArray("65537") << QByteArray("65,537"); + QTest::newRow("2147483647") << Q_UINT64_C(2147483647) << QByteArray("2147483647") << QByteArray("2,147,483,647"); + QTest::newRow("2147483648") << Q_UINT64_C(2147483648) << QByteArray("2147483648") << QByteArray("2,147,483,648"); + QTest::newRow("2147483649") << Q_UINT64_C(2147483649) << QByteArray("2147483649") << QByteArray("2,147,483,649"); + QTest::newRow("4294967295") << Q_UINT64_C(4294967295) << QByteArray("4294967295") << QByteArray("4,294,967,295"); + QTest::newRow("4294967296") << Q_UINT64_C(4294967296) << QByteArray("4294967296") << QByteArray("4,294,967,296"); + QTest::newRow("4294967297") << Q_UINT64_C(4294967297) << QByteArray("4294967297") << QByteArray("4,294,967,297"); + QTest::newRow("9223372036854775807") << Q_UINT64_C(9223372036854775807) << QByteArray("9223372036854775807") << QByteArray("9,223,372,036,854,775,807"); + QTest::newRow("9223372036854775808") << Q_UINT64_C(9223372036854775808) << QByteArray("9223372036854775808") << QByteArray("9,223,372,036,854,775,808"); + QTest::newRow("9223372036854775809") << Q_UINT64_C(9223372036854775809) << QByteArray("9223372036854775809") << QByteArray("9,223,372,036,854,775,809"); + QTest::newRow("18446744073709551615") << Q_UINT64_C(18446744073709551615) << QByteArray("18446744073709551615") << QByteArray("18,446,744,073,709,551,615"); } IMPLEMENT_STREAM_LEFT_INT_OPERATOR_TEST(qulonglong, qulonglong) ; @@ -2304,12 +2337,14 @@ void tst_QTextStream::generateRealNumbersDataWrite() { QTest::addColumn<double>("number"); QTest::addColumn<QByteArray>("data"); + QTest::addColumn<QByteArray>("dataWithSeparators"); - QTest::newRow("0") << 0.0 << QByteArray("0"); - QTest::newRow("3.14") << 3.14 << QByteArray("3.14"); - QTest::newRow("-3.14") << -3.14 << QByteArray("-3.14"); - QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10"); - QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10"); + QTest::newRow("0") << 0.0 << QByteArray("0") << QByteArray("0"); + QTest::newRow("3.14") << 3.14 << QByteArray("3.14") << QByteArray("3.14"); + QTest::newRow("-3.14") << -3.14 << QByteArray("-3.14") << QByteArray("-3.14"); + QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10") << QByteArray("1.2e+10"); + QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10") << QByteArray("-1.2e+10"); + QTest::newRow("12345") << 12345. << QByteArray("12345") << QByteArray("12,345"); } // ------------------------------------------------------------------------------ @@ -2320,14 +2355,22 @@ void tst_QTextStream::generateRealNumbersDataWrite() { \ QFETCH(double, number); \ QFETCH(QByteArray, data); \ + QFETCH(QByteArray, dataWithSeparators); \ \ QBuffer buffer; \ buffer.open(QBuffer::WriteOnly); \ QTextStream stream(&buffer); \ + stream.setLocale(QLocale::c()); \ float f = (float)number; \ stream << f; \ stream.flush(); \ QCOMPARE(buffer.data().constData(), data.constData()); \ + \ + buffer.reset(); \ + stream.setLocale(QLocale("en-US")); \ + stream << f; \ + stream.flush(); \ + QCOMPARE(buffer.data(), dataWithSeparators); \ } IMPLEMENT_STREAM_LEFT_REAL_OPERATOR_TEST(float, float) IMPLEMENT_STREAM_LEFT_REAL_OPERATOR_TEST(double, float) diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index d5eab54363..ac4be31d0e 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -165,6 +165,8 @@ private slots: void binaryData(); void fromUserInput_data(); void fromUserInput(); + void fromUserInputWithCwd_data(); + void fromUserInputWithCwd(); void fileName_data(); void fileName(); void isEmptyForEncodedUrl(); @@ -235,6 +237,11 @@ void tst_QUrl::constructing() QVERIFY(url == url); QVERIFY(!(url < url)); + QUrl fromLocal = QUrl::fromLocalFile(QString()); + QVERIFY(!fromLocal.isValid()); + QVERIFY(fromLocal.isEmpty()); + QCOMPARE(fromLocal.toString(), QString()); + QUrl justHost("qt-project.org"); QVERIFY(!justHost.isEmpty()); QVERIFY(justHost.host().isEmpty()); @@ -2920,6 +2927,52 @@ void tst_QUrl::fromUserInput() QCOMPARE(url, guessUrlFromString); } +void tst_QUrl::fromUserInputWithCwd_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<QString>("directory"); + QTest::addColumn<QUrl>("guessedUrlDefault"); + QTest::addColumn<QUrl>("guessedUrlAssumeLocalFile"); + + // Null + QTest::newRow("null") << QString() << QString() << QUrl() << QUrl(); + + // Existing file + QDirIterator it(QDir::currentPath(), QDir::NoDotDot | QDir::AllEntries); + int c = 0; + while (it.hasNext()) { + it.next(); + QUrl url = QUrl::fromLocalFile(it.filePath()); + QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.fileName() << QDir::currentPath() << url << url; + } + QDir parent = QDir::current(); + QVERIFY(parent.cdUp()); + QUrl parentUrl = QUrl::fromLocalFile(parent.path()); + QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl; + + QTest::newRow("nonexisting") << "nonexisting" << QDir::currentPath() << QUrl("http://nonexisting") << QUrl::fromLocalFile(QDir::currentPath() + "/nonexisting"); + QTest::newRow("short-url") << "example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl::fromLocalFile(QDir::currentPath() + "/example.org"); + QTest::newRow("full-url") << "http://example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl("http://example.org"); + QTest::newRow("absolute") << "/doesnotexist.txt" << QDir::currentPath() << QUrl("file:///doesnotexist.txt") << QUrl("file:///doesnotexist.txt"); +#ifdef Q_OS_WIN + QTest::newRow("windows-absolute") << "c:/doesnotexist.txt" << QDir::currentPath() << QUrl("file:///c:/doesnotexist.txt") << QUrl("file:///c:/doesnotexist.txt"); +#endif +} + +void tst_QUrl::fromUserInputWithCwd() +{ + QFETCH(QString, string); + QFETCH(QString, directory); + QFETCH(QUrl, guessedUrlDefault); + QFETCH(QUrl, guessedUrlAssumeLocalFile); + + QUrl url = QUrl::fromUserInput(string, directory); + QCOMPARE(url, guessedUrlDefault); + + url = QUrl::fromUserInput(string, directory, QUrl::AssumeLocalFile); + QCOMPARE(url, guessedUrlAssumeLocalFile); +} + void tst_QUrl::fileName_data() { QTest::addColumn<QString>("urlStr"); diff --git a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp index 8321f76bec..16f94e7c5d 100644 --- a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp +++ b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp @@ -58,6 +58,7 @@ private slots: void readFile(); void waitForNotified_data(); void waitForNotified(); + void waitForAnyNotified(); void brokenPipe(); void multipleOperations(); @@ -195,6 +196,45 @@ void tst_QWinOverlappedIoNotifier::waitForNotified() QCOMPARE(notifier.waitForNotified(100, &overlapped), false); } +void tst_QWinOverlappedIoNotifier::waitForAnyNotified() +{ + const QString fileName = QDir::toNativeSeparators(sourceFileInfo.absoluteFilePath()); + const int readBufferSize = sourceFileInfo.size(); + + QWinOverlappedIoNotifier notifier; + HANDLE hFile = CreateFile(reinterpret_cast<const wchar_t*>(fileName.utf16()), + GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + notifier.setHandle(hFile); + notifier.setEnabled(true); + QVERIFY(notifier.waitForAnyNotified(100) == 0); + + OVERLAPPED overlapped1; + ZeroMemory(&overlapped1, sizeof(OVERLAPPED)); + QByteArray buffer1(readBufferSize, 0); + BOOL readSuccess = ReadFile(hFile, buffer1.data(), buffer1.size(), NULL, &overlapped1); + QVERIFY(readSuccess || GetLastError() == ERROR_IO_PENDING); + + OVERLAPPED overlapped2; + ZeroMemory(&overlapped2, sizeof(OVERLAPPED)); + QByteArray buffer2(readBufferSize, 0); + readSuccess = ReadFile(hFile, buffer2.data(), buffer2.size(), NULL, &overlapped2); + QVERIFY(readSuccess || GetLastError() == ERROR_IO_PENDING); + + QSet<OVERLAPPED *> overlappedObjects; + overlappedObjects << &overlapped1 << &overlapped2; + + for (int i = 1; i <= 2; ++i) { + OVERLAPPED *notifiedOverlapped = notifier.waitForAnyNotified(3000); + QVERIFY(overlappedObjects.contains(notifiedOverlapped)); + overlappedObjects.remove(notifiedOverlapped); + } + + CloseHandle(hFile); + QVERIFY(overlappedObjects.isEmpty()); + QVERIFY(notifier.waitForAnyNotified(100) == 0); +} + void tst_QWinOverlappedIoNotifier::brokenPipe() { QWinOverlappedIoNotifier notifier; |