1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
46 #include <QDeclarativeContext>
47 #include <qdeclarativeinfo.h>
49 class tst_qdeclarativeinfo : public QObject
53 tst_qdeclarativeinfo() {}
57 void nestedQmlObject();
58 void nestedComponent();
61 void nonQmlContextedObject();
66 QDeclarativeEngine engine;
69 inline QUrl TEST_FILE(const QString &filename)
71 return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
74 void tst_qdeclarativeinfo::qmlObject()
76 QDeclarativeComponent component(&engine, TEST_FILE("qmlObject.qml"));
78 QObject *object = component.create();
81 QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
82 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
83 qmlInfo(object) << "Test Message";
85 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
88 message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
89 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
90 qmlInfo(nested) << "Second Test Message";
93 void tst_qdeclarativeinfo::nestedQmlObject()
95 QDeclarativeComponent component(&engine, TEST_FILE("nestedQmlObject.qml"));
97 QObject *object = component.create();
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);
105 QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
106 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
107 qmlInfo(nested) << "Outer Object";
109 message = TEST_FILE("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
110 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
111 qmlInfo(nested2) << "Inner Object";
114 void tst_qdeclarativeinfo::nestedComponent()
116 QDeclarativeComponent component(&engine, TEST_FILE("NestedComponent.qml"));
118 QObject *object = component.create();
119 QVERIFY(object != 0);
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);
126 QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
127 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
128 qmlInfo(nested) << "Complex Object";
130 message = component.url().toString() + ":16:9: QML Image: Simple Object";
131 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
132 qmlInfo(nested2) << "Simple Object";
135 void tst_qdeclarativeinfo::nonQmlObject()
138 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
139 qmlInfo(&object) << "Test Message";
142 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
143 qmlInfo(&nonQmlObject) << "Test Message";
146 void tst_qdeclarativeinfo::nullObject()
148 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
149 qmlInfo(0) << "Null Object Test Message";
152 void tst_qdeclarativeinfo::nonQmlContextedObject()
155 QDeclarativeContext context(&engine);
156 QDeclarativeEngine::setContextForObject(&object, &context);
157 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
158 qmlInfo(&object) << "Test Message";
161 void tst_qdeclarativeinfo::types()
163 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
166 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
169 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
172 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
175 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
176 qmlInfo(0) << QChar('b');
178 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
179 qmlInfo(0) << QByteArray("Qt");
181 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
182 qmlInfo(0) << QBool(true);
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");
189 //### should this be quoted?
190 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
191 qmlInfo(0) << QLatin1String("hello");
193 //### should this be quoted?
194 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
195 QString str("Hello World");
196 QStringRef ref(&str, 6, 5);
199 //### should this be quoted?
200 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
201 qmlInfo(0) << QString ("Quick");
204 void tst_qdeclarativeinfo::chaining()
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 << ' '
214 << QLatin1String("hello") << ' '
216 << QUrl("http://qt.nokia.com")
220 << QString ("Quick");
223 QTEST_MAIN(tst_qdeclarativeinfo)
225 #include "tst_qdeclarativeinfo.moc"