More tests, but need to be run with --test-threads=1
This commit is contained in:
@ -6,8 +6,9 @@ use id3_image::*;
|
||||
|
||||
macro_rules! in_temp_dir {
|
||||
($block:block) => {
|
||||
let tmpdir = env::temp_dir();
|
||||
let tmpdir = tempfile::tempdir().unwrap();
|
||||
env::set_current_dir(&tmpdir).unwrap();
|
||||
|
||||
$block;
|
||||
}
|
||||
}
|
||||
@ -23,66 +24,6 @@ macro_rules! fixture {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successful_jpeg_image_embedding() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1_no_image.mp3");
|
||||
fixture!("attempt_1.jpg");
|
||||
|
||||
{
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() == 0);
|
||||
}
|
||||
|
||||
embed_image("attempt_1_no_image.mp3", "attempt_1.jpg").unwrap();
|
||||
|
||||
{
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successful_png_image_embedding() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1_no_image.mp3");
|
||||
fixture!("attempt_1.png");
|
||||
|
||||
{
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() == 0);
|
||||
}
|
||||
|
||||
embed_image("attempt_1_no_image.mp3", "attempt_1.png").unwrap();
|
||||
|
||||
{
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successful_image_embedding_in_a_file_that_already_has_an_image() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1.mp3");
|
||||
fixture!("attempt_1.jpg");
|
||||
|
||||
{
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
}
|
||||
|
||||
embed_image("attempt_1.mp3", "attempt_1.jpg").unwrap();
|
||||
|
||||
{
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unsuccessful_image_embedding() {
|
||||
in_temp_dir!({
|
||||
@ -100,3 +41,72 @@ fn test_unsuccessful_image_embedding() {
|
||||
assert!(embed_image("attempt_1.jpg", "attempt_1.jpg").is_err());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successful_jpeg_image_embedding() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1_no_image.mp3");
|
||||
fixture!("attempt_1.jpg");
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() == 0);
|
||||
|
||||
embed_image("attempt_1_no_image.mp3", "attempt_1.jpg").unwrap();
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successful_png_image_embedding() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1_no_image.mp3");
|
||||
fixture!("attempt_1.png");
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() == 0);
|
||||
|
||||
embed_image("attempt_1_no_image.mp3", "attempt_1.png").unwrap();
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1_no_image.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successful_image_embedding_in_a_file_that_already_has_an_image() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1.mp3");
|
||||
fixture!("attempt_1.jpg");
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
|
||||
embed_image("attempt_1.mp3", "attempt_1.jpg").unwrap();
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_and_add_image() {
|
||||
in_temp_dir!({
|
||||
fixture!("attempt_1.mp3");
|
||||
fixture!("attempt_1.jpg");
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
|
||||
remove_images("attempt_1.mp3").unwrap();
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() == 0);
|
||||
|
||||
embed_image("attempt_1.mp3", "attempt_1.jpg").unwrap();
|
||||
|
||||
let tag = id3::Tag::read_from_path("attempt_1.mp3").unwrap();
|
||||
assert!(tag.pictures().count() > 0);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user