diff options
Diffstat (limited to 'tests/auto/corelib')
76 files changed, 2008 insertions, 301 deletions
diff --git a/tests/auto/corelib/animation/qpauseanimation/BLACKLIST b/tests/auto/corelib/animation/qpauseanimation/BLACKLIST new file mode 100644 index 0000000000..3b2cd84749 --- /dev/null +++ b/tests/auto/corelib/animation/qpauseanimation/BLACKLIST @@ -0,0 +1,4 @@ +[multiplePauseAnimations] +osx-10.9 +[pauseAndPropertyAnimations] +* diff --git a/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST b/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST new file mode 100644 index 0000000000..a7e95b1e97 --- /dev/null +++ b/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST @@ -0,0 +1,4 @@ +[statesAndSignals:normal animation] +windows +[startBackwardWithoutEndValue] +windows diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST new file mode 100644 index 0000000000..e11e4ae6fb --- /dev/null +++ b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST @@ -0,0 +1,4 @@ +[startGroupWithRunningChild] +windows +[finishWithUncontrolledAnimation] +windows diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 69bf7598fc..00f70f5380 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -457,7 +457,7 @@ void tst_QGlobal::isEnum() // fallback type traits implementation. Any compiler // supported by Qt that supports C++0x class enums // should also support the __is_enum intrinsic. - QVERIFY(Q_IS_ENUM(isEnum_G) == true); + QVERIFY(Q_IS_ENUM(isEnum_G)); #endif #undef IS_ENUM_TRUE diff --git a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp index a1cfff7e85..e9fd999e9f 100644 --- a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp +++ b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp @@ -41,10 +41,17 @@ #include <QtCore/QThread> #include <QtTest/QtTest> +#if defined(Q_OS_UNIX) +#include <sys/resource.h> +#endif + class tst_QGlobalStatic : public QObject { Q_OBJECT +public Q_SLOTS: + void initTestCase(); + private Q_SLOTS: void beforeInitialization(); void api(); @@ -55,6 +62,20 @@ private Q_SLOTS: void afterDestruction(); }; +void tst_QGlobalStatic::initTestCase() +{ +#if defined(Q_OS_UNIX) + // The tests create a lot of threads, which require file descriptors. On systems like + // OS X low defaults such as 256 as the limit for the number of simultaneously + // open files is not sufficient. + struct rlimit numFiles; + if (getrlimit(RLIMIT_NOFILE, &numFiles) == 0 && numFiles.rlim_cur < 1024) { + numFiles.rlim_cur = qMin(rlim_t(1024), numFiles.rlim_max); + setrlimit(RLIMIT_NOFILE, &numFiles); + } +#endif +} + Q_GLOBAL_STATIC_WITH_ARGS(const int, constInt, (42)) Q_GLOBAL_STATIC_WITH_ARGS(volatile int, volatileInt, (-47)) diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 3e19e816c9..db2805ebf0 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -49,6 +49,7 @@ private slots: void debugWithBool() const; void debugSpaceHandling() const; void debugNoQuotes() const; + void verbosity() const; void stateSaver() const; void veryLongWarningMessage() const; void qDebugQChar() const; @@ -192,7 +193,11 @@ public: QDebug operator<< (QDebug s, const MyLine& line) { const QDebugStateSaver saver(s); - s.nospace() << "MyLine(" << line.p1 << ", " << line.p2 << ")"; + s.nospace(); + s << "MyLine(" << line.p1 << ", "<< line.p2; + if (s.verbosity() > 2) + s << ", Manhattan length=" << (qAbs(line.p2.v1 - line.p1.v1) + qAbs(line.p2.v2 - line.p1.v2)); + s << ')'; return s; } @@ -255,6 +260,33 @@ void tst_QDebug::debugNoQuotes() const QCOMPARE(s_msg, QString::fromLatin1("'H' \"Hello\" \"Hello\" H Hello Hello")); } +void tst_QDebug::verbosity() const +{ + MyLine line(MyPoint(10, 11), MyPoint (12, 13)); + QString output; + QDebug d(&output); + d.nospace(); + d << line << '\n'; + const int oldVerbosity = d.verbosity(); + d.setVerbosity(0); + QCOMPARE(d.verbosity(), 0); + d.setVerbosity(7); + QCOMPARE(d.verbosity(), 7); + const int newVerbosity = oldVerbosity + 2; + d.setVerbosity(newVerbosity); + QCOMPARE(d.verbosity(), newVerbosity); + d << line << '\n'; + d.setVerbosity(oldVerbosity ); + QCOMPARE(d.verbosity(), oldVerbosity ); + d << line; + const QStringList lines = output.split(QLatin1Char('\n')); + QCOMPARE(lines.size(), 3); + // Verbose should be longer + QVERIFY2(lines.at(1).size() > lines.at(0).size(), qPrintable(lines.join(QLatin1Char(',')))); + // Switching back to brief produces same output + QCOMPARE(lines.at(0).size(), lines.at(2).size()); +} + void tst_QDebug::stateSaver() const { MessageHandlerSetter mhs(myMessageHandler); diff --git a/tests/auto/corelib/io/qdir/qdir.pro b/tests/auto/corelib/io/qdir/qdir.pro index d3e954bd32..0adc7e0450 100644 --- a/tests/auto/corelib/io/qdir/qdir.pro +++ b/tests/auto/corelib/io/qdir/qdir.pro @@ -10,3 +10,5 @@ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 android:!android-no-sdk { RESOURCES += android_testdata.qrc } + +win32: CONFIG += insignificant_test # Crashes on Windows in release builds diff --git a/tests/auto/corelib/io/qdiriterator/qdiriterator.pro b/tests/auto/corelib/io/qdiriterator/qdiriterator.pro index 3b5d2bd931..a2429bf2f0 100644 --- a/tests/auto/corelib/io/qdiriterator/qdiriterator.pro +++ b/tests/auto/corelib/io/qdiriterator/qdiriterator.pro @@ -8,3 +8,5 @@ TESTDATA += entrylist wince*mips*|wincewm50smart-msvc200*: DEFINES += WINCE_BROKEN_ITERATE=1 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +win32: CONFIG += insignificant_test # Crashes on Windows in release builds diff --git a/tests/auto/corelib/io/qfileinfo/qfileinfo.pro b/tests/auto/corelib/io/qfileinfo/qfileinfo.pro index de99447404..571637be37 100644 --- a/tests/auto/corelib/io/qfileinfo/qfileinfo.pro +++ b/tests/auto/corelib/io/qfileinfo/qfileinfo.pro @@ -7,3 +7,5 @@ RESOURCES += qfileinfo.qrc \ win32:!wince:!winrt:LIBS += -ladvapi32 -lnetapi32 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +win32: CONFIG += insignificant_test # Crashes on Windows in release builds diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 96ad78a666..8d276b3616 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -287,7 +287,8 @@ void tst_QFileInfo::initTestCase() m_resourcesDir = dataPath + QLatin1String("/resources"); m_proFile = dataPath + QLatin1String("/tst_qfileinfo.pro"); - QVERIFY(m_dir.isValid()); + QVERIFY2(m_dir.isValid(), + ("Failed to create temporary dir: " + m_dir.errorString()).toUtf8()); QVERIFY(QDir::setCurrent(m_dir.path())); } diff --git a/tests/auto/corelib/io/qfileselector/platforms/+haiku/test b/tests/auto/corelib/io/qfileselector/platforms/+haiku/test new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+haiku/test diff --git a/tests/auto/corelib/io/qfileselector/platforms/+haiku/test2 b/tests/auto/corelib/io/qfileselector/platforms/+haiku/test2 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+haiku/test2 diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+haiku/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+haiku/test new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+haiku/test diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc index 661647f933..6e2699774d 100644 --- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc +++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc @@ -19,6 +19,7 @@ <file>platforms/+unix/+darwin/+mac/+osx/test</file> <file>platforms/+unix/+darwin/+mac/test</file> <file>platforms/+unix/+darwin/test</file> + <file>platforms/+unix/+haiku/test</file> <file>platforms/+unix/+linux/test</file> <file>platforms/+unix/test</file> <file>platforms/+windows/+wince/test</file> @@ -30,6 +31,7 @@ <file>platforms/+osx/test</file> <file>platforms/+darwin/test</file> <file>platforms/+mac/test</file> + <file>platforms/+haiku/test</file> <file>platforms/+linux/test</file> <file>platforms/+wince/test</file> @@ -39,6 +41,7 @@ <file>platforms/+blackberry/test2</file> <file>platforms/+ios/test2</file> <file>platforms/+osx/test2</file> + <file>platforms/+haiku/test2</file> <file>platforms/+linux/test2</file> <file>platforms/+wince/test2</file> <file>platforms/+winnt/test2</file> diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index b3767b4887..87381f4c4e 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -89,7 +89,7 @@ void tst_QFileSelector::basicTest_data() QString expectedPlatform2File(""); //Only the last selector QString expectedPlatform3File; // Only the first selector (the family) #if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && \ - !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) + !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) /* We are only aware of specific unixes, and do not have test files for any of the others. However those unixes can get a selector added from the result of a uname call, so this will lead to a case where we don't have that file so we can't expect the concatenation of platform diff --git a/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST b/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST index 3ac0b9dff4..10a4ba069e 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST +++ b/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST @@ -6,3 +6,4 @@ windows 64bit msvc osx [watchFileAndItsDirectory:native backend-specialchars] osx +windows diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 7e56ecaab3..a0434aa8ee 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -553,7 +553,7 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() timer.start(3000); eventLoop.exec(); int fileChangedSpyCount = fileChangedSpy.count(); -#ifdef Q_OS_WIN64 +#ifdef Q_OS_WIN if (fileChangedSpyCount != 0) QEXPECT_FAIL("", "See QTBUG-30943", Continue); #endif diff --git a/tests/auto/corelib/io/qiodevice/BLACKLIST b/tests/auto/corelib/io/qiodevice/BLACKLIST new file mode 100644 index 0000000000..b8a61d3ca9 --- /dev/null +++ b/tests/auto/corelib/io/qiodevice/BLACKLIST @@ -0,0 +1,2 @@ +[unget] +redhatenterpriselinuxworkstation-6.6 diff --git a/tests/auto/corelib/io/qprocess/BLACKLIST b/tests/auto/corelib/io/qprocess/BLACKLIST new file mode 100644 index 0000000000..dcd913ca49 --- /dev/null +++ b/tests/auto/corelib/io/qprocess/BLACKLIST @@ -0,0 +1,2 @@ +[lockupsInStartDetached] +redhatenterpriselinuxworkstation-6.6 diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 0995f764b7..caefc3fc21 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -124,9 +124,9 @@ private slots: void removeFileWhileProcessIsRunning(); void fileWriterProcess(); void switchReadChannels(); -#ifdef Q_OS_WIN + void discardUnwantedOutput(); void setWorkingDirectory(); -#endif // Q_OS_WIN + void setNonExistentWorkingDirectory(); #endif // not Q_OS_WINCE void exitStatus_data(); @@ -220,7 +220,6 @@ void tst_QProcess::getSetCheck() QCOMPARE(QProcess::ProcessChannel(QProcess::StandardError), obj1.readChannel()); } -//----------------------------------------------------------------------------- void tst_QProcess::constructing() { QProcess process; @@ -282,7 +281,6 @@ void tst_QProcess::simpleStart() QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning); } -//----------------------------------------------------------------------------- void tst_QProcess::startWithOpen() { QProcess p; @@ -300,7 +298,6 @@ void tst_QProcess::startWithOpen() QVERIFY(p.waitForFinished(5000)); } -//----------------------------------------------------------------------------- void tst_QProcess::startWithOldOpen() { // similar to the above, but we start with start() actually @@ -319,7 +316,6 @@ void tst_QProcess::startWithOldOpen() QVERIFY(p.waitForFinished(5000)); } -//----------------------------------------------------------------------------- void tst_QProcess::execute() { QCOMPARE(QProcess::execute("testProcessNormal/testProcessNormal", @@ -327,7 +323,6 @@ void tst_QProcess::execute() QCOMPARE(QProcess::execute("nonexistingexe"), -2); } -//----------------------------------------------------------------------------- void tst_QProcess::startDetached() { QProcess proc; @@ -339,7 +334,6 @@ void tst_QProcess::startDetached() QCOMPARE(QProcess::startDetached("nonexistingexe"), false); } -//----------------------------------------------------------------------------- void tst_QProcess::readFromProcess() { int lines = 0; @@ -349,7 +343,6 @@ void tst_QProcess::readFromProcess() } } -//----------------------------------------------------------------------------- void tst_QProcess::crashTest() { qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); @@ -362,11 +355,13 @@ void tst_QProcess::crashTest() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("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)); + QSignalSpy spy(process, &QProcess::errorOccurred); + QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy3(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); + QVERIFY(spy3.isValid()); QVERIFY(process->waitForFinished(30000)); @@ -374,7 +369,10 @@ void tst_QProcess::crashTest() QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); QCOMPARE(spy2.count(), 1); - QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); + + QCOMPARE(spy3.count(), 1); + QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy3.at(0).at(1).constData()), QProcess::CrashExit); QCOMPARE(process->exitStatus(), QProcess::CrashExit); @@ -387,7 +385,6 @@ void tst_QProcess::crashTest() QCOMPARE(qvariant_cast<QProcess::ProcessState>(stateSpy.at(2).at(0)), QProcess::NotRunning); } -//----------------------------------------------------------------------------- void tst_QProcess::crashTest2() { process = new QProcess; @@ -397,7 +394,7 @@ void tst_QProcess::crashTest2() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::errorOccurred)); QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spy.isValid()); @@ -423,7 +420,6 @@ void tst_QProcess::crashTest2() #ifndef Q_OS_WINCE //Reading and writing to a process is not supported on Qt/CE -//----------------------------------------------------------------------------- void tst_QProcess::echoTest_data() { QTest::addColumn<QByteArray>("input"); @@ -438,8 +434,6 @@ void tst_QProcess::echoTest_data() QTest::newRow("10000 bytes") << QByteArray(10000, '@'); } -//----------------------------------------------------------------------------- - void tst_QProcess::echoTest() { QFETCH(QByteArray, input); @@ -484,14 +478,11 @@ void tst_QProcess::echoTest() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::exitLoopSlot() { QTestEventLoop::instance().exitLoop(); } -//----------------------------------------------------------------------------- - #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::echoTest2() @@ -543,7 +534,6 @@ void tst_QProcess::echoTest2() #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Reading and writing to a process is not supported on Qt/CE -//----------------------------------------------------------------------------- void tst_QProcess::echoTestGui() { QProcess process; @@ -572,7 +562,6 @@ void tst_QProcess::testSetNamedPipeHandleState() } #endif // !Q_OS_WINCE && Q_OS_WIN -//----------------------------------------------------------------------------- #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Batch files are not supported on Windows CE void tst_QProcess::batFiles_data() @@ -601,7 +590,6 @@ void tst_QProcess::batFiles() } #endif // !Q_OS_WINCE && Q_OS_WIN -//----------------------------------------------------------------------------- void tst_QProcess::exitStatus_data() { QTest::addColumn<QStringList>("processList"); @@ -644,7 +632,7 @@ void tst_QProcess::exitStatus() process->deleteLater(); process = 0; } -//----------------------------------------------------------------------------- + #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::loopBackTest() @@ -670,7 +658,6 @@ void tst_QProcess::loopBackTest() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::readTimeoutAndThenCrash() @@ -688,8 +675,10 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(process->error(), QProcess::Timedout); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(process, &QProcess::errorOccurred); + QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QVERIFY(spy.isValid()); + QVERIFY(spy2.isValid()); process->kill(); @@ -698,6 +687,8 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(spy.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); + QCOMPARE(spy2.count(), 1); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); delete process; process = 0; @@ -750,7 +741,6 @@ void tst_QProcess::deadWhileReading() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::restartProcessDeadlock() @@ -780,7 +770,6 @@ void tst_QProcess::restartProcess() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::closeWriteChannel() @@ -808,7 +797,6 @@ void tst_QProcess::closeWriteChannel() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE" void tst_QProcess::closeReadChannel() @@ -840,7 +828,6 @@ void tst_QProcess::closeReadChannel() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::openModes() @@ -885,7 +872,6 @@ void tst_QProcess::openModes() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() @@ -921,7 +907,6 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::hardExit() { QProcess proc; @@ -945,7 +930,6 @@ void tst_QProcess::hardExit() QCOMPARE(int(proc.error()), int(QProcess::Crashed)); } -//----------------------------------------------------------------------------- void tst_QProcess::softExit() { QProcess proc; @@ -1055,7 +1039,6 @@ private: QByteArray dataToWrite; }; -//----------------------------------------------------------------------------- void tst_QProcess::softExitInSlots_data() { QTest::addColumn<QString>("appName"); @@ -1065,7 +1048,6 @@ void tst_QProcess::softExitInSlots_data() #endif QTest::newRow("console app") << "testProcessEcho2/testProcessEcho2"; } -//----------------------------------------------------------------------------- void tst_QProcess::softExitInSlots() { @@ -1081,7 +1063,6 @@ void tst_QProcess::softExitInSlots() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::mergedChannels() @@ -1106,7 +1087,6 @@ void tst_QProcess::mergedChannels() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE @@ -1161,7 +1141,6 @@ void tst_QProcess::forwardedChannels() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::atEnd() @@ -1222,7 +1201,6 @@ private: int exitCode; }; -//----------------------------------------------------------------------------- void tst_QProcess::processInAThread() { for (int i = 0; i < 10; ++i) { @@ -1233,7 +1211,6 @@ void tst_QProcess::processInAThread() } } -//----------------------------------------------------------------------------- void tst_QProcess::processesInMultipleThreads() { for (int i = 0; i < 10; ++i) { @@ -1258,7 +1235,6 @@ void tst_QProcess::processesInMultipleThreads() } } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForFinishedWithTimeout() @@ -1279,7 +1255,6 @@ void tst_QProcess::waitForFinishedWithTimeout() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlot() @@ -1308,7 +1283,6 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() @@ -1320,7 +1294,6 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() @@ -1347,7 +1320,6 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() @@ -1357,7 +1329,7 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() QTestEventLoop::instance().exitLoop(); } #endif -//----------------------------------------------------------------------------- + void tst_QProcess::spaceArgsTest_data() { QTest::addColumn<QStringList>("args"); @@ -1410,7 +1382,6 @@ static QByteArray startFailMessage(const QString &program, const QProcess &proce return result; } -//----------------------------------------------------------------------------- void tst_QProcess::spaceArgsTest() { QFETCH(QStringList, args); @@ -1483,7 +1454,6 @@ void tst_QProcess::spaceArgsTest() #if defined(Q_OS_WIN) -//----------------------------------------------------------------------------- void tst_QProcess::nativeArguments() { QProcess proc; @@ -1527,7 +1497,6 @@ void tst_QProcess::nativeArguments() #endif -//----------------------------------------------------------------------------- void tst_QProcess::exitCodeTest() { for (int i = 0; i < 255; ++i) { @@ -1544,7 +1513,6 @@ void tst_QProcess::exitCodeTest() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStart() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1556,12 +1524,14 @@ void tst_QProcess::failToStart() QProcess process; QSignalSpy stateSpy(&process, &QProcess::stateChanged); - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&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()); + QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); QVERIFY(finishedSpy2.isValid()); @@ -1578,6 +1548,7 @@ void tst_QProcess::failToStart() for (int j = 0; j < 8; ++j) { for (int i = 0; i < attempts; ++i) { QCOMPARE(errorSpy.count(), j * attempts + i); + QCOMPARE(errorSpy2.count(), j * attempts + i); process.start("/blurp"); switch (j) { @@ -1602,6 +1573,7 @@ void tst_QProcess::failToStart() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), j * attempts + i + 1); + QCOMPARE(errorSpy2.count(), j * attempts + i + 1); QCOMPARE(finishedSpy.count(), 0); QCOMPARE(finishedSpy2.count(), 0); @@ -1614,7 +1586,6 @@ void tst_QProcess::failToStart() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStartWithWait() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1625,11 +1596,13 @@ void tst_QProcess::failToStartWithWait() QProcess process; QEventLoop loop; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&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(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); QVERIFY(finishedSpy2.isValid()); @@ -1639,12 +1612,12 @@ void tst_QProcess::failToStartWithWait() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); + QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); QCOMPARE(finishedSpy2.count(), 0); } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStartWithEventLoop() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1655,16 +1628,18 @@ void tst_QProcess::failToStartWithEventLoop() QProcess process; QEventLoop loop; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&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(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); QVERIFY(finishedSpy2.isValid()); // The error signal may be emitted before start() returns - connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()), Qt::QueuedConnection); + connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection); for (int i = 0; i < 50; ++i) { @@ -1674,6 +1649,7 @@ void tst_QProcess::failToStartWithEventLoop() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); + QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); QCOMPARE(finishedSpy2.count(), 0); } @@ -1715,7 +1691,6 @@ void tst_QProcess::failToStartEmptyArgs() QCOMPARE(process.error(), QProcess::FailedToStart); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::removeFileWhileProcessIsRunning() @@ -1734,7 +1709,6 @@ void tst_QProcess::removeFileWhileProcessIsRunning() QVERIFY(process.waitForFinished(5000)); } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // OS doesn't support environment variables void tst_QProcess::setEnvironment_data() @@ -1812,7 +1786,6 @@ void tst_QProcess::setEnvironment() } } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // OS doesn't support environment variables void tst_QProcess::setProcessEnvironment_data() @@ -1853,7 +1826,7 @@ void tst_QProcess::setProcessEnvironment() } } #endif -//----------------------------------------------------------------------------- + void tst_QProcess::systemEnvironment() { #if defined (Q_OS_WINCE) @@ -1869,7 +1842,6 @@ void tst_QProcess::systemEnvironment() #endif } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::spaceInName() @@ -1882,7 +1854,6 @@ void tst_QProcess::spaceInName() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::lockupsInStartDetached() { // Check that QProcess doesn't cause a lock up at this program's @@ -1896,7 +1867,6 @@ void tst_QProcess::lockupsInStartDetached() QProcess::startDetached("yjhbrty"); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::atEnd2() @@ -1915,7 +1885,6 @@ void tst_QProcess::atEnd2() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::waitForReadyReadForNonexistantProcess() { // Start a program that doesn't exist, process events and then try to waitForReadyRead @@ -1923,11 +1892,13 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); QProcess process; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&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(errorSpy2.isValid()); QVERIFY(finishedSpy1.isValid()); QVERIFY(finishedSpy2.isValid()); @@ -1939,11 +1910,12 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() #endif QCOMPARE(errorSpy.count(), 1); QCOMPARE(errorSpy.at(0).at(0).toInt(), 0); + QCOMPARE(errorSpy2.count(), 1); + QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0); QCOMPARE(finishedSpy1.count(), 0); QCOMPARE(finishedSpy2.count(), 0); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardInputFile() @@ -1973,7 +1945,6 @@ void tst_QProcess::setStandardInputFile() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputFile_data() @@ -2004,7 +1975,6 @@ void tst_QProcess::setStandardOutputFile_data() << true; } -//----------------------------------------------------------------------------- void tst_QProcess::setStandardOutputFile() { static const char data[] = "Original data. "; @@ -2089,7 +2059,6 @@ void tst_QProcess::setStandardOutputFileAndWaitForBytesWritten() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputProcess_data() @@ -2130,7 +2099,6 @@ void tst_QProcess::setStandardOutputProcess() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::fileWriterProcess() @@ -2158,7 +2126,6 @@ void tst_QProcess::fileWriterProcess() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::detachedWorkingDirectoryAndPid() { qint64 pid; @@ -2202,7 +2169,6 @@ void tst_QProcess::detachedWorkingDirectoryAndPid() QCOMPARE(actualPid, pid); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::switchReadChannels() @@ -2233,16 +2199,38 @@ void tst_QProcess::switchReadChannels() } #endif -//----------------------------------------------------------------------------- -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#ifndef Q_OS_WINCE +// Reading and writing to a process is not supported on Qt/CE +void tst_QProcess::discardUnwantedOutput() +{ + QProcess process; + + process.setProgram("testProcessEcho2/testProcessEcho2"); + process.start(QIODevice::WriteOnly); + process.write("Hello, World"); + process.closeWriteChannel(); + QVERIFY(process.waitForFinished(5000)); + + process.setReadChannel(QProcess::StandardOutput); + QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); + process.setReadChannel(QProcess::StandardError); + QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); +} +#endif + +#ifndef Q_OS_WINCE // Q_OS_WIN - setWorkingDirectory will chdir before starting the process on unices // Windows CE does not support working directory logic void tst_QProcess::setWorkingDirectory() { process = new QProcess; process->setWorkingDirectory("test"); - process->start("testSetWorkingDirectory/testSetWorkingDirectory"); - QVERIFY(process->waitForFinished()); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + + QVERIFY2(process->waitForFinished(), process->errorString().toLocal8Bit()); QByteArray workingDir = process->readAllStandardOutput(); QCOMPARE(QDir("test").canonicalPath(), QDir(workingDir.constData()).canonicalPath()); @@ -2250,9 +2238,26 @@ void tst_QProcess::setWorkingDirectory() delete process; process = 0; } + +void tst_QProcess::setNonExistentWorkingDirectory() +{ + process = new QProcess; + process->setWorkingDirectory("this/directory/should/not/exist/for/sure"); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + QVERIFY(!process->waitForFinished()); +#ifdef QPROCESS_USE_SPAWN + QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); +#endif + QCOMPARE(int(process->error()), int(QProcess::FailedToStart)); + + delete process; + process = 0; +} #endif -//----------------------------------------------------------------------------- void tst_QProcess::startFinishStartFinish() { QProcess process; @@ -2271,7 +2276,6 @@ void tst_QProcess::startFinishStartFinish() } } -//----------------------------------------------------------------------------- void tst_QProcess::invalidProgramString_data() { QTest::addColumn<QString>("programString"); @@ -2286,17 +2290,19 @@ void tst_QProcess::invalidProgramString() QProcess process; qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(&process, &QProcess::errorOccurred); + QSignalSpy spy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QVERIFY(spy.isValid()); + QVERIFY(spy2.isValid()); process.start(programString); QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(spy.count(), 1); + QCOMPARE(spy2.count(), 1); QVERIFY(!QProcess::startDetached(programString)); } -//----------------------------------------------------------------------------- void tst_QProcess::onlyOneStartedSignal() { qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); @@ -2323,8 +2329,6 @@ void tst_QProcess::onlyOneStartedSignal() QCOMPARE(spyFinished.count(), 1); } -//----------------------------------------------------------------------------- - class BlockOnReadStdOut : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp b/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp index be9a38c499..2099101a91 100644 --- a/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp +++ b/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp @@ -66,11 +66,19 @@ void tst_QProcessEnvironment::operator_eq() QVERIFY(e1 == e2); e1.clear(); - QVERIFY(e1 != e2); + QVERIFY(e1 == e2); e2.clear(); + QVERIFY(e1 == e2); + + e1.insert("FOO", "bar"); + QVERIFY(e1 != e2); + e2.insert("FOO", "bar"); QVERIFY(e1 == e2); + + e2.insert("FOO", "baz"); + QVERIFY(e1 != e2); } void tst_QProcessEnvironment::clearAndIsEmpty() @@ -196,6 +204,15 @@ void tst_QProcessEnvironment::insertEnv() QCOMPARE(e.value("Hello"), QString("Another World")); QCOMPARE(e.value("FOO2"), QString("bar2")); QCOMPARE(e.value("A2"), QString("bc2")); + + QProcessEnvironment e3; + e3.insert("FOO2", "bar2"); + e3.insert("A2", "bc2"); + e3.insert("Hello", "Another World"); + + e3.insert(e3); // mustn't deadlock + + QVERIFY(e3 == e2); } void tst_QProcessEnvironment::caseSensitivity() diff --git a/tests/auto/corelib/io/qsettings/BLACKLIST b/tests/auto/corelib/io/qsettings/BLACKLIST new file mode 100644 index 0000000000..1cba99b66c --- /dev/null +++ b/tests/auto/corelib/io/qsettings/BLACKLIST @@ -0,0 +1,2 @@ +[isWritable:native] +osx-10.10 diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 3e98a369ce..58a3db9615 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -93,6 +93,7 @@ void tst_QTemporaryDir::construction() QCOMPARE(dir.path().left(tmp.size()), tmp); QVERIFY(dir.path().contains("tst_qtemporarydir")); QVERIFY(QFileInfo(dir.path()).isDir()); + QCOMPARE(dir.errorString(), QString()); } // Testing get/set functions @@ -251,6 +252,7 @@ void tst_QTemporaryDir::nonWritableCurrentDir() QTemporaryDir dir("tempXXXXXX"); dir.setAutoRemove(true); QVERIFY(!dir.isValid()); + QVERIFY(!dir.errorString().isEmpty()); QVERIFY(dir.path().isEmpty()); #endif } @@ -287,7 +289,11 @@ void tst_QTemporaryDir::stressTest() for (int i = 0; i < iterations; ++i) { QTemporaryDir dir(pattern); dir.setAutoRemove(false); - QVERIFY2(dir.isValid(), qPrintable(QString::fromLatin1("Failed to create #%1 under %2.").arg(i).arg(QDir::toNativeSeparators(pattern)))); + QVERIFY2(dir.isValid(), + qPrintable(QString::fromLatin1("Failed to create #%1 under %2: %3.") + .arg(i) + .arg(QDir::toNativeSeparators(pattern)) + .arg(dir.errorString()))); QVERIFY(!names.contains(dir.path())); names.insert(dir.path()); } diff --git a/tests/auto/corelib/io/qtextstream/BLACKLIST b/tests/auto/corelib/io/qtextstream/BLACKLIST new file mode 100644 index 0000000000..bc3f118b33 --- /dev/null +++ b/tests/auto/corelib/io/qtextstream/BLACKLIST @@ -0,0 +1,2 @@ +[stillOpenWhenAtEnd] +windows diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp index db0136dd20..769a96ac64 100644 --- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp +++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp @@ -177,6 +177,7 @@ void tst_QUrlQuery::constructing() QVERIFY(copy.isEmpty()); QVERIFY(!copy.isDetached()); QVERIFY(copy == empty); + QCOMPARE(qHash(copy), qHash(empty)); QVERIFY(!(copy != empty)); copy = empty; @@ -184,6 +185,7 @@ void tst_QUrlQuery::constructing() copy = QUrlQuery(); QVERIFY(copy == empty); + QCOMPARE(qHash(copy), qHash(empty)); } { QUrlQuery copy(emptyQuery()); @@ -298,6 +300,7 @@ void tst_QUrlQuery::addRemove() QVERIFY(query == original); QVERIFY(!(query != original)); + QCOMPARE(qHash(query), qHash(original)); } { diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 64170b15dd..c4d2df7c3e 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -379,7 +379,7 @@ void tst_QAbstractItemModel::hasChildren() { QtTestModel model(1, 1); QModelIndex idx = model.index(0, 0, QModelIndex()); - QVERIFY(model.hasChildren(idx) == false); + QVERIFY(!model.hasChildren(idx)); } void tst_QAbstractItemModel::data() diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 8d331389f5..23cd254477 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -1530,7 +1530,7 @@ void tst_QItemSelectionModel::resetModel() model.reset(); QVERIFY(selectionModel->selection().isEmpty()); - QVERIFY(selectionModel->hasSelection() == false); + QVERIFY(!selectionModel->hasSelection()); selectionModel->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 1c30adc8de..0302ae5cbf 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -87,6 +87,7 @@ private slots: void filter_qtbug30662(); void changeSourceLayout(); + void changeSourceLayoutFilteredOut(); void removeSourceRows_data(); void removeSourceRows(); void insertSourceRows_data(); @@ -1533,6 +1534,32 @@ void tst_QSortFilterProxyModel::changeSourceLayout() } } +void tst_QSortFilterProxyModel::changeSourceLayoutFilteredOut() +{ + QStandardItemModel model(2, 1); + model.setData(model.index(0, 0), QString("b")); + model.setData(model.index(1, 0), QString("a")); + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + + int beforeSortFilter = proxy.rowCount(); + + QSignalSpy removeSpy(&proxy, &QSortFilterProxyModel::rowsRemoved); + // Filter everything out + proxy.setFilterRegExp(QRegExp("c")); + QCOMPARE(removeSpy.count(), 1); + QCOMPARE(0, proxy.rowCount()); + + // change layout of source model + model.sort(0, Qt::AscendingOrder); + + QSignalSpy insertSpy(&proxy, &QSortFilterProxyModel::rowsInserted); + // Remove filter; we expect an insert + proxy.setFilterRegExp(QRegExp("")); + QCOMPARE(insertSpy.count(), 1); + QCOMPARE(beforeSortFilter, proxy.rowCount()); +} + void tst_QSortFilterProxyModel::removeSourceRows_data() { QTest::addColumn<QStringList>("sourceItems"); diff --git a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro index 0602b9fc38..1039f2c08d 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro +++ b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro @@ -3,3 +3,4 @@ TARGET = tst_qcoreapplication QT = core testlib core-private SOURCES = tst_qcoreapplication.cpp HEADERS = tst_qcoreapplication.h +requires(contains(QT_CONFIG,private_tests)) diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index efecf31d66..060ef99d65 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -78,6 +78,21 @@ public: } }; +class Thread : public QDaemonThread +{ + void run() Q_DECL_OVERRIDE + { + QThreadData *data = QThreadData::current(); + QVERIFY(!data->requiresCoreApplication); // daemon thread + data->requiresCoreApplication = requiresCoreApplication; + QThread::run(); + } + +public: + Thread() : requiresCoreApplication(true) {} + bool requiresCoreApplication; +}; + void tst_QCoreApplication::sendEventsOnProcessEvents() { int argc = 1; @@ -853,6 +868,68 @@ void tst_QCoreApplication::applicationEventFilters_auxThread() QVERIFY(!spy.recordedEvents.contains(QEvent::User + 1)); } +void tst_QCoreApplication::threadedEventDelivery_data() +{ + QTest::addColumn<bool>("requiresCoreApplication"); + QTest::addColumn<bool>("createCoreApplication"); + QTest::addColumn<bool>("eventsReceived"); + + // invalid combination: + //QTest::newRow("default-without-coreapp") << true << false << false; + QTest::newRow("default") << true << true << true; + QTest::newRow("independent-without-coreapp") << false << false << true; + QTest::newRow("independent-with-coreapp") << false << true << true; +} + +// posts the event before the QCoreApplication is destroyed, starts thread after +void tst_QCoreApplication::threadedEventDelivery() +{ + QFETCH(bool, requiresCoreApplication); + QFETCH(bool, createCoreApplication); + QFETCH(bool, eventsReceived); + + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + QScopedPointer<TestApplication> app(createCoreApplication ? new TestApplication(argc, argv) : 0); + + Thread thread; + thread.requiresCoreApplication = requiresCoreApplication; + ThreadedEventReceiver receiver; + receiver.moveToThread(&thread); + QCoreApplication::postEvent(&receiver, new QEvent(QEvent::Type(QEvent::User + 1))); + + thread.start(); + QVERIFY(thread.wait(1000)); + QCOMPARE(receiver.recordedEvents.contains(QEvent::User + 1), eventsReceived); +} + +void tst_QCoreApplication::addRemoveLibPaths() +{ + QStringList paths = QCoreApplication::libraryPaths(); + if (paths.isEmpty()) + QSKIP("Cannot add/remove library paths if there are none."); + + QString currentDir = QDir().absolutePath(); + QCoreApplication::addLibraryPath(currentDir); + QVERIFY(QCoreApplication::libraryPaths().contains(currentDir)); + + QCoreApplication::removeLibraryPath(paths[0]); + QVERIFY(!QCoreApplication::libraryPaths().contains(paths[0])); + + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + TestApplication app(argc, argv); + + // Check that modifications stay alive across the creation of an application. + QVERIFY(QCoreApplication::libraryPaths().contains(currentDir)); + QVERIFY(!QCoreApplication::libraryPaths().contains(paths[0])); + + QStringList replace; + replace << currentDir << paths[0]; + QCoreApplication::setLibraryPaths(replace); + QVERIFY(QCoreApplication::libraryPaths() == replace); +} + static void createQObjectOnDestruction() { // Make sure that we can create a QObject after the last QObject has been diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h index 09e15723ac..d9296b3846 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -61,6 +61,9 @@ private slots: void QTBUG31606_QEventDestructorDeadLock(); void applicationEventFilters_mainThread(); void applicationEventFilters_auxThread(); + void threadedEventDelivery_data(); + void threadedEventDelivery(); + void addRemoveLibPaths(); }; #endif // TST_QCOREAPPLICATION_H diff --git a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST new file mode 100644 index 0000000000..00be65751b --- /dev/null +++ b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST @@ -0,0 +1,4 @@ +[sendPostedEvents] +windows +[registerTimer] +windows diff --git a/tests/auto/corelib/kernel/qeventloop/BLACKLIST b/tests/auto/corelib/kernel/qeventloop/BLACKLIST new file mode 100644 index 0000000000..6ea6314b0a --- /dev/null +++ b/tests/auto/corelib/kernel/qeventloop/BLACKLIST @@ -0,0 +1,2 @@ +[testQuitLock] +windows diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index a18c9eb370..4d54aa4dc8 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -46,6 +46,7 @@ class tst_QMetaProperty : public QObject Q_PROPERTY(int value8 READ value8) Q_PROPERTY(int value9 READ value9 CONSTANT) Q_PROPERTY(int value10 READ value10 FINAL) + Q_PROPERTY(QMap<int, int> map MEMBER map) private slots: void hasStdCppSet(); @@ -53,6 +54,7 @@ private slots: void isFinal(); void gadget(); void readAndWriteWithLazyRegistration(); + void mapProperty(); public: enum EnumType { EnumType1 }; @@ -65,6 +67,8 @@ public: int value8() const { return 1; } int value9() const { return 1; } int value10() const { return 1; } + + QMap<int, int> map; }; void tst_QMetaProperty::hasStdCppSet() @@ -182,6 +186,14 @@ void tst_QMetaProperty::readAndWriteWithLazyRegistration() QCOMPARE(o.property("write").value<CustomWriteObjectChild*>(), &data); } +void tst_QMetaProperty::mapProperty() +{ + map.insert(5, 9); + QVariant v1 = QVariant::fromValue(map); + QVariant v = property("map"); + QVERIFY(v.isValid()); + QCOMPARE(map, (v.value<QMap<int,int> >())); +} QTEST_MAIN(tst_QMetaProperty) #include "tst_qmetaproperty.moc" diff --git a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp index 01bf16c295..d368d9961b 100644 --- a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp +++ b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp @@ -70,7 +70,7 @@ void tst_QMimeData::clear() const mimeData.setData("text/plain", "pirates"); QVERIFY(mimeData.hasText()); mimeData.clear(); - QVERIFY(mimeData.hasText() == false); + QVERIFY(!mimeData.hasText()); // repopulate, verify not empty mimeData.setData("text/plain", "pirates"); @@ -136,7 +136,7 @@ void tst_QMimeData::hasColor() const QMimeData mimeData; // initial state - QVERIFY(mimeData.hasColor() == false); + QVERIFY(!mimeData.hasColor()); // set, verify mimeData.setColorData(QColor(Qt::red)); @@ -144,11 +144,11 @@ void tst_QMimeData::hasColor() const // clear, verify mimeData.clear(); - QVERIFY(mimeData.hasColor() == false); + QVERIFY(!mimeData.hasColor()); // set something else, verify mimeData.setData("text/plain", "pirates"); - QVERIFY(mimeData.hasColor() == false); + QVERIFY(!mimeData.hasColor()); } void tst_QMimeData::hasFormat() const @@ -156,17 +156,17 @@ void tst_QMimeData::hasFormat() const QMimeData mimeData; // initial state - QVERIFY(mimeData.hasFormat("text/plain") == false); + QVERIFY(!mimeData.hasFormat("text/plain")); // add, verify mimeData.setData("text/plain", "pirates"); QVERIFY(mimeData.hasFormat("text/plain")); - QVERIFY(mimeData.hasFormat("text/html") == false); + QVERIFY(!mimeData.hasFormat("text/html")); // clear, verify mimeData.clear(); - QVERIFY(mimeData.hasFormat("text/plain") == false); - QVERIFY(mimeData.hasFormat("text/html") == false); + QVERIFY(!mimeData.hasFormat("text/plain")); + QVERIFY(!mimeData.hasFormat("text/html")); } void tst_QMimeData::hasHtml() const @@ -174,11 +174,11 @@ void tst_QMimeData::hasHtml() const QMimeData mimeData; // initial state - QVERIFY(mimeData.hasHtml() == false); + QVERIFY(!mimeData.hasHtml()); // add plain, verify false mimeData.setData("text/plain", "pirates"); - QVERIFY(mimeData.hasHtml() == false); + QVERIFY(!mimeData.hasHtml()); // add html, verify mimeData.setData("text/html", "ninjas"); @@ -186,7 +186,7 @@ void tst_QMimeData::hasHtml() const // clear, verify mimeData.clear(); - QVERIFY(mimeData.hasHtml() == false); + QVERIFY(!mimeData.hasHtml()); // readd, verify mimeData.setData("text/html", "ninjas"); @@ -198,11 +198,11 @@ void tst_QMimeData::hasImage() const QMimeData mimeData; // initial state - QVERIFY(mimeData.hasImage() == false); + QVERIFY(!mimeData.hasImage()); // add text, verify false mimeData.setData("text/plain", "pirates"); - QVERIFY(mimeData.hasImage() == false); + QVERIFY(!mimeData.hasImage()); // add image mimeData.setImageData(QImage()); @@ -210,7 +210,7 @@ void tst_QMimeData::hasImage() const // clear, verify mimeData.clear(); - QVERIFY(mimeData.hasImage() == false); + QVERIFY(!mimeData.hasImage()); } void tst_QMimeData::imageData() const @@ -244,13 +244,13 @@ void tst_QMimeData::removeFormat() const // remove, verify mimeData.removeFormat("text/plain"); - QVERIFY(mimeData.hasFormat("text/plain") == false); + QVERIFY(!mimeData.hasFormat("text/plain")); QVERIFY(mimeData.hasFormat("text/html")); // remove, verify mimeData.removeFormat("text/html"); - QVERIFY(mimeData.hasFormat("text/plain") == false); - QVERIFY(mimeData.hasFormat("text/html") == false); + QVERIFY(!mimeData.hasFormat("text/plain")); + QVERIFY(!mimeData.hasFormat("text/html")); } void tst_QMimeData::setHtml() const @@ -258,7 +258,7 @@ void tst_QMimeData::setHtml() const QMimeData mimeData; // initial state - QVERIFY(mimeData.hasHtml() == false); + QVERIFY(!mimeData.hasHtml()); // add html, verify mimeData.setHtml("ninjas"); @@ -277,7 +277,7 @@ void tst_QMimeData::setText() const // verify initial state QCOMPARE(mimeData.text(), QLatin1String("")); - QVERIFY(mimeData.hasText() == false); + QVERIFY(!mimeData.hasText()); // set, verify mimeData.setText("pirates"); @@ -294,7 +294,7 @@ void tst_QMimeData::setText() const // clear, verify mimeData.clear(); QCOMPARE(mimeData.text(), QLatin1String("")); - QVERIFY(mimeData.hasText() == false); + QVERIFY(!mimeData.hasText()); } // Publish retrieveData for verifying content validity diff --git a/tests/auto/corelib/kernel/qobject/BLACKLIST b/tests/auto/corelib/kernel/qobject/BLACKLIST new file mode 100644 index 0000000000..0887a73b4c --- /dev/null +++ b/tests/auto/corelib/kernel/qobject/BLACKLIST @@ -0,0 +1,2 @@ +[moveToThread] +windows diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp index 814c4bb691..d7cce4ada4 100644 --- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp +++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp @@ -50,6 +50,7 @@ private slots: void destructor(); void assignment_operators(); void equality_operators(); + void swap(); void isNull(); void dereference_operators(); void disconnect(); @@ -169,6 +170,22 @@ void tst_QPointer::equality_operators() #endif } +void tst_QPointer::swap() +{ + QPointer<QObject> c1, c2; + { + QObject o; + c1 = &o; + QVERIFY(c2.isNull()); + QCOMPARE(c1.data(), &o); + c1.swap(c2); + QVERIFY(c1.isNull()); + QCOMPARE(c2.data(), &o); + } + QVERIFY(c1.isNull()); + QVERIFY(c2.isNull()); +} + void tst_QPointer::isNull() { QPointer<QObject> p1; diff --git a/tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST b/tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST new file mode 100644 index 0000000000..e68bf84268 --- /dev/null +++ b/tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST @@ -0,0 +1,3 @@ +[unexpectedDisconnection] +windows +osx diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 1d1432f600..1dc358bd97 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -440,6 +440,9 @@ void tst_QTimer::deleteLaterOnQTimer() void tst_QTimer::moveToThread() { +#if defined(Q_OS_WIN32) + QSKIP("Does not work reliably on Windows :("); +#endif QTimer ti1; QTimer ti2; ti1.start(MOVETOTHREAD_TIMEOUT); diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index a192ccde59..6da8f55e61 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -3357,9 +3357,6 @@ void tst_QVariant::numericalConvert_data() void tst_QVariant::numericalConvert() { -#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__) - QSKIP("Known to fail due to a GCC bug on at least Ubuntu 10.04 32-bit - check QTBUG-8959"); -#endif QFETCH(QVariant, v); QFETCH(bool, isInteger); double num = isInteger ? 5 : 5.3; diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 8bc90d917e..dd04849f87 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -35,6 +35,7 @@ #include "qstandardpaths.h" +#include <QtCore/QElapsedTimer> #include <QtCore/QFile> #include <QtCore/QFileInfo> #include <QtCore/QStandardPaths> @@ -129,7 +130,8 @@ void tst_QMimeDatabase::initTestCase() #ifdef USE_XDG_DATA_DIRS // Create a temporary "global" XDG data dir for later use // It will initially contain a copy of freedesktop.org.xml - QVERIFY(m_temporaryDir.isValid()); + QVERIFY2(m_temporaryDir.isValid(), + ("Could not create temporary subdir: " + m_temporaryDir.errorString()).toUtf8()); const QDir here = QDir(m_temporaryDir.path()); m_globalXdgDir = m_temporaryDir.path() + QStringLiteral("/global"); const QString globalPackageDir = m_globalXdgDir + QStringLiteral("/mime/packages"); @@ -818,16 +820,20 @@ static bool runUpdateMimeDatabase(const QString &path) // TODO make it a QMimeDa return false; } + QElapsedTimer timer; QProcess proc; proc.setProcessChannelMode(QProcess::MergedChannels); // silence output + qDebug().noquote() << "runUpdateMimeDatabase: running" << umd << path << "..."; + timer.start(); proc.start(umd, QStringList(path)); if (!proc.waitForStarted()) { qWarning("Cannot start %s: %s", qPrintable(umd), qPrintable(proc.errorString())); return false; } - proc.waitForFinished(); - //qDebug() << "runUpdateMimeDatabase" << path; + const bool success = proc.waitForFinished(); + qDebug().noquote() << "runUpdateMimeDatabase: done," + << success << timer.elapsed() << "ms"; return true; } diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index bdbb291d7f..72bd38d116 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -120,6 +120,7 @@ private slots: void loadGarbage(); #endif void relativePath(); + void absolutePath(); void reloadPlugin(); void preloadedPlugin_data(); void preloadedPlugin(); @@ -311,7 +312,7 @@ void tst_QPluginLoader::loadCorruptElf() void tst_QPluginLoader::loadMachO_data() { -#ifdef Q_OF_MACH_O +#if defined(QT_BUILD_INTERNAL) && defined(Q_OF_MACH_O) QTest::addColumn<int>("parseResult"); QTest::newRow("/dev/null") << int(QMachOParser::NotSuitable); @@ -347,7 +348,7 @@ void tst_QPluginLoader::loadMachO_data() void tst_QPluginLoader::loadMachO() { -#ifdef Q_OF_MACH_O +#if defined(QT_BUILD_INTERNAL) && defined(Q_OF_MACH_O) QFile f(QFINDTESTDATA(QTest::currentDataTag())); QVERIFY(f.open(QIODevice::ReadOnly)); QByteArray data = f.readAll(); @@ -406,6 +407,20 @@ void tst_QPluginLoader::relativePath() QVERIFY(loader.unload()); } +void tst_QPluginLoader::absolutePath() +{ + // Windows binaries run from release and debug subdirs, so we can't rely on the current dir. + const QString binDir = QFINDTESTDATA("bin"); + QVERIFY(!binDir.isEmpty()); + QVERIFY(QDir::isAbsolutePath(binDir)); + QPluginLoader loader(binDir + "/theplugin"); + loader.load(); // not recommended, instance() should do the job. + PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance()); + QVERIFY(instance); + QCOMPARE(instance->pluginName(), QLatin1String("Plugin ok")); + QVERIFY(loader.unload()); +} + void tst_QPluginLoader::reloadPlugin() { QPluginLoader loader; diff --git a/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp b/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp index ac3374b6a3..c64d55671a 100644 --- a/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp +++ b/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp @@ -47,6 +47,7 @@ private slots: void historyInitialState(); void transitions(); void privateSignals(); + void parallelStateAndInitialState(); }; class TestClass: public QObject @@ -344,5 +345,35 @@ void tst_QState::privateSignals() } +void tst_QState::parallelStateAndInitialState() +{ + QStateMachine machine; + + { // setting an initial state on a parallel state: + QState a(QState::ParallelStates, &machine); + QState b(&a); + QVERIFY(!a.initialState()); + const QString warning + = QString::asprintf("QState::setInitialState: ignoring attempt to set initial state of parallel state group %p", &a); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + a.setInitialState(&b); // should produce a warning and do nothing. + QVERIFY(!a.initialState()); + } + + { // setting the child-mode from ExclusiveStates to ParallelStates should remove the initial state: + QState a(QState::ExclusiveStates, &machine); + QState b(&a); + a.setInitialState(&b); + QCOMPARE(a.initialState(), &b); + const QString warning + = QString::asprintf("QState::setChildMode: setting the child-mode of state %p to " + "parallel removes the initial state", &a); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + a.setChildMode(QState::ParallelStates); // should produce a warning and remove the initial state + QVERIFY(!a.initialState()); + QCOMPARE(a.childMode(), QState::ParallelStates); + } +} + QTEST_MAIN(tst_QState) #include "tst_qstate.moc" diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 1292c3b98f..28df7cce7b 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -250,6 +250,7 @@ private slots: void internalTransition(); void conflictingTransition(); void qtbug_46059(); + void qtbug_46703(); }; class TestState : public QState @@ -265,7 +266,7 @@ public: TestState(ChildMode mode, const QString &objectName = QString()) : QState(mode) { setObjectName(objectName); } - QList<QPair<int, Event> > events; + QVector<QPair<int, Event> > events; protected: virtual void onEntry(QEvent *) { events.append(qMakePair(globalTick++, Entry)); @@ -281,7 +282,7 @@ public: TestTransition(QAbstractState *target, const QString &objectName = QString()) : QAbstractTransition() { setTargetState(target); setObjectName(objectName); } - QList<int> triggers; + QVector<int> triggers; protected: virtual bool eventTest(QEvent *) { return true; @@ -4860,7 +4861,7 @@ public: signalList.append(signal); } - QList<QMetaMethod> signalList; + QVector<QMetaMethod> signalList; }; void tst_QStateMachine::testIncrementReceivers() @@ -6485,5 +6486,59 @@ void tst_QStateMachine::qtbug_46059() QVERIFY(machine.isRunning()); } +void tst_QStateMachine::qtbug_46703() +{ + QStateMachine machine; + QState root(&machine); + QHistoryState h(&root); + QState p(QState::ParallelStates, &root); + QState a(&p); + QState a1(&a); + QState a2(&a); + QState a3(&a); + QState b(&p); + QState b1(&b); + QState b2(&b); + + machine.setObjectName("machine"); + root.setObjectName("root"); + h.setObjectName("h"); + p.setObjectName("p"); + a.setObjectName("a"); + a1.setObjectName("a1"); + a2.setObjectName("a2"); + a3.setObjectName("a3"); + b.setObjectName("b"); + b1.setObjectName("b1"); + b2.setObjectName("b2"); + + machine.setInitialState(&root); + root.setInitialState(&h); + a.setInitialState(&a3); + b.setInitialState(&b1); + struct : public QAbstractTransition { + virtual bool eventTest(QEvent *) { return false; } + virtual void onTransition(QEvent *) {} + } defaultTransition; + defaultTransition.setTargetStates(QList<QAbstractState*>() << &a2 << &b2); + h.setDefaultTransition(&defaultTransition); + + machine.start(); + QCoreApplication::processEvents(); + + QTRY_COMPARE(machine.configuration().contains(&root), true); + QTRY_COMPARE(machine.configuration().contains(&h), false); + QTRY_COMPARE(machine.configuration().contains(&p), true); + QTRY_COMPARE(machine.configuration().contains(&a), true); + QTRY_COMPARE(machine.configuration().contains(&a1), false); + QTRY_COMPARE(machine.configuration().contains(&a2), true); + QTRY_COMPARE(machine.configuration().contains(&a3), false); + QTRY_COMPARE(machine.configuration().contains(&b), true); + QTRY_COMPARE(machine.configuration().contains(&b1), false); + QTRY_COMPARE(machine.configuration().contains(&b2), true); + + QVERIFY(machine.isRunning()); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index e8c58a9fa5..72ae68f81a 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -479,34 +479,34 @@ void tst_QAtomicInt::testAndSet_data() QTest::addColumn<int>("value"); QTest::addColumn<int>("expected"); QTest::addColumn<int>("newval"); - QTest::addColumn<int>("result"); + QTest::addColumn<bool>("result"); // these should succeed - QTest::newRow("success0") << 0 << 0 << 0 << 1; - QTest::newRow("success1") << 0 << 0 << 1 << 1; - QTest::newRow("success2") << 0 << 0 << -1 << 1; - QTest::newRow("success3") << 1 << 1 << 0 << 1; - QTest::newRow("success4") << 1 << 1 << 1 << 1; - QTest::newRow("success5") << 1 << 1 << -1 << 1; - QTest::newRow("success6") << -1 << -1 << 0 << 1; - QTest::newRow("success7") << -1 << -1 << 1 << 1; - QTest::newRow("success8") << -1 << -1 << -1 << 1; - QTest::newRow("success9") << INT_MIN+1 << INT_MIN+1 << INT_MIN+1 << 1; - QTest::newRow("successA") << INT_MIN+1 << INT_MIN+1 << 1 << 1; - QTest::newRow("successB") << INT_MIN+1 << INT_MIN+1 << -1 << 1; - QTest::newRow("successC") << INT_MAX << INT_MAX << INT_MAX << 1; - QTest::newRow("successD") << INT_MAX << INT_MAX << 1 << 1; - QTest::newRow("successE") << INT_MAX << INT_MAX << -1 << 1; + QTest::newRow("success0") << 0 << 0 << 0 << true; + QTest::newRow("success1") << 0 << 0 << 1 << true; + QTest::newRow("success2") << 0 << 0 << -1 << true; + QTest::newRow("success3") << 1 << 1 << 0 << true; + QTest::newRow("success4") << 1 << 1 << 1 << true; + QTest::newRow("success5") << 1 << 1 << -1 << true; + QTest::newRow("success6") << -1 << -1 << 0 << true; + QTest::newRow("success7") << -1 << -1 << 1 << true; + QTest::newRow("success8") << -1 << -1 << -1 << true; + QTest::newRow("success9") << INT_MIN+1 << INT_MIN+1 << INT_MIN+1 << true; + QTest::newRow("successA") << INT_MIN+1 << INT_MIN+1 << 1 << true; + QTest::newRow("successB") << INT_MIN+1 << INT_MIN+1 << -1 << true; + QTest::newRow("successC") << INT_MAX << INT_MAX << INT_MAX << true; + QTest::newRow("successD") << INT_MAX << INT_MAX << 1 << true; + QTest::newRow("successE") << INT_MAX << INT_MAX << -1 << true; // these should fail - QTest::newRow("failure0") << 0 << 1 << ~0 << 0; - QTest::newRow("failure1") << 0 << -1 << ~0 << 0; - QTest::newRow("failure2") << 1 << 0 << ~0 << 0; - QTest::newRow("failure3") << -1 << 0 << ~0 << 0; - QTest::newRow("failure4") << 1 << -1 << ~0 << 0; - QTest::newRow("failure5") << -1 << 1 << ~0 << 0; - QTest::newRow("failure6") << INT_MIN+1 << INT_MAX << ~0 << 0; - QTest::newRow("failure7") << INT_MAX << INT_MIN+1 << ~0 << 0; + QTest::newRow("failure0") << 0 << 1 << ~0 << false; + QTest::newRow("failure1") << 0 << -1 << ~0 << false; + QTest::newRow("failure2") << 1 << 0 << ~0 << false; + QTest::newRow("failure3") << -1 << 0 << ~0 << false; + QTest::newRow("failure4") << 1 << -1 << ~0 << false; + QTest::newRow("failure5") << -1 << 1 << ~0 << false; + QTest::newRow("failure6") << INT_MIN+1 << INT_MAX << ~0 << false; + QTest::newRow("failure7") << INT_MAX << INT_MIN+1 << ~0 << false; } void tst_QAtomicInt::testAndSet() @@ -517,26 +517,26 @@ void tst_QAtomicInt::testAndSet() { QAtomicInt atomic = value; - QTEST(atomic.testAndSetRelaxed(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetRelaxed(expected, newval), "result"); } { QAtomicInt atomic = value; - QTEST(atomic.testAndSetAcquire(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetAcquire(expected, newval), "result"); } { QAtomicInt atomic = value; - QTEST(atomic.testAndSetRelease(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetRelease(expected, newval), "result"); } { QAtomicInt atomic = value; - QTEST(atomic.testAndSetOrdered(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetOrdered(expected, newval), "result"); } #ifdef Q_ATOMIC_INT32_IS_SUPPORTED - QFETCH(int, result); + QFETCH(bool, result); // the new implementation has the version that loads the current value { diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index 99978a9923..ad690a094b 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -648,7 +648,7 @@ void tst_QFuture::cancel() result.reportStarted(); f = result.future(); - QVERIFY(f.isCanceled() == false); + QVERIFY(!f.isCanceled()); result.reportCanceled(); QVERIFY(f.isCanceled()); result.reportFinished(); @@ -663,14 +663,14 @@ void tst_QFuture::cancel() QFutureInterface<void> result; QFuture<void> f; - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); result.reportStarted(); f = result.future(); - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); - QVERIFY(result.isCanceled() == false); + QVERIFY(!result.isCanceled()); f.cancel(); QVERIFY(result.isCanceled()); @@ -683,12 +683,12 @@ void tst_QFuture::cancel() QFutureInterface<void> result; QFuture<void> f; - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); result.reportStarted(); f = result.future(); - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); result.reportFinished(); @@ -805,12 +805,12 @@ void tst_QFuture::indexedResults() { QFutureInterface<QChar> Interface; QFuture<QChar> f; - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); Interface.reportStarted(); f = Interface.future(); - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); QChar result; @@ -1126,14 +1126,14 @@ void tst_QFuture::iterators() QVERIFY(it.hasNext()); QCOMPARE(it.peekNext(), resultCount - 1); QCOMPARE(it.next(), resultCount - 1); - QVERIFY(it.hasNext() == false); + QVERIFY(!it.hasNext()); } { QFutureIterator<int> it(f); QVERIFY(it.hasNext()); it.toBack(); - QVERIFY(it.hasNext() == false); + QVERIFY(!it.hasNext()); it.toFront(); QVERIFY(it.hasNext()); } @@ -1192,15 +1192,15 @@ void tst_QFuture::pause() Interface.reportStarted(); QFuture<void> f = Interface.future(); - QVERIFY(Interface.isPaused() == false); + QVERIFY(!Interface.isPaused()); f.pause(); - QVERIFY(Interface.isPaused() == true); + QVERIFY(Interface.isPaused()); f.resume(); - QVERIFY(Interface.isPaused() == false); + QVERIFY(!Interface.isPaused()); f.togglePaused(); - QVERIFY(Interface.isPaused() == true); + QVERIFY(Interface.isPaused()); f.togglePaused(); - QVERIFY(Interface.isPaused() == false); + QVERIFY(!Interface.isPaused()); Interface.reportFinished(); } @@ -1228,13 +1228,13 @@ void tst_QFuture::throttling() i.reportStarted(); QFuture<void> f = i.future(); - QVERIFY(i.isThrottled() == false); + QVERIFY(!i.isThrottled()); i.setThrottled(true); QVERIFY(i.isThrottled()); i.setThrottled(false); - QVERIFY(i.isThrottled() == false); + QVERIFY(!i.isThrottled()); i.setThrottled(true); QVERIFY(i.isThrottled()); diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index 8831345ad7..60a4d749c9 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -743,7 +743,7 @@ void tst_QFutureWatcher::finishedState() iface.reportFinished(); QVERIFY(future.isFinished()); - QVERIFY(watcher.isFinished() == false); + QVERIFY(!watcher.isFinished()); QTest::qWait(10); QVERIFY(watcher.isFinished()); @@ -761,18 +761,18 @@ void tst_QFutureWatcher::throttling() QFutureWatcher<int> watcher; watcher.setFuture(future); - QVERIFY(iface.isThrottled() == false); + QVERIFY(!iface.isThrottled()); for (int i = 0; i < 1000; ++i) { int result = 0; iface.reportResult(result); } - QVERIFY(iface.isThrottled() == true); + QVERIFY(iface.isThrottled()); QTest::qWait(100); // process events. - QVERIFY(iface.isThrottled() == false); + QVERIFY(!iface.isThrottled()); iface.reportFinished(); } diff --git a/tests/auto/corelib/thread/qsemaphore/BLACKLIST b/tests/auto/corelib/thread/qsemaphore/BLACKLIST new file mode 100644 index 0000000000..9f6f6e3ba6 --- /dev/null +++ b/tests/auto/corelib/thread/qsemaphore/BLACKLIST @@ -0,0 +1,3 @@ +# Times out randomly on linux, windows, osx +[tryAcquireWithTimeout] +* diff --git a/tests/auto/corelib/thread/qthread/BLACKLIST b/tests/auto/corelib/thread/qthread/BLACKLIST new file mode 100644 index 0000000000..d75249454f --- /dev/null +++ b/tests/auto/corelib/thread/qthread/BLACKLIST @@ -0,0 +1,2 @@ +[wait3_slowDestructor] +windows diff --git a/tests/auto/corelib/thread/qthreadpool/BLACKLIST b/tests/auto/corelib/thread/qthreadpool/BLACKLIST new file mode 100644 index 0000000000..684f650a72 --- /dev/null +++ b/tests/auto/corelib/thread/qthreadpool/BLACKLIST @@ -0,0 +1,5 @@ +[expiryTimeoutRace] +osx +[tryStartCount] +windows msvc-2012 +linux diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 7eedd5bcf7..ae8ffe48be 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -2235,7 +2235,7 @@ void tst_Collections::qstring() void tst_Collections::bitArray() { QBitArray ba(20); - QVERIFY(ba.testBit(17) == false); + QVERIFY(!ba.testBit(17)); ba.setBit(17); QVERIFY(ba.size() == 20); QVERIFY(ba.testBit(17)==true); diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 9bce948140..99e5c4c85d 100644..100755 --- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -31,6 +31,7 @@ ** ****************************************************************************/ +#include "../../../../../src/corelib/tools/qalgorithms.h" #include <QtTest/QtTest> #include <iostream> @@ -80,6 +81,24 @@ private slots: void popCount32() { popCount_impl<quint32>(); } void popCount64() { popCount_impl<quint64>(); } + void countTrailing08_data() { countTrailing_data_impl(sizeof(quint8 )); } + void countTrailing16_data() { countTrailing_data_impl(sizeof(quint16)); } + void countTrailing32_data() { countTrailing_data_impl(sizeof(quint32)); } + void countTrailing64_data() { countTrailing_data_impl(sizeof(quint64)); } + void countTrailing08() { countTrailing_impl<quint8 >(); } + void countTrailing16() { countTrailing_impl<quint16>(); } + void countTrailing32() { countTrailing_impl<quint32>(); } + void countTrailing64() { countTrailing_impl<quint64>(); } + + void countLeading08_data() { countLeading_data_impl(sizeof(quint8 )); } + void countLeading16_data() { countLeading_data_impl(sizeof(quint16)); } + void countLeading32_data() { countLeading_data_impl(sizeof(quint32)); } + void countLeading64_data() { countLeading_data_impl(sizeof(quint64)); } + void countLeading08() { countLeading_impl<quint8 >(); } + void countLeading16() { countLeading_impl<quint16>(); } + void countLeading32() { countLeading_impl<quint32>(); } + void countLeading64() { countLeading_impl<quint64>(); } + private: #if Q_TEST_PERFORMANCE void performance(); @@ -87,6 +106,14 @@ private: void popCount_data_impl(size_t sizeof_T_Int); template <typename T_Int> void popCount_impl(); + + void countTrailing_data_impl(size_t sizeof_T_Int); + template <typename T_Int> + void countTrailing_impl(); + + void countLeading_data_impl(size_t sizeof_T_Int); + template <typename T_Int> + void countLeading_impl(); }; class TestInt @@ -1084,6 +1111,86 @@ void tst_QAlgorithms::popCount_impl() QCOMPARE(qPopulationCount(value), expected); } +void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int) +{ + using namespace QTest; + addColumn<quint64>("input"); + addColumn<uint>("expected"); + + int nibs = sizeof_T_Int*2; + + newRow(("0x"+QByteArray::number(0,16).rightJustified(nibs,'0')).constData()) << Q_UINT64_C(0) << uint(sizeof_T_Int*8); + for (uint i = 0; i < sizeof_T_Int*8; ++i) { + const quint64 input = Q_UINT64_C(1) << i; + newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << i; + } + + quint64 type_mask; + if (sizeof_T_Int>=8) + type_mask = ~Q_UINT64_C(0); + else + type_mask = (Q_UINT64_C(1) << (sizeof_T_Int*8))-1; + + // and some random ones: + for (uint i = 0; i < sizeof_T_Int*8; ++i) { + for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary + const quint64 r = quint64(qrand()) << 32 | quint32(qrand()); + const quint64 b = Q_UINT64_C(1) << i; + const quint64 mask = ((~(b-1)) ^ b) & type_mask; + const quint64 input = (r&mask) | b; + newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << i; + } + } +} + +template <typename T_Int> +void tst_QAlgorithms::countTrailing_impl() +{ + QFETCH(quint64, input); + QFETCH(uint, expected); + + const T_Int value = static_cast<T_Int>(input); + + QCOMPARE(qCountTrailingZeroBits(value), expected); +} + +void tst_QAlgorithms::countLeading_data_impl(size_t sizeof_T_Int) +{ + using namespace QTest; + addColumn<quint64>("input"); + addColumn<uint>("expected"); + + int nibs = sizeof_T_Int*2; + + newRow(("0x"+QByteArray::number(0,16).rightJustified(nibs,'0')).constData()) << Q_UINT64_C(0) << uint(sizeof_T_Int*8); + for (uint i = 0; i < sizeof_T_Int*8; ++i) { + const quint64 input = Q_UINT64_C(1) << i; + newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << uint(sizeof_T_Int*8-i-1); + } + + // and some random ones: + for (uint i = 0; i < sizeof_T_Int*8; ++i) { + for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary + const quint64 r = quint64(qrand()) << 32 | quint32(qrand()); + const quint64 b = Q_UINT64_C(1) << i; + const quint64 mask = b-1; + const quint64 input = (r&mask) | b; + newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << uint(sizeof_T_Int*8-i-1); + } + } +} + +template <typename T_Int> +void tst_QAlgorithms::countLeading_impl() +{ + QFETCH(quint64, input); + QFETCH(uint, expected); + + const T_Int value = static_cast<T_Int>(input); + + QCOMPARE(qCountLeadingZeroBits(value), expected); +} + QTEST_APPLESS_MAIN(tst_QAlgorithms) #include "tst_qalgorithms.moc" diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 410b34e894..f942eab800 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -67,6 +67,7 @@ private slots: void endsWith_data(); void endsWith(); void endsWith_char(); + void reverseIterators(); void split_data(); void split(); void base64_data(); @@ -540,6 +541,20 @@ void tst_QByteArray::endsWith_char() QVERIFY(!QByteArray().endsWith('\0')); } +void tst_QByteArray::reverseIterators() +{ + QByteArray s = "1234"; + QByteArray sr = s; + std::reverse(sr.begin(), sr.end()); + const QByteArray &csr = sr; + QVERIFY(std::equal(s.begin(), s.end(), sr.rbegin())); + QVERIFY(std::equal(s.begin(), s.end(), sr.crbegin())); + QVERIFY(std::equal(s.begin(), s.end(), csr.rbegin())); + QVERIFY(std::equal(sr.rbegin(), sr.rend(), s.begin())); + QVERIFY(std::equal(sr.crbegin(), sr.crend(), s.begin())); + QVERIFY(std::equal(csr.rbegin(), csr.rend(), s.begin())); +} + void tst_QByteArray::split_data() { QTest::addColumn<QByteArray>("sample"); diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray_mac.mm b/tests/auto/corelib/tools/qbytearray/tst_qbytearray_mac.mm index c2b76cc41a..95d05904a2 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray_mac.mm +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray_mac.mm @@ -72,35 +72,31 @@ void tst_QByteArray_macTypes() } // QByteArray <-> NSData { - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QByteArray qtByteArray("test bytearray"); const NSData *nsData = qtByteArray.toNSData(); QCOMPARE(QByteArray::fromNSData(nsData), qtByteArray); - [autoreleasepool release]; } { - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QByteArray qtByteArray("test bytearray"); const NSData *nsData = qtByteArray.toNSData(); QByteArray qtByteArrayCopy(qtByteArray); qtByteArray = qtByteArray.toUpper(); // modify QCOMPARE(QByteArray::fromNSData(nsData), qtByteArrayCopy); - [autoreleasepool release]; } // QByteArray <-> NSData Raw { - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QByteArray qtByteArray("test bytearray"); const NSData *nsData = qtByteArray.toRawNSData(); QCOMPARE([nsData bytes], qtByteArray.constData()); - [autoreleasepool release]; } { - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; const char data[] = "nsdata test"; const NSData *nsData = [NSData dataWithBytes:data length:sizeof(data)]; QByteArray qtByteArray = QByteArray::fromRawNSData(nsData); QCOMPARE(qtByteArray.constData(), [nsData bytes]); - [autoreleasepool release]; } } diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp index 7b1b7ce963..6e09ebb09b 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp @@ -73,6 +73,12 @@ int main(int argc, char *argv[]) "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); parser.addOption(newlineOption); + // A hidden option + QCommandLineOption hiddenOption(QStringList() << QStringLiteral("hidden")); + hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR")); + hiddenOption.setHidden(true); + parser.addOption(hiddenOption); + // This program supports different options depending on the "command" (first argument). // Call parse() to find out the positional arguments. parser.parse(QCoreApplication::arguments()); diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 6ff46ed20b..fb0b971602 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -35,6 +35,7 @@ #include <QtCore/QCommandLineParser> Q_DECLARE_METATYPE(char**) +Q_DECLARE_METATYPE(QCommandLineParser::OptionsAfterPositionalArgumentsMode) class tst_QCommandLineParser : public QObject { @@ -51,6 +52,8 @@ private slots: void testPositionalArguments(); void testBooleanOption_data(); void testBooleanOption(); + void testOptionsAndPositional_data(); + void testOptionsAndPositional(); void testMultipleNames_data(); void testMultipleNames(); void testSingleValueOption_data(); @@ -130,7 +133,7 @@ void tst_QCommandLineParser::testBooleanOption() QFETCH(bool, expectedIsSet); QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; - QVERIFY(parser.addOption(QCommandLineOption(QStringLiteral("b"), QStringLiteral("a boolean option")))); + QVERIFY(parser.addOption(QCommandLineOption(QStringLiteral("b")))); QVERIFY(parser.parse(args)); QCOMPARE(parser.optionNames(), expectedOptionNames); QCOMPARE(parser.isSet("b"), expectedIsSet); @@ -141,6 +144,40 @@ void tst_QCommandLineParser::testBooleanOption() QVERIFY(!parser.isSet("c")); } +void tst_QCommandLineParser::testOptionsAndPositional_data() +{ + QTest::addColumn<QStringList>("args"); + QTest::addColumn<QStringList>("expectedOptionNames"); + QTest::addColumn<bool>("expectedIsSet"); + QTest::addColumn<QStringList>("expectedPositionalArguments"); + QTest::addColumn<QCommandLineParser::OptionsAfterPositionalArgumentsMode>("parsingMode"); + + const QStringList arg = QStringList() << "arg"; + QTest::newRow("before_positional_default") << (QStringList() << "tst_qcommandlineparser" << "-b" << "arg") << (QStringList() << "b") << true << arg << QCommandLineParser::ParseAsOptions; + QTest::newRow("after_positional_default") << (QStringList() << "tst_qcommandlineparser" << "arg" << "-b") << (QStringList() << "b") << true << arg << QCommandLineParser::ParseAsOptions; + QTest::newRow("before_positional_parseAsArg") << (QStringList() << "tst_qcommandlineparser" << "-b" << "arg") << (QStringList() << "b") << true << arg << QCommandLineParser::ParseAsPositionalArguments; + QTest::newRow("after_positional_parseAsArg") << (QStringList() << "tst_qcommandlineparser" << "arg" << "-b") << (QStringList()) << false << (QStringList() << "arg" << "-b") << QCommandLineParser::ParseAsPositionalArguments; +} + +void tst_QCommandLineParser::testOptionsAndPositional() +{ + QFETCH(QStringList, args); + QFETCH(QStringList, expectedOptionNames); + QFETCH(bool, expectedIsSet); + QFETCH(QStringList, expectedPositionalArguments); + QFETCH(QCommandLineParser::OptionsAfterPositionalArgumentsMode, parsingMode); + + QCoreApplication app(empty_argc, empty_argv); + QCommandLineParser parser; + parser.setOptionsAfterPositionalArgumentsMode(parsingMode); + QVERIFY(parser.addOption(QCommandLineOption(QStringLiteral("b"), QStringLiteral("a boolean option")))); + QVERIFY(parser.parse(args)); + QCOMPARE(parser.optionNames(), expectedOptionNames); + QCOMPARE(parser.isSet("b"), expectedIsSet); + QCOMPARE(parser.values("b"), QStringList()); + QCOMPARE(parser.positionalArguments(), expectedPositionalArguments); +} + void tst_QCommandLineParser::testMultipleNames_data() { QTest::addColumn<QStringList>("args"); diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm index 6bdaa94e49..0ad9a8253b 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm @@ -56,19 +56,17 @@ void tst_QDateTime_macTypes() } // QDateTime <-> NSDate { - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0); const NSDate *nsDate = qtDateTime.toNSDate(); QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTime); - [autoreleasepool release]; } { - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0); const NSDate *nsDate = qtDateTime.toNSDate(); QDateTime qtDateTimeCopy(qtDateTime); qtDateTime.setTime_t(10000); // modify QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTimeCopy); - [autoreleasepool release]; } } diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 6ea33fb37f..6a5c6b5670 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -62,6 +62,7 @@ private slots: void compare(); void compare2(); void iterators(); // sligthly modified from tst_QMap + void keyIterator(); void keys_values_uniqueKeys(); // slightly modified from tst_QMap void noNeedlessRehashes(); @@ -965,6 +966,34 @@ void tst_QHash::iterators() } } +void tst_QHash::keyIterator() +{ + QHash<int, int> hash; + + for (int i = 0; i < 100; ++i) + hash.insert(i, i*100); + + QHash<int, int>::key_iterator key_it = hash.keyBegin(); + QHash<int, int>::const_iterator it = hash.cbegin(); + for (int i = 0; i < 100; ++i) { + QCOMPARE(*key_it, it.key()); + key_it++; + it++; + } + + key_it = std::find(hash.keyBegin(), hash.keyEnd(), 50); + it = std::find(hash.cbegin(), hash.cend(), 50 * 100); + + QVERIFY(key_it != hash.keyEnd()); + QCOMPARE(*key_it, it.key()); + QCOMPARE(*(key_it++), (it++).key()); + QCOMPARE(*(key_it--), (it--).key()); + QCOMPARE(*(++key_it), (++it).key()); + QCOMPARE(*(--key_it), (--it).key()); + + QCOMPARE(std::count(hash.keyBegin(), hash.keyEnd(), 99), 1); +} + void tst_QHash::rehash_isnt_quadratic() { // this test should be incredibly slow if rehash() is quadratic diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index 82303b4f72..2e829bb05e 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -527,12 +527,12 @@ void tst_QLinkedList::contains() const QLinkedList<T> list; list << T_FOO << T_BAR << T_BAZ; - QVERIFY(list.contains(T_FOO) == true); + QVERIFY(list.contains(T_FOO)); QVERIFY(list.contains(T_BLAH) != true); // add it and make sure it matches list.append(T_BLAH); - QVERIFY(list.contains(T_BLAH) == true); + QVERIFY(list.contains(T_BLAH)); } void tst_QLinkedList::containsInt() const diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index 1207986dde..1bb31afa9c 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -76,6 +76,13 @@ struct Movable { return i == other.i; } + bool operator<(const Movable &other) const + { + check(state, Constructed); + check(other.state, Constructed); + return i < other.i; + } + Movable &operator=(const Movable &other) { check(state, Constructed); @@ -144,6 +151,13 @@ struct Optimal return i == other.i; } + bool operator<(const Optimal &other) const + { + check(state, Constructed); + check(other.state, Constructed); + return i < other.i; + } + Optimal &operator=(const Optimal &other) { check(state, Constructed); @@ -220,6 +234,12 @@ struct Complex return value == other.value; } + bool operator<(Complex const &other) const + { + check(); other.check(); + return value < other.value; + } + void check() const { QVERIFY(this == checkSum); @@ -293,6 +313,8 @@ private slots: void lastOptimal() const; void lastMovable() const; void lastComplex() const; + void constFirst() const; + void constLast() const; void beginOptimal() const; void beginMovable() const; void beginComplex() const; @@ -329,6 +351,9 @@ private slots: void replaceOptimal() const; void replaceMovable() const; void replaceComplex() const; + void reverseIteratorsOptimal() const; + void reverseIteratorsMovable() const; + void reverseIteratorsComplex() const; void startsWithOptimal() const; void startsWithMovable() const; void startsWithComplex() const; @@ -376,6 +401,9 @@ private slots: void eraseValidIteratorsOnSharedList() const; void insertWithValidIteratorsOnSharedList() const; + void qhashOptimal() const { qhash<Optimal>(); } + void qhashMovable() const { qhash<Movable>(); } + void qhashComplex() const { qhash<Complex>(); } void reserve() const; private: template<typename T> void length() const; @@ -392,10 +420,12 @@ private: template<typename T> void endsWith() const; template<typename T> void lastIndexOf() const; template<typename T> void move() const; + template<typename T> void qhash() const; template<typename T> void removeAll() const; template<typename T> void removeAt() const; template<typename T> void removeOne() const; template<typename T> void replace() const; + template<typename T> void reverseIterators() const; template<typename T> void startsWith() const; template<typename T> void swap() const; template<typename T> void takeAt() const; @@ -701,6 +731,140 @@ void tst_QList::firstComplex() const QCOMPARE(liveCount, Complex::getLiveCount()); } +void tst_QList::constFirst() const +{ + // Based on tst_QVector::constFirst() + QList<int> list; + list << 69 << 42 << 3; + + // test it starts ok + QCOMPARE(list.constFirst(), 69); + QVERIFY(list.isDetached()); + + QList<int> listCopy = list; + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + QCOMPARE(list.constFirst(), 69); + QCOMPARE(listCopy.constFirst(), 69); + + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + // test removal changes + list.removeAt(0); + QVERIFY(list.isDetached()); + QVERIFY(!list.isSharedWith(listCopy)); + QCOMPARE(list.constFirst(), 42); + QCOMPARE(listCopy.constFirst(), 69); + + listCopy = list; + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + QCOMPARE(list.constFirst(), 42); + QCOMPARE(listCopy.constFirst(), 42); + + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + // test prepend changes + list.prepend(23); + QVERIFY(list.isDetached()); + QVERIFY(!list.isSharedWith(listCopy)); + QCOMPARE(list.constFirst(), 23); + QCOMPARE(listCopy.constFirst(), 42); + + listCopy = list; + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + QCOMPARE(list.constFirst(), 23); + QCOMPARE(listCopy.constFirst(), 23); + + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); +} + +void tst_QList::constLast() const +{ + // Based on tst_QVector::constLast() + QList<int> list; + list << 69 << 42 << 3; + + // test it starts ok + QCOMPARE(list.constLast(), 3); + QVERIFY(list.isDetached()); + + QList<int> listCopy = list; + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + QCOMPARE(list.constLast(), 3); + QCOMPARE(listCopy.constLast(), 3); + + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + // test removal changes + list.removeLast(); + QVERIFY(list.isDetached()); + QVERIFY(!list.isSharedWith(listCopy)); + QCOMPARE(list.constLast(), 42); + QCOMPARE(listCopy.constLast(), 3); + + listCopy = list; + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + QCOMPARE(list.constLast(), 42); + QCOMPARE(listCopy.constLast(), 42); + + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + // test prepend changes + list.append(23); + QVERIFY(list.isDetached()); + QVERIFY(!list.isSharedWith(listCopy)); + QCOMPARE(list.constLast(), 23); + QCOMPARE(listCopy.constLast(), 42); + + listCopy = list; + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); + + QCOMPARE(list.constLast(), 23); + QCOMPARE(listCopy.constLast(), 23); + + QVERIFY(!list.isDetached()); + QVERIFY(!listCopy.isDetached()); + QVERIFY(list.isSharedWith(listCopy)); + QVERIFY(listCopy.isSharedWith(list)); +} + template<typename T> void tst_QList::last() const { @@ -812,12 +976,12 @@ void tst_QList::contains() const QList<T> list; list << T_FOO << T_BAR << T_BAZ; - QVERIFY(list.contains(T_FOO) == true); + QVERIFY(list.contains(T_FOO)); QVERIFY(list.contains(T_BLAH) != true); // add it and make sure it matches list.append(T_BLAH); - QVERIFY(list.contains(T_BLAH) == true); + QVERIFY(list.contains(T_BLAH)); } void tst_QList::containsOptimal() const @@ -1220,6 +1384,43 @@ void tst_QList::replaceComplex() const } template<typename T> +void tst_QList::reverseIterators() const +{ + QList<T> v; + v << T_CAT << T_DOG << T_BLAH << T_BAZ; + QList<T> vr = v; + std::reverse(vr.begin(), vr.end()); + const QList<T> &cvr = vr; + QVERIFY(std::equal(v.begin(), v.end(), vr.rbegin())); + QVERIFY(std::equal(v.begin(), v.end(), vr.crbegin())); + QVERIFY(std::equal(v.begin(), v.end(), cvr.rbegin())); + QVERIFY(std::equal(vr.rbegin(), vr.rend(), v.begin())); + QVERIFY(std::equal(vr.crbegin(), vr.crend(), v.begin())); + QVERIFY(std::equal(cvr.rbegin(), cvr.rend(), v.begin())); +} + +void tst_QList::reverseIteratorsOptimal() const +{ + const int liveCount = Optimal::getLiveCount(); + reverseIterators<Optimal>(); + QCOMPARE(liveCount, Optimal::getLiveCount()); +} + +void tst_QList::reverseIteratorsMovable() const +{ + const int liveCount = Movable::getLiveCount(); + reverseIterators<Movable>(); + QCOMPARE(liveCount, Movable::getLiveCount()); +} + +void tst_QList::reverseIteratorsComplex() const +{ + const int liveCount = Complex::getLiveCount(); + reverseIterators<Complex>(); + QCOMPARE(liveCount, Complex::getLiveCount()); +} + +template<typename T> void tst_QList::startsWith() const { QList<T> list; @@ -1576,6 +1777,19 @@ void tst_QList::testOperators() const // [] QCOMPARE(list[0], T_FOO); QCOMPARE(list[list.size() - 1], T_CAT); + + // <, >, <=, >= + QVERIFY(!(list < listtwo)); + QVERIFY(!(list > listtwo)); + QVERIFY( list <= listtwo); + QVERIFY( list >= listtwo); + listtwo.push_back(T_CAT); + QVERIFY( list < listtwo); + QVERIFY(!(list > listtwo)); + QVERIFY( list <= listtwo); + QVERIFY(!(list >= listtwo)); + QVERIFY(listtwo > list); + QVERIFY(listtwo >= list); } void tst_QList::testOperatorsOptimal() const @@ -1834,6 +2048,16 @@ void tst_QList::insertWithValidIteratorsOnSharedList() const QCOMPARE(a.at(1), 15); } +template <typename T> +void tst_QList::qhash() const +{ + QList<T> l1, l2; + QCOMPARE(qHash(l1), qHash(l2)); + l1 << T_BAR; + l2 << T_BAR; + QCOMPARE(qHash(l1), qHash(l2)); +} + void tst_QList::reserve() const { // Note: diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index b1e13a0384..11b6922278 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -371,6 +371,8 @@ void tst_QLocale::ctor() QString("requested: \"" + QString(req_lc) + "\", got: " \ + QLocale::languageToString(l.language()) \ + "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \ + QCOMPARE(l, QLocale(QLocale::exp_lang, QLocale::exp_country)); \ + QCOMPARE(qHash(l), qHash(QLocale(QLocale::exp_lang, QLocale::exp_country))); \ } QLocale::setDefault(QLocale(QLocale::C)); diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 8560a2f18c..bb6535b635 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -65,6 +65,7 @@ private slots: void take(); void iterators(); + void keyIterator(); void keys_values_uniqueKeys(); void qmultimap_specific(); @@ -835,6 +836,34 @@ void tst_QMap::iterators() } } +void tst_QMap::keyIterator() +{ + QMap<int, int> map; + + for (int i = 0; i < 100; ++i) + map.insert(i, i*100); + + QMap<int, int>::key_iterator key_it = map.keyBegin(); + QMap<int, int>::const_iterator it = map.cbegin(); + for (int i = 0; i < 100; ++i) { + QCOMPARE(*key_it, it.key()); + ++key_it; + ++it; + } + + key_it = std::find(map.keyBegin(), map.keyEnd(), 50); + it = std::find(map.cbegin(), map.cend(), 50 * 100); + + QVERIFY(key_it != map.keyEnd()); + QCOMPARE(*key_it, it.key()); + QCOMPARE(*(key_it++), (it++).key()); + QCOMPARE(*(key_it--), (it--).key()); + QCOMPARE(*(++key_it), (++it).key()); + QCOMPARE(*(--key_it), (--it).key()); + + QCOMPARE(std::count(map.keyBegin(), map.keyEnd(), 99), 1); +} + void tst_QMap::keys_values_uniqueKeys() { QMap<QString, int> map; @@ -996,11 +1025,16 @@ void tst_QMap::const_shared_null() void tst_QMap::equal_range() { QMap<int, QString> map; + const QMap<int, QString> &cmap = map; QPair<QMap<int, QString>::iterator, QMap<int, QString>::iterator> result = map.equal_range(0); QCOMPARE(result.first, map.end()); QCOMPARE(result.second, map.end()); + QPair<QMap<int, QString>::const_iterator, QMap<int, QString>::const_iterator> cresult = cmap.equal_range(0); + QCOMPARE(cresult.first, cmap.cend()); + QCOMPARE(cresult.second, cmap.cend()); + map.insert(1, "one"); result = map.equal_range(0); @@ -1015,6 +1049,18 @@ void tst_QMap::equal_range() QCOMPARE(result.first, map.end()); QCOMPARE(result.second, map.end()); + cresult = cmap.equal_range(0); + QCOMPARE(cresult.first, cmap.find(1)); + QCOMPARE(cresult.second, cmap.find(1)); + + cresult = cmap.equal_range(1); + QCOMPARE(cresult.first, cmap.find(1)); + QCOMPARE(cresult.second, cmap.cend()); + + cresult = cmap.equal_range(2); + QCOMPARE(cresult.first, cmap.cend()); + QCOMPARE(cresult.second, cmap.cend()); + for (int i = -10; i < 10; i += 2) map.insert(i, QString("%1").arg(i)); @@ -1030,11 +1076,28 @@ void tst_QMap::equal_range() QCOMPARE(result.first, map.find(2)); QCOMPARE(result.second, map.find(4)); + cresult = cmap.equal_range(0); + QCOMPARE(cresult.first, cmap.find(0)); + QCOMPARE(cresult.second, cmap.find(1)); + + cresult = cmap.equal_range(1); + QCOMPARE(cresult.first, cmap.find(1)); + QCOMPARE(cresult.second, cmap.find(2)); + + cresult = cmap.equal_range(2); + QCOMPARE(cresult.first, cmap.find(2)); + QCOMPARE(cresult.second, cmap.find(4)); + map.insertMulti(1, "another one"); + result = map.equal_range(1); QCOMPARE(result.first, map.find(1)); QCOMPARE(result.second, map.find(2)); + cresult = cmap.equal_range(1); + QCOMPARE(cresult.first, cmap.find(1)); + QCOMPARE(cresult.second, cmap.find(2)); + QCOMPARE(map.count(1), 2); } diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp index fefdec7496..b9a3fc13c5 100644 --- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp +++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp @@ -1224,6 +1224,9 @@ void tst_QRegExp::operator_eq() for (int j = 0; j < I * J * K * ELL; ++j) { QCOMPARE(rxtable[i] == rxtable[j], i / ELL == j / ELL); QCOMPARE(rxtable[i] != rxtable[j], i / ELL != j / ELL); + // this just happens to have no hash collisions. If at some point + // we get collisions, restrict the test to only equal elements: + QCOMPARE(qHash(rxtable[i]) == qHash(rxtable[j]), i / ELL == j / ELL); } } } diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index d185e64251..8ddd4979b6 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -1423,6 +1423,7 @@ static void verifyEquality(const QRegularExpression &re1, const QRegularExpressi { QVERIFY(re1 == re2); QVERIFY(re2 == re1); + QCOMPARE(qHash(re1), qHash(re2)); QVERIFY(!(re1 != re2)); QVERIFY(!(re2 != re1)); @@ -1430,22 +1431,26 @@ static void verifyEquality(const QRegularExpression &re1, const QRegularExpressi QVERIFY(re1 == re3); QVERIFY(re3 == re1); + QCOMPARE(qHash(re1), qHash(re3)); QVERIFY(!(re1 != re3)); QVERIFY(!(re3 != re1)); QVERIFY(re2 == re3); QVERIFY(re3 == re2); + QCOMPARE(qHash(re2), qHash(re3)); QVERIFY(!(re2 != re3)); QVERIFY(!(re3 != re2)); re3 = re2; QVERIFY(re1 == re3); QVERIFY(re3 == re1); + QCOMPARE(qHash(re1), qHash(re3)); QVERIFY(!(re1 != re3)); QVERIFY(!(re3 != re1)); QVERIFY(re2 == re3); QVERIFY(re3 == re2); + QCOMPARE(qHash(re2), qHash(re3)); QVERIFY(!(re2 != re3)); QVERIFY(!(re3 != re2)); } diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp index 8c29064457..77fc6ad6ae 100644 --- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp +++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp @@ -48,10 +48,12 @@ private slots: void sizeWhenReserved(); void free(); void reserveAndRead(); + void reserveFrontAndRead(); void chop(); void ungetChar(); void indexOf(); void appendAndRead(); + void peek(); void readLine(); }; @@ -60,7 +62,7 @@ void tst_QRingBuffer::sizeWhenReserved() QRingBuffer ringBuffer; ringBuffer.reserve(5); - QCOMPARE(ringBuffer.size(), 5); + QCOMPARE(ringBuffer.size(), Q_INT64_C(5)); } void tst_QRingBuffer::sizeWhenReservedAndChopped() @@ -69,14 +71,14 @@ void tst_QRingBuffer::sizeWhenReservedAndChopped() ringBuffer.reserve(31337); ringBuffer.chop(31337); - QCOMPARE(ringBuffer.size(), 0); + QCOMPARE(ringBuffer.size(), Q_INT64_C(0)); } void tst_QRingBuffer::sizeWhenEmpty() { QRingBuffer ringBuffer; - QCOMPARE(ringBuffer.size(), 0); + QCOMPARE(ringBuffer.size(), Q_INT64_C(0)); } void tst_QRingBuffer::readPointerAtPositionReadTooMuch() @@ -86,7 +88,7 @@ void tst_QRingBuffer::readPointerAtPositionReadTooMuch() qint64 length; const char *buf = ringBuffer.readPointerAtPosition(42, length); QVERIFY(buf == 0); - QVERIFY(length == 0); + QCOMPARE(length, Q_INT64_C(0)); } void tst_QRingBuffer::readPointerAtPositionWithHead() @@ -101,22 +103,22 @@ void tst_QRingBuffer::readPointerAtPositionWithHead() qint64 length; const char* buf2 = ringBuffer.readPointerAtPosition(0, length); - QCOMPARE(length, qint64(2)); - QVERIFY(*buf2 == '2'); - QVERIFY(*(buf2+1) == '3'); + QCOMPARE(length, Q_INT64_C(2)); + QCOMPARE(*buf2, '2'); + QCOMPARE(*(buf2 + 1), '3'); // advance 2 more, ringBuffer should be empty then ringBuffer.free(2); buf2 = ringBuffer.readPointerAtPosition(0, length); - QCOMPARE(length, qint64(0)); + QCOMPARE(length, Q_INT64_C(0)); QVERIFY(buf2 == 0); // check buffer with 2 blocks memcpy(ringBuffer.reserve(4), "0123", 4); ringBuffer.append(QByteArray("45678", 5)); ringBuffer.free(3); - buf2 = ringBuffer.readPointerAtPosition(1, length); - QCOMPARE(length, qint64(5)); + buf2 = ringBuffer.readPointerAtPosition(Q_INT64_C(1), length); + QCOMPARE(length, Q_INT64_C(5)); } void tst_QRingBuffer::readPointerAtPositionEmptyRead() @@ -126,7 +128,7 @@ void tst_QRingBuffer::readPointerAtPositionEmptyRead() qint64 length; const char *buf = ringBuffer.readPointerAtPosition(0, length); QVERIFY(buf == 0); - QVERIFY(length == 0); + QCOMPARE(length, Q_INT64_C(0)); } void tst_QRingBuffer::readPointerAtPositionWriteRead() @@ -149,14 +151,14 @@ void tst_QRingBuffer::readPointerAtPositionWriteRead() // write in chunks of 50 bytes // this ensures there will be multiple QByteArrays inside the QRingBuffer // since QRingBuffer is then only using individual arrays of around 4000 bytes - qint64 thisWrite = qMin(remaining, qint64(50)); + qint64 thisWrite = qMin(remaining, Q_INT64_C(50)); char *pos = ringBuffer.reserve(thisWrite); inData.read(pos, thisWrite); remaining -= thisWrite; } // was data put into it? QVERIFY(ringBuffer.size() > 0); - QCOMPARE(qint64(ringBuffer.size()), inData.size()); + QCOMPARE(ringBuffer.size(), inData.size()); //read from the QRingBuffer in loop, put back into another QBuffer QBuffer outData; @@ -187,12 +189,12 @@ void tst_QRingBuffer::free() ringBuffer.append(QByteArray("01234", 5)); ringBuffer.free(1); - QCOMPARE(ringBuffer.size(), 4095 + 2048 + 5); + QCOMPARE(ringBuffer.size(), Q_INT64_C(4095 + 2048 + 5)); ringBuffer.free(4096); - QCOMPARE(ringBuffer.size(), 2047 + 5); + QCOMPARE(ringBuffer.size(), Q_INT64_C(2047 + 5)); ringBuffer.free(48); ringBuffer.free(2000); - QCOMPARE(ringBuffer.size(), 4); + QCOMPARE(ringBuffer.size(), Q_INT64_C(4)); QVERIFY(memcmp(ringBuffer.readPointer(), "1234", 4) == 0); } @@ -211,11 +213,33 @@ void tst_QRingBuffer::reserveAndRead() for (int i = 1; i < 256; ++i) { QByteArray ba; ba.resize(i); - int thisRead = ringBuffer.read(ba.data(), i); - QCOMPARE(thisRead, i); - QVERIFY(ba.count(char(i)) == i); + qint64 thisRead = ringBuffer.read(ba.data(), i); + QCOMPARE(thisRead, qint64(i)); + QCOMPARE(ba.count(char(i)), i); } - QVERIFY(ringBuffer.size() == 0); + QCOMPARE(ringBuffer.size(), Q_INT64_C(0)); +} + +void tst_QRingBuffer::reserveFrontAndRead() +{ + QRingBuffer ringBuffer; + // fill buffer with an arithmetic progression + for (int i = 1; i < 256; ++i) { + QByteArray ba(i, char(i)); + char *ringPos = ringBuffer.reserveFront(i); + QVERIFY(ringPos); + memcpy(ringPos, ba.constData(), i); + } + + // readback and check stored data + for (int i = 255; i > 0; --i) { + QByteArray ba; + ba.resize(i); + qint64 thisRead = ringBuffer.read(ba.data(), i); + QCOMPARE(thisRead, qint64(i)); + QCOMPARE(ba.count(char(i)), i); + } + QCOMPARE(ringBuffer.size(), Q_INT64_C(0)); } void tst_QRingBuffer::chop() @@ -227,12 +251,12 @@ void tst_QRingBuffer::chop() ringBuffer.reserve(4096); ringBuffer.chop(1); - QCOMPARE(ringBuffer.size(), 5 + 2048 + 4095); + QCOMPARE(ringBuffer.size(), Q_INT64_C(5 + 2048 + 4095)); ringBuffer.chop(4096); - QCOMPARE(ringBuffer.size(), 5 + 2047); + QCOMPARE(ringBuffer.size(), Q_INT64_C(5 + 2047)); ringBuffer.chop(48); ringBuffer.chop(2000); - QCOMPARE(ringBuffer.size(), 4); + QCOMPARE(ringBuffer.size(), Q_INT64_C(4)); QVERIFY(memcmp(ringBuffer.readPointer(), "0123", 4) == 0); } @@ -244,11 +268,11 @@ void tst_QRingBuffer::ungetChar() for (int i = 1; i < 31; ++i) { int c = ringBuffer.getChar(); - QVERIFY(c == 1); + QCOMPARE(c, 1); ringBuffer.getChar(); ringBuffer.ungetChar(char(c)); // unget first char } - QCOMPARE(ringBuffer.size(), 1); + QCOMPARE(ringBuffer.size(), Q_INT64_C(1)); } void tst_QRingBuffer::indexOf() @@ -258,10 +282,10 @@ void tst_QRingBuffer::indexOf() ringBuffer.putChar(char(i)); for (int i = 1; i < 256; ++i) { - int index = ringBuffer.indexOf(char(i)); - QCOMPARE(i - 1, index); - QCOMPARE(index, ringBuffer.indexOf(char(i), i)); - QVERIFY(ringBuffer.indexOf(char(i), i - 1) == -1); // test for absent char + qint64 index = ringBuffer.indexOf(char(i)); + QCOMPARE(index, qint64(i - 1)); + QCOMPARE(ringBuffer.indexOf(char(i), i), index); + QCOMPARE(ringBuffer.indexOf(char(i), i - 1), -1); // test for absent char } } @@ -275,9 +299,34 @@ void tst_QRingBuffer::appendAndRead() ringBuffer.append(ba2); ringBuffer.append(ba3); - QVERIFY(ringBuffer.read() == ba1); - QVERIFY(ringBuffer.read() == ba2); - QVERIFY(ringBuffer.read() == ba3); + QCOMPARE(ringBuffer.read(), ba1); + QCOMPARE(ringBuffer.read(), ba2); + QCOMPARE(ringBuffer.read(), ba3); +} + +void tst_QRingBuffer::peek() +{ + QRingBuffer ringBuffer; + QByteArray testBuffer; + // fill buffer with an arithmetic progression + for (int i = 1; i < 256; ++i) { + char *ringPos = ringBuffer.reserve(i); + QVERIFY(ringPos); + memset(ringPos, i, i); + testBuffer.append(ringPos, i); + } + + // check stored data + QByteArray resultBuffer; + int peekPosition = testBuffer.size(); + for (int i = 1; i < 256; ++i) { + QByteArray ba(i, 0); + peekPosition -= i; + qint64 thisPeek = ringBuffer.peek(ba.data(), i, peekPosition); + QCOMPARE(thisPeek, qint64(i)); + resultBuffer.prepend(ba); + } + QCOMPARE(resultBuffer, testBuffer); } void tst_QRingBuffer::readLine() @@ -293,18 +342,18 @@ void tst_QRingBuffer::readLine() char stringBuf[102]; stringBuf[101] = 0; // non-crash terminator - QVERIFY(ringBuffer.readLine(stringBuf, sizeof(stringBuf) - 2) == ba1.size()); - QVERIFY(QByteArray(stringBuf, int(strlen(stringBuf))) == ba1); + QCOMPARE(ringBuffer.readLine(stringBuf, sizeof(stringBuf) - 2), qint64(ba1.size())); + QCOMPARE(QByteArray(stringBuf, int(strlen(stringBuf))), ba1); // check first empty string reading stringBuf[0] = char(0xFF); - QCOMPARE(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2), ba2.size()); - QVERIFY(stringBuf[0] == ba2[0]); + QCOMPARE(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2), qint64(ba2.size())); + QCOMPARE(stringBuf[0], ba2.at(0)); - QVERIFY(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2) == (ba3.size() + ba4.size() - + ba2.size())); - QVERIFY(QByteArray(stringBuf, int(strlen(stringBuf))) == (ba3 + ba4 + ba2)); - QVERIFY(ringBuffer.size() == 0); + QCOMPARE(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2), + qint64(ba3.size() + ba4.size() + ba2.size())); + QCOMPARE(QByteArray(stringBuf, int(strlen(stringBuf))), ba3 + ba4 + ba2); + QCOMPARE(ringBuffer.size(), Q_INT64_C(0)); } QTEST_APPLESS_MAIN(tst_QRingBuffer) diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index f13d69514a..ef0ebabd66 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -73,6 +73,7 @@ private slots: void makeSureTheComfortFunctionsCompile(); void initializerList(); void qhash(); + void intersects(); }; struct IdentityTracker { @@ -1030,6 +1031,32 @@ void tst_QSet::qhash() } } +void tst_QSet::intersects() +{ + QSet<int> s1; + QSet<int> s2; + + QVERIFY(!s1.intersects(s1)); + QVERIFY(!s1.intersects(s2)); + + s1 << 100; + QVERIFY(s1.intersects(s1)); + QVERIFY(!s1.intersects(s2)); + + s2 << 200; + QVERIFY(!s1.intersects(s2)); + + s1 << 200; + QVERIFY(s1.intersects(s2)); + + const QtQHashSeedSaver seedSaver(0x10101010); + QSet<int> s3; + s3 << 500; + QVERIFY(!s1.intersects(s3)); + s3 << 200; + QVERIFY(s1.intersects(s3)); +} + QTEST_APPLESS_MAIN(tst_QSet) #include "tst_qset.moc" diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 6d4dbab1fd..745cbbfad3 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -60,11 +60,241 @@ #include <qhash.h> #include <string> +#include <algorithm> #define CREATE_REF(string) \ const QString padded = QString::fromLatin1(" %1 ").arg(string); \ QStringRef ref = padded.midRef(1, padded.size() - 2); +namespace { + +// this wraps an argument to a QString function, as well as how to apply +// the argument to a given QString member function. +template <typename T> +class Arg; + +template <typename T> +class Reversed {}; // marker for Arg<QChar> to apply the operation in reverse order (for prepend()) + +class ArgBase +{ +protected: + QString pinned; + explicit ArgBase(const char *str) + : pinned(QString::fromLatin1(str)) {} +}; + +template <> +class Arg<QChar> : protected ArgBase +{ +public: + explicit Arg(const char *str) : ArgBase(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { Q_FOREACH (QChar ch, this->pinned) (s.*mf)(ch); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { Q_FOREACH (QChar ch, this->pinned) (s.*mf)(a1, ch); } +}; + +template <> +class Arg<Reversed<QChar> > : private Arg<QChar> +{ +public: + explicit Arg(const char *str) : Arg<QChar>(str) + { + std::reverse(this->pinned.begin(), this->pinned.end()); + } + + using Arg<QChar>::apply0; + using Arg<QChar>::apply1; +}; + +template <> +class Arg<QString> : ArgBase +{ +public: + explicit Arg(const char *str) : ArgBase(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { (s.*mf)(this->pinned); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { (s.*mf)(a1, this->pinned); } +}; + +template <> +class Arg<QStringRef> : ArgBase +{ + QStringRef ref() const + { return this->pinned.isNull() ? QStringRef() : this->pinned.midRef(0) ; } +public: + explicit Arg(const char *str) : ArgBase(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { (s.*mf)(ref()); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { (s.*mf)(a1, ref()); } +}; + +template <> +class Arg<QPair<const QChar *, int> > : ArgBase +{ +public: + explicit Arg(const char *str) : ArgBase(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { (s.*mf)(this->pinned.constData(), this->pinned.length()); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { (s.*mf)(a1, this->pinned.constData(), this->pinned.length()); } +}; + +template <> +class Arg<QLatin1String> +{ + QLatin1String l1; +public: + explicit Arg(const char *str) : l1(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { (s.*mf)(l1); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { (s.*mf)(a1, l1); } +}; + +template <> +class Arg<char> +{ +protected: + const char *str; +public: + explicit Arg(const char *str) : str(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { + if (str) { + for (const char *it = str; *it; ++it) + (s.*mf)(*it); + } + } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { + if (str) { + for (const char *it = str; *it; ++it) + (s.*mf)(a1, *it); + } + } +}; + +template <> +class Arg<Reversed<char> > : private Arg<char> +{ + static const char *dupAndReverse(const char *s) + { + char *s2 = qstrdup(s); + std::reverse(s2, s2 + qstrlen(s2)); + return s2; + } +public: + explicit Arg(const char *str) : Arg<char>(dupAndReverse(str)) {} + ~Arg() { delete[] str; } + + using Arg<char>::apply0; + using Arg<char>::apply1; +}; + +template <> +class Arg<const char*> +{ + const char *str; +public: + explicit Arg(const char *str) : str(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { (s.*mf)(str); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { (s.*mf)(a1, str); } +}; + +template <> +class Arg<QByteArray> +{ + QByteArray ba; +public: + explicit Arg(const char *str) : ba(str) {} + + template <typename MemFun> + void apply0(QString &s, MemFun mf) const + { (s.*mf)(ba); } + + template <typename MemFun, typename A1> + void apply1(QString &s, MemFun mf, A1 a1) const + { (s.*mf)(a1, ba); } +}; + +// const char* is not allowed as columns in data-driven tests (causes static_assert failure), +// so wrap it in a container (default ctor is a QMetaType/QVariant requirement): +class CharStarContainer +{ + const char *str; +public: + explicit Q_DECL_CONSTEXPR CharStarContainer(const char *s = Q_NULLPTR) : str(s) {} + Q_DECL_CONSTEXPR operator const char *() const { return str; } +}; + +} // unnamed namespace + +Q_DECLARE_METATYPE(CharStarContainer) + +// implementation helpers for append_impl/prepend_impl etc +template <typename ArgType, typename MemFun> +static void do_apply0(MemFun mf) +{ + QFETCH(QString, s); + QFETCH(CharStarContainer, arg); + QFETCH(QString, expected); + + Arg<ArgType>(arg).apply0(s, mf); + + QCOMPARE(s, expected); + QCOMPARE(s.isEmpty(), expected.isEmpty()); + QCOMPARE(s.isNull(), expected.isNull()); +} + +template <typename ArgType, typename A1, typename MemFun> +static void do_apply1(MemFun mf) +{ + QFETCH(QString, s); + QFETCH(CharStarContainer, arg); + QFETCH(A1, a1); + QFETCH(QString, expected); + + Arg<ArgType>(arg).apply1(s, mf, a1); + + QCOMPARE(s, expected); + QCOMPARE(s.isEmpty(), expected.isEmpty()); + QCOMPARE(s.isNull(), expected.isNull()); +} + class tst_QString : public QObject { Q_OBJECT @@ -73,6 +303,27 @@ class tst_QString : public QObject void split_regexp(const QString &string, const QString &pattern, QStringList result); template<typename List> void split(const QString &string, const QString &separator, QStringList result); + + template <typename ArgType, typename MemFun> + void append_impl() const { do_apply0<ArgType>(MemFun(&QString::append)); } + template <typename ArgType> + void append_impl() const { append_impl<ArgType, QString &(QString::*)(const ArgType&)>(); } + void append_data(bool emptyIsNoop = false); + template <typename ArgType, typename MemFun> + void operator_pluseq_impl() const { do_apply0<ArgType>(MemFun(&QString::operator+=)); } + template <typename ArgType> + void operator_pluseq_impl() const { operator_pluseq_impl<ArgType, QString &(QString::*)(const ArgType&)>(); } + void operator_pluseq_data(bool emptyIsNoop = false); + template <typename ArgType, typename MemFun> + void prepend_impl() const { do_apply0<ArgType>(MemFun(&QString::prepend)); } + template <typename ArgType> + void prepend_impl() const { prepend_impl<ArgType, QString &(QString::*)(const ArgType&)>(); } + void prepend_data(bool emptyIsNoop = false); + template <typename ArgType, typename MemFun> + void insert_impl() const { do_apply1<ArgType, int>(MemFun(&QString::insert)); } + template <typename ArgType> + void insert_impl() const { insert_impl<ArgType, QString &(QString::*)(int, const ArgType&)>(); } + void insert_data(bool emptyIsNoop = false); public: tst_QString(); public slots: @@ -121,19 +372,86 @@ private slots: void remove_regexp_data(); void remove_regexp(); void swap(); - void prepend(); - void prepend_bytearray_data(); - void prepend_bytearray(); - void append(); - void append_bytearray_data(); - void append_bytearray(); - void operator_pluseq_bytearray_data(); - void operator_pluseq_bytearray(); + + void prepend_qstring() { prepend_impl<QString>(); } + void prepend_qstring_data() { prepend_data(true); } + void prepend_qstringref() { prepend_impl<QStringRef>(); } + void prepend_qstringref_data() { prepend_data(true); } + void prepend_qlatin1string() { prepend_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); } + void prepend_qlatin1string_data() { prepend_data(true); } + void prepend_qcharstar_int() { prepend_impl<QPair<const QChar *, int>, QString &(QString::*)(const QChar *, int)>(); } + void prepend_qcharstar_int_data() { prepend_data(true); } + void prepend_qchar() { prepend_impl<Reversed<QChar>, QString &(QString::*)(QChar)>(); } + void prepend_qchar_data() { prepend_data(true); } + void prepend_qbytearray() { prepend_impl<QByteArray>(); } + void prepend_qbytearray_data() { prepend_data(true); } + void prepend_char() { prepend_impl<Reversed<char>, QString &(QString::*)(QChar)>(); } + void prepend_char_data() { prepend_data(true); } + void prepend_charstar() { prepend_impl<const char *, QString &(QString::*)(const char *)>(); } + void prepend_charstar_data() { prepend_data(true); } + void prepend_bytearray_special_cases_data(); + void prepend_bytearray_special_cases(); + + void append_qstring() { append_impl<QString>(); } + void append_qstring_data() { append_data(); } + void append_qstringref() { append_impl<QStringRef>(); } + void append_qstringref_data() { append_data(); } + void append_qlatin1string() { append_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); } + void append_qlatin1string_data() { append_data(); } + void append_qcharstar_int() { append_impl<QPair<const QChar *, int>, QString&(QString::*)(const QChar *, int)>(); } + void append_qcharstar_int_data() { append_data(true); } + void append_qchar() { append_impl<QChar, QString &(QString::*)(QChar)>(); } + void append_qchar_data() { append_data(true); } + void append_qbytearray() { append_impl<QByteArray>(); } + void append_qbytearray_data() { append_data(); } + void append_char() { append_impl<char, QString &(QString::*)(QChar)>(); } + void append_char_data() { append_data(true); } + void append_charstar() { append_impl<const char *, QString &(QString::*)(const char *)>(); } + void append_charstar_data() { append_data(); } + void append_special_cases(); + void append_bytearray_special_cases_data(); + void append_bytearray_special_cases(); + + void operator_pluseq_qstring() { operator_pluseq_impl<QString>(); } + void operator_pluseq_qstring_data() { operator_pluseq_data(); } + void operator_pluseq_qstringref() { operator_pluseq_impl<QStringRef>(); } + void operator_pluseq_qstringref_data() { operator_pluseq_data(); } + void operator_pluseq_qlatin1string() { operator_pluseq_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); } + void operator_pluseq_qlatin1string_data() { operator_pluseq_data(); } + void operator_pluseq_qchar() { operator_pluseq_impl<QChar, QString &(QString::*)(QChar)>(); } + void operator_pluseq_qchar_data() { operator_pluseq_data(true); } + void operator_pluseq_qbytearray() { operator_pluseq_impl<QByteArray>(); } + void operator_pluseq_qbytearray_data() { operator_pluseq_data(); } + void operator_pluseq_char() { operator_pluseq_impl<char, QString &(QString::*)(char)>(); } + void operator_pluseq_char_data() { operator_pluseq_data(true); } + void operator_pluseq_charstar() { operator_pluseq_impl<const char *, QString &(QString::*)(const char *)>(); } + void operator_pluseq_charstar_data() { operator_pluseq_data(); } + void operator_pluseq_bytearray_special_cases_data(); + void operator_pluseq_bytearray_special_cases(); + void operator_eqeq_bytearray_data(); void operator_eqeq_bytearray(); void operator_eqeq_nullstring(); void operator_smaller(); - void insert(); + + void insert_qstring() { insert_impl<QString>(); } + void insert_qstring_data() { insert_data(true); } + void insert_qstringref() { insert_impl<QStringRef>(); } + void insert_qstringref_data() { insert_data(true); } + void insert_qlatin1string() { insert_impl<QLatin1String, QString &(QString::*)(int, QLatin1String)>(); } + void insert_qlatin1string_data() { insert_data(true); } + void insert_qcharstar_int() { insert_impl<QPair<const QChar *, int>, QString &(QString::*)(int, const QChar*, int) >(); } + void insert_qcharstar_int_data() { insert_data(true); } + void insert_qchar() { insert_impl<Reversed<QChar>, QString &(QString::*)(int, QChar)>(); } + void insert_qchar_data() { insert_data(true); } + void insert_qbytearray() { insert_impl<QByteArray>(); } + void insert_qbytearray_data() { insert_data(true); } + void insert_char() { insert_impl<Reversed<char>, QString &(QString::*)(int, QChar)>(); } + void insert_char_data() { insert_data(true); } + void insert_charstar() { insert_impl<const char *, QString &(QString::*)(int, const char*) >(); } + void insert_charstar_data() { insert_data(true); } + void insert_special_cases(); + void simplified_data(); void simplified(); void trimmed(); @@ -183,6 +501,7 @@ private slots: void fromLocal8Bit(); void local8Bit_data(); void local8Bit(); + void nullFromLocal8Bit(); void fromLatin1Roundtrip_data(); void fromLatin1Roundtrip(); void toLatin1Roundtrip_data(); @@ -215,6 +534,7 @@ private slots: void localeAwareCompare_data(); void localeAwareCompare(); #endif + void reverseIterators(); void split_data(); void split(); void split_regexp_data(); @@ -827,7 +1147,7 @@ void tst_QString::constructorQByteArray_data() ba1[5] = 'e'; ba1[6] = 'f'; - QTest::newRow( "2" ) << ba1 << QString("abc"); + QTest::newRow( "2" ) << ba1 << QStringLiteral("abc\0def"); QTest::newRow( "3" ) << QByteArray::fromRawData("abcd", 3) << QString("abc"); QTest::newRow( "4" ) << QByteArray("\xc3\xa9") << QString("\xc3\xa9"); @@ -848,12 +1168,6 @@ void tst_QString::constructorQByteArray() QCOMPARE( strBA, expected ); // test operator= too - if (src.constData()[src.length()] == '\0') { - str1.clear(); - str1 = src.constData(); - QCOMPARE( str1, expected ); - } - strBA.clear(); strBA = src; QCOMPARE( strBA, expected ); @@ -2066,7 +2380,46 @@ void tst_QString::simplified() QCOMPARE(qMove(full).simplified(), simple); } -void tst_QString::insert() +void tst_QString::insert_data(bool emptyIsNoop) +{ + QTest::addColumn<QString>("s"); + QTest::addColumn<CharStarContainer>("arg"); + QTest::addColumn<int>("a1"); + QTest::addColumn<QString>("expected"); + + const CharStarContainer nullC; + const CharStarContainer emptyC(""); + const CharStarContainer aC("a"); + const CharStarContainer bC("b"); + //const CharStarContainer abC("ab"); + const CharStarContainer baC("ba"); + + const QString null; + const QString empty(""); + const QString a("a"); + const QString b("b"); + const QString ab("ab"); + const QString ba("ba"); + + QTest::newRow("null.insert(0, null)") << null << nullC << 0 << null; + QTest::newRow("null.insert(0, empty)") << null << emptyC << 0 << (emptyIsNoop ? null : empty); + QTest::newRow("null.insert(0, a)") << null << aC << 0 << a; + QTest::newRow("empty.insert(0, null)") << empty << nullC << 0 << empty; + QTest::newRow("empty.insert(0, empty)") << empty << emptyC << 0 << empty; + QTest::newRow("empty.insert(0, a)") << empty << aC << 0 << a; + QTest::newRow("a.insert(0, null)") << a << nullC << 0 << a; + QTest::newRow("a.insert(0, empty)") << a << emptyC << 0 << a; + QTest::newRow("a.insert(0, b)") << a << bC << 0 << ba; + QTest::newRow("a.insert(0, ba)") << a << baC << 0 << (ba + a); + QTest::newRow("a.insert(1, null)") << a << nullC << 1 << a; + QTest::newRow("a.insert(1, empty)") << a << emptyC << 1 << a; + QTest::newRow("a.insert(1, b)") << a << bC << 1 << ab; + QTest::newRow("a.insert(1, ba)") << a << baC << 1 << (a + ba); + QTest::newRow("ba.insert(1, a)") << ba << aC << 1 << (ba + a); + QTest::newRow("ba.insert(2, b)") << ba << bC << 2 << (ba + b); +} + +void tst_QString::insert_special_cases() { QString a; @@ -2097,14 +2450,37 @@ void tst_QString::insert() QCOMPARE(a.insert(0, QLatin1String("a")), QString("aMontreal")); } -void tst_QString::append() +void tst_QString::append_data(bool emptyIsNoop) { - { - QString a; - a = "<>ABCABCABCABC"; - QCOMPARE(a.append(">"),QString("<>ABCABCABCABC>")); - } + QTest::addColumn<QString>("s"); + QTest::addColumn<CharStarContainer>("arg"); + QTest::addColumn<QString>("expected"); + + const CharStarContainer nullC; + const CharStarContainer emptyC(""); + const CharStarContainer aC("a"); + const CharStarContainer bC("b"); + //const CharStarContainer abC("ab"); + const QString null; + const QString empty(""); + const QString a("a"); + //const QString b("b"); + const QString ab("ab"); + + QTest::newRow("null + null") << null << nullC << null; + QTest::newRow("null + empty") << null << emptyC << (emptyIsNoop ? null : empty); + QTest::newRow("null + a") << null << aC << a; + QTest::newRow("empty + null") << empty << nullC << empty; + QTest::newRow("empty + empty") << empty << emptyC << empty; + QTest::newRow("empty + a") << empty << aC << a; + QTest::newRow("a + null") << a << nullC << a; + QTest::newRow("a + empty") << a << emptyC << a; + QTest::newRow("a + b") << a << bC << ab; +} + +void tst_QString::append_special_cases() +{ { QString a; static const QChar unicode[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!' }; @@ -2124,7 +2500,7 @@ void tst_QString::append() } } -void tst_QString::append_bytearray_data() +void tst_QString::append_bytearray_special_cases_data() { QTest::addColumn<QString>("str" ); QTest::addColumn<QByteArray>("ba" ); @@ -2158,7 +2534,7 @@ void tst_QString::append_bytearray_data() QTest::newRow( "nonAsciiByteArray2") << QString() << QByteArray("\xc3\xa9") << QString::fromUtf8("\xc3\xa9"); } -void tst_QString::append_bytearray() +void tst_QString::append_bytearray_special_cases() { { QFETCH( QString, str ); @@ -2176,22 +2552,19 @@ void tst_QString::append_bytearray() QTEST( str, "res" ); } +} - QFETCH( QByteArray, ba ); - if (ba.constData()[ba.length()] == '\0') { - QFETCH( QString, str ); - - str.append(ba.constData()); - QTEST( str, "res" ); - } +void tst_QString::operator_pluseq_data(bool emptyIsNoop) +{ + append_data(emptyIsNoop); } -void tst_QString::operator_pluseq_bytearray_data() +void tst_QString::operator_pluseq_bytearray_special_cases_data() { - append_bytearray_data(); + append_bytearray_special_cases_data(); } -void tst_QString::operator_pluseq_bytearray() +void tst_QString::operator_pluseq_bytearray_special_cases() { { QFETCH( QString, str ); @@ -2209,14 +2582,6 @@ void tst_QString::operator_pluseq_bytearray() QTEST( str, "res" ); } - - QFETCH( QByteArray, ba ); - if (ba.constData()[ba.length()] == '\0') { - QFETCH( QString, str ); - - str += ba.constData(); - QTEST( str, "res" ); - } } void tst_QString::operator_eqeq_bytearray_data() @@ -2231,11 +2596,6 @@ void tst_QString::operator_eqeq_bytearray() QVERIFY(expected == src); QVERIFY(!(expected != src)); - - if (src.constData()[src.length()] == '\0') { - QVERIFY(expected == src.constData()); - QVERIFY(!(expected != src.constData())); - } } void tst_QString::swap() @@ -2248,14 +2608,37 @@ void tst_QString::swap() QCOMPARE(s2,QLatin1String("s1")); } -void tst_QString::prepend() +void tst_QString::prepend_data(bool emptyIsNoop) { - QString a; - a = "<>ABCABCABCABC>"; - QCOMPARE(a.prepend("-"),(QString)"-<>ABCABCABCABC>"); + QTest::addColumn<QString>("s"); + QTest::addColumn<CharStarContainer>("arg"); + QTest::addColumn<QString>("expected"); + + const CharStarContainer nullC; + const CharStarContainer emptyC(""); + const CharStarContainer aC("a"); + const CharStarContainer bC("b"); + const CharStarContainer baC("ba"); + + const QString null; + const QString empty(""); + const QString a("a"); + //const QString b("b"); + const QString ba("ba"); + + QTest::newRow("null.prepend(null)") << null << nullC << null; + QTest::newRow("null.prepend(empty)") << null << emptyC << (emptyIsNoop ? null : empty); + QTest::newRow("null.prepend(a)") << null << aC << a; + QTest::newRow("empty.prepend(null)") << empty << nullC << empty; + QTest::newRow("empty.prepend(empty)") << empty << emptyC << empty; + QTest::newRow("empty.prepend(a)") << empty << aC << a; + QTest::newRow("a.prepend(null)") << a << nullC << a; + QTest::newRow("a.prepend(empty)") << a << emptyC << a; + QTest::newRow("a.prepend(b)") << a << bC << ba; + QTest::newRow("a.prepend(ba)") << a << baC << (ba + a); } -void tst_QString::prepend_bytearray_data() +void tst_QString::prepend_bytearray_special_cases_data() { QTest::addColumn<QString>("str" ); QTest::addColumn<QByteArray>("ba" ); @@ -2270,7 +2653,7 @@ void tst_QString::prepend_bytearray_data() // byte array with only a 0 ba.resize( 1 ); ba[0] = 0; - QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QString("foobar "); + QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QStringLiteral("\0foobar "); // empty byte array ba.resize( 0 ); @@ -2281,7 +2664,7 @@ void tst_QString::prepend_bytearray_data() QTest::newRow( "nonAsciiByteArray2") << QString() << QByteArray("\xc3\xa9") << QString::fromUtf8("\xc3\xa9"); } -void tst_QString::prepend_bytearray() +void tst_QString::prepend_bytearray_special_cases() { { QFETCH( QString, str ); @@ -2300,14 +2683,6 @@ void tst_QString::prepend_bytearray() QTEST( str, "res" ); } - - QFETCH( QByteArray, ba ); - if (ba.constData()[ba.length()] == '\0') { - QFETCH( QString, str ); - - str.prepend(ba.constData()); - QTEST( str, "res" ); - } } void tst_QString::replace_uint_uint() @@ -3697,6 +4072,12 @@ void tst_QString::nullFromUtf8() a = QString::fromUtf8(""); QVERIFY(!a.isNull()); QVERIFY(a.isEmpty()); + a = QString::fromUtf8(QByteArray()); + QVERIFY(a.isNull()); + QVERIFY(a.isEmpty()); + a = QString::fromUtf8(QByteArray("")); + QVERIFY(!a.isNull()); + QVERIFY(a.isEmpty()); } void tst_QString::fromLocal8Bit_data() @@ -3779,6 +4160,23 @@ void tst_QString::local8Bit() QCOMPARE(local8Bit.toLocal8Bit(), QByteArray(result)); } +void tst_QString::nullFromLocal8Bit() +{ + QString a; + a = QString::fromLocal8Bit(0); + QVERIFY(a.isNull()); + QVERIFY(a.isEmpty()); + a = QString::fromLocal8Bit(""); + QVERIFY(!a.isNull()); + QVERIFY(a.isEmpty()); + a = QString::fromLocal8Bit(QByteArray()); + QVERIFY(a.isNull()); + QVERIFY(a.isEmpty()); + a = QString::fromLocal8Bit(QByteArray("")); + QVERIFY(!a.isNull()); + QVERIFY(a.isEmpty()); +} + void tst_QString::stringRef_local8Bit_data() { local8Bit_data(); @@ -3945,6 +4343,12 @@ void tst_QString::fromLatin1() a = QString::fromLatin1( "" ); QVERIFY( !a.isNull() ); QVERIFY( a.isEmpty() ); + a = QString::fromLatin1(QByteArray()); + QVERIFY(a.isNull()); + QVERIFY(a.isEmpty()); + a = QString::fromLatin1(QByteArray("")); + QVERIFY(!a.isNull()); + QVERIFY(a.isEmpty()); a = QString::fromLatin1(0, 0); QVERIFY(a.isNull()); @@ -4996,6 +5400,20 @@ void tst_QString::localeAwareCompare() } #endif //!defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE) +void tst_QString::reverseIterators() +{ + QString s = "1234"; + QString sr = s; + std::reverse(sr.begin(), sr.end()); + const QString &csr = sr; + QVERIFY(std::equal(s.begin(), s.end(), sr.rbegin())); + QVERIFY(std::equal(s.begin(), s.end(), sr.crbegin())); + QVERIFY(std::equal(s.begin(), s.end(), csr.rbegin())); + QVERIFY(std::equal(sr.rbegin(), sr.rend(), s.begin())); + QVERIFY(std::equal(sr.crbegin(), sr.crend(), s.begin())); + QVERIFY(std::equal(csr.rbegin(), csr.rend(), s.begin())); +} + void tst_QString::split_data() { QTest::addColumn<QString>("str"); diff --git a/tests/auto/corelib/tools/qstring/tst_qstring_mac.mm b/tests/auto/corelib/tools/qstring/tst_qstring_mac.mm index f4b748e62a..550f835bea 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring_mac.mm +++ b/tests/auto/corelib/tools/qstring/tst_qstring_mac.mm @@ -55,23 +55,19 @@ void tst_QString_macTypes() } // QString <-> NSString { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QString qtString("test string"); const NSString *nsString = qtString.toNSString(); QCOMPARE(QString::fromNSString(nsString), qtString); - - [pool release]; } { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; QString qtString("test string"); const NSString *nsString = qtString.toNSString(); QString qtStringCopy(qtString); qtString = qtString.toUpper(); // modify QCOMPARE(QString::fromNSString(nsString), qtStringCopy); - - [pool release]; } } diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp index 7fc855a359..82d103c460 100644 --- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp @@ -82,6 +82,7 @@ private slots: void integer_conversion_data(); void integer_conversion(); void trimmed(); + void truncate(); void left(); void right(); void mid(); @@ -1839,6 +1840,30 @@ void tst_QStringRef::trimmed() QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0); } +void tst_QStringRef::truncate() +{ + const QString str = "OriginalString~"; + const QStringRef cref = str.midRef(0); + { + QStringRef ref = cref; + ref.truncate(1000); + QCOMPARE(ref, cref); + for (int i = str.size(); i >= 0; --i) { + ref.truncate(i); + QCOMPARE(ref.size(), i); + QCOMPARE(ref, cref.left(i)); + } + QVERIFY(ref.isEmpty()); + } + + { + QStringRef ref = cref; + QVERIFY(!ref.isEmpty()); + ref.truncate(-1); + QVERIFY(ref.isEmpty()); + } +} + void tst_QStringRef::left() { QString originalString = "OrginalString~"; diff --git a/tests/auto/corelib/tools/qtimeline/BLACKLIST b/tests/auto/corelib/tools/qtimeline/BLACKLIST new file mode 100644 index 0000000000..b5861756d8 --- /dev/null +++ b/tests/auto/corelib/tools/qtimeline/BLACKLIST @@ -0,0 +1,4 @@ +[interpolation] +windows +[duration] +windows diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp index 975ed129fc..507f7e3992 100644 --- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp +++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp @@ -208,7 +208,7 @@ void tst_QTimeLine::frameRate() timeLine.start(); QTest::qWait(timeLine.duration()*2); QCOMPARE(timeLine.state(), QTimeLine::NotRunning); - QVERIFY(slowCount < spy.count()); + QVERIFY2(slowCount < spy.count(), QByteArray::number(spy.count())); } void tst_QTimeLine::value() diff --git a/tests/auto/corelib/tools/qtimezone/BLACKLIST b/tests/auto/corelib/tools/qtimezone/BLACKLIST new file mode 100644 index 0000000000..665e78bc08 --- /dev/null +++ b/tests/auto/corelib/tools/qtimezone/BLACKLIST @@ -0,0 +1,2 @@ +[tzTest] +opensuse-13.1 diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 94d81e0a5a..82f78b2b0b 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -47,10 +47,12 @@ private slots: void appendCausingRealloc(); void resize(); void realloc(); + void reverseIterators(); void count(); void first(); void last(); void squeeze(); + void operators(); void indexOf(); void lastIndexOf(); void contains(); @@ -563,6 +565,21 @@ void tst_QVarLengthArray::realloc() QVERIFY(reallocTestProceed); } +void tst_QVarLengthArray::reverseIterators() +{ + QVarLengthArray<int> v; + v << 1 << 2 << 3 << 4; + QVarLengthArray<int> vr = v; + std::reverse(vr.begin(), vr.end()); + const QVarLengthArray<int> &cvr = vr; + QVERIFY(std::equal(v.begin(), v.end(), vr.rbegin())); + QVERIFY(std::equal(v.begin(), v.end(), vr.crbegin())); + QVERIFY(std::equal(v.begin(), v.end(), cvr.rbegin())); + QVERIFY(std::equal(vr.rbegin(), vr.rend(), v.begin())); + QVERIFY(std::equal(vr.crbegin(), vr.crend(), v.begin())); + QVERIFY(std::equal(cvr.rbegin(), cvr.rend(), v.begin())); +} + void tst_QVarLengthArray::count() { // tests size(), count() and length(), since they're the same thing @@ -691,6 +708,49 @@ void tst_QVarLengthArray::squeeze() QCOMPARE(list.capacity(), sizeOnHeap); } +void tst_QVarLengthArray::operators() +{ + QVarLengthArray<QString> myvla; + myvla << "A" << "B" << "C"; + QVarLengthArray<QString> myvlatwo; + myvlatwo << "D" << "E" << "F"; + QVarLengthArray<QString> combined; + combined << "A" << "B" << "C" << "D" << "E" << "F"; + + // != + QVERIFY(myvla != myvlatwo); + + // +=: not provided, emulate + //myvla += myvlatwo; + Q_FOREACH (const QString &s, myvlatwo) + myvla.push_back(s); + QCOMPARE(myvla, combined); + + // == + QVERIFY(myvla == combined); + + // <, >, <=, >= + QVERIFY(!(myvla < combined)); + QVERIFY(!(myvla > combined)); + QVERIFY( myvla <= combined); + QVERIFY( myvla >= combined); + combined.push_back("G"); + QVERIFY( myvla < combined); + QVERIFY(!(myvla > combined)); + QVERIFY( myvla <= combined); + QVERIFY(!(myvla >= combined)); + QVERIFY(combined > myvla); + QVERIFY(combined >= myvla); + + // [] + QCOMPARE(myvla[0], QLatin1String("A")); + QCOMPARE(myvla[1], QLatin1String("B")); + QCOMPARE(myvla[2], QLatin1String("C")); + QCOMPARE(myvla[3], QLatin1String("D")); + QCOMPARE(myvla[4], QLatin1String("E")); + QCOMPARE(myvla[5], QLatin1String("F")); +} + void tst_QVarLengthArray::indexOf() { QVarLengthArray<QString> myvec; diff --git a/tests/auto/corelib/tools/qvector/qvector.pro b/tests/auto/corelib/tools/qvector/qvector.pro index 22edde3412..c1e0564915 100644 --- a/tests/auto/corelib/tools/qvector/qvector.pro +++ b/tests/auto/corelib/tools/qvector/qvector.pro @@ -1,4 +1,5 @@ CONFIG += testcase parallel_test +contains(QT_CONFIG, c++11):CONFIG += c++11 TARGET = tst_qvector QT = core testlib SOURCES = $$PWD/tst_qvector.cpp diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 69da6e450e..87822bca6f 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -86,6 +86,8 @@ private: } }; +inline uint qHash(const Movable &key, uint seed = 0) { return qHash(key.i, seed); } + QAtomicInt Movable::counter = 0; QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE); @@ -123,6 +125,13 @@ struct Custom { return i == other.i; } + bool operator<(const Custom &other) const + { + check(&other); + check(this); + return i < other.i; + } + Custom &operator=(const Custom &other) { check(&other); @@ -148,6 +157,8 @@ private: }; QAtomicInt Custom::counter = 0; +inline uint qHash(const Custom &key, uint seed = 0) { return qHash(key.i, seed); } + Q_DECLARE_METATYPE(Custom); // tests depends on the fact that: @@ -179,6 +190,7 @@ private slots: void appendInt() const; void appendMovable() const; void appendCustom() const; + void appendRvalue() const; void at() const; void capacityInt() const; void capacityMovable() const; @@ -187,6 +199,8 @@ private slots: void clearMovable() const; void clearCustom() const; void constData() const; + void constFirst() const; + void constLast() const; void contains() const; void countInt() const; void countMovable() const; @@ -227,9 +241,15 @@ private slots: void last() const; void lastIndexOf() const; void mid() const; + void moveInt() const; + void moveMovable() const; + void moveCustom() const; void prependInt() const; void prependMovable() const; void prependCustom() const; + void qhashInt() const { qhash<int>(); } + void qhashMovable() const { qhash<Movable>(); } + void qhashCustom() const { qhash<Custom>(); } void removeInt() const; void removeMovable() const; void removeCustom() const; @@ -241,6 +261,7 @@ private slots: void resizeComplex_data() const; void resizeComplex() const; void resizeCtorAndDtor() const; + void reverseIterators() const; void sizeInt() const; void sizeMovable() const; void sizeCustom() const; @@ -294,6 +315,8 @@ private: template<typename T> void fill() const; template<typename T> void fromList() const; template<typename T> void insert() const; + template<typename T> void qhash() const; + template<typename T> void move() const; template<typename T> void prepend() const; template<typename T> void remove() const; template<typename T> void size() const; @@ -332,6 +355,14 @@ const Movable SimpleValue<Movable>::Values[] = { 110, 105, 101, 114, 111, 98 }; template<> const Custom SimpleValue<Custom>::Values[] = { 110, 105, 101, 114, 111, 98 }; +// Make some macros for the tests to use in order to be slightly more readable... +#define T_FOO SimpleValue<T>::at(0) +#define T_BAR SimpleValue<T>::at(1) +#define T_BAZ SimpleValue<T>::at(2) +#define T_CAT SimpleValue<T>::at(3) +#define T_DOG SimpleValue<T>::at(4) +#define T_BLAH SimpleValue<T>::at(5) + void tst_QVector::constructors_empty() const { QVector<int> emptyInt; @@ -608,6 +639,21 @@ void tst_QVector::appendCustom() const QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } +void tst_QVector::appendRvalue() const +{ +#ifdef Q_COMPILER_RVALUE_REFS + QVector<QString> v; + v.append("hello"); + QString world = "world"; + v.append(std::move(world)); + QVERIFY(world.isEmpty()); + QCOMPARE(v.front(), QString("hello")); + QCOMPARE(v.back(), QString("world")); +#else + QSKIP("This test requires that C++11 move semantics support is enabled in the compiler"); +#endif +} + void tst_QVector::at() const { QVector<QString> myvec; @@ -1206,16 +1252,86 @@ void tst_QVector::first() const // test it starts ok QCOMPARE(myvec.first(), 69); + QCOMPARE(myvec.constFirst(), 69); // test removal changes myvec.remove(0); QCOMPARE(myvec.first(), 42); + QCOMPARE(myvec.constFirst(), 42); // test prepend changes myvec.prepend(23); QCOMPARE(myvec.first(), 23); + QCOMPARE(myvec.constFirst(), 23); +} + +void tst_QVector::constFirst() const +{ + QVector<int> myvec; + myvec << 69 << 42 << 3; + + // test it starts ok + QCOMPARE(myvec.constFirst(), 69); + QVERIFY(myvec.isDetached()); + + QVector<int> myvecCopy = myvec; + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + QCOMPARE(myvec.constFirst(), 69); + QCOMPARE(myvecCopy.constFirst(), 69); + + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + // test removal changes + myvec.remove(0); + QVERIFY(myvec.isDetached()); + QVERIFY(!myvec.isSharedWith(myvecCopy)); + QCOMPARE(myvec.constFirst(), 42); + QCOMPARE(myvecCopy.constFirst(), 69); + + myvecCopy = myvec; + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + QCOMPARE(myvec.constFirst(), 42); + QCOMPARE(myvecCopy.constFirst(), 42); + + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + // test prepend changes + myvec.prepend(23); + QVERIFY(myvec.isDetached()); + QVERIFY(!myvec.isSharedWith(myvecCopy)); + QCOMPARE(myvec.constFirst(), 23); + QCOMPARE(myvecCopy.constFirst(), 42); + + myvecCopy = myvec; + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + QCOMPARE(myvec.constFirst(), 23); + QCOMPARE(myvecCopy.constFirst(), 23); + + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); } + template<typename T> void tst_QVector::fromList() const { @@ -1393,14 +1509,83 @@ void tst_QVector::last() const // test starts ok QCOMPARE(myvec.last(), QLatin1String("C")); + QCOMPARE(myvec.constLast(), QLatin1String("C")); // test it changes ok myvec.append(QLatin1String("X")); QCOMPARE(myvec.last(), QLatin1String("X")); + QCOMPARE(myvec.constLast(), QLatin1String("X")); // and remove again myvec.remove(3); QCOMPARE(myvec.last(), QLatin1String("C")); + QCOMPARE(myvec.constLast(), QLatin1String("C")); +} + +void tst_QVector::constLast() const +{ + QVector<int> myvec; + myvec << 69 << 42 << 3; + + // test it starts ok + QCOMPARE(myvec.constLast(), 3); + QVERIFY(myvec.isDetached()); + + QVector<int> myvecCopy = myvec; + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + QCOMPARE(myvec.constLast(), 3); + QCOMPARE(myvecCopy.constLast(), 3); + + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + // test removal changes + myvec.removeLast(); + QVERIFY(myvec.isDetached()); + QVERIFY(!myvec.isSharedWith(myvecCopy)); + QCOMPARE(myvec.constLast(), 42); + QCOMPARE(myvecCopy.constLast(), 3); + + myvecCopy = myvec; + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + QCOMPARE(myvec.constLast(), 42); + QCOMPARE(myvecCopy.constLast(), 42); + + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + // test prepend changes + myvec.append(23); + QVERIFY(myvec.isDetached()); + QVERIFY(!myvec.isSharedWith(myvecCopy)); + QCOMPARE(myvec.constLast(), 23); + QCOMPARE(myvecCopy.constLast(), 42); + + myvecCopy = myvec; + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); + + QCOMPARE(myvec.constLast(), 23); + QCOMPARE(myvecCopy.constLast(), 23); + + QVERIFY(!myvec.isDetached()); + QVERIFY(!myvecCopy.isDetached()); + QVERIFY(myvec.isSharedWith(myvecCopy)); + QVERIFY(myvecCopy.isSharedWith(myvec)); } void tst_QVector::lastIndexOf() const @@ -1437,6 +1622,54 @@ void tst_QVector::mid() const QCOMPARE(list.mid(4), QVector<QString>() << "buck" << "hello" << "kitty"); } +template <typename T> +void tst_QVector::qhash() const +{ + QVector<T> l1, l2; + QCOMPARE(qHash(l1), qHash(l2)); + l1 << SimpleValue<T>::at(0); + l2 << SimpleValue<T>::at(0); + QCOMPARE(qHash(l1), qHash(l2)); +} + +template <typename T> +void tst_QVector::move() const +{ + QVector<T> list; + list << T_FOO << T_BAR << T_BAZ; + + // move an item + list.move(0, list.count() - 1); + QCOMPARE(list, QVector<T>() << T_BAR << T_BAZ << T_FOO); + + // move it back + list.move(list.count() - 1, 0); + QCOMPARE(list, QVector<T>() << T_FOO << T_BAR << T_BAZ); + + // move an item in the middle + list.move(1, 0); + QCOMPARE(list, QVector<T>() << T_BAR << T_FOO << T_BAZ); +} + +void tst_QVector::moveInt() const +{ + move<int>(); +} + +void tst_QVector::moveMovable() const +{ + const int instancesCount = Movable::counter.loadAcquire(); + move<Movable>(); + QCOMPARE(instancesCount, Movable::counter.loadAcquire()); +} + +void tst_QVector::moveCustom() const +{ + const int instancesCount = Custom::counter.loadAcquire(); + move<Custom>(); + QCOMPARE(instancesCount, Custom::counter.loadAcquire()); +} + template<typename T> void tst_QVector::prepend() const { @@ -1907,6 +2140,21 @@ void tst_QVector::resizeCtorAndDtor() const QCOMPARE(Custom::counter.loadAcquire(), items); } +void tst_QVector::reverseIterators() const +{ + QVector<int> v; + v << 1 << 2 << 3 << 4; + QVector<int> vr = v; + std::reverse(vr.begin(), vr.end()); + const QVector<int> &cvr = vr; + QVERIFY(std::equal(v.begin(), v.end(), vr.rbegin())); + QVERIFY(std::equal(v.begin(), v.end(), vr.crbegin())); + QVERIFY(std::equal(v.begin(), v.end(), cvr.rbegin())); + QVERIFY(std::equal(vr.rbegin(), vr.rend(), v.begin())); + QVERIFY(std::equal(vr.crbegin(), vr.crend(), v.begin())); + QVERIFY(std::equal(cvr.rbegin(), cvr.rend(), v.begin())); +} + template<typename T> void tst_QVector::size() const { @@ -2076,6 +2324,19 @@ void tst_QVector::testOperators() const // == QVERIFY(myvec == combined); + // <, >, <=, >= + QVERIFY(!(myvec < combined)); + QVERIFY(!(myvec > combined)); + QVERIFY( myvec <= combined); + QVERIFY( myvec >= combined); + combined.push_back("G"); + QVERIFY( myvec < combined); + QVERIFY(!(myvec > combined)); + QVERIFY( myvec <= combined); + QVERIFY(!(myvec >= combined)); + QVERIFY(combined > myvec); + QVERIFY(combined >= myvec); + // [] QCOMPARE(myvec[0], QLatin1String("A")); QCOMPARE(myvec[1], QLatin1String("B")); diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp index 4202b87b2d..0b8b63a1e8 100644 --- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp +++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp @@ -33,7 +33,7 @@ ****************************************************************************/ #include <QtTest/QtTest> -#include <private/qversionnumber_p.h> +#include <QtCore/qversionnumber.h> class tst_QVersionNumber : public QObject { |