2024-04-14 16:55:47 +00:00
|
|
|
use lofty::picture::{MimeType, Picture};
|
2021-11-23 17:41:57 +00:00
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
fn get_buf(path: &str) -> Vec<u8> {
|
|
|
|
let mut f = File::open(path).unwrap();
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
f.read_to_end(&mut buf).unwrap();
|
|
|
|
|
|
|
|
buf
|
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-23 17:41:57 +00:00
|
|
|
fn picture_from_reader_png() {
|
|
|
|
let pic = Picture::from_reader(&mut &*get_buf("tests/picture/assets/png_640x628.png")).unwrap();
|
|
|
|
|
2023-11-30 18:26:50 +00:00
|
|
|
assert_eq!(pic.mime_type(), Some(&MimeType::Png));
|
2021-11-23 17:41:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-23 17:41:57 +00:00
|
|
|
fn picture_from_reader_jpeg() {
|
|
|
|
let pic =
|
|
|
|
Picture::from_reader(&mut &*get_buf("tests/picture/assets/jpeg_640x628.jpg")).unwrap();
|
|
|
|
|
2023-11-30 18:26:50 +00:00
|
|
|
assert_eq!(pic.mime_type(), Some(&MimeType::Jpeg));
|
2021-11-23 17:41:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-23 17:41:57 +00:00
|
|
|
fn picture_from_reader_bmp() {
|
|
|
|
let pic = Picture::from_reader(&mut &*get_buf("tests/picture/assets/bmp_640x628.bmp")).unwrap();
|
|
|
|
|
2023-11-30 18:26:50 +00:00
|
|
|
assert_eq!(pic.mime_type(), Some(&MimeType::Bmp));
|
2021-11-23 17:41:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-23 17:41:57 +00:00
|
|
|
fn picture_from_reader_gif() {
|
|
|
|
let pic = Picture::from_reader(&mut &*get_buf("tests/picture/assets/gif_640x628.gif")).unwrap();
|
|
|
|
|
2023-11-30 18:26:50 +00:00
|
|
|
assert_eq!(pic.mime_type(), Some(&MimeType::Gif));
|
2021-11-23 17:41:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-23 17:41:57 +00:00
|
|
|
fn picture_from_reader_tiff() {
|
|
|
|
let pic =
|
|
|
|
Picture::from_reader(&mut &*get_buf("tests/picture/assets/tiff_640x628.tiff")).unwrap();
|
|
|
|
|
2023-11-30 18:26:50 +00:00
|
|
|
assert_eq!(pic.mime_type(), Some(&MimeType::Tiff));
|
2021-11-23 17:41:57 +00:00
|
|
|
}
|