diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-11-03 12:26:43 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-11-04 01:16:16 +0100 |
commit | f5fbad669d8b9b7284d8644ae51098a9c1998f64 (patch) | |
tree | f7213bcb2575d0e97d0b6f6a604050ac20e1e5fd /tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp | |
parent | 122f7d7adcbc16389728855dcff9f3e19c4652bd (diff) |
QByteArrayList: add join(QByteArrayView)
Since QByteArray/QByteArrayView don't overload nicely, we need to make
the existing QByteArray overload a Q_WEAK_OVERLOAD (= a template) as a
tie breaker. This automatically prefers the QByteArrayView version
over the QByteArray overload, transparently optimizing existing users
passing char string literals to avoid the implicit creation of a
QByteArray just for passing the separator.
None of our modules exports a subclass of QByteArrayList, so turning
join(QByteArray) into a function template should be ok.
[ChangeLog][QtCore][QByteArrayList] Added join(QByteArrayView)
overload.
Change-Id: I090671d9b94c30b63a986f17e966d124c22b5c54
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp')
-rw-r--r-- | tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp b/tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp index 29e5b947f6..82459f21ea 100644 --- a/tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp +++ b/tests/auto/corelib/text/qbytearraylist/tst_qbytearraylist.cpp @@ -27,10 +27,13 @@ ** ****************************************************************************/ +#define QT_USE_QSTRINGBUILDER + #include <QTest> #include <qbytearraylist.h> #include <qmetatype.h> +#include <qproperty.h> Q_DECLARE_METATYPE(QByteArrayList) @@ -38,6 +41,7 @@ class tst_QByteArrayList : public QObject { Q_OBJECT private slots: + void join_overloads() const; void join() const; void join_data() const; void joinByteArray() const; @@ -55,12 +59,34 @@ private slots: void initializerList() const; }; +void tst_QByteArrayList::join_overloads() const +{ + // Checks that there are no ambiguities between the different join() overloads: + + const QByteArrayList list = {"a", "b", "c"}; + const QByteArray expected = "aXbXc"; + + QCOMPARE(list.join('X'), expected); + QCOMPARE(list.join("X"), expected); + QCOMPARE(list.join(QByteArrayLiteral("X")), expected); + QCOMPARE(list.join(QByteArray("X")), expected); + QCOMPARE(list.join(QByteArrayView("X")), expected); + const char *sep = "X"; + QCOMPARE(list.join(sep), expected); + QCOMPARE(list.join(QByteArray() % "X"), expected); // QStringBuilder expression + QProperty<QByteArray> prop("X"); // implicitly convertible to QByteArray + QCOMPARE(list.join(prop), expected); + QCOMPARE(list.join(std::as_const(prop)), expected); +} + void tst_QByteArrayList::join() const { QFETCH(QByteArrayList, input); QFETCH(QByteArray, expectedResult); QCOMPARE(input.join(), expectedResult); + QCOMPARE(input.join(QByteArrayView{}), expectedResult); + QCOMPARE(input.join(QByteArray{}), expectedResult); } void tst_QByteArrayList::join_data() const @@ -88,6 +114,7 @@ void tst_QByteArrayList::joinByteArray() const QFETCH(QByteArray, expectedResult); QCOMPARE(input.join(separator), expectedResult); + QCOMPARE(input.join(QByteArrayView{separator}), expectedResult); } void tst_QByteArrayList::joinByteArray_data() const @@ -132,6 +159,7 @@ void tst_QByteArrayList::joinChar() const QFETCH(QByteArray, expectedResult); QCOMPARE(input.join(separator), expectedResult); + QCOMPARE(input.join(QByteArrayView{&separator, 1}), expectedResult); } void tst_QByteArrayList::joinChar_data() const |