Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeerror / tst_qdeclarativeerror.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QDeclarativeError>
44 #include <QDebug>
45
46 #ifdef Q_OS_SYMBIAN
47 // In Symbian OS test data is located in applications private dir
48 #define SRCDIR "."
49 #endif
50
51 class tst_qdeclarativeerror : public QObject
52 {
53     Q_OBJECT
54 private slots:
55     void url();
56     void description();
57     void line();
58     void column();
59     void toString();
60
61     void copy();
62     void debug();
63 };
64
65 void tst_qdeclarativeerror::url()
66 {
67     QDeclarativeError error;
68
69     QCOMPARE(error.url(), QUrl());
70
71     error.setUrl(QUrl("http://www.nokia.com/main.qml"));
72
73     QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml"));
74
75     QDeclarativeError error2 = error;
76
77     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
78
79     error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
80
81     QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
82     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
83 }
84
85 void tst_qdeclarativeerror::description()
86 {
87     QDeclarativeError error;
88
89     QCOMPARE(error.description(), QString());
90
91     error.setDescription("An Error");
92
93     QCOMPARE(error.description(), QString("An Error"));
94
95     QDeclarativeError error2 = error;
96
97     QCOMPARE(error2.description(), QString("An Error"));
98
99     error.setDescription("Another Error");
100
101     QCOMPARE(error.description(), QString("Another Error"));
102     QCOMPARE(error2.description(), QString("An Error"));
103 }
104
105 void tst_qdeclarativeerror::line()
106 {
107     QDeclarativeError error;
108
109     QCOMPARE(error.line(), -1);
110
111     error.setLine(102);
112
113     QCOMPARE(error.line(), 102);
114
115     QDeclarativeError error2 = error;
116
117     QCOMPARE(error2.line(), 102);
118
119     error.setLine(4);
120
121     QCOMPARE(error.line(), 4);
122     QCOMPARE(error2.line(), 102);
123 }
124
125 void tst_qdeclarativeerror::column()
126 {
127     QDeclarativeError error;
128
129     QCOMPARE(error.column(), -1);
130
131     error.setColumn(16);
132
133     QCOMPARE(error.column(), 16);
134
135     QDeclarativeError error2 = error;
136
137     QCOMPARE(error2.column(), 16);
138
139     error.setColumn(3);
140
141     QCOMPARE(error.column(), 3);
142     QCOMPARE(error2.column(), 16);
143 }
144
145 void tst_qdeclarativeerror::toString()
146 {
147     {
148         QDeclarativeError error;
149         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
150         error.setDescription("An Error");
151         error.setLine(92);
152         error.setColumn(13);
153
154         QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error"));
155     }
156
157     {
158         QDeclarativeError error;
159         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
160         error.setDescription("An Error");
161         error.setLine(92);
162
163         QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error"));
164     }
165 }
166
167 void tst_qdeclarativeerror::copy()
168 {
169     QDeclarativeError error;
170     error.setUrl(QUrl("http://www.nokia.com/main.qml"));
171     error.setDescription("An Error");
172     error.setLine(92);
173     error.setColumn(13);
174
175     QDeclarativeError error2(error);
176     QDeclarativeError error3;
177     error3 = error;
178
179     error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
180     error.setDescription("Another Error");
181     error.setLine(2);
182     error.setColumn(33);
183
184     QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
185     QCOMPARE(error.description(), QString("Another Error"));
186     QCOMPARE(error.line(), 2);
187     QCOMPARE(error.column(), 33);
188
189     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
190     QCOMPARE(error2.description(), QString("An Error"));
191     QCOMPARE(error2.line(), 92);
192     QCOMPARE(error2.column(), 13);
193
194     QCOMPARE(error3.url(), QUrl("http://www.nokia.com/main.qml"));
195     QCOMPARE(error3.description(), QString("An Error"));
196     QCOMPARE(error3.line(), 92);
197     QCOMPARE(error3.column(), 13);
198
199 }
200
201 void tst_qdeclarativeerror::debug()
202 {
203     {
204         QDeclarativeError error;
205         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
206         error.setDescription("An Error");
207         error.setLine(92);
208         error.setColumn(13);
209
210         QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error ");
211         qWarning() << error;
212     }
213
214     {
215         QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt")));
216         QDeclarativeError error;
217         error.setUrl(url);
218         error.setDescription("An Error");
219         error.setLine(2);
220         error.setColumn(5);
221
222         QString out = url.toString() + ":2:5: An Error \n     Line2 Content \n         ^ ";
223         QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
224
225         qWarning() << error;
226     }
227
228     {
229         QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt")));
230         QDeclarativeError error;
231         error.setUrl(url);
232         error.setDescription("An Error");
233         error.setLine(2);
234         error.setColumn(5);
235
236         QString out = url.toString() + ":2:5: An Error ";
237         QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
238
239         qWarning() << error;
240     }
241 }
242
243
244
245 QTEST_MAIN(tst_qdeclarativeerror)
246
247 #include "tst_qdeclarativeerror.moc"