// Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include #include #include #include #include #include #include #if QT_CONFIG(cpp_winrt) # include #endif #include #include #include #include #include #include #include #include #include // for negative testing (can't convert from) #include #include #ifdef __cpp_char8_t # define ONLY_IF_CHAR_8_T(expr) expr #else # define ONLY_IF_CHAR_8_T(expr) \ QSKIP("This test requires C++20 char8_t support enabled in the compiler.") #endif #ifdef __cpp_lib_char8_t # define ONLY_IF_LIB_CHAR_8_T(expr) expr #else # define ONLY_IF_LIB_CHAR_8_T(expr) \ QSKIP("This test requires C++20 char8_t support enabled in the standard library.") #endif #ifdef Q_OS_WIN # define ONLY_WIN(expr) expr #else # 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 constexpr inline bool CanConvert = std::is_convertible_v; static_assert(CanConvert); static_assert(CanConvert); static_assert(CanConvert); template struct ImplicitlyConvertibleTo { operator T() const; }; static_assert(CanConvert>); static_assert(CanConvert>); static_assert(!CanConvert>); // QAnyStringView qchar_does_not_compile() { return QAnyStringView(QChar('a')); } // QAnyStringView qlatin1string_does_not_compile() { return QAnyStringView(QLatin1String("a")); } // QAnyStringView const_char_star_does_not_compile() { return QAnyStringView("a"); } // QAnyStringView qbytearray_does_not_compile() { return QAnyStringView(QByteArray("a")); } // // QChar // static_assert(CanConvert); static_assert(CanConvert); static_assert(CanConvert< QString >); static_assert(CanConvert); static_assert(CanConvert< QString&>); static_assert(CanConvert); // // ushort // static_assert(CanConvert); static_assert(CanConvert); static_assert(CanConvert< ushort*>); static_assert(CanConvert); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); #ifdef __cpp_char8_t // // char8_t // static_assert(CanConvert); static_assert(CanConvert< char8_t*>); static_assert(CanConvert); #ifdef __cpp_lib_char8_t static_assert(CanConvert< std::u8string >); static_assert(CanConvert); static_assert(CanConvert< std::u8string&>); static_assert(CanConvert); static_assert(CanConvert< std::u8string_view >); static_assert(CanConvert); static_assert(CanConvert< std::u8string_view&>); static_assert(CanConvert); #endif // __cpp_lib_char8_t static_assert(CanConvert>); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); #endif // __cpp_char8_t // // char16_t // static_assert(CanConvert); static_assert(CanConvert< char16_t*>); static_assert(CanConvert); static_assert(CanConvert< std::u16string >); static_assert(CanConvert); static_assert(CanConvert< std::u16string&>); static_assert(CanConvert); static_assert(CanConvert< std::u16string_view >); static_assert(CanConvert); static_assert(CanConvert< std::u16string_view&>); static_assert(CanConvert); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); static_assert(CanConvert); // // char32_t // // Qt Policy: char32_t isn't supported static_assert(CanConvert); // ... except here static_assert(!CanConvert< char32_t*>); static_assert(!CanConvert); static_assert(!CanConvert< std::u32string >); static_assert(!CanConvert); static_assert(!CanConvert< std::u32string&>); static_assert(!CanConvert); static_assert(!CanConvert< std::u32string_view >); static_assert(!CanConvert); static_assert(!CanConvert< std::u32string_view&>); static_assert(!CanConvert); static_assert(!CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); static_assert(!CanConvert>); // // wchar_t // constexpr bool CanConvertFromWCharT = #ifdef Q_OS_WIN true #else false #endif ; static_assert(CanConvert == CanConvertFromWCharT); // ### FIXME: should work everywhere static_assert(CanConvert< wchar_t*> == CanConvertFromWCharT); static_assert(CanConvert == CanConvertFromWCharT); static_assert(CanConvert< std::wstring > == CanConvertFromWCharT); static_assert(CanConvert == CanConvertFromWCharT); static_assert(CanConvert< std::wstring&> == CanConvertFromWCharT); static_assert(CanConvert == CanConvertFromWCharT); static_assert(CanConvert< std::wstring_view > == CanConvertFromWCharT); static_assert(CanConvert == CanConvertFromWCharT); static_assert(CanConvert< std::wstring_view&> == CanConvertFromWCharT); static_assert(CanConvert == CanConvertFromWCharT); static_assert(CanConvert> == CanConvertFromWCharT); static_assert(CanConvert> == CanConvertFromWCharT); static_assert(CanConvert> == CanConvertFromWCharT); static_assert(CanConvert> == CanConvertFromWCharT); static_assert(!CanConvert>); static_assert(!CanConvert>); // // QStringBuilder // static_assert(CanConvert>); #if QT_CONFIG(cpp_winrt) // // winrt::hstring (QTBUG-111886) // static_assert(CanConvert< winrt::hstring >); static_assert(CanConvert); static_assert(CanConvert< winrt::hstring&>); static_assert(CanConvert); #endif // QT_CONFIG(cpp_winrt) // In bootstrapped build and in Qt 7+, two lower bits of size() are used as a // mask, so check that it is handled correctly, and the mask does not break the // actual size template struct SampleStrings { static constexpr char emptyString[] = ""; static constexpr char oneChar[] = "a"; static constexpr char twoChars[] = "ab"; static constexpr char threeChars[] = "abc"; static constexpr char regularString[] = "Hello World!"; static constexpr char regularLongString[] = R"(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.)"; static constexpr char stringWithNulls[] = "Hello\0World\0!"; static constexpr qsizetype stringWithNullsLength = std::size(stringWithNulls) -1; }; template <> struct SampleStrings { static constexpr char16_t emptyString[] = u""; static constexpr char16_t oneChar[] = u"a"; static constexpr char16_t twoChars[] = u"ab"; static constexpr char16_t threeChars[] = u"abc"; static constexpr char16_t regularString[] = u"Hello World!"; static constexpr char16_t regularLongString[] = uR"(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.)"; static constexpr char16_t stringWithNulls[] = u"Hello\0World\0!"; static constexpr qsizetype stringWithNullsLength = std::size(stringWithNulls) -1; }; template <> struct SampleStrings { static constexpr QChar emptyString[] = { {} }; // this one is easy static const QChar *const oneChar; static const QChar *const twoChars; static const QChar *const threeChars; static const QChar *const regularString; static const QChar *const regularLongString; static const QChar *const stringWithNulls; static constexpr qsizetype stringWithNullsLength = SampleStrings::stringWithNullsLength; }; const QChar *const SampleStrings::oneChar = reinterpret_cast(SampleStrings::oneChar); const QChar *const SampleStrings::twoChars = reinterpret_cast(SampleStrings::twoChars); const QChar *const SampleStrings::threeChars = reinterpret_cast(SampleStrings::threeChars); const QChar *const SampleStrings::regularString = reinterpret_cast(SampleStrings::regularString); const QChar *const SampleStrings::regularLongString = reinterpret_cast(SampleStrings::regularLongString); const QChar *const SampleStrings::stringWithNulls = reinterpret_cast(SampleStrings::stringWithNulls); class tst_QAnyStringView : public QObject { Q_OBJECT private Q_SLOTS: void constExpr() const; void basics() const; void debug() const; void asciiLiteralIsLatin1() const; void fromQString() const { fromQStringOrByteArray(); } void fromQByteArray() const { fromQStringOrByteArray(); } void fromQStringView() const { fromQStringOrByteArray(); } void fromQUtf8StringView() const { fromQStringOrByteArray(); } void fromQLatin1StringView() const { fromQStringOrByteArray(); } void fromCharArray() const { fromArray(); } void fromChar8Array() const { ONLY_IF_CHAR_8_T(fromArray()); } void fromChar16Array() const { fromArray(); } void fromQCharArray() const { fromArray(); } void fromWCharTArray() const { ONLY_WIN(fromArray()); } void fromQCharStar() const { const QChar str[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\0' }; fromLiteral(str); } void fromUShortStar() const { const ushort str[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\0' }; fromLiteral(str); } void fromChar8TStar() const { fromLiteral(u8"Hello, World!"); // char[] in <= C++17, char8_t[] in >= C++20 } void fromChar16TStar() const { fromLiteral(u"Hello, World!"); } void fromWCharTStar() const { ONLY_WIN(fromLiteral(L"Hello, World!")); } void fromCharRange() const { fromRange(); } void fromChar8TRange() const { ONLY_IF_CHAR_8_T(fromRange()); } void fromQCharRange() const { fromRange(); } void fromUShortRange() const { fromRange(); } void fromChar16TRange() const { fromRange(); } void fromWCharTRange() const { ONLY_WIN(fromRange()); } // std::basic_string void fromStdStringChar() const { fromStdString(); } void fromStdStringChar8T() const { ONLY_IF_LIB_CHAR_8_T(fromStdString()); } void fromStdStringWCharT() const { ONLY_WIN(fromStdString()); } void fromStdStringChar16T() const { fromStdString(); } void fromUShortContainers() const { fromContainers(); } void fromQCharContainers() const { fromContainers(); } void fromChar16TContainers() const { fromContainers(); } void fromWCharTContainers() const { ONLY_WIN(fromContainers()); } void fromQStringBuilder_QString_QString() const { fromQStringBuilder(u"1"_s % u"2"_s, u"12"); } void comparison(); void compare3way(); private: template void fromQStringBuilder(StringBuilder &&sb, QStringView expected) const; template void fromArray() const; template void conversion_tests(String arg) const; template void fromLiteral(const Char *arg) const; template void fromRange() const; template void fromContainer() const; template void fromContainers() const; template void fromStdString() const { fromContainer >(); } template void fromQStringOrByteArray() const; }; void tst_QAnyStringView::constExpr() const { #define IS_NULL(sv) \ do { \ static_assert(sv.size() == 0); \ static_assert(sv.isNull()); \ static_assert(sv.empty()); \ static_assert(sv.isEmpty()); \ static_assert(sv.data() == nullptr); \ } while (false) \ /*end*/ #define IS_EMPTY(sv) \ do { \ static_assert(sv.size() == 0); \ static_assert(!sv.isNull()); \ static_assert(sv.empty()); \ static_assert(sv.isEmpty()); \ static_assert(sv.data() != nullptr); \ } while (false) \ /*end*/ #define IS_OF_SIZE(sv, sz) \ do { \ static_assert(sv.size() == sz); \ static_assert(!sv.isNull()); \ static_assert(!sv.empty()); \ static_assert(!sv.isEmpty()); \ static_assert(sv.data() != nullptr); \ } while (false) \ /*end*/ // compile-time checks { constexpr QAnyStringView sv; IS_NULL(sv); } { constexpr const char *nul = nullptr; constexpr QAnyStringView sv(nul, 0); IS_NULL(sv); } { constexpr const char16_t *nul = nullptr; constexpr QAnyStringView sv(nul, 0); IS_NULL(sv); } #ifdef __cpp_char8_t { constexpr const char8_t *nul = nullptr; constexpr QAnyStringView sv(nul, 0); IS_NULL(sv); } #endif // __cpp_char8_t { constexpr QAnyStringView sv = nullptr; IS_NULL(sv); } { constexpr QAnyStringView sv = ""; IS_EMPTY(sv); } { constexpr QAnyStringView sv = u8""; IS_EMPTY(sv); } { constexpr QAnyStringView sv = u""; IS_EMPTY(sv); } { constexpr QAnyStringView sv = u"Hello"; IS_OF_SIZE(sv, 5); constexpr QAnyStringView sv2 = sv; IS_OF_SIZE(sv2, 5); } #undef IS_OF_SIZE #undef IS_EMPTY #undef IS_NULL } void tst_QAnyStringView::basics() const { QAnyStringView sv1; // a default-constructed QAnyStringView is null: QVERIFY(sv1.isNull()); // which implies it's empty(); QVERIFY(sv1.isEmpty()); QAnyStringView sv2; QVERIFY(sv2 == sv1); QVERIFY(!(sv2 != sv1)); } void tst_QAnyStringView::debug() const { #ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED # define MAYBE_L1(str) str "_L1" # define VERIFY_L1(s) QVERIFY(s.isLatin1()) #else # define MAYBE_L1(str) "u8" str # define VERIFY_L1(s) QVERIFY(s.isUtf8()) #endif #define CHECK1(s, mod, expected) do { \ QString result; \ QDebug(&result) mod << "X"_L1 << s << "Y"_L1; \ /* QDebug appends an eager ' ', so trim before comparison */ \ /* We use X and Y affixes so we can still check spacing */ \ /* around the QAnyStringView itself. */ \ QCOMPARE(result.trimmed(), expected); \ } while (false) #define CHECK(init, esq, eq, es, e) do { \ QAnyStringView s = init; \ CHECK1(s, , esq); \ CHECK1(s, .nospace(), eq); \ CHECK1(s, .noquote(), es); \ CHECK1(s, .nospace().noquote(), e); \ } while (false) CHECK(nullptr, R"("X" u8"" "Y")", R"("X"u8"""Y")", R"(X Y)", R"(XY)"); CHECK(QLatin1StringView(nullptr), R"("X" ""_L1 "Y")", R"("X"""_L1"Y")", R"(X Y)", R"(XY)"); CHECK(QUtf8StringView(nullptr), R"("X" u8"" "Y")", R"("X"u8"""Y")", R"(X Y)", R"(XY)"); CHECK(QStringView(nullptr), R"("X" u"" "Y")", R"("X"u"""Y")", R"(X Y)", R"(XY)"); { constexpr QAnyStringView asv = "hello"; VERIFY_L1(asv); // ### fails when asv isn't constexpr CHECK(asv, R"("X" )" MAYBE_L1(R"("hello")") R"( "Y")", R"("X")" MAYBE_L1(R"("hello")") R"("Y")", R"(X hello Y)", R"(XhelloY)"); } CHECK(u8"hällo", R"("X" u8"h\xC3\xA4llo" "Y")", R"("X"u8"h\xC3\xA4llo""Y")", R"(X hällo Y)", R"(XhälloY)"); CHECK(u"hällo", R"("X" u"hällo" "Y")", R"("X"u"hällo""Y")", R"(X hällo Y)", R"(XhälloY)"); #undef CHECK #undef CHECK1 #undef VERIFY_L1 #undef MAYBE_L1 } void tst_QAnyStringView::asciiLiteralIsLatin1() const { #ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED if constexpr (true) { constexpr bool asciiCstringIsLatin1 = QAnyStringView("Hello, World").isLatin1(); QVERIFY(asciiCstringIsLatin1); constexpr bool asciiUtf8stringIsLatin1 = QAnyStringView(u8"Hello, World").isLatin1(); QVERIFY(asciiUtf8stringIsLatin1); constexpr bool utf8StringIsNotLatin1 = !QAnyStringView(u8"Tørrfisk").isLatin1(); QVERIFY(utf8StringIsNotLatin1); constexpr bool asciiCstringArrayIsLatin1 = QAnyStringView::fromArray("Hello, World").isLatin1(); QVERIFY(asciiCstringArrayIsLatin1); constexpr bool asciiUtfstringArrayIsLatin1 = QAnyStringView::fromArray(u8"Hello, World").isLatin1(); QVERIFY(asciiUtfstringArrayIsLatin1); constexpr bool utf8StringArrayIsNotLatin1 = !QAnyStringView::fromArray(u8"Tørrfisk").isLatin1(); QVERIFY(utf8StringArrayIsNotLatin1); } #else QSKIP("Compile-detection of US-ASCII strings not possible with this compiler"); #endif } template void tst_QAnyStringView::fromQStringBuilder(StringBuilder &&sb, QStringView expected) const { auto toAnyStringView = [](QAnyStringView sv) { return sv; }; QCOMPARE(toAnyStringView(std::forward(sb)), expected); } template void tst_QAnyStringView::fromArray() const { constexpr Char hello[] = {'H', 'e', 'l', 'l', 'o', '\0', 'a', 'b', 'c', '\0', '\0', '.', '\0'}; QAnyStringView sv = QAnyStringView::fromArray(hello); QCOMPARE(sv.size(), 13); QVERIFY(!sv.empty()); QVERIFY(!sv.isEmpty()); QVERIFY(!sv.isNull()); QCOMPARE(sv.front(), 'H'); QCOMPARE(sv.back(), '\0'); const Char bytes[] = {'a', 'b', 'c'}; QAnyStringView sv2 = QAnyStringView::fromArray(bytes); QCOMPARE(sv2.data(), static_cast(bytes + 0)); QCOMPARE(sv2.size(), 3); QCOMPARE(sv2.back(), u'c'); } template void tst_QAnyStringView::fromQStringOrByteArray() const { using Char = std::remove_cv_t; using Strings = SampleStrings; QStringOrByteArray null; QStringOrByteArray empty(Strings::emptyString); QVERIFY( QAnyStringView(null).isNull()); QVERIFY( QAnyStringView(null).isEmpty()); QVERIFY( QAnyStringView(empty).isEmpty()); QVERIFY(!QAnyStringView(empty).isNull()); conversion_tests(QStringOrByteArray(Strings::oneChar)); if (QTest::currentTestFailed()) return; conversion_tests(QStringOrByteArray(Strings::twoChars)); if (QTest::currentTestFailed()) return; conversion_tests(QStringOrByteArray(Strings::threeChars)); if (QTest::currentTestFailed()) return; conversion_tests(QStringOrByteArray(Strings::regularString)); if (QTest::currentTestFailed()) return; conversion_tests(QStringOrByteArray(Strings::regularLongString)); if (QTest::currentTestFailed()) return; conversion_tests(QStringOrByteArray(Strings::stringWithNulls, Strings::stringWithNullsLength)); } template void tst_QAnyStringView::fromLiteral(const Char *arg) const { const Char *null = nullptr; const Char empty[] = { Char{} }; QCOMPARE(QAnyStringView(null).size(), qsizetype(0)); QCOMPARE(QAnyStringView(null).data(), nullptr); QCOMPARE(QAnyStringView(empty).size(), qsizetype(0)); QCOMPARE(static_cast(QAnyStringView(empty).data()), static_cast(empty)); QVERIFY( QAnyStringView(null).isNull()); QVERIFY( QAnyStringView(null).isEmpty()); QVERIFY( QAnyStringView(empty).isEmpty()); QVERIFY(!QAnyStringView(empty).isNull()); conversion_tests(arg); } template void tst_QAnyStringView::fromRange() const { auto doTest = [](const Char *first, const Char *last) { QCOMPARE(QAnyStringView(first, first).size(), 0); QCOMPARE(static_cast(QAnyStringView(first, first).data()), static_cast(first)); const auto sv = QAnyStringView(first, last); QCOMPARE(sv.size(), last - first); QCOMPARE(static_cast(sv.data()), static_cast(first)); // can't call conversion_tests() here, as it requires a single object }; const Char *null = nullptr; using RealChar = std::conditional_t; using Strings = SampleStrings; QCOMPARE(QAnyStringView(null, null).size(), 0); QCOMPARE(QAnyStringView(null, null).data(), nullptr); doTest(reinterpret_cast(std::begin(Strings::regularString)), reinterpret_cast(std::end(Strings::regularString))); if (QTest::currentTestFailed()) return; doTest(reinterpret_cast(std::begin(Strings::regularLongString)), reinterpret_cast(std::end(Strings::regularLongString))); if (QTest::currentTestFailed()) return; doTest(reinterpret_cast(std::begin(Strings::stringWithNulls)), reinterpret_cast(std::end(Strings::stringWithNulls))); if (QTest::currentTestFailed()) return; } template void tst_QAnyStringView::fromContainer() const { const std::string s = "Hello World!"; const std::string n(SampleStrings::stringWithNulls, SampleStrings::stringWithNullsLength); Container c; // unspecified whether empty containers make null QAnyStringViews QVERIFY(QAnyStringView(c).isEmpty()); std::copy(s.begin(), s.end(), std::back_inserter(c)); conversion_tests(std::move(c)); if (QTest::currentTestFailed()) return; // repeat with nulls c = {}; std::copy(n.begin(), n.end(), std::back_inserter(c)); conversion_tests(std::move(c)); } template void tst_QAnyStringView::fromContainers() const { fromContainer>(); fromContainer>(); fromContainer>(); } namespace help { template auto ssize(T &t) { return q20::ssize(t); } template qsizetype ssize(const T *t) { qsizetype result = 0; if (t) { while (*t++) ++result; } return result; } qsizetype ssize(const QChar *t) { qsizetype result = 0; if (t) { while (!t++->isNull()) ++result; } return result; } } template void tst_QAnyStringView::conversion_tests(String string) const { // copy-construct: { QAnyStringView sv = string; QCOMPARE(help::ssize(sv), help::ssize(string)); QCOMPARE(sv, string); } QAnyStringView sv; // copy-assign: { sv = string; QCOMPARE(help::ssize(sv), help::ssize(string)); // check relational operators: QCOMPARE(sv, string); QCOMPARE(string, sv); QVERIFY(!(sv != string)); QVERIFY(!(string != sv)); QVERIFY(!(sv < string)); QVERIFY(sv <= string); QVERIFY(!(sv > string)); QVERIFY(sv >= string); QVERIFY(!(string < sv)); QVERIFY(string <= sv); QVERIFY(!(string > sv)); QVERIFY(string >= sv); } // copy-construct from rvalue (QAnyStringView never assumes ownership): { QAnyStringView sv2 = std::move(string); QCOMPARE(sv2, sv); QCOMPARE(sv2, string); } // copy-assign from rvalue (QAnyStringView never assumes ownership): { QAnyStringView sv2; sv2 = std::move(string); QCOMPARE(sv2, sv); QCOMPARE(sv2, string); } } void tst_QAnyStringView::comparison() { const QAnyStringView aa = u"aa"; const QAnyStringView upperAa = u"AA"; const QAnyStringView bb = u"bb"; QVERIFY(aa == aa); QVERIFY(aa != bb); QVERIFY(aa < bb); QVERIFY(bb > aa); QCOMPARE(QAnyStringView::compare(aa, aa), 0); QVERIFY(QAnyStringView::compare(aa, upperAa) != 0); QCOMPARE(QAnyStringView::compare(aa, upperAa, Qt::CaseInsensitive), 0); QVERIFY(QAnyStringView::compare(aa, bb) < 0); 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); \ 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); COMPARE_3WAY(upperAa, aa, std::strong_ordering::less); COMPARE_3WAY(aa, upperAa, std::strong_ordering::greater); ); #undef COMPARE_3WAY } QTEST_APPLESS_MAIN(tst_QAnyStringView) #include "tst_qanystringview.moc"