Port tst_QFormDataBuilder to new style [6/6]: picksUtf8NameEncodingIfAsciiDoesNotSuffice()
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 picksUtf8NameEncodingIfAsciiDoesNotSuffice(), too. Requires to revert the needles from QString back to QByteArray. This completes the port away from QFormDataPartBuilder::build() use in the tests, allowing us to remove the tst_QFormDataBuilder friend declaration and unexport build(). Task-number: QTBUG-125985 Change-Id: Icae84f54c6f768e097b36b4c4f964eeb6d676809 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> (cherry picked from commit d0b0fe76663a4c7fe007cb66afa936ea7fe3d918) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
53d9f99a08
commit
e2ffa8ddf6
@ -19,8 +19,6 @@
|
||||
QT_REQUIRE_CONFIG(http);
|
||||
#endif
|
||||
|
||||
class tst_QFormDataBuilder;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QHttpPartPrivate;
|
||||
@ -75,7 +73,7 @@ private:
|
||||
Q_NETWORK_EXPORT QFormDataPartBuilder &setBodyHelper(const QByteArray &data,
|
||||
QAnyStringView fileName,
|
||||
QAnyStringView mimeType);
|
||||
Q_NETWORK_EXPORT QHttpPart build();
|
||||
QHttpPart build();
|
||||
|
||||
QByteArray m_headerValue;
|
||||
QByteArray m_mimeType;
|
||||
@ -85,7 +83,6 @@ private:
|
||||
void *m_reserved = nullptr;
|
||||
|
||||
friend class QFormDataBuilder;
|
||||
friend class ::tst_QFormDataBuilder;
|
||||
friend void swap(QFormDataPartBuilder &lhs, QFormDataPartBuilder &rhs) noexcept
|
||||
{ lhs.swap(rhs); }
|
||||
};
|
||||
|
@ -398,31 +398,31 @@ void tst_QFormDataBuilder::specifyMimeType()
|
||||
void tst_QFormDataBuilder::picksUtf8NameEncodingIfAsciiDoesNotSuffice_data()
|
||||
{
|
||||
QTest::addColumn<QAnyStringView>("name_data");
|
||||
QTest::addColumn<QString>("expected_content_disposition_data");
|
||||
QTest::addColumn<QByteArray>("expected_content_disposition_data");
|
||||
|
||||
QTest::newRow("latin1-ascii") << QAnyStringView("text"_L1) << uR"(form-data; name="text")"_s;
|
||||
QTest::newRow("u8-ascii") << QAnyStringView(u8"text") << uR"(form-data; name="text")"_s;
|
||||
QTest::newRow("u-ascii") << QAnyStringView(u"text") << uR"(form-data; name="text")"_s;
|
||||
QTest::newRow("latin1-ascii") << QAnyStringView("text"_L1) << R"(form-data; name="text")"_ba;
|
||||
QTest::newRow("u8-ascii") << QAnyStringView(u8"text") << R"(form-data; name="text")"_ba;
|
||||
QTest::newRow("u-ascii") << QAnyStringView(u"text") << R"(form-data; name="text")"_ba;
|
||||
|
||||
// 0xF6 is 'ö', use hex value with Latin-1 to avoid interpretation as UTF-8
|
||||
QTest::newRow("latin1-latin") << QAnyStringView("t\xF6xt"_L1) << uR"(form-data; name="töxt")"_s;
|
||||
QTest::newRow("u8-latin") << QAnyStringView(u8"töxt") << uR"(form-data; name="töxt")"_s;
|
||||
QTest::newRow("u-latin") << QAnyStringView(u"töxt") << uR"(form-data; name="töxt")"_s;
|
||||
QTest::newRow("latin1-latin") << QAnyStringView("t\xF6xt"_L1) << R"(form-data; name="töxt")"_ba;
|
||||
QTest::newRow("u8-latin") << QAnyStringView(u8"töxt") << R"(form-data; name="töxt")"_ba;
|
||||
QTest::newRow("u-latin") << QAnyStringView(u"töxt") << R"(form-data; name="töxt")"_ba;
|
||||
|
||||
QTest::newRow("u8-u8") << QAnyStringView(u8"テキスト") << uR"(form-data; name="テキスト")"_s;
|
||||
QTest::newRow("u8-u8") << QAnyStringView(u8"テキスト") << R"(form-data; name="テキスト")"_ba;
|
||||
}
|
||||
|
||||
void tst_QFormDataBuilder::picksUtf8NameEncodingIfAsciiDoesNotSuffice()
|
||||
{
|
||||
QFETCH(const QAnyStringView, name_data);
|
||||
QFETCH(const QString, expected_content_disposition_data);
|
||||
QFETCH(const QByteArray, expected_content_disposition_data);
|
||||
|
||||
QFormDataBuilder qfdb;
|
||||
QFormDataPartBuilder &qfdpb = qfdb.part(name_data).setBody("some"_ba);
|
||||
auto msg = QDebug::toString(qfdpb.build());
|
||||
const auto msg = serialized([&](auto &builder) {
|
||||
builder.part(name_data).setBody("some"_ba);
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void tst_QFormDataBuilder::moveSemantics()
|
||||
|
Loading…
x
Reference in New Issue
Block a user