diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-04-17 18:02:15 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-04-18 19:06:01 +0200 |
commit | d4aaf61b3333b48b4e79ad60b63bb50dbea72617 (patch) | |
tree | 356a1f3cb892d7c34955aad34a58b551b63832fb /tests/auto/network/access | |
parent | 96f78cbdd9412e6043bb4eb0d0dd818c5d800151 (diff) |
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>
Diffstat (limited to 'tests/auto/network/access')
-rw-r--r-- | tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp b/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp index a29b9c25ad..2f3ffaac33 100644 --- a/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp +++ b/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp @@ -638,12 +638,13 @@ void tst_QRestAccessManager::json() QTRY_VERIFY(networkReply); QRestReply restReply(networkReply); parseError.error = QJsonParseError::ParseError::DocumentTooLarge; - QVERIFY(!restReply.readJson(&parseError).has_value()); // std::nullopt returned + const auto json = restReply.readJson(&parseError); + networkReply->deleteLater(); + networkReply = nullptr; + QCOMPARE_EQ(json, std::nullopt); QCOMPARE_NE(parseError.error, QJsonParseError::ParseError::NoError); QCOMPARE_NE(parseError.error, QJsonParseError::ParseError::DocumentTooLarge); QCOMPARE_GT(parseError.offset, 0); - networkReply->deleteLater(); - networkReply = nullptr; } { @@ -654,6 +655,8 @@ void tst_QRestAccessManager::json() QRestReply restReply(networkReply); parseError.error = QJsonParseError::ParseError::DocumentTooLarge; json = restReply.readJson(&parseError); + networkReply->deleteLater(); + networkReply = nullptr; QCOMPARE(parseError.error, QJsonParseError::ParseError::NoError); QVERIFY(json); responseJsonDocument = *json; @@ -661,8 +664,6 @@ void tst_QRestAccessManager::json() QCOMPARE(responseJsonDocument.array().size(), 2); QCOMPARE(responseJsonDocument[0].toString(), "foo"_L1); QCOMPARE(responseJsonDocument[1].toString(), "bar"_L1); - networkReply->deleteLater(); - networkReply = nullptr; } } @@ -672,9 +673,9 @@ void tst_QRestAccessManager::json() QTRY_VERIFY(networkReply); \ QRestReply restReply(networkReply); \ responseString = restReply.readText(); \ - QCOMPARE(responseString, sourceString); \ networkReply->deleteLater(); \ networkReply = nullptr; \ + QCOMPARE(responseString, sourceString); \ } #define VERIFY_TEXT_REPLY_ERROR(WARNING_MESSAGE) \ @@ -684,9 +685,9 @@ void tst_QRestAccessManager::json() QTest::ignoreMessage(QtWarningMsg, WARNING_MESSAGE); \ QRestReply restReply(networkReply); \ responseString = restReply.readText(); \ - QVERIFY(responseString.isEmpty()); \ networkReply->deleteLater(); \ networkReply = nullptr; \ + QVERIFY(responseString.isEmpty()); \ } void tst_QRestAccessManager::text() |