From c9c44ca5925e0b544da64ce3a9f5f591900476e5 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 22 May 2010 20:06:19 +0000 Subject: [PATCH] Move the playlist parsers to another directory, and add a PlaylistParser class that magically uses the right parser. --- src/CMakeLists.txt | 2 + src/core/CMakeLists.txt | 4 - src/playlistparsers/CMakeLists.txt | 29 +++++++ src/{core => playlistparsers}/m3uparser.cpp | 57 +++++++------ src/{core => playlistparsers}/m3uparser.h | 39 ++++----- src/playlistparsers/parserbase.cpp | 22 +++++ src/playlistparsers/parserbase.h | 37 +++++++++ src/playlistparsers/playlistparser.cpp | 85 ++++++++++++++++++++ src/playlistparsers/playlistparser.h | 44 ++++++++++ src/{core => playlistparsers}/xspfparser.cpp | 22 +++-- src/{core => playlistparsers}/xspfparser.h | 21 +++-- src/ui/CMakeLists.txt | 1 + src/ui/mainwindow.cpp | 19 +---- src/ui/mainwindow.h | 42 +++++----- tests/m3uparser_test.cpp | 18 ++--- tests/xspfparser_test.cpp | 14 ++-- 16 files changed, 332 insertions(+), 124 deletions(-) create mode 100644 src/playlistparsers/CMakeLists.txt rename src/{core => playlistparsers}/m3uparser.cpp (69%) rename src/{core => playlistparsers}/m3uparser.h (75%) create mode 100644 src/playlistparsers/parserbase.cpp create mode 100644 src/playlistparsers/parserbase.h create mode 100644 src/playlistparsers/playlistparser.cpp create mode 100644 src/playlistparsers/playlistparser.h rename src/{core => playlistparsers}/xspfparser.cpp (91%) rename src/{core => playlistparsers}/xspfparser.h (75%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df315ff03..7c9536c35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,6 +32,7 @@ add_subdirectory(core) add_subdirectory(engines) add_subdirectory(library) add_subdirectory(playlist) +add_subdirectory(playlistparsers) add_subdirectory(radio) add_subdirectory(transcoder) add_subdirectory(ui) @@ -59,6 +60,7 @@ target_link_libraries(clementine_lib clementine_engines clementine_library clementine_playlist + clementine_playlistparsers clementine_radio clementine_transcoder clementine_ui diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 07b954e07..816269e1e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -12,7 +12,6 @@ set(SOURCES globalshortcutbackend.cpp globalshortcuts.cpp gnomeglobalshortcutbackend.cpp - m3uparser.cpp mergedproxymodel.cpp networkaccessmanager.cpp player.cpp @@ -22,7 +21,6 @@ set(SOURCES song.cpp stylesheetloader.cpp utilities.cpp - xspfparser.cpp ) set(HEADERS @@ -32,11 +30,9 @@ set(HEADERS database.h globalshortcuts.h gnomeglobalshortcutbackend.h - m3uparser.h mergedproxymodel.h networkaccessmanager.h player.h - xspfparser.h ) if(NOT APPLE AND NOT WIN32) diff --git a/src/playlistparsers/CMakeLists.txt b/src/playlistparsers/CMakeLists.txt new file mode 100644 index 000000000..efe1ddc32 --- /dev/null +++ b/src/playlistparsers/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 2.6) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +set(SOURCES + m3uparser.cpp + parserbase.cpp + playlistparser.cpp + xspfparser.cpp +) + +set(HEADERS + m3uparser.h + parserbase.h + playlistparser.h + xspfparser.h +) + +qt4_wrap_cpp(MOC ${HEADERS}) + +add_library(clementine_playlistparsers + ${SOURCES} + ${MOC} +) + +target_link_libraries(clementine_playlistparsers +) + +add_translation_source(playlistparsers ${SOURCES} ${MOC}) diff --git a/src/core/m3uparser.cpp b/src/playlistparsers/m3uparser.cpp similarity index 69% rename from src/core/m3uparser.cpp rename to src/playlistparsers/m3uparser.cpp index cba6d57e9..d4d10d8ca 100644 --- a/src/core/m3uparser.cpp +++ b/src/playlistparsers/m3uparser.cpp @@ -18,54 +18,57 @@ #include -M3UParser::M3UParser(QIODevice* device, const QDir& directory, QObject* parent) - : QObject(parent), - device_(device), - type_(STANDARD), - directory_(directory) { +M3UParser::M3UParser(QObject* parent) + : ParserBase(parent) +{ } -const QList& M3UParser::Parse() { - QString line = QString::fromLatin1(device_->readLine()).trimmed(); +SongList M3UParser::Load(QIODevice* device, const QDir& dir) const { + SongList ret; + + M3UType type = STANDARD; + Metadata current_metadata; + + QString line = QString::fromLatin1(device->readLine()).trimmed(); if (line.startsWith("#EXTM3U")) { // This is in extended M3U format. - type_ = EXTENDED; - line = QString::fromLatin1(device_->readLine()).trimmed(); + type = EXTENDED; + line = QString::fromLatin1(device->readLine()).trimmed(); } forever { if (line.startsWith('#')) { // Extended info or comment. - if (type_ == EXTENDED && line.startsWith("#EXT")) { - if (!ParseMetadata(line, ¤t_metadata_)) { + if (type == EXTENDED && line.startsWith("#EXT")) { + if (!ParseMetadata(line, ¤t_metadata)) { qWarning() << "Failed to parse metadata: " << line; continue; } } } else { Song song; - song.Init(current_metadata_.title, - current_metadata_.artist, + song.Init(current_metadata.title, + current_metadata.artist, QString(), // Unknown album. - current_metadata_.length); + current_metadata.length); + // Track location. - QString location; - if (!ParseTrackLocation(line, &song)) { + if (!ParseTrackLocation(line, dir, &song)) { qWarning() << "Failed to parse location: " << line; } else { - songs_ << song; - current_metadata_.artist.clear(); - current_metadata_.title.clear(); - current_metadata_.length = -1; + ret << song; + current_metadata.artist.clear(); + current_metadata.title.clear(); + current_metadata.length = -1; } } - if (device_->atEnd()) { + if (device->atEnd()) { break; } - line = QString::fromLatin1(device_->readLine()).trimmed(); + line = QString::fromLatin1(device->readLine()).trimmed(); } - return songs_; + return ret; } bool M3UParser::ParseMetadata(const QString& line, M3UParser::Metadata* metadata) const { @@ -89,7 +92,7 @@ bool M3UParser::ParseMetadata(const QString& line, M3UParser::Metadata* metadata return true; } -bool M3UParser::ParseTrackLocation(const QString& line, Song* song) const { +bool M3UParser::ParseTrackLocation(const QString& line, const QDir& dir, Song* song) const { if (line.contains(QRegExp("^[a-z]+://"))) { // Looks like a url. QUrl temp(line); @@ -113,7 +116,7 @@ bool M3UParser::ParseTrackLocation(const QString& line, Song* song) const { } else { // Relative path. QString proper_path = QDir::fromNativeSeparators(line); - QString absolute_path = directory_.absoluteFilePath(proper_path); + QString absolute_path = dir.absoluteFilePath(proper_path); if (!QFile::exists(absolute_path)) { return false; } @@ -122,3 +125,7 @@ bool M3UParser::ParseTrackLocation(const QString& line, Song* song) const { song->InitFromFile(song->filename(), -1); return true; } + +void M3UParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) const { + // TODO +} diff --git a/src/core/m3uparser.h b/src/playlistparsers/m3uparser.h similarity index 75% rename from src/core/m3uparser.h rename to src/playlistparsers/m3uparser.h index 0ad069f1c..ed06cfdbd 100644 --- a/src/core/m3uparser.h +++ b/src/playlistparsers/m3uparser.h @@ -17,31 +17,22 @@ #ifndef M3UPARSER_H #define M3UPARSER_H -#include -#include #include #include "gtest/gtest_prod.h" -#include "song.h" +#include "parserbase.h" -class QIODevice; - -class M3UParser : public QObject { +class M3UParser : public ParserBase { Q_OBJECT + public: - M3UParser(QIODevice* device, const QDir& directory = QDir(), QObject* parent = 0); - virtual ~M3UParser() {} + M3UParser(QObject* parent = 0); - // Reference valid as long as the M3UParser instance lives. - const SongList& Parse(); + QStringList file_extensions() const { return QStringList() << "m3u"; } - struct Metadata { - Metadata() : length(-1) {} - QString artist; - QString title; - int length; - }; + SongList Load(QIODevice* device, const QDir& dir = QDir()) const; + void Save(const SongList &songs, QIODevice* device, const QDir& dir = QDir()) const; private: enum M3UType { @@ -50,8 +41,15 @@ class M3UParser : public QObject { LINK, // Points to a directory. }; + struct Metadata { + Metadata() : length(-1) {} + QString artist; + QString title; + int length; + }; + bool ParseMetadata(const QString& line, Metadata* metadata) const; - bool ParseTrackLocation(const QString& line, Song* song) const; + bool ParseTrackLocation(const QString& line, const QDir& dir, Song* song) const; FRIEND_TEST(M3UParserTest, ParsesMetadata); FRIEND_TEST(M3UParserTest, ParsesTrackLocation); @@ -60,13 +58,6 @@ class M3UParser : public QObject { #ifdef Q_OS_WIN32 FRIEND_TEST(M3UParserTest, ParsesTrackLocationAbsoluteWindows); #endif // Q_OS_WIN32 - - QIODevice* device_; - M3UType type_; - QDir directory_; - Metadata current_metadata_; - - SongList songs_; }; #endif // M3UPARSER_H diff --git a/src/playlistparsers/parserbase.cpp b/src/playlistparsers/parserbase.cpp new file mode 100644 index 000000000..610070143 --- /dev/null +++ b/src/playlistparsers/parserbase.cpp @@ -0,0 +1,22 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "parserbase.h" + +ParserBase::ParserBase(QObject *parent) + : QObject(parent) +{ +} diff --git a/src/playlistparsers/parserbase.h b/src/playlistparsers/parserbase.h new file mode 100644 index 000000000..0a3305b43 --- /dev/null +++ b/src/playlistparsers/parserbase.h @@ -0,0 +1,37 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef PARSERBASE_H +#define PARSERBASE_H + +#include +#include + +#include "core/song.h" + +class ParserBase : public QObject { + Q_OBJECT + +public: + ParserBase(QObject *parent = 0); + + virtual QStringList file_extensions() const = 0; + + virtual SongList Load(QIODevice* device, const QDir& dir = QDir()) const = 0; + virtual void Save(const SongList& songs, QIODevice* device, const QDir& dir = QDir()) const = 0; +}; + +#endif // PARSERBASE_H diff --git a/src/playlistparsers/playlistparser.cpp b/src/playlistparsers/playlistparser.cpp new file mode 100644 index 000000000..feb8758a9 --- /dev/null +++ b/src/playlistparsers/playlistparser.cpp @@ -0,0 +1,85 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "playlistparser.h" +#include "xspfparser.h" +#include "m3uparser.h" + +#include + +PlaylistParser::PlaylistParser(QObject *parent) + : QObject(parent) +{ + parsers_ << new M3UParser(this); + parsers_ << new XSPFParser(this); +} + +QStringList PlaylistParser::file_extensions() const { + QStringList ret; + + foreach (ParserBase* parser, parsers_) { + ret << parser->file_extensions(); + } + + qStableSort(ret); + return ret; +} + +bool PlaylistParser::can_load(const QString &filename) const { + return file_extensions().contains(QFileInfo(filename).suffix()); +} + +ParserBase* PlaylistParser::ParserForExtension(const QString& suffix) const { + foreach (ParserBase* p, parsers_) { + if (p->file_extensions().contains(suffix)) + return p; + } + return NULL; +} + +SongList PlaylistParser::Load(const QString &filename) const { + QFileInfo info(filename); + + // Find a parser that supports this file extension + ParserBase* parser = ParserForExtension(info.suffix()); + if (!parser) { + qWarning() << "Unknown filetype:" << filename; + return SongList(); + } + + // Open the file + QFile file(filename); + file.open(QIODevice::ReadOnly); + + return parser->Load(&file, info.absolutePath()); +} + +void PlaylistParser::Save(const SongList &songs, const QString &filename) const { + QFileInfo info(filename); + + // Find a parser that supports this file extension + ParserBase* parser = ParserForExtension(info.suffix()); + if (!parser) { + qWarning() << "Unknown filetype:" << filename; + return; + } + + // Open the file + QFile file(filename); + file.open(QIODevice::WriteOnly); + + return parser->Save(songs, &file, info.absolutePath()); +} diff --git a/src/playlistparsers/playlistparser.h b/src/playlistparsers/playlistparser.h new file mode 100644 index 000000000..ab486f161 --- /dev/null +++ b/src/playlistparsers/playlistparser.h @@ -0,0 +1,44 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef PLAYLISTPARSER_H +#define PLAYLISTPARSER_H + +#include + +#include "core/song.h" + +class ParserBase; + +class PlaylistParser : public QObject { + Q_OBJECT + +public: + PlaylistParser(QObject *parent = 0); + + QStringList file_extensions() const; + bool can_load(const QString& filename) const; + + SongList Load(const QString& filename) const; + void Save(const SongList& songs, const QString& filename) const; + +private: + ParserBase* ParserForExtension(const QString& suffix) const; + + QList parsers_; +}; + +#endif // PLAYLISTPARSER_H diff --git a/src/core/xspfparser.cpp b/src/playlistparsers/xspfparser.cpp similarity index 91% rename from src/core/xspfparser.cpp rename to src/playlistparsers/xspfparser.cpp index dad0fffa8..ac398725d 100644 --- a/src/core/xspfparser.cpp +++ b/src/playlistparsers/xspfparser.cpp @@ -21,25 +21,27 @@ #include #include -XSPFParser::XSPFParser(QIODevice* device, QObject* parent) - : QObject(parent), - device_(device) { +XSPFParser::XSPFParser(QObject* parent) + : ParserBase(parent) +{ } -const SongList& XSPFParser::Parse() { - QXmlStreamReader reader(device_); +SongList XSPFParser::Load(QIODevice *device, const QDir&) const { + SongList ret; + + QXmlStreamReader reader(device); if (!ParseUntilElement(&reader, "playlist") || !ParseUntilElement(&reader, "trackList")) { - return songs_; + return ret; } while (!reader.atEnd() && ParseUntilElement(&reader, "track")) { Song song = ParseTrack(&reader); if (song.is_valid()) { - songs_ << song; + ret << song; } } - return songs_; + return ret; } bool XSPFParser::ParseUntilElement(QXmlStreamReader* reader, const QString& name) const { @@ -133,3 +135,7 @@ Song XSPFParser::ParseTrack(QXmlStreamReader* reader) const { song.Init(title, artist, album, length); return song; } + +void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) const { + +} diff --git a/src/core/xspfparser.h b/src/playlistparsers/xspfparser.h similarity index 75% rename from src/core/xspfparser.h rename to src/playlistparsers/xspfparser.h index ebdb72a38..9977e74eb 100644 --- a/src/core/xspfparser.h +++ b/src/playlistparsers/xspfparser.h @@ -17,28 +17,25 @@ #ifndef XSPFPARSER_H #define XSPFPARSER_H -#include "song.h" +#include "parserbase.h" -#include #include -class QIODevice; - -class XSPFParser : public QObject { +class XSPFParser : public ParserBase { Q_OBJECT - public: - XSPFParser(QIODevice* device, QObject* parent = 0); - virtual ~XSPFParser() {} - const SongList& Parse(); + public: + XSPFParser(QObject* parent = 0); + + QStringList file_extensions() const { return QStringList() << "xspf"; } + + SongList Load(QIODevice *device, const QDir &dir = QDir()) const; + void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir()) const; private: bool ParseUntilElement(QXmlStreamReader* reader, const QString& element) const; void IgnoreElement(QXmlStreamReader* reader) const; Song ParseTrack(QXmlStreamReader* reader) const; - - QIODevice* device_; - SongList songs_; }; #endif diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 7301d7f7d..0405d09c2 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -56,6 +56,7 @@ target_link_libraries(clementine_ui clementine_engines clementine_library clementine_playlist + clementine_playlistparsers clementine_radio clementine_transcoder ) diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 0c7456a46..7fd799b22 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -20,12 +20,10 @@ #include "core/commandlineoptions.h" #include "core/database.h" #include "core/globalshortcuts.h" -#include "core/m3uparser.h" #include "core/mac_startup.h" #include "core/mergedproxymodel.h" #include "core/player.h" #include "core/stylesheetloader.h" -#include "core/xspfparser.h" #include "engines/enginebase.h" #include "library/groupbydialog.h" #include "library/libraryconfigdialog.h" @@ -37,6 +35,7 @@ #include "playlist/playlistsequence.h" #include "playlist/playlistview.h" #include "playlist/songplaylistitem.h" +#include "playlistparsers/playlistparser.h" #include "radio/lastfmservice.h" #include "radio/radiomodel.h" #include "radio/radioview.h" @@ -106,6 +105,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg radio_model_(new RadioModel(database_, network, this)), playlist_backend_(new PlaylistBackend(database_, this)), playlists_(new PlaylistManager(this)), + playlist_parser_(new PlaylistParser(this)), player_(new Player(playlists_, radio_model_->GetLastFMService(), engine, this)), library_(new Library(database_, this)), global_shortcuts_(new GlobalShortcuts(this)), @@ -930,19 +930,8 @@ void MainWindow::AddFile() { // Add media QList urls; foreach (const QString& path, file_names) { - if (path.endsWith(".m3u")) { - QFile file(path); - QFileInfo info(file); - file.open(QIODevice::ReadOnly); - M3UParser parser(&file, info.dir()); - const SongList& songs = parser.Parse(); - playlists_->current()->InsertSongs(songs); - } else if (path.endsWith(".xspf") || path.endsWith(".xml")) { - QFile file(path); - file.open(QIODevice::ReadOnly); - XSPFParser parser(&file); - const SongList& songs = parser.Parse(); - playlists_->current()->InsertSongs(songs); + if (playlist_parser_->can_load(path)) { + playlists_->current()->InsertSongs(playlist_parser_->Load(path)); } else { QUrl url(QUrl::fromLocalFile(path)); if (url.scheme().isEmpty()) diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index dfc797d05..351920eaa 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -27,34 +27,35 @@ #include "library/librarymodel.h" #include "playlist/playlistitem.h" -class PlaylistManager; -class Player; -class Library; -class PlaylistBackend; -class RadioModel; -class Song; -class RadioItem; -class OSD; -class TrackSlider; -class EditTagDialog; -class MultiLoadingIndicator; -class SettingsDialog; class About; class AddStreamDialog; class AlbumCoverManager; -class PlaylistSequence; -class GlobalShortcuts; -class GroupByDialog; -class Equalizer; class CommandlineOptions; -class TranscodeDialog; class Database; -class NetworkAccessManager; -class Ui_MainWindow; +class EditTagDialog; +class Equalizer; +class GlobalShortcuts; class GlobalShortcutsDialog; +class GroupByDialog; +class Library; +class MultiLoadingIndicator; +class NetworkAccessManager; +class OSD; +class Player; +class PlaylistBackend; +class PlaylistManager; +class PlaylistParser; +class PlaylistSequence; +class RadioItem; +class RadioModel; +class SettingsDialog; +class Song; +class SystemTrayIcon; +class TrackSlider; +class TranscodeDialog; +class Ui_MainWindow; class QSortFilterProxyModel; -class SystemTrayIcon; class MainWindow : public QMainWindow { Q_OBJECT @@ -162,6 +163,7 @@ class MainWindow : public QMainWindow { RadioModel* radio_model_; PlaylistBackend* playlist_backend_; PlaylistManager* playlists_; + PlaylistParser* playlist_parser_; Player* player_; Library* library_; GlobalShortcuts* global_shortcuts_; diff --git a/tests/m3uparser_test.cpp b/tests/m3uparser_test.cpp index 00ce40dcc..69a12c364 100644 --- a/tests/m3uparser_test.cpp +++ b/tests/m3uparser_test.cpp @@ -18,7 +18,7 @@ #include "test_utils.h" #include "mock_taglib.h" -#include "core/m3uparser.h" +#include "playlistparsers/m3uparser.h" #include #include @@ -52,7 +52,7 @@ TEST_F(M3UParserTest, ParsesTrackLocation) { taglib_.ExpectCall(temp.fileName(), "foo", "bar", "baz"); Song song(&taglib_); QString line(temp.fileName()); - ASSERT_TRUE(parser_.ParseTrackLocation(line, &song)); + ASSERT_TRUE(parser_.ParseTrackLocation(line, QDir(), &song)); EXPECT_EQ(temp.fileName(), song.filename()); EXPECT_EQ("foo", song.title()); EXPECT_EQ("bar", song.artist()); @@ -64,10 +64,10 @@ TEST_F(M3UParserTest, ParsesTrackLocationRelative) { temp.open(); QFileInfo info(temp); taglib_.ExpectCall(temp.fileName(), "foo", "bar", "baz"); - M3UParser parser(NULL, info.dir()); + M3UParser parser; QString line(info.fileName()); Song song(&taglib_); - ASSERT_TRUE(parser.ParseTrackLocation(line, &song)); + ASSERT_TRUE(parser.ParseTrackLocation(line, info.dir(), &song)); EXPECT_EQ(temp.fileName(), song.filename()); EXPECT_EQ("foo", song.title()); } @@ -75,7 +75,7 @@ TEST_F(M3UParserTest, ParsesTrackLocationRelative) { TEST_F(M3UParserTest, ParsesTrackLocationHttp) { QString line("http://example.com/foo/bar.mp3"); Song song; - ASSERT_TRUE(parser_.ParseTrackLocation(line, &song)); + ASSERT_TRUE(parser_.ParseTrackLocation(line, QDir(), &song)); EXPECT_EQ("http://example.com/foo/bar.mp3", song.filename()); } @@ -85,8 +85,8 @@ TEST_F(M3UParserTest, ParsesSongsFromDevice) { "http://foo.com/bar/somefile.mp3\n"; QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); - M3UParser parser(&buffer); - const QList& songs = parser.Parse(); + M3UParser parser; + SongList songs = parser.Load(&buffer); ASSERT_EQ(1, songs.size()); Song s = songs[0]; EXPECT_EQ("Some Artist", s.artist()); @@ -101,8 +101,8 @@ TEST_F(M3UParserTest, ParsesNonExtendedM3U) { "http://baz.com/thing.mp3\n"; QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); - M3UParser parser(&buffer, QDir("somedir")); - const QList& songs = parser.Parse(); + M3UParser parser; + SongList songs = parser.Load(&buffer, QDir("somedir")); ASSERT_EQ(2, songs.size()); EXPECT_PRED_FORMAT2(::testing::IsSubstring, "http://foo.com/bar/somefile.mp3", songs[0].filename().toStdString()); diff --git a/tests/xspfparser_test.cpp b/tests/xspfparser_test.cpp index 594fb4c9d..2fe0fc2ed 100644 --- a/tests/xspfparser_test.cpp +++ b/tests/xspfparser_test.cpp @@ -17,7 +17,7 @@ #include "test_utils.h" #include "gtest/gtest.h" -#include "core/xspfparser.h" +#include "playlistparsers/xspfparser.h" #include @@ -38,8 +38,8 @@ TEST_F(XSPFParserTest, ParsesOneTrackFromXML) { ""; QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); - XSPFParser parser(&buffer); - const SongList& songs = parser.Parse(); + XSPFParser parser; + SongList songs = parser.Load(&buffer); ASSERT_EQ(1, songs.length()); const Song& song = songs[0]; EXPECT_EQ("Foo", song.title()); @@ -62,8 +62,8 @@ TEST_F(XSPFParserTest, ParsesMoreThanOneTrackFromXML) { ""; QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); - XSPFParser parser(&buffer); - const SongList& songs = parser.Parse(); + XSPFParser parser; + SongList songs = parser.Load(&buffer); 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()); @@ -84,8 +84,8 @@ TEST_F(XSPFParserTest, IgnoresInvalidLength) { ""; QBuffer buffer(&data); buffer.open(QIODevice::ReadOnly); - XSPFParser parser(&buffer); - const SongList& songs = parser.Parse(); + XSPFParser parser; + SongList songs = parser.Load(&buffer); ASSERT_EQ(1, songs.length()); EXPECT_EQ(-1, songs[0].length()); }