Port tst_QFormDataBuilder to new style [3/6]: picksUtf8FilenameEncodingIfAsciiDontSuffice()
We don't want to have to rely on QDebug:toString() and the private QFormDataPartBuilder::build() function for checks, so use the framework originally introduced by Máté for the the moveSemantics() test for picksUtf8FilenameEncodingIfAsciiDontSuffice(), too. Requires to actually open the QBuffer and to revert the needles from QString back to QByteArray. Task-number: QTBUG-125985 Change-Id: I13c41e8df86296ae8652c460039798eb529d4628 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> (cherry picked from commit 2541f1945d2a64de7b2c13465a178ef70d96da89) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
95590adb55
commit
df6a26d9f0
@ -222,58 +222,59 @@ void tst_QFormDataBuilder::picksUtf8FilenameEncodingIfAsciiDontSuffice_data()
|
|||||||
{
|
{
|
||||||
QTest::addColumn<QLatin1StringView>("name_data");
|
QTest::addColumn<QLatin1StringView>("name_data");
|
||||||
QTest::addColumn<QAnyStringView>("body_name_data");
|
QTest::addColumn<QAnyStringView>("body_name_data");
|
||||||
QTest::addColumn<QString>("expected_content_type_data");
|
QTest::addColumn<QByteArray>("expected_content_type_data");
|
||||||
QTest::addColumn<QString>("expected_content_disposition_data");
|
QTest::addColumn<QByteArray>("expected_content_disposition_data");
|
||||||
QTest::addColumn<QString>("content_disposition_must_not_contain_data");
|
QTest::addColumn<QByteArray>("content_disposition_must_not_contain_data");
|
||||||
|
|
||||||
QTest::newRow("latin1-ascii") << "text"_L1 << QAnyStringView("rfc3252.txt"_L1) << u"text/plain"_s
|
QTest::newRow("latin1-ascii") << "text"_L1 << QAnyStringView("rfc3252.txt"_L1) << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="rfc3252.txt")"_s
|
<< R"(form-data; name="text"; filename="rfc3252.txt")"_ba
|
||||||
<< u"filename*"_s;
|
<< "filename*"_ba;
|
||||||
QTest::newRow("u8-ascii") << "text"_L1 << QAnyStringView(u8"rfc3252.txt") << u"text/plain"_s
|
QTest::newRow("u8-ascii") << "text"_L1 << QAnyStringView(u8"rfc3252.txt") << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="rfc3252.txt")"_s
|
<< R"(form-data; name="text"; filename="rfc3252.txt")"_ba
|
||||||
<< u"filename*"_s;
|
<< "filename*"_ba;
|
||||||
QTest::newRow("u-ascii") << "text"_L1 << QAnyStringView(u"rfc3252.txt") << u"text/plain"_s
|
QTest::newRow("u-ascii") << "text"_L1 << QAnyStringView(u"rfc3252.txt") << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="rfc3252.txt")"_s
|
<< R"(form-data; name="text"; filename="rfc3252.txt")"_ba
|
||||||
<< u"filename*"_s;
|
<< "filename*"_ba;
|
||||||
|
|
||||||
// 0xF6 is 'ö', use hex value with Latin-1 to avoid interpretation as UTF-8 (0xC3 0xB6)
|
// 0xF6 is 'ö', use hex value with Latin-1 to avoid interpretation as UTF-8 (0xC3 0xB6)
|
||||||
QTest::newRow("latin1-latin") << "text"_L1 << QAnyStringView("sz\xF6veg.txt"_L1) << u"text/plain"_s
|
QTest::newRow("latin1-latin") << "text"_L1 << QAnyStringView("sz\xF6veg.txt"_L1) << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="szöveg.txt"; filename*=UTF-8''sz%C3%B6veg.txt)"_s
|
<< R"(form-data; name="text"; filename="szöveg.txt"; filename*=UTF-8''sz%C3%B6veg.txt)"_ba
|
||||||
<< u""_s;
|
<< ""_ba;
|
||||||
QTest::newRow("u8-latin") << "text"_L1 << QAnyStringView(u8"szöveg.txt") << u"text/plain"_s
|
QTest::newRow("u8-latin") << "text"_L1 << QAnyStringView(u8"szöveg.txt") << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="szöveg.txt"; filename*=UTF-8''sz%C3%B6veg.txt)"_s
|
<< R"(form-data; name="text"; filename="szöveg.txt"; filename*=UTF-8''sz%C3%B6veg.txt)"_ba
|
||||||
<< u""_s;
|
<< ""_ba;
|
||||||
QTest::newRow("u-latin") << "text"_L1 << QAnyStringView(u"szöveg.txt") << u"text/plain"_s
|
QTest::newRow("u-latin") << "text"_L1 << QAnyStringView(u"szöveg.txt") << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="szöveg.txt"; filename*=UTF-8''sz%C3%B6veg.txt)"_s
|
<< R"(form-data; name="text"; filename="szöveg.txt"; filename*=UTF-8''sz%C3%B6veg.txt)"_ba
|
||||||
<< u""_s;
|
<< ""_ba;
|
||||||
|
|
||||||
QTest::newRow("u8-u8") << "text"_L1 << QAnyStringView(u8"テキスト.txt") << u"text/plain"_s
|
QTest::newRow("u8-u8") << "text"_L1 << QAnyStringView(u8"テキスト.txt") << "text/plain"_ba
|
||||||
<< uR"(form-data; name="text"; filename="テキスト.txt"; filename*=UTF-8''%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88.txt)"_s
|
<< R"(form-data; name="text"; filename="テキスト.txt"; filename*=UTF-8''%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88.txt)"_ba
|
||||||
<< u""_s;
|
<< ""_ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QFormDataBuilder::picksUtf8FilenameEncodingIfAsciiDontSuffice()
|
void tst_QFormDataBuilder::picksUtf8FilenameEncodingIfAsciiDontSuffice()
|
||||||
{
|
{
|
||||||
QFETCH(const QLatin1StringView, name_data);
|
QFETCH(const QLatin1StringView, name_data);
|
||||||
QFETCH(const QAnyStringView, body_name_data);
|
QFETCH(const QAnyStringView, body_name_data);
|
||||||
QFETCH(const QString, expected_content_type_data);
|
QFETCH(const QByteArray, expected_content_type_data);
|
||||||
QFETCH(const QString, expected_content_disposition_data);
|
QFETCH(const QByteArray, expected_content_disposition_data);
|
||||||
QFETCH(const QString, content_disposition_must_not_contain_data);
|
QFETCH(const QByteArray, content_disposition_must_not_contain_data);
|
||||||
|
|
||||||
QBuffer buff;
|
QBuffer buff;
|
||||||
QFormDataBuilder qfdb;
|
QVERIFY(buff.open(QIODevice::ReadOnly));
|
||||||
QFormDataPartBuilder &qfdpb = qfdb.part(name_data).setBodyDevice(&buff, body_name_data);
|
|
||||||
const QHttpPart httpPart = qfdpb.build();
|
const auto msg = serialized([&](auto &builder) {
|
||||||
|
builder.part(name_data).setBodyDevice(&buff, body_name_data);
|
||||||
|
});
|
||||||
|
|
||||||
const auto msg = QDebug::toString(httpPart);
|
|
||||||
QVERIFY2(msg.contains(expected_content_type_data),
|
QVERIFY2(msg.contains(expected_content_type_data),
|
||||||
qPrintable(u"content-type not found : "_s + expected_content_type_data));
|
"content-type not found : " + expected_content_type_data);
|
||||||
QVERIFY2(msg.contains(expected_content_disposition_data),
|
QVERIFY2(msg.contains(expected_content_disposition_data),
|
||||||
qPrintable(u"content-disposition not found : "_s + expected_content_disposition_data));
|
"content-disposition not found : " + expected_content_disposition_data);
|
||||||
if (!content_disposition_must_not_contain_data.isEmpty()) {
|
if (!content_disposition_must_not_contain_data.isEmpty()) {
|
||||||
QVERIFY2(!msg.contains(content_disposition_must_not_contain_data),
|
QVERIFY2(!msg.contains(content_disposition_must_not_contain_data),
|
||||||
qPrintable(u"content-disposition contained data it shouldn't : "_s
|
"content-disposition contained data it shouldn't : "
|
||||||
+ content_disposition_must_not_contain_data));
|
+ content_disposition_must_not_contain_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user