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 ** 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.
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.
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.
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.
40 ****************************************************************************/
43 #include <QDeclarativeError>
46 class tst_qdeclarativeerror : public QObject
60 void tst_qdeclarativeerror::url()
62 QDeclarativeError error;
64 QCOMPARE(error.url(), QUrl());
66 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
68 QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml"));
70 QDeclarativeError error2 = error;
72 QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
74 error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
76 QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
77 QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
80 void tst_qdeclarativeerror::description()
82 QDeclarativeError error;
84 QCOMPARE(error.description(), QString());
86 error.setDescription("An Error");
88 QCOMPARE(error.description(), QString("An Error"));
90 QDeclarativeError error2 = error;
92 QCOMPARE(error2.description(), QString("An Error"));
94 error.setDescription("Another Error");
96 QCOMPARE(error.description(), QString("Another Error"));
97 QCOMPARE(error2.description(), QString("An Error"));
100 void tst_qdeclarativeerror::line()
102 QDeclarativeError error;
104 QCOMPARE(error.line(), -1);
108 QCOMPARE(error.line(), 102);
110 QDeclarativeError error2 = error;
112 QCOMPARE(error2.line(), 102);
116 QCOMPARE(error.line(), 4);
117 QCOMPARE(error2.line(), 102);
120 void tst_qdeclarativeerror::column()
122 QDeclarativeError error;
124 QCOMPARE(error.column(), -1);
128 QCOMPARE(error.column(), 16);
130 QDeclarativeError error2 = error;
132 QCOMPARE(error2.column(), 16);
136 QCOMPARE(error.column(), 3);
137 QCOMPARE(error2.column(), 16);
140 void tst_qdeclarativeerror::toString()
143 QDeclarativeError error;
144 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
145 error.setDescription("An Error");
149 QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error"));
153 QDeclarativeError error;
154 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
155 error.setDescription("An Error");
158 QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error"));
162 void tst_qdeclarativeerror::copy()
164 QDeclarativeError error;
165 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
166 error.setDescription("An Error");
170 QDeclarativeError error2(error);
171 QDeclarativeError error3;
174 error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
175 error.setDescription("Another Error");
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);
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);
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);
196 void tst_qdeclarativeerror::debug()
199 QDeclarativeError error;
200 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
201 error.setDescription("An Error");
205 QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error ");
210 QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt")));
211 QDeclarativeError error;
213 error.setDescription("An Error");
217 QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ ";
218 QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
224 QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt")));
225 QDeclarativeError error;
227 error.setDescription("An Error");
231 QString out = url.toString() + ":2:5: An Error ";
232 QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
240 QTEST_MAIN(tst_qdeclarativeerror)
242 #include "tst_qdeclarativeerror.moc"