Skip to content

Commit 9d2fa98

Browse files
alnyanIsaacWoods
authored andcommitted
AML: Implement tests for DefPackage parsing
1 parent 05c5578 commit 9d2fa98

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

aml/src/term_object.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,44 @@ mod test {
995995
use super::*;
996996
use crate::test_utils::*;
997997

998+
#[test]
999+
fn test_package() {
1000+
let mut context = make_test_context();
1001+
1002+
// The tests also check that DefPackage consumes no more input than required
1003+
// Empty DefPackage
1004+
check_ok_value!(
1005+
def_package().parse(&[0x12, 0x02, 0x00, 0x12, 0x34], &mut context),
1006+
AmlValue::Package(Vec::new()),
1007+
&[0x12, 0x34]
1008+
);
1009+
1010+
// DefPackage where NumElements == package_content.len()
1011+
check_ok_value!(
1012+
def_package()
1013+
.parse(&[0x12, 0x09, 0x04, 0x01, 0x0A, 0x02, 0x0A, 0x03, 0x0A, 0x04, 0x12, 0x34], &mut context),
1014+
AmlValue::Package(alloc::vec![
1015+
AmlValue::Integer(1),
1016+
AmlValue::Integer(2),
1017+
AmlValue::Integer(3),
1018+
AmlValue::Integer(4)
1019+
]),
1020+
&[0x12, 0x34]
1021+
);
1022+
1023+
// DefPackage where NumElements > package_content.len()
1024+
check_ok_value!(
1025+
def_package().parse(&[0x012, 0x05, 0x04, 0x01, 0x0A, 0x02, 0x12, 0x34], &mut context),
1026+
AmlValue::Package(alloc::vec![
1027+
AmlValue::Integer(1),
1028+
AmlValue::Integer(2),
1029+
AmlValue::Uninitialized,
1030+
AmlValue::Uninitialized,
1031+
]),
1032+
&[0x12, 0x34]
1033+
);
1034+
}
1035+
9981036
#[test]
9991037
fn test_computational_data() {
10001038
let mut context = make_test_context();

aml/src/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ pub(crate) fn crudely_cmp_values(a: &AmlValue, b: &AmlValue) -> bool {
119119
use crate::value::MethodCode;
120120

121121
match a {
122+
AmlValue::Uninitialized => match b {
123+
AmlValue::Uninitialized => true,
124+
_ => false,
125+
},
122126
AmlValue::Boolean(a) => match b {
123127
AmlValue::Boolean(b) => a == b,
124128
_ => false,

0 commit comments

Comments
 (0)