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. Manual conflict resolution: - Rebased to before conflicting change 15b0bd69ff2a3ac967ddb98b5fc3c3ce8c3d5b4b Task-number: QTBUG-120307 Change-Id: Ic47b23132f2a7ea81b6c480bfb036bc2daff05da Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> (cherry picked from commit 2822b226109bc2e537e810b7c885baa2cb369588)
This commit is contained in:
parent
0aa0d505b1
commit
5eecb650f6
@ -13,6 +13,7 @@
|
|||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QtTest/qsignalspy.h>
|
#include <QtTest/qsignalspy.h>
|
||||||
|
|
||||||
|
#include <QtCore/private/qglobal_p.h> // for access to Qt's feature system
|
||||||
#include <QtCore/qbuffer.h>
|
#include <QtCore/qbuffer.h>
|
||||||
#include <QtCore/qjsonobject.h>
|
#include <QtCore/qjsonobject.h>
|
||||||
#include <QtCore/qjsondocument.h>
|
#include <QtCore/qjsondocument.h>
|
||||||
@ -665,7 +666,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(); }); \
|
manager.get(request, this, [&](QRestReply &reply) { networkReply = reply.networkReply(); }); \
|
||||||
QTRY_VERIFY(networkReply); \
|
QTRY_VERIFY(networkReply); \
|
||||||
@ -673,8 +674,11 @@ void tst_QRestAccessManager::json()
|
|||||||
responseString = restReply.readText(); \
|
responseString = restReply.readText(); \
|
||||||
networkReply->deleteLater(); \
|
networkReply->deleteLater(); \
|
||||||
networkReply = nullptr; \
|
networkReply = nullptr; \
|
||||||
|
__VA_ARGS__ ; \
|
||||||
QCOMPARE(responseString, sourceString); \
|
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) \
|
#define VERIFY_TEXT_REPLY_ERROR(WARNING_MESSAGE) \
|
||||||
{ \
|
{ \
|
||||||
@ -721,11 +725,30 @@ void tst_QRestAccessManager::text()
|
|||||||
// should consider the indicated charset and convert it to an UTF-16 QString => the returned
|
// 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.
|
// QString from text() should match with the original (UTF-16) QString.
|
||||||
|
|
||||||
// Successful UTF-8
|
// Successful UTF-8 (explicit)
|
||||||
serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-8"_ba);
|
serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-8"_ba);
|
||||||
serverSideResponse.body = encUTF8(sourceString);
|
serverSideResponse.body = encUTF8(sourceString);
|
||||||
VERIFY_TEXT_REPLY_OK;
|
VERIFY_TEXT_REPLY_OK;
|
||||||
|
|
||||||
|
// Successful UTF-8 (obfuscated)
|
||||||
|
serverSideResponse.headers["Content-Type:"_ba] = "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["Content-Type:"_ba] = "text/plain; charset=\"\""_ba;
|
||||||
|
serverSideResponse.body = encUTF8(sourceString);
|
||||||
|
VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307);
|
||||||
|
|
||||||
|
// Successful UTF-8 (implicit)
|
||||||
|
serverSideResponse.headers["Content-Type:"_ba] = "text/plain"_ba;
|
||||||
|
serverSideResponse.body = encUTF8(sourceString);
|
||||||
|
VERIFY_TEXT_REPLY_OK;
|
||||||
|
|
||||||
// Successful UTF-16
|
// Successful UTF-16
|
||||||
serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-16"_ba);
|
serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-16"_ba);
|
||||||
serverSideResponse.body = encUTF16(sourceString);
|
serverSideResponse.body = encUTF16(sourceString);
|
||||||
@ -741,12 +764,18 @@ void tst_QRestAccessManager::text()
|
|||||||
serverSideResponse.body = encUTF32(sourceString);
|
serverSideResponse.body = encUTF32(sourceString);
|
||||||
VERIFY_TEXT_REPLY_OK;
|
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.insert("Content-Type:"_ba,
|
serverSideResponse.headers.insert("Content-Type:"_ba,
|
||||||
"text/plain; charset = \"UTF-32\";extraparameter=bar"_ba);
|
"text/plain; charset = \"UTF-32\";extraparameter=bar"_ba);
|
||||||
serverSideResponse.body = encUTF32(sourceString);
|
serverSideResponse.body = encUTF32(sourceString);
|
||||||
VERIFY_TEXT_REPLY_OK;
|
VERIFY_TEXT_REPLY_OK;
|
||||||
|
|
||||||
|
// Successful UTF-32 with spec-wise allowed extra leading content in the Content-Type header value
|
||||||
|
serverSideResponse.headers.insert("Content-Type:"_ba,
|
||||||
|
"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)
|
// Unsuccessful UTF-32, wrong encoding indicated (indicated UTF-32 but data is UTF-8)
|
||||||
serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-32"_ba);
|
serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-32"_ba);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user