summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-03 17:26:31 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-13 01:09:08 +0100
commit0c3a56b621e28648a3bdfdc14bf68df37ea2a126 (patch)
tree38a7de68206e3eb1fae287e83fe2481744404eba /tests/auto
parenta93f07e9773257ac9385b6f7e3ca92df20318450 (diff)
tst_QString/tst_QByteArray: add checks for null-ness
We want to preserve nullness where possible. Test that various ctors do the right thing when presented with null input. Pick-to: 6.3 Change-Id: Ia1a1d4fb3c919b4fed2d9b87827815a1b5072c54 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp33
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp46
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index ae65b8d27e..b0d9f39b3e 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -95,6 +95,7 @@ private slots:
void number_double();
void number_base_data();
void number_base();
+ void nullness();
void blockSizeCalculations();
void resizeAfterFromRawData();
@@ -1362,6 +1363,38 @@ void tst_QByteArray::number_base()
}
}
+void tst_QByteArray::nullness()
+{
+ {
+ QByteArray ba;
+ QVERIFY(ba.isNull());
+ }
+ {
+ QByteArray ba = nullptr;
+ QVERIFY(ba.isNull());
+ }
+ {
+ const char *ptr = nullptr;
+ QByteArray ba = ptr;
+ QVERIFY(ba.isNull());
+ }
+ {
+ QByteArray ba(nullptr, 0);
+ QVERIFY(ba.isNull());
+ }
+ {
+ const char *ptr = nullptr;
+ QByteArray ba(ptr, 0);
+ QVERIFY(ba.isNull());
+ }
+ {
+ QByteArrayView bav;
+ QVERIFY(bav.isNull());
+ QByteArray ba = bav.toByteArray();
+ QVERIFY(ba.isNull());
+ }
+}
+
static bool checkSize(qsizetype value, qsizetype min)
{
return value >= min && value <= std::numeric_limits<qsizetype>::max();
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 07122f6235..69166ea4f6 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -515,6 +515,7 @@ private slots:
void macTypes();
void isEmpty();
void isNull();
+ void nullness();
void acc_01();
void length_data();
void length();
@@ -1090,6 +1091,51 @@ void tst_QString::isNull()
QT_WARNING_POP
+void tst_QString::nullness()
+{
+ {
+ QString s;
+ QVERIFY(s.isNull());
+ }
+ {
+ QString s = nullptr;
+ QVERIFY(s.isNull());
+ }
+ {
+ const char *ptr = nullptr;
+ QString s = ptr;
+ QVERIFY(s.isNull());
+ }
+#ifdef __cpp_char8_t
+ {
+ const char8_t *ptr = nullptr;
+ QString s = ptr;
+ QVERIFY(s.isNull());
+ }
+#endif
+ {
+ QString s(nullptr, 0);
+ QVERIFY(s.isNull());
+ }
+ {
+ const QChar *ptr = nullptr;
+ QString s(ptr, 0);
+ QVERIFY(s.isNull());
+ }
+ {
+ QLatin1String l1;
+ QVERIFY(l1.isNull());
+ QString s = l1;
+ QVERIFY(s.isNull());
+ }
+ {
+ QStringView sv;
+ QVERIFY(sv.isNull());
+ QString s = sv.toString();
+ QVERIFY(s.isNull());
+ }
+}
+
void tst_QString::isEmpty()
{
QString a;