summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-10-17 10:19:31 +0200
committerLiang Qi <liang.qi@qt.io>2017-10-17 10:34:24 +0200
commitd0a0a3c0418a0fdd2ed84b2a5f7e6565537715c6 (patch)
treed6aeb4d51caf30ccf23eadb806a09295cbf679cd /tests/auto/corelib/tools
parent9f405f98a4247cd263b9c5d35659a4ba89e282de (diff)
parentac35f9c44c0fb3b2f40ae5585c497200b2ba743d (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: examples/network/fortuneclient/client.cpp examples/network/fortuneserver/server.cpp src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h src/plugins/platforms/cocoa/qcocoabackingstore.h src/plugins/platforms/cocoa/qcocoaintegration.h src/plugins/platforms/cocoa/qcocoascreen.h src/plugins/platforms/ios/qiosbackingstore.h src/plugins/sqldrivers/oci/qsql_oci.cpp src/widgets/kernel/qwidgetwindow.cpp Change-Id: Ia6dd2c52d4a691b671cf9a2ffca70deccece8f10
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qstringview/tst_qstringview.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp
index 48ea5a794c..4174b85f4c 100644
--- a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp
+++ b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp
@@ -364,14 +364,21 @@ void tst_QStringView::basics() const
void tst_QStringView::literals() const
{
#if !defined(Q_OS_WIN) || defined(Q_COMPILER_UNICODE_STRINGS)
- // the + ensures it's a pointer, not an array
- QCOMPARE(QStringView(+u"Hello").size(), 5);
- QStringView sv = u"Hello";
+ const char16_t hello[] = u"Hello";
+ const char16_t longhello[] =
+ u"Hello World. This is a much longer message, to exercise qustrlen.";
+ const char16_t withnull[] = u"a\0zzz";
#else // storage_type is wchar_t
- // the + ensures it's a pointer, not an array
- QCOMPARE(QStringView(+L"Hello").size(), 5);
- QStringView sv = L"Hello";
+ const wchar_t hello[] = L"Hello";
+ const wchar_t longhello[] =
+ L"Hello World. This is a much longer message, to exercise qustrlen.";
+ const wchar_t withnull[] = L"a\0zzz";
#endif
+ Q_STATIC_ASSERT(sizeof(longhello) >= 16);
+
+ QCOMPARE(QStringView(hello).size(), 5);
+ QCOMPARE(QStringView(hello + 0).size(), 5); // forces decay to pointer
+ QStringView sv = hello;
QCOMPARE(sv.size(), 5);
QVERIFY(!sv.empty());
QVERIFY(!sv.isEmpty());
@@ -390,6 +397,24 @@ void tst_QStringView::literals() const
QVERIFY(!sv2.isNull());
QVERIFY(!sv2.empty());
QCOMPARE(sv2.size(), 5);
+
+ QStringView sv3(longhello);
+ QCOMPARE(size_t(sv3.size()), sizeof(longhello)/sizeof(longhello[0]) - 1);
+ QCOMPARE(sv3.last(), QLatin1Char('.'));
+ sv3 = longhello;
+ QCOMPARE(size_t(sv3.size()), sizeof(longhello)/sizeof(longhello[0]) - 1);
+
+ for (int i = 0; i < sv3.size(); ++i) {
+ QStringView sv4(longhello + i);
+ QCOMPARE(size_t(sv4.size()), sizeof(longhello)/sizeof(longhello[0]) - 1 - i);
+ QCOMPARE(sv4.last(), QLatin1Char('.'));
+ sv4 = longhello + i;
+ QCOMPARE(size_t(sv4.size()), sizeof(longhello)/sizeof(longhello[0]) - 1 - i);
+ }
+
+ // these are different results
+ QCOMPARE(size_t(QStringView(withnull).size()), sizeof(withnull)/sizeof(withnull[0]) - 1);
+ QCOMPARE(QStringView(withnull + 0).size(), 1);
}
void tst_QStringView::at() const