1 // This is a separate test program because it has to start a JVM with a specific option.
2
3 #![cfg(feature = "invocation")]
4
5 use jni::{objects::JString, InitArgsBuilder, JavaVM};
6
7 #[test]
invocation_character_encoding()8 fn invocation_character_encoding() {
9 let jvm_args = InitArgsBuilder::new()
10 .version(jni::JNIVersion::V8)
11 .option("-Xcheck:jni")
12 // U+00A0 NO-BREAK SPACE is the only non-ASCII character that's present in all parts of
13 // ISO 8859. This minimizes the chance of this test failing as a result of the character
14 // not being present in the platform default character encoding. This test will still fail
15 // on platforms where the default character encoding cannot represent a no-break space,
16 // such as GBK.
17 .option("-Dnbsp=\u{00a0}")
18 .build()
19 .unwrap_or_else(|e| panic!("{:#?}", e));
20
21 let jvm = JavaVM::new(jvm_args).unwrap_or_else(|e| panic!("{:#?}", e));
22
23 let mut env = jvm.attach_current_thread().unwrap();
24
25 let prop_name = env.new_string("nbsp").unwrap();
26
27 let prop_value: JString = env
28 .call_static_method(
29 "java/lang/System",
30 "getProperty",
31 "(Ljava/lang/String;)Ljava/lang/String;",
32 &[(&prop_name).into()],
33 )
34 .unwrap()
35 .l()
36 .unwrap()
37 .into();
38
39 let prop_value_str = env.get_string(&prop_value).unwrap();
40 let prop_value_str: &str = prop_value_str.to_str().unwrap();
41
42 assert_eq!("\u{00a0}", prop_value_str);
43 }
44