summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtest.h
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-06-03 09:27:27 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-06-03 20:37:51 +0000
commit0681a2dd5a8095baddb5905fb21a58ce19b958c5 (patch)
treee9a8a67e50f817e3f48cebd5294fa4a96bee8945 /src/testlib/qtest.h
parent1e36eedb7f6d312f439aa3d1b1529e7fd672d81a (diff)
QTestLib: rework QTest::compare_helper()
[ChangeLog][QTestLib] QCOMPARE now evaluates toString() on its arguments lazily, speeding up the general case where the comparison doesn't fail. This is true for the QCOMPARE functionality provided by Qt. If you specialized qCompare() for your own types, then you need to change its implementation in line with Qt's own qCompare() specializations in order to enable this feature. [ChangeLog][QTestLib] QCOMPARE calls with nullptr argument(s) will now print the actual and expected values upon failure. Previously it was not like that because of the compareHelper() overload in qtestresult.cpp that treated the presence of nullptr-arguments as a reason to ignore formatFailMessage() call. New implementation does not have this check, and correctly executes formatFailMessage() for all arguments. Note that the qCompare() overloads that call QTestResult::compare() internally were not affected by this patch, because they already defer toString() invocation until the comparison fails. Some numbers, collected against shared release developer build. I checked how this change affects the test execution. The idea was to pick some tests for types that do not have a specific QTestResult::compare overload, so I picked a couple of QByteArray tests. The comparison is done by running a test 10 times and taking the average execution duration, as reported in the log. tst_qbytearrayapisymmetry: Before: 15.6 ms After: 14.2 ms tst_qbytearray: Before: 41 ms After: 36 ms The benefit is around 9% and 12% respectively. Fixes: QTBUG-98874 Change-Id: I7d59ddc760168b15974e7720930f629fb34efa13 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/testlib/qtest.h')
-rw-r--r--src/testlib/qtest.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index cb73a9538a..e185e81eb8 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -421,7 +421,7 @@ bool _q_compareSequence(ActualIterator actualIt, ActualIterator actualEnd,
delete [] val2;
}
}
- return compare_helper(isOk, msg, nullptr, nullptr, actual, expected, file, line);
+ return compare_helper(isOk, msg, actual, expected, file, line);
}
namespace Internal {