aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qquickfolderlistmodel
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-08-05 11:13:07 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-05 12:24:29 +0200
commitc9d43466b871b5fb15fb6e3892a3176176ae2621 (patch)
treeacbe0108a91d8c9efbf23a45704fb4513d01f189 /tests/auto/qml/qquickfolderlistmodel
parentfed09b2365236522989b25e83a9bf552a682c0e4 (diff)
Fix race condition in tst_QQuickFolderListModel::basicProperties
The FLM updates its contents asynchronously using a thread, so before we query for the new properties after changing the folder, make sure the thread finished updating. Change-Id: Icbd72801f639f9dffdc0dd85fbbd8b3ee53fedda Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qquickfolderlistmodel')
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
index 9308bc6f40..cc55fd721c 100644
--- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
+++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
@@ -52,6 +52,21 @@
#include <qt_windows.h>
#endif
+static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)
+{
+ QEventLoop loop;
+ QObject::connect(obj, signal, &loop, SLOT(quit()));
+ QTimer timer;
+ QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
+ if (timeout > 0) {
+ QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ timer.setSingleShot(true);
+ timer.start(timeout);
+ }
+ loop.exec();
+ return timeoutSpy.isEmpty();
+}
+
// From qquickfolderlistmodel.h
const int FileNameRole = Qt::UserRole+1;
const int FilePathRole = Qt::UserRole+2;
@@ -116,7 +131,8 @@ void tst_qquickfolderlistmodel::basicProperties()
QVERIFY(flm != 0);
flm->setProperty("folder", dataDirectoryUrl());
- QTRY_COMPARE(flm->property("count").toInt(),5); // wait for refresh
+ ::waitForSignal(flm, SIGNAL(folderChanged()), 0);
+ QCOMPARE(flm->property("count").toInt(), 5);
QCOMPARE(flm->property("folder").toUrl(), dataDirectoryUrl());
QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(QDir(directory()).canonicalPath()));
QCOMPARE(flm->property("sortField").toInt(), int(Name));