summaryrefslogtreecommitdiff
path: root/vendor/gif/tests/decode.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/gif/tests/decode.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/gif/tests/decode.rs')
-rw-r--r--vendor/gif/tests/decode.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/gif/tests/decode.rs b/vendor/gif/tests/decode.rs
new file mode 100644
index 0000000..6fc3aab
--- /dev/null
+++ b/vendor/gif/tests/decode.rs
@@ -0,0 +1,84 @@
+use gif::{DecodeOptions, DisposalMethod, Encoder, Frame};
+
+#[test]
+fn frame_consistency_is_configurable() {
+ let image = create_image_with_oob_frames();
+
+ {
+ let options = DecodeOptions::new();
+ let mut data = image.as_slice();
+ let mut decoder = options.clone().read_info(&mut data).unwrap();
+ assert!(decoder.read_next_frame().is_ok());
+ assert!(decoder.read_next_frame().is_ok());
+ }
+
+ {
+ let mut options = DecodeOptions::new();
+ options.check_frame_consistency(true);
+ let mut data = image.as_slice();
+ let mut decoder = options.clone().read_info(&mut data).unwrap();
+ assert!(decoder.read_next_frame().is_ok());
+ assert!(decoder.read_next_frame().is_err());
+ }
+
+ {
+ let mut options = DecodeOptions::new();
+ options.check_frame_consistency(false);
+ let mut data = image.as_slice();
+ let mut decoder = options.clone().read_info(&mut data).unwrap();
+ assert!(decoder.read_next_frame().is_ok());
+ assert!(decoder.read_next_frame().is_ok());
+ }
+}
+
+fn create_image_with_oob_frames() -> Vec<u8> {
+ let mut data = vec![];
+ let mut encoder = Encoder::new(&mut data, 2, 2, &[0, 0, 0]).unwrap();
+
+ let mut frame = Frame {
+ delay: 1,
+ dispose: DisposalMethod::Any,
+ transparent: None,
+ needs_user_input: false,
+ top: 0,
+ left: 0,
+ width: 2,
+ height: 2,
+ interlaced: false,
+ palette: None,
+ buffer: vec![0, 0, 0, 0].into(),
+ };
+
+ encoder.write_frame(&frame).unwrap();
+ frame.top = 1;
+ frame.left = 1;
+ encoder.write_frame(&frame).unwrap();
+
+ drop(encoder);
+ data
+}
+
+#[test]
+fn check_for_end_code_is_configurable() {
+ // In this particular image, the image data of the 62nd frame has no end code.
+ let image: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/samples/gifplayer-muybridge.gif"));
+
+ {
+ let options = DecodeOptions::new();
+ let mut decoder = options.clone().read_info(&image[..]).unwrap();
+ for _ in 0..61 {
+ assert!(decoder.read_next_frame().is_ok());
+ }
+ assert!(decoder.read_next_frame().is_ok());
+ }
+
+ {
+ let mut options = DecodeOptions::new();
+ options.check_lzw_end_code(true);
+ let mut decoder = options.clone().read_info(&image[..]).unwrap();
+ for _ in 0..61 {
+ assert!(decoder.read_next_frame().is_ok());
+ }
+ assert!(decoder.read_next_frame().is_err());
+ }
+}