Import qtxmlpatterns 5.0.0-beta1
[profile/ivi/qtxmlpatterns.git] / tests / auto / qxmlnodemodelindex / tst_qxmlnodemodelindex.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #include <QtTest/QtTest>
44
45 #include <QXmlNodeModelIndex>
46
47 /*!
48  \class tst_QXmlNodeModelIndex
49  \internal
50  \since 4.4
51  \brief Tests class QXmlNodeModelIndex.
52
53  */
54 class tst_QXmlNodeModelIndex : public QObject
55 {
56     Q_OBJECT
57
58 private Q_SLOTS:
59     void copyConstructor() const;
60     void constCorrectness() const;
61     void assignmentOperator() const;
62     void equalnessOperator() const;
63     void inequalnessOperator() const;
64     void objectSize() const;
65     void internalPointer() const;
66     void data() const;
67     void additionalData() const;
68     void isNull() const;
69     void model() const;
70     void withqHash() const;
71 };
72
73 void tst_QXmlNodeModelIndex::objectSize() const
74 {
75     /* We can't do an exact comparison, because some platforms do padding. */
76     QVERIFY(sizeof(QXmlNodeModelIndex) >= sizeof(QAbstractXmlNodeModel *) + sizeof(qint64) * 2);
77 }
78
79 void tst_QXmlNodeModelIndex::constCorrectness() const
80 {
81     const QXmlNodeModelIndex index;
82     /* All these functions should be const. */
83     index.internalPointer();
84     index.data();
85     index.additionalData();
86     index.isNull();
87     index.model();
88 }
89
90 void tst_QXmlNodeModelIndex::assignmentOperator() const
91 {
92     QXmlNodeModelIndex o1;
93     const QXmlNodeModelIndex o2;
94     o1 = o2;
95     // TODO
96 }
97
98 void tst_QXmlNodeModelIndex::equalnessOperator() const
99 {
100     QXmlNodeModelIndex o1;
101     const QXmlNodeModelIndex o2;
102     // TODO check const correctness
103     o1 == o2;
104 }
105
106 void tst_QXmlNodeModelIndex::inequalnessOperator() const
107 {
108     QXmlNodeModelIndex o1;
109     const QXmlNodeModelIndex o2;
110     // TODO check const correctness
111     o1 != o2;
112 }
113
114 void tst_QXmlNodeModelIndex::copyConstructor() const
115 {
116     /* Check that we can take a const reference. */
117     {
118         const QXmlNodeModelIndex index;
119         const QXmlNodeModelIndex copy(index);
120     }
121
122     /* Take a copy of a temporary. */
123     {
124         /* The extra paranthesis silences a warning on win32-msvc. */
125         const QXmlNodeModelIndex copy((QXmlNodeModelIndex()));
126     }
127 }
128
129 void tst_QXmlNodeModelIndex::internalPointer() const
130 {
131     /* Check default value. */
132     {
133         const QXmlNodeModelIndex index;
134         QCOMPARE(index.internalPointer(), static_cast<void *>(0));
135     }
136 }
137
138 void tst_QXmlNodeModelIndex::data() const
139 {
140     /* Check default value. */
141     {
142         const QXmlNodeModelIndex index;
143         QCOMPARE(index.data(), qint64(0));
144     }
145
146     // TODO check that the return value for data() is qint64.
147 }
148
149 void tst_QXmlNodeModelIndex::additionalData() const
150 {
151     /* Check default value. */
152     {
153         const QXmlNodeModelIndex index;
154         QCOMPARE(index.additionalData(), qint64(0));
155     }
156
157     // TODO check that the return value for data() is qint64.
158 }
159
160 void tst_QXmlNodeModelIndex::isNull() const
161 {
162     /* Check default value. */
163     {
164         const QXmlNodeModelIndex index;
165         QVERIFY(index.isNull());
166     }
167
168     /* Test default value on a temporary object. */
169     {
170         QVERIFY(QXmlNodeModelIndex().isNull());
171     }
172 }
173
174 void tst_QXmlNodeModelIndex::model() const
175 {
176     /* Check default value. */
177     {
178         const QXmlNodeModelIndex index;
179         QCOMPARE(index.model(), static_cast<const QAbstractXmlNodeModel *>(0));
180     }
181 }
182
183 void tst_QXmlNodeModelIndex::withqHash() const
184 {
185     QXmlNodeModelIndex null;
186     qHash(null);
187     //Do something which means operator== must be available.
188 }
189
190 QTEST_MAIN(tst_QXmlNodeModelIndex)
191
192 #include "tst_qxmlnodemodelindex.moc"