Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeengine / tst_qdeclarativeengine.cpp
index 17249ab..f8b0ef6 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** 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.
 **
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $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
 {
@@ -70,6 +66,7 @@ private slots:
     void clearComponentCache();
     void outputWarningsToStandardError();
     void objectOwnership();
+    void multipleEngines();
 };
 
 void tst_qdeclarativeengine::rootContext()
@@ -180,7 +177,7 @@ void tst_qdeclarativeengine::offlineStoragePath()
 
     QDeclarativeEngine engine;
 
-    QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
+    QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
     dir.mkpath("QML");
     dir.cd("QML");
     dir.mkpath("OfflineStorage");
@@ -271,7 +268,7 @@ void tst_qdeclarativeengine::outputWarningsToStandardError()
     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();
 
 
@@ -328,6 +325,41 @@ void tst_qdeclarativeengine::objectOwnership()
 
 }
 
+// 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"