diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2024-02-22 11:43:35 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-03-02 00:12:54 +0100 |
commit | ee612626f99d5a8da6814c2df90db00f9beb463f (patch) | |
tree | 5a92a286c27418b2b4e76e0faf01a24246f5fa82 /tests/auto/corelib/text/qchar | |
parent | a08bafc9205d0b67f71a1896ad84272eeb294374 (diff) |
Q(Latin1)Char: use comparison helper macros
Replace the existing friend relational operators with the macros.
Add the previously-missing QChar vs `const char *` relational operators.
These require out-of-line helper methods, because we need to interpret
the `const char *` array as utf-8.
The `const char *` relational operators cause ambiguities when
comparing QChar with 0 (previously it was only handled by the nullptr_t
overloads). As we have it in several places in our tests, I'd assume
that the users can also do it. To resolve the ambiguities, mark the
new relational operators as Q_WEAK_OVERLOADs.
This allows to remove the dummy QChar vs `const char *` relational
operators from tst_qstringapisymmetry, but at the same time requires
that we introduce new dummy operators for QByteArray vs char16_t
comparison. These will be fixed in a follow-up patch.
For QLatin1Char - convert to uchar before doing the comparison, to
match the behavior of QLatin1StringView and QChar. Extend QChar's
unit tests.
Task-number: QTBUG-117661
Change-Id: I9213fe05a5efdb96d48688f07bec9519f9887a77
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qchar')
-rw-r--r-- | tests/auto/corelib/text/qchar/tst_qchar.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qchar/tst_qchar.cpp b/tests/auto/corelib/text/qchar/tst_qchar.cpp index e0578bacb2..b112538a8c 100644 --- a/tests/auto/corelib/text/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/text/qchar/tst_qchar.cpp @@ -17,6 +17,8 @@ private slots: void operator_eqeq_null(); void operators_data(); void operators(); + void qchar_qlatin1char_operators_symmetry_data(); + void qchar_qlatin1char_operators_symmetry(); void toUpper(); void toLower(); void toTitle(); @@ -174,6 +176,36 @@ void tst_QChar::operators() #undef CHECK } +void tst_QChar::qchar_qlatin1char_operators_symmetry_data() +{ + QTest::addColumn<char>("lhs"); + QTest::addColumn<char>("rhs"); + + const uchar values[] = {0x00, 0x3a, 0x7f, 0x80, 0xab, 0xff}; + + for (uchar i : values) { + for (uchar j : values) + QTest::addRow("'\\x%02x'_op_'\\x%02x'", i, j) << char(i) << char(j); + } +} + +void tst_QChar::qchar_qlatin1char_operators_symmetry() +{ + QFETCH(char, lhs); + QFETCH(char, rhs); + + const QLatin1Char l1lhs(lhs); + const QLatin1Char l1rhs(rhs); +#define CHECK(op) QCOMPARE((l1lhs op l1rhs), (QChar(l1lhs) op QChar(l1rhs))) + CHECK(==); + CHECK(!=); + CHECK(< ); + CHECK(> ); + CHECK(<=); + CHECK(>=); +#undef CHECK +} + void tst_QChar::toUpper() { QVERIFY(QChar('a').toUpper() == 'A'); |