summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstring
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-03-04 17:19:33 +0100
committerAndrei Golubev <andrei.golubev@qt.io>2021-03-30 10:37:07 +0100
commitb1377ed02dce9a173e345aab22af504de2b77d54 (patch)
tree7909d18d4d97211ecf78600b9fca706dc399c483 /tests/auto/corelib/text/qstring
parentccf1a1a9536be7b904494f5b3243202d71a33b06 (diff)
Add literal operators for QString and QByteArray
[ChangeLog][QtCore][QString] Added literal operator u"..."_qs that converts a char16_t string literal to QString [ChangeLog][QtCore][QByteArray] Added literal operator "..."_qba that converts char string literal to QByteArray Change-Id: I4aa59b28cc17bff346b378eb70008fb8185d21ac Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qstring')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 79c4fa4ab0..f36da049f9 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -569,6 +569,7 @@ private slots:
#if !defined(QT_NO_UNICODE_LITERAL)
void literals();
#endif
+ void userDefinedLiterals();
void eightBitLiterals_data();
void eightBitLiterals();
void reserve();
@@ -6445,6 +6446,29 @@ void tst_QString::literals()
}
#endif
+void tst_QString::userDefinedLiterals()
+{
+ QString str = u"abcd"_qs;
+
+ QVERIFY(str.length() == 4);
+ QCOMPARE(str.capacity(), 0);
+ QVERIFY(str == QLatin1String("abcd"));
+ QVERIFY(!str.data_ptr()->isMutable());
+
+ const QChar *s = str.constData();
+ QString 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());
+}
+
void tst_QString::eightBitLiterals_data()
{
QTest::addColumn<QByteArray>("data");