summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp')
-rw-r--r--tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp96
1 files changed, 94 insertions, 2 deletions
diff --git a/tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp b/tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp
index 1a77750246..894f0430dd 100644
--- a/tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp
+++ b/tests/auto/corelib/text/qbytearrayview/tst_qbytearrayview.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// 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 <QByteArrayView>
@@ -171,6 +171,7 @@ private slots:
void comparison() const;
void compare() const;
+ void std_stringview_conversion();
private:
template <typename Data>
@@ -196,6 +197,10 @@ void tst_QByteArrayView::constExpr() const
static_assert(bv.isEmpty());
static_assert(bv.data() == nullptr);
+ constexpr std::string_view sv = bv;
+ static_assert(sv.size() == 0);
+ static_assert(sv.data() == nullptr);
+
constexpr QByteArrayView bv2(bv.data(), bv.data() + bv.size());
static_assert(bv2.isNull());
static_assert(bv2.empty());
@@ -208,6 +213,10 @@ void tst_QByteArrayView::constExpr() const
static_assert(bv.isEmpty());
static_assert(bv.data() != nullptr);
+ constexpr std::string_view sv = bv;
+ static_assert(sv.size() == bv.size());
+ static_assert(sv.data() == bv.data());
+
constexpr QByteArrayView bv2(bv.data(), bv.data() + bv.size());
static_assert(!bv2.isNull());
static_assert(bv2.empty());
@@ -240,6 +249,14 @@ void tst_QByteArrayView::constExpr() const
static_assert(bv.rbegin() != bv.rend());
static_assert(bv.crbegin() != bv.crend());
+ constexpr std::string_view sv = bv;
+ static_assert(sv.size() == bv.size());
+ static_assert(sv.data() == bv.data());
+#ifdef AMBIGUOUS_CALL // QTBUG-108805
+ static_assert(sv == bv);
+ static_assert(bv == sv);
+#endif
+
constexpr QByteArrayView bv2(bv.data(), bv.data() + bv.size());
static_assert(!bv2.isNull());
static_assert(!bv2.empty());
@@ -265,6 +282,13 @@ void tst_QByteArrayView::constExpr() const
static_assert(bv.at(4) == 'o');
static_assert(bv.back() == 'o');
static_assert(bv.last() == 'o');
+
+ constexpr std::string_view sv = bv;
+ static_assert(bv.size() == sv.size());
+#ifdef AMBIGUOUS_CALL // QTBUG-108805
+ static_assert(bv == sv);
+ static_assert(sv == bv);
+#endif
}
{
static constexpr char hello[] = { 'H', 'e', 'l', 'l', 'o' };
@@ -282,6 +306,13 @@ void tst_QByteArrayView::constExpr() const
static_assert(bv.at(4) == 'o');
static_assert(bv.back() == 'o');
static_assert(bv.last() == 'o');
+
+ constexpr std::string_view sv = bv;
+ static_assert(bv.size() == sv.size());
+#ifdef AMBIGUOUS_CALL // QTBUG-108805
+ static_assert(bv == sv);
+ static_assert(sv == bv);
+#endif
}
#endif
{
@@ -290,6 +321,42 @@ void tst_QByteArrayView::constExpr() const
static_assert(bv.isNull());
static_assert(bv.isEmpty());
static_assert(bv.size() == 0);
+
+ constexpr std::string_view sv = bv;
+ static_assert(sv.size() == 0);
+ static_assert(sv.data() == nullptr);
+ }
+ {
+ constexpr QByteArrayView bv(QLatin1StringView("Hello"));
+ static_assert(bv.size() == 5);
+ static_assert(!bv.empty());
+ static_assert(!bv.isEmpty());
+ static_assert(!bv.isNull());
+ static_assert(*bv.data() == 'H');
+ static_assert(bv[0] == 'H');
+ static_assert(bv.at(0) == 'H');
+ static_assert(bv.front() == 'H');
+ static_assert(bv.first() == 'H');
+ static_assert(bv[4] == 'o');
+ static_assert(bv.at(4) == 'o');
+ static_assert(bv.back() == 'o');
+ static_assert(bv.last() == 'o');
+ }
+ {
+ constexpr QByteArrayView bv(QUtf8StringView("Hello"));
+ static_assert(bv.size() == 5);
+ static_assert(!bv.empty());
+ static_assert(!bv.isEmpty());
+ static_assert(!bv.isNull());
+ static_assert(*bv.data() == 'H');
+ static_assert(bv[0] == 'H');
+ static_assert(bv.at(0) == 'H');
+ static_assert(bv.front() == 'H');
+ static_assert(bv.first() == 'H');
+ static_assert(bv[4] == 'o');
+ static_assert(bv.at(4) == 'o');
+ static_assert(bv.back() == 'o');
+ static_assert(bv.last() == 'o');
}
}
@@ -432,7 +499,7 @@ void tst_QByteArrayView::fromQByteArray() const
QByteArray empty = "";
QVERIFY(QByteArrayView(null).isNull());
- QVERIFY(!qToByteArrayViewIgnoringNull(null).isNull());
+ QVERIFY(qToByteArrayViewIgnoringNull(null).isNull());
QVERIFY(QByteArrayView(null).isEmpty());
QVERIFY(qToByteArrayViewIgnoringNull(null).isEmpty());
@@ -632,5 +699,30 @@ void tst_QByteArrayView::compare() const
QVERIFY(alpha.compare(beta, Qt::CaseSensitive) > 0);
}
+void tst_QByteArrayView::std_stringview_conversion()
+{
+ static_assert(std::is_convertible_v<QByteArrayView, std::string_view>);
+
+ QByteArrayView bav;
+ std::string_view sv(bav);
+ QCOMPARE(sv, std::string_view());
+
+ bav = "";
+ sv = bav;
+ QCOMPARE(bav.size(), 0);
+ QCOMPARE(sv.size(), size_t(0));
+ QCOMPARE(sv, std::string_view());
+
+ bav = "Hello";
+ sv = bav;
+ QCOMPARE(sv, std::string_view("Hello"));
+
+ bav = QByteArrayView::fromArray("Hello\0world");
+ sv = bav;
+ QCOMPARE(bav.size(), 12);
+ QCOMPARE(sv.size(), size_t(12));
+ QCOMPARE(sv, std::string_view("Hello\0world", 12));
+}
+
QTEST_APPLESS_MAIN(tst_QByteArrayView)
#include "tst_qbytearrayview.moc"