diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-21 14:32:58 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-04-07 09:22:28 +0200 |
commit | 8aa3cf21da696f241ab06504362fe243c3ca32b0 (patch) | |
tree | e9c1b988d3543af02eedbf637fd718b23639d047 /tests/auto/corelib/text/qbytearray | |
parent | a0470ec2617357293d13fa5ec2c87efbd3965b4c (diff) |
Add literal operators for QString/QByteArray to StringLiterals namespace
[ChangeLog][QtCore] Added literal operators for _s and _ba for QString
and QByteArray respectively in the Qt::Literals::StringLiterals
namespace.
Task-number: QTBUG-101408
Change-Id: I5cd4e7f36f614ea805cfecc27b91c5d981cd3794
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qbytearray')
-rw-r--r-- | tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index 1de223d1e7..e92011aeb8 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -2215,25 +2215,50 @@ void tst_QByteArray::literals() void tst_QByteArray::userDefinedLiterals() { - QByteArray str = "abcd"_qba; + { + using namespace Qt::StringLiterals; + QByteArray str = "abcd"_ba; + + QVERIFY(str.length() == 4); + QCOMPARE(str.capacity(), 0); + QVERIFY(str == "abcd"); + QVERIFY(!str.data_ptr()->isMutable()); + + const char *s = str.constData(); + QByteArray str2 = str; + QVERIFY(str2.constData() == s); + QCOMPARE(str2.capacity(), 0); + + // detach on non const access + QVERIFY(str.data() != s); + QVERIFY(str.capacity() >= str.length()); + + QVERIFY(str2.constData() == s); + QVERIFY(str2.data() != s); + QVERIFY(str2.capacity() >= str2.length()); + } - QVERIFY(str.length() == 4); - QCOMPARE(str.capacity(), 0); - QVERIFY(str == "abcd"); - QVERIFY(!str.data_ptr()->isMutable()); + { + QByteArray str = "abcd"_qba; - const char *s = str.constData(); - QByteArray str2 = str; - QVERIFY(str2.constData() == s); - QCOMPARE(str2.capacity(), 0); + QVERIFY(str.length() == 4); + QCOMPARE(str.capacity(), 0); + QVERIFY(str == "abcd"); + QVERIFY(!str.data_ptr()->isMutable()); - // detach on non const access - QVERIFY(str.data() != s); - QVERIFY(str.capacity() >= str.length()); + const char *s = str.constData(); + QByteArray str2 = str; + QVERIFY(str2.constData() == s); + QCOMPARE(str2.capacity(), 0); - QVERIFY(str2.constData() == s); - QVERIFY(str2.data() != s); - QVERIFY(str2.capacity() >= str2.length()); + // detach on non const access + QVERIFY(str.data() != s); + QVERIFY(str.capacity() >= str.length()); + + QVERIFY(str2.constData() == s); + QVERIFY(str2.data() != s); + QVERIFY(str2.capacity() >= str2.length()); + } } void tst_QByteArray::toUpperLower_data() |