MCPcopy Index your code
hub / github.com/cretz/stackparam / bytecode_tests

Function bytecode_tests

tests/bytecode_tests.rs:17–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15#[test]
16#[ignore]
17fn bytecode_tests() {
18 let _ = env_logger::init();
19
20 // Find rt.jar
21 let java_home = env::var("JAVA_HOME").expect("Unable to find JAVA_HOME");
22 let java_home_path = PathBuf::from(java_home);
23 let rt_jar_path: PathBuf = {
24 // Try JDK first
25 let mut rt_maybe = java_home_path.join("jre/lib/rt.jar");
26 if !rt_maybe.is_file() {
27 rt_maybe = java_home_path.join("lib/rt.jar");
28 assert!(rt_maybe.is_file(), "Unable to find rt.jar on JAVA_HOME path: {}", java_home_path.display());
29 }
30 rt_maybe.to_owned()
31 };
32
33 // Check each class
34 let file = File::open(rt_jar_path).unwrap();
35 let mut rt_jar = ZipArchive::new(file).unwrap();
36 for i in 0..rt_jar.len() {
37 let mut file = rt_jar.by_index(i).unwrap();
38 if file.name().ends_with(".class") {
39 // Read the class and just write it back and confirm same bytes
40 let mut in_bytes: Vec<u8> = Vec::new();
41 file.read_to_end(&mut in_bytes).expect(&format!("Cannot read {}", file.name()));
42 let mut in_curs = Cursor::new(in_bytes);
43 let class_file = ClassReader::read_class(&mut in_curs).expect(&format!("Failed parsing {}", file.name()));
44 let mut out_curs = Cursor::new(Vec::new());
45 ClassWriter::new(&mut out_curs).write_class(&class_file).expect(&format!("Failed writing {}", file.name()));
46
47 in_bytes = in_curs.into_inner();
48 let out_bytes = out_curs.into_inner();
49 debug!("For {} - {} and {}", file.name(), in_bytes.len(), out_bytes.len());
50 assert_eq!(in_bytes.as_slice(), out_bytes.as_slice(), "Not same for {}", file.name());
51 }
52 }
53}

Callers

nothing calls this directly

Calls 4

read_classFunction · 0.85
lenMethod · 0.80
write_classMethod · 0.80
initFunction · 0.50

Tested by

no test coverage detected