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