1 #![cfg(feature = "invocation")]
2 
3 mod util;
4 use util::{attach_current_thread, call_java_abs, detach_current_thread, jvm};
5 
6 #[test]
explicit_detach_detaches_thread_attached_locally()7 pub fn explicit_detach_detaches_thread_attached_locally() {
8     assert_eq!(jvm().threads_attached(), 0);
9     let mut guard = attach_current_thread();
10     let val = call_java_abs(&mut guard, -1);
11     assert_eq!(val, 1);
12     assert_eq!(jvm().threads_attached(), 1);
13 
14     // # Safety
15     // we won't be trying to use a pre-existing (invalid) `JNIEnv` after detaching
16     unsafe {
17         detach_current_thread();
18     }
19     assert_eq!(jvm().threads_attached(), 0);
20     assert!(jvm().get_env().is_err());
21 }
22