QJniArray: add test case for QJniArray::size

Fix build of the test by removing the reference from the
container type before accessing the nested typedef.

Pick-to: 6.7
Change-Id: Ic35f312bac70b8f8f80149a3432329070c8c8c7d
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Volker Hilsheimer 2024-01-22 13:22:25 +01:00
parent 2a832b40af
commit 2c9525a501
2 changed files with 17 additions and 1 deletions

View File

@ -11,6 +11,7 @@
#include <QtCore/qjniobject.h>
#include <utility>
#include <type_traits>
QT_BEGIN_NAMESPACE
@ -87,7 +88,7 @@ public:
>
static auto fromContainer(Container &&container)
{
using ElementType = typename Container::value_type;
using ElementType = typename std::remove_reference_t<Container>::value_type;
if constexpr (std::disjunction_v<std::is_same<ElementType, jobject>,
std::is_same<ElementType, QJniObject>>) {
return makeObjectArray(std::forward<Container>(container));

View File

@ -14,6 +14,9 @@ class tst_QJniArray : public QObject
public:
tst_QJniArray() = default;
private slots:
void size();
};
using namespace QtJniTypes;
@ -70,6 +73,18 @@ VERIFY_RETURN_FOR_TYPE(QList<double>, QList<double>);
VERIFY_RETURN_FOR_TYPE(QString, QString);
void tst_QJniArray::size()
{
QJniArray<jint> array;
QVERIFY(!array.isValid());
QCOMPARE(array.size(), 0);
QList<int> intList;
intList.resize(10);
auto intArray = QJniArrayBase::fromContainer(intList);
QCOMPARE(intArray.size(), 10);
}
QTEST_MAIN(tst_QJniArray)
#include "tst_qjniarray.moc"