summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-06-10 16:52:17 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-06-12 03:08:59 +0200
commite0ae1af278f3cc6df6c3f66e4118585cc8384b15 (patch)
treed18ecb98ef82d006dc67ef9e914e756e92b83424 /tests
parent77d62727d0c1c638b904ada8fc720de2a4d60a6e (diff)
QLatin1String: Add a constructor taking QByteArrayView
Change-Id: Ie90645486431d7af3fe8128417b0fb6bd02a88b5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp b/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp
index 41c4f26c2c..039a024d64 100644
--- a/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp
+++ b/tests/auto/corelib/text/qlatin1string/tst_qlatin1string.cpp
@@ -44,6 +44,7 @@ class tst_QLatin1String : public QObject
Q_OBJECT
private Q_SLOTS:
+ void construction();
void at();
void arg() const;
void midLeftRight();
@@ -54,6 +55,36 @@ private Q_SLOTS:
void relationalOperators();
};
+void tst_QLatin1String::construction()
+{
+ {
+ const char str[6] = "hello";
+ QLatin1String l1s(str);
+ QCOMPARE(l1s.size(), 5);
+ QCOMPARE(l1s.latin1(), reinterpret_cast<const void *>(&str[0]));
+ QCOMPARE(l1s.latin1(), "hello");
+
+ QByteArrayView helloView(str);
+ helloView = helloView.first(4);
+ l1s = QLatin1String(helloView);
+ QCOMPARE(l1s.latin1(), helloView.data());
+ QCOMPARE(l1s.latin1(), reinterpret_cast<const void *>(helloView.data()));
+ QCOMPARE(l1s.size(), helloView.size());
+ }
+
+ {
+ const QByteArray helloArray("hello");
+ QLatin1String l1s(helloArray);
+ QCOMPARE(l1s.latin1(), helloArray.data());
+ QCOMPARE(l1s.size(), helloArray.size());
+
+ QByteArrayView helloView(helloArray);
+ helloView = helloView.first(4);
+ l1s = QLatin1String(helloView);
+ QCOMPARE(l1s.latin1(), helloView.data());
+ QCOMPARE(l1s.size(), helloView.size());
+ }
+}
void tst_QLatin1String::at()
{