diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-02-22 15:40:43 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-04-21 19:58:51 +0000 |
commit | a611a9f537f1187825339c2a2214c8ec4a23680f (patch) | |
tree | 328fc4df9b633bafe0394b165c72e6cedcd65311 /src/testlib/qtestcase.qdoc | |
parent | 3f135dbcb931bc74741f0f23831831775b84eba3 (diff) |
QCOMPARE: allow mixed-type comparisons
There's no reason to restrict the LHS and the RHS to the same type
like it was done before. That just leads to lots of casting. or use
of QVERIFY(. == .) instead of QCOMPARE, with all the disadvantages
like no printing of the LHS and RHS values.
The rationale given in the documentation for this behavior is
incorrect. Ensuring that RHS and LHS have the same type by no means
ensures that no implicit conversions take place when calling
operator==. Proof:
QCOMPARE(QLatin1Char('a'), QLatin1Char('a'));
// instantiates
qCompare<QLatin1Char, QLatin1Char>
// but calls
operator==(QChar, QChar)
If the intent is to disable implicit conversions of the argument
types, then some serious metaprogramming magic would be needed, along
the following lines:
1. find out which op== overload is actually chosen
2. find that overload's RHS parameter type, assert it's the same as
(possibly cv-qualified) T1.
3. ditto for the LHS parameter type and T2
This is not attempted here.
Fix the inconvenience this restriction caused by simply allowing
two types.
This cannot break existing code, since we didn't actually change
anything in the qCompare() overload set. All we do is implement the
existing qCompare<T1, T2>() overload.
[ChangeLog][QtTest] QCOMPARE can now be used for mixed-type
comparisons.
Change-Id: I0413dbd3689809852413eaca22827257f1527720
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.qdoc')
-rw-r--r-- | src/testlib/qtestcase.qdoc | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc index 8f3d140add..92c9093bc5 100644 --- a/src/testlib/qtestcase.qdoc +++ b/src/testlib/qtestcase.qdoc @@ -82,11 +82,6 @@ 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. - QCOMPARE is very strict on the data types. Both \a actual and \a expected - have to be of the same type, otherwise the test won't compile. This prohibits - unspecified behavior from being introduced; that is behavior that usually - occurs when the compiler implicitly casts the argument. - For your own classes, you can use \l QTest::toString() to format values for outputting into the test log. |