From 15eb9dccae8264c97c1fc242f999003f3bbff9ff Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 9 Apr 2024 09:27:10 -0500 Subject: [PATCH] QTest::test*Operators: test reverse order too There's no need to condition that comparison only for heterogeneous types. The reverse comparisons will compile if the types are homogeneous (it's what we had already tested), but this now ensures the results are also the expected ones. Change-Id: If1bf59ecbe014b569ba1fffd17c4a2dd756157b2 Reviewed-by: Ivan Solovev --- src/testlib/qcomparisontesthelper_p.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/testlib/qcomparisontesthelper_p.h b/src/testlib/qcomparisontesthelper_p.h index b422fc40495..afeb1088c46 100644 --- a/src/testlib/qcomparisontesthelper_p.h +++ b/src/testlib/qcomparisontesthelper_p.h @@ -167,7 +167,8 @@ void testAllComparisonOperatorsCompile() Basic testing of equality operators. The helper function tests {in}equality operators (== and !=) for the \a lhs - operand of type \c {LeftType} and the \a rhs operand of type \c {RightType}. + operand of type \c {LeftType} and the \a rhs operand of type \c {RightType}, + plus the reverse order of the operands. The \a expectedEqual parameter is an expected result for \c {operator==()}. @@ -187,10 +188,8 @@ void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual) { CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, lhs, rhs, ==, expectedEqual); CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, lhs, rhs, !=, !expectedEqual); - if constexpr (!std::is_same_v) { - CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, ==, expectedEqual); - CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, !=, !expectedEqual); - } + CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, ==, expectedEqual); + CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, !=, !expectedEqual); } /*! @@ -199,7 +198,8 @@ void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual) The helper function tests all six relation and equality operators (==, !=, <, >, <=, >=) for the \a lhs operand of type \c {LeftType} and - the \a rhs operand of type \c {RightType}. + the \a rhs operand of type \c {RightType} and all six for the reverse + order of the operands. If compiled in C++20 mode, also checks \c {operator<=>()} if that is implemented. @@ -283,7 +283,6 @@ void testAllComparisonOperators(LeftType lhs, RightType rhs, OrderingType expect } #endif - if constexpr (!std::is_same_v) { CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, ==, !expectedUnordered && expectedEqual); CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, !=, @@ -319,7 +318,6 @@ void testAllComparisonOperators(LeftType lhs, RightType rhs, OrderingType expect !expectedUnordered && (expectedEqual || expectedLess)); } #endif - } } #ifdef __cpp_lib_three_way_comparison