summaryrefslogtreecommitdiffstats
path: root/tests/auto/qabstractnetworkcache
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-12-06 15:43:57 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-12-06 15:43:57 (GMT)
commit9888fa259875d82bf08a28cac134fe6f71f371f0 (patch)
treea58a6ab673888d5c352d2cfe98b22fb1c11c40e9 /tests/auto/qabstractnetworkcache
parenta70ccc4aaad74dbf28569c78479d4668781bb0fe (diff)
parent9327490ad51b737211c26cae53a095a8485e2dad (diff)
downloadQt-9888fa259875d82bf08a28cac134fe6f71f371f0.zip
Qt-9888fa259875d82bf08a28cac134fe6f71f371f0.tar.gz
Qt-9888fa259875d82bf08a28cac134fe6f71f371f0.tar.bz2
Merge remote branch 'origin/4.7' into qt-master-from-4.7
Conflicts: configure qmake/generators/win32/msbuild_objectmodel.cpp src/gui/image/qpnghandler.cpp src/network/access/qnetworkaccessdatabackend.cpp src/opengl/qgl_x11egl.cpp tests/auto/qnetworkreply/tst_qnetworkreply.cpp
Diffstat (limited to 'tests/auto/qabstractnetworkcache')
-rw-r--r--tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp111
1 files changed, 101 insertions, 10 deletions
diff --git a/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp b/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp
index 04bd432..fc8a126 100644
--- a/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp
+++ b/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp
@@ -58,20 +58,29 @@ public:
private slots:
void expires_data();
void expires();
+ void expiresSynchronous_data();
+ void expiresSynchronous();
void lastModified_data();
void lastModified();
+ void lastModifiedSynchronous_data();
+ void lastModifiedSynchronous();
void etag_data();
void etag();
+ void etagSynchronous_data();
+ void etagSynchronous();
void cacheControl_data();
void cacheControl();
+ void cacheControlSynchronous_data();
+ void cacheControlSynchronous();
void deleteCache();
private:
void check();
+ void checkSynchronous();
};
class NetworkDiskCache : public QNetworkDiskCache
@@ -142,6 +151,16 @@ void tst_QAbstractNetworkCache::expires()
check();
}
+void tst_QAbstractNetworkCache::expiresSynchronous_data()
+{
+ expires_data();
+}
+
+void tst_QAbstractNetworkCache::expiresSynchronous()
+{
+ checkSynchronous();
+}
+
void tst_QAbstractNetworkCache::lastModified_data()
{
QTest::addColumn<QNetworkRequest::CacheLoadControl>("cacheLoadControl");
@@ -164,6 +183,16 @@ void tst_QAbstractNetworkCache::lastModified()
check();
}
+void tst_QAbstractNetworkCache::lastModifiedSynchronous_data()
+{
+ tst_QAbstractNetworkCache::lastModified_data();
+}
+
+void tst_QAbstractNetworkCache::lastModifiedSynchronous()
+{
+ checkSynchronous();
+}
+
void tst_QAbstractNetworkCache::etag_data()
{
QTest::addColumn<QNetworkRequest::CacheLoadControl>("cacheLoadControl");
@@ -186,6 +215,16 @@ void tst_QAbstractNetworkCache::etag()
check();
}
+void tst_QAbstractNetworkCache::etagSynchronous_data()
+{
+ tst_QAbstractNetworkCache::etag_data();
+}
+
+void tst_QAbstractNetworkCache::etagSynchronous()
+{
+ checkSynchronous();
+}
+
void tst_QAbstractNetworkCache::cacheControl_data()
{
QTest::addColumn<QNetworkRequest::CacheLoadControl>("cacheLoadControl");
@@ -217,6 +256,16 @@ void tst_QAbstractNetworkCache::cacheControl()
check();
}
+void tst_QAbstractNetworkCache::cacheControlSynchronous_data()
+{
+ tst_QAbstractNetworkCache::cacheControl_data();
+}
+
+void tst_QAbstractNetworkCache::cacheControlSynchronous()
+{
+ checkSynchronous();
+}
+
void tst_QAbstractNetworkCache::check()
{
QFETCH(QNetworkRequest::CacheLoadControl, cacheLoadControl);
@@ -250,8 +299,6 @@ void tst_QAbstractNetworkCache::check()
QCOMPARE(reply2->error(), QNetworkReply::ContentNotFoundError);
QCOMPARE(secondData, QByteArray());
} else {
- if (reply2->error() != QNetworkReply::NoError)
- qDebug() << reply2->errorString();
QCOMPARE(reply2->error(), QNetworkReply::NoError);
QCOMPARE(QString(secondData), QString(goodData));
QCOMPARE(secondData, goodData);
@@ -263,16 +310,60 @@ void tst_QAbstractNetworkCache::check()
QList<QByteArray> rawHeaderList2 = reply2->rawHeaderList();
qSort(rawHeaderList);
qSort(rawHeaderList2);
+ }
+ QCOMPARE(diskCache->gotData, fetchFromCache);
+}
- // headers can change
- for (int i = 0; i < rawHeaderList.count(); ++i) {
- //qDebug() << i << rawHeaderList.value(i) << reply->rawHeader(rawHeaderList.value(i));
- //qDebug() << i << rawHeaderList2.value(i) << reply2->rawHeader(rawHeaderList2.value(i));
- //QCOMPARE(QString(rawHeaderList.value(i)), QString(rawHeaderList2.value(i)));
- //QCOMPARE(QString(reply->rawHeader(rawHeaderList.value(i))), QString(reply2->rawHeader(rawHeaderList2.value(i))));
- }
- //QCOMPARE(rawHeaderList.count(), rawHeaderList2.count());
+void tst_QAbstractNetworkCache::checkSynchronous()
+{
+ QSKIP("not working yet, see QTBUG-15221", SkipAll);
+ QFETCH(QNetworkRequest::CacheLoadControl, cacheLoadControl);
+ QFETCH(QString, url);
+ QFETCH(bool, fetchFromCache);
+
+ QNetworkAccessManager manager;
+ NetworkDiskCache *diskCache = new NetworkDiskCache(&manager);
+ manager.setCache(diskCache);
+ QCOMPARE(diskCache->gotData, false);
+
+ QUrl realUrl = url.contains("://") ? url : TESTFILE + url;
+ QNetworkRequest request(realUrl);
+
+ request.setAttribute(
+ static_cast<QNetworkRequest::Attribute>(QNetworkRequest::DownloadBufferAttribute + 1),
+ true);
+
+ // prime the cache
+ QNetworkReply *reply = manager.get(request);
+ QVERIFY(reply->isFinished()); // synchronous
+ QCOMPARE(diskCache->gotData, false);
+ QByteArray goodData = reply->readAll();
+
+ request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, cacheLoadControl);
+
+ // should be in the cache now
+ QNetworkReply *reply2 = manager.get(request);
+ QVERIFY(reply2->isFinished()); // synchronous
+
+ QByteArray secondData = reply2->readAll();
+ if (!fetchFromCache && cacheLoadControl == QNetworkRequest::AlwaysCache) {
+ QCOMPARE(reply2->error(), QNetworkReply::ContentNotFoundError);
+ QCOMPARE(secondData, QByteArray());
+ } else {
+ if (reply2->error() != QNetworkReply::NoError)
+ qDebug() << reply2->errorString();
+ QCOMPARE(reply2->error(), QNetworkReply::NoError);
+ QCOMPARE(QString(secondData), QString(goodData));
+ QCOMPARE(secondData, goodData);
+ QCOMPARE(reply2->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
+ }
+
+ if (fetchFromCache) {
+ QList<QByteArray> rawHeaderList = reply->rawHeaderList();
+ QList<QByteArray> rawHeaderList2 = reply2->rawHeaderList();
+ qSort(rawHeaderList);
+ qSort(rawHeaderList2);
}
QCOMPARE(diskCache->gotData, fetchFromCache);
}