960b042b9554b237350cf29a28dbd7a2b5d65532
[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
49 class tst_qdeclarativeinfo : public QObject
50 {
51     Q_OBJECT
52 public:
53     tst_qdeclarativeinfo() {}
54
55 private slots:
56     void qmlObject();
57     void nestedQmlObject();
58     void nestedComponent();
59     void nonQmlObject();
60     void nullObject();
61     void nonQmlContextedObject();
62     void types();
63     void chaining();
64
65 private:
66     QDeclarativeEngine engine;
67 };
68
69 inline QUrl TEST_FILE(const QString &filename)
70 {
71     return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
72 }
73
74 void tst_qdeclarativeinfo::qmlObject()
75 {
76     QDeclarativeComponent component(&engine, TEST_FILE("qmlObject.qml"));
77
78     QObject *object = component.create();
79     QVERIFY(object != 0);
80
81     QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
82     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
83     qmlInfo(object) << "Test Message";
84
85     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
86     QVERIFY(nested != 0);
87
88     message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
89     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
90     qmlInfo(nested) << "Second Test Message";
91 }
92
93 void tst_qdeclarativeinfo::nestedQmlObject()
94 {
95     QDeclarativeComponent component(&engine, TEST_FILE("nestedQmlObject.qml"));
96
97     QObject *object = component.create();
98     QVERIFY(object != 0);
99
100     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
101     QVERIFY(nested != 0);
102     QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
103     QVERIFY(nested2 != 0);
104
105     QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
106     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
107     qmlInfo(nested) << "Outer Object";
108
109     message = TEST_FILE("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
110     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
111     qmlInfo(nested2) << "Inner Object";
112 }
113
114 void tst_qdeclarativeinfo::nestedComponent()
115 {
116     QDeclarativeComponent component(&engine, TEST_FILE("NestedComponent.qml"));
117
118     QObject *object = component.create();
119     QVERIFY(object != 0);
120
121     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
122     QVERIFY(nested != 0);
123     QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
124     QVERIFY(nested2 != 0);
125
126     QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
127     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
128     qmlInfo(nested) << "Complex Object";
129
130     message = component.url().toString() + ":16:9: QML Image: Simple Object";
131     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
132     qmlInfo(nested2) << "Simple Object";
133 }
134
135 void tst_qdeclarativeinfo::nonQmlObject()
136 {
137     QObject object;
138     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
139     qmlInfo(&object) << "Test Message";
140
141     QTimer nonQmlObject;
142     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
143     qmlInfo(&nonQmlObject) << "Test Message";
144 }
145
146 void tst_qdeclarativeinfo::nullObject()
147 {
148     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
149     qmlInfo(0) << "Null Object Test Message";
150 }
151
152 void tst_qdeclarativeinfo::nonQmlContextedObject()
153 {
154     QObject object;
155     QDeclarativeContext context(&engine);
156     QDeclarativeEngine::setContextForObject(&object, &context);
157     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
158     qmlInfo(&object) << "Test Message";
159 }
160
161 void tst_qdeclarativeinfo::types()
162 {
163     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
164     qmlInfo(0) << false;
165
166     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
167     qmlInfo(0) << 1.1;
168
169     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
170     qmlInfo(0) << 1.2f;
171
172     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
173     qmlInfo(0) << 15;
174
175     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
176     qmlInfo(0) << QChar('b');
177
178     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
179     qmlInfo(0) << QByteArray("Qt");
180
181     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
182     qmlInfo(0) << QBool(true);
183
184     //### do we actually want QUrl to show up in the output?
185     //### why the extra space at the end?
186     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QUrl(\"http://qt.nokia.com\") ");
187     qmlInfo(0) << QUrl("http://qt.nokia.com");
188
189     //### should this be quoted?
190     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
191     qmlInfo(0) << QLatin1String("hello");
192
193     //### should this be quoted?
194     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
195     QString str("Hello World");
196     QStringRef ref(&str, 6, 5);
197     qmlInfo(0) << ref;
198
199     //### should this be quoted?
200     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
201     qmlInfo(0) << QString ("Quick");
202 }
203
204 void tst_qdeclarativeinfo::chaining()
205 {
206     //### should more of these be automatically inserting spaces?
207     QString str("Hello World");
208     QStringRef ref(&str, 6, 5);
209     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' QUrl(\"http://qt.nokia.com\") World \"Qt\" true Quick ");
210     qmlInfo(0) << false << ' '
211                << 1.1 << ' '
212                << 1.2f << ' '
213                << 15 << ' '
214                << QLatin1String("hello") << ' '
215                << QChar('b') << ' '
216                << QUrl("http://qt.nokia.com")
217                << ref
218                << QByteArray("Qt")
219                << QBool(true)
220                << QString ("Quick");
221 }
222
223 QTEST_MAIN(tst_qdeclarativeinfo)
224
225 #include "tst_qdeclarativeinfo.moc"