Commit Graph

1756 Commits (08fb81fb170392d5d6384d4abb4de251f8728362)

Author SHA1 Message Date
Mate Barany 4ca0c6db5e Add move semantics autotest for QFormDataBuilder
Change-Id: If9df38f0afd09218c15587b2864edb957cbbdaac
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 12d2ba9c913d03d637ffb9d123949a5f45e69e5e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-20 19:30:13 +00:00
Juha Vuolle 78784065a8 Accept QASV for multipart 'name' field
And adjust the encoding of 'name' parameter to  always
use UTF-8 / ASCII. This aligns with how other frameworks
behave. Also amended docs to recommend ASCII for 'name'.

Found in API review.

Change-Id: I54d1148bf95dece54b75c76914c49985da05e0b2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 6b23a3c5e4316c5f889ea5e9bbfd785b78716268)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-18 17:08:34 +00:00
Juha Vuolle b5dde79bc4 Adjust multipart 'filename' parameter encoding
The RFCs around these encodings are loose and allow
several ways for dealing with non-ASCII characters.
The encoding introduced in this commit should be
interoperable and aligns with other frameworks
(checked Curl, JS FormData, Postman, and Python
requests).

This consists of several adjustments:

1. Enclose the filename attribute in double quotes
2. If filename contains only ASCII characters, use them as-is
3. If filename contains characters beyond ASCII:
3.1. Encode them directly as raw UTF-8 to filename=
3.2. Set an additional filename*= parameter with
     percent encoded UTF-8. This is a legacy encoding
     for compatibility.

Task-number: QTBUG-125985
Change-Id: I5a6ad5388e4bb69e142caa7f6de7127526f441ad
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 8c8a0c06d4f77ba8a707ec0a101b423543bf30f0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-18 17:08:31 +00:00
Mate Barany 0a57b0e542 Refactor test cases in tst_qformdatabuilder
Hide the construction details of QFormDataPartBuilder, change
the verification to be QString based instead of QByteArray based,
and use raw string literals (where useful) for readability.

Task-number: QTBUG-114647
Change-Id: I16fb6c943cf6fd7385e78bbffe3b2780ab0a6ac8
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit cb8abb718da4e18232de525ef1bb611f3a5dd929)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-18 17:08:21 +00:00
Juha Vuolle 34f6210bb6 Relax QHttpHeaders value field checks to allow UTF-8
UTF-8 doesn't per se contain illegal characters from
an HTTP header RFC point of view. UTF-8 is the dominant
character encoding outside of ASCII, and is used
directly at least with HTTP multipart headers.

[ChangeLog][QtNetwork][QHttpHeaders] Allows UTF-8 in header
values now.

Task-number: QTBUG-125985
Pick-to: 6.7
Change-Id: I2d8d8f00855c96c1d2ba190f2e27e2d48fcd4975
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit f39b39b8c72b5c3428396d5e74cf15cafd5bbc42)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-18 04:53:43 +00:00
Marc Mutz 8bc09e9db3 tst_QNetworkReply: port _WITH_TIMEOUT calls to chrono literals
Dogfooding the new 6.8 feature.

Change-Id: Ic4c371896fcab0c94cef76341a6ef97763127968
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit 34089abeeac14a6437851530aa25f8b31a22acf1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-17 23:17:49 +00:00
Łukasz Matysiak 45d87f7bab Skip tst_QNetworkReply::contentEncodingBigPayload on 32b arch
The test requires allocating 4GB of memory to handle a big file.
On a 32b architecture, this leads to a std::bad_alloc exception and
abort in result (tested on VxWorks 24.03 on an imx6 board).
Because of that, the test can't work properly and it can't be
blacklisted.

Work around the issue by skipping the test.

Pick-to: 6.7
Task-number: QTBUG-115777
Change-Id: I46002a27aed09706cd61d2e2c8d4bd1e12a16c36
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 4d2744e4345193cdf7ec2bbf06b0a0d169827d8b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-14 14:59:03 +00:00
Mate Barany 885a49548d Add some missing tests for QFormDataBuilder
Test the setHeaders method and the option of manually setting the mime
type.

Task-number: QTBUG-114647
Change-Id: I86644b243830259156e60239adf370e5894450dc
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit 132498a69a626be6feaf1855cf63dd79d1ac9445)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-13 20:34:42 +00:00
Mårten Nordheim dbb945fd43 Update public suffix list
Version 903a83ff7bfc3148e3692e09396f9f3bdc9462ef, fetched on
2024-06-05.

[ChangeLog][Third-Party Code] Updated the public suffix list to upstream
SHA 903a83ff7bfc3148e3692e09396f9f3bdc9462ef.

Pick-to: 6.7 6.5 6.2 5.15
Task-number: QTBUG-126060
Change-Id: I96320b5df1a3573ab9198ad412fc1eca55204c02
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit c0d5c1b2fef140a44b6512ee79ba7fb67187a39c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-06-07 06:59:21 +00:00
Jari Helaakoski 313392ec6b Fix compilation issues when configuration features are disabled
Commit fixes settings and http features

Task-number: QTBUG-122999
Change-Id: Iff94e9e4f7122a35000376e59cdea2a93e6a7f40
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit ba672abfaed6fa8adde44b32c7f43c91630b5eeb)
2024-06-05 08:55:18 +00:00
Marc Mutz 5677c111cb QFormData(Part)Builder: simplify filename formatting
We don't need the bodyName member, because it's the same as
originalBodyName, just encoded, and we can delay the encoding to
build() time.

This is not worse than the old code, since we anyway toString() the
QAnyStringView unconditionally.

So we don't need to visit the QASV and implement RFC2232 encoding for
all three view types, we can just use the QString version, after
toString().

This not only has the advantage of less code and not storing duplicate
data, but we now also encode u8"ä.txt" the same as "ä.txt"_L1 and
u"ä.txt", ie. using latin1, as required by Postel's Law, and not as
UTF-8, as the old code did.

Change-Id: If82a33a1cd09b859b3a4450a60083b1d3aedf7bc
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-05-30 20:52:42 +02:00
Mate Barany 32610561e3 Add convenience classes to generate QHttpMultipart messages
Constructing and composing a QHttpMultipart contains some aspects that
are possible candidates for automating, such as setting the headers
manually for each included part. As a reference, when issuing a default
multipart with CURL, one does not need to manually set the headers.

Add the class QFormDataPartBuilder to simplify the construction of
QHttpPart objects.

Add the class QFormDataBuilder to simplify the construction of
QHttpMultiPart objects.

[ChangeLog][QtNetwork][QFormDataBuilder] New class to help constructing
multipart/form-data QHttpMultiParts.

Fixes: QTBUG-114647
Change-Id: Ie035dabc01a9818d65a67c239807b50001fd984a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-05-30 18:52:42 +00:00
Mårten Nordheim 48aad482a8 Http: Add support for full localsocket paths
[ChangeLog][QtNetwork][QNetworkAccessManager] QNetworkAccessManager now
supports using full local server name, as in, named pipes on Windows or path to
socket objects on Unix.

Task-number: QTBUG-102855
Change-Id: Ifc743f5025b3d8d0b558ecffff437881897915d9
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2024-05-24 22:36:59 +02:00
Assam Boudjelthia f1c6c66985 Android: prefer wlan IPv6 connection over other interfaces
Android doesn't allow connection from interfaces like (radio0, eth0,
etc.) when wlan0 is already connected, so prefer testing that.

Task-number: QTBUG-125023
Change-Id: Id48a6717755edc22909a4a0d58631d8132a42b1a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-05-23 10:26:20 +03:00
Marc Mutz 658939dae2 tst_http2: fix -Wunused-parameter warning
Amends 4f9387f2ae.

Pick-to: 6.7 6.5
Change-Id: I3e58967e05afad9f1a0dd581c3795e4f4c8c8de5
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-05-22 15:47:50 +02:00
Mårten Nordheim 68ceb847d6 QNetworkReply: Add a separate test for self-contained tests
Nothing there should rely on the network testing server.
Part of this will also be testing the local/unix domain socket support.

Task-number: QTBUG-102855
Change-Id: Icf3b0bd9370ec62e003862caf4cd3ed38d875bac
Reviewed-by: Mate Barany <mate.barany@qt.io>
2024-05-16 19:40:03 +02:00
Jari Helaakoski 0ae44ccc6f Improve test compilation setup with QtLite configuration
Functional fix will come later via separate tasks.

Task-number: QTBUG-122999
Change-Id: Ib805740c87ff21cea5a186add71cc594ab4d4df1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-10 09:04:44 +00:00
Thiago Macieira a6d26ef64b tst_QDnsLookup: add debugging information with the query time
Change-Id: I455fe22ef4ad4b2f9b01fffd17c805aa76d2b314
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-08 21:13:49 -07:00
Thiago Macieira 4503dabfbd QDnsLookup: add support for TLSA records
[ChangeLog][QtNetwork][QDnsLookup] Added support for querying records of
type TLSA, which are useful in DNS-based Authentication of Named
Entities (DANE).

Change-Id: I455fe22ef4ad4b2f9b01fffd17c723aa6ab7f278
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-08 21:13:47 -07:00
Thiago Macieira f2f00b2a46 QDnsLookup: implement DNS-over-TLS
For the libresolv (Unix) implementation, we already had the packet
prepared by res_nmkquery(). This commit moves the res_nsend() to a
separate function so QDnsLookupRunnable::query() can be more concise.

On the Windows side, this commit creates a separate function for the DoT
case, because we now need to use two other functions from WinDNS so we
can create a query and parse the reply.

The rest is just QSslSocket.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c805a3cb0466eb
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-09 04:13:44 +00:00
Thiago Macieira 9724b039ca QDnsLookup: add initial support for DNS-over-TLS (DoT)
This is just an empty shell for now. The implementation will come in the
next commit.

[ChangeLog][QtNetwork][QDnsLookup] The class now supports DNS-over-TLS
and some other DNSSEC experimental features, on some platforms. Use
QDnsLookup::isProtocolSupported to know if the protocol is supported on
a given platform.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c7e034dee75533
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-08 21:13:43 -07:00
Lena Biliaieva fb2ea1e52a tst_QNetworkRequest: add test for operator==()
Task-number: QTBUG-107751
Change-Id: I4ed77b022f9e576f1363d55a05de6f6fad5b01dc
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-05-07 21:28:59 +02:00
Lena Biliaieva 0fef8f53c3 Use QHttpHeaders: Update internal users of QNRequest, QNReply, QNProxy
Replace QNetworkHeadersPrivate's main headers storage, which was
RawHeadersList, with QHttpHeaders. Replace internal usage of raw and
cooked header methods with the QHttpHeaders API.

[ChangeLog][QtNetwork][QNetworkRequest] Header value added by
QNetworkRequest::setRawHeader() method is trimmed now.

Task-number: QTBUG-107751
Change-Id: I8882978afa430651e6c798a4fed00beef6c4cfd2
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-05-07 12:39:23 +02:00
Jari Helaakoski 30cc8a28de Fix test compilation issues with QtLite configuration
Now developer build tests compile, but some are not working.
Functional fix will come later via separate tasks.

Task-number: QTBUG-122999
Change-Id: I70487b46c1b32ba4279cb02a4978e4f55ac0d310
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-05-06 14:29:02 +00:00
Mate Barany 3377b74df9 Add QDebug support to QHttpPart
As part of QTBUG-114647 we are planning to introduce a deduction
mechanism that could deduce the contentType header and the
contentDisposition headers based on the arguments (and the MIME
database).

In case of non-trivial types this deduction may give the wrong result
and without QDebug support it might be a bit tedious to check.

The debug output displays some information about the body device if
one is attached, otherwise it displays the size of the body.

Task-number: QTBUG-114647
Change-Id: Ia693b078ff5b9f8ea57fbf3c385edaec47886ff1
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-03 15:16:14 +00:00
Ari Parkkila 53a58a191c ptests: Skip qlocalsocket when running as root on Linux
On Linux root user has access rights to all files so it makes no sense
to verify socket file permissions.

Task-number: QTBUG-118680
Change-Id: I94a95e80c311f8d5cd6c799b1a76ffaaab7d9167
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-05-03 11:58:54 +03:00
Marc Mutz 834e7d60a9 QRestReply: allow comments where white-space is allowed
This is RFC2822 grammar (except that line folding is not
allowed).

RFC9110 doesn't allow it anymore, but it might make sense to accept it
nonetheless (Postel's Law).

Pick-to: 6.7
Task-number: QTBUG-123544
Change-Id: Ie990cd332c7603dbdae29c19b2804bd33a058ca0
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-05-03 01:05:07 +02:00
Lena Biliaieva 78b0d507ce Add QHttpHeaders methods to QNetworkCacheMetaData
[ChangeLog][QtNetwork][QNetworkCacheMetaData] Added headers() and
setHeaders() methods to QNetworkCacheMetaData to provide an interface
to work with QHttpHeaders.

Task-number: QTBUG-107751
Change-Id: I1dfed5c2e03f4912de0da96156425cd6b713c1d5
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-05-02 22:11:44 +02:00
Lena Biliaieva fa456ad550 Add QHttpHeaders to QNetworkRequest
Added headers() and setHeaders() methods to QNetworkRequest.

[ChangeLog][QtNetwork][QNetworkRequest] Added headers() and setHeaders()
methods to QNetworkRequest, which provide an interface to work with
QHttpHeaders.

Task-number: QTBUG-107751
Change-Id: I2e1dc7cb2efab5903eb7ff23b75d01aefe13273d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-29 18:26:15 +02:00
Marc Mutz 98b034e53a QRestReply: make charset parsing more robust
The old code was based on QString::split and e.g. didn't handle
escapes in quoted-strings.

Write a modern recursive-descent parser to parse out type/subtype and
charset parameter. Since we don't, yet, support CFWS (see below),
recursion depth is strictly limited, so we're not susceptible to
recursion bombs here.

It currently handles only RFC9110-style grammar, but can be easily
extended to support CFWS (RFC2822-style comments and folding
white-space) or RFC2231-style continuuations, if needed.

It's a bit more general than strictly required, because I expect this
to be reused elsewhere ere long.

Pick-to: 6.7
Fixes: QTBUG-120307
Change-Id: I309928dc350a043672dffb4a259b457764c031be
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-04-26 02:24:53 +02:00
Marc Mutz 2822b22610 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>
2024-04-24 21:36:49 +02:00
Thiago Macieira f110bd2663 tst_QDnsLookup: add testing of PTR records on global names
The DNS servers from Google and CloudFare are probably stable enough
over the long-term.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c748dc1233bc1b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 6800e168d5 tst_QDnsLookup: also use the nameservers behind systemd-resolved
If the file exists, we are using systemd-resolved, so let's try directly
using the nameservers it uses.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c7476a2385bf4b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira f7d293d3da tst_QDnsLookup refactor: use the new helpers in other test functions
Change-Id: I455fe22ef4ad4b2f9b01fffd17c7414e111cb8ed
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 4b8bdab27d tst_QDnsLookup refactor: rewrite lookup() function
This is a major simplification to use only one column in the QtTest
tables for the results, which makes it far easier to read the code as
well as to add more record types.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c745d13c9c4037
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 121a081d20 tst_QDnsLookup refactor: split the NXDOMAIN tests from lookup()
This will allow making lookup() require positive results only.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c740e36002d25e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 41675df695 tst_QDnsLookup: use the 4-argument writeDatagram() overload
When using writeDatagram(QNetworkDatagram), the sendmsg() call on
FreeBSD is failing. It works on Linux and on macOS, so my guess is that
IP_PKTINFO works to set the sender address but IP_SENDSRCADDR is not
allowed in this context for some reason.

Before:
 recvmsg(5,{{ AF_INET 127.0.0.1:19530 },16,[{"H\M-p\^A\0\0\^A\0\0\0\0\0\^A\tso"...,49}],1,{{level=IPPROTO_IP,type=IP_RECVDSTADDR,data={0x7f,0x00,0x00,0x01}},{level=IPPROTO_IP,type=IP_RECVTTL,data={0x40}}},48,0},0) = 49 (0x31)
 sendmsg(5,{{ AF_INET 127.0.0.1:19530 },16,[{"H\M-p\M^@\^C\0\^A\0\0\0\0\0\^A\t"...,49}],1,{{level=IPPROTO_IP,type=IP_RECVDSTADDR,data={0x7f,0x00,0x00,0x01}}},24,0},MSG_NOSIGNAL) ERR#22 'Invalid argument'

After:
 recvmsg(5,{{ AF_INET 127.0.0.1:16018 },16,[{"\^U\M-X\^A\0\0\^A\0\0\0\0\0\^A\t"...,49}],1,{{level=IPPROTO_IP,type=IP_RECVDSTADDR,data={0x7f,0x00,0x00,0x01}},{level=IPPROTO_IP,type=IP_RECVTTL,data={0x40}}},48,0},0) = 49 (0x31)
 sendmsg(5,{{ AF_INET 127.0.0.1:16018 },16,[{"\^U\M-X\M^@\^C\0\^A\0\0\0\0\0\^A"...,49}],1,{},0,0},MSG_NOSIGNAL) = 49 (0x31)

Pick-to: 6.7
Change-Id: I455fe22ef4ad4b2f9b01fffd17c77565e230ce31
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:29 -07:00
Thiago Macieira 2dfb7f3337 tst_QDnsLookup: fix MSVC 'truncation of constant value' warning
0x80 is too big for a signed char (range is -0x80 to 0x7f).

Pick-to: 6.7
Change-Id: I455fe22ef4ad4b2f9b01fffd17c7746f4ea3c536
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:29 -07:00
Mårten Nordheim 4f9387f2ae Http2: fix handling unsuppported authenticate challenge
When adding/fixing parts earlier it was missed that it was not handling
the _unsupported_ case, when authentication is not handled and there is
no resend. But there _is_ a challenge header.

Pick-to: 6.7 6.6 6.5
Fixes: QTBUG-123891
Change-Id: I21470df0ce2528bad3babffc6e9f19b7afd29d20
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2024-04-20 13:48:37 +02:00
Marc Mutz a564618838 HttpTestServer: pass std::function by value and move into place
Virtually all callers of this function (will) pass rvalues, so take
the std::function by value (reaping C++17 guaranteed copy elision) and
std::move() into the member variable ("perfect sink").

Like for many owning types, moves are much cheaper than copies for
std::function, because the external state is merely tranferred between
objects, and not copied.

Amends e560adef21.

Pick-to: 6.7
Change-Id: I269b54e51ba09ac595ac4e4f255209778819adad
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-04-18 19:06:02 +02:00
Marc Mutz 5b6c6dab63 tst_QRestAccessManager: fix signature of server handlers
HttpTestServer::Handler is declared to take the first argument by
reference to const, not by value, so use the same parameter passing
for the lambdas passed to setHandler().

Avoids copying the (rather large) argument when invoked through the
std::function wrapper, and silences clazy-function-args-by-ref.

Pick-to: 6.7
Change-Id: I726d0b98a7fcb3b1b33c5bde203035f593c39bdd
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-04-18 19:06:02 +02:00
Marc Mutz d4aaf61b33 tst_QRestAccessManager: leak less on failure
Move some deleteLater() calls to before the first QCOMPARE/QVERIFY
macros, so they get executed even if the macros return on failure.

This isn't an all-encompassing solution, but I lack the time to port
all this to smart pointers, and this is some improvement.

As a drive-by, port QVERIFY(opt.has_value()) to QCOMPARE(opt, nullopt).

Task-number: QTBUG-120307
Pick-to: 6.7
Change-Id: Ia5a2cabd273a779938b22badc91b109fcc545203
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-04-18 19:06:01 +02:00
Mårten Nordheim b85acc8356 tst_QHttpNetworkConnection: Move to use only one ctor
We want to get rid of the other one, it's all internal
API anyway.

Task-number: QTBUG-102855
Change-Id: I2b621c20f4dd7c8bf5f07db8db908c2b7b86976f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2024-04-17 20:30:36 +02:00
Giuseppe D'Angelo c68f8db62b Tests: make some QFile::open calls fail
In some cases calls to QFile::open are made outside of a testfunction
(so we can't use QVERIFY), or even in standalone executables that are
executed by tests. Make them fail "visibly".

Change-Id: Iec4d56f6d874be16aa2e9ad6974eeec2a98caa3f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-04-13 01:36:06 +02:00
Mårten Nordheim 1d03e1851b QHttp2Connection: fix handling of replies on locally initiated stream
It was overlooked in testing, but it would emit a signal for new
incoming stream even if the server was just replying with HEADERS on a
stream the client had initiated. Or vice-versa.

Pick-to: 6.7
Change-Id: Ie7b3a45729a78106da1d8c058e15705cc7dcc53b
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
2024-04-11 21:53:59 +02:00
Giuseppe D'Angelo 58ff4e22f7 tst_qnetworkreply: verify we can open the local file for comparison
... except for bigfile.

Change-Id: Ide04a9c80b438272e868a6d2b410a507c76d6239
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-03 23:57:45 +01:00
Giuseppe D'Angelo 8414a0aa2c Tests: check the output of QFile::open
Wrap the call in QVERIFY.

tst_QTextStream::read0d0d0a was also faulty as it *never* opened
the file because of a broken path. Fix it with QFINDTESTDATA.

Change-Id: I61a8f83beddf098d37fda13cb3bfb4aaa4913fc5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-03-27 04:24:11 +01:00
Marc Mutz 20eba275d8 tst_QNetworkReply: don't leak on failure in emitErrorForAllReplies()
The old code allocated QSignalSpies on the heap and stored them in a
non-owning container, so if one of the many check macros trigger,
those objects would be leaked. Ditto QNetworkReplies. The code also
used dynamically-sized containers for statically-sized data; a common
anti-pattern.

Hold the sample QUrls in a C array instead, QSignalSpies in C arrays
of std::optional (to delay initialization) and QNetworkReplies in a C
array of std::unique_ptr with the existing QScopedPointerDeleteLater
deleter.

Pick-to: 6.7
Change-Id: I7305115af15c079abba6d45c5de8db2198ea7a6d
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-03-21 11:20:49 +01:00
Marc Mutz eefd8ab1e8 tst_QNetworkReply: don't use deleteLater() on QSignalSpies
Turn the QSignalSpy deletions from deferred (via deleteLater()) into
immediate ones. This is ok: QSignalSpy is using itself as a context
object in QMetaObject::connect(), so the connection thus established
to the monitored signal will be atomically severed if either sender or
receiver are destroyed. There never was a need to defer deletion of
the signal spy, so don't.

Found by making QSignalSpy's inheritance from QObject private.

Pick-to: 6.7 6.6 6.5
Change-Id: I962d28c3a78f356d234324fed68716f2f1052100
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-20 21:22:12 +01:00
Marc Mutz 17d2550ed0 tst_QNetworkReply: use QtCore's QScopedPointerDeleteLater
... instead of rolling your own.

Pick-to: 6.7 6.6 6.5
Change-Id: I4fee2218eb874bfee34bd3a0abac3f85b0746540
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-20 21:21:29 +01:00