Basic test for EntryByteReader

This commit is contained in:
A. Molzer committed 2026-03-31 09:16:33 +02:00
1 parent f890d22657
commit a2996ab34e
2 files changed
+51

No files matched your search

+44
View File
@@ -194,3 +194,47 @@ impl<R: Read + Seek> Seek for EntryBytesReader<'_, R> {
}
}
}
#[cfg(test)]
mod tests {
use crate::{decoder::Decoder, tags::Tag};
use std::io::{Read as _, Seek as _, SeekFrom};
#[test]
fn can_seek_tag_bytes() -> Result<(), crate::error::TiffError> {
let file = std::fs::File::open(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/images/int8_rgb.tif"
))
.unwrap();
let mut decoder = Decoder::open(file).unwrap();
decoder.next_directory().unwrap();
let strips = decoder
.current_ifd()
.find_entry(Tag::StripByteCounts)
.expect("some strip byte count is present");
let mut buffer = crate::tags::ValueBuffer::default();
decoder
.current_ifd()
.find_tag_buf(Tag::StripByteCounts, &mut buffer)
.expect("some strip byte count is present");
let mut reader = decoder.read_entry(strips)?;
let mut data = vec![];
reader.read_to_end(&mut data)?;
assert_eq!(buffer.as_bytes(), data);
reader.seek(SeekFrom::Start(0))?;
reader.read_to_end(&mut data)?;
let (first, second) = data.split_at(data.len() / 2);
assert_eq!(first, second);
Ok(())
}
}
+7
View File
@@ -567,6 +567,13 @@ impl ValueBuffer {
}
}
/// Create an empty value buffer with `Byte` type. This type choice is arbitrary.
impl Default for ValueBuffer {
fn default() -> Self {
ValueBuffer::empty(Type::BYTE)
}
}
/// Byte order of the TIFF file.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ByteOrder {