diff options
-rw-r--r-- | src/declarative/qml/qdeclarativecompositetypemanager.cpp | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 186 |
2 files changed, 133 insertions, 59 deletions
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp index 55723ea..61978a4 100644 --- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp +++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp @@ -633,10 +633,12 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData // - type with unknown namespace (UnknownNamespace.SomeType {}) QDeclarativeError error; error.setUrl(unit->imports.baseUrl()); + QString userTypeName = QString::fromUtf8(typeName); + userTypeName.replace('/','.'); if (typeNamespace) - error.setDescription(tr("Namespace %1 cannot be used as a type").arg(QString::fromUtf8(typeName))); + error.setDescription(tr("Namespace %1 cannot be used as a type").arg(userTypeName)); else - error.setDescription(tr("%1 is not a type").arg(QString::fromUtf8(typeName))); + error.setDescription(tr("%1 is not a type").arg(userTypeName)); if (!parserRef->refObjects.isEmpty()) { QDeclarativeParser::Object *obj = parserRef->refObjects.first(); error.setLine(obj->location.start.line); diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 722e161..8990fb4 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -136,7 +136,7 @@ private slots: private: QDeclarativeEngine engine; - void testType(const QString& qml, const QString& type); + void testType(const QString& qml, const QString& type, const QString& error); }; #define VERIFY_ERRORS(errorfile) \ @@ -1069,7 +1069,7 @@ void tst_qdeclarativelanguage::declaredPropertyValues() } // Check that first child of qml is of given type. Empty type insists on error. -void tst_qdeclarativelanguage::testType(const QString& qml, const QString& type) +void tst_qdeclarativelanguage::testType(const QString& qml, const QString& type, const QString& expectederror) { QDeclarativeComponent component(&engine); component.setData(qml.toUtf8(), TEST_FILE("empty.qml")); // just a file for relative local imports @@ -1078,6 +1078,13 @@ void tst_qdeclarativelanguage::testType(const QString& qml, const QString& type) if (type.isEmpty()) { QVERIFY(component.isError()); + QString actualerror; + foreach (const QDeclarativeError e, component.errors()) { + if (!actualerror.isEmpty()) + actualerror.append("; "); + actualerror.append(e.description()); + } + QCOMPARE(actualerror,expectederror); } else { VERIFY_ERRORS(0); QObject *object = component.create(); @@ -1097,156 +1104,199 @@ void tst_qdeclarativelanguage::importsBuiltin_data() QTest::addColumn<QString>("qml"); QTest::addColumn<QString>("type"); + QTest::addColumn<QString>("error"); // import built-ins QTest::newRow("missing import") << "Test {}" - << ""; + << "" + << "Test is not a type"; QTest::newRow("not in version 0.0") << "import com.nokia.Test 0.0\n" "Test {}" - << ""; + << "" + << "Test is not a type"; + QTest::newRow("version not installed") + << "import com.nokia.Test 99.0\n" + "Test {}" + << "" + << "module \"com.nokia.Test\" version 99.0 is not installed"; QTest::newRow("in version 0.0") << "import com.nokia.Test 0.0\n" "TestTP {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("qualified in version 0.0") << "import com.nokia.Test 0.0 as T\n" "T.TestTP {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("in version 1.0") << "import com.nokia.Test 1.0\n" "Test {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("qualified wrong") << "import com.nokia.Test 1.0 as T\n" // QT-610 "Test {}" - << ""; + << "" + << "Test is not a type"; QTest::newRow("qualified right") << "import com.nokia.Test 1.0 as T\n" "T.Test {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("qualified right but not in version 0.0") << "import com.nokia.Test 0.0 as T\n" "T.Test {}" - << ""; + << "" + << "T.Test is not a type"; QTest::newRow("in version 1.1") << "import com.nokia.Test 1.1\n" "Test {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("in version 1.3") << "import com.nokia.Test 1.3\n" "Test {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("in version 1.5") << "import com.nokia.Test 1.5\n" "Test {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("changed in version 1.8") << "import com.nokia.Test 1.8\n" "Test {}" - << "TestType2"; + << "TestType2" + << ""; QTest::newRow("in version 1.12") << "import com.nokia.Test 1.12\n" "Test {}" - << "TestType2"; + << "TestType2" + << ""; QTest::newRow("old in version 1.9") << "import com.nokia.Test 1.9\n" "OldTest {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("old in version 1.11") << "import com.nokia.Test 1.11\n" "OldTest {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("multiversion 1") << "import com.nokia.Test 1.11\n" "import com.nokia.Test 1.12\n" "Test {}" - << "TestType2"; + << "TestType2" + << ""; QTest::newRow("multiversion 2") << "import com.nokia.Test 1.11\n" "import com.nokia.Test 1.12\n" "OldTest {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("qualified multiversion 3") << "import com.nokia.Test 1.0 as T0\n" "import com.nokia.Test 1.8 as T8\n" "T0.Test {}" - << "TestType"; + << "TestType" + << ""; QTest::newRow("qualified multiversion 4") << "import com.nokia.Test 1.0 as T0\n" "import com.nokia.Test 1.8 as T8\n" "T8.Test {}" - << "TestType2"; + << "TestType2" + << ""; } void tst_qdeclarativelanguage::importsBuiltin() { QFETCH(QString, qml); QFETCH(QString, type); - testType(qml,type); + QFETCH(QString, error); + testType(qml,type,error); } void tst_qdeclarativelanguage::importsLocal_data() { QTest::addColumn<QString>("qml"); QTest::addColumn<QString>("type"); + QTest::addColumn<QString>("error"); // import locals QTest::newRow("local import") << "import \"subdir\"\n" // QT-613 "Test {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("local import second") << "import Qt 4.6\nimport \"subdir\"\n" "Test {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("local import subsubdir") << "import Qt 4.6\nimport \"subdir/subsubdir\"\n" "SubTest {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("local import QTBUG-7721 A") << "subdir.Test {}" // no longer allowed (QTBUG-7721) - << ""; + << "" + << "subdir.Test is not a type"; QTest::newRow("local import QTBUG-7721 B") << "import \"subdir\" as X\n" "X.subsubdir.SubTest {}" // no longer allowed (QTBUG-7721) - << ""; + << "" + << "X.subsubdir.SubTest is not a type"; QTest::newRow("local import as") << "import \"subdir\" as T\n" "T.Test {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("wrong local import as") << "import \"subdir\" as T\n" "Test {}" - << ""; + << "" + << "Test is not a type"; QTest::newRow("library precedence over local import") << "import \"subdir\"\n" "import com.nokia.Test 1.0\n" "Test {}" - << "TestType"; + << "TestType" + << ""; } void tst_qdeclarativelanguage::importsLocal() { QFETCH(QString, qml); QFETCH(QString, type); - testType(qml,type); + QFETCH(QString, error); + testType(qml,type,error); } void tst_qdeclarativelanguage::importsRemote_data() { QTest::addColumn<QString>("qml"); QTest::addColumn<QString>("type"); + QTest::addColumn<QString>("error"); QString serverdir = "http://127.0.0.1:14445/qtest/declarative/qmllanguage"; - QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QDeclarativeRectangle"; - QTest::newRow("remote import with subdir") << "import \""+serverdir+"\"\nTestSubDir {}" << "QDeclarativeText"; - QTest::newRow("remote import with local") << "import \""+serverdir+"\"\nTestLocal {}" << "QDeclarativeImage"; - QTest::newRow("wrong remote import with undeclared local") << "import \""+serverdir+"\"\nWrongTestLocal {}" << ""; - QTest::newRow("wrong remote import of internal local") << "import \""+serverdir+"\"\nLocalInternal {}" << ""; - QTest::newRow("wrong remote import of undeclared local") << "import \""+serverdir+"\"\nUndeclaredLocal {}" << ""; + QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QDeclarativeRectangle" + << ""; + QTest::newRow("remote import with subdir") << "import \""+serverdir+"\"\nTestSubDir {}" << "QDeclarativeText" + << ""; + QTest::newRow("remote import with local") << "import \""+serverdir+"\"\nTestLocal {}" << "QDeclarativeImage" + << ""; + QTest::newRow("wrong remote import with undeclared local") << "import \""+serverdir+"\"\nWrongTestLocal {}" << "" + << "WrongTestLocal is not a type"; + QTest::newRow("wrong remote import of internal local") << "import \""+serverdir+"\"\nLocalInternal {}" << "" + << "LocalInternal is not a type"; + QTest::newRow("wrong remote import of undeclared local") << "import \""+serverdir+"\"\nUndeclaredLocal {}" << "" + << "UndeclaredLocal is not a type"; } #include "testhttpserver.h" @@ -1255,11 +1305,12 @@ void tst_qdeclarativelanguage::importsRemote() { QFETCH(QString, qml); QFETCH(QString, type); + QFETCH(QString, error); TestHTTPServer server(14445); server.serveDirectory(SRCDIR); - testType(qml,type); + testType(qml,type,error); } void tst_qdeclarativelanguage::importsInstalled_data() @@ -1268,43 +1319,52 @@ void tst_qdeclarativelanguage::importsInstalled_data() QTest::addColumn<QString>("qml"); QTest::addColumn<QString>("type"); + QTest::addColumn<QString>("error"); // import installed QTest::newRow("installed import 0") << "import com.nokia.installedtest 0.0\n" "InstalledTestTP {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import 0 as TP") << "import com.nokia.installedtest 0.0 as TP\n" "TP.InstalledTestTP {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import 1") << "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import 2") << "import com.nokia.installedtest 1.3\n" "InstalledTest {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import 3") << "import com.nokia.installedtest 1.4\n" "InstalledTest {}" - << "QDeclarativeText"; + << "QDeclarativeText" + << ""; QTest::newRow("installed import 4") << "import com.nokia.installedtest 1.10\n" "InstalledTest {}" - << "QDeclarativeText"; + << "QDeclarativeText" + << ""; QTest::newRow("installed import visibility") // QT-614 << "import com.nokia.installedtest 1.4\n" "PrivateType {}" - << ""; + << "" + << "PrivateType is not a type"; } void tst_qdeclarativelanguage::importsInstalled() { QFETCH(QString, qml); QFETCH(QString, type); - testType(qml,type); + QFETCH(QString, error); + testType(qml,type,error); } @@ -1312,65 +1372,77 @@ void tst_qdeclarativelanguage::importsOrder_data() { QTest::addColumn<QString>("qml"); QTest::addColumn<QString>("type"); + QTest::addColumn<QString>("error"); QTest::newRow("installed import overrides 1") << "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" - << "QDeclarativeText"; + << "QDeclarativeText" + << ""; QTest::newRow("installed import overrides 2") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import re-overrides 1") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" - << "QDeclarativeText"; + << "QDeclarativeText" + << ""; QTest::newRow("installed import re-overrides 2") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import versus builtin 1") << "import com.nokia.installedtest 1.5\n" "import Qt 4.6\n" "Rectangle {}" - << "QDeclarativeRectangle"; + << "QDeclarativeRectangle" + << ""; QTest::newRow("installed import versus builtin 2") << "import Qt 4.6\n" "import com.nokia.installedtest 1.5\n" "Rectangle {}" - << "QDeclarativeText"; + << "QDeclarativeText" + << ""; QTest::newRow("namespaces cannot be overridden by types 1") << "import Qt 4.6 as Rectangle\n" "import com.nokia.installedtest 1.5\n" "Rectangle {}" - << ""; + << "" + << "Namespace Rectangle cannot be used as a type"; QTest::newRow("namespaces cannot be overridden by types 2") << "import Qt 4.6 as Rectangle\n" "import com.nokia.installedtest 1.5\n" "Rectangle.Image {}" - << "QDeclarativeImage"; + << "QDeclarativeImage" + << ""; QTest::newRow("local last 1") << "LocalLast {}" - << "QDeclarativeText"; + << "QDeclarativeText" + << ""; QTest::newRow("local last 2") << "import com.nokia.installedtest 1.0\n" "LocalLast {}" - << "QDeclarativeRectangle"; // i.e. from com.nokia.installedtest, not data/LocalLast.qml + << "QDeclarativeRectangle" + << ""; // i.e. from com.nokia.installedtest, not data/LocalLast.qml } void tst_qdeclarativelanguage::importsOrder() { QFETCH(QString, qml); QFETCH(QString, type); - testType(qml,type); + QFETCH(QString, error); + testType(qml,type,error); } void tst_qdeclarativelanguage::qmlAttachedPropertiesObjectMethod() |