Skip to content

Commit

Permalink
Use check:jni for tests and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi committed Apr 8, 2024
1 parent 630a7a3 commit 1ef2422
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 13 deletions.
6 changes: 6 additions & 0 deletions pkgs/jni/src/dartjni.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ JniExceptionDetails getExceptionDetails(jthrowable exception) {
JniExceptionDetails details;
details.message = (*jniEnv)->CallObjectMethod(
jniEnv, exception, exceptionMethods.toStringMethod);
// No exception is thrown from toString.
(*jniEnv)->ExceptionClear(jniEnv);
jobject buffer =
(*jniEnv)->NewObject(jniEnv, exceptionMethods.byteArrayOutputStreamClass,
exceptionMethods.byteArrayOutputStreamCtor);
Expand All @@ -529,8 +531,12 @@ JniExceptionDetails getExceptionDetails(jthrowable exception) {
exceptionMethods.printStreamCtor, buffer);
(*jniEnv)->CallVoidMethod(
jniEnv, exception, exceptionMethods.printStackTraceMethod, printStream);
// No exception is thrown from printStackTrace.
(*jniEnv)->ExceptionClear(jniEnv);
details.stacktrace = (*jniEnv)->CallObjectMethod(
jniEnv, buffer, exceptionMethods.toStringMethod);
// No exception is thrown from toString.
(*jniEnv)->ExceptionClear(jniEnv);
details.message = to_global_ref(details.message);
details.stacktrace = to_global_ref(details.stacktrace);
return details;
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/boxed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/test/exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
} on HelperNotFoundError catch (_) {
// stderr.write("\n$_\n");
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
caught = true;
} on JniVmExistsError {
stderr.writeln('cannot verify: HelperNotFoundError thrown');
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/global_env_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ void main() {

if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/isolate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jarray_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jbyte_buffer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jlist_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jmap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import 'test_util/test_util.dart';
void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jobject_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/jstring_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ void main() {
// Don't forget to initialize JNI.
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/load_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void doGC() {
void main() {
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
3 changes: 2 additions & 1 deletion pkgs/jni/test/type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ final class $FType extends JObjType<F> {
void main() {
if (!Platform.isAndroid) {
checkDylibIsUpToDate();
Jni.spawnIfNotExists(dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m"]);
Jni.spawnIfNotExists(
dylibDir: "build/jni_libs", jvmOptions: ["-Xmx128m", "-Xcheck:jni"]);
}
run(testRunner: test);
}
Expand Down
2 changes: 2 additions & 0 deletions pkgs/jnigen/test/test_util/bindings_test_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Future<void> bindingsTestSetup() async {
tempClassDir.path,
...jacksonJars,
kotlinTestJar,
], jvmOptions: [
"-Xcheck:jni",
]);
}
}
Expand Down

0 comments on commit 1ef2422

Please sign in to comment.