summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2024-02-19 18:29:48 +0100
committerIvan Solovev <ivan.solovev@qt.io>2024-03-02 00:12:53 +0100
commit42b6fdfb523f47ba711138bb299d97823e7c64d2 (patch)
treeecce14e5fe4fe52e00a231e37d082e158cb0b794 /tests
parent755581e2e78f017f2c783a637ddb2ab9108b083b (diff)
QString: use comparison helper macros - comparison with byte arrays [2/3]
Use the comparison helper macros to replace the member relational operators for comparison with QByteArray and const char *. As QString and QByteArray are exported, we cannot simply remove the inline methods, so wrap them into QT_CORE_REMOVED_SINCE. Add relational operators with QByteArrayView. Provide more unit-tests for the comparison with the byte array types. This enables operator<=> for QString vs byte arrays in C++20 builds. Task-number: QTBUG-117661 Change-Id: I305343e1b6c5d78b10f2976573db4e904ba6b44b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp16
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp1
2 files changed, 16 insertions, 1 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 6aaa8bc813..ae7a80dcc6 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -8041,6 +8041,11 @@ void tst_QString::comparisonCompiles()
QTestPrivate::testAllComparisonOperatorsCompile<QString, QChar>();
QTestPrivate::testAllComparisonOperatorsCompile<QString, QLatin1StringView>();
QTestPrivate::testAllComparisonOperatorsCompile<QString, const char16_t *>();
+#if !defined(QT_RESTRICTED_CAST_FROM_ASCII) && !defined(QT_NO_CAST_FROM_ASCII)
+ QTestPrivate::testAllComparisonOperatorsCompile<QString, QByteArrayView>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QString, QByteArray>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QString, const char *>();
+#endif
}
void tst_QString::compare_data()
@@ -8268,6 +8273,17 @@ void tst_QString::comparisonMacros()
const QLatin1StringView l1s2{ba};
QT_TEST_ALL_COMPARISON_OPS(s1, l1s2, expectedOrdering);
}
+
+ const QByteArray u8s2 = s2.toUtf8();
+#if !defined(QT_RESTRICTED_CAST_FROM_ASCII) && !defined(QT_NO_CAST_FROM_ASCII)
+ QT_TEST_ALL_COMPARISON_OPS(s1, u8s2, expectedOrdering);
+ const QByteArrayView u8s2view{u8s2.begin(), u8s2.size()};
+ QT_TEST_ALL_COMPARISON_OPS(s1, u8s2view, expectedOrdering);
+ if (!s2.contains(QChar(u'\0'))) {
+ const char *u8data = u8s2.constData();
+ QT_TEST_ALL_COMPARISON_OPS(s1, u8data, expectedOrdering);
+ }
+#endif // !defined(QT_RESTRICTED_CAST_FROM_ASCII) && !defined(QT_NO_CAST_FROM_ASCII)
}
void tst_QString::resize()
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
index 443ea4ce64..3b88fe176a 100644
--- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -74,7 +74,6 @@ MAKE_ALL(QString, QUtf8StringView)
MAKE_ALL(QUtf8StringView, QChar)
MAKE_ALL(QUtf8StringView, char16_t)
-MAKE_ALL(QUtf8StringView, QStringView)
#undef MAKE_ALL
#undef MAKE_RELOP