|
| 1 | +use lofty::{Accessor, AudioFile, FileType, TaggedFileExt}; |
| 2 | + |
| 3 | +use std::io::Seek; |
| 4 | + |
| 5 | +use crate::util::get_filetype; |
| 6 | +use crate::{assert_delta, temp_file}; |
| 7 | + |
| 8 | +#[test] |
| 9 | +#[ignore] |
| 10 | +fn test_aiff_properties() { |
| 11 | + let file = lofty::read_from_path("tests/taglib/data/empty.aiff").unwrap(); |
| 12 | + |
| 13 | + assert_eq!(file.file_type(), FileType::AIFF); |
| 14 | + |
| 15 | + let properties = file.properties(); |
| 16 | + assert_eq!(properties.duration().as_secs(), 0); |
| 17 | + assert_delta!(properties.duration().as_millis(), 67, 1); |
| 18 | + assert_delta!(properties.audio_bitrate().unwrap(), 706, 1); |
| 19 | + assert_eq!(properties.sample_rate(), Some(44100)); |
| 20 | + assert_eq!(properties.channels(), Some(1)); |
| 21 | + assert_eq!(properties.bit_depth(), Some(16)); |
| 22 | + // TODO: get those options in lofty |
| 23 | + // CPPUNIT_ASSERT_EQUAL(2941U, f.audioProperties()->sampleFrames()); |
| 24 | + // CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isAiffC()); |
| 25 | +} |
| 26 | + |
| 27 | +#[test] |
| 28 | +#[ignore] |
| 29 | +fn test_aifc_properties() { |
| 30 | + let file = lofty::read_from_path("tests/taglib/data/alaw.aifc").unwrap(); |
| 31 | + |
| 32 | + assert_eq!(file.file_type(), FileType::AIFF); |
| 33 | + |
| 34 | + let properties = file.properties(); |
| 35 | + assert_eq!(properties.duration().as_secs(), 0); |
| 36 | + assert_delta!(properties.duration().as_millis(), 37, 1); |
| 37 | + assert_eq!(properties.audio_bitrate(), Some(355)); |
| 38 | + assert_eq!(properties.sample_rate(), Some(44100)); |
| 39 | + assert_eq!(properties.channels(), Some(1)); |
| 40 | + assert_eq!(properties.bit_depth(), Some(16)); |
| 41 | + // TODO: get those options in lofty |
| 42 | + // CPPUNIT_ASSERT_EQUAL(1622U, f.audioProperties()->sampleFrames()); |
| 43 | + // CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isAiffC()); |
| 44 | + // CPPUNIT_ASSERT_EQUAL(ByteVector("ALAW"), f.audioProperties()->compressionType()); |
| 45 | + // CPPUNIT_ASSERT_EQUAL(String("SGI CCITT G.711 A-law"), f.audioProperties()->compressionName()); |
| 46 | +} |
| 47 | + |
| 48 | +#[test] |
| 49 | +#[ignore] |
| 50 | +fn test_save_id3v2() { |
| 51 | + let mut file = temp_file!("tests/taglib/data/empty.aiff"); |
| 52 | + |
| 53 | + { |
| 54 | + let mut tfile = lofty::read_from(&mut file).unwrap(); |
| 55 | + |
| 56 | + assert_eq!(tfile.file_type(), FileType::AIFF); |
| 57 | + |
| 58 | + assert!(tfile.tag(lofty::TagType::ID3v2).is_none()); |
| 59 | + |
| 60 | + let mut tag = lofty::Tag::new(lofty::TagType::ID3v2); |
| 61 | + tag.set_title("TitleXXX".to_string()); |
| 62 | + tfile.insert_tag(tag); |
| 63 | + file.rewind().unwrap(); |
| 64 | + tfile.save_to(&mut file).unwrap(); |
| 65 | + assert!(tfile.contains_tag_type(lofty::TagType::ID3v2)); |
| 66 | + } |
| 67 | + |
| 68 | + file.rewind().unwrap(); |
| 69 | + |
| 70 | + { |
| 71 | + let mut tfile = lofty::read_from(&mut file).unwrap(); |
| 72 | + |
| 73 | + assert_eq!(tfile.file_type(), FileType::AIFF); |
| 74 | + |
| 75 | + let mut tag = tfile.tag(lofty::TagType::ID3v2).unwrap().to_owned(); |
| 76 | + assert_eq!(tag.title().as_deref(), Some("TitleXXX")); |
| 77 | + tag.set_title("".to_string()); |
| 78 | + tfile.insert_tag(tag); |
| 79 | + file.rewind().unwrap(); |
| 80 | + tfile.save_to(&mut file).unwrap(); |
| 81 | + assert!(!tfile.contains_tag_type(lofty::TagType::ID3v2)); |
| 82 | + } |
| 83 | + |
| 84 | + file.rewind().unwrap(); |
| 85 | + |
| 86 | + { |
| 87 | + let tfile = lofty::read_from(&mut file).unwrap(); |
| 88 | + |
| 89 | + assert_eq!(tfile.file_type(), FileType::AIFF); |
| 90 | + |
| 91 | + assert!(!tfile.contains_tag_type(lofty::TagType::ID3v2)); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +// TODO: testSaveID3v23 |
| 96 | +// TODO: testDuplicateID3v2 |
| 97 | + |
| 98 | +#[test] |
| 99 | +#[ignore] |
| 100 | +fn test_fuzzed_file1() { |
| 101 | + assert_eq!( |
| 102 | + get_filetype("tests/taglib/data/segfault.aif"), |
| 103 | + FileType::AIFF |
| 104 | + ); |
| 105 | +} |
| 106 | + |
| 107 | +// the file doesn't even have a valid signature |
| 108 | +// #[test] |
| 109 | +// #[ignore] |
| 110 | +// fn test_fuzzed_file2() { |
| 111 | +// let mut file = File::open("tests/taglib/data/excessive_alloc.aif").unwrap(); |
| 112 | +// |
| 113 | +// let mut buf = [0; 12]; |
| 114 | +// file.read_exact(&mut buf).unwrap(); |
| 115 | +// |
| 116 | +// assert_eq!(FileType::from_buffer(&buf).unwrap(), FileType::AIFF); |
| 117 | +// } |
0 commit comments