diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-05-31 15:54:15 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-08 07:42:32 +0000 |
commit | b31e9cf4817112e5dbf567bb622fe3f70f38bfbf (patch) | |
tree | 65c2976580465d54eed01c5f4b8d418866ff2480 /tests/auto | |
parent | e80cc5dc6b02176b1339e51dc474049328e5cdbb (diff) |
tst_qqmlengine::clearComponentCache(): Use QTemporaryDir
The test used to create a file temp.qml in the working directory.
Put it into a temporary directory.
Change-Id: I0720a4b4c652c83656505a5dc979660b94503717
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 30 | ||||
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 2 |
2 files changed, 26 insertions, 6 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 07569efc72..dac6ddaebd 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -41,6 +41,7 @@ #include <QQmlNetworkAccessManagerFactory> #include <QQmlExpression> #include <QQmlIncubationController> +#include <QTemporaryDir> #include <private/qqmlengine_p.h> #include <QQmlAbstractUrlInterceptor> @@ -51,6 +52,7 @@ public: tst_qqmlengine() {} private slots: + void initTestCase() override; void rootContext(); void networkAccessManager(); void synchronousNetworkAccessManager(); @@ -80,8 +82,17 @@ public slots: static QObject *ptr = new QObject(); return ptr; } + +private: + QTemporaryDir m_tempDir; }; +void tst_qqmlengine::initTestCase() +{ + QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString())); + QQmlDataTest::initTestCase(); +} + void tst_qqmlengine::rootContext() { QQmlEngine engine; @@ -286,9 +297,12 @@ void tst_qqmlengine::clearComponentCache() { QQmlEngine engine; + const QString fileName = m_tempDir.filePath(QStringLiteral("temp.qml")); + const QUrl fileUrl = QUrl::fromLocalFile(fileName); + // Create original qml file { - QFile file("temp.qml"); + QFile file(fileName); QVERIFY(file.open(QIODevice::WriteOnly)); file.write("import QtQuick 2.0\nQtObject {\nproperty int test: 10\n}\n"); file.close(); @@ -296,7 +310,7 @@ void tst_qqmlengine::clearComponentCache() // Test "test" property { - QQmlComponent component(&engine, "temp.qml"); + QQmlComponent component(&engine, fileUrl); QObject *obj = component.create(); QVERIFY(obj != 0); QCOMPARE(obj->property("test").toInt(), 10); @@ -311,7 +325,7 @@ void tst_qqmlengine::clearComponentCache() // Similar effects of lacking precision have been observed on some Linux systems. QThread::sleep(1); - QFile file("temp.qml"); + QFile file(fileName); QVERIFY(file.open(QIODevice::WriteOnly)); file.write("import QtQuick 2.0\nQtObject {\nproperty int test: 11\n}\n"); file.close(); @@ -319,7 +333,7 @@ void tst_qqmlengine::clearComponentCache() // Test cache hit { - QQmlComponent component(&engine, "temp.qml"); + QQmlComponent component(&engine, fileUrl); QObject *obj = component.create(); QVERIFY(obj != 0); QCOMPARE(obj->property("test").toInt(), 10); @@ -331,12 +345,18 @@ void tst_qqmlengine::clearComponentCache() // Test cache refresh { - QQmlComponent component(&engine, "temp.qml"); + QQmlComponent component(&engine, fileUrl); QObject *obj = component.create(); QVERIFY(obj != 0); QCOMPARE(obj->property("test").toInt(), 11); delete obj; } + + // Regular Synchronous loading will leave us with an event posted + // to the gui thread and an extra refcount that will only be dropped after the + // event delivery. Call sendPostedEvents() to get rid of it so that + // the temporary directory can be removed. + QCoreApplication::sendPostedEvents(); } struct ComponentCacheFunctions : public QObject, public QQmlIncubationController diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 163ce11cb8..ce52afc862 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -1486,7 +1486,7 @@ void tst_qqmlvaluetypes::groupedInterceptors() QQmlComponent component(&engine, testFileUrl(qmlfile)); QObject *object = component.create(); - QVERIFY(object != 0); + QVERIFY2(object != nullptr, qPrintable(component.errorString())); QColor initialColor = object->property("color").value<QColor>(); QVERIFY(fuzzyCompare(initialColor.redF(), expectedInitialColor.redF())); |