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 ** 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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <QDeclarativeError>
47 // In Symbian OS test data is located in applications private dir
51 class tst_qdeclarativeerror : public QObject
65 void tst_qdeclarativeerror::url()
67 QDeclarativeError error;
69 QCOMPARE(error.url(), QUrl());
71 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
73 QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml"));
75 QDeclarativeError error2 = error;
77 QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
79 error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
81 QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml"));
82 QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml"));
85 void tst_qdeclarativeerror::description()
87 QDeclarativeError error;
89 QCOMPARE(error.description(), QString());
91 error.setDescription("An Error");
93 QCOMPARE(error.description(), QString("An Error"));
95 QDeclarativeError error2 = error;
97 QCOMPARE(error2.description(), QString("An Error"));
99 error.setDescription("Another Error");
101 QCOMPARE(error.description(), QString("Another Error"));
102 QCOMPARE(error2.description(), QString("An Error"));
105 void tst_qdeclarativeerror::line()
107 QDeclarativeError error;
109 QCOMPARE(error.line(), -1);
113 QCOMPARE(error.line(), 102);
115 QDeclarativeError error2 = error;
117 QCOMPARE(error2.line(), 102);
121 QCOMPARE(error.line(), 4);
122 QCOMPARE(error2.line(), 102);
125 void tst_qdeclarativeerror::column()
127 QDeclarativeError error;
129 QCOMPARE(error.column(), -1);
133 QCOMPARE(error.column(), 16);
135 QDeclarativeError error2 = error;
137 QCOMPARE(error2.column(), 16);
141 QCOMPARE(error.column(), 3);
142 QCOMPARE(error2.column(), 16);
145 void tst_qdeclarativeerror::toString()
148 QDeclarativeError error;
149 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
150 error.setDescription("An Error");
154 QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error"));
158 QDeclarativeError error;
159 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
160 error.setDescription("An Error");
163 QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error"));
167 void tst_qdeclarativeerror::copy()
169 QDeclarativeError error;
170 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
171 error.setDescription("An Error");
175 QDeclarativeError error2(error);
176 QDeclarativeError error3;
179 error.setUrl(QUrl("http://qt.nokia.com/main.qml"));
180 error.setDescription("Another Error");
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);
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);
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);
201 void tst_qdeclarativeerror::debug()
204 QDeclarativeError error;
205 error.setUrl(QUrl("http://www.nokia.com/main.qml"));
206 error.setDescription("An Error");
210 QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error ");
215 QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt")));
216 QDeclarativeError error;
218 error.setDescription("An Error");
222 QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ ";
223 QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
229 QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt")));
230 QDeclarativeError error;
232 error.setDescription("An Error");
236 QString out = url.toString() + ":2:5: An Error ";
237 QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
245 QTEST_MAIN(tst_qdeclarativeerror)
247 #include "tst_qdeclarativeerror.moc"