From 2c9525a501a33b880e49b57a7c5fa5f11d70bc0c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 22 Jan 2024 13:22:25 +0100 Subject: [PATCH] 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 --- src/corelib/kernel/qjniarray.h | 3 ++- .../corelib/kernel/qjniarray/tst_qjniarray.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qjniarray.h b/src/corelib/kernel/qjniarray.h index d690137ac06..0fec3d094ec 100644 --- a/src/corelib/kernel/qjniarray.h +++ b/src/corelib/kernel/qjniarray.h @@ -11,6 +11,7 @@ #include #include +#include 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::value_type; if constexpr (std::disjunction_v, std::is_same>) { return makeObjectArray(std::forward(container)); diff --git a/tests/auto/corelib/kernel/qjniarray/tst_qjniarray.cpp b/tests/auto/corelib/kernel/qjniarray/tst_qjniarray.cpp index fa0da3ca664..3d2fb662418 100644 --- a/tests/auto/corelib/kernel/qjniarray/tst_qjniarray.cpp +++ b/tests/auto/corelib/kernel/qjniarray/tst_qjniarray.cpp @@ -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, QList); VERIFY_RETURN_FOR_TYPE(QString, QString); +void tst_QJniArray::size() +{ + QJniArray array; + QVERIFY(!array.isValid()); + QCOMPARE(array.size(), 0); + + QList intList; + intList.resize(10); + auto intArray = QJniArrayBase::fromContainer(intList); + QCOMPARE(intArray.size(), 10); +} + QTEST_MAIN(tst_QJniArray) #include "tst_qjniarray.moc"