1 /****************************************************************************
3 ** Copyright (C) 2012 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>
45 #include "../../shared/util.h"
47 class tst_qdeclarativeerror : public QDeclarativeDataTest
61 void tst_qdeclarativeerror::url()
63 QDeclarativeError error;
65 QCOMPARE(error.url(), QUrl());
67 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
69 QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml"));
71 QDeclarativeError error2 = error;
73 QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
75 error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
77 QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
78 QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
81 void tst_qdeclarativeerror::description()
83 QDeclarativeError error;
85 QCOMPARE(error.description(), QString());
87 error.setDescription("An Error");
89 QCOMPARE(error.description(), QString("An Error"));
91 QDeclarativeError error2 = error;
93 QCOMPARE(error2.description(), QString("An Error"));
95 error.setDescription("Another Error");
97 QCOMPARE(error.description(), QString("Another Error"));
98 QCOMPARE(error2.description(), QString("An Error"));
101 void tst_qdeclarativeerror::line()
103 QDeclarativeError error;
105 QCOMPARE(error.line(), -1);
109 QCOMPARE(error.line(), 102);
111 QDeclarativeError error2 = error;
113 QCOMPARE(error2.line(), 102);
117 QCOMPARE(error.line(), 4);
118 QCOMPARE(error2.line(), 102);
121 void tst_qdeclarativeerror::column()
123 QDeclarativeError error;
125 QCOMPARE(error.column(), -1);
129 QCOMPARE(error.column(), 16);
131 QDeclarativeError error2 = error;
133 QCOMPARE(error2.column(), 16);
137 QCOMPARE(error.column(), 3);
138 QCOMPARE(error2.column(), 16);
141 void tst_qdeclarativeerror::toString()
144 QDeclarativeError error;
145 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
146 error.setDescription("An Error");
150 QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error"));
154 QDeclarativeError error;
155 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
156 error.setDescription("An Error");
159 QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error"));
163 void tst_qdeclarativeerror::copy()
165 QDeclarativeError error;
166 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
167 error.setDescription("An Error");
171 QDeclarativeError error2(error);
172 QDeclarativeError error3;
175 error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
176 error.setDescription("Another Error");
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);
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);
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);
197 void tst_qdeclarativeerror::debug()
200 QDeclarativeError error;
201 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
202 error.setDescription("An Error");
206 QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error ");
211 QUrl url(dataDirectoryUrl().resolved(QUrl("test.txt")));
212 QDeclarativeError error;
214 error.setDescription("An Error");
218 QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ ";
219 QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
225 QUrl url(dataDirectoryUrl().resolved(QUrl("foo.txt")));
226 QDeclarativeError error;
228 error.setDescription("An Error");
232 QString out = url.toString() + ":2:5: An Error ";
233 QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
241 QTEST_MAIN(tst_qdeclarativeerror)
243 #include "tst_qdeclarativeerror.moc"