Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / benchmarks / declarative / typeimports / tst_typeimports.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
45 #include <QDebug>
46
47 class tst_typeimports : public QObject
48 {
49     Q_OBJECT
50 public:
51     tst_typeimports();
52
53 private slots:
54     void cpp();
55     void qml();
56
57 private:
58     QDeclarativeEngine engine;
59 };
60
61 class TestType1 : public QObject
62 {
63     Q_OBJECT
64     Q_PROPERTY(QDeclarativeListProperty<QObject> resources READ resources);
65     Q_CLASSINFO("DefaultProperty", "resources");
66 public:
67     TestType1(QObject *parent = 0) : QObject(parent) {}
68
69     QDeclarativeListProperty<QObject> resources() {
70         return QDeclarativeListProperty<QObject>(this, 0, resources_append);
71     }
72
73     static void resources_append(QDeclarativeListProperty<QObject> *p, QObject *o) {
74         o->setParent(p->object);
75     }
76 };
77
78 class TestType2 : public TestType1
79 {
80     Q_OBJECT
81 public:
82     TestType2(QObject *parent = 0) : TestType1(parent) {}
83 };
84
85
86 class TestType3 : public TestType1
87 {
88     Q_OBJECT
89 public:
90     TestType3(QObject *parent = 0) : TestType1(parent) {}
91 };
92
93 class TestType4 : public TestType1
94 {
95     Q_OBJECT
96 public:
97     TestType4(QObject *parent = 0) : TestType1(parent) {}
98 };
99
100
101 tst_typeimports::tst_typeimports()
102 {
103     qmlRegisterType<TestType1>("Qt.test", 1, 0, "TestType1");
104     qmlRegisterType<TestType2>("Qt.test", 1, 0, "TestType2");
105     qmlRegisterType<TestType3>("Qt.test", 2, 0, "TestType3");
106     qmlRegisterType<TestType4>("Qt.test", 2, 0, "TestType4");
107 }
108
109 inline QUrl TEST_FILE(const QString &filename)
110 {
111     return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
112 }
113
114 void tst_typeimports::cpp()
115 {
116     QBENCHMARK {
117         QDeclarativeComponent component(&engine, TEST_FILE("cpp.qml"));
118         QVERIFY(component.isReady());
119     }
120 }
121
122 void tst_typeimports::qml()
123 {
124     //get rid of initialization effects
125     { QDeclarativeComponent component(&engine, TEST_FILE("qml.qml")); }
126
127     QBENCHMARK {
128         QDeclarativeComponent component(&engine, TEST_FILE("qml.qml"));
129         QVERIFY(component.isReady());
130     }
131 }
132
133 QTEST_MAIN(tst_typeimports)
134
135 #include "tst_typeimports.moc"