From a24c9e8aeba0420c96be32e87319af61652a881a Mon Sep 17 00:00:00 2001 From: Victor Derks Date: Sat, 7 Oct 2023 18:12:43 +0200 Subject: [PATCH] Add unit test read_header_with_application_data (#2) --- src/jpeg_stream_reader.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/jpeg_stream_reader.rs b/src/jpeg_stream_reader.rs index 31048a6..5361c9e 100644 --- a/src/jpeg_stream_reader.rs +++ b/src/jpeg_stream_reader.rs @@ -141,11 +141,29 @@ mod tests { let x = reader.read_header().unwrap_err(); assert_eq!(x, DecodingError::JpegMarkerStartByteNotFound); + } - // - // assert_expect_exception(jpegls_errc::jpeg_marker_start_byte_not_found, [&reader] { reader.read_header(); }); + #[test] + fn read_header_with_application_data() { + for i in 0..16 { + read_header_with_application_data_for(i); + } } + fn read_header_with_application_data_for(data_number: u8) { + let mut buffer = Vec::new(); + + write_start_of_image(&mut buffer); + write_byte(&mut buffer, 0xFF); + write_byte(&mut buffer, 0xE0 + data_number); + write_byte(&mut buffer, 0); + write_byte(&mut buffer, 0x02); + write_start_of_frame_segment(&mut buffer, 1, 1, 2,1); + write_start_of_scan_segment(&mut buffer, 0, 1, 1, 0); + + let mut reader = JpegStreamReader::new(buffer.as_slice()); + assert!(reader.read_header().is_ok()); + } fn write_byte(buffer: &mut Vec, value: u8) { buffer.write_all(&[value]).unwrap();