diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-06-09 09:52:58 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-14 01:31:01 +0000 |
commit | eb545512b259065a4be7dc9c4ab9be57212c89f2 (patch) | |
tree | 4cc9410c03080fe4745c25c9807592b163a89e19 /tests | |
parent | 478d48eb6dc18bbd5b9601e83110d22f115db130 (diff) |
tst_QAnyStringView: explicitly check the spaceship operator
We implicitly checked it, because, in C++20 builds, the non-equality
relational operators are synthesized from it by the compiler, and we
test those, but we didn't check that <=> returns strong_ordering.
We now do.
Task-number: QTBUG-104108
Change-Id: Ieb19a2d4cb2d600d884f4e2e89e98c6187e23872
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 1b8b8024554f9f36bc6642c2dfe830765e932df5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp b/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp index fe7083502e..4433b8efbc 100644 --- a/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp +++ b/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp @@ -42,6 +42,14 @@ # define ONLY_WIN(expr) QSKIP("This is a Windows-only test") #endif +#ifdef __cpp_impl_three_way_comparison +# define ONLY_3WAY(expr) expr +#else +# define ONLY_3WAY(expr) \ + QSKIP("This test requires C++20 spaceship operator (<=>) " \ + "support enabled in the standard library.") +#endif + using namespace Qt::StringLiterals; template <typename T> @@ -292,6 +300,7 @@ private Q_SLOTS: void fromQStringBuilder_QString_QString() const { fromQStringBuilder(u"1"_s % u"2"_s, u"12"); } void comparison(); + void compare3way(); private: template <typename StringBuilder> @@ -629,5 +638,27 @@ void tst_QAnyStringView::comparison() QVERIFY(QAnyStringView::compare(bb, aa) > 0); } +void tst_QAnyStringView::compare3way() +{ +#define COMPARE_3WAY(lhs, rhs, res) \ + do { \ + const auto qt_3way_cmp_res = (lhs) <=> (rhs); \ + static_assert(std::is_same_v<decltype(qt_3way_cmp_res), decltype(res)>); \ + QCOMPARE(std::is_eq(qt_3way_cmp_res), std::is_eq(res)); \ + QCOMPARE(std::is_lt(qt_3way_cmp_res), std::is_lt(res)); \ + QCOMPARE(std::is_gt(qt_3way_cmp_res), std::is_gt(res)); \ + } while (false) + + ONLY_3WAY( + const QAnyStringView aa = u"aa"; + const QAnyStringView upperAa = u"AA"; + const QAnyStringView bb = u"bb"; + COMPARE_3WAY(aa, aa, std::strong_ordering::equal); + COMPARE_3WAY(aa, bb, std::strong_ordering::less); + COMPARE_3WAY(bb, aa, std::strong_ordering::greater) + ); +#undef COMPARE_3WAY +} + QTEST_APPLESS_MAIN(tst_QAnyStringView) #include "tst_qanystringview.moc" |