From 218daa6f777a1ff8be7a08abb91a887ff876ad12 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 21 Sep 2023 21:03:01 +0200 Subject: [PATCH] JNI: harden QJniObject test case Fail the test when an unexpected warning message about a field, class, or method not being found is generated from a JNI exception. Fix the failure when trying to look-up a boolean field that is no longer available, and ignore the one expected message from looking up an unavailable class explicitly. Change-Id: Ic5e4c003c64272f06a6d4da028e232abba75c4e4 Reviewed-by: Zoltan Gera Reviewed-by: Juha Vuolle --- .../corelib/kernel/qjniobject/tst_qjniobject.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp index 3d8c15d0b0f..6f690f0091f 100644 --- a/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp +++ b/tests/auto/corelib/kernel/qjniobject/tst_qjniobject.cpp @@ -35,6 +35,7 @@ public: private slots: void initTestCase(); + void init(); void ctor(); void callMethodTest(); @@ -121,6 +122,14 @@ void tst_QJniObject::initTestCase() { } +void tst_QJniObject::init() +{ + // Unless explicitly ignored to test error handling, warning messages + // in this test about a failure to look up a field, method, or class + // make the test fail. + QTest::failOnWarning(QRegularExpression("java.lang.NoSuch.*Error")); +} + void tst_QJniObject::cleanupTestCase() { } @@ -992,7 +1001,7 @@ void tst_QJniObject::getBooleanField() QJniObject obj("org/qtproject/qt/android/QtActivityDelegate"); QVERIFY(obj.isValid()); - QVERIFY(!obj.getField("m_fullScreen")); + QVERIFY(!obj.getField("m_backKeyPressedSent")); } void tst_QJniObject::getIntField() @@ -1555,6 +1564,7 @@ void tst_QJniObject::templateApiCheck() void tst_QJniObject::isClassAvailable() { QVERIFY(QJniObject::isClassAvailable("java/lang/String")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.ClassNotFoundException")); QVERIFY(!QJniObject::isClassAvailable("class/not/Available")); QVERIFY(QJniObject::isClassAvailable("org/qtproject/qt/android/QtActivityDelegate")); }