summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.qdoc
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-10 11:41:33 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-21 22:01:20 +0200
commitd25589e0529732996e405aaff8d6c46b012e1601 (patch)
tree29b596d0c2ca0e36aa9aea65f426ed393c660e78 /src/testlib/qtestcase.qdoc
parentb50daef9771d8829fc7f808898cbe051a5464b79 (diff)
QTestlib: Enable comparing QList against initializer lists/arrays
It is unnecessary to create a QList container just for comparison. Split out helpers for comparing sequence sizes and sequences from qCompare(QList) and add a template for an array with a non-type template parameter for the size. One can then write something like: const int expected[] = {10, 12,...}; QCOMPARE(QFontDatabase.pointSizes(...), expected) Unfortunately, any commas in such an array will be misread by macro expansion as macro argument separators, so any expected array with more than one entry needs an extra macro expanding __VA_ARGS__. Change-Id: Ie7c8dc20bf669bbb25f6d7f8562455f8d03968c8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.qdoc')
-rw-r--r--src/testlib/qtestcase.qdoc19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc
index 98112027a5..8c89b37baf 100644
--- a/src/testlib/qtestcase.qdoc
+++ b/src/testlib/qtestcase.qdoc
@@ -116,19 +116,28 @@
Expected. If the parameter order is swapped, debugging a failing test can be
confusing and tests expecting zero may fail due to rounding errors.
+ QCOMPARE() tries to output the contents of the values if the comparison fails,
+ so it is visible from the test log why the comparison failed.
+
+ Example:
+ \snippet code/src_qtestlib_qtestcase.cpp 2
+
When comparing floating-point types (\c float, \c double, and \c qfloat16),
\l qFuzzyCompare() is used for finite values. If qFuzzyIsNull() is true for
both values, they are also considered equal. Infinities match if they have
the same sign, and any NaN as actual value matches with any NaN as expected
value (even though NaN != NaN, even when they're identical).
- QCOMPARE() tries to output the contents of the values if the comparison fails,
- so it is visible from the test log why the comparison failed.
+ When comparing QList, arrays and initializer lists of the value type
+ can be passed as expected value:
+ \snippet code/src_qtestlib_qtestcase.cpp 34
- Example:
- \snippet code/src_qtestlib_qtestcase.cpp 2
+ Note that using initializer lists requires a defining a helper macro
+ to prevent the preprocessor from interpreting the commas as macro argument
+ delimiters:
+ \snippet code/src_qtestlib_qtestcase.cpp 35
- \note This macro can only be used in a test function that is invoked
+ \note QCOMPARE() can only be used in a test function that is invoked
by the test framework.
For your own classes, you can use \l QTest::toString() to format values for