From 39b3fcba96d6f9d7d7b96d3c875ef569a3083898 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 5 Nov 2009 20:16:25 +1000 Subject: QmlError test --- tests/auto/declarative/declarative.pro | 1 + tests/auto/declarative/qmlerror/qmlerror.pro | 6 + tests/auto/declarative/qmlerror/test.txt | 3 + tests/auto/declarative/qmlerror/tst_qmlerror.cpp | 242 +++++++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 tests/auto/declarative/qmlerror/qmlerror.pro create mode 100644 tests/auto/declarative/qmlerror/test.txt create mode 100644 tests/auto/declarative/qmlerror/tst_qmlerror.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 02d5a55..716d278 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += \ qmlcontext \ # Cover qmldom \ # Cover qmlecmascript \ # Cover + qmlerror \ # Cover qmlfontloader \ # Cover qmlgraphicsborderimage \ # Cover qmlgraphicsparticles \ # Cover diff --git a/tests/auto/declarative/qmlerror/qmlerror.pro b/tests/auto/declarative/qmlerror/qmlerror.pro new file mode 100644 index 0000000..fa9b79e --- /dev/null +++ b/tests/auto/declarative/qmlerror/qmlerror.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlerror.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlerror/test.txt b/tests/auto/declarative/qmlerror/test.txt new file mode 100644 index 0000000..cdafd9e --- /dev/null +++ b/tests/auto/declarative/qmlerror/test.txt @@ -0,0 +1,3 @@ +Line Content +Line2 Content +Line3 Content diff --git a/tests/auto/declarative/qmlerror/tst_qmlerror.cpp b/tests/auto/declarative/qmlerror/tst_qmlerror.cpp new file mode 100644 index 0000000..70fef1d --- /dev/null +++ b/tests/auto/declarative/qmlerror/tst_qmlerror.cpp @@ -0,0 +1,242 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_qmlerror : public QObject +{ + Q_OBJECT +private slots: + void url(); + void description(); + void line(); + void column(); + void toString(); + + void copy(); + void debug(); +}; + +void tst_qmlerror::url() +{ + QmlError error; + + QCOMPARE(error.url(), QUrl()); + + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + + QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml")); + + QmlError error2 = error; + + QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml")); + + error.setUrl(QUrl("http://qt.nokia.com/main.qml")); + + QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml")); + QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml")); +} + +void tst_qmlerror::description() +{ + QmlError error; + + QCOMPARE(error.description(), QString()); + + error.setDescription("An Error"); + + QCOMPARE(error.description(), QString("An Error")); + + QmlError error2 = error; + + QCOMPARE(error2.description(), QString("An Error")); + + error.setDescription("Another Error"); + + QCOMPARE(error.description(), QString("Another Error")); + QCOMPARE(error2.description(), QString("An Error")); +} + +void tst_qmlerror::line() +{ + QmlError error; + + QCOMPARE(error.line(), -1); + + error.setLine(102); + + QCOMPARE(error.line(), 102); + + QmlError error2 = error; + + QCOMPARE(error2.line(), 102); + + error.setLine(4); + + QCOMPARE(error.line(), 4); + QCOMPARE(error2.line(), 102); +} + +void tst_qmlerror::column() +{ + QmlError error; + + QCOMPARE(error.column(), -1); + + error.setColumn(16); + + QCOMPARE(error.column(), 16); + + QmlError error2 = error; + + QCOMPARE(error2.column(), 16); + + error.setColumn(3); + + QCOMPARE(error.column(), 3); + QCOMPARE(error2.column(), 16); +} + +void tst_qmlerror::toString() +{ + { + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + error.setColumn(13); + + QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error")); + } + + { + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + + QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error")); + } +} + +void tst_qmlerror::copy() +{ + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + error.setColumn(13); + + QmlError error2(error); + QmlError error3; + error3 = error; + + error.setUrl(QUrl("http://qt.nokia.com/main.qml")); + error.setDescription("Another Error"); + error.setLine(2); + error.setColumn(33); + + QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml")); + QCOMPARE(error.description(), QString("Another Error")); + QCOMPARE(error.line(), 2); + QCOMPARE(error.column(), 33); + + QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml")); + QCOMPARE(error2.description(), QString("An Error")); + QCOMPARE(error2.line(), 92); + QCOMPARE(error2.column(), 13); + + QCOMPARE(error3.url(), QUrl("http://www.nokia.com/main.qml")); + QCOMPARE(error3.description(), QString("An Error")); + QCOMPARE(error3.line(), 92); + QCOMPARE(error3.column(), 13); + +} + +void tst_qmlerror::debug() +{ + { + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + error.setColumn(13); + + QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error "); + qWarning() << error; + } + + { + QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt"))); + QmlError error; + error.setUrl(url); + error.setDescription("An Error"); + error.setLine(2); + error.setColumn(5); + + QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ "; + QTest::ignoreMessage(QtWarningMsg, qPrintable(out)); + + qWarning() << error; + } + + { + QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt"))); + QmlError error; + error.setUrl(url); + error.setDescription("An Error"); + error.setLine(2); + error.setColumn(5); + + QString out = url.toString() + ":2:5: An Error "; + QTest::ignoreMessage(QtWarningMsg, qPrintable(out)); + + qWarning() << error; + } +} + + + +QTEST_MAIN(tst_qmlerror) + +#include "tst_qmlerror.moc" -- cgit v0.12