summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-04-17 12:33:11 +0200
committerMarc Mutz <marc.mutz@qt.io>2024-04-24 21:36:49 +0200
commit2822b226109bc2e537e810b7c885baa2cb369588 (patch)
tree404c5c3ee7f63d5d10c842f5c63e04a627440b08 /tests/auto
parent2b694aae4796d05dca6e12392c920f9f2ba86e4f (diff)
QRestReply: add a few more content-type parsing tests
... incl. some that fail. This is in preparation of a patch that makes the parser more compliant. Pick-to: 6.7 Task-number: QTBUG-120307 Change-Id: Ic47b23132f2a7ea81b6c480bfb036bc2daff05da Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp b/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp
index 602bffd9c1..d1b8e3bdd7 100644
--- a/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp
+++ b/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp
@@ -13,6 +13,7 @@
#include <QTest>
#include <QtTest/qsignalspy.h>
+#include <QtCore/private/qglobal_p.h> // for access to Qt's feature system
#include <QtCore/qbuffer.h>
#include <QtCore/qjsonobject.h>
#include <QtCore/qjsondocument.h>
@@ -667,7 +668,7 @@ void tst_QRestAccessManager::json()
}
}
-#define VERIFY_TEXT_REPLY_OK \
+#define VERIFY_TEXT_REPLY_OK_IMPL(...) \
{ \
manager.get(request, this, [&](QRestReply &reply) { networkReply = reply.networkReply(); }); \
QTRY_VERIFY(networkReply); \
@@ -675,8 +676,11 @@ void tst_QRestAccessManager::json()
responseString = restReply.readText(); \
networkReply->deleteLater(); \
networkReply = nullptr; \
+ __VA_ARGS__ ; \
QCOMPARE(responseString, sourceString); \
}
+#define VERIFY_TEXT_REPLY_OK VERIFY_TEXT_REPLY_OK_IMPL(do {} while (false))
+#define VERIFY_TEXT_REPLY_XFAIL(JIRA) VERIFY_TEXT_REPLY_OK_IMPL(QEXPECT_FAIL("", #JIRA, Continue))
#define VERIFY_TEXT_REPLY_ERROR(WARNING_MESSAGE) \
{ \
@@ -723,11 +727,33 @@ void tst_QRestAccessManager::text()
// should consider the indicated charset and convert it to an UTF-16 QString => the returned
// QString from text() should match with the original (UTF-16) QString.
- // Successful UTF-8
+ // Successful UTF-8 (explicit)
serverSideResponse.headers.append(Header::ContentType, "text/plain; charset=UTF-8"_ba);
serverSideResponse.body = encUTF8(sourceString);
VERIFY_TEXT_REPLY_OK;
+ // Successful UTF-8 (obfuscated)
+ serverSideResponse.headers.removeAll(Header::ContentType);
+ serverSideResponse.headers.append(Header::ContentType, "text/plain; charset=\"UT\\F-8\""_ba);
+ serverSideResponse.body = encUTF8(sourceString);
+#if QT_CONFIG(icu) // ICU ignores `\` during name lookup, making this test succeed when it shouldn't
+ VERIFY_TEXT_REPLY_OK;
+#else
+ VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307);
+#endif
+
+ // Successful UTF-8 (empty charset)
+ serverSideResponse.headers.removeAll(Header::ContentType);
+ serverSideResponse.headers.append(Header::ContentType, "text/plain; charset=\"\""_ba);
+ serverSideResponse.body = encUTF8(sourceString);
+ VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307);
+
+ // Successful UTF-8 (implicit)
+ serverSideResponse.headers.removeAll(Header::ContentType);
+ serverSideResponse.headers.append(Header::ContentType, "text/plain"_ba);
+ serverSideResponse.body = encUTF8(sourceString);
+ VERIFY_TEXT_REPLY_OK;
+
// Successful UTF-16
serverSideResponse.headers.removeAll(Header::ContentType);
serverSideResponse.headers.append(Header::ContentType, "text/plain; charset=UTF-16"_ba);
@@ -746,13 +772,20 @@ void tst_QRestAccessManager::text()
serverSideResponse.body = encUTF32(sourceString);
VERIFY_TEXT_REPLY_OK;
- // Successful UTF-32 with spec-wise allowed extra content in the Content-Type header value
+ // Successful UTF-32 with spec-wise allowed extra trailing content in the Content-Type header value
serverSideResponse.headers.removeAll(Header::ContentType);
serverSideResponse.headers.append(Header::ContentType,
"text/plain; charset = \"UTF-32\";extraparameter=bar"_ba);
serverSideResponse.body = encUTF32(sourceString);
VERIFY_TEXT_REPLY_OK;
+ // Successful UTF-32 with spec-wise allowed extra leading content in the Content-Type header value
+ serverSideResponse.headers.removeAll(Header::ContentType);
+ serverSideResponse.headers.append(Header::ContentType,
+ "text/plain; extraparameter=bar;charset = \"UT\\F-32\""_ba);
+ serverSideResponse.body = encUTF32(sourceString);
+ VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307);
+
{
// Unsuccessful UTF-32, wrong encoding indicated (indicated UTF-32 but data is UTF-8)
serverSideResponse.headers.removeAll(Header::ContentType);