summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-01-24 13:38:26 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-20 15:51:06 +0000
commit096e934e5bc7a11e04e1c576ba47a78848d784f4 (patch)
treef54d40288caf5fd6e92518285b2dfd4484aaeed9 /tests
parent561b48c76bbcd7cf2cd70580cdba6bd318f15b8f (diff)
downloadqtbase-096e934e5bc7a11e04e1c576ba47a78848d784f4.tar.gz
QString: build tst_QString::contructor() without ASCII casts [12/13]
Constructing from const char* etc is already covered by constructorQByteArray. I took a guess that the "// b(10)" comment is about testing constructing a QString from a QChar[] that has an explicit \0 charcater. I tried finding what the initial intent was but the trail went cold at the "Initial import from the monolithic Qt" commit. Change-Id: I15bcdb24e55286eb6cd3056af0714a1eed581635 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit ff7848318f565a55b914cd4ac79651f3650efaad) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp61
1 files changed, 37 insertions, 24 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index d891f834f1..1179e9f8a3 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -1213,38 +1213,51 @@ void tst_QString::isEmpty()
void tst_QString::constructor()
{
- QString a;
- QString b; //b(10);
- QString c("String C");
- QChar tmp[10];
- tmp[0] = 'S';
- tmp[1] = 't';
- tmp[2] = 'r';
- tmp[3] = 'i';
- tmp[4] = 'n';
- tmp[5] = 'g';
- tmp[6] = ' ';
- tmp[7] = 'D';
- tmp[8] = 'X';
- tmp[9] = '\0';
- QString d(tmp,8);
- QString ca(a);
- QString cb(b);
- QString cc(c);
+ // String literal with explicit \0 character
+ static constexpr char16_t utf16[] = u"String DX\u0000";
+ const int size_minus_null_terminator = std::size(utf16) - 1;
+ const auto *qchar = reinterpret_cast<const QChar *>(utf16);
+
+ // Up to but not including the explicit \0 in utf16[]
+ QString b1(qchar);
+ QCOMPARE(b1, u"String DX");
+ // Up to and including the explicit \0 in utf16[]
+ QString b2(qchar, size_minus_null_terminator);
+ QCOMPARE(b2, QStringView(utf16, size_minus_null_terminator));
- QCOMPARE(a,ca);
+ QString a;
+ QString a_copy(a);
+ QCOMPARE(a, a_copy);
QVERIFY(a.isNull());
- QVERIFY(a == (QString)"");
- QCOMPARE(b,cb);
- QCOMPARE(c,cc);
- QCOMPARE(d, QLatin1String("String D"));
+ QCOMPARE(a, u""_s);
+
+ QString c(u"String C"_s);
+ QString c_copy(c);
+ QCOMPARE(c, c_copy);
+
+ QString e(QLatin1StringView("String E"));
+ QString e_copy(e);
+ QCOMPARE(e, e_copy);
+ QCOMPARE(e, "String E"_L1);
+
+ QString d(qchar, 8);
+ QCOMPARE(d, "String D"_L1);
QString nullStr;
QVERIFY( nullStr.isNull() );
QVERIFY( nullStr.isEmpty() );
- QString empty("");
+
+ QString empty(u""_s);
QVERIFY( !empty.isNull() );
QVERIFY( empty.isEmpty() );
+
+ empty = QString::fromLatin1("");
+ QVERIFY(!empty.isNull());
+ QVERIFY(empty.isEmpty());
+
+ empty = QString::fromUtf8("");
+ QVERIFY(!empty.isNull());
+ QVERIFY(empty.isEmpty());
}
#ifndef QT_RESTRICTED_CAST_FROM_ASCII