diff options
author | Tobias Koenig <tokoe@kde.org> | 2009-05-16 10:19:10 (GMT) |
---|---|---|
committer | Tobias Koenig <tokoe@kde.org> | 2009-05-16 10:19:10 (GMT) |
commit | 135a028d9dc9a28a0a072665a7dc43b7e9e187be (patch) | |
tree | d259e1d265589d10a541899d4982ab4e656900eb /tests/auto/qxmlschemavalidator | |
parent | 210bd7b6033e41aad61fe131002dc5e496d7427a (diff) | |
download | Qt-135a028d9dc9a28a0a072665a7dc43b7e9e187be.zip Qt-135a028d9dc9a28a0a072665a7dc43b7e9e187be.tar.gz Qt-135a028d9dc9a28a0a072665a7dc43b7e9e187be.tar.bz2 |
Add W3C XML Schema validation support
This was done by Tobias Koenig, as part of an internship at Trolltech/Qt
Software, started at Wed Oct 1 18:32:43 2008 +0200, and the last commit being
part of this commit dating Tue Feb 24 11:03:36 2009 +0100. This is work
consisting of about 650 commits squashed into one, where the first commit was
61b280386c1905a15690fdd917dcbc8eb09b6283, in the repository before Qt's history
cut.
Diffstat (limited to 'tests/auto/qxmlschemavalidator')
-rw-r--r-- | tests/auto/qxmlschemavalidator/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/qxmlschemavalidator/qxmlschemavalidator.pro | 4 | ||||
-rw-r--r-- | tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp | 308 |
3 files changed, 313 insertions, 0 deletions
diff --git a/tests/auto/qxmlschemavalidator/.gitignore b/tests/auto/qxmlschemavalidator/.gitignore new file mode 100644 index 0000000..8857212 --- /dev/null +++ b/tests/auto/qxmlschemavalidator/.gitignore @@ -0,0 +1 @@ +tst_qxmlschemavalidator diff --git a/tests/auto/qxmlschemavalidator/qxmlschemavalidator.pro b/tests/auto/qxmlschemavalidator/qxmlschemavalidator.pro new file mode 100644 index 0000000..88ef317 --- /dev/null +++ b/tests/auto/qxmlschemavalidator/qxmlschemavalidator.pro @@ -0,0 +1,4 @@ +load(qttest_p4) +SOURCES += tst_qxmlschemavalidator.cpp + +include (../xmlpatterns.pri) diff --git a/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp b/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp new file mode 100644 index 0000000..b021b08 --- /dev/null +++ b/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp @@ -0,0 +1,308 @@ +/**************************************************************************** +** +** 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> +#include <QXmlSchemaValidator> + +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_QXmlSchemaValidatorValidator + \internal + \brief Tests class QXmlSchemaValidator. + + This test is not intended for testing the engine, but the functionality specific + to the QXmlSchemaValidator class. + */ +class tst_QXmlSchemaValidator : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void defaultConstructor() const; + void propertyInitialization() 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_QXmlSchemaValidator::defaultConstructor() const +{ + /* Allocate instance in different orders. */ + { + QXmlSchema schema; + QXmlSchemaValidator validator(schema); + } + + { + QXmlSchema schema1; + QXmlSchema schema2; + + QXmlSchemaValidator validator1(schema1); + QXmlSchemaValidator validator2(schema2); + } + + { + QXmlSchema schema; + + QXmlSchemaValidator validator1(schema); + QXmlSchemaValidator validator2(schema); + } +} + +void tst_QXmlSchemaValidator::propertyInitialization() const +{ + /* Verify that properties set in the schema are used as default values for the validator */ + { + DummyMessageHandler handler; + DummyUriResolver resolver; + QNetworkAccessManager manager; + + QXmlSchema schema; + schema.setMessageHandler(&handler); + schema.setUriResolver(&resolver); + schema.setNetworkAccessManager(&manager); + + QXmlSchemaValidator validator(schema); + QCOMPARE(validator.messageHandler(), &handler); + QCOMPARE(validator.uriResolver(), &resolver); + QCOMPARE(validator.networkAccessManager(), &manager); + } +} + +void tst_QXmlSchemaValidator::networkAccessManagerSignature() const +{ + const QXmlSchema schema; + + /* Const object. */ + const QXmlSchemaValidator validator(schema); + + /* The function should be const. */ + validator.networkAccessManager(); +} + +void tst_QXmlSchemaValidator::networkAccessManagerDefaultValue() const +{ + /* Test that the default value of network access manager is equal to the one from the schema. */ + { + const QXmlSchema schema; + const QXmlSchemaValidator validator(schema); + QVERIFY(validator.networkAccessManager() == schema.networkAccessManager()); + } + + /* Test that the default value of network access manager is equal to the one from the schema. */ + { + QXmlSchema schema; + + QNetworkAccessManager manager; + schema.setNetworkAccessManager(&manager); + + const QXmlSchemaValidator validator(schema); + QVERIFY(validator.networkAccessManager() == schema.networkAccessManager()); + } +} + +void tst_QXmlSchemaValidator::networkAccessManager() const +{ + /* Test that we return the network access manager that was set. */ + { + QNetworkAccessManager manager; + + const QXmlSchema schema; + QXmlSchemaValidator validator(schema); + + validator.setNetworkAccessManager(&manager); + QCOMPARE(validator.networkAccessManager(), &manager); + } + + /* Test that we return the network access manager that was set, even if the schema changed in between. */ + { + QNetworkAccessManager manager; + + const QXmlSchema schema; + QXmlSchemaValidator validator(schema); + + validator.setNetworkAccessManager(&manager); + + const QXmlSchema schema2; + validator.setSchema(schema2); + + QCOMPARE(validator.networkAccessManager(), &manager); + } +} + +void tst_QXmlSchemaValidator::messageHandlerSignature() const +{ + const QXmlSchema schema; + + /* Const object. */ + const QXmlSchemaValidator validator(schema); + + /* The function should be const. */ + validator.messageHandler(); +} + +void tst_QXmlSchemaValidator::messageHandlerDefaultValue() const +{ + /* Test that the default value of message handler is equal to the one from the schema. */ + { + const QXmlSchema schema; + const QXmlSchemaValidator validator(schema); + QVERIFY(validator.messageHandler() == schema.messageHandler()); + } + + /* Test that the default value of network access manager is equal to the one from the schema. */ + { + QXmlSchema schema; + + DummyMessageHandler handler; + schema.setMessageHandler(&handler); + + const QXmlSchemaValidator validator(schema); + QVERIFY(validator.messageHandler() == schema.messageHandler()); + } +} + +void tst_QXmlSchemaValidator::messageHandler() const +{ + /* Test that we return the message handler that was set. */ + { + DummyMessageHandler handler; + + const QXmlSchema schema; + QXmlSchemaValidator validator(schema); + + validator.setMessageHandler(&handler); + QCOMPARE(validator.messageHandler(), &handler); + } + + /* Test that we return the message handler that was set, even if the schema changed in between. */ + { + DummyMessageHandler handler; + + const QXmlSchema schema; + QXmlSchemaValidator validator(schema); + + validator.setMessageHandler(&handler); + + const QXmlSchema schema2; + validator.setSchema(schema2); + + QCOMPARE(validator.messageHandler(), &handler); + } +} + +void tst_QXmlSchemaValidator::uriResolverSignature() const +{ + const QXmlSchema schema; + + /* Const object. */ + const QXmlSchemaValidator validator(schema); + + /* The function should be const. */ + validator.uriResolver(); +} + +void tst_QXmlSchemaValidator::uriResolverDefaultValue() const +{ + /* Test that the default value of uri resolver is equal to the one from the schema. */ + { + const QXmlSchema schema; + const QXmlSchemaValidator validator(schema); + QVERIFY(validator.uriResolver() == schema.uriResolver()); + } + + /* Test that the default value of uri resolver is equal to the one from the schema. */ + { + QXmlSchema schema; + + DummyUriResolver resolver; + schema.setUriResolver(&resolver); + + const QXmlSchemaValidator validator(schema); + QVERIFY(validator.uriResolver() == schema.uriResolver()); + } +} + +void tst_QXmlSchemaValidator::uriResolver() const +{ + /* Test that we return the uri resolver that was set. */ + { + DummyUriResolver resolver; + + const QXmlSchema schema; + QXmlSchemaValidator validator(schema); + + validator.setUriResolver(&resolver); + QCOMPARE(validator.uriResolver(), &resolver); + } + + /* Test that we return the uri resolver that was set, even if the schema changed in between. */ + { + DummyUriResolver resolver; + + const QXmlSchema schema; + QXmlSchemaValidator validator(schema); + + validator.setUriResolver(&resolver); + + const QXmlSchema schema2; + validator.setSchema(schema2); + + QCOMPARE(validator.uriResolver(), &resolver); + } +} + +QTEST_MAIN(tst_QXmlSchemaValidator) + +#include "tst_qxmlschemavalidator.moc" +#else //QTEST_PATTERNIST +QTEST_NOOP_MAIN +#endif |