Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeerror / tst_qdeclarativeerror.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 <QDeclarativeError>
44 #include <QDebug>
45 #include "../../shared/util.h"
46
47 class tst_qdeclarativeerror : public QDeclarativeDataTest
48 {
49     Q_OBJECT
50 private slots:
51     void url();
52     void description();
53     void line();
54     void column();
55     void toString();
56
57     void copy();
58     void debug();
59 };
60
61 void tst_qdeclarativeerror::url()
62 {
63     QDeclarativeError error;
64
65     QCOMPARE(error.url(), QUrl());
66
67     error.setUrl(QUrl("http://www.nokia.com/main.qml"));
68
69     QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml"));
70
71     QDeclarativeError error2 = error;
72
73     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
74
75     error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
76
77     QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
78     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
79 }
80
81 void tst_qdeclarativeerror::description()
82 {
83     QDeclarativeError error;
84
85     QCOMPARE(error.description(), QString());
86
87     error.setDescription("An Error");
88
89     QCOMPARE(error.description(), QString("An Error"));
90
91     QDeclarativeError error2 = error;
92
93     QCOMPARE(error2.description(), QString("An Error"));
94
95     error.setDescription("Another Error");
96
97     QCOMPARE(error.description(), QString("Another Error"));
98     QCOMPARE(error2.description(), QString("An Error"));
99 }
100
101 void tst_qdeclarativeerror::line()
102 {
103     QDeclarativeError error;
104
105     QCOMPARE(error.line(), -1);
106
107     error.setLine(102);
108
109     QCOMPARE(error.line(), 102);
110
111     QDeclarativeError error2 = error;
112
113     QCOMPARE(error2.line(), 102);
114
115     error.setLine(4);
116
117     QCOMPARE(error.line(), 4);
118     QCOMPARE(error2.line(), 102);
119 }
120
121 void tst_qdeclarativeerror::column()
122 {
123     QDeclarativeError error;
124
125     QCOMPARE(error.column(), -1);
126
127     error.setColumn(16);
128
129     QCOMPARE(error.column(), 16);
130
131     QDeclarativeError error2 = error;
132
133     QCOMPARE(error2.column(), 16);
134
135     error.setColumn(3);
136
137     QCOMPARE(error.column(), 3);
138     QCOMPARE(error2.column(), 16);
139 }
140
141 void tst_qdeclarativeerror::toString()
142 {
143     {
144         QDeclarativeError error;
145         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
146         error.setDescription("An Error");
147         error.setLine(92);
148         error.setColumn(13);
149
150         QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error"));
151     }
152
153     {
154         QDeclarativeError error;
155         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
156         error.setDescription("An Error");
157         error.setLine(92);
158
159         QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error"));
160     }
161 }
162
163 void tst_qdeclarativeerror::copy()
164 {
165     QDeclarativeError error;
166     error.setUrl(QUrl("http://www.nokia.com/main.qml"));
167     error.setDescription("An Error");
168     error.setLine(92);
169     error.setColumn(13);
170
171     QDeclarativeError error2(error);
172     QDeclarativeError error3;
173     error3 = error;
174
175     error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
176     error.setDescription("Another Error");
177     error.setLine(2);
178     error.setColumn(33);
179
180     QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
181     QCOMPARE(error.description(), QString("Another Error"));
182     QCOMPARE(error.line(), 2);
183     QCOMPARE(error.column(), 33);
184
185     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
186     QCOMPARE(error2.description(), QString("An Error"));
187     QCOMPARE(error2.line(), 92);
188     QCOMPARE(error2.column(), 13);
189
190     QCOMPARE(error3.url(), QUrl("http://www.nokia.com/main.qml"));
191     QCOMPARE(error3.description(), QString("An Error"));
192     QCOMPARE(error3.line(), 92);
193     QCOMPARE(error3.column(), 13);
194
195 }
196
197 void tst_qdeclarativeerror::debug()
198 {
199     {
200         QDeclarativeError error;
201         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
202         error.setDescription("An Error");
203         error.setLine(92);
204         error.setColumn(13);
205
206         QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error ");
207         qWarning() << error;
208     }
209
210     {
211         QUrl url(dataDirectoryUrl().resolved(QUrl("test.txt")));
212         QDeclarativeError error;
213         error.setUrl(url);
214         error.setDescription("An Error");
215         error.setLine(2);
216         error.setColumn(5);
217
218         QString out = url.toString() + ":2:5: An Error \n     Line2 Content \n         ^ ";
219         QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
220
221         qWarning() << error;
222     }
223
224     {
225         QUrl url(dataDirectoryUrl().resolved(QUrl("foo.txt")));
226         QDeclarativeError error;
227         error.setUrl(url);
228         error.setDescription("An Error");
229         error.setLine(2);
230         error.setColumn(5);
231
232         QString out = url.toString() + ":2:5: An Error ";
233         QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
234
235         qWarning() << error;
236     }
237 }
238
239
240
241 QTEST_MAIN(tst_qdeclarativeerror)
242
243 #include "tst_qdeclarativeerror.moc"