Use TESTDATA macro in declarative tests.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeinfo / tst_qdeclarativeinfo.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
45 #include <QTimer>
46 #include <QDeclarativeContext>
47 #include <qdeclarativeinfo.h>
48 #include "../shared/util.h"
49
50 class tst_qdeclarativeinfo : public QObject
51 {
52     Q_OBJECT
53 public:
54     tst_qdeclarativeinfo() {}
55
56 private slots:
57     void qmlObject();
58     void nestedQmlObject();
59     void nestedComponent();
60     void nonQmlObject();
61     void nullObject();
62     void nonQmlContextedObject();
63     void types();
64     void chaining();
65
66 private:
67     QDeclarativeEngine engine;
68 };
69
70 inline QUrl TEST_FILE(const QString &filename)
71 {
72     return QUrl::fromLocalFile(TESTDATA(filename));
73 }
74
75 void tst_qdeclarativeinfo::qmlObject()
76 {
77     QDeclarativeComponent component(&engine, TEST_FILE("qmlObject.qml"));
78
79     QObject *object = component.create();
80     QVERIFY(object != 0);
81
82     QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
83     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
84     qmlInfo(object) << "Test Message";
85
86     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
87     QVERIFY(nested != 0);
88
89     message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
90     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
91     qmlInfo(nested) << "Second Test Message";
92 }
93
94 void tst_qdeclarativeinfo::nestedQmlObject()
95 {
96     QDeclarativeComponent component(&engine, TEST_FILE("nestedQmlObject.qml"));
97
98     QObject *object = component.create();
99     QVERIFY(object != 0);
100
101     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
102     QVERIFY(nested != 0);
103     QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
104     QVERIFY(nested2 != 0);
105
106     QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
107     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
108     qmlInfo(nested) << "Outer Object";
109
110     message = TEST_FILE("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
111     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
112     qmlInfo(nested2) << "Inner Object";
113 }
114
115 void tst_qdeclarativeinfo::nestedComponent()
116 {
117     QDeclarativeComponent component(&engine, TEST_FILE("NestedComponent.qml"));
118
119     QObject *object = component.create();
120     QVERIFY(object != 0);
121
122     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
123     QVERIFY(nested != 0);
124     QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
125     QVERIFY(nested2 != 0);
126
127     QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
128     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
129     qmlInfo(nested) << "Complex Object";
130
131     message = component.url().toString() + ":16:9: QML Image: Simple Object";
132     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
133     qmlInfo(nested2) << "Simple Object";
134 }
135
136 void tst_qdeclarativeinfo::nonQmlObject()
137 {
138     QObject object;
139     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
140     qmlInfo(&object) << "Test Message";
141
142     QTimer nonQmlObject;
143     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
144     qmlInfo(&nonQmlObject) << "Test Message";
145 }
146
147 void tst_qdeclarativeinfo::nullObject()
148 {
149     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
150     qmlInfo(0) << "Null Object Test Message";
151 }
152
153 void tst_qdeclarativeinfo::nonQmlContextedObject()
154 {
155     QObject object;
156     QDeclarativeContext context(&engine);
157     QDeclarativeEngine::setContextForObject(&object, &context);
158     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
159     qmlInfo(&object) << "Test Message";
160 }
161
162 void tst_qdeclarativeinfo::types()
163 {
164     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
165     qmlInfo(0) << false;
166
167     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
168     qmlInfo(0) << 1.1;
169
170     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
171     qmlInfo(0) << 1.2f;
172
173     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
174     qmlInfo(0) << 15;
175
176     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
177     qmlInfo(0) << QChar('b');
178
179     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
180     qmlInfo(0) << QByteArray("Qt");
181
182     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
183     qmlInfo(0) << QBool(true);
184
185     //### do we actually want QUrl to show up in the output?
186     //### why the extra space at the end?
187     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QUrl(\"http://qt.nokia.com\") ");
188     qmlInfo(0) << QUrl("http://qt.nokia.com");
189
190     //### should this be quoted?
191     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
192     qmlInfo(0) << QLatin1String("hello");
193
194     //### should this be quoted?
195     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
196     QString str("Hello World");
197     QStringRef ref(&str, 6, 5);
198     qmlInfo(0) << ref;
199
200     //### should this be quoted?
201     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
202     qmlInfo(0) << QString ("Quick");
203 }
204
205 void tst_qdeclarativeinfo::chaining()
206 {
207     //### should more of these be automatically inserting spaces?
208     QString str("Hello World");
209     QStringRef ref(&str, 6, 5);
210     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' QUrl(\"http://qt.nokia.com\") World \"Qt\" true Quick ");
211     qmlInfo(0) << false << ' '
212                << 1.1 << ' '
213                << 1.2f << ' '
214                << 15 << ' '
215                << QLatin1String("hello") << ' '
216                << QChar('b') << ' '
217                << QUrl("http://qt.nokia.com")
218                << ref
219                << QByteArray("Qt")
220                << QBool(true)
221                << QString ("Quick");
222 }
223
224 QTEST_MAIN(tst_qdeclarativeinfo)
225
226 #include "tst_qdeclarativeinfo.moc"