mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-14 18:56:32 +01:00
Fix code review comment for r353
Add more tests for XSPF parser.
This commit is contained in:
parent
116204d58e
commit
e809019bef
@ -94,9 +94,8 @@ Song XSPFParser::ParseTrack(QXmlStreamReader* reader) const {
|
||||
bool ok = false;
|
||||
length = duration.toInt(&ok) / 1000;
|
||||
if (!ok) {
|
||||
return Song();
|
||||
length = -1;
|
||||
}
|
||||
song.set_length(length);
|
||||
} else if (name == "image") {
|
||||
// TODO: Fetch album covers.
|
||||
} else if (name == "info") {
|
||||
|
@ -30,5 +30,46 @@ TEST_F(XSPFParserTest, ParsesOneTrackFromXML) {
|
||||
EXPECT_EQ("Bar", song.artist());
|
||||
EXPECT_EQ("Baz", song.album());
|
||||
EXPECT_EQ("http://example.com/foo.mp3", song.filename());
|
||||
EXPECT_EQ(60, song.length());
|
||||
EXPECT_TRUE(song.is_valid());
|
||||
}
|
||||
|
||||
TEST_F(XSPFParserTest, ParsesMoreThanOneTrackFromXML) {
|
||||
QByteArray data =
|
||||
"<playlist><trackList>"
|
||||
"<track>"
|
||||
"<location>http://example.com/foo.mp3</location>"
|
||||
"</track>"
|
||||
"<track>"
|
||||
"<location>http://example.com/bar.mp3</location>"
|
||||
"</track>"
|
||||
"</trackList></playlist>";
|
||||
QBuffer buffer(&data);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
XSPFParser parser(&buffer);
|
||||
const SongList& songs = parser.Parse();
|
||||
ASSERT_EQ(2, songs.length());
|
||||
EXPECT_EQ("http://example.com/foo.mp3", songs[0].filename());
|
||||
EXPECT_EQ("http://example.com/bar.mp3", songs[1].filename());
|
||||
EXPECT_EQ(Song::Type_Stream, songs[0].filetype());
|
||||
EXPECT_EQ(Song::Type_Stream, songs[1].filetype());
|
||||
}
|
||||
|
||||
TEST_F(XSPFParserTest, IgnoresInvalidLength) {
|
||||
QByteArray data =
|
||||
"<playlist><trackList><track>"
|
||||
"<location>http://example.com/foo.mp3</location>"
|
||||
"<title>Foo</title>"
|
||||
"<creator>Bar</creator>"
|
||||
"<album>Baz</album>"
|
||||
"<duration>60000qwerty</duration>"
|
||||
"<image>http://example.com/albumcover.jpg</image>"
|
||||
"<info>http://example.com</info>"
|
||||
"</track></trackList></playlist>";
|
||||
QBuffer buffer(&data);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
XSPFParser parser(&buffer);
|
||||
const SongList& songs = parser.Parse();
|
||||
ASSERT_EQ(1, songs.length());
|
||||
EXPECT_EQ(-1, songs[0].length());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user