summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-09-12 17:52:25 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-09-22 07:18:21 +0200
commitcf0bd543d6d410ada24fd375f224aeafd65f5bbf (patch)
tree8e658cae8e9662e3c2691a7f19985d4324b381fe /tests/auto/corelib/kernel
parente1a349983c93143211342d34c458d2bb06986971 (diff)
QJniObject: add callStaticMethod overload that takes class as type
Equivalent to get/setStaticField. Add a test, and tighten up the surrounding test code a bit. Change-Id: Ic0993c5d6223f4de271cb01baf727459b5167f94 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io> Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
index 7ea6b1e121..b524997961 100644
--- a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
+++ b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp
@@ -8,6 +8,8 @@
#include <QtCore/QJniObject>
#include <QtTest>
+using namespace Qt::StringLiterals;
+
static const char testClassName[] = "org/qtproject/qt/android/testdatapackage/QtJniObjectTestClass";
Q_DECLARE_JNI_CLASS(QtJniObjectTestClass, testClassName)
@@ -310,7 +312,8 @@ void tst_QJniObject::callStaticObjectMethod()
jclass cls = env->FindClass("java/lang/String");
QVERIFY(cls != 0);
- QJniObject formatString = QJniObject::fromString(QLatin1String("test format"));
+ const QString string = u"test format"_s;
+ QJniObject formatString = QJniObject::fromString(string);
QVERIFY(formatString.isValid());
QJniObject returnValue = QJniObject::callStaticObjectMethod(cls,
@@ -319,20 +322,14 @@ void tst_QJniObject::callStaticObjectMethod()
formatString.object<jstring>(),
jobjectArray(0));
QVERIFY(returnValue.isValid());
-
- QString returnedString = returnValue.toString();
-
- QCOMPARE(returnedString, QString::fromLatin1("test format"));
+ QCOMPARE(returnValue.toString(), string);
returnValue = QJniObject::callStaticObjectMethod<jstring>(cls,
"format",
formatString.object<jstring>(),
jobjectArray(0));
QVERIFY(returnValue.isValid());
-
- returnedString = returnValue.toString();
-
- QCOMPARE(returnedString, QString::fromLatin1("test format"));
+ QCOMPARE(returnValue.toString(), string);
// from 6.4 on we can use callStaticMethod
returnValue = QJniObject::callStaticMethod<jstring>(cls,
@@ -340,10 +337,15 @@ void tst_QJniObject::callStaticObjectMethod()
formatString.object<jstring>(),
jobjectArray(0));
QVERIFY(returnValue.isValid());
+ QCOMPARE(returnValue.toString(), string);
- returnedString = returnValue.toString();
+ // from 6.7 we can use callStaticMethod without specifying the class string
+ returnValue = QJniObject::callStaticMethod<jstring, jstring>("format",
+ formatString.object<jstring>(),
+ jobjectArray(0));
+ QVERIFY(returnValue.isValid());
+ QCOMPARE(returnValue.toString(), string);
- QCOMPARE(returnedString, QString::fromLatin1("test format"));
}
void tst_QJniObject::callStaticObjectMethodById()