tst_qvarlengtharray: add test for QVLA(n) ctor
Also add one for types that are neither copy- nor move-constructible. In contrast to resize(n), the QVLA(n) ctor worked for such types, so make sure it stays that way. Pick-to: 6.5 6.4 6.4.3 6.2 5.15 Change-Id: If54fbc9dd6a4808175c4bcb0ffb492b33c879746 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
a02fb41c8e
commit
e7c792ba71
@ -42,12 +42,29 @@ public:
|
|||||||
{ return !operator==(lhs, rhs); }
|
{ return !operator==(lhs, rhs); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NonCopyable
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY(NonCopyable)
|
||||||
|
int n;
|
||||||
|
public:
|
||||||
|
NonCopyable() : n(0) {}
|
||||||
|
explicit NonCopyable(int n) : n(n) {}
|
||||||
|
|
||||||
|
friend bool operator==(const NonCopyable &lhs, const NonCopyable &rhs) noexcept
|
||||||
|
{ return lhs.n == rhs.n; }
|
||||||
|
friend bool operator!=(const NonCopyable &lhs, const NonCopyable &rhs) noexcept
|
||||||
|
{ return !operator==(lhs, rhs); }
|
||||||
|
};
|
||||||
|
|
||||||
class tst_QVarLengthArray : public QObject
|
class tst_QVarLengthArray : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void defaultConstructor_int() { defaultConstructor<int>(); }
|
void defaultConstructor_int() { defaultConstructor<int>(); }
|
||||||
void defaultConstructor_QString() { defaultConstructor<QString>(); }
|
void defaultConstructor_QString() { defaultConstructor<QString>(); }
|
||||||
|
void sizeConstructor_int() { sizeConstructor<int>(); }
|
||||||
|
void sizeConstructor_QString() { sizeConstructor<QString>(); }
|
||||||
|
void sizeConstructor_NonCopyable() { sizeConstructor<NonCopyable>(); }
|
||||||
void append();
|
void append();
|
||||||
#if QT_DEPRECATED_SINCE(6, 3)
|
#if QT_DEPRECATED_SINCE(6, 3)
|
||||||
void prepend();
|
void prepend();
|
||||||
@ -99,6 +116,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void defaultConstructor();
|
void defaultConstructor();
|
||||||
|
template <typename T>
|
||||||
|
void sizeConstructor();
|
||||||
template <qsizetype N, typename T>
|
template <qsizetype N, typename T>
|
||||||
void move(T t1, T t2);
|
void move(T t1, T t2);
|
||||||
template <qsizetype N>
|
template <qsizetype N>
|
||||||
@ -128,6 +147,31 @@ void tst_QVarLengthArray::defaultConstructor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void tst_QVarLengthArray::sizeConstructor()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
QVarLengthArray<T, 123> vla(0);
|
||||||
|
QCOMPARE(vla.size(), 0);
|
||||||
|
QVERIFY(vla.empty());
|
||||||
|
QVERIFY(vla.isEmpty());
|
||||||
|
QCOMPARE(vla.begin(), vla.end());
|
||||||
|
QCOMPARE(vla.capacity(), 123);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
QVarLengthArray<T, 124> vla(124);
|
||||||
|
QCOMPARE(vla.size(), 124);
|
||||||
|
QVERIFY(!vla.empty());
|
||||||
|
QCOMPARE(vla.capacity(), 124);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
QVarLengthArray<T, 124> vla(125);
|
||||||
|
QCOMPARE(vla.size(), 125);
|
||||||
|
QVERIFY(!vla.empty());
|
||||||
|
QCOMPARE_GE(vla.capacity(), 125);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QVarLengthArray::append()
|
void tst_QVarLengthArray::append()
|
||||||
{
|
{
|
||||||
QVarLengthArray<QString, 2> v;
|
QVarLengthArray<QString, 2> v;
|
||||||
|
Loading…
Reference in New Issue
Block a user