mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-14 10:24:19 +01:00
Ensure Song is valid from m3u parser.
Fix tests.
This commit is contained in:
parent
768bf85cd7
commit
1aebf19077
@ -28,9 +28,9 @@ const QList<Song>& M3UParser::Parse() {
|
||||
}
|
||||
} else {
|
||||
Song song;
|
||||
song.set_title(current_metadata_.title);
|
||||
song.set_artist(current_metadata_.artist);
|
||||
song.set_length(current_metadata_.length);
|
||||
song.Init(current_metadata_.title,
|
||||
current_metadata_.artist,
|
||||
current_metadata_.length);
|
||||
// Track location.
|
||||
QString location;
|
||||
if (!ParseTrackLocation(line, &song)) {
|
||||
|
@ -17,6 +17,7 @@ class M3UParser : public QObject {
|
||||
M3UParser(QIODevice* device, const QDir& directory = QDir(), QObject* parent = 0);
|
||||
virtual ~M3UParser() {}
|
||||
|
||||
// Reference valid as long as the M3UParser instance lives.
|
||||
const SongList& Parse();
|
||||
|
||||
struct Metadata {
|
||||
|
@ -90,6 +90,13 @@ Song::Song(FileRefFactory* factory)
|
||||
factory_(factory) {
|
||||
}
|
||||
|
||||
void Song::Init(const QString& title, const QString& artist, int length) {
|
||||
d->valid_ = true;
|
||||
d->title_ = title;
|
||||
d->artist_ = artist;
|
||||
d->length_ = length;
|
||||
}
|
||||
|
||||
void Song::InitFromFile(const QString& filename, int directory_id) {
|
||||
d->filename_ = filename;
|
||||
d->directory_id_ = directory_id;
|
||||
|
@ -78,6 +78,7 @@ class Song {
|
||||
static const char* kUpdateSpec;
|
||||
|
||||
// Constructors
|
||||
void Init(const QString& title, const QString& artist, int length);
|
||||
void InitFromFile(const QString& filename, int directory_id);
|
||||
void InitFromQuery(const QSqlQuery& query);
|
||||
void InitFromLastFM(const lastfm::Track& track);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "m3uparser.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
class M3UParserTest : public ::testing::Test {
|
||||
protected:
|
||||
@ -30,23 +31,28 @@ TEST_F(M3UParserTest, ParsesMetadata) {
|
||||
}
|
||||
|
||||
TEST_F(M3UParserTest, ParsesTrackLocation) {
|
||||
taglib_.ExpectCall("/foo/bar.mp3", "foo", "bar", "baz");
|
||||
QTemporaryFile temp;
|
||||
temp.open();
|
||||
taglib_.ExpectCall(temp.fileName(), "foo", "bar", "baz");
|
||||
Song song(&taglib_);
|
||||
QString line("/foo/bar.mp3");
|
||||
QString line(temp.fileName());
|
||||
ASSERT_TRUE(parser_.ParseTrackLocation(line, &song));
|
||||
EXPECT_EQ("/foo/bar.mp3", song.filename());
|
||||
EXPECT_EQ(temp.fileName(), song.filename());
|
||||
EXPECT_EQ("foo", song.title());
|
||||
EXPECT_EQ("bar", song.artist());
|
||||
EXPECT_EQ("baz", song.album());
|
||||
}
|
||||
|
||||
TEST_F(M3UParserTest, ParsesTrackLocationRelative) {
|
||||
taglib_.ExpectCall("/tmp/foo/bar.mp3", "foo", "bar", "baz");
|
||||
M3UParser parser(NULL, QDir("/tmp"));
|
||||
QString line("foo/bar.mp3");
|
||||
QTemporaryFile temp;
|
||||
temp.open();
|
||||
QFileInfo info(temp);
|
||||
taglib_.ExpectCall(temp.fileName(), "foo", "bar", "baz");
|
||||
M3UParser parser(NULL, info.dir());
|
||||
QString line(info.fileName());
|
||||
Song song(&taglib_);
|
||||
ASSERT_TRUE(parser.ParseTrackLocation(line, &song));
|
||||
EXPECT_EQ("/tmp/foo/bar.mp3", song.filename());
|
||||
EXPECT_EQ(temp.fileName(), song.filename());
|
||||
EXPECT_EQ("foo", song.title());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "mock_taglib.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
#include <QFile>
|
||||
|
||||
using ::testing::Return;
|
||||
|
||||
@ -34,9 +34,7 @@ void MockFileRefFactory::ExpectCall(const QString& filename,
|
||||
|
||||
TagLib::FileRef* MockFileRefFactory::GetFileRef(const QString& filename) {
|
||||
MockTag* tag = tags_.take(filename);
|
||||
QTemporaryFile temp_file;
|
||||
temp_file.open();
|
||||
MockFile* file = new MockFile(tag, temp_file.fileName());
|
||||
MockFile* file = new MockFile(tag, filename);
|
||||
TagLib::FileRef* fileref = new TagLib::FileRef(file);
|
||||
return fileref;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "test_utils.h"
|
||||
#include "mock_taglib.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
|
||||
namespace {
|
||||
|
||||
class SongTest : public ::testing::Test {
|
||||
@ -36,9 +38,11 @@ TEST_F(SongTest, InitsFromLastFM) {
|
||||
}
|
||||
|
||||
TEST_F(SongTest, InitsFromFile) {
|
||||
mock_factory_.ExpectCall("foobar.mp3", "Foo", "Bar", "Baz");
|
||||
QTemporaryFile temp;
|
||||
temp.open();
|
||||
mock_factory_.ExpectCall(temp.fileName(), "Foo", "Bar", "Baz");
|
||||
Song song(&mock_factory_);
|
||||
song.InitFromFile("foobar.mp3", 42);
|
||||
song.InitFromFile(temp.fileName(), 42);
|
||||
EXPECT_EQ("Foo", song.title());
|
||||
EXPECT_EQ("Bar", song.artist());
|
||||
EXPECT_EQ("Baz", song.album());
|
||||
|
Loading…
Reference in New Issue
Block a user