Skip to content

Commit ea5c340

Browse files
committed
Tests: Add TagLib APETag tests
1 parent 823afd6 commit ea5c340

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

tests/taglib/data/no-tags.ape

158 Bytes
Binary file not shown.

tests/taglib/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub(crate) mod util;
22

33
mod test_aiff;
44
mod test_ape;
5+
mod test_apetag;

tests/taglib/test_apetag.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use crate::temp_file;
2+
3+
use std::io::Seek;
4+
5+
use lofty::ape::{ApeFile, ApeItem, ApeTag};
6+
use lofty::{Accessor, AudioFile, ItemValue, ParseOptions, TagExt};
7+
8+
#[test]
9+
fn test_is_empty() {
10+
let mut tag = ApeTag::default();
11+
assert!(tag.is_empty());
12+
tag.insert(
13+
ApeItem::new(
14+
String::from("COMPOSER"),
15+
ItemValue::Text(String::from("Mike Oldfield")),
16+
)
17+
.unwrap(),
18+
);
19+
assert!(!tag.is_empty());
20+
}
21+
22+
#[test]
23+
fn test_is_empty_2() {
24+
let mut tag = ApeTag::default();
25+
assert!(tag.is_empty());
26+
tag.set_artist(String::from("Mike Oldfield"));
27+
assert!(!tag.is_empty());
28+
}
29+
30+
#[test]
31+
#[ignore]
32+
fn test_property_interface_1() {
33+
// Marker test, Lofty does not replicate the TagLib property API
34+
}
35+
36+
#[test]
37+
#[ignore]
38+
fn test_property_interface_2() {
39+
// Marker test, Lofty does not replicate the TagLib property API
40+
}
41+
42+
#[test]
43+
fn test_invalid_keys() {
44+
static INVALID_KEY_ONE_CHARACTER: &str = "A";
45+
static INVALID_KEY_FORBIDDEN_STRING: &str = "MP+";
46+
static INVALID_KEY_UNICODE: &str = "\x1234\x3456";
47+
static VALID_KEY_SPACE_AND_TILDE: &str = "A B~C";
48+
static VALID_KEY_NORMAL_ONE: &str = "ARTIST";
49+
50+
assert!(ApeItem::new(
51+
String::from(INVALID_KEY_ONE_CHARACTER),
52+
ItemValue::Text(String::from("invalid key: one character"))
53+
)
54+
.is_err());
55+
assert!(ApeItem::new(
56+
String::from(INVALID_KEY_FORBIDDEN_STRING),
57+
ItemValue::Text(String::from("invalid key: forbidden string"))
58+
)
59+
.is_err());
60+
assert!(ApeItem::new(
61+
String::from(INVALID_KEY_UNICODE),
62+
ItemValue::Text(String::from("invalid key: Unicode"))
63+
)
64+
.is_err());
65+
66+
let valid_space_and_tilde = ApeItem::new(
67+
String::from(VALID_KEY_SPACE_AND_TILDE),
68+
ItemValue::Text(String::from("valid key: space and tilde")),
69+
);
70+
assert!(valid_space_and_tilde.is_ok());
71+
72+
let valid_normal_one = ApeItem::new(
73+
String::from(VALID_KEY_NORMAL_ONE),
74+
ItemValue::Text(String::from("valid key: normal one")),
75+
);
76+
assert!(valid_normal_one.is_ok());
77+
78+
let mut tag = ApeTag::default();
79+
tag.insert(valid_space_and_tilde.unwrap());
80+
tag.insert(valid_normal_one.unwrap());
81+
assert_eq!(tag.items().len(), 2);
82+
}
83+
84+
#[test]
85+
#[ignore]
86+
fn test_text_binary() {
87+
// Marker test, this is useless as Lofty does not have a similar API that the test is based upon:
88+
// https://github.com/taglib/taglib/blob/a31356e330674640a07bef7d71d08242cae8e9bf/tests/test_apetag.cpp#L153
89+
}
90+
91+
// TODO: Does not work! We fall for this collision.
92+
#[test]
93+
#[ignore]
94+
fn test_id3v1_collision() {
95+
// TODO: This uses a musepack file in the TagLib test suite. It makes no difference for this test, but should
96+
// be changed once Musepack is supported in Lofty.
97+
let mut file = temp_file!("tests/taglib/data/no-tags.ape");
98+
{
99+
let mut ape_file =
100+
ApeFile::read_from(&mut file, ParseOptions::new().read_properties(false)).unwrap();
101+
assert!(ape_file.ape().is_none());
102+
assert!(ape_file.id3v1().is_none());
103+
104+
let mut ape_tag = ApeTag::default();
105+
ape_tag.set_artist(String::from("Filltointersect "));
106+
ape_tag.set_title(String::from("Filltointersect "));
107+
ape_file.set_ape(ape_tag);
108+
ape_file.save_to(&mut file).unwrap();
109+
}
110+
{
111+
file.rewind().unwrap();
112+
let ape_file =
113+
ApeFile::read_from(&mut file, ParseOptions::new().read_properties(false)).unwrap();
114+
assert!(ape_file.id3v1().is_none());
115+
}
116+
}

0 commit comments

Comments
 (0)