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>
48 #include "../shared/util.h"
50 class tst_qdeclarativeinfo : public QObject
54 tst_qdeclarativeinfo() {}
58 void nestedQmlObject();
59 void nestedComponent();
62 void nonQmlContextedObject();
67 QDeclarativeEngine engine;
70 inline QUrl TEST_FILE(const QString &filename)
72 return QUrl::fromLocalFile(TESTDATA(filename));
75 void tst_qdeclarativeinfo::qmlObject()
77 QDeclarativeComponent component(&engine, TEST_FILE("qmlObject.qml"));
79 QObject *object = component.create();
82 QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
83 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
84 qmlInfo(object) << "Test Message";
86 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
89 message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
90 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
91 qmlInfo(nested) << "Second Test Message";
94 void tst_qdeclarativeinfo::nestedQmlObject()
96 QDeclarativeComponent component(&engine, TEST_FILE("nestedQmlObject.qml"));
98 QObject *object = component.create();
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);
106 QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
107 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
108 qmlInfo(nested) << "Outer Object";
110 message = TEST_FILE("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
111 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
112 qmlInfo(nested2) << "Inner Object";
115 void tst_qdeclarativeinfo::nestedComponent()
117 QDeclarativeComponent component(&engine, TEST_FILE("NestedComponent.qml"));
119 QObject *object = component.create();
120 QVERIFY(object != 0);
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);
127 QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
128 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
129 qmlInfo(nested) << "Complex Object";
131 message = component.url().toString() + ":16:9: QML Image: Simple Object";
132 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
133 qmlInfo(nested2) << "Simple Object";
136 void tst_qdeclarativeinfo::nonQmlObject()
139 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
140 qmlInfo(&object) << "Test Message";
143 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
144 qmlInfo(&nonQmlObject) << "Test Message";
147 void tst_qdeclarativeinfo::nullObject()
149 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
150 qmlInfo(0) << "Null Object Test Message";
153 void tst_qdeclarativeinfo::nonQmlContextedObject()
156 QDeclarativeContext context(&engine);
157 QDeclarativeEngine::setContextForObject(&object, &context);
158 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
159 qmlInfo(&object) << "Test Message";
162 void tst_qdeclarativeinfo::types()
164 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
167 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
170 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
173 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
176 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
177 qmlInfo(0) << QChar('b');
179 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
180 qmlInfo(0) << QByteArray("Qt");
182 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
183 qmlInfo(0) << QBool(true);
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");
190 //### should this be quoted?
191 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
192 qmlInfo(0) << QLatin1String("hello");
194 //### should this be quoted?
195 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
196 QString str("Hello World");
197 QStringRef ref(&str, 6, 5);
200 //### should this be quoted?
201 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
202 qmlInfo(0) << QString ("Quick");
205 void tst_qdeclarativeinfo::chaining()
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 << ' '
215 << QLatin1String("hello") << ' '
217 << QUrl("http://qt.nokia.com")
221 << QString ("Quick");
224 QTEST_MAIN(tst_qdeclarativeinfo)
226 #include "tst_qdeclarativeinfo.moc"