1 /****************************************************************************
3 ** Copyright (C) 2009 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 <QtTest/QtTest>
45 #ifdef QTEST_XMLPATTERNS
53 \brief Tests class QXmlItem.
55 class tst_QXmlItem
: public QObject
60 void defaultConstructor() const;
61 void copyConstructor() const;
62 void copyConstructorFromQVariant() const;
63 void copyConstructorFromQXmlNodeModelIndex() const;
64 void assignmentOperator() const;
67 void isAtomicValue() const;
68 void toAtomicValue() const;
69 void toNodeModelIndex() const;
71 void objectSize() const;
72 void constCorrectness() const;
73 void withinQVariant() const;
76 void tst_QXmlItem::defaultConstructor() const
94 void tst_QXmlItem::copyConstructor() const
96 /* Check that we can copy from a const reference. */
99 const QXmlItem
copy(item
);
102 /* On a QXmlItem constructed from a null QVariant. */
104 const QXmlItem
item((QVariant()));
105 const QXmlItem
copy(item
);
108 /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
110 const QXmlItem
item((QXmlNodeModelIndex()));
111 const QXmlItem
copy(item
);
115 void tst_QXmlItem::copyConstructorFromQVariant() const
117 /* Construct & destruct a single value. */
119 const QXmlItem
item(QVariant(QString::fromLatin1("dummy")));
122 /* Copy a null QVariant. */
124 const QXmlItem
item((QVariant()));
125 QVERIFY(item
.isNull());
130 void tst_QXmlItem::copyConstructorFromQXmlNodeModelIndex() const
132 // TODO copy a valid model index.
134 /* Construct from a null QXmlNodeModelIndex. */
136 const QXmlItem
item((QXmlNodeModelIndex()));
137 QVERIFY(item
.isNull());
141 void tst_QXmlItem::assignmentOperator() const
143 /* Assign to self. */
145 /* With null value. */
155 /* With the same atomic value. */
157 QXmlItem
item(QVariant(QString::fromLatin1("dummy")));
165 /* With the same node. */
170 /* With a QXmlItem constructed from a null QVariant. */
172 QXmlItem
item((QVariant()));
180 /* With a QXmlItem constructed from a null QXmlNodeModelIndex. */
182 QXmlItem
item((QXmlNodeModelIndex()));
192 void tst_QXmlItem::isNull() const
194 /* Check default value. */
197 QVERIFY(item
.isNull());
200 /* On atomic value. */
202 const QXmlItem
item(QVariant(3));
203 QVERIFY(!item
.isNull());
206 /* On a QXmlItem constructed from a null QVariant. */
208 const QXmlItem
item((QVariant()));
209 QVERIFY(item
.isNull());
212 /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
214 const QXmlItem
item((QXmlNodeModelIndex()));
215 QVERIFY(item
.isNull());
219 void tst_QXmlItem::isNode() const
221 /* Check default value. */
224 QVERIFY(!item
.isNode());
227 /* On atomic value. */
229 const QXmlItem
item(QVariant(3));
230 QVERIFY(!item
.isNode());
232 // TODO on valid node index
234 /* On a QXmlItem constructed from a null QVariant. */
236 const QXmlItem
item((QVariant()));
237 QVERIFY(!item
.isNode());
240 /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
242 const QXmlItem
item((QXmlNodeModelIndex()));
243 QVERIFY(!item
.isNode());
247 void tst_QXmlItem::isAtomicValue() const
249 /* Check default value. */
252 QVERIFY(!item
.isAtomicValue());
255 /* On valid atomic value. */
257 const QXmlItem
item(QVariant(3));
258 QVERIFY(item
.isAtomicValue());
261 // TODO on valid node index
263 /* On a QXmlItem constructed from a null QVariant. */
265 const QXmlItem
item((QVariant()));
266 QVERIFY(!item
.isAtomicValue());
269 /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
271 const QXmlItem
item((QXmlNodeModelIndex()));
272 QVERIFY(!item
.isAtomicValue());
276 void tst_QXmlItem::toAtomicValue() const
278 /* Check default value. */
281 QVERIFY(item
.toAtomicValue().isNull());
284 /* On atomic value. */
286 const QXmlItem
item(QVariant(3));
287 QCOMPARE(item
.toAtomicValue(), QVariant(3));
290 /* On a QXmlItem constructed from a null QVariant. */
292 const QXmlItem
item((QVariant()));
293 QVERIFY(item
.toAtomicValue().isNull());
296 /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
298 const QXmlItem
item((QXmlNodeModelIndex()));
299 QVERIFY(item
.toAtomicValue().isNull());
303 void tst_QXmlItem::toNodeModelIndex() const
305 /* Check default value. */
308 QVERIFY(item
.toNodeModelIndex().isNull());
311 /* On valid atomic value. */
313 const QXmlItem
item(QVariant(3));
314 QVERIFY(item
.toNodeModelIndex().isNull());
317 /* On a QXmlItem constructed from a null QVariant. */
319 const QXmlItem
item((QVariant()));
320 QVERIFY(item
.isNull());
323 /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
325 const QXmlItem
item((QXmlNodeModelIndex()));
326 QVERIFY(item
.isNull());
330 void tst_QXmlItem::objectSize() const
332 /* We can't currently test this in portable way,
336 QCOMPARE(sizeof(QPatternist::NodeIndexStorage
), sizeof(QXmlItem
));
338 /* Data, additional data, and pointer to model. We test for two, such that we
339 * account for the padding that MSVC do. */
340 QVERIFY(sizeof(QXmlItem
) == sizeof(qint64
) * 2 + sizeof(QAbstractXmlNodeModel
*) * 2
341 || sizeof(QXmlItem
) == sizeof(qint64
) * 2 + sizeof(QAbstractXmlNodeModel
*) * 2);
345 Check that the functions that should be const, are.
347 void tst_QXmlItem::constCorrectness() const
352 item
.isAtomicValue();
354 item
.toAtomicValue();
355 item
.toNodeModelIndex();
359 Check that QXmlItem can be used inside QVariant.
361 void tst_QXmlItem::withinQVariant() const
364 const QVariant
variant(qVariantFromValue(val
));
365 QXmlItem
val2(qVariantValue
<QXmlItem
>(variant
));
368 QTEST_MAIN(tst_QXmlItem
)
370 #include "tst_qxmlitem.moc"
371 #else //QTEST_XMLPATTERNS