diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-01-07 00:51:34 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-01-07 00:51:34 (GMT) |
commit | 5b67b61150771cf978648a35db201345d6fb37ae (patch) | |
tree | c8927dd65b3d1edeff76fd21ac0c49b7ace72bf6 /tests/auto/declarative/qdeclarativexmllistmodel | |
parent | c527a1ee371c4758776217e7d16c75e20fe6f5aa (diff) | |
parent | 9cc21c043238dc7576a465c9d236e8968fd8c549 (diff) | |
download | Qt-5b67b61150771cf978648a35db201345d6fb37ae.zip Qt-5b67b61150771cf978648a35db201345d6fb37ae.tar.gz Qt-5b67b61150771cf978648a35db201345d6fb37ae.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into qtquick11
Conflicts:
src/declarative/graphicsitems/qdeclarativeitem.cpp
tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
Diffstat (limited to 'tests/auto/declarative/qdeclarativexmllistmodel')
-rw-r--r-- | tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp | 67 |
2 files changed, 68 insertions, 1 deletions
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro b/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro index 472cffb..efcea12 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro +++ b/tests/auto/declarative/qdeclarativexmllistmodel/qdeclarativexmllistmodel.pro @@ -1,5 +1,5 @@ load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative script gui +contains(QT_CONFIG,declarative): QT += declarative script gui network contains(QT_CONFIG,xmlpatterns) { QT += xmlpatterns DEFINES += QTEST_XMLPATTERNS diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 3e81c53..137a3a4 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -46,6 +46,9 @@ #include <qtest.h> #include <QtTest/qsignalspy.h> +#include <QtDeclarative/qdeclarativenetworkaccessmanagerfactory.h> +#include <QtNetwork/qnetworkaccessmanager.h> +#include <QtNetwork/qnetworkrequest.h> #include <QtCore/qtimer.h> #include <QtCore/qfile.h> #include <QtCore/qtemporaryfile.h> @@ -88,6 +91,7 @@ private slots: void roles(); void roleErrors(); void uniqueRoleNames(); + void headers(); void xml(); void xml_data(); void source(); @@ -146,6 +150,44 @@ private: QDeclarativeEngine engine; }; +class CustomNetworkAccessManagerFactory : public QObject, public QDeclarativeNetworkAccessManagerFactory +{ + Q_OBJECT +public: + QVariantMap lastSentHeaders; + +protected: + QNetworkAccessManager *create(QObject *parent); +}; + +class CustomNetworkAccessManager : public QNetworkAccessManager +{ + Q_OBJECT +public: + CustomNetworkAccessManager(CustomNetworkAccessManagerFactory *factory, QObject *parent) + : QNetworkAccessManager(parent), m_factory(factory) {} + +protected: + QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice * outgoingData = 0) + { + if (m_factory) { + QVariantMap map; + foreach (const QString &header, req.rawHeaderList()) + map[header] = req.rawHeader(header.toUtf8()); + m_factory->lastSentHeaders = map; + } + return QNetworkAccessManager::createRequest(op, req, outgoingData); + } + + QPointer<CustomNetworkAccessManagerFactory> m_factory; +}; + +QNetworkAccessManager *CustomNetworkAccessManagerFactory::create(QObject *parent) +{ + return new CustomNetworkAccessManager(this, parent); +} + + void tst_qdeclarativexmllistmodel::buildModel() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml")); @@ -362,6 +404,31 @@ void tst_qdeclarativexmllistmodel::xml_data() QTest::newRow("one item") << "<Pets><Pet><name>Hobbes</name><type>Tiger</type><age>7</age><size>Large</size></Pet></Pets>" << 1; } +void tst_qdeclarativexmllistmodel::headers() +{ + // ensure the QNetworkAccessManagers created for this test are immediately deleted + QDeclarativeEngine qmlEng; + + CustomNetworkAccessManagerFactory factory; + qmlEng.setNetworkAccessManagerFactory(&factory); + + QDeclarativeComponent component(&qmlEng, QUrl::fromLocalFile(SRCDIR "/data/model.qml")); + QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create()); + QVERIFY(model != 0); + QTRY_COMPARE(model->status(), QDeclarativeXmlListModel::Ready); + + QVariantMap expectedHeaders; + expectedHeaders["Accept"] = "application/xml"; + + QCOMPARE(factory.lastSentHeaders.count(), expectedHeaders.count()); + foreach (const QString &header, expectedHeaders.keys()) { + QVERIFY(factory.lastSentHeaders.contains(header)); + QCOMPARE(factory.lastSentHeaders[header].toString(), expectedHeaders[header].toString()); + } + + delete model; +} + void tst_qdeclarativexmllistmodel::source() { QFETCH(QUrl, source); |