Remove Symbian-specific code from tests.
[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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QDeclarativeError>
44 #include <QDebug>
45
46 class tst_qdeclarativeerror : public QObject
47 {
48     Q_OBJECT
49 private slots:
50     void url();
51     void description();
52     void line();
53     void column();
54     void toString();
55
56     void copy();
57     void debug();
58 };
59
60 void tst_qdeclarativeerror::url()
61 {
62     QDeclarativeError error;
63
64     QCOMPARE(error.url(), QUrl());
65
66     error.setUrl(QUrl("http://www.nokia.com/main.qml"));
67
68     QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml"));
69
70     QDeclarativeError error2 = error;
71
72     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
73
74     error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
75
76     QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
77     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
78 }
79
80 void tst_qdeclarativeerror::description()
81 {
82     QDeclarativeError error;
83
84     QCOMPARE(error.description(), QString());
85
86     error.setDescription("An Error");
87
88     QCOMPARE(error.description(), QString("An Error"));
89
90     QDeclarativeError error2 = error;
91
92     QCOMPARE(error2.description(), QString("An Error"));
93
94     error.setDescription("Another Error");
95
96     QCOMPARE(error.description(), QString("Another Error"));
97     QCOMPARE(error2.description(), QString("An Error"));
98 }
99
100 void tst_qdeclarativeerror::line()
101 {
102     QDeclarativeError error;
103
104     QCOMPARE(error.line(), -1);
105
106     error.setLine(102);
107
108     QCOMPARE(error.line(), 102);
109
110     QDeclarativeError error2 = error;
111
112     QCOMPARE(error2.line(), 102);
113
114     error.setLine(4);
115
116     QCOMPARE(error.line(), 4);
117     QCOMPARE(error2.line(), 102);
118 }
119
120 void tst_qdeclarativeerror::column()
121 {
122     QDeclarativeError error;
123
124     QCOMPARE(error.column(), -1);
125
126     error.setColumn(16);
127
128     QCOMPARE(error.column(), 16);
129
130     QDeclarativeError error2 = error;
131
132     QCOMPARE(error2.column(), 16);
133
134     error.setColumn(3);
135
136     QCOMPARE(error.column(), 3);
137     QCOMPARE(error2.column(), 16);
138 }
139
140 void tst_qdeclarativeerror::toString()
141 {
142     {
143         QDeclarativeError error;
144         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
145         error.setDescription("An Error");
146         error.setLine(92);
147         error.setColumn(13);
148
149         QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error"));
150     }
151
152     {
153         QDeclarativeError error;
154         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
155         error.setDescription("An Error");
156         error.setLine(92);
157
158         QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error"));
159     }
160 }
161
162 void tst_qdeclarativeerror::copy()
163 {
164     QDeclarativeError error;
165     error.setUrl(QUrl("http://www.nokia.com/main.qml"));
166     error.setDescription("An Error");
167     error.setLine(92);
168     error.setColumn(13);
169
170     QDeclarativeError error2(error);
171     QDeclarativeError error3;
172     error3 = error;
173
174     error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
175     error.setDescription("Another Error");
176     error.setLine(2);
177     error.setColumn(33);
178
179     QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
180     QCOMPARE(error.description(), QString("Another Error"));
181     QCOMPARE(error.line(), 2);
182     QCOMPARE(error.column(), 33);
183
184     QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
185     QCOMPARE(error2.description(), QString("An Error"));
186     QCOMPARE(error2.line(), 92);
187     QCOMPARE(error2.column(), 13);
188
189     QCOMPARE(error3.url(), QUrl("http://www.nokia.com/main.qml"));
190     QCOMPARE(error3.description(), QString("An Error"));
191     QCOMPARE(error3.line(), 92);
192     QCOMPARE(error3.column(), 13);
193
194 }
195
196 void tst_qdeclarativeerror::debug()
197 {
198     {
199         QDeclarativeError error;
200         error.setUrl(QUrl("http://www.nokia.com/main.qml"));
201         error.setDescription("An Error");
202         error.setLine(92);
203         error.setColumn(13);
204
205         QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error ");
206         qWarning() << error;
207     }
208
209     {
210         QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt")));
211         QDeclarativeError error;
212         error.setUrl(url);
213         error.setDescription("An Error");
214         error.setLine(2);
215         error.setColumn(5);
216
217         QString out = url.toString() + ":2:5: An Error \n     Line2 Content \n         ^ ";
218         QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
219
220         qWarning() << error;
221     }
222
223     {
224         QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt")));
225         QDeclarativeError error;
226         error.setUrl(url);
227         error.setDescription("An Error");
228         error.setLine(2);
229         error.setColumn(5);
230
231         QString out = url.toString() + ":2:5: An Error ";
232         QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
233
234         qWarning() << error;
235     }
236 }
237
238
239
240 QTEST_MAIN(tst_qdeclarativeerror)
241
242 #include "tst_qdeclarativeerror.moc"