/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the test suite of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QNetworkAccessManager>
#include <QPointer>
#include <QDir>
-#include <QDesktopServices>
+#include <QStandardPaths>
#include <QDebug>
#include <QDeclarativeComponent>
#include <QDeclarativeNetworkAccessManagerFactory>
-
-#ifdef Q_OS_SYMBIAN
-// In Symbian OS test data is located in applications private dir
-#define SRCDIR "."
-#endif
+#include <QDeclarativeExpression>
class tst_qdeclarativeengine : public QObject
{
void clearComponentCache();
void outputWarningsToStandardError();
void objectOwnership();
+ void multipleEngines();
};
void tst_qdeclarativeengine::rootContext()
QDeclarativeEngine engine;
- QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
+ QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
dir.mkpath("QML");
dir.cd("QML");
dir.mkpath("OfflineStorage");
delete o;
QCOMPARE(warnings.count(), 1);
- QCOMPARE(warnings.at(0), QLatin1String("<Unknown File>:1: Unable to assign [undefined] to int a"));
+ QCOMPARE(warnings.at(0), QLatin1String("<Unknown File>:1: Unable to assign [undefined] to int"));
warnings.clear();
}
+// Test an object can be accessed by multiple engines
+void tst_qdeclarativeengine::multipleEngines()
+{
+ QObject o;
+ o.setObjectName("TestName");
+
+ // Simultaneous engines
+ {
+ QDeclarativeEngine engine1;
+ QDeclarativeEngine engine2;
+ engine1.rootContext()->setContextProperty("object", &o);
+ engine2.rootContext()->setContextProperty("object", &o);
+
+ QDeclarativeExpression expr1(engine1.rootContext(), 0, QString("object.objectName"));
+ QDeclarativeExpression expr2(engine2.rootContext(), 0, QString("object.objectName"));
+
+ QCOMPARE(expr1.evaluate().toString(), QString("TestName"));
+ QCOMPARE(expr2.evaluate().toString(), QString("TestName"));
+ }
+
+ // Serial engines
+ {
+ QDeclarativeEngine engine1;
+ engine1.rootContext()->setContextProperty("object", &o);
+ QDeclarativeExpression expr1(engine1.rootContext(), 0, QString("object.objectName"));
+ QCOMPARE(expr1.evaluate().toString(), QString("TestName"));
+ }
+ {
+ QDeclarativeEngine engine1;
+ engine1.rootContext()->setContextProperty("object", &o);
+ QDeclarativeExpression expr1(engine1.rootContext(), 0, QString("object.objectName"));
+ QCOMPARE(expr1.evaluate().toString(), QString("TestName"));
+ }
+}
+
QTEST_MAIN(tst_qdeclarativeengine)
#include "tst_qdeclarativeengine.moc"