Skip to content

Commit 56e2c68

Browse files
committed
Tests: Implement TagLib ID3v2 UTF16 delimiter tests
1 parent 3f3c570 commit 56e2c68

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

tests/taglib/test_id3v2.rs

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use lofty::id3::v2::{
99
EventTimingCodesFrame, EventType, ExtendedTextFrame, ExtendedUrlFrame, Frame, FrameFlags,
1010
FrameId, FrameValue, GeneralEncapsulatedObject, Id3v2Tag, Id3v2Version, OwnershipFrame,
1111
Popularimeter, PrivateFrame, RelativeVolumeAdjustmentFrame, SyncTextContentType,
12-
SynchronizedText, TimestampFormat, UniqueFileIdentifierFrame, UrlLinkFrame,
12+
SynchronizedText, TextInformationFrame, TimestampFormat, UniqueFileIdentifierFrame,
13+
UrlLinkFrame,
1314
};
1415
use lofty::mpeg::MpegFile;
1516
use lofty::{
@@ -41,12 +42,69 @@ fn test_downgrade_utf8_for_id3v23_2() {}
4142

4243
#[test]
4344
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\0Bar"),
48+
};
49+
50+
let data = f.as_bytes();
51+
52+
let no_bom_be_data = b"\x02\
53+
\0F\0o\0o\0\0\
54+
\0B\0a\0r";
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\0Bar");
4561
}
4662

4763
#[test]
4864
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\0Bar"),
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\0o\0o\0\0\0\
77+
B\0a\0r\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\0Bar");
84+
85+
let multi_bom_le_data = b"\x01\xff\xfe\
86+
F\0o\0o\0\0\0\xff\xfe\
87+
B\0a\0r\0";
88+
f = TextInformationFrame::parse(&mut &multi_bom_le_data[..], Id3v2Version::V4)
89+
.unwrap()
90+
.unwrap();
91+
assert_eq!(f.value, "Foo\0Bar");
92+
93+
let multi_bom_be_data = b"\x01\xfe\xff\
94+
\0F\0o\0o\0\0\xfe\xff\
95+
\0B\0a\0r";
96+
f = TextInformationFrame::parse(&mut &multi_bom_be_data[..], Id3v2Version::V4)
97+
.unwrap()
98+
.unwrap();
99+
assert_eq!(f.value, "Foo\0Bar");
100+
101+
let single_bom_be_data = b"\x01\xfe\xff\
102+
\0F\0o\0o\0\0\
103+
\0B\0a\0r";
104+
f = TextInformationFrame::parse(&mut &single_bom_be_data[..], Id3v2Version::V4)
105+
.unwrap()
106+
.unwrap();
107+
assert_eq!(f.value, "Foo\0Bar");
50108
}
51109

52110
#[test]

0 commit comments

Comments
 (0)