2014-10-28 16:56:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
2015-02-17 11:18:57 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2014-10-28 16:56:06 +01:00
|
|
|
**
|
|
|
|
** This file is part of the Qt Installer Framework.
|
|
|
|
**
|
|
|
|
** $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
|
2015-02-17 11:18:57 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2014-10-28 16:56:06 +01:00
|
|
|
**
|
|
|
|
** 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 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
2015-02-17 11:18:57 +01:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2014-10-28 16:56:06 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2013-05-07 13:43:13 +02:00
|
|
|
#include <component.h>
|
|
|
|
#include <errors.h>
|
|
|
|
#include <packagemanagercore.h>
|
|
|
|
#include <packagemanagergui.h>
|
2013-05-08 13:26:41 +02:00
|
|
|
#include <scriptengine.h>
|
2013-05-07 13:43:13 +02:00
|
|
|
|
|
|
|
#include <QTest>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
using namespace QInstaller;
|
|
|
|
|
|
|
|
class TestGui : public QInstaller::PackageManagerGui
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TestGui(QInstaller::PackageManagerCore *core)
|
|
|
|
: PackageManagerGui(core, 0)
|
|
|
|
{
|
|
|
|
setPage(PackageManagerCore::Introduction, new IntroductionPage(core));
|
|
|
|
setPage(PackageManagerCore::ComponentSelection, new ComponentSelectionPage(core));
|
|
|
|
setPage(PackageManagerCore::InstallationFinished, new FinishedPage(core));
|
2014-12-08 17:34:12 +01:00
|
|
|
|
|
|
|
foreach (const int id, pageIds()) {
|
2015-01-05 16:44:07 +01:00
|
|
|
packageManagerCore()->controlScriptEngine()->addToGlobalObject(page(id));
|
|
|
|
packageManagerCore()->componentScriptEngine()->addToGlobalObject(page(id));
|
2014-12-08 17:34:12 +01:00
|
|
|
}
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void init() {}
|
|
|
|
|
2013-09-27 12:14:59 +02:00
|
|
|
void callProtectedDelayedExecuteControlScript(int id)
|
2013-05-07 13:43:13 +02:00
|
|
|
{
|
2013-09-27 12:14:59 +02:00
|
|
|
executeControlScript(id);
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-28 16:56:06 +01:00
|
|
|
class DynamicPageGui : public PackageManagerGui
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit DynamicPageGui(PackageManagerCore *core)
|
|
|
|
: PackageManagerGui(core)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
m_widget = new QWidget;
|
|
|
|
m_widget->setObjectName("Widget");
|
2015-01-06 10:56:49 +01:00
|
|
|
QWidget *button = new QWidget(m_widget);
|
|
|
|
button->setObjectName("Button");
|
2014-10-28 16:56:06 +01:00
|
|
|
|
|
|
|
packageManagerCore()->wizardPageInsertionRequested(m_widget,
|
|
|
|
PackageManagerCore::Introduction);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *widget() const { return m_widget; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWidget *m_widget;
|
|
|
|
};
|
|
|
|
|
2015-01-27 10:47:52 +01:00
|
|
|
class EnteringPage : public PackageManagerPage
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QStringList invocationOrder READ invocationOrder)
|
|
|
|
public:
|
|
|
|
explicit EnteringPage(PackageManagerCore *core)
|
|
|
|
: PackageManagerPage(core)
|
|
|
|
{
|
|
|
|
setObjectName(QLatin1String("EnteringPage"));
|
|
|
|
}
|
|
|
|
QStringList invocationOrder() const {
|
|
|
|
return m_invocationOrder;
|
|
|
|
}
|
|
|
|
public slots:
|
|
|
|
Q_INVOKABLE void enteringInvoked() {
|
|
|
|
m_invocationOrder << QLatin1String("Entering");
|
|
|
|
}
|
|
|
|
Q_INVOKABLE void callbackInvoked() {
|
|
|
|
m_invocationOrder << QLatin1String("Callback");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void entering() {
|
|
|
|
enteringInvoked();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
QStringList m_invocationOrder;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EnteringGui : public PackageManagerGui
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit EnteringGui(PackageManagerCore *core)
|
|
|
|
: PackageManagerGui(core)
|
|
|
|
{}
|
|
|
|
|
|
|
|
EnteringPage *enteringPage() const {
|
|
|
|
return m_enteringPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
m_enteringPage = new EnteringPage(packageManagerCore());
|
|
|
|
setPage(0, m_enteringPage);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
EnteringPage *m_enteringPage;
|
|
|
|
};
|
|
|
|
|
2013-05-29 15:21:59 +02:00
|
|
|
class EmitSignalObject : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
EmitSignalObject() {}
|
|
|
|
~EmitSignalObject() {}
|
|
|
|
void produceSignal() { emit emitted(); }
|
|
|
|
signals:
|
|
|
|
void emitted();
|
|
|
|
};
|
|
|
|
|
2013-05-07 13:43:13 +02:00
|
|
|
|
2013-05-08 13:26:41 +02:00
|
|
|
class tst_ScriptEngine : public QObject
|
2013-05-07 13:43:13 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase()
|
|
|
|
{
|
|
|
|
m_component = new Component(&m_core);
|
2013-05-08 11:21:37 +02:00
|
|
|
// append the component to the package manager which deletes it at destructor
|
2013-05-07 13:43:13 +02:00
|
|
|
// (it calls clearAllComponentLists which calls qDeleteAll(m_rootComponents);)
|
|
|
|
m_core.appendRootComponent(m_component);
|
|
|
|
|
|
|
|
m_component->setValue("Default", "Script");
|
|
|
|
m_component->setValue(scName, "component.test.name");
|
|
|
|
|
2013-11-06 12:45:23 +01:00
|
|
|
m_scriptEngine = m_core.componentScriptEngine();
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
|
2014-05-23 16:24:09 +02:00
|
|
|
void testDefaultScriptEngineValues()
|
|
|
|
{
|
|
|
|
const QJSValue global = m_scriptEngine->globalObject();
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("print")), true);
|
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("installer")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("installer"))
|
|
|
|
.hasProperty(QLatin1String("componentByName")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("installer"))
|
|
|
|
.hasProperty(QLatin1String("components")), true);
|
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("console")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("console"))
|
|
|
|
.hasProperty(QLatin1String("log")), true);
|
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("QFileDialog")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("QFileDialog"))
|
|
|
|
.hasProperty(QLatin1String("getExistingDirectory")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("QFileDialog"))
|
|
|
|
.hasProperty(QLatin1String("getOpenFileName")), true);
|
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("InstallerProxy")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("InstallerProxy"))
|
|
|
|
.hasProperty(QLatin1String("componentByName")), true);
|
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("QDesktopServices")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("QDesktopServices"))
|
|
|
|
.hasProperty(QLatin1String("openUrl")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("QDesktopServices"))
|
|
|
|
.hasProperty(QLatin1String("displayName")), true);
|
|
|
|
QCOMPARE(global.property(QLatin1String("QDesktopServices"))
|
|
|
|
.hasProperty(QLatin1String("storageLocation")), true);
|
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("buttons")), true);
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("QInstaller")), true);
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("QMessageBox")), true);
|
2014-10-28 17:04:08 +01:00
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("gui")), true);
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("qsTr")), true);
|
2014-12-03 10:41:48 +01:00
|
|
|
|
|
|
|
QCOMPARE(global.hasProperty(QLatin1String("systemInfo")), true);
|
|
|
|
QJSValue sinfo = global.property(QLatin1String("systemInfo"));
|
|
|
|
QCOMPARE(sinfo.property(QLatin1String("currentCpuArchitecture")).toString(),
|
|
|
|
QSysInfo::currentCpuArchitecture());
|
|
|
|
QCOMPARE(sinfo.property(QLatin1String("kernelType")).toString(), QSysInfo::kernelType());
|
|
|
|
QCOMPARE(sinfo.property(QLatin1String("kernelVersion")).toString(),
|
|
|
|
QSysInfo::kernelVersion());
|
|
|
|
QCOMPARE(sinfo.property(QLatin1String("productType")).toString(), QSysInfo::productType());
|
|
|
|
QCOMPARE(sinfo.property(QLatin1String("productVersion")).toString(),
|
|
|
|
QSysInfo::productVersion());
|
|
|
|
QCOMPARE(sinfo.property(QLatin1String("prettyProductName")).toString(),
|
|
|
|
QSysInfo::prettyProductName());
|
2014-05-23 16:24:09 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 15:21:59 +02:00
|
|
|
void testBrokenJSMethodConnect()
|
|
|
|
{
|
2015-01-28 16:04:03 +01:00
|
|
|
#if QT_VERSION <= 0x50400
|
|
|
|
QSKIP("Behavior changed from 5.4.1 onwards");
|
|
|
|
#endif
|
2013-05-29 15:21:59 +02:00
|
|
|
EmitSignalObject emiter;
|
|
|
|
m_scriptEngine->globalObject().setProperty(QLatin1String("emiter"),
|
|
|
|
m_scriptEngine->newQObject(&emiter));
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
QJSValue context = m_scriptEngine->loadInContext(QLatin1String("BrokenConnect"),
|
2013-05-29 15:21:59 +02:00
|
|
|
":///data/broken_connect.qs");
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
if (context.isError()) {
|
|
|
|
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
|
|
|
|
context.toString())));
|
2013-05-29 15:21:59 +02:00
|
|
|
}
|
2014-06-02 15:14:12 +02:00
|
|
|
QCOMPARE(context.isError(), false);
|
2013-05-29 15:21:59 +02:00
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
// ignore Output from script
|
|
|
|
setExpectedScriptOutput("\"function receive()\"");
|
|
|
|
|
2015-01-28 16:04:03 +01:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, ":10: ReferenceError: foo is not defined");
|
2014-06-02 15:14:12 +02:00
|
|
|
emiter.produceSignal();
|
|
|
|
|
|
|
|
const QJSValue value = m_scriptEngine->evaluate("");
|
2015-01-28 16:04:03 +01:00
|
|
|
QCOMPARE(value.isError(), false);
|
2013-05-29 15:21:59 +02:00
|
|
|
}
|
|
|
|
|
2013-05-07 13:43:13 +02:00
|
|
|
void testScriptPrint()
|
|
|
|
{
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"test\"");
|
|
|
|
const QJSValue value = m_scriptEngine->evaluate("print(\"test\");");
|
|
|
|
if (value.isError()) {
|
|
|
|
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
|
|
|
|
value.toString())));
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testExistingInstallerObject()
|
|
|
|
{
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"object\"");
|
|
|
|
const QJSValue value = m_scriptEngine->evaluate("print(typeof installer)");
|
|
|
|
if (value.isError()) {
|
|
|
|
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
|
|
|
|
value.toString())));
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testComponentByName()
|
|
|
|
{
|
2014-06-02 15:14:12 +02:00
|
|
|
const QString script = QString::fromLatin1("var component = installer.componentByName('%1');"
|
|
|
|
"\n"
|
|
|
|
"print(component.name);").arg(m_component->name());
|
|
|
|
|
|
|
|
setExpectedScriptOutput("\"component.test.name\"");
|
|
|
|
const QJSValue value = m_scriptEngine->evaluate(script);
|
|
|
|
if (value.isError()) {
|
|
|
|
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
|
|
|
|
value.toString())));
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testComponentByWrongName()
|
|
|
|
{
|
2014-06-02 15:14:12 +02:00
|
|
|
const QString script = QString::fromLatin1( "var component = installer.componentByName('%1');"
|
|
|
|
"\n"
|
|
|
|
"print(brokenComponent.name);").arg("NotExistingComponentName");
|
2013-05-07 13:43:13 +02:00
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
const QJSValue value = m_scriptEngine->evaluate(script);
|
|
|
|
QCOMPARE(value.isError(), true);
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loadSimpleComponentScript()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// ignore retranslateUi which is called by loadComponentScript
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"Component constructor - OK\"");
|
|
|
|
setExpectedScriptOutput("\"retranslateUi - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
m_component->loadComponentScript(":///data/component1.qs");
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"retranslateUi - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
m_component->languageChanged();
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"createOperationsForPath - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
m_component->createOperationsForPath(":///data/");
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"createOperationsForArchive - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
// ignore createOperationsForPath which is called by createOperationsForArchive
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"createOperationsForPath - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
m_component->createOperationsForArchive("test.7z");
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"beginInstallation - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
m_component->beginInstallation();
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"createOperations - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
m_component->createOperations();
|
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"isDefault - OK\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
bool returnIsDefault = m_component->isDefault();
|
|
|
|
QCOMPARE(returnIsDefault, false);
|
|
|
|
|
|
|
|
} catch (const Error &error) {
|
|
|
|
QFAIL(qPrintable(error.message()));
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 11:21:37 +02:00
|
|
|
|
2013-05-07 13:43:13 +02:00
|
|
|
void loadBrokenComponentScript()
|
|
|
|
{
|
2013-05-22 18:08:25 +02:00
|
|
|
Component *testComponent = new Component(&m_core);
|
|
|
|
testComponent->setValue(scName, "broken.component");
|
2013-05-21 15:36:31 +02:00
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
// m_core becomes the owner of testComponent, it will delete it in the destructor
|
2013-05-22 18:08:25 +02:00
|
|
|
m_core.appendRootComponent(testComponent);
|
2013-05-07 13:43:13 +02:00
|
|
|
|
|
|
|
const QString debugMesssage(
|
2014-06-02 15:14:12 +02:00
|
|
|
"create Error-Exception: \"Exception while loading the component script '"
|
|
|
|
":///data/component2.qs'. (ReferenceError: broken is not defined)\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
try {
|
|
|
|
// ignore Output from script
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"script function: Component\"");
|
2013-05-07 13:43:13 +02:00
|
|
|
setExpectedScriptOutput(qPrintable(debugMesssage));
|
2013-05-22 18:08:25 +02:00
|
|
|
testComponent->loadComponentScript(":///data/component2.qs");
|
2013-05-07 13:43:13 +02:00
|
|
|
} catch (const Error &error) {
|
2014-06-02 15:14:12 +02:00
|
|
|
QVERIFY2(debugMesssage.contains(error.message()), "(ReferenceError: broken is not defined)");
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-19 14:21:33 +01:00
|
|
|
void loadComponentUserInterfaces()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
setExpectedScriptOutput("\"checked: false\"");
|
|
|
|
m_component->loadUserInterfaces(QDir(":///data"), QStringList() << QLatin1String("form.ui"));
|
|
|
|
m_component->loadComponentScript(":///data/userinterface.qs");
|
|
|
|
} catch (const Error &error) {
|
|
|
|
QFAIL(qPrintable(error.message()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 13:43:13 +02:00
|
|
|
void loadSimpleAutoRunScript()
|
|
|
|
{
|
2013-05-08 13:26:41 +02:00
|
|
|
try {
|
|
|
|
TestGui testGui(&m_core);
|
|
|
|
setExpectedScriptOutput("Loaded control script \":///data/auto-install.qs\" ");
|
|
|
|
testGui.loadControlScript(":///data/auto-install.qs");
|
|
|
|
QCOMPARE(m_core.value("GuiTestValue"), QString("hello"));
|
|
|
|
|
2013-09-27 12:14:59 +02:00
|
|
|
testGui.show();
|
2013-05-08 13:26:41 +02:00
|
|
|
|
|
|
|
// inside the auto-install script we are clicking the next button, with a not existing button
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, "Button with type: \"unknown button\" not found! ");
|
2013-09-27 12:14:59 +02:00
|
|
|
testGui.callProtectedDelayedExecuteControlScript(PackageManagerCore::ComponentSelection);
|
2013-05-08 13:26:41 +02:00
|
|
|
|
2014-06-02 15:14:12 +02:00
|
|
|
setExpectedScriptOutput("\"FinishedPageCallback - OK\"");
|
2013-09-27 12:14:59 +02:00
|
|
|
testGui.callProtectedDelayedExecuteControlScript(PackageManagerCore::InstallationFinished);
|
2013-05-08 13:26:41 +02:00
|
|
|
} catch (const Error &error) {
|
|
|
|
QFAIL(qPrintable(error.message()));
|
|
|
|
}
|
2013-05-07 13:43:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:56:06 +01:00
|
|
|
void testDynamicPage()
|
|
|
|
{
|
|
|
|
DynamicPageGui gui(&m_core);
|
|
|
|
gui.init();
|
|
|
|
|
|
|
|
setExpectedScriptOutput("Loaded control script \":///data/dynamicpage.qs\" ");
|
|
|
|
gui.loadControlScript(":///data/dynamicpage.qs");
|
|
|
|
|
|
|
|
gui.callControlScriptMethod("ReadAndSetValues");
|
|
|
|
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.final"), QString("false"));
|
|
|
|
QCOMPARE(gui.widget()->property("final").toString(), QString("false"));
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.commit"), QString("false"));
|
|
|
|
QCOMPARE(gui.widget()->property("commit").toString(), QString("false"));
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.complete"), QString("true"));
|
|
|
|
QCOMPARE(gui.widget()->property("complete").toString(), QString("true"));
|
|
|
|
|
|
|
|
gui.widget()->setProperty("final", true);
|
|
|
|
gui.widget()->setProperty("commit", true);
|
|
|
|
gui.widget()->setProperty("complete", false);
|
|
|
|
|
|
|
|
gui.callControlScriptMethod("ReadAndSetValues");
|
|
|
|
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.final"), QString("true"));
|
|
|
|
QCOMPARE(gui.widget()->property("final").toString(), QString("true"));
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.commit"), QString("true"));
|
|
|
|
QCOMPARE(gui.widget()->property("commit").toString(), QString("true"));
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.complete"), QString("false"));
|
|
|
|
QCOMPARE(gui.widget()->property("complete").toString(), QString("false"));
|
|
|
|
|
|
|
|
gui.callControlScriptMethod("UpdateAndSetValues");
|
|
|
|
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.final"), QString("false"));
|
|
|
|
QCOMPARE(gui.widget()->property("final").toString(), QString("false"));
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.commit"), QString("false"));
|
|
|
|
QCOMPARE(gui.widget()->property("commit").toString(), QString("false"));
|
|
|
|
QCOMPARE(m_core.value("DynamicWidget.complete"), QString("true"));
|
|
|
|
QCOMPARE(gui.widget()->property("complete").toString(), QString("true"));
|
|
|
|
}
|
|
|
|
|
2015-01-27 10:47:52 +01:00
|
|
|
void checkEnteringCalledBeforePageCallback()
|
|
|
|
{
|
|
|
|
EnteringGui gui(&m_core);
|
|
|
|
gui.init();
|
|
|
|
setExpectedScriptOutput("Loaded control script \":///data/enteringpage.qs\" ");
|
|
|
|
gui.loadControlScript(":///data/enteringpage.qs");
|
|
|
|
gui.show();
|
|
|
|
|
|
|
|
EnteringPage *enteringPage = gui.enteringPage();
|
|
|
|
|
|
|
|
QStringList expectedOrder;
|
|
|
|
expectedOrder << QLatin1String("Entering") << QLatin1String("Callback");
|
|
|
|
QCOMPARE(enteringPage->invocationOrder(), expectedOrder);
|
|
|
|
}
|
|
|
|
|
2013-05-07 13:43:13 +02:00
|
|
|
private:
|
|
|
|
void setExpectedScriptOutput(const char *message)
|
|
|
|
{
|
|
|
|
// Using setExpectedScriptOutput(...); inside the test method
|
|
|
|
// as a simple test that the scripts are called.
|
|
|
|
QTest::ignoreMessage(QtDebugMsg, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageManagerCore m_core;
|
|
|
|
Component *m_component;
|
2013-05-29 15:21:59 +02:00
|
|
|
ScriptEngine *m_scriptEngine;
|
2013-05-07 13:43:13 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-08 13:26:41 +02:00
|
|
|
QTEST_MAIN(tst_ScriptEngine)
|
2013-05-07 13:43:13 +02:00
|
|
|
|
2013-05-08 13:26:41 +02:00
|
|
|
#include "tst_scriptengine.moc"
|