1 use lazy_static::lazy_static;
2 
3 use proguard::{ProguardMapper, ProguardMapping, StackFrame};
4 
5 static MAPPING_R8: &[u8] = include_bytes!("res/mapping-r8.txt");
6 
7 lazy_static! {
8     static ref MAPPING_WIN_R8: Vec<u8> = MAPPING_R8
9         .iter()
10         .flat_map(|&byte| if byte == b'\n' {
11             vec![b'\r', b'\n']
12         } else {
13             vec![byte]
14         })
15         .collect();
16 }
17 
18 #[test]
test_basic_r8()19 fn test_basic_r8() {
20     let mapping = ProguardMapping::new(MAPPING_R8);
21     assert!(mapping.is_valid());
22     assert!(mapping.has_line_info());
23 
24     let mapper = ProguardMapper::new(mapping);
25 
26     let class = mapper.remap_class("a.a.a.a.c");
27     assert_eq!(class, Some("android.arch.core.executor.ArchTaskExecutor"));
28 }
29 
30 #[test]
test_extra_methods()31 fn test_extra_methods() {
32     let mapper = ProguardMapper::new(ProguardMapping::new(MAPPING_R8));
33 
34     let mut mapped = mapper.remap_frame(&StackFrame::new("a.a.a.b.c$a", "<init>", 1));
35 
36     assert_eq!(
37         mapped.next().unwrap(),
38         StackFrame::new(
39             "android.arch.core.internal.SafeIterableMap$AscendingIterator",
40             "<init>",
41             270
42         )
43     );
44     assert_eq!(mapped.next(), None);
45 }
46 
47 #[test]
test_method_matches()48 fn test_method_matches() {
49     let mapper = ProguardMapper::new(ProguardMapping::new(MAPPING_R8));
50 
51     let mut mapped = mapper.remap_frame(&StackFrame::new("a.a.a.b.c", "a", 1));
52 
53     assert_eq!(
54         mapped.next().unwrap(),
55         StackFrame::new(
56             "android.arch.core.internal.SafeIterableMap",
57             "access$100",
58             35
59         )
60     );
61     assert_eq!(mapped.next(), None);
62 
63     let mut mapped = mapper.remap_frame(&StackFrame::new("a.a.a.b.c", "a", 13));
64 
65     assert_eq!(
66         mapped.next().unwrap(),
67         StackFrame::new("android.arch.core.internal.SafeIterableMap", "eldest", 168)
68     );
69     assert_eq!(mapped.next(), None);
70 }
71 
72 #[test]
test_summary()73 fn test_summary() {
74     let mapping = ProguardMapping::new(MAPPING_R8);
75 
76     let summary = mapping.summary();
77     assert_eq!(summary.compiler(), Some("R8"));
78     assert_eq!(summary.compiler_version(), Some("1.3.49"));
79     assert_eq!(summary.min_api(), Some(15));
80     assert_eq!(summary.class_count(), 1167);
81     assert_eq!(summary.method_count(), 24076);
82 }
83 
84 #[cfg(feature = "uuid")]
85 #[test]
test_uuid()86 fn test_uuid() {
87     assert_eq!(
88         ProguardMapping::new(MAPPING_R8).uuid(),
89         "c96fb926-797c-53de-90ee-df2aeaf28340".parse().unwrap()
90     );
91 }
92 
93 #[cfg(feature = "uuid")]
94 #[test]
test_uuid_win()95 fn test_uuid_win() {
96     assert_eq!(
97         ProguardMapping::new(&MAPPING_WIN_R8[..]).uuid(),
98         "d8b03b44-58df-5cd7-adc7-aefcfb0e2ade".parse().unwrap()
99     );
100 }
101