diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-09-27 10:21:10 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-10-05 19:50:33 +0200 |
commit | fd4319700f1919b9a80cdfaf49167a271483e81b (patch) | |
tree | ac4a20b526aca970569f39f0f17a5b73d1426ef2 /tests/auto/corelib/kernel | |
parent | c3986032a8d74f62447a3a9c9fd8bd96ea030012 (diff) |
JNI: Silence and harden QJniEnvironment test
Ignore expected warning messages when looking up classes, methods, or
field that don't exist. Make the test implicitly fail for any other
warning messages.
Change-Id: I79ec799102b1ab9424aa39c5255413931b8ad152
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qjnienvironment/tst_qjnienvironment.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qjnienvironment/tst_qjnienvironment.cpp b/tests/auto/corelib/kernel/qjnienvironment/tst_qjnienvironment.cpp index da72b6d32b..60837c95e1 100644 --- a/tests/auto/corelib/kernel/qjnienvironment/tst_qjnienvironment.cpp +++ b/tests/auto/corelib/kernel/qjnienvironment/tst_qjnienvironment.cpp @@ -20,6 +20,7 @@ class tst_QJniEnvironment : public QObject Q_OBJECT private slots: + void init(); void jniEnv(); void javaVM(); void registerNativeMethods(); @@ -30,6 +31,14 @@ private slots: void findStaticField(); }; +void tst_QJniEnvironment::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_QJniEnvironment::jniEnv() { QJniEnvironment env; @@ -59,6 +68,7 @@ void tst_QJniEnvironment::jniEnv() QVERIFY(!QJniEnvironment::checkAndClearExceptions(env.jniEnv())); // try to find a nonexistent class + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.ClassNotFoundException: .*")); QVERIFY(!env->FindClass("this/doesnt/Exist")); QVERIFY(QJniEnvironment::checkAndClearExceptions(env.jniEnv())); @@ -68,9 +78,11 @@ void tst_QJniEnvironment::jniEnv() QVERIFY(env.findClass<jstring>()); // try to find a nonexistent class + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.ClassNotFoundException: .*")); QVERIFY(!env.findClass("this/doesnt/Exist")); // clear exception with member function + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.ClassNotFoundException: .*")); QVERIFY(!env->FindClass("this/doesnt/Exist")); QVERIFY(env.checkAndClearExceptions()); } @@ -273,6 +285,7 @@ void tst_QJniEnvironment::findMethod() QVERIFY(methodId != nullptr); // invalid signature + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.NoSuchMethodError: .*")); jmethodID invalid = env.findMethod(clazz, "unknown", "()I"); QVERIFY(invalid == nullptr); // check that all exceptions are already cleared @@ -299,8 +312,10 @@ void tst_QJniEnvironment::findStaticMethod() QCOMPARE(result, 123); // invalid method + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.NoSuchMethodError: .*")); jmethodID invalid = env.findStaticMethod(clazz, "unknown", "()I"); QVERIFY(invalid == nullptr); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.NoSuchMethodError: .*")); invalid = env.findStaticMethod<jint>(clazz, "unknown"); QVERIFY(invalid == nullptr); // check that all exceptions are already cleared @@ -328,6 +343,7 @@ void tst_QJniEnvironment::findField() QVERIFY(value == 123); // invalid signature + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.NoSuchFieldError: .*")); jfieldID invalidId = env.findField(clazz, "unknown", "I"); QVERIFY(invalidId == nullptr); // check that all exceptions are already cleared @@ -351,6 +367,7 @@ void tst_QJniEnvironment::findStaticField() QVERIFY(size == 321); // invalid signature + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("java.lang.NoSuchFieldError: .*")); jfieldID invalidId = env.findStaticField(clazz, "unknown", "I"); QVERIFY(invalidId == nullptr); // check that all exceptions are already cleared |