Skip to content

Commit

Permalink
QJniArray: add test case for QJniArray::size
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vohi committed Jan 23, 2024
1 parent 2a832b4 commit 2c9525a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/corelib/kernel/qjniarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QtCore/qjniobject.h>

#include <utility>
#include <type_traits>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -87,7 +88,7 @@ class QJniArrayBase : public QJniObject
>
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));
Expand Down
15 changes: 15 additions & 0 deletions tests/auto/corelib/kernel/qjniarray/tst_qjniarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class tst_QJniArray : public QObject

public:
tst_QJniArray() = default;

private slots:
void size();
};

using namespace QtJniTypes;
Expand Down Expand Up @@ -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"

0 comments on commit 2c9525a

Please sign in to comment.