diff options
Diffstat (limited to 'tests/auto/qscriptextensionplugin')
9 files changed, 371 insertions, 0 deletions
diff --git a/tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro b/tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro new file mode 100644 index 0000000..d4671c8 --- /dev/null +++ b/tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +CONFIG -= app_bundle +SUBDIRS = simpleplugin staticplugin test diff --git a/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp new file mode 100644 index 0000000..1679512 --- /dev/null +++ b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtScript/qscriptextensionplugin.h> +#include <QtScript/qscriptengine.h> +#include <qdebug.h> + +class SimplePlugin : public QScriptExtensionPlugin +{ +public: + SimplePlugin(QObject *parent = 0); + ~SimplePlugin(); + + virtual QStringList keys() const; + virtual void initialize(const QString &key, QScriptEngine *engine); +}; + +SimplePlugin::SimplePlugin(QObject *parent) + : QScriptExtensionPlugin(parent) +{ +} + +SimplePlugin::~SimplePlugin() +{ +} + +QStringList SimplePlugin::keys() const +{ + return QStringList() << "simple" + << "simple.foo" + << "simple.foo.bar"; +} + +void SimplePlugin::initialize(const QString &key, QScriptEngine *engine) +{ + engine->globalObject().setProperty("pluginKey", key); + QScriptValue package = setupPackage(key, engine); + engine->globalObject().setProperty("package", package); +} + +Q_EXPORT_PLUGIN2(simpleplugin, SimplePlugin) diff --git a/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro new file mode 100644 index 0000000..e184ca4 --- /dev/null +++ b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro @@ -0,0 +1,10 @@ +TEMPLATE = lib +CONFIG += plugin +SOURCES = simpleplugin.cpp +QT = core script +TARGET = simpleplugin +DESTDIR = ../plugins/script + +symbian { + TARGET.EPOCALLOWDLLDATA=1 +} diff --git a/tests/auto/qscriptextensionplugin/staticplugin/__init__.js b/tests/auto/qscriptextensionplugin/staticplugin/__init__.js new file mode 100644 index 0000000..4e462ae --- /dev/null +++ b/tests/auto/qscriptextensionplugin/staticplugin/__init__.js @@ -0,0 +1,6 @@ +spy = { + extension: __extension__, + setupPackage: __setupPackage__, + postInit: __postInit__ +}; +__postInit__ = function() { postInitWasCalled = true; }; diff --git a/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp new file mode 100644 index 0000000..b13f723 --- /dev/null +++ b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtScript/qscriptextensionplugin.h> +#include <QtScript/qscriptengine.h> +#include <qdebug.h> + +class StaticPlugin : public QScriptExtensionPlugin +{ +public: + StaticPlugin(QObject *parent = 0); + ~StaticPlugin(); + + virtual QStringList keys() const; + virtual void initialize(const QString &key, QScriptEngine *engine); +}; + +StaticPlugin::StaticPlugin(QObject *parent) + : QScriptExtensionPlugin(parent) +{ +} + +StaticPlugin::~StaticPlugin() +{ +} + +QStringList StaticPlugin::keys() const +{ + return QStringList() << "static"; +} + +void StaticPlugin::initialize(const QString &key, QScriptEngine *engine) +{ + engine->globalObject().setProperty("pluginKey", key); +} + +Q_EXPORT_PLUGIN2(staticplugin, StaticPlugin) diff --git a/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro new file mode 100644 index 0000000..a003338 --- /dev/null +++ b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro @@ -0,0 +1,7 @@ +TEMPLATE = lib +CONFIG += static plugin +SOURCES = staticplugin.cpp +RESOURCES = staticplugin.qrc +QT = core script +TARGET = staticplugin +DESTDIR = ../plugins/script diff --git a/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc new file mode 100644 index 0000000..293bf0e --- /dev/null +++ b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/qtscriptextension/static/"> +<file>__init__.js</file> +</qresource> +</RCC> + diff --git a/tests/auto/qscriptextensionplugin/test/test.pro b/tests/auto/qscriptextensionplugin/test/test.pro new file mode 100644 index 0000000..549bac2 --- /dev/null +++ b/tests/auto/qscriptextensionplugin/test/test.pro @@ -0,0 +1,18 @@ +load(qttest_p4) + +QT = core script +SOURCES = ../tst_qscriptextensionplugin.cpp +CONFIG -= app_bundle +LIBS += -L../plugins/script -lstaticplugin + +TARGET = tst_qscriptextensionplugin +CONFIG(debug_and_release) { + CONFIG(debug, debug|release) { + DESTDIR = ../debug + } else { + DESTDIR = ../release + } +} else { + DESTDIR = .. +} + diff --git a/tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp b/tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp new file mode 100644 index 0000000..e8b5e0a --- /dev/null +++ b/tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> + +#include <QtScript/qscriptengine.h> + +//TESTED_CLASS= +//TESTED_FILES= + +class tst_QScriptExtensionPlugin : public QObject +{ + Q_OBJECT + +public: + tst_QScriptExtensionPlugin(); + virtual ~tst_QScriptExtensionPlugin(); + +private slots: + void importSimplePlugin(); + void importStaticPlugin(); +}; + +tst_QScriptExtensionPlugin::tst_QScriptExtensionPlugin() +{ +} + +tst_QScriptExtensionPlugin::~tst_QScriptExtensionPlugin() +{ +} + +void tst_QScriptExtensionPlugin::importSimplePlugin() +{ + QScriptEngine eng; + QCoreApplication::addLibraryPath("plugins"); + + QVERIFY(eng.importedExtensions().isEmpty()); + + QStringList available = eng.availableExtensions(); + QVERIFY(available.contains("simple")); + QVERIFY(available.contains("simple.foo")); + QVERIFY(available.contains("simple.foo.bar")); + + QScriptValue extensionObject; + { + QVERIFY(eng.importExtension("simple").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 1); + QCOMPARE(eng.importedExtensions().at(0), QString::fromLatin1("simple")); + QVERIFY(eng.availableExtensions().contains("simple")); + QVERIFY(eng.globalObject().property("pluginKey").equals("simple")); + QVERIFY(eng.globalObject().property("package").isObject()); + extensionObject = eng.globalObject().property("simple"); + QVERIFY(extensionObject.isObject()); + QVERIFY(extensionObject.equals(eng.globalObject().property("package"))); + } + + { + QVERIFY(eng.importExtension("simple.foo").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 2); + QCOMPARE(eng.importedExtensions().at(1), QString::fromLatin1("simple.foo")); + QVERIFY(eng.availableExtensions().contains("simple.foo")); + QVERIFY(eng.globalObject().property("pluginKey").equals("simple.foo")); + QVERIFY(eng.globalObject().property("package").isObject()); + QVERIFY(!extensionObject.equals(eng.globalObject().property("package"))); + QVERIFY(extensionObject.equals(eng.globalObject().property("simple"))); + QVERIFY(extensionObject.property("foo").isObject()); + QVERIFY(extensionObject.property("foo").equals(eng.globalObject().property("package"))); + } + + { + QVERIFY(eng.importExtension("simple.foo.bar").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 3); + QCOMPARE(eng.importedExtensions().at(2), QString::fromLatin1("simple.foo.bar")); + QVERIFY(eng.availableExtensions().contains("simple.foo.bar")); + QVERIFY(eng.globalObject().property("pluginKey").equals("simple.foo.bar")); + QVERIFY(eng.globalObject().property("package").isObject()); + QVERIFY(!extensionObject.equals(eng.globalObject().property("package"))); + QVERIFY(extensionObject.equals(eng.globalObject().property("simple"))); + QVERIFY(extensionObject.property("foo").property("bar").isObject()); + QVERIFY(extensionObject.property("foo").property("bar").equals(eng.globalObject().property("package"))); + } + + // Extensions can't be imported multiple times. + eng.globalObject().setProperty("pluginKey", QScriptValue()); + QVERIFY(eng.importExtension("simple").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 3); + QVERIFY(!eng.globalObject().property("pluginKey").isValid()); + + QVERIFY(eng.importExtension("simple.foo").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 3); + QVERIFY(!eng.globalObject().property("pluginKey").isValid()); + + QVERIFY(eng.importExtension("simple.foo.bar").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 3); + QVERIFY(!eng.globalObject().property("pluginKey").isValid()); +} + +void tst_QScriptExtensionPlugin::importStaticPlugin() +{ + Q_INIT_RESOURCE(staticplugin); + QScriptEngine eng; + QVERIFY(eng.availableExtensions().contains("static")); + QVERIFY(eng.importExtension("static").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 1); + QCOMPARE(eng.importedExtensions().at(0), QString::fromLatin1("static")); + QVERIFY(eng.availableExtensions().contains("static")); + QVERIFY(eng.globalObject().property("pluginKey").equals("static")); + + // Verify that :/qtscriptextension/static/__init__.js was evaluated. + QVERIFY(eng.evaluate("spy").isObject()); + QVERIFY(eng.evaluate("spy.extension").equals("static")); + QVERIFY(eng.evaluate("spy.setupPackage").isFunction()); + QVERIFY(eng.evaluate("spy.postInit").isUndefined()); + + QVERIFY(eng.evaluate("postInitWasCalled").isBool()); + QVERIFY(eng.evaluate("postInitWasCalled").toBool()); + + // Extensions can't be imported multiple times. + eng.globalObject().setProperty("pluginKey", QScriptValue()); + QVERIFY(eng.importExtension("static").isUndefined()); + QCOMPARE(eng.importedExtensions().size(), 1); + QVERIFY(!eng.globalObject().property("pluginKey").isValid()); +} + +Q_IMPORT_PLUGIN(staticplugin) + +QTEST_MAIN(tst_QScriptExtensionPlugin) +#include "tst_qscriptextensionplugin.moc" |