summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-04-30 14:22:39 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-05-17 00:34:06 +0200
commitf6e89e901ba718d64b50f79f3b1b327a7f6a0211 (patch)
tree5a4c7752642f28dd1102fbb74cd83b0856b9115b /tests/auto
parent18a16533b9c8782c5ff642a37dd58f82c1eb881d (diff)
Fold methods for object return type into generic methods
Since we know at compile time whether the return type is an object type, we can use 'if constexpr' and auto return type in the call(Static)Method and get(Static)Field functions to call the object-type methods. This makes the object-methods conceptually obsolete, but don't declare them as deprecated as long as they are still used in submodules to avoid warning floods and build failures in -Werror configurations. Change-Id: Ic3019ed990a9252eefcb02cdb355f8a6ed6bc2ff Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
index 30c71ad798..8faa9b6fbb 100644
--- a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
+++ b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
@@ -201,6 +201,17 @@ void tst_QJniObject::callMethodTest()
jlong ret = longObject.callMethod<jlong>("longValue");
QCOMPARE(ret, jLong);
}
+
+ // as of Qt 6.4, callMethod works with an object type as well!
+ {
+ const QString qString = QLatin1String("Hello, Java");
+ QJniObject jString = QJniObject::fromString(qString);
+ const QString qStringRet = jString.callMethod<jstring>("toUpperCase").toString();
+ QCOMPARE(qString.toUpper(), qStringRet);
+
+ QJniObject subString = jString.callMethod<jstring>("substring", 0, 4);
+ QCOMPARE(subString.toString(), qString.mid(0, 4));
+ }
}
void tst_QJniObject::callObjectMethodTest()
@@ -316,6 +327,17 @@ void tst_QJniObject::callStaticObjectMethod()
returnedString = returnValue.toString();
QCOMPARE(returnedString, QString::fromLatin1("test format"));
+
+ // from 6.4 on we can use callStaticMethod
+ returnValue = QJniObject::callStaticMethod<jstring>(cls,
+ "format",
+ formatString.object<jstring>(),
+ jobjectArray(0));
+ QVERIFY(returnValue.isValid());
+
+ returnedString = returnValue.toString();
+
+ QCOMPARE(returnedString, QString::fromLatin1("test format"));
}
void tst_QJniObject::callStaticObjectMethodById()
@@ -338,6 +360,15 @@ void tst_QJniObject::callStaticObjectMethodById()
QString returnedString = returnValue.toString();
QCOMPARE(returnedString, QString::fromLatin1("test format"));
+
+ // from Qt 6.4 on we can use callStaticMethod as well
+ returnValue = QJniObject::callStaticMethod<jstring>(
+ cls, id, formatString.object<jstring>(), jobjectArray(0));
+ QVERIFY(returnValue.isValid());
+
+ returnedString = returnValue.toString();
+
+ QCOMPARE(returnedString, QString::fromLatin1("test format"));
}
void tst_QJniObject::callStaticBooleanMethod()