1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
45 #include <QSimpleXmlNodeModel>
46 #include <QXmlNamePool>
48 #include <QXmlSerializer>
49 #include <QXmlStreamReader>
51 #include "TestSimpleNodeModel.h"
54 \class tst_QSimpleXmlNodeModel
57 \brief Tests class QSimpleXmlNodeModel.
59 class tst_QSimpleXmlNodeModel : public QObject
64 void namePool() const;
65 void namePoolIsReference() const;
66 void defaultConstructor() const;
67 void objectSize() const;
68 void constCorrectness() const;
69 void stringValue() const;
72 void tst_QSimpleXmlNodeModel::namePool() const
74 /* Check that the name pool we pass in, is what actually is returned. */
76 const QXmlName name(np, QLatin1String("localName"),
77 QLatin1String("http://example.com/XYZ"),
78 QLatin1String("prefix432"));
79 TestSimpleNodeModel model(np);
80 const QXmlNamePool np2(model.namePool());
82 /* If it's a bug, this will more or less crash. */
83 QCOMPARE(name.namespaceUri(np2), QString::fromLatin1("http://example.com/XYZ"));
84 QCOMPARE(name.localName(np2), QString::fromLatin1("localName"));
85 QCOMPARE(name.prefix(np2), QString::fromLatin1("prefix432"));
88 void tst_QSimpleXmlNodeModel::namePoolIsReference() const
90 /* Test is placed in TestSimpleNodeModel.h:~50. */
93 void tst_QSimpleXmlNodeModel::defaultConstructor() const
98 void tst_QSimpleXmlNodeModel::objectSize() const
100 /* We shouldn't have added any members. */
101 QCOMPARE(sizeof(QSimpleXmlNodeModel), sizeof(QAbstractXmlNodeModel));
104 void tst_QSimpleXmlNodeModel::constCorrectness() const
107 const TestSimpleNodeModel instance(np);
109 instance.nextFromSimpleAxis(QSimpleXmlNodeModel::Parent, QXmlNodeModelIndex());
110 instance.attributes(QXmlNodeModelIndex());
116 Verify that if QAbstractXmlNodeModel::typedValue() return a null
117 QVariant, it is treated as that the node has no typed value.
119 This verifies the default implementation of QSimpleXmlNodeModel::stringValue().
121 void tst_QSimpleXmlNodeModel::stringValue() const
123 class TypedModel : public TestSimpleNodeModel
126 TypedModel(const QXmlNamePool &np) : TestSimpleNodeModel(np)
130 virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &) const
132 return QXmlNodeModelIndex::Element;
135 virtual QVariant typedValue(const QXmlNodeModelIndex &) const
140 QXmlNodeModelIndex root() const
142 return createIndex(qint64(1));
147 TypedModel model(np);
150 query.bindVariable(QLatin1String("node"), model.root());
151 query.setQuery(QLatin1String("declare variable $node external;"
152 "string($node), data($node)"));
155 QBuffer buffer(&output);
156 QVERIFY(buffer.open(QIODevice::WriteOnly));
157 QVERIFY(query.isValid());
159 QXmlSerializer serializer(query, &buffer);
160 QVERIFY(query.evaluateTo(&serializer));
162 QVERIFY(output.isEmpty());
165 QTEST_MAIN(tst_QSimpleXmlNodeModel)
167 #include "tst_qsimplexmlnodemodel.moc"