| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <qtest.h> |
| 30 | #include <QQmlError> |
| 31 | #include <QDebug> |
| 32 | #include "../../shared/util.h" |
| 33 | |
| 34 | class tst_qqmlerror : public QQmlDataTest |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | private slots: |
| 38 | void url(); |
| 39 | void description(); |
| 40 | void line(); |
| 41 | void column(); |
| 42 | void toString(); |
| 43 | |
| 44 | void copy(); |
| 45 | void debug(); |
| 46 | }; |
| 47 | |
| 48 | void tst_qqmlerror::url() |
| 49 | { |
| 50 | QQmlError error; |
| 51 | |
| 52 | QCOMPARE(error.url(), QUrl()); |
| 53 | |
| 54 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 55 | |
| 56 | QCOMPARE(error.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 57 | |
| 58 | QQmlError error2 = error; |
| 59 | |
| 60 | QCOMPARE(error2.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 61 | |
| 62 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 63 | |
| 64 | QCOMPARE(error.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 65 | QCOMPARE(error2.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 66 | } |
| 67 | |
| 68 | void tst_qqmlerror::description() |
| 69 | { |
| 70 | QQmlError error; |
| 71 | |
| 72 | QCOMPARE(error.description(), QString()); |
| 73 | |
| 74 | error.setDescription("An Error" ); |
| 75 | |
| 76 | QCOMPARE(error.description(), QString("An Error" )); |
| 77 | |
| 78 | QQmlError error2 = error; |
| 79 | |
| 80 | QCOMPARE(error2.description(), QString("An Error" )); |
| 81 | |
| 82 | error.setDescription("Another Error" ); |
| 83 | |
| 84 | QCOMPARE(error.description(), QString("Another Error" )); |
| 85 | QCOMPARE(error2.description(), QString("An Error" )); |
| 86 | } |
| 87 | |
| 88 | void tst_qqmlerror::line() |
| 89 | { |
| 90 | QQmlError error; |
| 91 | |
| 92 | QCOMPARE(error.line(), -1); |
| 93 | |
| 94 | error.setLine(102); |
| 95 | |
| 96 | QCOMPARE(error.line(), 102); |
| 97 | |
| 98 | QQmlError error2 = error; |
| 99 | |
| 100 | QCOMPARE(error2.line(), 102); |
| 101 | |
| 102 | error.setLine(4); |
| 103 | |
| 104 | QCOMPARE(error.line(), 4); |
| 105 | QCOMPARE(error2.line(), 102); |
| 106 | } |
| 107 | |
| 108 | void tst_qqmlerror::column() |
| 109 | { |
| 110 | QQmlError error; |
| 111 | |
| 112 | QCOMPARE(error.column(), -1); |
| 113 | |
| 114 | error.setColumn(16); |
| 115 | |
| 116 | QCOMPARE(error.column(), 16); |
| 117 | |
| 118 | QQmlError error2 = error; |
| 119 | |
| 120 | QCOMPARE(error2.column(), 16); |
| 121 | |
| 122 | error.setColumn(3); |
| 123 | |
| 124 | QCOMPARE(error.column(), 3); |
| 125 | QCOMPARE(error2.column(), 16); |
| 126 | } |
| 127 | |
| 128 | void tst_qqmlerror::toString() |
| 129 | { |
| 130 | { |
| 131 | QQmlError error; |
| 132 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 133 | error.setDescription("An Error" ); |
| 134 | error.setLine(92); |
| 135 | error.setColumn(13); |
| 136 | |
| 137 | QCOMPARE(error.toString(), QString("http://www.qt-project.org/main.qml:92:13: An Error" )); |
| 138 | } |
| 139 | |
| 140 | { |
| 141 | QQmlError error; |
| 142 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 143 | error.setDescription("An Error" ); |
| 144 | error.setLine(92); |
| 145 | |
| 146 | QCOMPARE(error.toString(), QString("http://www.qt-project.org/main.qml:92: An Error" )); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void tst_qqmlerror::copy() |
| 151 | { |
| 152 | QQmlError error; |
| 153 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 154 | error.setDescription("An Error" ); |
| 155 | error.setLine(92); |
| 156 | error.setColumn(13); |
| 157 | |
| 158 | QQmlError error2(error); |
| 159 | QQmlError error3; |
| 160 | error3 = error; |
| 161 | |
| 162 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 163 | error.setDescription("Another Error" ); |
| 164 | error.setLine(2); |
| 165 | error.setColumn(33); |
| 166 | |
| 167 | QCOMPARE(error.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 168 | QCOMPARE(error.description(), QString("Another Error" )); |
| 169 | QCOMPARE(error.line(), 2); |
| 170 | QCOMPARE(error.column(), 33); |
| 171 | |
| 172 | QCOMPARE(error2.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 173 | QCOMPARE(error2.description(), QString("An Error" )); |
| 174 | QCOMPARE(error2.line(), 92); |
| 175 | QCOMPARE(error2.column(), 13); |
| 176 | |
| 177 | QCOMPARE(error3.url(), QUrl("http://www.qt-project.org/main.qml" )); |
| 178 | QCOMPARE(error3.description(), QString("An Error" )); |
| 179 | QCOMPARE(error3.line(), 92); |
| 180 | QCOMPARE(error3.column(), 13); |
| 181 | |
| 182 | } |
| 183 | |
| 184 | void tst_qqmlerror::debug() |
| 185 | { |
| 186 | { |
| 187 | QQmlError error; |
| 188 | error.setUrl(QUrl("http://www.qt-project.org/main.qml" )); |
| 189 | error.setDescription("An Error" ); |
| 190 | error.setLine(92); |
| 191 | error.setColumn(13); |
| 192 | |
| 193 | QTest::ignoreMessage(type: QtWarningMsg, message: "http://www.qt-project.org/main.qml:92:13: An Error" ); |
| 194 | qWarning() << error; |
| 195 | } |
| 196 | |
| 197 | { |
| 198 | QUrl url = testFileUrl(fileName: "test.txt" ); |
| 199 | QQmlError error; |
| 200 | error.setUrl(url); |
| 201 | error.setDescription("An Error" ); |
| 202 | error.setLine(2); |
| 203 | error.setColumn(5); |
| 204 | |
| 205 | QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ " ; |
| 206 | QTest::ignoreMessage(type: QtWarningMsg, qPrintable(out)); |
| 207 | |
| 208 | qWarning() << error; |
| 209 | } |
| 210 | |
| 211 | { |
| 212 | QUrl url(dataDirectoryUrl().resolved(relative: QUrl("foo.txt" ))); |
| 213 | QQmlError error; |
| 214 | error.setUrl(url); |
| 215 | error.setDescription("An Error" ); |
| 216 | error.setLine(2); |
| 217 | error.setColumn(5); |
| 218 | |
| 219 | QString out = url.toString() + ":2:5: An Error " ; |
| 220 | QTest::ignoreMessage(type: QtWarningMsg, qPrintable(out)); |
| 221 | |
| 222 | qWarning() << error; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | |
| 228 | QTEST_MAIN(tst_qqmlerror) |
| 229 | |
| 230 | #include "tst_qqmlerror.moc" |
| 231 | |