summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qjniobject
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-07-08 12:31:36 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-07-12 13:25:04 +0200
commit7b6350fa7743fa4ca10f5aebe0962b6544604e33 (patch)
treeef89bf9d601538fc85369dcf450079236ddcfb1d /tests/auto/corelib/kernel/qjniobject
parent1c563035c7b66349018898cb880ffef8c002a545 (diff)
QJniObject: Add template overloads for get/setStaticField
Allow specifying the Java class on which to set/get the field via its corresponding C++ type, removing the need to explicitly provide the Java type string. Those were missing from a085a14d76553ebd1fa4a4a11a27110ee544a531, which was noticed when porting QtConnectivity over to the new template APIs. Pick-to: 6.4 Change-Id: I8f324c9fcc486b4c6c2f2b9051f7eca0cbec0e91 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qjniobject')
-rw-r--r--tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
index e57785c5c5..7ea6b1e121 100644
--- a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
+++ b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
@@ -9,6 +9,7 @@
#include <QtTest>
static const char testClassName[] = "org/qtproject/qt/android/testdatapackage/QtJniObjectTestClass";
+Q_DECLARE_JNI_CLASS(QtJniObjectTestClass, testClassName)
static const jbyte A_BYTE_VALUE = 127;
static const jshort A_SHORT_VALUE = 32767;
@@ -1035,6 +1036,12 @@ void setStaticField(const char *fieldName, T testValue)
T res = QJniObject::getStaticField<T>(testClassName, fieldName);
QCOMPARE(res, testValue);
+
+ // use template overload to reset to default
+ T defaultValue = {};
+ QJniObject::setStaticField<QtJniTypes::QtJniObjectTestClass, T>(fieldName, defaultValue);
+ res = QJniObject::getStaticField<QtJniTypes::QtJniObjectTestClass, T>(fieldName);
+ QCOMPARE(res, defaultValue);
}
void tst_QJniObject::setStaticIntField()