@@ -9,7 +9,8 @@ use lofty::id3::v2::{
9
9
EventTimingCodesFrame , EventType , ExtendedTextFrame , ExtendedUrlFrame , Frame , FrameFlags ,
10
10
FrameId , FrameValue , GeneralEncapsulatedObject , Id3v2Tag , Id3v2Version , OwnershipFrame ,
11
11
Popularimeter , PrivateFrame , RelativeVolumeAdjustmentFrame , SyncTextContentType ,
12
- SynchronizedText , TimestampFormat , UniqueFileIdentifierFrame , UrlLinkFrame ,
12
+ SynchronizedText , TextInformationFrame , TimestampFormat , UniqueFileIdentifierFrame ,
13
+ UrlLinkFrame ,
13
14
} ;
14
15
use lofty:: mpeg:: MpegFile ;
15
16
use lofty:: {
@@ -41,12 +42,69 @@ fn test_downgrade_utf8_for_id3v23_2() {}
41
42
42
43
#[ test]
43
44
fn test_utf16be_delimiter ( ) {
44
- todo ! ( "Need to think of a nice way to handle multiple UTF-16 values separated by null" )
45
+ let mut f = TextInformationFrame {
46
+ encoding : TextEncoding :: UTF16BE ,
47
+ value : String :: from ( "Foo\0 Bar" ) ,
48
+ } ;
49
+
50
+ let data = f. as_bytes ( ) ;
51
+
52
+ let no_bom_be_data = b"\x02 \
53
+ \0 F\0 o\0 o\0 \0 \
54
+ \0 B\0 a\0 r";
55
+
56
+ assert_eq ! ( data, no_bom_be_data) ;
57
+ f = TextInformationFrame :: parse ( & mut & data[ ..] , Id3v2Version :: V4 )
58
+ . unwrap ( )
59
+ . unwrap ( ) ;
60
+ assert_eq ! ( f. value, "Foo\0 Bar" ) ;
45
61
}
46
62
47
63
#[ test]
48
64
fn test_utf16_delimiter ( ) {
49
- todo ! ( "Need to think of a nice way to handle multiple UTF-16 values separated by null" )
65
+ let mut f = TextInformationFrame {
66
+ encoding : TextEncoding :: UTF16 ,
67
+ value : String :: from ( "Foo\0 Bar" ) ,
68
+ } ;
69
+
70
+ let data = f. as_bytes ( ) ;
71
+
72
+ // TODO: TagLib writes a BOM to every string, making the output identical to `mutli_bom_le_data`,
73
+ // rather than `single_bom_le_data` in Lofty's case. Not sure if we should be writing the BOM
74
+ // to every string?
75
+ let single_bom_le_data = b"\x01 \xff \xfe \
76
+ F\0 o\0 o\0 \0 \0 \
77
+ B\0 a\0 r\0 ";
78
+
79
+ assert_eq ! ( data, single_bom_le_data) ;
80
+ f = TextInformationFrame :: parse ( & mut & data[ ..] , Id3v2Version :: V4 )
81
+ . unwrap ( )
82
+ . unwrap ( ) ;
83
+ assert_eq ! ( f. value, "Foo\0 Bar" ) ;
84
+
85
+ let multi_bom_le_data = b"\x01 \xff \xfe \
86
+ F\0 o\0 o\0 \0 \0 \xff \xfe \
87
+ B\0 a\0 r\0 ";
88
+ f = TextInformationFrame :: parse ( & mut & multi_bom_le_data[ ..] , Id3v2Version :: V4 )
89
+ . unwrap ( )
90
+ . unwrap ( ) ;
91
+ assert_eq ! ( f. value, "Foo\0 Bar" ) ;
92
+
93
+ let multi_bom_be_data = b"\x01 \xfe \xff \
94
+ \0 F\0 o\0 o\0 \0 \xfe \xff \
95
+ \0 B\0 a\0 r";
96
+ f = TextInformationFrame :: parse ( & mut & multi_bom_be_data[ ..] , Id3v2Version :: V4 )
97
+ . unwrap ( )
98
+ . unwrap ( ) ;
99
+ assert_eq ! ( f. value, "Foo\0 Bar" ) ;
100
+
101
+ let single_bom_be_data = b"\x01 \xfe \xff \
102
+ \0 F\0 o\0 o\0 \0 \
103
+ \0 B\0 a\0 r";
104
+ f = TextInformationFrame :: parse ( & mut & single_bom_be_data[ ..] , Id3v2Version :: V4 )
105
+ . unwrap ( )
106
+ . unwrap ( ) ;
107
+ assert_eq ! ( f. value, "Foo\0 Bar" ) ;
50
108
}
51
109
52
110
#[ test]
0 commit comments