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 <QXmlNodeModelIndex>
33
34/*!
35 \class tst_QXmlNodeModelIndex
36 \internal
37 \since 4.4
38 \brief Tests class QXmlNodeModelIndex.
39
40 */
41class tst_QXmlNodeModelIndex : public QObject
42{
43 Q_OBJECT
44
45private Q_SLOTS:
46 void copyConstructor() const;
47 void constCorrectness() const;
48 void assignmentOperator() const;
49 void equalnessOperator() const;
50 void inequalnessOperator() const;
51 void objectSize() const;
52 void internalPointer() const;
53 void data() const;
54 void additionalData() const;
55 void isNull() const;
56 void model() const;
57 void withqHash() const;
58};
59
60void tst_QXmlNodeModelIndex::objectSize() const
61{
62 /* We can't do an exact comparison, because some platforms do padding. */
63 QVERIFY(sizeof(QXmlNodeModelIndex) >= sizeof(QAbstractXmlNodeModel *) + sizeof(qint64) * 2);
64}
65
66void tst_QXmlNodeModelIndex::constCorrectness() const
67{
68 const QXmlNodeModelIndex index;
69 /* All these functions should be const. */
70 index.internalPointer();
71 index.data();
72 index.additionalData();
73 index.isNull();
74 index.model();
75}
76
77void tst_QXmlNodeModelIndex::assignmentOperator() const
78{
79 QXmlNodeModelIndex o1;
80 const QXmlNodeModelIndex o2;
81 o1 = o2;
82 // TODO
83}
84
85void tst_QXmlNodeModelIndex::equalnessOperator() const
86{
87 QXmlNodeModelIndex o1;
88 const QXmlNodeModelIndex o2;
89 // TODO check const correctness
90 o1 == o2;
91}
92
93void tst_QXmlNodeModelIndex::inequalnessOperator() const
94{
95 QXmlNodeModelIndex o1;
96 const QXmlNodeModelIndex o2;
97 // TODO check const correctness
98 o1 != o2;
99}
100
101void tst_QXmlNodeModelIndex::copyConstructor() const
102{
103 /* Check that we can take a const reference. */
104 {
105 const QXmlNodeModelIndex index;
106 const QXmlNodeModelIndex copy(index);
107 }
108
109 /* Take a copy of a temporary. */
110 {
111 /* The extra paranthesis silences a warning on win32-msvc. */
112 const QXmlNodeModelIndex copy((QXmlNodeModelIndex()));
113 Q_UNUSED(copy)
114 }
115}
116
117void tst_QXmlNodeModelIndex::internalPointer() const
118{
119 /* Check default value. */
120 {
121 const QXmlNodeModelIndex index;
122 QCOMPARE(index.internalPointer(), static_cast<void *>(0));
123 }
124}
125
126void tst_QXmlNodeModelIndex::data() const
127{
128 /* Check default value. */
129 {
130 const QXmlNodeModelIndex index;
131 QCOMPARE(index.data(), qint64(0));
132 }
133
134 // TODO check that the return value for data() is qint64.
135}
136
137void tst_QXmlNodeModelIndex::additionalData() const
138{
139 /* Check default value. */
140 {
141 const QXmlNodeModelIndex index;
142 QCOMPARE(index.additionalData(), qint64(0));
143 }
144
145 // TODO check that the return value for data() is qint64.
146}
147
148void tst_QXmlNodeModelIndex::isNull() const
149{
150 /* Check default value. */
151 {
152 const QXmlNodeModelIndex index;
153 QVERIFY(index.isNull());
154 }
155
156 /* Test default value on a temporary object. */
157 {
158 QVERIFY(QXmlNodeModelIndex().isNull());
159 }
160}
161
162void tst_QXmlNodeModelIndex::model() const
163{
164 /* Check default value. */
165 {
166 const QXmlNodeModelIndex index;
167 QCOMPARE(index.model(), static_cast<const QAbstractXmlNodeModel *>(0));
168 }
169}
170
171void tst_QXmlNodeModelIndex::withqHash() const
172{
173 QXmlNodeModelIndex null;
174 qHash(index: null);
175 //Do something which means operator== must be available.
176}
177
178QTEST_MAIN(tst_QXmlNodeModelIndex)
179
180#include "tst_qxmlnodemodelindex.moc"
181

source code of qtxmlpatterns/tests/auto/qxmlnodemodelindex/tst_qxmlnodemodelindex.cpp