Fix macplist autotest
[qt-netbsd.git] / tests / auto / qxmlitem / tst_qxmlitem.cpp
blob8bb0c15ee9c8b8b2a0e06cd48253ef9a3d6c00f2
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
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
14 ** this package.
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.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
43 #include <QtTest/QtTest>
45 #ifdef QTEST_XMLPATTERNS
47 #include <QXmlItem>
49 /*!
50 \class tst_QXmlItem
51 \internal
52 \since 4.4
53 \brief Tests class QXmlItem.
55 class tst_QXmlItem : public QObject
57 Q_OBJECT
59 private Q_SLOTS:
60 void defaultConstructor() const;
61 void copyConstructor() const;
62 void copyConstructorFromQVariant() const;
63 void copyConstructorFromQXmlNodeModelIndex() const;
64 void assignmentOperator() const;
65 void isNull() const;
66 void isNode() 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
79 QXmlItem();
83 QXmlItem();
84 QXmlItem();
88 QXmlItem();
89 QXmlItem();
90 QXmlItem();
94 void tst_QXmlItem::copyConstructor() const
96 /* Check that we can copy from a const reference. */
98 const QXmlItem item;
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. */
147 QXmlItem item;
148 item = item;
149 item = item;
150 item = item;
151 item = item;
152 item = item;
155 /* With the same atomic value. */
157 QXmlItem item(QVariant(QString::fromLatin1("dummy")));
158 item = item;
159 item = item;
160 item = item;
161 item = item;
162 item = item;
165 /* With the same node. */
167 // TODO
170 /* With a QXmlItem constructed from a null QVariant. */
172 QXmlItem item((QVariant()));
173 item = item;
174 item = item;
175 item = item;
176 item = item;
177 item = item;
180 /* With a QXmlItem constructed from a null QXmlNodeModelIndex. */
182 QXmlItem item((QXmlNodeModelIndex()));
183 item = item;
184 item = item;
185 item = item;
186 item = item;
187 item = item;
192 void tst_QXmlItem::isNull() const
194 /* Check default value. */
196 const QXmlItem item;
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. */
223 const QXmlItem item;
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. */
251 const QXmlItem item;
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. */
280 const QXmlItem item;
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. */
307 const QXmlItem item;
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,
333 * so disable it. */
334 return;
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
349 const QXmlItem item;
350 item.isNull();
351 item.isNode();
352 item.isAtomicValue();
354 item.toAtomicValue();
355 item.toNodeModelIndex();
359 Check that QXmlItem can be used inside QVariant.
361 void tst_QXmlItem::withinQVariant() const
363 QXmlItem val;
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
372 QTEST_NOOP_MAIN
373 #endif