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>
bb10
Marc Mutz 2022-01-03 17:26:31 +01:00
parent a93f07e977
commit 0c3a56b621
2 changed files with 79 additions and 0 deletions

View File

@ -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();

View File

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