|
1 | 1 | use crate::temp_file;
|
2 | 2 |
|
3 | 3 | use std::borrow::Cow;
|
| 4 | +use std::collections::HashMap; |
4 | 5 | use std::io::Seek;
|
5 | 6 |
|
6 | 7 | use lofty::id3::v2::{
|
7 |
| - AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Frame, FrameFlags, |
8 |
| - FrameId, FrameValue, GeneralEncapsulatedObject, Id3v2Tag, Id3v2Version, Popularimeter, |
9 |
| - SyncTextContentType, SynchronizedText, TimestampFormat, UniqueFileIdentifierFrame, |
10 |
| - UrlLinkFrame, |
| 8 | + AttachedPictureFrame, ChannelInformation, ChannelType, CommentFrame, Event, |
| 9 | + EventTimingCodesFrame, EventType, ExtendedTextFrame, ExtendedUrlFrame, Frame, FrameFlags, |
| 10 | + FrameId, FrameValue, GeneralEncapsulatedObject, Id3v2Tag, Id3v2Version, OwnershipFrame, |
| 11 | + Popularimeter, PrivateFrame, RelativeVolumeAdjustmentFrame, SyncTextContentType, |
| 12 | + SynchronizedText, TimestampFormat, UniqueFileIdentifierFrame, UrlLinkFrame, |
11 | 13 | };
|
12 | 14 | use lofty::mpeg::MpegFile;
|
13 | 15 | use lofty::{
|
@@ -264,12 +266,61 @@ fn test_popm_from_file() {
|
264 | 266 | }
|
265 | 267 |
|
266 | 268 | #[test]
|
267 |
| -#[ignore] // TODO: We don't support RVA2 frames yet |
268 |
| -fn test_parse_relative_volume_frame() {} |
| 269 | +fn test_parse_relative_volume_frame() { |
| 270 | + let f = RelativeVolumeAdjustmentFrame::parse( |
| 271 | + &mut &b"\ |
| 272 | + ident\x00\ |
| 273 | + \x02\ |
| 274 | + \x00\x0F\ |
| 275 | + \x08\ |
| 276 | + \x45"[..], |
| 277 | + ParsingMode::Strict, |
| 278 | + ) |
| 279 | + .unwrap() |
| 280 | + .unwrap(); |
269 | 281 |
|
270 |
| -#[test] |
271 |
| -#[ignore] // TODO: We don't support RVA2 frames yet |
272 |
| -fn test_render_relative_volume_frame() {} |
| 282 | + assert_eq!(f.identification, "ident"); |
| 283 | + let front_right = f.channels.get(&ChannelType::FrontRight).unwrap(); |
| 284 | + assert_eq!( |
| 285 | + front_right.volume_adjustment as f32 / 512.0f32, |
| 286 | + 15.0f32 / 512.0f32 |
| 287 | + ); |
| 288 | + assert_eq!(front_right.volume_adjustment, 15); |
| 289 | + assert_eq!(front_right.bits_representing_peak, 8); |
| 290 | + assert_eq!(front_right.peak_volume, Some(vec![0x45])); |
| 291 | + let channels = f.channels; |
| 292 | + assert_eq!(channels.len(), 1); |
| 293 | +} |
| 294 | + |
| 295 | +#[test] |
| 296 | +fn test_render_relative_volume_frame() { |
| 297 | + let f = RelativeVolumeAdjustmentFrame { |
| 298 | + identification: String::from("ident"), |
| 299 | + channels: { |
| 300 | + let mut m = HashMap::new(); |
| 301 | + m.insert( |
| 302 | + ChannelType::FrontRight, |
| 303 | + ChannelInformation { |
| 304 | + channel_type: ChannelType::FrontRight, |
| 305 | + volume_adjustment: 15, |
| 306 | + bits_representing_peak: 8, |
| 307 | + peak_volume: Some(vec![0x45]), |
| 308 | + }, |
| 309 | + ); |
| 310 | + m |
| 311 | + }, |
| 312 | + }; |
| 313 | + |
| 314 | + assert_eq!( |
| 315 | + f.as_bytes(), |
| 316 | + b"\ |
| 317 | + ident\x00\ |
| 318 | + \x02\ |
| 319 | + \x00\x0F\ |
| 320 | + \x08\ |
| 321 | + \x45" |
| 322 | + ); |
| 323 | +} |
273 | 324 |
|
274 | 325 | #[test]
|
275 | 326 | fn test_parse_unique_file_identifier_frame() {
|
@@ -364,12 +415,40 @@ fn test_render_user_url_link_frame() {
|
364 | 415 | }
|
365 | 416 |
|
366 | 417 | #[test]
|
367 |
| -#[ignore] // TODO: We don't support OWNE frames yet |
368 |
| -fn test_parse_ownership_frame() {} |
| 418 | +fn test_parse_ownership_frame() { |
| 419 | + let f = OwnershipFrame::parse( |
| 420 | + &mut &b"\ |
| 421 | + \x00\ |
| 422 | + GBP1.99\x00\ |
| 423 | + 20120905\ |
| 424 | + Beatport"[..], |
| 425 | + ) |
| 426 | + .unwrap() |
| 427 | + .unwrap(); |
| 428 | + |
| 429 | + assert_eq!(f.price_paid, "GBP1.99"); |
| 430 | + assert_eq!(f.date_of_purchase, "20120905"); |
| 431 | + assert_eq!(f.seller, "Beatport"); |
| 432 | +} |
369 | 433 |
|
370 | 434 | #[test]
|
371 |
| -#[ignore] // TODO: We don't support OWNE frames yet |
372 |
| -fn test_render_ownership_frame() {} |
| 435 | +fn test_render_ownership_frame() { |
| 436 | + let f = OwnershipFrame { |
| 437 | + encoding: TextEncoding::Latin1, |
| 438 | + price_paid: String::from("GBP1.99"), |
| 439 | + date_of_purchase: String::from("20120905"), |
| 440 | + seller: String::from("Beatport"), |
| 441 | + }; |
| 442 | + |
| 443 | + assert_eq!( |
| 444 | + f.as_bytes().unwrap(), |
| 445 | + b"\ |
| 446 | + \x00\ |
| 447 | + GBP1.99\x00\ |
| 448 | + 20120905\ |
| 449 | + Beatport"[..] |
| 450 | + ) |
| 451 | +} |
373 | 452 |
|
374 | 453 | #[test]
|
375 | 454 | fn test_parse_synchronized_lyrics_frame() {
|
@@ -459,12 +538,54 @@ fn test_render_synchronized_lyrics_frame() {
|
459 | 538 | }
|
460 | 539 |
|
461 | 540 | #[test]
|
462 |
| -#[ignore] // TODO: We don't support ETCO frames yet |
463 |
| -fn test_parse_event_timing_codes_frame() {} |
| 541 | +fn test_parse_event_timing_codes_frame() { |
| 542 | + let f = EventTimingCodesFrame::parse( |
| 543 | + &mut &b"\ |
| 544 | + \x02\ |
| 545 | + \x02\ |
| 546 | + \x00\x00\xf3\x5c\ |
| 547 | + \xfe\ |
| 548 | + \x00\x36\xee\x80"[..], |
| 549 | + ) |
| 550 | + .unwrap() |
| 551 | + .unwrap(); |
| 552 | + |
| 553 | + assert_eq!(f.timestamp_format, TimestampFormat::MS); |
| 554 | + |
| 555 | + let sel = f.events; |
| 556 | + assert_eq!(sel.len(), 2); |
| 557 | + assert_eq!(sel[0].event_type, EventType::IntroStart); |
| 558 | + assert_eq!(sel[0].timestamp, 62300); |
| 559 | + assert_eq!(sel[1].event_type, EventType::AudioFileEnds); |
| 560 | + assert_eq!(sel[1].timestamp, 3600000); |
| 561 | +} |
464 | 562 |
|
465 | 563 | #[test]
|
466 |
| -#[ignore] // TODO: We don't support ETCO frames yet |
467 |
| -fn test_render_event_timing_codes_frame() {} |
| 564 | +fn test_render_event_timing_codes_frame() { |
| 565 | + let f = EventTimingCodesFrame { |
| 566 | + timestamp_format: TimestampFormat::MS, |
| 567 | + events: vec![ |
| 568 | + Event { |
| 569 | + event_type: EventType::IntroStart, |
| 570 | + timestamp: 62300, |
| 571 | + }, |
| 572 | + Event { |
| 573 | + event_type: EventType::AudioFileEnds, |
| 574 | + timestamp: 3600000, |
| 575 | + }, |
| 576 | + ], |
| 577 | + }; |
| 578 | + |
| 579 | + assert_eq!( |
| 580 | + f.as_bytes(), |
| 581 | + b"\ |
| 582 | + \x02\ |
| 583 | + \x02\ |
| 584 | + \x00\x00\xf3\x5c\ |
| 585 | + \xfe\ |
| 586 | + \x00\x36\xee\x80" |
| 587 | + ) |
| 588 | +} |
468 | 589 |
|
469 | 590 | #[test]
|
470 | 591 | fn test_parse_comments_frame() {
|
@@ -516,12 +637,33 @@ fn test_render_podcast_frame() {
|
516 | 637 | }
|
517 | 638 |
|
518 | 639 | #[test]
|
519 |
| -#[ignore] // TODO: We don't support PRIV frames yet |
520 |
| -fn test_parse_private_frame() {} |
| 640 | +fn test_parse_private_frame() { |
| 641 | + let f = PrivateFrame::parse( |
| 642 | + &mut &b"\ |
| 643 | + WM/Provider\x00\ |
| 644 | + TL"[..], |
| 645 | + ) |
| 646 | + .unwrap() |
| 647 | + .unwrap(); |
| 648 | + |
| 649 | + assert_eq!(f.owner, "WM/Provider"); |
| 650 | + assert_eq!(f.private_data, b"TL"); |
| 651 | +} |
521 | 652 |
|
522 | 653 | #[test]
|
523 |
| -#[ignore] // TODO: We don't support PRIV frames yet |
524 |
| -fn test_render_private_frame() {} |
| 654 | +fn test_render_private_frame() { |
| 655 | + let f = PrivateFrame { |
| 656 | + owner: String::from("WM/Provider"), |
| 657 | + private_data: b"TL".to_vec(), |
| 658 | + }; |
| 659 | + |
| 660 | + assert_eq!( |
| 661 | + f.as_bytes(), |
| 662 | + b"\ |
| 663 | + WM/Provider\x00\ |
| 664 | + TL" |
| 665 | + ); |
| 666 | +} |
525 | 667 |
|
526 | 668 | #[test]
|
527 | 669 | fn test_parse_user_text_identification_frame() {
|
@@ -747,7 +889,7 @@ fn test_delete_frame() {
|
747 | 889 | file.rewind().unwrap();
|
748 | 890 |
|
749 | 891 | let t = f.id3v2_mut().unwrap();
|
750 |
| - t.remove("TCON"); |
| 892 | + let _ = t.remove(&FrameId::Valid(Cow::Borrowed("TCON"))); |
751 | 893 | f.save_to(&mut file).unwrap();
|
752 | 894 | }
|
753 | 895 | file.rewind().unwrap();
|
@@ -776,7 +918,10 @@ fn test_save_and_strip_id3v1_should_not_add_frame_from_id3v1_to_id3v2() {
|
776 | 918 | let mut bar = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
|
777 | 919 | file.rewind().unwrap();
|
778 | 920 |
|
779 |
| - bar.id3v2_mut().unwrap().remove("TPE1"); |
| 921 | + let _ = bar |
| 922 | + .id3v2_mut() |
| 923 | + .unwrap() |
| 924 | + .remove(&FrameId::Valid(Cow::Borrowed("TPE1"))); |
780 | 925 |
|
781 | 926 | bar.save_to(&mut file).unwrap();
|
782 | 927 | }
|
|
0 commit comments