1
1
use crate :: temp_file;
2
2
use lofty:: id3:: v2:: {
3
3
AttachedPictureFrame , CommentFrame , ExtendedTextFrame , ExtendedUrlFrame , Frame , FrameFlags ,
4
- FrameId , FrameValue , GEOBInformation , GeneralEncapsulatedObject , ID3v2Tag , ID3v2Version ,
5
- Popularimeter , SyncTextContentType , SyncTextInformation , SynchronizedText , TimestampFormat ,
6
- UniqueFileIdentifierFrame , UrlLinkFrame ,
4
+ FrameId , FrameValue , GeneralEncapsulatedObject , Id3v2Tag , Id3v2Version , Popularimeter ,
5
+ SyncTextContentType , SynchronizedText , TimestampFormat , UniqueFileIdentifierFrame ,
6
+ UrlLinkFrame ,
7
7
} ;
8
8
use lofty:: mpeg:: MpegFile ;
9
9
use lofty:: {
10
- Accessor , AudioFile , MimeType , ParseOptions , Picture , PictureType , TagExt , TextEncoding ,
10
+ Accessor , AudioFile , MimeType , ParseOptions , ParsingMode , Picture , PictureType , TagExt ,
11
+ TextEncoding ,
11
12
} ;
12
13
use std:: borrow:: Cow ;
13
14
use std:: io:: Seek ;
@@ -60,13 +61,13 @@ fn test_read_string_field() {
60
61
#[ test]
61
62
fn test_parse_apic ( ) {
62
63
let f = AttachedPictureFrame :: parse (
63
- b"\
64
+ & mut & b"\
64
65
\x00 \
65
66
m\x00 \
66
67
\x01 \
67
68
d\x00 \
68
- \x00 ",
69
- ID3v2Version :: V4 ,
69
+ \x00 "[ .. ] ,
70
+ Id3v2Version :: V4 ,
70
71
)
71
72
. unwrap ( ) ;
72
73
assert_eq ! ( f. picture. mime_type( ) , & MimeType :: Unknown ( String :: from( "m" ) ) ) ;
@@ -77,11 +78,11 @@ fn test_parse_apic() {
77
78
#[ test]
78
79
fn test_parse_apic_utf16_bom ( ) {
79
80
let f = AttachedPictureFrame :: parse (
80
- b"\
81
+ & mut & b"\
81
82
\x01 \x69 \x6d \x61 \x67 \x65 \
82
83
\x2f \x6a \x70 \x65 \x67 \x00 \x00 \xfe \xff \x00 \x63 \x00 \x6f \x00 \x76 \x00 \
83
- \x65 \x00 \x72 \x00 \x2e \x00 \x6a \x00 \x70 \x00 \x67 \x00 \x00 \xff \xd8 \xff ",
84
- ID3v2Version :: V4 ,
84
+ \x65 \x00 \x72 \x00 \x2e \x00 \x6a \x00 \x70 \x00 \x67 \x00 \x00 \xff \xd8 \xff "[ .. ] ,
85
+ Id3v2Version :: V4 ,
85
86
)
86
87
. unwrap ( ) ;
87
88
@@ -94,13 +95,13 @@ fn test_parse_apic_utf16_bom() {
94
95
#[ test]
95
96
fn test_parse_apicv22 ( ) {
96
97
let frame = AttachedPictureFrame :: parse (
97
- b"\
98
+ & mut & b"\
98
99
\x00 \
99
100
JPG\
100
101
\x01 \
101
102
d\x00 \
102
- \x00 ",
103
- ID3v2Version :: V2 ,
103
+ \x00 "[ .. ] ,
104
+ Id3v2Version :: V2 ,
104
105
)
105
106
. unwrap ( ) ;
106
107
@@ -122,7 +123,7 @@ fn test_render_apic() {
122
123
} ;
123
124
124
125
assert_eq ! (
125
- f. as_bytes( ID3v2Version :: V4 ) . unwrap( ) ,
126
+ f. as_bytes( Id3v2Version :: V4 ) . unwrap( ) ,
126
127
b"\
127
128
\x03 \
128
129
image/png\x00 \
@@ -149,20 +150,18 @@ fn test_parse_geob() {
149
150
\x00 ",
150
151
)
151
152
. unwrap ( ) ;
152
- assert_eq ! ( f. information . mime_type. as_deref( ) , Some ( "m" ) ) ;
153
- assert_eq ! ( f. information . file_name. as_deref( ) , Some ( "f" ) ) ;
154
- assert_eq ! ( f. information . descriptor. as_deref( ) , Some ( "d" ) ) ;
153
+ assert_eq ! ( f. mime_type. as_deref( ) , Some ( "m" ) ) ;
154
+ assert_eq ! ( f. file_name. as_deref( ) , Some ( "f" ) ) ;
155
+ assert_eq ! ( f. descriptor. as_deref( ) , Some ( "d" ) ) ;
155
156
}
156
157
157
158
#[ test]
158
159
fn test_render_geob ( ) {
159
160
let f = GeneralEncapsulatedObject {
160
- information : GEOBInformation {
161
- encoding : TextEncoding :: Latin1 ,
162
- mime_type : Some ( String :: from ( "application/octet-stream" ) ) ,
163
- file_name : Some ( String :: from ( "test.bin" ) ) ,
164
- descriptor : Some ( String :: from ( "Description" ) ) ,
165
- } ,
161
+ encoding : TextEncoding :: Latin1 ,
162
+ mime_type : Some ( String :: from ( "application/octet-stream" ) ) ,
163
+ file_name : Some ( String :: from ( "test.bin" ) ) ,
164
+ descriptor : Some ( String :: from ( "Description" ) ) ,
166
165
data : vec ! [ 0x01 ; 3 ] ,
167
166
} ;
168
167
@@ -180,10 +179,10 @@ fn test_render_geob() {
180
179
#[ test]
181
180
fn test_parse_popm ( ) {
182
181
let f = Popularimeter :: parse (
183
- b"\
182
+ & mut & b"\
184
183
email@example.com\x00 \
185
184
\x02 \
186
- \x00 \x00 \x00 \x03 ",
185
+ \x00 \x00 \x00 \x03 "[ .. ] ,
187
186
)
188
187
. unwrap ( ) ;
189
188
assert_eq ! ( f. email, "email@example.com" ) ;
@@ -194,9 +193,9 @@ fn test_parse_popm() {
194
193
#[ test]
195
194
fn test_parse_popm_without_counter ( ) {
196
195
let f = Popularimeter :: parse (
197
- b"\
196
+ & mut & b"\
198
197
email@example.com\x00 \
199
- \x02 ",
198
+ \x02 "[ .. ] ,
200
199
)
201
200
. unwrap ( ) ;
202
201
assert_eq ! ( f. email, "email@example.com" ) ;
@@ -241,7 +240,7 @@ fn test_popm_from_file() {
241
240
let mut foo = MpegFile :: read_from ( & mut file, ParseOptions :: new ( ) ) . unwrap ( ) ;
242
241
file. rewind ( ) . unwrap ( ) ;
243
242
244
- let mut tag = ID3v2Tag :: new ( ) ;
243
+ let mut tag = Id3v2Tag :: new ( ) ;
245
244
tag. insert (
246
245
Frame :: new ( "POPM" , FrameValue :: Popularimeter ( f) , FrameFlags :: default ( ) ) . unwrap ( ) ,
247
246
) ;
@@ -276,6 +275,7 @@ fn test_parse_unique_file_identifier_frame() {
276
275
& mut & b"\
277
276
owner\x00 \
278
277
\x00 \x01 \x02 "[ ..] ,
278
+ ParsingMode :: Strict ,
279
279
)
280
280
. unwrap ( )
281
281
. unwrap ( ) ;
@@ -290,6 +290,7 @@ fn test_parse_empty_unique_file_identifier_frame() {
290
290
& mut & b"\
291
291
\x00 \
292
292
"[ ..] ,
293
+ ParsingMode :: Strict ,
293
294
) ;
294
295
295
296
// NOTE: TagLib considers a missing owner to be valid, we do not
@@ -313,24 +314,28 @@ owner\x00\
313
314
314
315
#[ test]
315
316
fn test_parse_url_link_frame ( ) {
316
- let f = UrlLinkFrame :: parse ( b"http://example.com" ) . unwrap ( ) . unwrap ( ) ;
317
+ let f = UrlLinkFrame :: parse ( & mut & b"http://example.com" [ ..] )
318
+ . unwrap ( )
319
+ . unwrap ( ) ;
317
320
assert_eq ! ( f. url( ) , "http://example.com" ) ;
318
321
}
319
322
320
323
#[ test]
321
324
fn test_render_url_link_frame ( ) {
322
- let f = UrlLinkFrame :: parse ( b"http://example.com" ) . unwrap ( ) . unwrap ( ) ;
325
+ let f = UrlLinkFrame :: parse ( & mut & b"http://example.com" [ ..] )
326
+ . unwrap ( )
327
+ . unwrap ( ) ;
323
328
assert_eq ! ( f. as_bytes( ) , b"http://example.com" ) ;
324
329
}
325
330
326
331
#[ test]
327
332
fn test_parse_user_url_link_frame ( ) {
328
333
let f = ExtendedUrlFrame :: parse (
329
- b"\
334
+ & mut & b"\
330
335
\x00 \
331
336
foo\x00 \
332
- http://example.com",
333
- ID3v2Version :: V4 ,
337
+ http://example.com"[ .. ] ,
338
+ Id3v2Version :: V4 ,
334
339
)
335
340
. unwrap ( )
336
341
. unwrap ( ) ;
@@ -380,11 +385,11 @@ Lyrics\x00\
380
385
)
381
386
. unwrap ( ) ;
382
387
383
- assert_eq ! ( f. information . encoding, TextEncoding :: Latin1 ) ;
384
- assert_eq ! ( f. information . language, * b"eng" ) ;
385
- assert_eq ! ( f. information . timestamp_format, TimestampFormat :: MS ) ;
386
- assert_eq ! ( f. information . content_type, SyncTextContentType :: Lyrics ) ;
387
- assert_eq ! ( f. information . description. as_deref( ) , Some ( "foo" ) ) ;
388
+ assert_eq ! ( f. encoding, TextEncoding :: Latin1 ) ;
389
+ assert_eq ! ( f. language, * b"eng" ) ;
390
+ assert_eq ! ( f. timestamp_format, TimestampFormat :: MS ) ;
391
+ assert_eq ! ( f. content_type, SyncTextContentType :: Lyrics ) ;
392
+ assert_eq ! ( f. description. as_deref( ) , Some ( "foo" ) ) ;
388
393
389
394
assert_eq ! ( f. content. len( ) , 2 ) ;
390
395
assert_eq ! ( f. content[ 0 ] . 1 , "Example" ) ;
@@ -409,11 +414,11 @@ fn test_parse_synchronized_lyrics_frame_with_empty_description() {
409
414
)
410
415
. unwrap ( ) ;
411
416
412
- assert_eq ! ( f. information . encoding, TextEncoding :: Latin1 ) ;
413
- assert_eq ! ( f. information . language, * b"eng" ) ;
414
- assert_eq ! ( f. information . timestamp_format, TimestampFormat :: MS ) ;
415
- assert_eq ! ( f. information . content_type, SyncTextContentType :: Lyrics ) ;
416
- assert ! ( f. information . description. is_none( ) ) ;
417
+ assert_eq ! ( f. encoding, TextEncoding :: Latin1 ) ;
418
+ assert_eq ! ( f. language, * b"eng" ) ;
419
+ assert_eq ! ( f. timestamp_format, TimestampFormat :: MS ) ;
420
+ assert_eq ! ( f. content_type, SyncTextContentType :: Lyrics ) ;
421
+ assert ! ( f. description. is_none( ) ) ;
417
422
418
423
assert_eq ! ( f. content. len( ) , 2 ) ;
419
424
assert_eq ! ( f. content[ 0 ] . 1 , "Example" ) ;
@@ -425,13 +430,11 @@ fn test_parse_synchronized_lyrics_frame_with_empty_description() {
425
430
#[ test]
426
431
fn test_render_synchronized_lyrics_frame ( ) {
427
432
let f = SynchronizedText {
428
- information : SyncTextInformation {
429
- encoding : TextEncoding :: Latin1 ,
430
- language : * b"eng" ,
431
- timestamp_format : TimestampFormat :: MS ,
432
- content_type : SyncTextContentType :: Lyrics ,
433
- description : Some ( String :: from ( "foo" ) ) ,
434
- } ,
433
+ encoding : TextEncoding :: Latin1 ,
434
+ language : * b"eng" ,
435
+ timestamp_format : TimestampFormat :: MS ,
436
+ content_type : SyncTextContentType :: Lyrics ,
437
+ description : Some ( String :: from ( "foo" ) ) ,
435
438
content : vec ! [
436
439
( 1234 , String :: from( "Example" ) ) ,
437
440
( 4567 , String :: from( "Lyrics" ) ) ,
@@ -464,11 +467,11 @@ fn test_render_event_timing_codes_frame() {}
464
467
#[ test]
465
468
fn test_parse_comments_frame ( ) {
466
469
let f = CommentFrame :: parse (
467
- b"\x03 \
470
+ & mut & b"\x03 \
468
471
deu\
469
472
Description\x00 \
470
- Text",
471
- ID3v2Version :: V4 ,
473
+ Text"[ .. ] ,
474
+ Id3v2Version :: V4 ,
472
475
)
473
476
. unwrap ( )
474
477
. unwrap ( ) ;
@@ -521,11 +524,11 @@ fn test_render_private_frame() {}
521
524
#[ test]
522
525
fn test_parse_user_text_identification_frame ( ) {
523
526
let frame_without_description = ExtendedUrlFrame :: parse (
524
- b"\
527
+ & mut & b"\
525
528
\x00 \
526
529
\x00 \
527
- Text",
528
- ID3v2Version :: V4 ,
530
+ Text"[ .. ] ,
531
+ Id3v2Version :: V4 ,
529
532
)
530
533
. unwrap ( )
531
534
. unwrap ( ) ;
@@ -534,11 +537,11 @@ fn test_parse_user_text_identification_frame() {
534
537
assert_eq ! ( frame_without_description. content, String :: from( "Text" ) ) ;
535
538
536
539
let frame_with_description = ExtendedUrlFrame :: parse (
537
- b"\
540
+ & mut & b"\
538
541
\x00 \
539
542
Description\x00 \
540
- Text",
541
- ID3v2Version :: V4 ,
543
+ Text"[ .. ] ,
544
+ Id3v2Version :: V4 ,
542
545
)
543
546
. unwrap ( )
544
547
. unwrap ( ) ;
@@ -601,7 +604,7 @@ fn test_save_utf16_comment() {
601
604
let mut foo = MpegFile :: read_from ( & mut file, ParseOptions :: new ( ) ) . unwrap ( ) ;
602
605
file. rewind ( ) . unwrap ( ) ;
603
606
604
- let mut tag = ID3v2Tag :: new ( ) ;
607
+ let mut tag = Id3v2Tag :: new ( ) ;
605
608
tag. insert (
606
609
Frame :: new (
607
610
"COMM" ,
@@ -761,7 +764,7 @@ fn test_save_and_strip_id3v1_should_not_add_frame_from_id3v1_to_id3v2() {
761
764
let mut foo = MpegFile :: read_from ( & mut file, ParseOptions :: new ( ) ) . unwrap ( ) ;
762
765
file. rewind ( ) . unwrap ( ) ;
763
766
764
- let mut tag = ID3v2Tag :: new ( ) ;
767
+ let mut tag = Id3v2Tag :: new ( ) ;
765
768
tag. set_artist ( String :: from ( "Artist" ) ) ;
766
769
foo. set_id3v2 ( tag) ;
767
770
foo. save_to ( & mut file) . unwrap ( ) ;
0 commit comments