Skip to content

Commit

Permalink
AML: Implement tests for DefPackage parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
alnyan authored and IsaacWoods committed Sep 5, 2023
1 parent 05c5578 commit 9d2fa98
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions aml/src/term_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,44 @@ mod test {
use super::*;
use crate::test_utils::*;

#[test]
fn test_package() {
let mut context = make_test_context();

// The tests also check that DefPackage consumes no more input than required
// Empty DefPackage
check_ok_value!(
def_package().parse(&[0x12, 0x02, 0x00, 0x12, 0x34], &mut context),
AmlValue::Package(Vec::new()),
&[0x12, 0x34]
);

// DefPackage where NumElements == package_content.len()
check_ok_value!(
def_package()
.parse(&[0x12, 0x09, 0x04, 0x01, 0x0A, 0x02, 0x0A, 0x03, 0x0A, 0x04, 0x12, 0x34], &mut context),
AmlValue::Package(alloc::vec![
AmlValue::Integer(1),
AmlValue::Integer(2),
AmlValue::Integer(3),
AmlValue::Integer(4)
]),
&[0x12, 0x34]
);

// DefPackage where NumElements > package_content.len()
check_ok_value!(
def_package().parse(&[0x012, 0x05, 0x04, 0x01, 0x0A, 0x02, 0x12, 0x34], &mut context),
AmlValue::Package(alloc::vec![
AmlValue::Integer(1),
AmlValue::Integer(2),
AmlValue::Uninitialized,
AmlValue::Uninitialized,
]),
&[0x12, 0x34]
);
}

#[test]
fn test_computational_data() {
let mut context = make_test_context();
Expand Down
4 changes: 4 additions & 0 deletions aml/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ pub(crate) fn crudely_cmp_values(a: &AmlValue, b: &AmlValue) -> bool {
use crate::value::MethodCode;

match a {
AmlValue::Uninitialized => match b {
AmlValue::Uninitialized => true,
_ => false,
},
AmlValue::Boolean(a) => match b {
AmlValue::Boolean(b) => a == b,
_ => false,
Expand Down

0 comments on commit 9d2fa98

Please sign in to comment.