From 2b098cd37d86bc7c843225412c90948affb8fef1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 19 Mar 2010 09:17:17 +1000 Subject: Test imports with realistic paths (previously passed accidentally). Fix failure when import path is ancestor dir of other import path. --- src/declarative/qml/qdeclarativeengine.cpp | 13 ++++++++++--- .../com/nokia/AutoTestQmlPluginType/qmldir | 1 - .../declarative/qdeclarativemoduleplugin/data/works.qml | 3 +++ .../imports/com/nokia/AutoTestQmlPluginType/qmldir | 1 + tests/auto/declarative/qdeclarativemoduleplugin/plugin.qml | 3 --- .../declarative/qdeclarativemoduleplugin/plugin/plugin.pro | 2 +- .../tst_qdeclarativemoduleplugin.cpp | 7 ++++--- 7 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir create mode 100644 tests/auto/declarative/qdeclarativemoduleplugin/data/works.qml create mode 100644 tests/auto/declarative/qdeclarativemoduleplugin/imports/com/nokia/AutoTestQmlPluginType/qmldir delete mode 100644 tests/auto/declarative/qdeclarativemoduleplugin/plugin.qml diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 0bedbeb..c49c464 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1418,6 +1418,11 @@ struct QDeclarativeEnginePrivate::ImportedNamespace { } }; +static bool greaterThan(const QString &s1, const QString &s2) +{ + return s1 > s2; +} + class QDeclarativeImportsPrivate { public: QDeclarativeImportsPrivate() : ref(1) @@ -1495,6 +1500,8 @@ public: // add fileImportPath last, this is *not* search order. paths += QDeclarativeEnginePrivate::get(engine)->fileImportPath; + qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents. + QString stableRelativePath = dir; foreach( QString path, paths) { if (dir.startsWith(path)) { @@ -1545,11 +1552,11 @@ public: paths += applicationDirPath; paths += QDeclarativeEnginePrivate::get(engine)->environmentImportPath; - #if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath); - #else +#else QString builtinPath; - #endif +#endif if (!builtinPath.isEmpty()) paths += builtinPath; diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir b/tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir deleted file mode 100644 index 0a8b5d4..0000000 --- a/tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin plugin diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/data/works.qml b/tests/auto/declarative/qdeclarativemoduleplugin/data/works.qml new file mode 100644 index 0000000..f29ae24 --- /dev/null +++ b/tests/auto/declarative/qdeclarativemoduleplugin/data/works.qml @@ -0,0 +1,3 @@ +import com.nokia.AutoTestQmlPluginType 1.0 + +MyPluginType { value: 123 } diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/imports/com/nokia/AutoTestQmlPluginType/qmldir b/tests/auto/declarative/qdeclarativemoduleplugin/imports/com/nokia/AutoTestQmlPluginType/qmldir new file mode 100644 index 0000000..0a8b5d4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativemoduleplugin/imports/com/nokia/AutoTestQmlPluginType/qmldir @@ -0,0 +1 @@ +plugin plugin diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/plugin.qml b/tests/auto/declarative/qdeclarativemoduleplugin/plugin.qml deleted file mode 100644 index f29ae24..0000000 --- a/tests/auto/declarative/qdeclarativemoduleplugin/plugin.qml +++ /dev/null @@ -1,3 +0,0 @@ -import com.nokia.AutoTestQmlPluginType 1.0 - -MyPluginType { value: 123 } diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro b/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro index 035cb7d..fc77225 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro +++ b/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro @@ -2,5 +2,5 @@ TEMPLATE = lib CONFIG += plugin SOURCES = plugin.cpp QT = core declarative -DESTDIR = ../com/nokia/AutoTestQmlPluginType +DESTDIR = ../imports/com/nokia/AutoTestQmlPluginType diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp index 1335c7c..26199d3 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp +++ b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp @@ -48,8 +48,8 @@ class tst_qdeclarativemoduleplugin : public QObject { Q_OBJECT public: - tst_qdeclarativemoduleplugin() { - QCoreApplication::addLibraryPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("plugin")); + tst_qdeclarativemoduleplugin() + { } private slots: @@ -103,9 +103,10 @@ void tst_qdeclarativemoduleplugin::importsPlugin() { QSKIP("Fix me", SkipAll); QDeclarativeEngine engine; + engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); QTest::ignoreMessage(QtWarningMsg, "plugin created"); QTest::ignoreMessage(QtWarningMsg, "import worked"); - QDeclarativeComponent component(&engine, TEST_FILE("plugin.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("data/works.qml")); foreach (QDeclarativeError err, component.errors()) qWarning() << err; VERIFY_ERRORS(0); -- cgit v0.12