diff options
author | Alan Alpert <416365416c@gmail.com> | 2013-05-17 15:32:19 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 01:09:05 +0200 |
commit | fee79b70773ef26c5d45993c4618d302392b0782 (patch) | |
tree | 89c5a0c07eb0c8504ecb1e77ef78b7899d10ed7a /tests/auto/qml | |
parent | 8850e2eafaba8a6493d3ad5ab584b751eb9a8742 (diff) |
Add qmlProtectModule
A C++ analog to the protected qmldir syntax, this is also a potential
performance improvement because we can avoid some file system accesses.
Change-Id: I41781a6cc72aa65bd2d397800345ea16ef442e90
Reviewed-by: Antti Piira <apiira@blackberry.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qml')
5 files changed, 106 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlmoduleplugin/protectedModule/plugin.cpp b/tests/auto/qml/qqmlmoduleplugin/protectedModule/plugin.cpp new file mode 100644 index 0000000000..c960a69a9e --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/protectedModule/plugin.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyPluginType : public QObject +{ + Q_OBJECT +public: + MyPluginType(QObject *parent=0) : QObject(parent) {} +}; + + +class MyPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + MyPlugin() {} + + void registerTypes(const char *uri) + { + // Because the module is protected, this plugin should never be loaded + Q_UNUSED(uri); + Q_ASSERT(0); + } +}; + +#include "plugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/protectedModule/protectedModule.pro b/tests/auto/qml/qqmlmoduleplugin/protectedModule/protectedModule.pro new file mode 100644 index 0000000000..749a440ca8 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/protectedModule/protectedModule.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += plugin +SOURCES = plugin.cpp +QT = core qml +DESTDIR = ../imports/org/qtproject/ProtectedModule + +QT += core-private gui-private qml-private + +IMPORT_FILES = \ + qmldir + +include (../../../shared/imports.pri) +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qml/qqmlmoduleplugin/protectedModule/qmldir b/tests/auto/qml/qqmlmoduleplugin/protectedModule/qmldir new file mode 100644 index 0000000000..8d121bb17b --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/protectedModule/qmldir @@ -0,0 +1 @@ +plugin protectedModule diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro index 4806d34699..54acabe8eb 100644 --- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro +++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro @@ -15,7 +15,8 @@ SUBDIRS =\ preemptiveModule\ preemptedStrictModule\ invalidNamespaceModule\ - invalidFirstCommandModule + invalidFirstCommandModule\ + protectedModule tst_qqmlmoduleplugin_pro.depends += plugin SUBDIRS += tst_qqmlmoduleplugin.pro diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index ab8ff0e1a4..4379a90d47 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -80,6 +80,7 @@ private slots: void importLocalModule_data(); void importStrictModule(); void importStrictModule_data(); + void importProtectedModule(); private: QString m_importsDirectory; @@ -542,6 +543,26 @@ void tst_qqmlmoduleplugin::importStrictModule_data() << ":1:1: module identifier directive must be the first directive in a qmldir file"; } +void tst_qqmlmoduleplugin::importProtectedModule() +{ + //TODO: More than basic test (test errors,test inverse works...) + qmlRegisterType<QObject>("org.qtproject.ProtectedModule", 1, 0, "TestType"); + qmlProtectModule("org.qtproject.ProtectedModule", 1); + + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + + QUrl url(testFileUrl("empty.qml")); + + QString qml = "import org.qtproject.ProtectedModule 1.0\n TestType {}\n"; + QQmlComponent component(&engine); + component.setData(qml.toUtf8(), url); + //If plugin is loaded due to import, should assert + QScopedPointer<QObject> object(component.create()); + //qDebug() << component.errorString(); + QVERIFY(object != 0); +} + QTEST_MAIN(tst_qqmlmoduleplugin) #include "tst_qqmlmoduleplugin.moc" |