From d01d08971a1ba4d66927a48577041abc5b7df8a2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 30 Jun 2015 18:15:53 -0700 Subject: Fix the remainingTime() result after the first activation of a QTimer On Windows, t->timeout was updated only once, at creation time, so the timer would always show as "overdue" after the first activation. The timer is updated to indicate the full remaining time during the slot activation, which is the behavior of the Unix and Glib dispatchers. Task-number: QTBUG-46940 Change-Id: I255870833a024a36adf6ffff13ecadb021c4358c Reviewed-by: Oswald Buddenhagen Reviewed-by: Joerg Bornemann Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 59 ++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index c7011dbc04..1d1432f600 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -54,6 +54,8 @@ private slots: void singleShotTimeout(); void timeout(); void remainingTime(); + void remainingTimeDuringActivation_data(); + void remainingTimeDuringActivation(); void livelock_data(); void livelock(); void timerInfiniteRecursion_data(); @@ -79,14 +81,16 @@ class TimerHelper : public QObject { Q_OBJECT public: - TimerHelper() : QObject(), count(0) + TimerHelper() : QObject(), count(0), remainingTime(-1) { } int count; + int remainingTime; public slots: void timeout(); + void fetchRemainingTime(); }; void TimerHelper::timeout() @@ -94,6 +98,12 @@ void TimerHelper::timeout() ++count; } +void TimerHelper::fetchRemainingTime() +{ + QTimer *timer = static_cast(sender()); + remainingTime = timer->remainingTime(); +} + void tst_QTimer::zeroTimer() { TimerHelper helper; @@ -158,6 +168,53 @@ void tst_QTimer::remainingTime() int remainingTime = timer.remainingTime(); QVERIFY2(qAbs(remainingTime - 150) < 50, qPrintable(QString::number(remainingTime))); + + // wait for the timer to actually fire now + connect(&timer, SIGNAL(timeout()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(helper.count, 1); + + // the timer is still active, so it should have a non-zero remaining time + remainingTime = timer.remainingTime(); + QVERIFY2(remainingTime > 150, qPrintable(QString::number(remainingTime))); +} + +void tst_QTimer::remainingTimeDuringActivation_data() +{ + QTest::addColumn("singleShot"); + QTest::newRow("repeating") << true; + QTest::newRow("single-shot") << true; +} + +void tst_QTimer::remainingTimeDuringActivation() +{ + QFETCH(bool, singleShot); + + TimerHelper helper; + QTimer timer; + + const int timeout = 20; // 20 ms is short enough and should not round down to 0 in any timer mode + + connect(&timer, SIGNAL(timeout()), &helper, SLOT(fetchRemainingTime())); + connect(&timer, SIGNAL(timeout()), &QTestEventLoop::instance(), SLOT(exitLoop())); + timer.start(timeout); + timer.setSingleShot(singleShot); + + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + if (singleShot) + QCOMPARE(helper.remainingTime, -1); // timer not running + else + QCOMPARE(helper.remainingTime, timeout); + + if (!singleShot) { + // do it again - see QTBUG-46940 + helper.remainingTime = -1; + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(helper.remainingTime, timeout); + } } void tst_QTimer::livelock_data() -- cgit v1.2.3 From f61de80e1f11cea088faf946fc59999936090661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Mon, 15 Jun 2015 20:02:20 +0100 Subject: QVarLengthArray: Unit-test that clear() preserves capacity Change-Id: Ib2b798b93ce9a1b77bca09b2a8c27a568ebf8670 Reviewed-by: Marc Mutz --- .../tools/qvarlengtharray/tst_qvarlengtharray.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 5d12cd9804..94d81e0a5a 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -54,6 +54,7 @@ private slots: void indexOf(); void lastIndexOf(); void contains(); + void clear(); void initializeListInt(); void initializeListMovable(); void initializeListComplex(); @@ -752,6 +753,21 @@ void tst_QVarLengthArray::contains() QVERIFY(myvec.contains(QLatin1String("I don't exist"))); } +void tst_QVarLengthArray::clear() +{ + QVarLengthArray myvec; + + for (int i = 0; i < 10; ++i) + myvec << "aaa"; + + QCOMPARE(myvec.size(), 10); + QVERIFY(myvec.capacity() >= myvec.size()); + const int oldCapacity = myvec.capacity(); + myvec.clear(); + QCOMPARE(myvec.size(), 0); + QCOMPARE(myvec.capacity(), oldCapacity); +} + void tst_QVarLengthArray::initializeListInt() { initializeList(); -- cgit v1.2.3 From 02418d1aaa6760e08d55f0f6213d02d56b057fd2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 19 May 2015 17:51:15 -0700 Subject: Set the state of QTemporaryFileEngine properly prior to reopening QTemporaryFileEngine does not store the pattern, so it needs to get it again from QTemporaryFilePrivate prior to reopening the file. It's possible to lose the pattern when remove() is called on the object. Task-number: QTBUG-46156 Change-Id: I66a35ce5f88941f29aa6ffff13dfc7f83d4fa3a2 Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: David Faure --- tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index e7325d2b8e..94e6bbaade 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -353,6 +353,7 @@ void tst_QTemporaryFile::removeAndReOpen() QVERIFY(!QFile::exists(fileName)); QVERIFY(file.open()); + QCOMPARE(QFileInfo(file.fileName()).path(), QFileInfo(fileName).path()); fileName = file.fileName(); QVERIFY(QFile::exists(fileName)); } -- cgit v1.2.3 From 3aa5ef2ea92ccede193b89acc2ba7194a04df17d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 15 Jul 2015 11:30:21 -0700 Subject: Disable thread-safe statics for MSVC 2015: they're broken An object that throws in its constructor cannot be reentered. This violates both C++11 and C++98. It's also a regression from MSVC 2013. The unit test is renamed to indicate what it really does, as opposed to a misleading name that was probably a "thinko" on my part. Task-number: QTBUG-47224 Change-Id: Ib306f8f647014b399b87ffff13f132436d0578ef Reviewed-by: Friedemann Kleint --- tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp index e6b2f8a116..a1cfff7e85 100644 --- a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp +++ b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp @@ -50,7 +50,7 @@ private Q_SLOTS: void api(); void constVolatile(); void exception(); - void threadedException(); + void catchExceptionAndRetry(); void threadStressTest(); void afterDestruction(); }; @@ -142,7 +142,7 @@ void tst_QGlobalStatic::exception() QBasicAtomicInt exceptionControlVar = Q_BASIC_ATOMIC_INITIALIZER(1); Q_GLOBAL_STATIC_WITH_ARGS(ThrowingType, exceptionGS, (exceptionControlVar)) -void tst_QGlobalStatic::threadedException() +void tst_QGlobalStatic::catchExceptionAndRetry() { if (exceptionControlVar.load() != 1) QSKIP("This test cannot be run more than once"); -- cgit v1.2.3 From 26bcc0565f49c731a4f288f93f04056ca20136a5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 14 Jul 2015 09:29:58 +0200 Subject: QDir::removeRecursively(): Retry file deletion with write permission set. On Windows, having read-only files in a directory can cause removal to fail. When file deletion fails, check on the permissions, set write permissions and retry. Split apart code paths by OS in tst_QDir::removeRecursivelyFailure(); deletion of the read-only directory on UNIX should still fail. Change-Id: I36e54be5229a7b552e90fd5f42722b868fa0b6ee Reviewed-by: David Faure --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 15 ++++++++------- tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 45289df398..72d036c2ae 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -470,21 +470,22 @@ void tst_QDir::removeRecursivelyFailure() #ifdef Q_OS_UNIX QFile dirAsFile(path); // yay, I have to use QFile to change a dir's permissions... QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions -#else - QVERIFY(file.setPermissions(QFile::ReadOwner)); -#endif + QVERIFY(!QDir().rmdir(path)); QDir dir(path); QVERIFY(!dir.removeRecursively()); // didn't work QVERIFY(dir.exists()); // still exists -#ifdef Q_OS_UNIX QVERIFY(dirAsFile.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner))); -#else - QVERIFY(file.setPermissions(QFile::ReadOwner | QFile::WriteOwner)); -#endif QVERIFY(dir.removeRecursively()); QVERIFY(!dir.exists()); +#else // Q_OS_UNIX + QVERIFY(file.setPermissions(QFile::ReadOwner)); + QVERIFY(!QDir().rmdir(path)); + QDir dir(path); + QVERIFY(dir.removeRecursively()); + QVERIFY(!dir.exists()); +#endif // !Q_OS_UNIX } void tst_QDir::removeRecursivelySymlink() diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index e144e32c77..3e98a369ce 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -215,6 +215,8 @@ void tst_QTemporaryDir::autoRemove() QFile file(dirName + "/dir1/file"); QVERIFY(file.open(QIODevice::WriteOnly)); QCOMPARE(file.write("Hello"), 5LL); + file.close(); + QVERIFY(file.setPermissions(QFile::ReadUser)); } #ifdef Q_OS_WIN QTRY_VERIFY(!QDir(dirName).exists()); -- cgit v1.2.3