1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
46 #include <QDeclarativeContext>
47 #include <qdeclarativeinfo.h>
48 #include "../../shared/util.h"
50 class tst_qdeclarativeinfo : public QDeclarativeDataTest
54 tst_qdeclarativeinfo() {}
58 void nestedQmlObject();
59 void nestedComponent();
62 void nonQmlContextedObject();
67 QDeclarativeEngine engine;
70 void tst_qdeclarativeinfo::qmlObject()
72 QDeclarativeComponent component(&engine, testFileUrl("qmlObject.qml"));
74 QObject *object = component.create();
77 QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
78 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
79 qmlInfo(object) << "Test Message";
81 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
84 message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
85 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
86 qmlInfo(nested) << "Second Test Message";
89 void tst_qdeclarativeinfo::nestedQmlObject()
91 QDeclarativeComponent component(&engine, testFileUrl("nestedQmlObject.qml"));
93 QObject *object = component.create();
96 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
98 QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
99 QVERIFY(nested2 != 0);
101 QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
102 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
103 qmlInfo(nested) << "Outer Object";
105 message = testFileUrl("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
106 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
107 qmlInfo(nested2) << "Inner Object";
110 void tst_qdeclarativeinfo::nestedComponent()
112 QDeclarativeComponent component(&engine, testFileUrl("NestedComponent.qml"));
114 QObject *object = component.create();
115 QVERIFY(object != 0);
117 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
118 QVERIFY(nested != 0);
119 QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
120 QVERIFY(nested2 != 0);
122 QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
123 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
124 qmlInfo(nested) << "Complex Object";
126 message = component.url().toString() + ":16:9: QML Image: Simple Object";
127 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
128 qmlInfo(nested2) << "Simple Object";
131 void tst_qdeclarativeinfo::nonQmlObject()
134 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
135 qmlInfo(&object) << "Test Message";
138 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
139 qmlInfo(&nonQmlObject) << "Test Message";
142 void tst_qdeclarativeinfo::nullObject()
144 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
145 qmlInfo(0) << "Null Object Test Message";
148 void tst_qdeclarativeinfo::nonQmlContextedObject()
151 QDeclarativeContext context(&engine);
152 QDeclarativeEngine::setContextForObject(&object, &context);
153 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
154 qmlInfo(&object) << "Test Message";
157 void tst_qdeclarativeinfo::types()
159 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
162 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
165 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
168 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
171 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
172 qmlInfo(0) << QChar('b');
174 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
175 qmlInfo(0) << QByteArray("Qt");
177 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
178 qmlInfo(0) << bool(true);
180 //### do we actually want QUrl to show up in the output?
181 //### why the extra space at the end?
182 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QUrl(\"http://qt.nokia.com\") ");
183 qmlInfo(0) << QUrl("http://qt.nokia.com");
185 //### should this be quoted?
186 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
187 qmlInfo(0) << QLatin1String("hello");
189 //### should this be quoted?
190 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
191 QString str("Hello World");
192 QStringRef ref(&str, 6, 5);
195 //### should this be quoted?
196 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
197 qmlInfo(0) << QString ("Quick");
200 void tst_qdeclarativeinfo::chaining()
202 //### should more of these be automatically inserting spaces?
203 QString str("Hello World");
204 QStringRef ref(&str, 6, 5);
205 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' QUrl(\"http://qt.nokia.com\") World \"Qt\" true Quick ");
206 qmlInfo(0) << false << ' '
210 << QLatin1String("hello") << ' '
212 << QUrl("http://qt.nokia.com")
216 << QString ("Quick");
219 QTEST_MAIN(tst_qdeclarativeinfo)
221 #include "tst_qdeclarativeinfo.moc"