JNI API review: minor API and implementation cleanups
- prefix ValidField/SignatureTypes predicates with "If" - make QJniArray SMF constexpr and noexcept - remove const from return-by-value QJniArray functions - rename QJniArray::asContainer to toContainer - constrain QJniEnvironment::registerNativeMethods to valid class types - don't home-grow std::forward - make default QtJniTypes::Object constructor implicit - don't include copy/move constructors in QtJniTypes::Object variadic constructor Change-Id: Ied02993d32d8b0f3ef1e571b75ada15ede1f8389 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit a936b86ec8720ac3dc63f9eca0f873b4f86827ce) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
10b480f1d8
commit
7a6359c614
@ -18,10 +18,10 @@ template <typename T> class QJniArray;
|
||||
template <typename T>
|
||||
struct QJniArrayIterator
|
||||
{
|
||||
QJniArrayIterator(const QJniArrayIterator &other) = default;
|
||||
QJniArrayIterator(QJniArrayIterator &&other) noexcept = default;
|
||||
QJniArrayIterator &operator=(const QJniArrayIterator &other) = default;
|
||||
QJniArrayIterator &operator=(QJniArrayIterator &&other) noexcept = default;
|
||||
constexpr QJniArrayIterator(const QJniArrayIterator &other) noexcept = default;
|
||||
constexpr QJniArrayIterator(QJniArrayIterator &&other) noexcept = default;
|
||||
constexpr QJniArrayIterator &operator=(const QJniArrayIterator &other) noexcept = default;
|
||||
constexpr QJniArrayIterator &operator=(QJniArrayIterator &&other) noexcept = default;
|
||||
|
||||
friend bool operator==(const QJniArrayIterator<T> &lhs, const QJniArrayIterator<T> &rhs) noexcept
|
||||
{
|
||||
@ -31,7 +31,7 @@ struct QJniArrayIterator
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
const T operator*() const
|
||||
T operator*() const
|
||||
{
|
||||
return m_array->at(m_index);
|
||||
}
|
||||
@ -196,7 +196,7 @@ public:
|
||||
const_iterator constEnd() const { return {end()}; }
|
||||
const_iterator cend() const { return {end()}; }
|
||||
|
||||
const T operator[](qsizetype i) const { return at(i); } // const return value to disallow assignment
|
||||
T operator[](qsizetype i) const { return at(i); }
|
||||
T at(qsizetype i) const
|
||||
{
|
||||
JNIEnv *env = jniEnv();
|
||||
@ -227,7 +227,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
}
|
||||
auto asContainer() const
|
||||
auto toContainer() const
|
||||
{
|
||||
JNIEnv *env = jniEnv();
|
||||
if constexpr (std::is_same_v<T, jobject>) {
|
||||
@ -337,14 +337,14 @@ namespace QtJniTypes
|
||||
template <typename T> struct IsJniArray: std::false_type {};
|
||||
template <typename T> struct IsJniArray<QJniArray<T>> : std::true_type {};
|
||||
template <typename T> struct Traits<QJniArray<T>> {
|
||||
template <ValidFieldType<T> = true>
|
||||
template <IfValidFieldType<T> = true>
|
||||
static constexpr auto signature()
|
||||
{
|
||||
return CTString("[") + Traits<T>::signature();
|
||||
}
|
||||
};
|
||||
template <typename T> struct Traits<QList<T>> {
|
||||
template <ValidFieldType<T> = true>
|
||||
template <IfValidFieldType<T> = true>
|
||||
static constexpr auto signature()
|
||||
{
|
||||
return CTString("[") + Traits<T>::signature();
|
||||
|
@ -64,7 +64,11 @@ public:
|
||||
return registerNativeMethods(clazz, std::data(methods), methods.size());
|
||||
}
|
||||
|
||||
template<typename Class>
|
||||
template<typename Class
|
||||
#ifndef Q_QDOC
|
||||
, std::enable_if_t<QtJniTypes::isObjectType<Class>(), bool> = true
|
||||
#endif
|
||||
>
|
||||
bool registerNativeMethods(std::initializer_list<JNINativeMethod> methods)
|
||||
{
|
||||
return registerNativeMethods(QtJniTypes::Traits<Class>::className().data(), methods);
|
||||
|
@ -116,7 +116,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<Ret> = true
|
||||
, QtJniTypes::IfValidFieldType<Ret> = true
|
||||
#endif
|
||||
>
|
||||
auto callMethod(const char *methodName, const char *signature, Args &&...args) const
|
||||
@ -148,7 +148,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
auto callMethod(const char *methodName, Args &&...args) const
|
||||
@ -159,7 +159,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
QJniObject callObjectMethod(const char *methodName, Args &&...args) const
|
||||
@ -192,7 +192,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<Ret> = true
|
||||
, QtJniTypes::IfValidFieldType<Ret> = true
|
||||
#endif
|
||||
>
|
||||
static auto callStaticMethod(jclass clazz, jmethodID methodId, Args &&...args)
|
||||
@ -223,7 +223,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
static auto callStaticMethod(const char *className, const char *methodName, Args &&...args)
|
||||
@ -238,7 +238,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
static auto callStaticMethod(jclass clazz, const char *methodName, Args &&...args)
|
||||
@ -248,7 +248,7 @@ public:
|
||||
}
|
||||
template <typename Klass, typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
static auto callStaticMethod(const char *methodName, Args &&...args)
|
||||
@ -273,7 +273,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
static QJniObject callStaticObjectMethod(const char *className, const char *methodName, Args &&...args)
|
||||
@ -287,7 +287,7 @@ public:
|
||||
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
static QJniObject callStaticObjectMethod(jclass clazz, const char *methodName, Args &&...args)
|
||||
@ -301,7 +301,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
auto getField(const char *fieldName) const
|
||||
@ -324,7 +324,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static auto getStaticField(const char *className, const char *fieldName)
|
||||
@ -342,7 +342,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static auto getStaticField(jclass clazz, const char *fieldName)
|
||||
@ -365,7 +365,7 @@ public:
|
||||
|
||||
template <typename Klass, typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static auto getStaticField(const char *fieldName)
|
||||
@ -417,7 +417,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
void setField(const char *fieldName, T value)
|
||||
@ -432,7 +432,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
void setField(const char *fieldName, const char *signature, T value)
|
||||
@ -446,7 +446,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static void setStaticField(const char *className, const char *fieldName, T value)
|
||||
@ -468,7 +468,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static void setStaticField(const char *className, const char *fieldName,
|
||||
@ -490,7 +490,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static void setStaticField(jclass clazz, const char *fieldName,
|
||||
@ -507,7 +507,7 @@ public:
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static void setStaticField(jclass clazz, const char *fieldName, T value)
|
||||
@ -517,7 +517,7 @@ public:
|
||||
|
||||
template <typename Klass, typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static void setStaticField(const char *fieldName, T value)
|
||||
@ -793,7 +793,7 @@ auto QJniObject::LocalFrame<Args...>::convertToJni(T &&value)
|
||||
} else if constexpr (std::is_base_of_v<QJniObject, Type>) {
|
||||
return value.object();
|
||||
} else {
|
||||
return static_cast<T &&>(value);
|
||||
return std::forward<T>(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -812,7 +812,7 @@ auto QJniObject::LocalFrame<Args...>::convertFromJni(QJniObject &&object)
|
||||
// then that QJniArray would have elements of type
|
||||
using ElementType = typename QJniArrayType::Type;
|
||||
// construct a QJniArray from a jobject pointer of that type
|
||||
return QJniArray<ElementType>(object.template object<jarray>()).asContainer();
|
||||
return QJniArray<ElementType>(object.template object<jarray>()).toContainer();
|
||||
} else if constexpr (std::is_array_v<Type>) {
|
||||
using ElementType = std::remove_extent_t<Type>;
|
||||
return QJniArray<ElementType>{object};
|
||||
|
@ -34,12 +34,17 @@ struct Object : QJniObject
|
||||
// avoid ambiguities with deleted const char * constructor
|
||||
Q_IMPLICIT Object(std::nullptr_t) : QJniObject() {}
|
||||
|
||||
// this intentionally includes the default constructor
|
||||
template<typename ...Args
|
||||
, ValidSignatureTypes<Args...> = true
|
||||
Object()
|
||||
: QJniObject(QtJniTypes::Traits<Class>::className())
|
||||
{}
|
||||
|
||||
template<typename Arg, typename ...Args
|
||||
, std::enable_if_t<!std::is_same_v<Arg, Object>, bool> = true
|
||||
, IfValidSignatureTypes<Arg, Args...> = true
|
||||
>
|
||||
explicit Object(Args &&...args)
|
||||
: QJniObject(QtJniTypes::Traits<Class>::className(), std::forward<Args>(args)...)
|
||||
explicit Object(Arg && arg, Args &&...args)
|
||||
: QJniObject(QtJniTypes::Traits<Class>::className(), std::forward<Arg>(arg),
|
||||
std::forward<Args>(args)...)
|
||||
{}
|
||||
|
||||
// named constructors avoid ambiguities
|
||||
@ -56,7 +61,7 @@ struct Object : QJniObject
|
||||
// public API forwarding to QJniObject, with the implicit Class template parameter
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
static auto callStaticMethod(const char *name, Args &&...args)
|
||||
@ -66,7 +71,7 @@ struct Object : QJniObject
|
||||
}
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static auto getStaticField(const char *field)
|
||||
@ -75,7 +80,7 @@ struct Object : QJniObject
|
||||
}
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
static void setStaticField(const char *field, T &&value)
|
||||
@ -86,7 +91,7 @@ struct Object : QJniObject
|
||||
// keep only these overloads, the rest is made private
|
||||
template <typename Ret, typename ...Args
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidSignatureTypes<Ret, Args...> = true
|
||||
, QtJniTypes::IfValidSignatureTypes<Ret, Args...> = true
|
||||
#endif
|
||||
>
|
||||
auto callMethod(const char *method, Args &&...args) const
|
||||
@ -95,7 +100,7 @@ struct Object : QJniObject
|
||||
}
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
auto getField(const char *fieldName) const
|
||||
@ -105,7 +110,7 @@ struct Object : QJniObject
|
||||
|
||||
template <typename T
|
||||
#ifndef Q_QDOC
|
||||
, QtJniTypes::ValidFieldType<T> = true
|
||||
, QtJniTypes::IfValidFieldType<T> = true
|
||||
#endif
|
||||
>
|
||||
void setField(const char *fieldName, T &&value)
|
||||
|
@ -156,7 +156,7 @@ struct Traits {
|
||||
// The return type of className/signature becomes void for any type
|
||||
// not handled here. This indicates that the Traits type is not specialized
|
||||
// for the respective type, which we use to detect invalid types in the
|
||||
// ValidSignatureTypes and ValidFieldType predicates below.
|
||||
// IfValidSignatureTypes and IfValidFieldType predicates below.
|
||||
|
||||
static constexpr auto className()
|
||||
{
|
||||
@ -281,17 +281,17 @@ constexpr bool ValidSignatureTypesDetail = !std::disjunction<std::is_same<
|
||||
void>...,
|
||||
IsStringType<Types>...>::value;
|
||||
template<typename ...Types>
|
||||
using ValidSignatureTypes = std::enable_if_t<
|
||||
using IfValidSignatureTypes = std::enable_if_t<
|
||||
ValidSignatureTypesDetail<q20::remove_cvref_t<Types>...>, bool>;
|
||||
|
||||
template<typename Type>
|
||||
constexpr bool ValidFieldTypeDetail = isObjectType<Type>() || isPrimitiveType<Type>();
|
||||
template<typename Type>
|
||||
using ValidFieldType = std::enable_if_t<
|
||||
using IfValidFieldType = std::enable_if_t<
|
||||
ValidFieldTypeDetail<q20::remove_cvref_t<Type>>, bool>;
|
||||
|
||||
|
||||
template<typename R, typename ...Args, ValidSignatureTypes<R, Args...> = true>
|
||||
template<typename R, typename ...Args, IfValidSignatureTypes<R, Args...> = true>
|
||||
static constexpr auto methodSignature()
|
||||
{
|
||||
return (CTString("(") +
|
||||
@ -300,25 +300,25 @@ static constexpr auto methodSignature()
|
||||
+ Traits<R>::signature();
|
||||
}
|
||||
|
||||
template<typename T, ValidSignatureTypes<T> = true>
|
||||
template<typename T, IfValidSignatureTypes<T> = true>
|
||||
static constexpr auto fieldSignature()
|
||||
{
|
||||
return QtJniTypes::Traits<T>::signature();
|
||||
}
|
||||
|
||||
template<typename ...Args, ValidSignatureTypes<Args...> = true>
|
||||
template<typename ...Args, IfValidSignatureTypes<Args...> = true>
|
||||
static constexpr auto constructorSignature()
|
||||
{
|
||||
return methodSignature<void, Args...>();
|
||||
}
|
||||
|
||||
template<typename Ret, typename ...Args, ValidSignatureTypes<Ret, Args...> = true>
|
||||
template<typename Ret, typename ...Args, IfValidSignatureTypes<Ret, Args...> = true>
|
||||
static constexpr auto nativeMethodSignature(Ret (*)(JNIEnv *, jobject, Args...))
|
||||
{
|
||||
return methodSignature<Ret, Args...>();
|
||||
}
|
||||
|
||||
template<typename Ret, typename ...Args, ValidSignatureTypes<Ret, Args...> = true>
|
||||
template<typename Ret, typename ...Args, IfValidSignatureTypes<Ret, Args...> = true>
|
||||
static constexpr auto nativeMethodSignature(Ret (*)(JNIEnv *, jclass, Args...))
|
||||
{
|
||||
return methodSignature<Ret, Args...>();
|
||||
|
@ -1550,13 +1550,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jboolean[]>("staticBooleanArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jboolean>{true, true, true}));
|
||||
QCOMPARE(array.toContainer(), (QList<jboolean>{true, true, true}));
|
||||
|
||||
QJniArray<jboolean> newArray(QList<jboolean>{true, false, false});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jboolean[]>("staticReverseBooleanArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jboolean>{false, false, true}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jboolean>{false, false, true}));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1566,13 +1566,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jboolean[]>("booleanArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jboolean>{true, true, true}));
|
||||
QCOMPARE(array.toContainer(), (QList<jboolean>{true, true, true}));
|
||||
|
||||
QJniArray<jboolean> newArray(QList<jboolean>{true, false, false});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jboolean[]>("reverseBooleanArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jboolean>{false, false, true}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jboolean>{false, false, true}));
|
||||
}
|
||||
|
||||
// jbyteArray ---------------------------------------------------------------------------------
|
||||
@ -1584,13 +1584,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jbyte[]>("staticByteArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), "abc");
|
||||
QCOMPARE(array.toContainer(), "abc");
|
||||
|
||||
QJniArray<jbyte> newArray(QByteArray{"cba"});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jbyte[]>("staticReverseByteArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), "abc");
|
||||
QCOMPARE(reverse.toContainer(), "abc");
|
||||
|
||||
const QByteArray reverse2 = TestClass::callStaticMethod<QByteArray>("staticReverseByteArray",
|
||||
QByteArray("abc"));
|
||||
@ -1604,13 +1604,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jbyte[]>("byteArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), "abc");
|
||||
QCOMPARE(array.toContainer(), "abc");
|
||||
|
||||
QJniArray<jbyte> newArray = QJniArrayBase::fromContainer(QByteArray{"cba"});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jbyte[]>("reverseByteArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), "abc");
|
||||
QCOMPARE(reverse.toContainer(), "abc");
|
||||
}
|
||||
|
||||
// jcharArray ---------------------------------------------------------------------------------
|
||||
@ -1622,13 +1622,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jchar[]>("staticCharArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
QCOMPARE(array.toContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
|
||||
QJniArray<jchar> newArray(QList<jchar>{u'c', u'b', u'a'});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jchar[]>("staticReverseCharArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
|
||||
const QList<jchar> reverse2 = TestClass::callStaticMethod<QList<jchar>>("staticReverseCharArray",
|
||||
(QList<jchar>{u'c', u'b', u'a'}));
|
||||
@ -1642,13 +1642,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jchar[]>("charArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
QCOMPARE(array.toContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
|
||||
QJniArray<jchar> newArray = QJniArrayBase::fromContainer(QList<jchar>{u'c', u'b', u'a'});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jchar[]>("reverseCharArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jchar>{u'a', u'b', u'c'}));
|
||||
}
|
||||
|
||||
// jshortArray --------------------------------------------------------------------------------
|
||||
@ -1660,13 +1660,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jshort[]>("staticShortArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jshort>{3, 2, 1}));
|
||||
QCOMPARE(array.toContainer(), (QList<jshort>{3, 2, 1}));
|
||||
|
||||
QJniArray<jshort> newArray(QList<jshort>{3, 2, 1});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jshort[]>("staticReverseShortArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jshort>{1, 2, 3}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jshort>{1, 2, 3}));
|
||||
|
||||
const QList<jshort> reverse2 = TestClass::callStaticMethod<QList<jshort>>("staticReverseShortArray",
|
||||
(QList<jshort>{1, 2, 3}));
|
||||
@ -1680,14 +1680,14 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jshort[]>("shortArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jshort>{3, 2, 1}));
|
||||
QCOMPARE(array.toContainer(), (QList<jshort>{3, 2, 1}));
|
||||
|
||||
QJniArray<jshort> newArray = QJniArrayBase::fromContainer(QList<jshort>{3, 2, 1});
|
||||
static_assert(std::is_same_v<decltype(newArray)::Type, jshort>);
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jshort[]>("reverseShortArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jshort>{1, 2, 3}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jshort>{1, 2, 3}));
|
||||
}
|
||||
|
||||
// jintArray ----------------------------------------------------------------------------------
|
||||
@ -1699,13 +1699,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jint[]>("staticIntArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jint>{3, 2, 1}));
|
||||
QCOMPARE(array.toContainer(), (QList<jint>{3, 2, 1}));
|
||||
|
||||
QJniArray<jint> newArray(QList<jint>{3, 2, 1});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jint[]>("staticReverseIntArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jint>{1, 2, 3}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jint>{1, 2, 3}));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1715,13 +1715,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jint[]>("intArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jint>{3, 2, 1}));
|
||||
QCOMPARE(array.toContainer(), (QList<jint>{3, 2, 1}));
|
||||
|
||||
QJniArray<jint> newArray = QJniArrayBase::fromContainer(QList<jint>{3, 2, 1});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jint[]>("reverseIntArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jint>{1, 2, 3}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jint>{1, 2, 3}));
|
||||
}
|
||||
|
||||
// jlongArray ---------------------------------------------------------------------------------
|
||||
@ -1733,13 +1733,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jlong[]>("staticLongArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jlong>{3, 2, 1}));
|
||||
QCOMPARE(array.toContainer(), (QList<jlong>{3, 2, 1}));
|
||||
|
||||
QJniArray<jlong> newArray(QList<jlong>{3, 2, 1});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jlong[]>("staticReverseLongArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jlong>{1, 2, 3}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jlong>{1, 2, 3}));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1749,13 +1749,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jlong[]>("longArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jlong>{3, 2, 1}));
|
||||
QCOMPARE(array.toContainer(), (QList<jlong>{3, 2, 1}));
|
||||
|
||||
QJniArray<jlong> newArray = QJniArrayBase::fromContainer(QList<jlong>{3, 2, 1});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jlong[]>("reverseLongArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jlong>{1, 2, 3}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jlong>{1, 2, 3}));
|
||||
}
|
||||
|
||||
// jfloatArray --------------------------------------------------------------------------------
|
||||
@ -1767,13 +1767,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jfloat[]>("staticFloatArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
QCOMPARE(array.toContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
|
||||
QJniArray<jfloat> newArray(QList<jfloat>{3.0f, 2.0f, 1.0f});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jfloat[]>("staticReverseFloatArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1783,13 +1783,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jfloat[]>("floatArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
QCOMPARE(array.toContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
|
||||
QJniArray<jfloat> newArray = QJniArrayBase::fromContainer(QList<jfloat>{3.0f, 2.0f, 1.0f});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jfloat[]>("reverseFloatArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jfloat>{1.0f, 2.0f, 3.0f}));
|
||||
}
|
||||
|
||||
// jdoubleArray -------------------------------------------------------------------------------
|
||||
@ -1801,13 +1801,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = TestClass::callStaticMethod<jdouble[]>("staticDoubleArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jdouble>{3.0, 2.0, 1.0}));
|
||||
QCOMPARE(array.toContainer(), (QList<jdouble>{3.0, 2.0, 1.0}));
|
||||
|
||||
QJniArray<jdouble> newArray(QList<jdouble>{3.0, 2.0, 1.0});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = TestClass::callStaticMethod<jdouble[]>("staticReverseDoubleArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jdouble>{1.0, 2.0, 3.0}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jdouble>{1.0, 2.0, 3.0}));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1817,13 +1817,13 @@ void tst_QJniObject::templateApiCheck()
|
||||
const auto array = testClass.callMethod<jdouble[]>("doubleArrayMethod");
|
||||
QVERIFY(array.isValid());
|
||||
QCOMPARE(array.size(), 3);
|
||||
QCOMPARE(array.asContainer(), (QList<jdouble>{3.0, 2.0, 1.0}));
|
||||
QCOMPARE(array.toContainer(), (QList<jdouble>{3.0, 2.0, 1.0}));
|
||||
|
||||
QJniArray<jdouble> newArray = QJniArrayBase::fromContainer(QList<jdouble>{3.0, 2.0, 1.0});
|
||||
QVERIFY(newArray.isValid());
|
||||
const auto reverse = testClass.callMethod<jdouble[]>("reverseDoubleArray", newArray);
|
||||
QVERIFY(reverse.isValid());
|
||||
QCOMPARE(reverse.asContainer(), (QList<jdouble>{1.0, 2.0, 3.0}));
|
||||
QCOMPARE(reverse.toContainer(), (QList<jdouble>{1.0, 2.0, 3.0}));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user