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>bb10
parent
96f78cbdd9
commit
d4aaf61b33
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue