Add compile-time checks for QLatin1String

Change-Id: If1b10a857275fb53c5d0b230bf6d11ce3e1ff2ca
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Sona Kurazyan 2022-02-25 10:35:06 +01:00
parent 62c7145390
commit e4aa4d4f3d

View File

@ -44,6 +44,7 @@ class tst_QLatin1String : public QObject
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void constExpr();
void construction(); void construction();
void at(); void at();
void arg() const; void arg() const;
@ -55,6 +56,65 @@ private Q_SLOTS:
void relationalOperators(); void relationalOperators();
}; };
void tst_QLatin1String::constExpr()
{
// compile-time checks
{
constexpr QLatin1String l1s;
static_assert(l1s.size() == 0);
static_assert(l1s.isNull());
static_assert(l1s.empty());
static_assert(l1s.isEmpty());
static_assert(l1s.latin1() == nullptr);
constexpr QLatin1String l1s2(l1s.latin1(), l1s.latin1() + l1s.size());
static_assert(l1s2.isNull());
static_assert(l1s2.empty());
}
{
constexpr QLatin1String l1s = nullptr;
static_assert(l1s.size() == 0);
static_assert(l1s.isNull());
static_assert(l1s.empty());
static_assert(l1s.isEmpty());
static_assert(l1s.latin1() == nullptr);
}
{
constexpr QLatin1String l1s("");
static_assert(l1s.size() == 0);
static_assert(!l1s.isNull());
static_assert(l1s.empty());
static_assert(l1s.isEmpty());
static_assert(l1s.latin1() != nullptr);
constexpr QLatin1String l1s2(l1s.latin1(), l1s.latin1() + l1s.size());
static_assert(!l1s2.isNull());
static_assert(l1s2.empty());
}
{
static_assert(QLatin1String("Hello").size() == 5);
constexpr QLatin1String l1s("Hello");
static_assert(l1s.size() == 5);
static_assert(!l1s.empty());
static_assert(!l1s.isEmpty());
static_assert(!l1s.isNull());
static_assert(*l1s.latin1() == 'H');
static_assert(l1s[0] == QLatin1Char('H'));
static_assert(l1s.at(0) == QLatin1Char('H'));
static_assert(l1s.front() == QLatin1Char('H'));
static_assert(l1s.first() == QLatin1Char('H'));
static_assert(l1s[4] == QLatin1Char('o'));
static_assert(l1s.at(4) == QLatin1Char('o'));
static_assert(l1s.back() == QLatin1Char('o'));
static_assert(l1s.last() == QLatin1Char('o'));
constexpr QLatin1String l1s2(l1s.latin1(), l1s.latin1() + l1s.size());
static_assert(!l1s2.isNull());
static_assert(!l1s2.empty());
static_assert(l1s2.size() == 5);
}
}
void tst_QLatin1String::construction() void tst_QLatin1String::construction()
{ {
{ {