summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <[email protected]>2024-10-03 22:57:03 -0700
committerThiago Macieira <[email protected]>2024-10-30 13:15:51 -0700
commit627f804d80d76cb729b84dc319382213cd89763c (patch)
tree51fed3405b722a90d6b135ff038339ead54d6a71
parentdf040fb1115071fbea80213814b7dc34b17ba085 (diff)
QTest: fix debug-printing of arrays
Namely, string literals (char[n], char16_t[n]). Amends commit 0756cc1eae5fd8981983319fef1d084762a67b8d. I had to use the std::decay_t in that commit because the cast would fail to compile. But I didn't check that it was correct: std::addressof() will return the address of the first element for an array, which meant the cast would make a pointer of the string's contents and crash. Pick-to: 6.8 Change-Id: I701ae76be9b3340db49afffd9132b6c6dbae660b Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r--src/testlib/qtestcase.h18
-rw-r--r--tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp23
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.junitxml8
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.lightxml43
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.tap224
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.teamcity17
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.txt34
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xml43
-rw-r--r--tests/auto/testlib/selftests/tst_selftests.cpp16
9 files changed, 347 insertions, 79 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 75a51992d28..6e7be04ba0a 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -621,19 +621,17 @@ namespace QTest
inline bool qCompare(const T1 &t1, const T2 &t2, const char *actual, const char *expected,
const char *file, int line)
{
- using D1 = std::decay_t<T1>;
- using D2 = std::decay_t<T2>;
using Internal::genericToString;
if constexpr (QtPrivate::is_standard_or_extended_integer_type_v<T1>
&& QtPrivate::is_standard_or_extended_integer_type_v<T2>) {
return compare_helper(q20::cmp_equal(t1, t2), "Compared values are not the same",
std::addressof(t1), std::addressof(t2),
- genericToString<D1>, genericToString<D2>,
+ genericToString<T1>, genericToString<T2>,
actual, expected, file, line);
} else {
return compare_helper(t1 == t2, "Compared values are not the same",
std::addressof(t1), std::addressof(t2),
- genericToString<D1>, genericToString<D2>,
+ genericToString<T1>, genericToString<T2>,
actual, expected, file, line);
}
}
@@ -745,12 +743,16 @@ namespace QTest
using Internal::genericToString;
using Comparator = Internal::Compare<op>;
+ // force decaying of T1 and T2
+ auto doReport = [&](bool result, const D1 &lhs_, const D2 &rhs_) {
+ return reportResult(result, std::addressof(lhs_), std::addressof(rhs_),
+ genericToString<D1>, genericToString<D2>,
+ lhsExpr, rhsExpr, op, file, line);
+ };
+
/* assumes that op does not actually move from lhs and rhs */
bool result = Comparator::compare(std::forward<T1>(lhs), std::forward<T2>(rhs));
- return reportResult(result, std::addressof(lhs), std::addressof(rhs),
- genericToString<D1>, genericToString<D2>,
- lhsExpr, rhsExpr, op, file, line);
-
+ return doReport(result, std::forward<T1>(lhs), std::forward<T2>(rhs));
}
}
diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
index 36e355c614e..df8dc9f9c95 100644
--- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
@@ -116,6 +116,7 @@ private slots:
void compare_boolfuncs();
void compare_to_nullptr();
void compare_pointerfuncs();
+ void compare_stringLiterals();
void compare_tostring();
void compare_tostring_data();
void compare_unknown();
@@ -287,6 +288,28 @@ void tst_Cmptest::compareQObjects()
QCOMPARE(nullptr, &object2);
}
+void tst_Cmptest::compare_stringLiterals()
+{
+ const QString lhs = QStringLiteral("abc");
+
+ // We don't want to put those into test data since we want to specifically test comparison
+ // against inline string literals.
+
+ [&]() { QCOMPARE(lhs, u""); }();
+ [&]() { QCOMPARE_EQ(lhs, u""); }();
+ [&]() { QCOMPARE(lhs, u"abc"); }();
+ [&]() { QCOMPARE_EQ(lhs, u"abc"); }();
+ [&]() { QCOMPARE(lhs, u"abcd"); }();
+ [&]() { QCOMPARE_EQ(lhs, u"abcd"); }();
+
+ [&]() { QCOMPARE(lhs, ""); }();
+ [&]() { QCOMPARE_EQ(lhs, ""); }();
+ [&]() { QCOMPARE(lhs, "abc"); }();
+ [&]() { QCOMPARE_EQ(lhs, "abc"); }();
+ [&]() { QCOMPARE(lhs, "abcd"); }();
+ [&]() { QCOMPARE_EQ(lhs, "abcd"); }();
+}
+
struct PhonyClass
{
int i;
diff --git a/tests/auto/testlib/selftests/expected_cmptest.junitxml b/tests/auto/testlib/selftests/expected_cmptest.junitxml
index 134a188753f..75c0c064285 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.junitxml
+++ b/tests/auto/testlib/selftests/expected_cmptest.junitxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<testsuite name="tst_Cmptest" timestamp="@TEST_START_TIME@" hostname="@HOSTNAME@" tests="74" failures="51" errors="0" skipped="0" time="@TEST_DURATION@">
+<testsuite name="tst_Cmptest" timestamp="@TEST_START_TIME@" hostname="@HOSTNAME@" tests="75" failures="52" errors="0" skipped="0" time="@TEST_DURATION@">
<properties>
<property name="QTestVersion" value="@INSERT_QT_VERSION_HERE@"/>
<property name="QtVersion" value="@INSERT_QT_VERSION_HERE@"/>
@@ -53,6 +53,12 @@
<testcase name="compare_boolfuncs" classname="tst_Cmptest" time="@TEST_DURATION@"/>
<testcase name="compare_to_nullptr" classname="tst_Cmptest" time="@TEST_DURATION@"/>
<testcase name="compare_pointerfuncs" classname="tst_Cmptest" time="@TEST_DURATION@"/>
+ <testcase name="compare_stringLiterals" classname="tst_Cmptest" time="@TEST_DURATION@">
+ <failure type="fail" message="Compared values are not the same">
+ <![CDATA[ Actual (lhs): "abc"
+ Expected (u""): ]]>
+ </failure>
+ </testcase>
<testcase name="compare_tostring(int, string)" classname="tst_Cmptest" time="@TEST_DURATION@">
<failure type="fail" message="Compared values are not the same">
<![CDATA[ Actual (actual) : QVariant(int,123)
diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml
index 9c54d206500..8d10234490c 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.lightxml
+++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml
@@ -79,6 +79,49 @@
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
</TestFunction>
+ <TestFunction name="compare_stringLiterals">
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs): "abc"
+ Expected (u""): ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs): "abc"
+ Baseline (u""): ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs) : "abc"
+ Expected (u"abcd"): abcd]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs) : "abc"
+ Baseline (u"abcd"): abcd]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs): "abc"
+ Expected ("") : ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs): "abc"
+ Baseline ("") : ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs) : "abc"
+ Expected ("abcd"): abcd]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs) : "abc"
+ Baseline ("abcd"): abcd]]></Description>
+ </Incident>
+ <Duration msecs="0"/>
+ </TestFunction>
<TestFunction name="compare_tostring">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
<DataTag><![CDATA[int, string]]></DataTag>
diff --git a/tests/auto/testlib/selftests/expected_cmptest.tap b/tests/auto/testlib/selftests/expected_cmptest.tap
index a5f5c3c8a27..2236bc54031 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.tap
+++ b/tests/auto/testlib/selftests/expected_cmptest.tap
@@ -90,7 +90,103 @@ not ok 10 - test_unregistered_flags(fail2)
ok 11 - compare_boolfuncs()
ok 12 - compare_to_nullptr()
ok 13 - compare_pointerfuncs()
-not ok 14 - compare_tostring(int, string)
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE
+ message: Compared values are not the same
+ wanted: (u"")
+ found: "abc" (lhs)
+ expected: (u"")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE_EQ
+ message: The computed value is expected to be equal to the baseline, but is not
+ wanted: == (u"")
+ found: "abc" (lhs)
+ expected: == (u"")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE
+ message: Compared values are not the same
+ wanted: abcd (u"abcd")
+ found: "abc" (lhs)
+ expected: abcd (u"abcd")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE_EQ
+ message: The computed value is expected to be equal to the baseline, but is not
+ wanted: == abcd (u"abcd")
+ found: "abc" (lhs)
+ expected: == abcd (u"abcd")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE
+ message: Compared values are not the same
+ wanted: ("")
+ found: "abc" (lhs)
+ expected: ("")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE_EQ
+ message: The computed value is expected to be equal to the baseline, but is not
+ wanted: == ("")
+ found: "abc" (lhs)
+ expected: == ("")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE
+ message: Compared values are not the same
+ wanted: abcd ("abcd")
+ found: "abc" (lhs)
+ expected: abcd ("abcd")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 14 - compare_stringLiterals()
+ ---
+ type: QCOMPARE_EQ
+ message: The computed value is expected to be equal to the baseline, but is not
+ wanted: == abcd ("abcd")
+ found: "abc" (lhs)
+ expected: == abcd ("abcd")
+ actual: "abc" (lhs)
+ at: tst_Cmptest::compare_stringLiterals() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+ line: 0
+ ...
+not ok 15 - compare_tostring(int, string)
---
type: QCOMPARE
message: Compared values are not the same
@@ -102,8 +198,8 @@ not ok 14 - compare_tostring(int, string)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 15 - compare_tostring(both invalid)
-not ok 16 - compare_tostring(null hash, invalid)
+ok 16 - compare_tostring(both invalid)
+not ok 17 - compare_tostring(null hash, invalid)
---
type: QCOMPARE
message: Compared values are not the same
@@ -115,7 +211,7 @@ not ok 16 - compare_tostring(null hash, invalid)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 17 - compare_tostring(string, null user type)
+not ok 18 - compare_tostring(string, null user type)
---
type: QCOMPARE
message: Compared values are not the same
@@ -127,7 +223,7 @@ not ok 17 - compare_tostring(string, null user type)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 18 - compare_tostring(both non-null user type)
+not ok 19 - compare_tostring(both non-null user type)
---
type: QCOMPARE
message: Compared values are not the same
@@ -139,7 +235,7 @@ not ok 18 - compare_tostring(both non-null user type)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 19 - compare_unknown()
+not ok 20 - compare_unknown()
---
# Compared values are not the same
Actual : a
@@ -148,7 +244,7 @@ not ok 19 - compare_unknown()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 20 - compare_textFromDebug()
+not ok 21 - compare_textFromDebug()
---
type: QCOMPARE
message: Compared values are not the same
@@ -160,7 +256,7 @@ not ok 20 - compare_textFromDebug()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 21 - compareQObjects()
+not ok 22 - compareQObjects()
---
type: QCOMPARE
message: Compared QObject pointers are not the same
@@ -172,9 +268,9 @@ not ok 21 - compareQObjects()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 22 - compareQStringLists(empty lists)
-ok 23 - compareQStringLists(equal lists)
-not ok 24 - compareQStringLists(last item different)
+ok 23 - compareQStringLists(empty lists)
+ok 24 - compareQStringLists(equal lists)
+not ok 25 - compareQStringLists(last item different)
---
type: QCOMPARE
message: Compared lists differ at index 2.
@@ -186,7 +282,7 @@ not ok 24 - compareQStringLists(last item different)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 25 - compareQStringLists(second-last item different)
+not ok 26 - compareQStringLists(second-last item different)
---
type: QCOMPARE
message: Compared lists differ at index 2.
@@ -198,7 +294,7 @@ not ok 25 - compareQStringLists(second-last item different)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 26 - compareQStringLists(prefix)
+not ok 27 - compareQStringLists(prefix)
---
# Compared lists have different sizes.
Actual (opA) size: 2
@@ -207,7 +303,7 @@ not ok 26 - compareQStringLists(prefix)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 27 - compareQStringLists(short list second)
+not ok 28 - compareQStringLists(short list second)
---
# Compared lists have different sizes.
Actual (opA) size: 12
@@ -216,7 +312,7 @@ not ok 27 - compareQStringLists(short list second)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 28 - compareQStringLists(short list first)
+not ok 29 - compareQStringLists(short list first)
---
# Compared lists have different sizes.
Actual (opA) size: 1
@@ -225,8 +321,8 @@ not ok 28 - compareQStringLists(short list first)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 29 - compareQListInt(match)
-not ok 30 - compareQListInt(size mismatch)
+ok 30 - compareQListInt(match)
+not ok 31 - compareQListInt(size mismatch)
---
# Compared lists have different sizes.
Actual (actual) size: 2
@@ -235,7 +331,7 @@ not ok 30 - compareQListInt(size mismatch)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 31 - compareQListInt(value mismatch)
+not ok 32 - compareQListInt(value mismatch)
---
type: QCOMPARE
message: Compared lists differ at index 2.
@@ -247,8 +343,8 @@ not ok 31 - compareQListInt(value mismatch)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 32 - compareQListIntToArray(match)
-not ok 33 - compareQListIntToArray(size mismatch)
+ok 33 - compareQListIntToArray(match)
+not ok 34 - compareQListIntToArray(size mismatch)
---
# Compared lists have different sizes.
Actual (actual) size: 2
@@ -257,7 +353,7 @@ not ok 33 - compareQListIntToArray(size mismatch)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 34 - compareQListIntToArray(value mismatch)
+not ok 35 - compareQListIntToArray(value mismatch)
---
type: QCOMPARE
message: Compared lists differ at index 2.
@@ -269,8 +365,8 @@ not ok 34 - compareQListIntToArray(value mismatch)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 35 - compareQListIntToInitializerList(match)
-not ok 36 - compareQListIntToInitializerList(size mismatch)
+ok 36 - compareQListIntToInitializerList(match)
+not ok 37 - compareQListIntToInitializerList(size mismatch)
---
# Compared lists have different sizes.
Actual (actual) size: 2
@@ -279,7 +375,7 @@ not ok 36 - compareQListIntToInitializerList(size mismatch)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 37 - compareQListIntToInitializerList(value mismatch)
+not ok 38 - compareQListIntToInitializerList(value mismatch)
---
type: QCOMPARE
message: Compared lists differ at index 2.
@@ -291,7 +387,7 @@ not ok 37 - compareQListIntToInitializerList(value mismatch)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 38 - compareQListDouble()
+not ok 39 - compareQListDouble()
---
type: QCOMPARE
message: Compared lists differ at index 0.
@@ -303,9 +399,9 @@ not ok 38 - compareQListDouble()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 39 - compareContainerToInitializerList()
-ok 40 - compareQColor(Qt::yellow vs "yellow")
-not ok 41 - compareQColor(Qt::yellow vs Qt::green)
+ok 40 - compareContainerToInitializerList()
+ok 41 - compareQColor(Qt::yellow vs "yellow")
+not ok 42 - compareQColor(Qt::yellow vs Qt::green)
---
type: QCOMPARE
message: Compared values are not the same
@@ -317,7 +413,7 @@ not ok 41 - compareQColor(Qt::yellow vs Qt::green)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 42 - compareQColor(0x88ff0000 vs 0xffff0000)
+not ok 43 - compareQColor(0x88ff0000 vs 0xffff0000)
---
type: QCOMPARE
message: Compared values are not the same
@@ -329,8 +425,8 @@ not ok 42 - compareQColor(0x88ff0000 vs 0xffff0000)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 43 - compareQPixmaps(both null)
-not ok 44 - compareQPixmaps(one null)
+ok 44 - compareQPixmaps(both null)
+not ok 45 - compareQPixmaps(one null)
---
type: QCOMPARE
message: Compared QPixmaps differ.
@@ -342,7 +438,7 @@ not ok 44 - compareQPixmaps(one null)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 45 - compareQPixmaps(other null)
+not ok 46 - compareQPixmaps(other null)
---
type: QCOMPARE
message: Compared QPixmaps differ.
@@ -354,8 +450,8 @@ not ok 45 - compareQPixmaps(other null)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 46 - compareQPixmaps(equal)
-not ok 47 - compareQPixmaps(different size)
+ok 47 - compareQPixmaps(equal)
+not ok 48 - compareQPixmaps(different size)
---
type: QCOMPARE
message: Compared QPixmaps differ in size.
@@ -367,14 +463,14 @@ not ok 47 - compareQPixmaps(different size)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 48 - compareQPixmaps(different pixels)
+not ok 49 - compareQPixmaps(different pixels)
---
# Compared values are not the same
at: tst_Cmptest::compareQPixmaps() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 49 - compareQPixmaps(different dpr)
+not ok 50 - compareQPixmaps(different dpr)
---
type: QCOMPARE
message: Compared QPixmaps differ in device pixel ratio.
@@ -386,8 +482,8 @@ not ok 49 - compareQPixmaps(different dpr)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 50 - compareQImages(both null)
-not ok 51 - compareQImages(one null)
+ok 51 - compareQImages(both null)
+not ok 52 - compareQImages(one null)
---
type: QCOMPARE
message: Compared QImages differ.
@@ -399,7 +495,7 @@ not ok 51 - compareQImages(one null)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 52 - compareQImages(other null)
+not ok 53 - compareQImages(other null)
---
type: QCOMPARE
message: Compared QImages differ.
@@ -411,8 +507,8 @@ not ok 52 - compareQImages(other null)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 53 - compareQImages(equal)
-not ok 54 - compareQImages(different size)
+ok 54 - compareQImages(equal)
+not ok 55 - compareQImages(different size)
---
type: QCOMPARE
message: Compared QImages differ in size.
@@ -424,7 +520,7 @@ not ok 54 - compareQImages(different size)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 55 - compareQImages(different format)
+not ok 56 - compareQImages(different format)
---
type: QCOMPARE
message: Compared QImages differ in format.
@@ -436,14 +532,14 @@ not ok 55 - compareQImages(different format)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 56 - compareQImages(different pixels)
+not ok 57 - compareQImages(different pixels)
---
# Compared values are not the same
at: tst_Cmptest::compareQImages() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 57 - compareQImages(different dpr)
+not ok 58 - compareQImages(different dpr)
---
type: QCOMPARE
message: Compared QImages differ in device pixel ratio.
@@ -455,8 +551,8 @@ not ok 57 - compareQImages(different dpr)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 58 - compareQRegion(equal-empty)
-not ok 59 - compareQRegion(1-empty)
+ok 59 - compareQRegion(equal-empty)
+not ok 60 - compareQRegion(1-empty)
---
type: QCOMPARE
message: Compared values are not the same
@@ -468,8 +564,8 @@ not ok 59 - compareQRegion(1-empty)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 60 - compareQRegion(equal)
-not ok 61 - compareQRegion(different lists)
+ok 61 - compareQRegion(equal)
+not ok 62 - compareQRegion(different lists)
---
type: QCOMPARE
message: Compared values are not the same
@@ -481,7 +577,7 @@ not ok 61 - compareQRegion(different lists)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 62 - compareQVector2D()
+not ok 63 - compareQVector2D()
---
type: QCOMPARE
message: Compared values are not the same
@@ -493,7 +589,7 @@ not ok 62 - compareQVector2D()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 63 - compareQVector3D()
+not ok 64 - compareQVector3D()
---
type: QCOMPARE
message: Compared values are not the same
@@ -505,7 +601,7 @@ not ok 63 - compareQVector3D()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 64 - compareQVector4D()
+not ok 65 - compareQVector4D()
---
type: QCOMPARE
message: Compared values are not the same
@@ -517,7 +613,7 @@ not ok 64 - compareQVector4D()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 65 - compareQPalettes(all roles are different)
+not ok 66 - compareQPalettes(all roles are different)
---
type: QCOMPARE
message: Compared values are not the same
@@ -529,7 +625,7 @@ not ok 65 - compareQPalettes(all roles are different)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 66 - compareQPalettes(one role is different)
+not ok 67 - compareQPalettes(one role is different)
---
type: QCOMPARE
message: Compared values are not the same
@@ -541,8 +637,8 @@ not ok 66 - compareQPalettes(one role is different)
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 67 - compareQPalettes(all roles are the same)
-not ok 68 - tryCompare()
+ok 68 - compareQPalettes(all roles are the same)
+not ok 69 - tryCompare()
---
type: QCOMPARE
message: Compared values are not the same
@@ -558,7 +654,7 @@ not ok 68 - tryCompare()
- severity: info
message: Should now time out and fail
...
-not ok 69 - verify()
+not ok 70 - verify()
---
type: QVERIFY
message: Verification failed
@@ -570,7 +666,7 @@ not ok 69 - verify()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 70 - verify2()
+not ok 71 - verify2()
---
type: QVERIFY
message: 42 >= 2 (as expected, in fact)
@@ -582,7 +678,7 @@ not ok 70 - verify2()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-not ok 71 - tryVerify()
+not ok 72 - tryVerify()
---
type: QVERIFY
message: Verification failed
@@ -598,7 +694,7 @@ not ok 71 - tryVerify()
- severity: info
message: Should now time out and fail
...
-not ok 72 - tryVerify2()
+not ok 73 - tryVerify2()
---
type: QVERIFY
message: Should time out and fail
@@ -610,9 +706,9 @@ not ok 72 - tryVerify2()
file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
line: 0
...
-ok 73 - verifyExplicitOperatorBool()
-ok 74 - cleanupTestCase()
-1..74
-# tests 74
+ok 74 - verifyExplicitOperatorBool()
+ok 75 - cleanupTestCase()
+1..75
+# tests 75
# pass 23
-# fail 51
+# fail 52
diff --git a/tests/auto/testlib/selftests/expected_cmptest.teamcity b/tests/auto/testlib/selftests/expected_cmptest.teamcity
index b5ff6754657..c610eb0089a 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.teamcity
+++ b/tests/auto/testlib/selftests/expected_cmptest.teamcity
@@ -32,6 +32,23 @@
##teamcity[testFinished name='compare_to_nullptr()' flowId='tst_Cmptest']
##teamcity[testStarted name='compare_pointerfuncs()' flowId='tst_Cmptest']
##teamcity[testFinished name='compare_pointerfuncs()' flowId='tst_Cmptest']
+##teamcity[testStarted name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (lhs): "abc"|n Expected (u""):' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='The computed value is expected to be equal to the baseline, but is not|n Computed (lhs): "abc"|n Baseline (u""):' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (lhs) : "abc"|n Expected (u"abcd"): abcd' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='The computed value is expected to be equal to the baseline, but is not|n Computed (lhs) : "abc"|n Baseline (u"abcd"): abcd' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (lhs): "abc"|n Expected ("") :' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='The computed value is expected to be equal to the baseline, but is not|n Computed (lhs): "abc"|n Baseline ("") :' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (lhs) : "abc"|n Expected ("abcd"): abcd' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
+##teamcity[testFailed name='compare_stringLiterals()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='The computed value is expected to be equal to the baseline, but is not|n Computed (lhs) : "abc"|n Baseline ("abcd"): abcd' flowId='tst_Cmptest']
+##teamcity[testFinished name='compare_stringLiterals()' flowId='tst_Cmptest']
##teamcity[testStarted name='compare_tostring(int, string)' flowId='tst_Cmptest']
##teamcity[testFailed name='compare_tostring(int, string)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (actual) : QVariant(int,123)|n Expected (expected): QVariant(QString,hi)' flowId='tst_Cmptest']
##teamcity[testFinished name='compare_tostring(int, string)' flowId='tst_Cmptest']
diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt
index ff81a463975..042625243c0 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.txt
+++ b/tests/auto/testlib/selftests/expected_cmptest.txt
@@ -34,6 +34,38 @@ FAIL! : tst_Cmptest::test_unregistered_flags(fail2) Compared values are not the
PASS : tst_Cmptest::compare_boolfuncs()
PASS : tst_Cmptest::compare_to_nullptr()
PASS : tst_Cmptest::compare_pointerfuncs()
+FAIL! : tst_Cmptest::compare_stringLiterals() Compared values are not the same
+ Actual (lhs): "abc"
+ Expected (u""):
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs): "abc"
+ Baseline (u""):
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() Compared values are not the same
+ Actual (lhs) : "abc"
+ Expected (u"abcd"): abcd
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs) : "abc"
+ Baseline (u"abcd"): abcd
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() Compared values are not the same
+ Actual (lhs): "abc"
+ Expected ("") :
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs): "abc"
+ Baseline ("") :
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() Compared values are not the same
+ Actual (lhs) : "abc"
+ Expected ("abcd"): abcd
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compare_stringLiterals() The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs) : "abc"
+ Baseline ("abcd"): abcd
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
FAIL! : tst_Cmptest::compare_tostring(int, string) Compared values are not the same
Actual (actual) : QVariant(int,123)
Expected (expected): QVariant(QString,hi)
@@ -217,5 +249,5 @@ FAIL! : tst_Cmptest::tryVerify2() '!c' returned FALSE. (Should time out and fai
Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
PASS : tst_Cmptest::verifyExplicitOperatorBool()
PASS : tst_Cmptest::cleanupTestCase()
-Totals: 23 passed, 51 failed, 0 skipped, 0 blacklisted, 0ms
+Totals: 23 passed, 52 failed, 0 skipped, 0 blacklisted, 0ms
********* Finished testing of tst_Cmptest *********
diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml
index df4d8b28be2..e34c38e5bc9 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.xml
+++ b/tests/auto/testlib/selftests/expected_cmptest.xml
@@ -81,6 +81,49 @@
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
</TestFunction>
+ <TestFunction name="compare_stringLiterals">
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs): "abc"
+ Expected (u""): ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs): "abc"
+ Baseline (u""): ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs) : "abc"
+ Expected (u"abcd"): abcd]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs) : "abc"
+ Baseline (u"abcd"): abcd]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs): "abc"
+ Expected ("") : ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs): "abc"
+ Baseline ("") : ]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[Compared values are not the same
+ Actual (lhs) : "abc"
+ Expected ("abcd"): abcd]]></Description>
+ </Incident>
+ <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <Description><![CDATA[The computed value is expected to be equal to the baseline, but is not
+ Computed (lhs) : "abc"
+ Baseline ("abcd"): abcd]]></Description>
+ </Incident>
+ <Duration msecs="0"/>
+ </TestFunction>
<TestFunction name="compare_tostring">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
<DataTag><![CDATA[int, string]]></DataTag>
diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp
index eda3d9afc7c..2d799a04c85 100644
--- a/tests/auto/testlib/selftests/tst_selftests.cpp
+++ b/tests/auto/testlib/selftests/tst_selftests.cpp
@@ -27,6 +27,8 @@ QT_REQUIRE_CONFIG(process);
using namespace Qt::StringLiterals;
+enum class Throw { OnFail = 1 };
+
struct BenchmarkResult
{
qint64 total;
@@ -622,7 +624,7 @@ struct TestLogger
return outputFile.readAll();
}
- bool shouldIgnoreTest(const QString &test) const;
+ bool shouldIgnoreTest(const QString &test, Throw throwing) const;
operator QTestLog::LogMode() const { return logger; }
@@ -631,13 +633,19 @@ struct TestLogger
ArgumentStyle argumentStyle = NewStyleArgument;
};
-bool TestLogger::shouldIgnoreTest(const QString &test) const
+bool TestLogger::shouldIgnoreTest(const QString &test, Throw throwing) const
{
#if defined(QT_USE_APPLE_UNIFIED_LOGGING)
if (logger == QTestLog::Apple)
return true;
#endif
+ if (throwing == Throw::OnFail && test == "cmptest") {
+ // This test requires continuing the same test function after failure,
+ // so the output is different with this flag.
+ return true;
+ }
+
if (!qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY")) {
qDebug() << "TestLogger::shouldIgnoreTest() ignore" << test << "on wayland/xwayland!";
return true;
@@ -1025,8 +1033,6 @@ TestProcessResult runTestProcess(const QString &test, const QStringList &argumen
return { process.exitCode(), standardOutput, standardError };
}
-enum class Throw { OnFail = 1 };
-
/*
Runs a single test and verifies the output against the expected results.
*/
@@ -1034,7 +1040,7 @@ void runTest(const QString &test, const TestLoggers &requestedLoggers, Throw thr
{
TestLoggers loggers;
for (auto logger : requestedLoggers) {
- if (!logger.shouldIgnoreTest(test))
+ if (!logger.shouldIgnoreTest(test, throwing))
loggers += logger;
}