Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeinfo / tst_qdeclarativeinfo.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
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 #include "../../shared/util.h"
49
50 class tst_qdeclarativeinfo : public QDeclarativeDataTest
51 {
52     Q_OBJECT
53 public:
54     tst_qdeclarativeinfo() {}
55
56 private slots:
57     void qmlObject();
58     void nestedQmlObject();
59     void nestedComponent();
60     void nonQmlObject();
61     void nullObject();
62     void nonQmlContextedObject();
63     void types();
64     void chaining();
65
66 private:
67     QDeclarativeEngine engine;
68 };
69
70 void tst_qdeclarativeinfo::qmlObject()
71 {
72     QDeclarativeComponent component(&engine, testFileUrl("qmlObject.qml"));
73
74     QObject *object = component.create();
75     QVERIFY(object != 0);
76
77     QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
78     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
79     qmlInfo(object) << "Test Message";
80
81     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
82     QVERIFY(nested != 0);
83
84     message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
85     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
86     qmlInfo(nested) << "Second Test Message";
87 }
88
89 void tst_qdeclarativeinfo::nestedQmlObject()
90 {
91     QDeclarativeComponent component(&engine, testFileUrl("nestedQmlObject.qml"));
92
93     QObject *object = component.create();
94     QVERIFY(object != 0);
95
96     QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
97     QVERIFY(nested != 0);
98     QObject *nested2 = qvariant_cast<QObject *>(object->property("nested2"));
99     QVERIFY(nested2 != 0);
100
101     QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
102     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
103     qmlInfo(nested) << "Outer Object";
104
105     message = testFileUrl("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
106     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
107     qmlInfo(nested2) << "Inner Object";
108 }
109
110 void tst_qdeclarativeinfo::nestedComponent()
111 {
112     QDeclarativeComponent component(&engine, testFileUrl("NestedComponent.qml"));
113
114     QObject *object = component.create();
115     QVERIFY(object != 0);
116
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);
121
122     QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
123     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
124     qmlInfo(nested) << "Complex Object";
125
126     message = component.url().toString() + ":16:9: QML Image: Simple Object";
127     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
128     qmlInfo(nested2) << "Simple Object";
129 }
130
131 void tst_qdeclarativeinfo::nonQmlObject()
132 {
133     QObject object;
134     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
135     qmlInfo(&object) << "Test Message";
136
137     QTimer nonQmlObject;
138     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
139     qmlInfo(&nonQmlObject) << "Test Message";
140 }
141
142 void tst_qdeclarativeinfo::nullObject()
143 {
144     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
145     qmlInfo(0) << "Null Object Test Message";
146 }
147
148 void tst_qdeclarativeinfo::nonQmlContextedObject()
149 {
150     QObject object;
151     QDeclarativeContext context(&engine);
152     QDeclarativeEngine::setContextForObject(&object, &context);
153     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
154     qmlInfo(&object) << "Test Message";
155 }
156
157 void tst_qdeclarativeinfo::types()
158 {
159     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
160     qmlInfo(0) << false;
161
162     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
163     qmlInfo(0) << 1.1;
164
165     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
166     qmlInfo(0) << 1.2f;
167
168     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
169     qmlInfo(0) << 15;
170
171     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
172     qmlInfo(0) << QChar('b');
173
174     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
175     qmlInfo(0) << QByteArray("Qt");
176
177     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
178     qmlInfo(0) << bool(true);
179
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");
184
185     //### should this be quoted?
186     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
187     qmlInfo(0) << QLatin1String("hello");
188
189     //### should this be quoted?
190     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
191     QString str("Hello World");
192     QStringRef ref(&str, 6, 5);
193     qmlInfo(0) << ref;
194
195     //### should this be quoted?
196     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
197     qmlInfo(0) << QString ("Quick");
198 }
199
200 void tst_qdeclarativeinfo::chaining()
201 {
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 << ' '
207                << 1.1 << ' '
208                << 1.2f << ' '
209                << 15 << ' '
210                << QLatin1String("hello") << ' '
211                << QChar('b') << ' '
212                << QUrl("http://qt.nokia.com")
213                << ref
214                << QByteArray("Qt")
215                << bool(true)
216                << QString ("Quick");
217 }
218
219 QTEST_MAIN(tst_qdeclarativeinfo)
220
221 #include "tst_qdeclarativeinfo.moc"