summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-10-16 17:21:08 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-10-18 15:02:22 +0200
commitb7a7351767bc58bc7e8719972e309a1e9f23967c (patch)
treeda52fd46f22c1c07e3bca43f02bedafb2c5bb038 /tests/auto/corelib/kernel
parent872f7b0b4e7ddfbbe96612c4470466681df41aba (diff)
JNI: treat equivalent C++ types as the same JNI types as well
Our signature mapping treats both e.g. bool and jboolean as "Z", and it is allowed to pass a bool variable as an argument to a function expecting a jboolean. Except for fields and callMethod return values, where we only allowed the JNI primitive types. Fix this by comparing the signatures and size of the type we have with the JNI types that there are explicit functions for. Cast from and to the JNI type in both directions to address narrowing (e.g. jboolean is an unsigned char and converting to bool would be narrowing, even though both are 8bit types). This way we can get boolean fields using getField<bool>, and int fields using getField<int> etc. Change-Id: I2f1ba855ee01423e79ba999dfb9d86f4b98b1402 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
index 751e5a84d8..364b0c5d62 100644
--- a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
+++ b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
@@ -77,6 +77,7 @@ private slots:
void getStaticIntField();
void getStaticByteFieldClassName();
void getStaticByteField();
+ void getStaticBooleanField();
void getStaticLongFieldClassName();
void getStaticLongField();
void getStaticDoubleFieldClassName();
@@ -936,6 +937,12 @@ void tst_QJniObject::getStaticByteField()
QCOMPARE(e, Enum::MAX_VALUE);
}
+void tst_QJniObject::getStaticBooleanField()
+{
+ QCOMPARE(TestClass::getStaticField<jboolean>("S_BOOLEAN_VAR"),
+ TestClass::getStaticField<bool>("S_BOOLEAN_VAR"));
+}
+
void tst_QJniObject::getStaticLongFieldClassName()
{
jlong i = QJniObject::getStaticField<jlong>("java/lang/Long", "MAX_VALUE");
@@ -1038,6 +1045,7 @@ void tst_QJniObject::getBooleanField()
QVERIFY(obj.isValid());
QVERIFY(obj.getField<jboolean>("BOOL_FIELD"));
+ QVERIFY(obj.getField<bool>("BOOL_FIELD"));
}
void tst_QJniObject::getIntField()
@@ -1109,6 +1117,7 @@ void tst_QJniObject::setCharField()
void tst_QJniObject::setBooleanField()
{
setField("BOOLEAN_VAR", jboolean(true));
+ setField("BOOLEAN_VAR", true);
}
void tst_QJniObject::setObjectField()
@@ -1191,6 +1200,7 @@ void tst_QJniObject::setStaticCharField()
void tst_QJniObject::setStaticBooleanField()
{
setStaticField("S_BOOLEAN_VAR", jboolean(true));
+ setStaticField("S_BOOLEAN_VAR", true);
}
void tst_QJniObject::setStaticObjectField()