()
| 6 | |
| 7 | #[test] |
| 8 | fn test_valid_class() { |
| 9 | let valid_class = include_bytes!("../java-assets/compiled-classes/BasicClass.class"); |
| 10 | let res = class_parser(valid_class); |
| 11 | match res { |
| 12 | Result::Ok((_, c)) => { |
| 13 | println!("Valid class file, version {},{} const_pool({}), this=const[{}], super=const[{}], interfaces({}), fields({}), methods({}), attributes({}), access({:?})", c.major_version, c.minor_version, c.const_pool_size, c.this_class, c.super_class, c.interfaces_count, c.fields_count, c.methods_count, c.attributes_count, c.access_flags); |
| 14 | |
| 15 | let mut code_const_index = 0; |
| 16 | |
| 17 | println!("Constant pool:"); |
| 18 | for (const_index, const_item) in c.const_pool.iter().enumerate() { |
| 19 | println!("\t[{}] = {:?}", (const_index + 1), const_item); |
| 20 | match *const_item { |
| 21 | ConstantInfo::Utf8(ref c) => { |
| 22 | if c.utf8_string == "Code" { |
| 23 | code_const_index = (const_index + 1) as u16; |
| 24 | } |
| 25 | } |
| 26 | _ => {} |
| 27 | } |
| 28 | } |
| 29 | println!("Code index = {}", code_const_index); |
| 30 | |
| 31 | println!("Interfaces:"); |
| 32 | let mut interface_index = 0; |
| 33 | for i in &c.interfaces { |
| 34 | println!( |
| 35 | "\t[{}] = const[{}] = {:?}", |
| 36 | interface_index, |
| 37 | i, |
| 38 | c.const_pool[(i - 1) as usize] |
| 39 | ); |
| 40 | |
| 41 | interface_index += 1; |
| 42 | } |
| 43 | println!("Fields:"); |
| 44 | let mut field_index = 0; |
| 45 | for f in &c.fields { |
| 46 | println!( |
| 47 | "\t[{}] Name(const[{}] = {:?}) - access({:?})", |
| 48 | field_index, |
| 49 | f.name_index, |
| 50 | c.const_pool[(f.name_index - 1) as usize], |
| 51 | f.access_flags |
| 52 | ); |
| 53 | field_index += 1; |
| 54 | } |
| 55 | println!("Methods:"); |
| 56 | let mut method_index = 0; |
| 57 | for m in &c.methods { |
| 58 | println!( |
| 59 | "\t[{}] Name(const[{}] = {:?}) - access({:?})", |
| 60 | method_index, |
| 61 | m.name_index, |
| 62 | c.const_pool[(m.name_index - 1) as usize], |
| 63 | m.access_flags |
| 64 | ); |
| 65 | method_index += 1; |
nothing calls this directly
no test coverage detected