summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qstringview/tst_qstringview.cpp')
-rw-r--r--tests/auto/corelib/text/qstringview/tst_qstringview.cpp94
1 files changed, 54 insertions, 40 deletions
diff --git a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
index a78004f04d..df3ef94371 100644
--- a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
+++ b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
#include <QStringView>
#include <QStringTokenizer>
@@ -32,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>
@@ -115,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
//
@@ -149,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
@@ -263,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;
@@ -472,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); \
@@ -552,13 +553,11 @@ void tst_QStringView::tokenize() const
QFETCH(const QStringList, result);
// lvalue QString
-#ifdef __cpp_deduction_guides
{
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, sep})
QCOMPARE(sv, *rit++);
}
-#endif
{
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(sep))
@@ -566,13 +565,11 @@ void tst_QStringView::tokenize() const
}
// rvalue QString
-#ifdef __cpp_deduction_guides
{
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, QString{sep}})
QCOMPARE(sv, *rit++);
}
-#endif
{
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(QString{sep}))
@@ -580,13 +577,11 @@ void tst_QStringView::tokenize() const
}
// (rvalue) QChar
-#ifdef __cpp_deduction_guides
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, sep.front()})
QCOMPARE(sv, *rit++);
}
-#endif
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(sep.front()))
@@ -594,13 +589,11 @@ void tst_QStringView::tokenize() const
}
// (rvalue) char16_t
-#ifdef __cpp_deduction_guides
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, *qToStringViewIgnoringNull(sep).utf16()})
QCOMPARE(sv, *rit++);
}
-#endif
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(*qToStringViewIgnoringNull(sep).utf16()))
@@ -615,20 +608,17 @@ void tst_QStringView::tokenize() const
return literal;
};
const std::unique_ptr<const char16_t[]> literal = make_literal(sep);
-#ifdef __cpp_deduction_guides
{
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, literal.get()})
QCOMPARE(sv, *rit++);
}
-#endif
{
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(literal.get()))
QCOMPARE(sv, *rit++);
}
-#ifdef __cpp_deduction_guides
#ifdef __cpp_lib_ranges
// lvalue QString
{
@@ -657,7 +647,6 @@ void tst_QStringView::tokenize() const
QCOMPARE(result, actual);
}
#endif // __cpp_lib_ranges
-#endif // __cpp_deduction_guides
}
template <typename Char>
@@ -891,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"