Skip to content

Commit

Permalink
Add some tests around loading StaticHeaders and BDAs
Browse files Browse the repository at this point in the history
The last test indicates a desirable fix: if it is only possible to read
two sectors of the BDA, loading the BDA should return an error.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jul 20, 2017
1 parent e685c70 commit b142d37
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/engine/strat_engine/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,39 @@ mod tests {
.quickcheck(test_ownership as fn(u64, u32) -> TestResult);
}

#[test]
/// Construct a BDA input stream of all 0s of size _BDA_STATIC_HDR_SIZE.
/// Verify that loading the StaticHeader and loading the BDA yield None.
fn all_zero_bda() {
let mut buf = Cursor::new(vec![0u8; _BDA_STATIC_HDR_SIZE]);
assert!(StaticHeader::setup(&mut buf).unwrap().is_none());
assert!(BDA::load(&mut buf).unwrap().is_none());
}

#[test]
/// Make a buffer that is too short to have a StaticHeader on it.
/// Verify that loading the Static Header and loading the BDA yield None.
fn very_short_bda() {
let mut buf = Cursor::new(vec![0u8; SECTOR_SIZE]);
assert!(StaticHeader::setup(&mut buf).unwrap().is_none());
assert!(BDA::load(&mut buf).unwrap().is_none());
}

#[test]
/// Make a buffer just large enough to contain a single static header.
/// Verify that the StaticHeader is read and that the BDA's last update
/// time is None.
fn just_one_static_header() {
let mut vec = vec![0u8; 2 * SECTOR_SIZE];
vec[SECTOR_SIZE..2 * SECTOR_SIZE].clone_from_slice(&random_static_header(0, 0)
.sigblock_to_buf());
let mut buf = Cursor::new(vec);
assert!(StaticHeader::setup(&mut buf).unwrap().is_some());

let bda = BDA::load(&mut buf).unwrap().unwrap();
assert_eq!(bda.last_update_time(), None);
}

#[test]
/// Construct an arbitrary StaticHeader object.
/// Initialize a BDA.
Expand Down

0 comments on commit b142d37

Please sign in to comment.