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::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;