1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
****************************************************************************/
#include <QtTest/QtTest>
#ifdef QTEST_XMLPATTERNS
#include <QAbstractMessageHandler>
#include <QAbstractUriResolver>
#include <QtNetwork/QNetworkAccessManager>
#include <QXmlName>
#include <QXmlSchema>
class DummyMessageHandler : public QAbstractMessageHandler
{
public:
DummyMessageHandler(QObject *parent = 0)
: QAbstractMessageHandler(parent)
{
}
protected:
virtual void handleMessage(QtMsgType, const QString&, const QUrl&, const QSourceLocation&)
{
}
};
class DummyUriResolver : public QAbstractUriResolver
{
public:
DummyUriResolver(QObject *parent = 0)
: QAbstractUriResolver(parent)
{
}
virtual QUrl resolve(const QUrl&, const QUrl&) const
{
return QUrl();
}
};
/*!
\class tst_QXmlSchema
\internal
\brief Tests class QXmlSchema.
This test is not intended for testing the engine, but the functionality specific
to the QXmlSchema class.
*/
class tst_QXmlSchema : public QObject
{
Q_OBJECT
private Q_SLOTS:
void defaultConstructor() const;
void copyConstructor() const;
void constructorQXmlNamePool() const;
void networkAccessManagerSignature() const;
void networkAccessManagerDefaultValue() const;
void networkAccessManager() const;
void messageHandlerSignature() const;
void messageHandlerDefaultValue() const;
void messageHandler() const;
void uriResolverSignature() const;
void uriResolverDefaultValue() const;
void uriResolver() const;
};
void tst_QXmlSchema::defaultConstructor() const
{
/* Allocate instance in different orders. */
{
QXmlSchema schema;
}
{
QXmlSchema schema1;
QXmlSchema schema2;
}
{
QXmlSchema schema1;
QXmlSchema schema2;
QXmlSchema schema3;
}
}
void tst_QXmlSchema::copyConstructor() const
{
/* Verify that we can take a const reference, and simply do a copy of a default constructed object. */
{
const QXmlSchema schema1;
QXmlSchema schema2(schema1);
}
/* Copy twice. */
{
const QXmlSchema schema1;
QXmlSchema schema2(schema1);
QXmlSchema schema3(schema2);
}
/* Verify that copying default values works. */
{
const QXmlSchema schema1;
const QXmlSchema schema2(schema1);
QCOMPARE(schema2.messageHandler(), schema1.messageHandler());
QCOMPARE(schema2.uriResolver(), schema1.uriResolver());
QCOMPARE(schema2.networkAccessManager(), schema1.networkAccessManager());
QCOMPARE(schema2.isValid(), schema1.isValid());
}
}
void tst_QXmlSchema::constructorQXmlNamePool() const
{
QXmlSchema schema;
QXmlNamePool np = schema.namePool();
const QXmlName name(np, QLatin1String("localName"),
QLatin1String("http://example.com/"),
QLatin1String("prefix"));
QXmlNamePool np2(schema.namePool());
QCOMPARE(name.namespaceUri(np2), QString::fromLatin1("http://example.com/"));
QCOMPARE(name.localName(np2), QString::fromLatin1("localName"));
QCOMPARE(name.prefix(np2), QString::fromLatin1("prefix"));
}
void tst_QXmlSchema::networkAccessManagerSignature() const
{
/* Const object. */
const QXmlSchema schema;
/* The function should be const. */
schema.networkAccessManager();
}
void tst_QXmlSchema::networkAccessManagerDefaultValue() const
{
/* Test that the default value of network access manager is not empty. */
{
QXmlSchema schema;
QVERIFY(schema.networkAccessManager() != static_cast<QNetworkAccessManager*>(0));
}
}
void tst_QXmlSchema::networkAccessManager() const
{
/* Test that we return the network manager that was set. */
{
QNetworkAccessManager manager;
QXmlSchema schema;
schema.setNetworkAccessManager(&manager);
QCOMPARE(schema.networkAccessManager(), &manager);
}
}
void tst_QXmlSchema::messageHandlerSignature() const
{
/* Const object. */
const QXmlSchema schema;
/* The function should be const. */
schema.messageHandler();
}
void tst_QXmlSchema::messageHandlerDefaultValue() const
{
/* Test that the default value of message handler is not empty. */
{
QXmlSchema schema;
QVERIFY(schema.messageHandler() != static_cast<QAbstractMessageHandler*>(0));
}
}
void tst_QXmlSchema::messageHandler() const
{
/* Test that we return the message handler that was set. */
{
DummyMessageHandler handler;
QXmlSchema schema;
schema.setMessageHandler(&handler);
QCOMPARE(schema.messageHandler(), &handler);
}
}
void tst_QXmlSchema::uriResolverSignature() const
{
/* Const object. */
const QXmlSchema schema;
/* The function should be const. */
schema.uriResolver();
}
void tst_QXmlSchema::uriResolverDefaultValue() const
{
/* Test that the default value of uri resolver is empty. */
{
QXmlSchema schema;
QVERIFY(schema.uriResolver() == static_cast<QAbstractUriResolver*>(0));
}
}
void tst_QXmlSchema::uriResolver() const
{
/* Test that we return the uri resolver that was set. */
{
DummyUriResolver resolver;
QXmlSchema schema;
schema.setUriResolver(&resolver);
QCOMPARE(schema.uriResolver(), &resolver);
}
}
QTEST_MAIN(tst_QXmlSchema)
#include "tst_qxmlschema.moc"
#else //QTEST_PATTERNIST
QTEST_NOOP_MAIN
#endif
|