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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
45 #include <QPushButton>
46 #include <QDeclarativeContext>
47 #include <qdeclarativeinfo.h>
50 // In Symbian OS test data is located in applications private dir
54 class tst_qdeclarativeinfo : public QObject
58 tst_qdeclarativeinfo() {}
62 void nestedQmlObject();
65 void nonQmlContextedObject();
70 QDeclarativeEngine engine;
73 inline QUrl TEST_FILE(const QString &filename)
75 return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
78 void tst_qdeclarativeinfo::qmlObject()
80 QDeclarativeComponent component(&engine, TEST_FILE("qmlObject.qml"));
82 QObject *object = component.create();
85 QString message = component.url().toString() + ":3:1: QML QObject_QML_0: Test Message";
86 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
87 qmlInfo(object) << "Test Message";
89 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
92 message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
93 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
94 qmlInfo(nested) << "Second Test Message";
97 void tst_qdeclarativeinfo::nestedQmlObject()
99 QDeclarativeComponent component(&engine, TEST_FILE("nestedQmlObject.qml"));
101 QObject *object = component.create();
102 QVERIFY(object != 0);
104 QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
105 QVERIFY(nested != 0);
106 QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
107 QVERIFY(nested2 != 0);
109 QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
110 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
111 qmlInfo(nested) << "Outer Object";
113 message = TEST_FILE("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
114 QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
115 qmlInfo(nested2) << "Inner Object";
118 void tst_qdeclarativeinfo::nonQmlObject()
121 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
122 qmlInfo(&object) << "Test Message";
124 QPushButton pbObject;
125 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QPushButton: Test Message");
126 qmlInfo(&pbObject) << "Test Message";
129 void tst_qdeclarativeinfo::nullObject()
131 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
132 qmlInfo(0) << "Null Object Test Message";
135 void tst_qdeclarativeinfo::nonQmlContextedObject()
138 QDeclarativeContext context(&engine);
139 QDeclarativeEngine::setContextForObject(&object, &context);
140 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
141 qmlInfo(&object) << "Test Message";
144 void tst_qdeclarativeinfo::types()
146 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
149 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
152 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
155 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
158 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
159 qmlInfo(0) << QChar('b');
161 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
162 qmlInfo(0) << QByteArray("Qt");
164 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
165 qmlInfo(0) << QBool(true);
167 //### do we actually want QUrl to show up in the output?
168 //### why the extra space at the end?
169 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QUrl(\"http://qt.nokia.com\") ");
170 qmlInfo(0) << QUrl("http://qt.nokia.com");
172 //### should this be quoted?
173 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
174 qmlInfo(0) << QLatin1String("hello");
176 //### should this be quoted?
177 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
178 QString str("Hello World");
179 QStringRef ref(&str, 6, 5);
182 //### should this be quoted?
183 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
184 qmlInfo(0) << QString ("Quick");
187 void tst_qdeclarativeinfo::chaining()
189 //### should more of these be automatically inserting spaces?
190 QString str("Hello World");
191 QStringRef ref(&str, 6, 5);
192 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' QUrl(\"http://qt.nokia.com\") World \"Qt\" true Quick ");
193 qmlInfo(0) << false << ' '
197 << QLatin1String("hello") << ' '
199 << QUrl("http://qt.nokia.com")
203 << QString ("Quick");
206 QTEST_MAIN(tst_qdeclarativeinfo)
208 #include "tst_qdeclarativeinfo.moc"