mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 16:24:38 +00:00
dex: retain array_widths regressions
Source crates/formats/tests/dex_array_widths.rs at b9ca099903aeef5d4b33a7e83e8e7062ab94c65a. Imports adapted only.
This commit is contained in:
1 parent
794b884096
commit
e1eae62fe2
1 file changed
+39
@@ -0,0 +1,39 @@
|
||||
use crate::dex_ops::{Payload, decode, decode_one};
|
||||
|
||||
#[test]
|
||||
fn zero_width_does_not_describe_a_huge_complete_array() {
|
||||
let code = [0x0300, 0, 0xffff, 0xffff];
|
||||
assert!(decode_one(&code, 0).is_none());
|
||||
assert!(!decode(&code, 16).1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_element_widths_are_refused_even_for_empty_arrays() {
|
||||
for width in [0, 3, 5, 6, 7, 9, 16, u16::MAX] {
|
||||
assert!(decode_one(&[0x0300, width, 0, 0], 0).is_none(), "width {width}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_primitive_widths_and_odd_byte_padding_still_decode() {
|
||||
for width in [1u16, 2, 4, 8] {
|
||||
let count = 3u32;
|
||||
let bytes = usize::from(width) * count as usize;
|
||||
let mut code = vec![0x0300, width, count as u16, 0];
|
||||
code.resize(4 + bytes.div_ceil(2), 0x2211);
|
||||
let instruction = decode_one(&code, 0).unwrap();
|
||||
assert_eq!(instruction.units as usize, code.len());
|
||||
match instruction.payload.unwrap() {
|
||||
Payload::FillArrayData { element_width, count: decoded, data } => {
|
||||
assert_eq!(element_width, width);
|
||||
assert_eq!(decoded, count);
|
||||
assert_eq!(data.len(), bytes);
|
||||
assert_eq!(data[0], 0x11);
|
||||
}
|
||||
other => panic!("unexpected payload {other:?}"),
|
||||
}
|
||||
assert!(decode_one(&[0x0300, width, 0, 0], 0).is_some());
|
||||
code.pop();
|
||||
assert!(decode_one(&code, 0).is_none());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user