aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeincubator
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativeincubator')
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/AsynchronousIfNestedType.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.1.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.2.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/chainInCompletion.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/chainedAsynchronousIfNested.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/clear.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/clearDuringCompletion.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/forceCompletion.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.js1
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/noIncubationController.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.errors.txt1
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.1.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.2.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/setInitialState.qml17
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/statusChanged.nested.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/data/statusChanged.qml5
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/qdeclarativeincubator.pro18
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/testtypes.cpp137
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/testtypes.h125
-rw-r--r--tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp1030
25 files changed, 0 insertions, 1452 deletions
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/AsynchronousIfNestedType.qml b/tests/auto/declarative/qdeclarativeincubator/data/AsynchronousIfNestedType.qml
deleted file mode 100644
index 8a3f46ee72..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/AsynchronousIfNestedType.qml
+++ /dev/null
@@ -1,7 +0,0 @@
-import Qt.test 1.0
-
-SelfRegistering {
- property int dummy1: 11
- property int dummy2: 19
-}
-
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.1.qml b/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.1.qml
deleted file mode 100644
index 18ff4aabb7..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.1.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property int a: 10
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.2.qml b/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.2.qml
deleted file mode 100644
index 3f6cd932de..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.2.qml
+++ /dev/null
@@ -1,6 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property QtObject o: AsynchronousIfNestedType { }
- property int dummy: 11
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml b/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml
deleted file mode 100644
index 7e5ee7cf5c..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import Qt.test 1.0
-
-CallbackRegistering {
- value: 19
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/chainInCompletion.qml b/tests/auto/declarative/qdeclarativeincubator/data/chainInCompletion.qml
deleted file mode 100644
index e79fed356a..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/chainInCompletion.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import Qt.test 1.0
-
-SelfRegistering {
- property variant a: CompletionCallback {}
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/chainedAsynchronousIfNested.qml b/tests/auto/declarative/qdeclarativeincubator/data/chainedAsynchronousIfNested.qml
deleted file mode 100644
index 1300426cfa..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/chainedAsynchronousIfNested.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import Qt.test 1.0
-
-SelfRegistering {
- property int dummy: 10
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/clear.qml b/tests/auto/declarative/qdeclarativeincubator/data/clear.qml
deleted file mode 100644
index f00f975923..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/clear.qml
+++ /dev/null
@@ -1,8 +0,0 @@
-import QtQuick 2.0
-import Qt.test 1.0
-
-Item {
- SelfRegistering {
- value: 11
- }
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/clearDuringCompletion.qml b/tests/auto/declarative/qdeclarativeincubator/data/clearDuringCompletion.qml
deleted file mode 100644
index 556f460d58..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/clearDuringCompletion.qml
+++ /dev/null
@@ -1,6 +0,0 @@
-import Qt.test 1.0
-
-SelfRegistering {
- property variant a: CompletionRegistering {}
- property variant b: CompletionRegistering {}
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml b/tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml
deleted file mode 100644
index c3952074f1..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property int dummy: 12
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/forceCompletion.qml b/tests/auto/declarative/qdeclarativeincubator/data/forceCompletion.qml
deleted file mode 100644
index 9b76701c1b..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/forceCompletion.qml
+++ /dev/null
@@ -1,9 +0,0 @@
-import QtQuick 2.0
-import Qt.test 1.0
-
-Item {
- property int testValue: 3499
- SelfRegistering {
- property int testValue2: 19
- }
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.js b/tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.js
deleted file mode 100644
index 4b6b0bde43..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.js
+++ /dev/null
@@ -1 +0,0 @@
-var value = 19988
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.qml b/tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.qml
deleted file mode 100644
index dd20707456..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/nestedComponent.qml
+++ /dev/null
@@ -1,10 +0,0 @@
-import QtQuick 2.0
-import "nestedComponent.js" as NestedJS
-
-QtObject {
- property Component c: Component {
- QtObject {
- property int value: NestedJS.value
- }
- }
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/noIncubationController.qml b/tests/auto/declarative/qdeclarativeincubator/data/noIncubationController.qml
deleted file mode 100644
index 7d93e856f0..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/noIncubationController.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property int testValue: 1913
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.errors.txt b/tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.errors.txt
deleted file mode 100644
index eeda289d35..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.errors.txt
+++ /dev/null
@@ -1 +0,0 @@
--1:-1:Object destroyed during incubation
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.qml b/tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.qml
deleted file mode 100644
index f00f975923..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/objectDeleted.qml
+++ /dev/null
@@ -1,8 +0,0 @@
-import QtQuick 2.0
-import Qt.test 1.0
-
-Item {
- SelfRegistering {
- value: 11
- }
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.1.qml b/tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.1.qml
deleted file mode 100644
index 748a3f0cbf..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.1.qml
+++ /dev/null
@@ -1,9 +0,0 @@
-import QtQuick 2.0
-
-Rectangle {
- objectName: "switchMe"
- signal switchMe
- width: 100; height: 100
- color: "green"
- Component.onCompleted: switchMe()
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.2.qml b/tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.2.qml
deleted file mode 100644
index e96ac00f21..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/recursiveClear.2.qml
+++ /dev/null
@@ -1,8 +0,0 @@
-import QtQuick 2.0
-
-Rectangle {
- objectName: "blue"
- width: 100
- height: 100
- color: "blue"
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml b/tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml
deleted file mode 100644
index c3952074f1..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property int dummy: 12
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/setInitialState.qml b/tests/auto/declarative/qdeclarativeincubator/data/setInitialState.qml
deleted file mode 100644
index 0fd61abfd2..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/setInitialState.qml
+++ /dev/null
@@ -1,17 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property int test1: (testData1 * 32 + 99) / testData2
- property int test2: myValueFunction()
-
- property bool myValueFunctionCalled: false
-
- property int testData1: 19
- property int testData2: 13
-
- function myValueFunction() {
- myValueFunctionCalled = true;
- return 13;
- }
-}
-
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/statusChanged.nested.qml b/tests/auto/declarative/qdeclarativeincubator/data/statusChanged.nested.qml
deleted file mode 100644
index 3a496ea6fe..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/statusChanged.nested.qml
+++ /dev/null
@@ -1,12 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- id: root
-
- property bool test: false
-
- Component.onCompleted: {
- var c = Qt.createComponent("statusChanged.qml");
- c.incubateObject(root, null, Qt.Synchronous);
- }
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/statusChanged.qml b/tests/auto/declarative/qdeclarativeincubator/data/statusChanged.qml
deleted file mode 100644
index 18ff4aabb7..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/data/statusChanged.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import QtQuick 2.0
-
-QtObject {
- property int a: 10
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/qdeclarativeincubator.pro b/tests/auto/declarative/qdeclarativeincubator/qdeclarativeincubator.pro
deleted file mode 100644
index 90a6720bd7..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/qdeclarativeincubator.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qdeclarativeincubator
-macx:CONFIG -= app_bundle
-
-SOURCES += tst_qdeclarativeincubator.cpp \
- testtypes.cpp
-
-HEADERS += testtypes.h
-
-include (../../shared/util.pri)
-
-testDataFiles.files = data
-testDataFiles.path = .
-DEPLOYMENT += testDataFiles
-
-CONFIG += parallel_test
-
-QT += core-private gui-private v8-private declarative-private network widgets testlib
diff --git a/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp b/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp
deleted file mode 100644
index 784c727cb7..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/****************************************************************************
-**
-** 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_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** 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.
-**
-** 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "testtypes.h"
-#include <QtDeclarative/qdeclarative.h>
-
-SelfRegisteringType *SelfRegisteringType::m_me = 0;
-SelfRegisteringType::SelfRegisteringType()
-: m_v(0)
-{
- m_me = this;
-}
-
-SelfRegisteringType *SelfRegisteringType::me()
-{
- return m_me;
-}
-
-void SelfRegisteringType::clearMe()
-{
- m_me = 0;
-}
-
-CompletionRegisteringType *CompletionRegisteringType::m_me = 0;
-CompletionRegisteringType::CompletionRegisteringType()
-{
-}
-
-void CompletionRegisteringType::classBegin()
-{
-}
-
-void CompletionRegisteringType::componentComplete()
-{
- m_me = this;
-}
-
-CompletionRegisteringType *CompletionRegisteringType::me()
-{
- return m_me;
-}
-
-void CompletionRegisteringType::clearMe()
-{
- m_me = 0;
-}
-
-CallbackRegisteringType::callback CallbackRegisteringType::m_callback = 0;
-void *CallbackRegisteringType::m_data = 0;
-CallbackRegisteringType::CallbackRegisteringType()
-: m_v(0)
-{
-}
-
-void CallbackRegisteringType::clearCallback()
-{
- m_callback = 0;
- m_data = 0;
-}
-
-void CallbackRegisteringType::registerCallback(callback c, void *d)
-{
- m_callback = c;
- m_data = d;
-}
-
-CompletionCallbackType::callback CompletionCallbackType::m_callback = 0;
-void *CompletionCallbackType::m_data = 0;
-CompletionCallbackType::CompletionCallbackType()
-{
-}
-
-void CompletionCallbackType::classBegin()
-{
-}
-
-void CompletionCallbackType::componentComplete()
-{
- if (m_callback) m_callback(this, m_data);
-}
-
-void CompletionCallbackType::clearCallback()
-{
- m_callback = 0;
- m_data = 0;
-}
-
-void CompletionCallbackType::registerCallback(callback c, void *d)
-{
- m_callback = c;
- m_data = d;
-}
-
-void registerTypes()
-{
- qmlRegisterType<SelfRegisteringType>("Qt.test", 1,0, "SelfRegistering");
- qmlRegisterType<CompletionRegisteringType>("Qt.test", 1,0, "CompletionRegistering");
- qmlRegisterType<CallbackRegisteringType>("Qt.test", 1,0, "CallbackRegistering");
- qmlRegisterType<CompletionCallbackType>("Qt.test", 1,0, "CompletionCallback");
-}
diff --git a/tests/auto/declarative/qdeclarativeincubator/testtypes.h b/tests/auto/declarative/qdeclarativeincubator/testtypes.h
deleted file mode 100644
index 3e679d3119..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/testtypes.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** 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_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** 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.
-**
-** 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef TESTTYPES_H
-#define TESTTYPES_H
-
-#include <QtCore/qobject.h>
-#include <QDeclarativeParserStatus>
-
-class SelfRegisteringType : public QObject
-{
-Q_OBJECT
-Q_PROPERTY(int value READ value WRITE setValue);
-public:
- SelfRegisteringType();
-
- int value() const { return m_v; }
- void setValue(int v) { m_v = v; }
-
- static SelfRegisteringType *me();
- static void clearMe();
-
-private:
- static SelfRegisteringType *m_me;
-
- int m_v;
-};
-
-class CallbackRegisteringType : public QObject
-{
-Q_OBJECT
-Q_PROPERTY(int value READ value WRITE setValue)
-public:
- CallbackRegisteringType();
-
- int value() const { return m_v; }
- void setValue(int v) { if (m_callback) m_callback(this, m_data); m_v = v; }
-
- typedef void (*callback)(CallbackRegisteringType *, void *);
- static void clearCallback();
- static void registerCallback(callback, void *);
-
-private:
- static callback m_callback;
- static void *m_data;
-
- int m_v;
-};
-
-class CompletionRegisteringType : public QObject, public QDeclarativeParserStatus
-{
- Q_OBJECT
- Q_INTERFACES(QDeclarativeParserStatus)
-public:
- CompletionRegisteringType();
-
- virtual void classBegin();
- virtual void componentComplete();
-
- static CompletionRegisteringType *me();
- static void clearMe();
-
-private:
- static CompletionRegisteringType *m_me;
-};
-
-class CompletionCallbackType : public QObject, public QDeclarativeParserStatus
-{
- Q_OBJECT
- Q_INTERFACES(QDeclarativeParserStatus)
-public:
- CompletionCallbackType();
-
- virtual void classBegin();
- virtual void componentComplete();
-
- typedef void (*callback)(CompletionCallbackType *, void *);
- static void clearCallback();
- static void registerCallback(callback, void *);
-
-private:
- static callback m_callback;
- static void *m_data;
-};
-
-void registerTypes();
-
-#endif // TESTTYPES_H
diff --git a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp
deleted file mode 100644
index 7f68b9af95..0000000000
--- a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp
+++ /dev/null
@@ -1,1030 +0,0 @@
-/****************************************************************************
-**
-** 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_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** 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.
-**
-** 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "testtypes.h"
-
-#include <QUrl>
-#include <QDir>
-#include <QDebug>
-#include <qtest.h>
-#include <QPointer>
-#include <QFileInfo>
-#include <QDeclarativeEngine>
-#include <QDeclarativeContext>
-#include <QDeclarativeProperty>
-#include <QDeclarativeComponent>
-#include <QDeclarativeIncubator>
-#include "../../shared/util.h"
-
-class tst_qdeclarativeincubator : public QDeclarativeDataTest
-{
- Q_OBJECT
-public:
- tst_qdeclarativeincubator() {}
-
-private slots:
- void initTestCase();
-
- void incubationMode();
- void objectDeleted();
- void clear();
- void noIncubationController();
- void forceCompletion();
- void setInitialState();
- void clearDuringCompletion();
- void objectDeletionAfterInit();
- void recursiveClear();
- void statusChanged();
- void asynchronousIfNested();
- void nestedComponent();
- void chainedAsynchronousIfNested();
- void chainedAsynchronousIfNestedOnCompleted();
- void selfDelete();
- void contextDelete();
-
-private:
- QDeclarativeIncubationController controller;
- QDeclarativeEngine engine;
-};
-
-#define VERIFY_ERRORS(component, errorfile) \
- if (!errorfile) { \
- if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) \
- qWarning() << "Unexpected Errors:" << component.errors(); \
- QVERIFY(!component.isError()); \
- QVERIFY(component.errors().isEmpty()); \
- } else { \
- QFile file(QDeclarativeDataTest::instance()->testFile(errorfile)); \
- QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \
- QByteArray data = file.readAll(); \
- file.close(); \
- QList<QByteArray> expected = data.split('\n'); \
- expected.removeAll(QByteArray("")); \
- QList<QDeclarativeError> errors = component.errors(); \
- QList<QByteArray> actual; \
- for (int ii = 0; ii < errors.count(); ++ii) { \
- const QDeclarativeError &error = errors.at(ii); \
- QByteArray errorStr = QByteArray::number(error.line()) + ":" + \
- QByteArray::number(error.column()) + ":" + \
- error.description().toUtf8(); \
- actual << errorStr; \
- } \
- if (qgetenv("DEBUG") != "" && expected != actual) \
- qWarning() << "Expected:" << expected << "Actual:" << actual; \
- QCOMPARE(expected, actual); \
- }
-
-void tst_qdeclarativeincubator::initTestCase()
-{
- QDeclarativeDataTest::initTestCase();
- registerTypes();
- engine.setIncubationController(&controller);
-}
-
-void tst_qdeclarativeincubator::incubationMode()
-{
- {
- QDeclarativeIncubator incubator;
- QCOMPARE(incubator.incubationMode(), QDeclarativeIncubator::Asynchronous);
- }
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Asynchronous);
- QCOMPARE(incubator.incubationMode(), QDeclarativeIncubator::Asynchronous);
- }
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Synchronous);
- QCOMPARE(incubator.incubationMode(), QDeclarativeIncubator::Synchronous);
- }
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested);
- QCOMPARE(incubator.incubationMode(), QDeclarativeIncubator::AsynchronousIfNested);
- }
-}
-
-void tst_qdeclarativeincubator::objectDeleted()
-{
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("objectDeleted.qml"));
- QVERIFY(component.isReady());
-
- QDeclarativeIncubator incubator;
- component.create(incubator);
-
- QCOMPARE(incubator.status(), QDeclarativeIncubator::Loading);
- QVERIFY(SelfRegisteringType::me() == 0);
-
- while (SelfRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator.isLoading());
-
- delete SelfRegisteringType::me();
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isError());
- VERIFY_ERRORS(incubator, "objectDeleted.errors.txt");
- QVERIFY(incubator.object() == 0);
-}
-
-void tst_qdeclarativeincubator::clear()
-{
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("clear.qml"));
- QVERIFY(component.isReady());
-
- // Clear in null state
- {
- QDeclarativeIncubator incubator;
- QVERIFY(incubator.isNull());
- incubator.clear(); // no effect
- QVERIFY(incubator.isNull());
- }
-
- // Clear in loading state
- {
- QDeclarativeIncubator incubator;
- component.create(incubator);
- QVERIFY(incubator.isLoading());
- incubator.clear();
- QVERIFY(incubator.isNull());
- }
-
- // Clear mid load
- {
- QDeclarativeIncubator incubator;
- component.create(incubator);
-
- while (SelfRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(SelfRegisteringType::me() != 0);
- QPointer<SelfRegisteringType> srt = SelfRegisteringType::me();
-
- incubator.clear();
- QVERIFY(incubator.isNull());
- QVERIFY(srt.isNull());
- }
-
- // Clear in ready state
- {
- QDeclarativeIncubator incubator;
- component.create(incubator);
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object() != 0);
- QPointer<QObject> obj = incubator.object();
-
- incubator.clear();
- QVERIFY(incubator.isNull());
- QVERIFY(incubator.object() == 0);
- QVERIFY(!obj.isNull());
-
- delete obj;
- QVERIFY(obj.isNull());
- }
-}
-
-void tst_qdeclarativeincubator::noIncubationController()
-{
- // All incubators should behave synchronously when there is no controller
-
- QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, testFileUrl("noIncubationController.qml"));
-
- QVERIFY(component.isReady());
-
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component.create(incubator);
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("testValue").toInt(), 1913);
- delete incubator.object();
- }
-
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested);
- component.create(incubator);
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("testValue").toInt(), 1913);
- delete incubator.object();
- }
-
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Synchronous);
- component.create(incubator);
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("testValue").toInt(), 1913);
- delete incubator.object();
- }
-}
-
-void tst_qdeclarativeincubator::forceCompletion()
-{
- QDeclarativeComponent component(&engine, testFileUrl("forceCompletion.qml"));
- QVERIFY(component.isReady());
-
- {
- // forceCompletion on a null incubator does nothing
- QDeclarativeIncubator incubator;
- QVERIFY(incubator.isNull());
- incubator.forceCompletion();
- QVERIFY(incubator.isNull());
- }
-
- {
- // forceCompletion immediately after creating an asynchronous object completes it
- QDeclarativeIncubator incubator;
- QVERIFY(incubator.isNull());
- component.create(incubator);
- QVERIFY(incubator.isLoading());
-
- incubator.forceCompletion();
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object() != 0);
- QCOMPARE(incubator.object()->property("testValue").toInt(), 3499);
-
- delete incubator.object();
- }
-
- {
- // forceCompletion during creation completes it
- SelfRegisteringType::clearMe();
-
- QDeclarativeIncubator incubator;
- QVERIFY(incubator.isNull());
- component.create(incubator);
- QVERIFY(incubator.isLoading());
-
- while (SelfRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator.isLoading());
-
- incubator.forceCompletion();
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object() != 0);
- QCOMPARE(incubator.object()->property("testValue").toInt(), 3499);
-
- delete incubator.object();
- }
-
- {
- // forceCompletion on a ready incubator has no effect
- QDeclarativeIncubator incubator;
- QVERIFY(incubator.isNull());
- component.create(incubator);
- QVERIFY(incubator.isLoading());
-
- incubator.forceCompletion();
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object() != 0);
- QCOMPARE(incubator.object()->property("testValue").toInt(), 3499);
-
- incubator.forceCompletion();
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object() != 0);
- QCOMPARE(incubator.object()->property("testValue").toInt(), 3499);
-
- delete incubator.object();
- }
-}
-
-void tst_qdeclarativeincubator::setInitialState()
-{
- QDeclarativeComponent component(&engine, testFileUrl("setInitialState.qml"));
- QVERIFY(component.isReady());
-
- struct MyIncubator : public QDeclarativeIncubator
- {
- MyIncubator(QDeclarativeIncubator::IncubationMode mode)
- : QDeclarativeIncubator(mode) {}
-
- virtual void setInitialState(QObject *o) {
- QDeclarativeProperty::write(o, "test2", 19);
- QDeclarativeProperty::write(o, "testData1", 201);
- }
- };
-
- {
- MyIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component.create(incubator);
- QVERIFY(incubator.isLoading());
- bool b = true;
- controller.incubateWhile(&b);
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("myValueFunctionCalled").toBool(), false);
- QCOMPARE(incubator.object()->property("test1").toInt(), 502);
- QCOMPARE(incubator.object()->property("test2").toInt(), 19);
- delete incubator.object();
- }
-
- {
- MyIncubator incubator(QDeclarativeIncubator::Synchronous);
- component.create(incubator);
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("myValueFunctionCalled").toBool(), false);
- QCOMPARE(incubator.object()->property("test1").toInt(), 502);
- QCOMPARE(incubator.object()->property("test2").toInt(), 19);
- delete incubator.object();
- }
-}
-
-void tst_qdeclarativeincubator::clearDuringCompletion()
-{
- CompletionRegisteringType::clearMe();
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("clearDuringCompletion.qml"));
- QVERIFY(component.isReady());
-
- QDeclarativeIncubator incubator;
- component.create(incubator);
-
- QCOMPARE(incubator.status(), QDeclarativeIncubator::Loading);
- QVERIFY(CompletionRegisteringType::me() == 0);
-
- while (CompletionRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(CompletionRegisteringType::me() != 0);
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator.isLoading());
-
- QPointer<QObject> srt = SelfRegisteringType::me();
-
- incubator.clear();
- QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
- QCoreApplication::processEvents();
- QVERIFY(incubator.isNull());
- QVERIFY(srt.isNull());
-}
-
-void tst_qdeclarativeincubator::objectDeletionAfterInit()
-{
- QDeclarativeComponent component(&engine, testFileUrl("clear.qml"));
- QVERIFY(component.isReady());
-
- struct MyIncubator : public QDeclarativeIncubator
- {
- MyIncubator(QDeclarativeIncubator::IncubationMode mode)
- : QDeclarativeIncubator(mode), obj(0) {}
-
- virtual void setInitialState(QObject *o) {
- obj = o;
- }
-
- QObject *obj;
- };
-
- SelfRegisteringType::clearMe();
- MyIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component.create(incubator);
-
- while (!incubator.obj && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(SelfRegisteringType::me() != 0);
-
- delete incubator.obj;
-
- incubator.clear();
- QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
- QCoreApplication::processEvents();
- QVERIFY(incubator.isNull());
-}
-
-class Switcher : public QObject
-{
- Q_OBJECT
-public:
- Switcher(QDeclarativeEngine *e) : QObject(), engine(e) { }
-
- struct MyIncubator : public QDeclarativeIncubator
- {
- MyIncubator(QDeclarativeIncubator::IncubationMode mode, QObject *s)
- : QDeclarativeIncubator(mode), switcher(s) {}
-
- virtual void setInitialState(QObject *o) {
- if (o->objectName() == "switchMe")
- connect(o, SIGNAL(switchMe()), switcher, SLOT(switchIt()));
- }
-
- QObject *switcher;
- };
-
- void start()
- {
- incubator = new MyIncubator(QDeclarativeIncubator::Synchronous, this);
- component = new QDeclarativeComponent(engine, QDeclarativeDataTest::instance()->testFileUrl("recursiveClear.1.qml"));
- component->create(*incubator);
- }
-
- QDeclarativeEngine *engine;
- MyIncubator *incubator;
- QDeclarativeComponent *component;
-
-public slots:
- void switchIt() {
- component->deleteLater();
- incubator->clear();
- component = new QDeclarativeComponent(engine, QDeclarativeDataTest::instance()->testFileUrl("recursiveClear.2.qml"));
- component->create(*incubator);
- }
-};
-
-void tst_qdeclarativeincubator::recursiveClear()
-{
- Switcher switcher(&engine);
- switcher.start();
-}
-
-void tst_qdeclarativeincubator::statusChanged()
-{
- class MyIncubator : public QDeclarativeIncubator
- {
- public:
- MyIncubator(QDeclarativeIncubator::IncubationMode mode = QDeclarativeIncubator::Asynchronous)
- : QDeclarativeIncubator(mode) {}
-
- QList<int> statuses;
- protected:
- virtual void statusChanged(Status s) { statuses << s; }
- virtual void setInitialState(QObject *) { statuses << -1; }
- };
-
- {
- QDeclarativeComponent component(&engine, testFileUrl("statusChanged.qml"));
- QVERIFY(component.isReady());
-
- MyIncubator incubator(QDeclarativeIncubator::Synchronous);
- component.create(incubator);
- QVERIFY(incubator.isReady());
- QCOMPARE(incubator.statuses.count(), 3);
- QCOMPARE(incubator.statuses.at(0), int(QDeclarativeIncubator::Loading));
- QCOMPARE(incubator.statuses.at(1), -1);
- QCOMPARE(incubator.statuses.at(2), int(QDeclarativeIncubator::Ready));
- delete incubator.object();
- }
-
- {
- QDeclarativeComponent component(&engine, testFileUrl("statusChanged.qml"));
- QVERIFY(component.isReady());
-
- MyIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component.create(incubator);
- QVERIFY(incubator.isLoading());
- QCOMPARE(incubator.statuses.count(), 1);
- QCOMPARE(incubator.statuses.at(0), int(QDeclarativeIncubator::Loading));
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QCOMPARE(incubator.statuses.count(), 3);
- QCOMPARE(incubator.statuses.at(0), int(QDeclarativeIncubator::Loading));
- QCOMPARE(incubator.statuses.at(1), -1);
- QCOMPARE(incubator.statuses.at(2), int(QDeclarativeIncubator::Ready));
- delete incubator.object();
- }
-
- {
- QDeclarativeComponent component2(&engine, testFileUrl("statusChanged.nested.qml"));
- QVERIFY(component2.isReady());
-
- MyIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component2.create(incubator);
- QVERIFY(incubator.isLoading());
- QCOMPARE(incubator.statuses.count(), 1);
- QCOMPARE(incubator.statuses.at(0), int(QDeclarativeIncubator::Loading));
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isReady());
- QCOMPARE(incubator.statuses.count(), 3);
- QCOMPARE(incubator.statuses.at(0), int(QDeclarativeIncubator::Loading));
- QCOMPARE(incubator.statuses.at(1), -1);
- QCOMPARE(incubator.statuses.at(2), int(QDeclarativeIncubator::Ready));
- delete incubator.object();
- }
-}
-
-void tst_qdeclarativeincubator::asynchronousIfNested()
-{
- // Asynchronous if nested within a finalized context behaves synchronously
- {
- QDeclarativeComponent component(&engine, testFileUrl("asynchronousIfNested.1.qml"));
- QVERIFY(component.isReady());
-
- QObject *object = component.create();
- QVERIFY(object != 0);
- QCOMPARE(object->property("a").toInt(), 10);
-
- QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested);
- component.create(incubator, 0, qmlContext(object));
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("a").toInt(), 10);
- delete incubator.object();
- delete object;
- }
-
- // Asynchronous if nested within an executing context behaves asynchronously, but prevents
- // the parent from finishing
- {
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("asynchronousIfNested.2.qml"));
- QVERIFY(component.isReady());
-
- QDeclarativeIncubator incubator;
- component.create(incubator);
-
- QVERIFY(incubator.isLoading());
- QVERIFY(SelfRegisteringType::me() == 0);
- while (SelfRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator.isLoading());
-
- QDeclarativeIncubator nested(QDeclarativeIncubator::AsynchronousIfNested);
- component.create(nested, 0, qmlContext(SelfRegisteringType::me()));
- QVERIFY(nested.isLoading());
-
- while (nested.isLoading()) {
- QVERIFY(incubator.isLoading());
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(nested.isReady());
- QVERIFY(incubator.isLoading());
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(nested.isReady());
- QVERIFY(incubator.isReady());
-
- delete nested.object();
- delete incubator.object();
- }
-
- // AsynchronousIfNested within a synchronous AsynchronousIfNested behaves synchronously
- {
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("asynchronousIfNested.3.qml"));
- QVERIFY(component.isReady());
-
- struct CallbackData {
- CallbackData(QDeclarativeEngine *e) : engine(e), pass(false) {}
- QDeclarativeEngine *engine;
- bool pass;
- static void callback(CallbackRegisteringType *o, void *data) {
- CallbackData *d = (CallbackData *)data;
-
- QDeclarativeComponent c(d->engine, QDeclarativeDataTest::instance()->testFileUrl("asynchronousIfNested.1.qml"));
- if (!c.isReady()) return;
-
- QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested);
- c.create(incubator, 0, qmlContext(o));
-
- if (!incubator.isReady()) return;
-
- if (incubator.object()->property("a").toInt() != 10) return;
-
- d->pass = true;
- }
- };
-
- CallbackData cd(&engine);
- CallbackRegisteringType::registerCallback(&CallbackData::callback, &cd);
-
- QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested);
- component.create(incubator);
-
- QVERIFY(incubator.isReady());
- QCOMPARE(cd.pass, true);
-
- delete incubator.object();
- }
-}
-
-void tst_qdeclarativeincubator::nestedComponent()
-{
- QDeclarativeComponent component(&engine, testFileUrl("nestedComponent.qml"));
- QVERIFY(component.isReady());
-
- QObject *object = component.create();
-
- QDeclarativeComponent *nested = object->property("c").value<QDeclarativeComponent*>();
- QVERIFY(nested);
- QVERIFY(nested->isReady());
-
- // Test without incubator
- {
- QObject *nestedObject = nested->create();
- QCOMPARE(nestedObject->property("value").toInt(), 19988);
- delete nestedObject;
- }
-
- // Test with incubator
- {
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Synchronous);
- nested->create(incubator);
- QVERIFY(incubator.isReady());
- QVERIFY(incubator.object());
- QCOMPARE(incubator.object()->property("value").toInt(), 19988);
- delete incubator.object();
- }
-
- delete object;
-}
-
-// Checks that a new AsynchronousIfNested incubator can be correctly started in the
-// statusChanged() callback of another.
-void tst_qdeclarativeincubator::chainedAsynchronousIfNested()
-{
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("chainedAsynchronousIfNested.qml"));
- QVERIFY(component.isReady());
-
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component.create(incubator);
-
- QVERIFY(incubator.isLoading());
- QVERIFY(SelfRegisteringType::me() == 0);
-
- while (SelfRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator.isLoading());
-
- struct MyIncubator : public QDeclarativeIncubator {
- MyIncubator(MyIncubator *next, QDeclarativeComponent *component, QDeclarativeContext *ctxt)
- : QDeclarativeIncubator(AsynchronousIfNested), next(next), component(component), ctxt(ctxt) {}
-
- protected:
- virtual void statusChanged(Status s) {
- if (s == Ready && next)
- component->create(*next, 0, ctxt);
- }
-
- private:
- MyIncubator *next;
- QDeclarativeComponent *component;
- QDeclarativeContext *ctxt;
- };
-
- MyIncubator incubator2(0, &component, 0);
- MyIncubator incubator1(&incubator2, &component, qmlContext(SelfRegisteringType::me()));
-
- component.create(incubator1, 0, qmlContext(SelfRegisteringType::me()));
-
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isLoading());
- QVERIFY(incubator2.isNull());
-
- while (incubator1.isLoading()) {
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isLoading());
- QVERIFY(incubator2.isNull());
-
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isLoading());
-
- while (incubator2.isLoading()) {
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isLoading());
-
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isReady());
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isReady());
-}
-
-// Checks that new AsynchronousIfNested incubators can be correctly chained if started in
-// componentCompleted().
-void tst_qdeclarativeincubator::chainedAsynchronousIfNestedOnCompleted()
-{
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("chainInCompletion.qml"));
- QVERIFY(component.isReady());
-
- QDeclarativeComponent c1(&engine, testFileUrl("chainedAsynchronousIfNested.qml"));
- QVERIFY(c1.isReady());
-
- struct MyIncubator : public QDeclarativeIncubator {
- MyIncubator(MyIncubator *next, QDeclarativeComponent *component, QDeclarativeContext *ctxt)
- : QDeclarativeIncubator(AsynchronousIfNested), next(next), component(component), ctxt(ctxt) {}
-
- protected:
- virtual void statusChanged(Status s) {
- if (s == Ready && next) {
- component->create(*next, 0, ctxt);
- }
- }
-
- private:
- MyIncubator *next;
- QDeclarativeComponent *component;
- QDeclarativeContext *ctxt;
- };
-
- struct CallbackData {
- CallbackData(QDeclarativeComponent *c, MyIncubator *i, QDeclarativeContext *ct)
- : component(c), incubator(i), ctxt(ct) {}
- QDeclarativeComponent *component;
- MyIncubator *incubator;
- QDeclarativeContext *ctxt;
- static void callback(CompletionCallbackType *, void *data) {
- CallbackData *d = (CallbackData *)data;
- d->component->create(*d->incubator, 0, d->ctxt);
- }
- };
-
- QDeclarativeIncubator incubator(QDeclarativeIncubator::Asynchronous);
- component.create(incubator);
-
- QVERIFY(incubator.isLoading());
- QVERIFY(SelfRegisteringType::me() == 0);
-
- while (SelfRegisteringType::me() == 0 && incubator.isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator.isLoading());
-
- MyIncubator incubator3(0, &c1, qmlContext(SelfRegisteringType::me()));
- MyIncubator incubator2(&incubator3, &c1, qmlContext(SelfRegisteringType::me()));
- MyIncubator incubator1(&incubator2, &c1, qmlContext(SelfRegisteringType::me()));
-
- // start incubator1 in componentComplete
- CallbackData cd(&c1, &incubator1, qmlContext(SelfRegisteringType::me()));
- CompletionCallbackType::registerCallback(&CallbackData::callback, &cd);
-
- while (!incubator1.isLoading()) {
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator2.isNull());
- QVERIFY(incubator3.isNull());
-
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isLoading());
- QVERIFY(incubator2.isNull());
- QVERIFY(incubator3.isNull());
-
- while (incubator1.isLoading()) {
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isLoading());
- QVERIFY(incubator2.isNull());
- QVERIFY(incubator3.isNull());
-
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isLoading());
- QVERIFY(incubator3.isNull());
-
- while (incubator2.isLoading()) {
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isLoading());
- QVERIFY(incubator3.isNull());
-
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isReady());
- QVERIFY(incubator3.isLoading());
-
- while (incubator3.isLoading()) {
- QVERIFY(incubator.isLoading());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isReady());
- QVERIFY(incubator3.isLoading());
-
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(incubator.isReady());
- QVERIFY(incubator1.isReady());
- QVERIFY(incubator2.isReady());
- QVERIFY(incubator3.isReady());
-}
-
-void tst_qdeclarativeincubator::selfDelete()
-{
- struct MyIncubator : public QDeclarativeIncubator {
- MyIncubator(bool *done, Status status, IncubationMode mode)
- : QDeclarativeIncubator(mode), done(done), status(status) {}
-
- protected:
- virtual void statusChanged(Status s) {
- if (s == status) {
- *done = true;
- if (s == Ready) delete object();
- delete this;
- }
- }
-
- private:
- bool *done;
- Status status;
- };
-
- {
- QDeclarativeComponent component(&engine, testFileUrl("selfDelete.qml"));
-
-#define DELETE_TEST(status, mode) { \
- bool done = false; \
- component.create(*(new MyIncubator(&done, status, mode))); \
- bool True = true; \
- controller.incubateWhile(&True); \
- QVERIFY(done == true); \
- }
-
- DELETE_TEST(QDeclarativeIncubator::Loading, QDeclarativeIncubator::Synchronous);
- DELETE_TEST(QDeclarativeIncubator::Ready, QDeclarativeIncubator::Synchronous);
- DELETE_TEST(QDeclarativeIncubator::Loading, QDeclarativeIncubator::Asynchronous);
- DELETE_TEST(QDeclarativeIncubator::Ready, QDeclarativeIncubator::Asynchronous);
-
-#undef DELETE_TEST
- }
-
- // Delete within error status
- {
- SelfRegisteringType::clearMe();
-
- QDeclarativeComponent component(&engine, testFileUrl("objectDeleted.qml"));
- QVERIFY(component.isReady());
-
- bool done = false;
- MyIncubator *incubator = new MyIncubator(&done, QDeclarativeIncubator::Error,
- QDeclarativeIncubator::Asynchronous);
- component.create(*incubator);
-
- QCOMPARE(incubator->QDeclarativeIncubator::status(), QDeclarativeIncubator::Loading);
- QVERIFY(SelfRegisteringType::me() == 0);
-
- while (SelfRegisteringType::me() == 0 && incubator->isLoading()) {
- bool b = false;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(SelfRegisteringType::me() != 0);
- QVERIFY(incubator->isLoading());
-
- delete SelfRegisteringType::me();
-
- {
- bool b = true;
- controller.incubateWhile(&b);
- }
-
- QVERIFY(done);
- }
-}
-
-// Test that QML doesn't crash if the context is deleted prior to the incubator
-// first executing.
-void tst_qdeclarativeincubator::contextDelete()
-{
- QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
- QDeclarativeComponent component(&engine, testFileUrl("contextDelete.qml"));
-
- QDeclarativeIncubator incubator;
- component.create(incubator, context);
-
- delete context;
-
- {
- bool b = false;
- controller.incubateWhile(&b);
- }
-}
-
-QTEST_MAIN(tst_qdeclarativeincubator)
-
-#include "tst_qdeclarativeincubator.moc"