| 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 | |
| 30 | #include <QtTest/QtTest> |
| 31 | |
| 32 | #include <QXmlItem> |
| 33 | |
| 34 | /*! |
| 35 | \class tst_QXmlItem |
| 36 | \internal |
| 37 | \since 4.4 |
| 38 | \brief Tests class QXmlItem. |
| 39 | */ |
| 40 | class tst_QXmlItem : public QObject |
| 41 | { |
| 42 | Q_OBJECT |
| 43 | |
| 44 | private Q_SLOTS: |
| 45 | void defaultConstructor() const; |
| 46 | void copyConstructor() const; |
| 47 | void copyConstructorFromQVariant() const; |
| 48 | void copyConstructorFromQXmlNodeModelIndex() const; |
| 49 | void assignmentOperator() const; |
| 50 | void isNull() const; |
| 51 | void isNode() const; |
| 52 | void isAtomicValue() const; |
| 53 | void toAtomicValue() const; |
| 54 | void toNodeModelIndex() const; |
| 55 | |
| 56 | void objectSize() const; |
| 57 | void constCorrectness() const; |
| 58 | void withinQVariant() const; |
| 59 | }; |
| 60 | |
| 61 | void tst_QXmlItem::defaultConstructor() const |
| 62 | { |
| 63 | { |
| 64 | QXmlItem(); |
| 65 | } |
| 66 | |
| 67 | { |
| 68 | QXmlItem(); |
| 69 | QXmlItem(); |
| 70 | } |
| 71 | |
| 72 | { |
| 73 | QXmlItem(); |
| 74 | QXmlItem(); |
| 75 | QXmlItem(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void tst_QXmlItem::copyConstructor() const |
| 80 | { |
| 81 | /* Check that we can copy from a const reference. */ |
| 82 | { |
| 83 | const QXmlItem item; |
| 84 | const QXmlItem copy(item); |
| 85 | } |
| 86 | |
| 87 | /* On a QXmlItem constructed from a null QVariant. */ |
| 88 | { |
| 89 | const QXmlItem item((QVariant())); |
| 90 | const QXmlItem copy(item); |
| 91 | } |
| 92 | |
| 93 | /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 94 | { |
| 95 | const QXmlItem item((QXmlNodeModelIndex())); |
| 96 | const QXmlItem copy(item); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void tst_QXmlItem::copyConstructorFromQVariant() const |
| 101 | { |
| 102 | /* Construct & destruct a single value. */ |
| 103 | { |
| 104 | const QXmlItem item(QVariant(QString::fromLatin1(str: "dummy" ))); |
| 105 | } |
| 106 | |
| 107 | /* Copy a null QVariant. */ |
| 108 | { |
| 109 | const QXmlItem item((QVariant())); |
| 110 | QVERIFY(item.isNull()); |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | void tst_QXmlItem::copyConstructorFromQXmlNodeModelIndex() const |
| 116 | { |
| 117 | // TODO copy a valid model index. |
| 118 | |
| 119 | /* Construct from a null QXmlNodeModelIndex. */ |
| 120 | { |
| 121 | const QXmlItem item((QXmlNodeModelIndex())); |
| 122 | QVERIFY(item.isNull()); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void tst_QXmlItem::assignmentOperator() const |
| 127 | { |
| 128 | /* Assign to self. */ |
| 129 | { |
| 130 | /* With null value. */ |
| 131 | { |
| 132 | QXmlItem item; |
| 133 | item = item; |
| 134 | item = item; |
| 135 | item = item; |
| 136 | item = item; |
| 137 | item = item; |
| 138 | } |
| 139 | |
| 140 | /* With the same atomic value. */ |
| 141 | { |
| 142 | QXmlItem item(QVariant(QString::fromLatin1(str: "dummy" ))); |
| 143 | item = item; |
| 144 | item = item; |
| 145 | item = item; |
| 146 | item = item; |
| 147 | item = item; |
| 148 | } |
| 149 | |
| 150 | /* With the same node. */ |
| 151 | { |
| 152 | // TODO |
| 153 | } |
| 154 | |
| 155 | /* With a QXmlItem constructed from a null QVariant. */ |
| 156 | { |
| 157 | QXmlItem item((QVariant())); |
| 158 | item = item; |
| 159 | item = item; |
| 160 | item = item; |
| 161 | item = item; |
| 162 | item = item; |
| 163 | } |
| 164 | |
| 165 | /* With a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 166 | { |
| 167 | QXmlItem item((QXmlNodeModelIndex())); |
| 168 | item = item; |
| 169 | item = item; |
| 170 | item = item; |
| 171 | item = item; |
| 172 | item = item; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void tst_QXmlItem::isNull() const |
| 178 | { |
| 179 | /* Check default value. */ |
| 180 | { |
| 181 | const QXmlItem item; |
| 182 | QVERIFY(item.isNull()); |
| 183 | } |
| 184 | |
| 185 | /* On atomic value. */ |
| 186 | { |
| 187 | const QXmlItem item(QVariant(3)); |
| 188 | QVERIFY(!item.isNull()); |
| 189 | } |
| 190 | |
| 191 | /* On a QXmlItem constructed from a null QVariant. */ |
| 192 | { |
| 193 | const QXmlItem item((QVariant())); |
| 194 | QVERIFY(item.isNull()); |
| 195 | } |
| 196 | |
| 197 | /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 198 | { |
| 199 | const QXmlItem item((QXmlNodeModelIndex())); |
| 200 | QVERIFY(item.isNull()); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void tst_QXmlItem::isNode() const |
| 205 | { |
| 206 | /* Check default value. */ |
| 207 | { |
| 208 | const QXmlItem item; |
| 209 | QVERIFY(!item.isNode()); |
| 210 | } |
| 211 | |
| 212 | /* On atomic value. */ |
| 213 | { |
| 214 | const QXmlItem item(QVariant(3)); |
| 215 | QVERIFY(!item.isNode()); |
| 216 | } |
| 217 | // TODO on valid node index |
| 218 | |
| 219 | /* On a QXmlItem constructed from a null QVariant. */ |
| 220 | { |
| 221 | const QXmlItem item((QVariant())); |
| 222 | QVERIFY(!item.isNode()); |
| 223 | } |
| 224 | |
| 225 | /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 226 | { |
| 227 | const QXmlItem item((QXmlNodeModelIndex())); |
| 228 | QVERIFY(!item.isNode()); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void tst_QXmlItem::isAtomicValue() const |
| 233 | { |
| 234 | /* Check default value. */ |
| 235 | { |
| 236 | const QXmlItem item; |
| 237 | QVERIFY(!item.isAtomicValue()); |
| 238 | } |
| 239 | |
| 240 | /* On valid atomic value. */ |
| 241 | { |
| 242 | const QXmlItem item(QVariant(3)); |
| 243 | QVERIFY(item.isAtomicValue()); |
| 244 | } |
| 245 | |
| 246 | // TODO on valid node index |
| 247 | |
| 248 | /* On a QXmlItem constructed from a null QVariant. */ |
| 249 | { |
| 250 | const QXmlItem item((QVariant())); |
| 251 | QVERIFY(!item.isAtomicValue()); |
| 252 | } |
| 253 | |
| 254 | /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 255 | { |
| 256 | const QXmlItem item((QXmlNodeModelIndex())); |
| 257 | QVERIFY(!item.isAtomicValue()); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void tst_QXmlItem::toAtomicValue() const |
| 262 | { |
| 263 | /* Check default value. */ |
| 264 | { |
| 265 | const QXmlItem item; |
| 266 | QVERIFY(item.toAtomicValue().isNull()); |
| 267 | } |
| 268 | |
| 269 | /* On atomic value. */ |
| 270 | { |
| 271 | const QXmlItem item(QVariant(3)); |
| 272 | QCOMPARE(item.toAtomicValue(), QVariant(3)); |
| 273 | } |
| 274 | |
| 275 | /* On a QXmlItem constructed from a null QVariant. */ |
| 276 | { |
| 277 | const QXmlItem item((QVariant())); |
| 278 | QVERIFY(item.toAtomicValue().isNull()); |
| 279 | } |
| 280 | |
| 281 | /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 282 | { |
| 283 | const QXmlItem item((QXmlNodeModelIndex())); |
| 284 | QVERIFY(item.toAtomicValue().isNull()); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void tst_QXmlItem::toNodeModelIndex() const |
| 289 | { |
| 290 | /* Check default value. */ |
| 291 | { |
| 292 | const QXmlItem item; |
| 293 | QVERIFY(item.toNodeModelIndex().isNull()); |
| 294 | } |
| 295 | |
| 296 | /* On valid atomic value. */ |
| 297 | { |
| 298 | const QXmlItem item(QVariant(3)); |
| 299 | QVERIFY(item.toNodeModelIndex().isNull()); |
| 300 | } |
| 301 | |
| 302 | /* On a QXmlItem constructed from a null QVariant. */ |
| 303 | { |
| 304 | const QXmlItem item((QVariant())); |
| 305 | QVERIFY(item.isNull()); |
| 306 | } |
| 307 | |
| 308 | /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */ |
| 309 | { |
| 310 | const QXmlItem item((QXmlNodeModelIndex())); |
| 311 | QVERIFY(item.isNull()); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | void tst_QXmlItem::objectSize() const |
| 316 | { |
| 317 | /* We can't currently test this in portable way, |
| 318 | * so disable it. */ |
| 319 | return; |
| 320 | |
| 321 | QCOMPARE(sizeof(QPatternist::NodeIndexStorage), sizeof(QXmlItem)); |
| 322 | |
| 323 | /* Data, additional data, and pointer to model. We test for two, such that we |
| 324 | * account for the padding that MSVC do. */ |
| 325 | QVERIFY(sizeof(QXmlItem) == sizeof(qint64) * 2 + sizeof(QAbstractXmlNodeModel *) * 2 |
| 326 | || sizeof(QXmlItem) == sizeof(qint64) * 2 + sizeof(QAbstractXmlNodeModel *) * 2); |
| 327 | } |
| 328 | |
| 329 | /*! |
| 330 | Check that the functions that should be const, are. |
| 331 | */ |
| 332 | void tst_QXmlItem::constCorrectness() const |
| 333 | { |
| 334 | const QXmlItem item; |
| 335 | item.isNull(); |
| 336 | item.isNode(); |
| 337 | item.isAtomicValue(); |
| 338 | |
| 339 | item.toAtomicValue(); |
| 340 | item.toNodeModelIndex(); |
| 341 | } |
| 342 | |
| 343 | /*! |
| 344 | Check that QXmlItem can be used inside QVariant. |
| 345 | */ |
| 346 | void tst_QXmlItem::withinQVariant() const |
| 347 | { |
| 348 | QXmlItem val; |
| 349 | const auto variant = QVariant::fromValue(value: val); |
| 350 | QXmlItem val2(qvariant_cast<QXmlItem>(v: variant)); |
| 351 | } |
| 352 | |
| 353 | QTEST_MAIN(tst_QXmlItem) |
| 354 | |
| 355 | #include "tst_qxmlitem.moc" |
| 356 | |