summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-05-07 15:20:55 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2020-05-13 13:54:44 +0200
commit80e0d0e08eaccf032c4a42ce7c5d3ffb91837141 (patch)
tree8b9acabac005e0abeab1f519cb94c477ccc74e24 /tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
parentb35551a75e37d4ae1ddb024a82c67cdba714879a (diff)
QNetworkReply/http2: Add a contentEncoding test
Will be useful when DecompressHelper gets taken into use for both. Task-number: QTBUG-83269 Change-Id: Iaf253219bed193025c2b82d6609f4dcc4de33df8 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp')
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 915926e488..2f1e97f853 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -503,6 +503,10 @@ private Q_SLOTS:
void getWithTimeout();
void postWithTimeout();
+
+ void contentEncoding_data();
+ void contentEncoding();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
private:
@@ -9175,6 +9179,57 @@ void tst_QNetworkReply::postWithTimeout()
manager.setTransferTimeout(0);
}
+void tst_QNetworkReply::contentEncoding_data()
+{
+ QTest::addColumn<QByteArray>("encoding");
+ QTest::addColumn<QByteArray>("body");
+ QTest::addColumn<QByteArray>("expected");
+
+ QTest::newRow("gzip-hello-world")
+ << QByteArray("gzip")
+ << QByteArray::fromBase64("H4sIAAAAAAAAA8tIzcnJVyjPL8pJAQCFEUoNCwAAAA==")
+ << QByteArray("hello world");
+ QTest::newRow("deflate-hello-world")
+ << QByteArray("deflate") << QByteArray::fromBase64("eJzLSM3JyVcozy/KSQEAGgsEXQ==")
+ << QByteArray("hello world");
+}
+
+void tst_QNetworkReply::contentEncoding()
+{
+ QFETCH(QByteArray, encoding);
+ QFETCH(QByteArray, body);
+ QString header("HTTP/1.0 200 OK\r\nContent-Encoding: %1\r\nContent-Length: %2\r\n\r\n");
+ header = header.arg(encoding, QString::number(body.size()));
+
+ MiniHttpServer server(header.toLatin1() + body);
+
+ QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
+ QNetworkReplyPtr reply(manager.get(request));
+
+ QVERIFY2(waitForFinish(reply) == Success, msgWaitForFinished(reply));
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+
+ {
+ // Check that we included the content encoding method in our Accept-Encoding header
+ const QByteArray &receivedData = server.receivedData;
+ int start = receivedData.indexOf("Accept-Encoding");
+ QVERIFY(start != -1);
+ int end = receivedData.indexOf("\r\n", start);
+ QVERIFY(end != -1);
+ QByteArray acceptedEncoding = receivedData.mid(start, end - start);
+ acceptedEncoding = acceptedEncoding.mid(acceptedEncoding.indexOf(':') + 1).trimmed();
+ QByteArrayList list = acceptedEncoding.split(',');
+ for (QByteArray &encoding : list)
+ encoding = encoding.trimmed();
+ QVERIFY2(list.contains(encoding), acceptedEncoding.data());
+ }
+
+ QFETCH(QByteArray, expected);
+
+ QCOMPARE(reply->bytesAvailable(), expected.size());
+ QCOMPARE(reply->readAll(), expected);
+}
+
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()
{