pngme_book
pngme_book copied to clipboard
Unit test test_invalid_chunk in Chapter 3 should add a standard header
#[test]
fn test_invalid_chunk() {
let mut chunk_bytes: Vec<u8> = testing_chunks()
.into_iter()
.flat_map(|chunk| chunk.as_bytes())
.collect();
#[rustfmt::skip]
let mut bad_chunk = vec![
0, 0, 0, 5, // length
32, 117, 83, 116, // Chunk Type (bad)
65, 64, 65, 66, 67, // Data
1, 2, 3, 4, 5 // CRC (bad)
];
chunk_bytes.append(&mut bad_chunk);
let png = Png::try_from(chunk_bytes.as_ref());
assert!(png.is_err());
}
This is used to test invalid chunks, so I think it needs a correct standard header. I changed it to below:
#[test]
fn test_invalid_chunk() {
let mut chunk_bytes: Vec<u8> = testing_chunks()
.into_iter()
.flat_map(|chunk| chunk.as_bytes())
.collect();
#[rustfmt::skip]
let mut bad_chunk = vec![
0, 0, 0, 5, // length
32, 117, 83, 116, // Chunk Type (bad)
65, 64, 65, 66, 67, // Data
1, 2, 3, 4, 5 // CRC (bad)
];
chunk_bytes.append(&mut bad_chunk);
let bytes: Vec<u8> = [137, 80, 78, 71, 13, 10, 26, 10]
.iter()
.chain(chunk_bytes.iter())
.copied()
.collect();
let png = Png::try_from(bytes.as_ref());
assert!(png.is_err());
}