1 #![cfg(feature = "invocation")]
2
3 use jni::{objects::JObject, objects::JValue};
4
5 mod util;
6 use util::{attach_current_thread, print_exception};
7
8 #[test]
test_java_integers()9 fn test_java_integers() {
10 let env = attach_current_thread();
11
12 let array_length = 50;
13
14 for value in -10..10 {
15 env.with_local_frame(16, || {
16 let integer_value =
17 env.new_object("java/lang/Integer", "(I)V", &[JValue::Int(value)])?;
18
19 let values_array = JObject::from(env.new_object_array(
20 array_length,
21 "java/lang/Integer",
22 integer_value,
23 )?);
24
25 let result = env
26 .call_static_method(
27 "java/util/Arrays",
28 "binarySearch",
29 "([Ljava/lang/Object;Ljava/lang/Object;)I",
30 &[JValue::Object(values_array), JValue::Object(integer_value)],
31 )?
32 .i()?;
33
34 assert!(0 <= result && result < array_length);
35
36 Ok(JObject::null())
37 })
38 .unwrap_or_else(|e| {
39 print_exception(&env);
40 panic!("{:#?}", e);
41 });
42 }
43 }
44