summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-07-09 17:01:38 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-07-13 15:14:35 +0200
commit92e696b4bad52c40c6cdc1c5bf7c0c0ea8a2b283 (patch)
treedd87bef36f4b7a06d395237ee0a66b816d6598ca /tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
parent3fee97c4ab0796fcafcdea692ff7c7e83005a2aa (diff)
Use debug stream in QTest::toString's default fallback if possible
For built-in types, this is a compile-time assert - we should not have any types in Qt for which we have neither debug streaming nor a QTest::toString specialization implemented. A build of most of Qt submodules passes with this change, after minor modifications to some tests. We cannot declare QSizeHint::Policy as a metatype after the QMetaType has already been instantiated for it, and the QDebug stream operator for QElaspedTimer needs to be correctly declared within the namespace. Add a self-test function for a custom type, and update reference files of the self-test. Task-number: QTBUG-104867 Pick-to: 6.4 Change-Id: I2936db5933f4589fce45f47cf2f3224ed614d8c9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp')
-rw-r--r--tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
index 5842d7b3b1..94c04157f2 100644
--- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
@@ -115,6 +115,7 @@ private slots:
void compare_tostring();
void compare_tostring_data();
void compare_unknown();
+ void compare_textFromDebug();
void compareQObjects();
void compareQStringLists();
void compareQStringLists_data();
@@ -324,10 +325,36 @@ void tst_Cmptest::compare_tostring()
QCOMPARE(actual, expected);
}
+struct UnknownType
+{
+ int value;
+ bool operator==(const UnknownType &rhs) const { return value == rhs.value; }
+};
+
void tst_Cmptest::compare_unknown()
{
- std::string a("a");
- std::string b("b");
+ UnknownType a{1};
+ UnknownType b{2};
+
+ QCOMPARE(a, b);
+}
+
+struct CustomType
+{
+ int value;
+ bool operator==(const CustomType &rhs) const { return value == rhs.value; }
+};
+
+QDebug operator<<(QDebug dbg, const CustomType &val)
+{
+ dbg << "QDebug stream: " << val.value;
+ return dbg;
+}
+
+void tst_Cmptest::compare_textFromDebug()
+{
+ CustomType a{0};
+ CustomType b{1};
QCOMPARE(a, b);
}