QHeaderView: modernize calculateAndCheck helper function

Use QCOMPARE_* macros to compare results, and use a qScopeGuard to emit
diagnostic output in case of failure.

Task-number: QTBUG-116013
Change-Id: Id13ba70244d5c58c14c088619dbf0ee835492eb7
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit d9098760134bad9c1d18837a204ea7fb26d30e43)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-10-30 14:01:31 +01:00
parent 98d03964ac
commit 9f79ffe8f0

View File

@ -2926,24 +2926,26 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
const bool sanity_checks = true; const bool sanity_checks = true;
if (sanity_checks) { if (sanity_checks) {
QString msg = QString("sanity problem at ") + sline; const QString msg = QString("sanity problem at ") + sline;
const QScopedArrayPointer<char> holder(QTest::toString(msg)); auto diagnostics = qScopeGuard([msg]{
const auto verifytext = holder.data(); qWarning() << msg;
});
QVERIFY2(m_tableview->model()->rowCount() == view->count() , verifytext); QCOMPARE(m_tableview->model()->rowCount(), view->count());
QVERIFY2(view->visualIndex(lastindex + 1) <= 0, verifytext); // there is no such index in model QCOMPARE_LE(view->visualIndex(lastindex + 1), 0); // there is no such index in model
QVERIFY2(view->logicalIndex(lastindex + 1) <= 0, verifytext); // there is no such index in model. QCOMPARE_LE(view->logicalIndex(lastindex + 1), 0); // there is no such index in model.
QVERIFY2(view->logicalIndex(lastindex + 1) <= 0, verifytext); // there is no such index in model. QCOMPARE_LE(view->logicalIndex(lastindex + 1), 0); // there is no such index in model.
QVERIFY2(lastindex < 0 || view->visualIndex(0) >= 0, verifytext); // no rows or legal index QCOMPARE_GE(lastindex < 0 || view->visualIndex(0), 0); // no rows or legal index
QVERIFY2(lastindex < 0 || view->logicalIndex(0) >= 0, verifytext); // no rows or legal index QCOMPARE_GE(lastindex < 0 || view->logicalIndex(0), 0); // no rows or legal index
QVERIFY2(lastindex < 0 || view->visualIndex(lastindex) >= 0, verifytext); // no rows or legal index QCOMPARE_GE(lastindex < 0 || view->visualIndex(lastindex), 0); // no rows or legal index
QVERIFY2(lastindex < 0 || view->logicalIndex(lastindex) >= 0, verifytext); // no rows or legal index QCOMPARE_GE(lastindex < 0 || view->logicalIndex(lastindex), 0); // no rows or legal index
QVERIFY2(view->visualIndexAt(-1) == -1, verifytext); QCOMPARE(view->visualIndexAt(-1), -1);
QVERIFY2(view->logicalIndexAt(-1) == -1, verifytext); QCOMPARE(view->logicalIndexAt(-1), -1);
QVERIFY2(view->visualIndexAt(view->length()) == -1, verifytext); QCOMPARE(view->visualIndexAt(view->length()), -1);
QVERIFY2(view->logicalIndexAt(view->length()) == -1, verifytext); QCOMPARE(view->logicalIndexAt(view->length()), -1);
QVERIFY2(sum_visual == sum_logical, verifytext); QCOMPARE(sum_visual, sum_logical);
QVERIFY2(sum_to_last_index == sum_logical, verifytext); QCOMPARE(sum_to_last_index, sum_logical);
diagnostics.dismiss();
} }
// Semantic test // Semantic test
@ -2960,16 +2962,18 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
msg += istr(chk_visual) + istr(chk_logical) + istr(chk_sizes) + istr(chk_hidden_size) msg += istr(chk_visual) + istr(chk_logical) + istr(chk_sizes) + istr(chk_hidden_size)
+ istr(chk_lookup_visual) + istr(chk_lookup_logical) + istr(header_lenght, false) + "};"; + istr(chk_lookup_visual) + istr(chk_lookup_logical) + istr(header_lenght, false) + "};";
const QScopedArrayPointer<char> holder(QTest::toString(msg)); auto diagnostics = qScopeGuard([msg]{
const auto verifytext = holder.data(); qWarning() << msg;
});
QVERIFY2(chk_visual == x[0], verifytext); QCOMPARE(chk_visual , x[0]);
QVERIFY2(chk_logical == x[1], verifytext); QCOMPARE(chk_logical , x[1]);
QVERIFY2(chk_sizes == x[2], verifytext); QCOMPARE(chk_sizes , x[2]);
QVERIFY2(chk_hidden_size == x[3], verifytext); QCOMPARE(chk_hidden_size , x[3]);
QVERIFY2(chk_lookup_visual == x[4], verifytext); QCOMPARE(chk_lookup_visual , x[4]);
QVERIFY2(chk_lookup_logical == x[5], verifytext); QCOMPARE(chk_lookup_logical , x[5]);
QVERIFY2(header_lenght == x[6], verifytext); QCOMPARE(header_lenght , x[6]);
diagnostics.dismiss();
} }
void tst_QHeaderView::setupTestData(bool also_use_reset_model) void tst_QHeaderView::setupTestData(bool also_use_reset_model)