summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstringview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qstringview')
-rw-r--r--tests/auto/corelib/text/qstringview/CMakeLists.txt11
-rw-r--r--tests/auto/corelib/text/qstringview/tst_qstringview.cpp55
2 files changed, 63 insertions, 3 deletions
diff --git a/tests/auto/corelib/text/qstringview/CMakeLists.txt b/tests/auto/corelib/text/qstringview/CMakeLists.txt
index 34c145a498..ba5f540838 100644
--- a/tests/auto/corelib/text/qstringview/CMakeLists.txt
+++ b/tests/auto/corelib/text/qstringview/CMakeLists.txt
@@ -1,12 +1,21 @@
-# Generated from qstringview.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstringview Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstringview LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstringview
SOURCES
tst_qstringview.cpp
+ LIBRARIES
+ Qt::CorePrivate
)
## Scopes:
diff --git a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
index ccb12488a7..df3ef94371 100644
--- a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
+++ b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QStringView>
#include <QStringTokenizer>
@@ -7,6 +7,11 @@
#include <QChar>
#include <QVarLengthArray>
#include <QList>
+#if QT_CONFIG(cpp_winrt)
+# include <private/qt_winrtbase_p.h>
+#endif
+#include <private/qxmlstream_p.h>
+
#include <QTest>
@@ -90,6 +95,8 @@ static_assert(CanConvert<std::array<char16_t, 123>>::value);
static_assert(!CanConvert<std::deque<char16_t>>::value);
static_assert(!CanConvert<std::list<char16_t>>::value);
+static_assert(CanConvert<QtPrivate::XmlStringRef>::value);
+
//
// wchar_t
//
@@ -124,6 +131,19 @@ static_assert(CanConvert<std::array<wchar_t, 123>>::value == CanConvertFromWChar
static_assert(!CanConvert<std::deque<wchar_t>>::value);
static_assert(!CanConvert<std::list<wchar_t>>::value);
+#if QT_CONFIG(cpp_winrt)
+
+//
+// winrt::hstring (QTBUG-111886)
+//
+
+static_assert(CanConvert< winrt::hstring >::value);
+static_assert(CanConvert<const winrt::hstring >::value);
+static_assert(CanConvert< winrt::hstring&>::value);
+static_assert(CanConvert<const winrt::hstring&>::value);
+
+#endif // QT_CONFIG(cpp_winrt)
+
class tst_QStringView : public QObject
{
Q_OBJECT
@@ -238,6 +258,8 @@ private Q_SLOTS:
void tokenize_data() const;
void tokenize() const;
+ void std_stringview_conversion();
+
private:
template <typename String>
void conversion_tests(String arg) const;
@@ -447,6 +469,10 @@ void tst_QStringView::at() const
void tst_QStringView::arg() const
{
+ // nullness checks
+ QCOMPARE(QStringView().arg(QStringView()), "");
+ QCOMPARE(QStringView(u"%1").arg(QStringView()), "");
+
#define CHECK1(pattern, arg1, expected) \
do { \
auto p = QStringView(u"" pattern); \
@@ -854,10 +880,35 @@ void tst_QStringView::overloadResolution()
{
std::u16string string;
QStringViewOverloadResolution::test(string);
- QStringViewOverloadResolution::test(qAsConst(string));
+ QStringViewOverloadResolution::test(std::as_const(string));
QStringViewOverloadResolution::test(std::move(string));
}
}
+void tst_QStringView::std_stringview_conversion()
+{
+ static_assert(std::is_convertible_v<QStringView, std::u16string_view>);
+
+ QStringView s;
+ std::u16string_view sv(s);
+ QCOMPARE(sv, std::u16string_view());
+
+ s = u"";
+ sv = s;
+ QCOMPARE(s.size(), 0);
+ QCOMPARE(sv.size(), size_t(0));
+ QCOMPARE(sv, std::u16string_view());
+
+ s = u"Hello";
+ sv = s;
+ QCOMPARE(sv, std::u16string_view(u"Hello"));
+
+ s = QStringView::fromArray(u"Hello\0world");
+ sv = s;
+ QCOMPARE(s.size(), 12);
+ QCOMPARE(sv.size(), size_t(12));
+ QCOMPARE(sv, std::u16string_view(u"Hello\0world\0", 12));
+}
+
QTEST_APPLESS_MAIN(tst_QStringView)
#include "tst_qstringview.moc"