Skip to content

Commit

Permalink
[QCOMPARE_3WAY] Expected and actual vars should use different formatters
Browse files Browse the repository at this point in the history
- Split the orderFormatter into two parameters: actualOrderFormatter
and expectedOrderFormatter

Ammends 454f010

Change-Id: I4ec468a0c0a4daea41c5ba2ce5ccfff0378460b8
Reviewed-by: Marc Mutz <[email protected]>
Reviewed-by: Ivan Solovev <[email protected]>
  • Loading branch information
qt-tatiana authored and Ivan Solovev committed Nov 21, 2024
1 parent 35022c1 commit 69315d6
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 111 deletions.
8 changes: 5 additions & 3 deletions src/testlib/qtestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,7 @@ bool QTest::compare_helper(bool success, const char *failureMsg,
in the output, with the expected comparison expression
\a expectedExpression. Their respective values are supplied by
\a actualOrderPtr and \a expectedOrderPtr pointers, which are
formatted by \a orderFormatter.
formatted by \a actualOrderFormatter and \a expectedOrderFormatter.
If \a failureMsg is \nullptr a default is used. If a formatter
function returns \a nullptr, the text \c{"<null>"} is used.
Expand All @@ -2869,7 +2869,8 @@ bool QTest::compare_3way_helper(bool success, const char *failureMsg,
const char *(*lhsFormatter)(const void*),
const char *(*rhsFormatter)(const void*),
const char *lhsExpression, const char *rhsExpression,
const char *(*orderFormatter)(const void*),
const char *(*actualOrderFormatter)(const void *),
const char *(*expectedOrderFormatter)(const void *),
const void *actualOrderPtr, const void *expectedOrderPtr,
const char *expectedExpression,
const char *file, int line)
Expand All @@ -2878,7 +2879,8 @@ bool QTest::compare_3way_helper(bool success, const char *failureMsg,
lhsPtr, rhsPtr,
lhsFormatter, rhsFormatter,
lhsExpression, rhsExpression,
orderFormatter,
actualOrderFormatter,
expectedOrderFormatter,
actualOrderPtr, expectedOrderPtr,
expectedExpression,
file, line);
Expand Down
7 changes: 5 additions & 2 deletions src/testlib/qtestcase.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ namespace QTest
const char *(*lhsFormatter)(const void*),
const char *(*rhsFormatter)(const void*),
const char *lhsStr, const char *rhsStr,
const char *(*orderFormatter)(const void *),
const char *(*actualOrderFormatter)(const void *),
const char *(*expectedOrderFormatter)(const void *),
const void *actualOrderPtr,
const void *expectedOrderPtr,
const char *expectedExpression,
Expand Down Expand Up @@ -815,8 +816,10 @@ namespace QTest
std::addressof(lhs), std::addressof(rhs),
genericToString<DLHS>, genericToString<DRHS>,
lhsExpression, rhsExpression,
genericToString<decltype(comparisonResult)>,
genericToString<OrderingType>,
std::addressof(actualOrder), std::addressof(order),
std::addressof(comparisonResult),
std::addressof(order),
resultExpression, file, line);
}
#else
Expand Down
7 changes: 4 additions & 3 deletions src/testlib/qtestresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ bool QTestResult::report3WayResult(bool success,
const char *(*lhsFormatter)(const void*),
const char *(*rhsFormatter)(const void*),
const char *lhsExpression, const char *rhsExpression,
const char *(*orderFormatter)(const void*),
const char *(*actualOrderFormatter)(const void *),
const char *(*expectedOrderFormatter)(const void *),
const void *actualOrder, const void *expectedOrder,
const char *expectedExpression,
const char *file, int line)
Expand Down Expand Up @@ -762,8 +763,8 @@ bool QTestResult::report3WayResult(bool success,
const std::unique_ptr<const char[]> lhsStr{lhsFormatter(lhs)};
const std::unique_ptr<const char[]> rhsStr{rhsFormatter(rhs)};

const std::unique_ptr<const char[]> actual{orderFormatter(actualOrder)};
const std::unique_ptr<const char[]> expected{orderFormatter(expectedOrder)};
const std::unique_ptr<const char[]> actual{actualOrderFormatter(actualOrder)};
const std::unique_ptr<const char[]> expected{expectedOrderFormatter(expectedOrder)};

if (!failureMessage)
failureMessage = failureMessageForOp(QTest::ComparisonOperation::ThreeWayCompare);
Expand Down
3 changes: 2 additions & 1 deletion src/testlib/qtestresult_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class Q_TESTLIB_EXPORT QTestResult
const char *(*lhsFormatter)(const void *),
const char *(*rhsFormatter)(const void *),
const char *lhsExpression, const char *rhsExpression,
const char *(*orderFormatter)(const void *),
const char *(*actualOrderFormatter)(const void *),
const char *(*expectedOrderFormatter)(const void *),
const void *actualOrder, const void *expectedOrder,
const char *expectedExpression,
const char *file, int line);
Expand Down
34 changes: 17 additions & 17 deletions tests/auto/testlib/selftests/expected_threewaycompare.junitxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 1
Right (rhs): 2
Actual (lhs <=> rhs) : Qt::strong_ordering::less
Actual (lhs <=> rhs) : std::strong_ordering::less
Expected (expectedOrder): Qt::strong_ordering::equal]]>
</failure>
</testcase>
<testcase name="compareInts(Qt::strong_ordering::greater)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 2
Right (rhs): 1
Actual (lhs <=> rhs) : Qt::strong_ordering::greater
Actual (lhs <=> rhs) : std::strong_ordering::greater
Expected (expectedOrder): Qt::strong_ordering::equal]]>
</failure>
</testcase>
<testcase name="compareFloats(Qt::partial_ordering::equivalent)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 1
Right (rhs): 1
Actual (lhs <=> rhs) : Qt::partial_ordering::equivalent
Actual (lhs <=> rhs) : std::partial_ordering::equivalent
Expected (expectedOrder): Qt::partial_ordering::less]]>
</failure>
</testcase>
Expand All @@ -36,23 +36,23 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 1.1
Right (rhs): 1
Actual (lhs <=> rhs) : Qt::partial_ordering::greater
Actual (lhs <=> rhs) : std::partial_ordering::greater
Expected (expectedOrder): Qt::partial_ordering::less]]>
</failure>
</testcase>
<testcase name="compareDoubles(Qt::partial_ordering::equivalent)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 0
Right (rhs): 0
Actual (lhs <=> rhs) : Qt::partial_ordering::equivalent
Actual (lhs <=> rhs) : std::partial_ordering::equivalent
Expected (expectedOrder): Qt::partial_ordering::greater]]>
</failure>
</testcase>
<testcase name="compareDoubles(Qt::partial_ordering::less)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 0
Right (rhs): 0.1
Actual (lhs <=> rhs) : Qt::partial_ordering::less
Actual (lhs <=> rhs) : std::partial_ordering::less
Expected (expectedOrder): Qt::partial_ordering::greater]]>
</failure>
</testcase>
Expand All @@ -62,15 +62,15 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 1
Right (rhs): 2
Actual (lhs <=> rhs) : Qt::strong_ordering::less
Actual (lhs <=> rhs) : std::strong_ordering::less
Expected (expectedOrder): Qt::strong_ordering::equal]]>
</failure>
</testcase>
<testcase name="comparePointers(Qt::strong_ordering::greater)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 2
Right (rhs): 1
Actual (lhs <=> rhs) : Qt::strong_ordering::greater
Actual (lhs <=> rhs) : std::strong_ordering::greater
Expected (expectedOrder): Qt::strong_ordering::equal]]>
</failure>
</testcase>
Expand All @@ -79,23 +79,23 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): "nullptr"
Right (rhs): 1
Actual (lhs <=> rhs) : Qt::strong_ordering::less
Actual (lhs <=> rhs) : std::strong_ordering::less
Expected (expectedOrder): Qt::strong_ordering::equal]]>
</failure>
</testcase>
<testcase name="compareToNullptr(Qt::strong_ordering::greater)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 1
Right (rhs): "nullptr"
Actual (lhs <=> rhs) : Qt::strong_ordering::greater
Actual (lhs <=> rhs) : std::strong_ordering::greater
Expected (expectedOrder): Qt::strong_ordering::equal]]>
</failure>
</testcase>
<testcase name="compareUnregisteredEnum(Qt::strong_ordering::equivalent)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 0
Right (rhs): 0
Actual (lhs <=> rhs) : Qt::strong_ordering::equal
Actual (lhs <=> rhs) : std::strong_ordering::equal
Expected (expectedOrder): Qt::strong_ordering::less]]>
</failure>
</testcase>
Expand All @@ -104,23 +104,23 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): 1
Right (rhs): 0
Actual (lhs <=> rhs) : Qt::strong_ordering::greater
Actual (lhs <=> rhs) : std::strong_ordering::greater
Expected (expectedOrder): Qt::strong_ordering::less]]>
</failure>
</testcase>
<testcase name="compareRegisteredEnum(Qt::strong_ordering::equivalent)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): Monday
Right (rhs): Monday
Actual (lhs <=> rhs) : Qt::strong_ordering::equal
Actual (lhs <=> rhs) : std::strong_ordering::equal
Expected (expectedOrder): Qt::strong_ordering::greater]]>
</failure>
</testcase>
<testcase name="compareRegisteredEnum(Qt::strong_ordering::less)" classname="tst_ThreeWayCompare" time="@TEST_DURATION@">
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): Monday
Right (rhs): Sunday
Actual (lhs <=> rhs) : Qt::strong_ordering::less
Actual (lhs <=> rhs) : std::strong_ordering::less
Expected (expectedOrder): Qt::strong_ordering::greater]]>
</failure>
</testcase>
Expand All @@ -129,7 +129,7 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): MyClass(1)
Right (rhs): MyClass(1)
Actual (lhs <=> rhs) : Qt::strong_ordering::equal
Actual (lhs <=> rhs) : std::strong_ordering::equal
Expected (expectedOrder): Qt::strong_ordering::less]]>
</failure>
</testcase>
Expand All @@ -138,7 +138,7 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (lhs): MyClass(2)
Right (rhs): MyClass(1)
Actual (lhs <=> rhs) : Qt::strong_ordering::greater
Actual (lhs <=> rhs) : std::strong_ordering::greater
Expected (expectedOrder): Qt::strong_ordering::less]]>
</failure>
</testcase>
Expand Down Expand Up @@ -290,7 +290,7 @@
<failure type="fail" message="The result of operator&lt;=&gt;() is not what was expected">
<![CDATA[ Left (june) : 2012/06/20 14:33:02.500[CEST]
Right (juneLater): 2012/06/20 14:33:02.501[CEST]
Actual (june <=> juneLater) : Qt::weak_ordering::less
Actual (june <=> juneLater) : std::weak_ordering::less
Expected (Qt::weak_ordering::greater): Qt::weak_ordering::greater]]>
</failure>
</testcase>
Expand Down
Loading

0 comments on commit 69315d6

Please sign in to comment.