[quarkplayer] r1420 committed - Fix PlaylistParser library

0 views
Skip to first unread message

quark...@googlecode.com

unread,
Feb 17, 2011, 10:54:06 AM2/17/11
to quarkplay...@googlegroups.com
Revision: 1420
Author: tkrotoff
Date: Thu Feb 17 07:53:14 2011
Log: Fix PlaylistParser library
http://code.google.com/p/quarkplayer/source/detail?r=1420

Added:
/trunk/tests/libs/PlaylistParser/PlaylistReaderTest.cpp
/trunk/tests/libs/PlaylistParser/PlaylistReaderTest.h
/trunk/tests/libs/PlaylistParser/PlaylistWriterTest.cpp
/trunk/tests/libs/PlaylistParser/PlaylistWriterTest.h
Deleted:
/trunk/tests/libs/PlaylistParser/PlaylistParserTest.cpp
/trunk/tests/libs/PlaylistParser/PlaylistParserTest.h
Modified:
/trunk/libs/MediaInfoFetcher/MediaInfo.cpp
/trunk/libs/PlaylistParser/ASXParser.cpp
/trunk/libs/PlaylistParser/ASXParser.h
/trunk/libs/PlaylistParser/CUEParser.cpp
/trunk/libs/PlaylistParser/CUEParser.h
/trunk/libs/PlaylistParser/IPlaylistParser.h
/trunk/libs/PlaylistParser/IPlaylistParserImpl.h
/trunk/libs/PlaylistParser/M3UParser.cpp
/trunk/libs/PlaylistParser/M3UParser.h
/trunk/libs/PlaylistParser/PLSParser.cpp
/trunk/libs/PlaylistParser/PLSParser.h
/trunk/libs/PlaylistParser/PlaylistParser.cpp
/trunk/libs/PlaylistParser/PlaylistParser.h
/trunk/libs/PlaylistParser/Util.cpp
/trunk/libs/PlaylistParser/Util.h
/trunk/libs/PlaylistParser/WPLParser.cpp
/trunk/libs/PlaylistParser/WPLParser.h
/trunk/libs/PlaylistParser/XSPFParser.cpp
/trunk/libs/PlaylistParser/XSPFParser.h
/trunk/tests/libs/PlaylistParser/CMakeLists.txt

=======================================
--- /dev/null
+++ /trunk/tests/libs/PlaylistParser/PlaylistReaderTest.cpp Thu Feb 17
07:53:14 2011
@@ -0,0 +1,458 @@
+/*
+ * QuarkPlayer, a Phonon media player
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "PlaylistReaderTest.h"
+
+#include <PlaylistParser/PlaylistParser.h>
+#include <PlaylistParser/PlaylistParserLogger.h>
+
+#include <MediaInfoFetcher/MediaInfo.h>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QFile>
+#include <QtCore/QList>
+
+QTEST_MAIN(PlaylistReaderTest)
+
+void disableMessageOutput(QtMsgType type, const char * msg) {
+ Q_UNUSED(type);
+ Q_UNUSED(msg);
+}
+
+void PlaylistReaderTest::initTestCase() {
+ //Disable qDebug() and friends
+ qInstallMsgHandler(disableMessageOutput);
+ ///
+
+ //Playlist reader
+ _reader = new PlaylistReader(this);
+ connect(_reader, SIGNAL(filesFound(const QList<MediaInfo> &)),
+ SLOT(filesFound(const QList<MediaInfo> &)));
+ connect(_reader, SIGNAL(finished(PlaylistParser::Error, int)),
+ SLOT(finished(PlaylistParser::Error, int)));
+}
+
+void PlaylistReaderTest::cleanupTestCase() {
+}
+
+void PlaylistReaderTest::init() {
+}
+
+void PlaylistReaderTest::cleanup() {
+}
+
+void PlaylistReaderTest::loadPlaylist_data() {
+ QTest::addColumn<QString>("playlistFileName");
+ QTest::addColumn<QList<MediaInfo> >("filesToFind");
+ QTest::addColumn<int>("parserError");
+ QTest::addColumn<int>("parserTimeElapsed");
+
+ //Non existing file
+ QTest::newRow("Non existing File") << "Non existing File.m3u"
+ << QList<MediaInfo>()
+ << static_cast<int>(PlaylistParser::IOError)
+ << 0;
+
+ //Unsupported format: The KMPlayer proprietary format
+ QTest::newRow("Unsupported Format") << ":/TheKMPlayer/test.KPL"
+ << QList<MediaInfo>()
+ << static_cast<int>(PlaylistParser::UnsupportedFormatError)
+ << 0;
+
+ loadPlaylistM3U();
+ loadPlaylistWPL();
+ loadPlaylistPLS();
+ loadPlaylistASX();
+ loadPlaylistXSPF();
+ loadPlaylistCUE();
+}
+
+QList<MediaInfo> localM3UPlaylist() {
+ return QList<MediaInfo>()
+ << MediaInfo("C:\\1.mp3")
+ << MediaInfo("C:\\2.mp3")
+ << MediaInfo("C:\\3.mp3")
+ << MediaInfo("C:\\4.mp3")
+ << MediaInfo("C:\\5.mp3");
+}
+
+QList<MediaInfo> localM3UPlaylist_WithMetaDatas() {
+ QList<MediaInfo> mediaInfoList;
+
+ MediaInfo m1("C:\\1.mp3");
+ m1.setDurationSecs(0);
+ mediaInfoList << m1;
+
+ MediaInfo m2("C:\\2.mp3");
+ m2.setMetaData(MediaInfo::Title, "Title2");
+ m2.setDurationSecs(0);
+ mediaInfoList << m2;
+
+ MediaInfo m3("C:\\3.mp3");
+ //m3.setMetaData(MediaInfo::Title, "Artist3 - 3");
+ m3.setDurationSecs(0);
+ mediaInfoList << m3;
+
+ MediaInfo m4("C:\\4.mp3");
+ m4.setMetaData(MediaInfo::Title, "Artist4 - Title4");
+ m4.setDurationSecs(0);
+ mediaInfoList << m4;
+
+ MediaInfo m5("C:\\5.mp3");
+ m5.setMetaData(MediaInfo::Title, "Artist5 - Title5");
+ m5.setDurationSecs(0);
+ mediaInfoList << m5;
+
+ return mediaInfoList;
+}
+
+QList<MediaInfo> localM3UPlaylist_NoRoot() {
+ return QList<MediaInfo>()
+ << MediaInfo("\\1.mp3")
+ << MediaInfo("\\2.mp3")
+ << MediaInfo("\\3.mp3")
+ << MediaInfo("\\4.mp3")
+ << MediaInfo("\\5.mp3");
+}
+
+QList<MediaInfo> localM3UPlaylist_Relative() {
+ return QList<MediaInfo>()
+ << MediaInfo("..\\mp3\\1.mp3")
+ << MediaInfo("..\\mp3\\2.mp3")
+ << MediaInfo("..\\mp3\\3.mp3")
+ << MediaInfo("..\\mp3\\4.mp3")
+ << MediaInfo("..\\mp3\\5.mp3");
+}
+
+QList<MediaInfo> localXSPFPlaylist() {
+ QList<MediaInfo> mediaInfoList;
+
+ MediaInfo m1("file:///C:/1.mp3");
+ mediaInfoList << m1;
+
+ MediaInfo m2("file:///C:/2.mp3");
+ m2.setMetaData(MediaInfo::TrackNumber, 2);
+ //m2.setMetaData(MediaInfo::DiscNumber, 2);
+ //m2.setMetaData(MediaInfo::BPM, 2);
+ m2.setMetaData(MediaInfo::Title, "Title2");
+ m2.setMetaData(MediaInfo::Album, "Album2");
+ //m2.setMetaData(MediaInfo::AlbumArtist, "Album Artist2");
+ //m2.setMetaData(MediaInfo::Year, 2011);
+ //m2.setMetaData(MediaInfo::Genre, "Genre2");
+ m2.setMetaData(MediaInfo::Comment, "Comment2");
+ //m2.setMetaData(MediaInfo::Composer, "Composer2");
+ //m2.setMetaData(MediaInfo::Publisher, "Publisher2");
+ mediaInfoList << m2;
+
+ MediaInfo m3("file:///C:/3.mp3");
+ m3.setMetaData(MediaInfo::TrackNumber, 3);
+ //m3.setMetaData(MediaInfo::DiscNumber, 3);
+ //m3.setMetaData(MediaInfo::BPM, 3);
+ m3.setMetaData(MediaInfo::Artist, "Artist3");
+ m3.setMetaData(MediaInfo::Album, "Album3");
+ //m3.setMetaData(MediaInfo::AlbumArtist, "Album Artist3");
+ //m3.setMetaData(MediaInfo::Year, 2011);
+ //m3.setMetaData(MediaInfo::Genre, "Genre3");
+ m3.setMetaData(MediaInfo::Comment, "Comment3");
+ //m3.setMetaData(MediaInfo::Composer, "Composer3");
+ //m3.setMetaData(MediaInfo::Publisher, "Publisher3");
+ mediaInfoList << m3;
+
+ MediaInfo m4("file:///C:/4.mp3");
+ m4.setMetaData(MediaInfo::TrackNumber, 4);
+ //m4.setMetaData(MediaInfo::DiscNumber, 4);
+ //m4.setMetaData(MediaInfo::BPM, 4);
+ m4.setMetaData(MediaInfo::Title, "Title4");
+ m4.setMetaData(MediaInfo::Artist, "Artist4");
+ m4.setMetaData(MediaInfo::Album, "Album4");
+ //m4.setMetaData(MediaInfo::AlbumArtist, "Album Artist4");
+ //m4.setMetaData(MediaInfo::Year, 2011);
+ //m4.setMetaData(MediaInfo::Genre, "Genre4");
+ m4.setMetaData(MediaInfo::Comment, "Comment4");
+ //m4.setMetaData(MediaInfo::Composer, "Composer4");
+ //m4.setMetaData(MediaInfo::Publisher, "Publisher4");
+ mediaInfoList << m4;
+
+ MediaInfo m5("file:///C:/5.mp3");
+ m5.setMetaData(MediaInfo::TrackNumber, 5);
+ //m5.setMetaData(MediaInfo::DiscNumber, 5);
+ //m5.setMetaData(MediaInfo::BPM, 5);
+ m5.setMetaData(MediaInfo::Title, "Title5");
+ m5.setMetaData(MediaInfo::Artist, "Artist5");
+ m5.setMetaData(MediaInfo::Album, "Album5");
+ //m5.setMetaData(MediaInfo::AlbumArtist, "Album Artist5");
+ //m5.setMetaData(MediaInfo::Year, 2011);
+ //m5.setMetaData(MediaInfo::Genre, "Genre5");
+ m5.setMetaData(MediaInfo::Comment, "Comment5");
+ //m5.setMetaData(MediaInfo::Composer, "Composer5");
+ //m5.setMetaData(MediaInfo::Publisher, "Publisher5");
+ mediaInfoList << m5;
+
+ return mediaInfoList;
+}
+
+void PlaylistReaderTest::loadPlaylistM3U() {
+ //Foobar
+ QTest::newRow("Foobar M3U") << ":/foobar2000/test.m3u"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Foobar
+ QTest::newRow("Foobar M3U8") << ":/foobar2000/test.m3u8"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //TheKMPlayer
+ QTest::newRow("TheKMPlayer M3U") << ":/TheKMPlayer/test.M3U"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //VLC
+ QTest::newRow("VLC M3U") << ":/VLC/test.m3u"
+ << localM3UPlaylist_WithMetaDatas()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //VLC
+ QTest::newRow("VLC M3U8") << ":/VLC/test.m3u8"
+ << localM3UPlaylist_WithMetaDatas()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Winamp
+ QTest::newRow("Winamp M3U") << ":/Winamp/test.m3u"
+ << localM3UPlaylist_WithMetaDatas()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Winamp
+ QTest::newRow("Winamp M3U8") << ":/Winamp/test.m3u8"
+ << localM3UPlaylist_WithMetaDatas()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Winamp
+ QTest::newRow("Winamp M3U") << ":/Winamp/test-noroot.m3u"
+ << localM3UPlaylist_NoRoot()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //WindowsMediaPlayer
+ QTest::newRow("WindowsMediaPlayer M3U") << ":/WindowsMediaPlayer/test.m3u"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //WindowsMediaPlayer
+ QTest::newRow("WindowsMediaPlayer M3U")
<< ":/WindowsMediaPlayer/test-relative.m3u"
+ << localM3UPlaylist_Relative()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Europe1
+ QTest::newRow("Europe1 M3U") << ":/Internet/webradio/europe1/europe1.m3u"
+ << (QList<MediaInfo>()
+ << MediaInfo("http://vipicecast.yacast.net/europe1"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Live9
+ QTest::newRow("Live9 M3U") << ":/Internet/webradio/live9/192.m3u"
+ << (QList<MediaInfo>()
+ << MediaInfo("http://stream192.live9.fr:8050")
+ << MediaInfo("http://stream192.live9.fr:8050")
+ << MediaInfo("http://stream192.live9.fr:8050")
+ << MediaInfo("http://stream192.live9.fr:8050")
+ << MediaInfo("http://stream192.live9.fr:8050"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //France Inter
+ QTest::newRow("France Inter M3U")
<< ":/Internet/webradio/franceinter/france_inter_mp3-128k.m3u"
+ << (QList<MediaInfo>()
+ <<
MediaInfo("http://mp3.live.tv-radio.com/franceinter/all/franceinterhautdebit.mp3"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Radio Nova
+ QTest::newRow("Radio Nova M3U")
<< ":/Internet/webradio/radionova/radionova.m3u"
+ << (QList<MediaInfo>()
+ << MediaInfo("http://broadcast.infomaniak.net:80/radionova-high.mp3"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+}
+
+void PlaylistReaderTest::loadPlaylistWPL() {
+ //WindowsMediaPlayer
+ QTest::newRow("WindowsMediaPlayer WPL") << ":/WindowsMediaPlayer/test.wpl"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //WindowsMediaPlayer
+ QTest::newRow("WindowsMediaPlayer WPL")
<< ":/WindowsMediaPlayer/test-relative.wpl"
+ << localM3UPlaylist_Relative()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+}
+
+void PlaylistReaderTest::loadPlaylistPLS() {
+ //France Inter
+ QTest::newRow("France Inter PLS")
<< ":/Internet/webradio/franceinter/france_inter_mp3-128k.pls"
+ << (QList<MediaInfo>()
+ <<
MediaInfo("http://mp3.live.tv-radio.com/franceinter/all/franceinterhautdebit.mp3")
+ <<
MediaInfo("http://mp3.live.tv-radio.com/franceinter/all/franceinterhautdebit.mp3"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //TheKMPlayer
+ QTest::newRow("TheKMPlayer PLS") << ":/TheKMPlayer/test.PLS"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Winamp
+ QTest::newRow("Winamp PLS") << ":/Winamp/test.pls"
+ << localM3UPlaylist_WithMetaDatas()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+}
+
+void PlaylistReaderTest::loadPlaylistASX() {
+ //Live9
+ QTest::newRow("Live9 ASX") << ":/Internet/webradio/live9/192.asx"
+ << (QList<MediaInfo>()
+ << MediaInfo("mms://wm.live9.fr/live9live"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //OUI FM
+ QTest::newRow("OUI FM ASX")
<< ":/Internet/webradio/ouifm/Ouifm-hautdebit-wmp.asx"
+ << (QList<MediaInfo>()
+ << MediaInfo("http://www.ouifm.fr/player/IntroPubOUIFM.mp3")
+ << MediaInfo("http://broadcast.infomaniak.net:80/ouifm-high.mp3"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Virgin Radio
+ QTest::newRow("Virgin Radio ASX")
<< ":/Internet/webradio/virginradio/virgin.asx"
+ << (QList<MediaInfo>()
+ << MediaInfo("mms://viplagardere.yacast.net/encodereurope2"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //Europe1
+ QTest::newRow("Europe1 ASX") << ":/Internet/webradio/europe1/europe1.asx"
+ << (QList<MediaInfo>()
+ << MediaInfo("mms://viplagardere.yacast.net/encodereurope1"))
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //TheKMPlayer
+ //FIXME Qt bug, tested with Qt 4.7.0 MinGW Windows XP
+ //"<Ref href = "C:\1.mp3"/>"
+ //will return "C:C:\1.mp3.mp3"
+ /*QTest::newRow("TheKMPlayer ASX") << ":/TheKMPlayer/test.ASX"
+ << localM3UPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << static_cast<int>(QFile::NoError)
+ << 0;*/
+}
+
+void PlaylistReaderTest::loadPlaylistXSPF() {
+ //Foobar
+ QTest::newRow("Foobar XSPF") << ":/foobar2000/test.xspf"
+ << localXSPFPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //VLC
+ QTest::newRow("VLC XSPF") << ":/VLC/test.xspf"
+ << localXSPFPlaylist()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+}
+
+void PlaylistReaderTest::loadPlaylistCUE() {
+}
+
+void PlaylistReaderTest::loadPlaylist() {
+ QSignalSpy spyFilesFound(_reader, SIGNAL(filesFound(const
QList<MediaInfo> &)));
+ QSignalSpy spyFinished(_reader, SIGNAL(finished(PlaylistParser::Error,
int)));
+
+ QFETCH(QString, playlistFileName);
+ _reader->load(playlistFileName);
+
+ //finished() signal might be already sent by load() method
+ //if the file couldn't be opened
+ if (spyFinished.count() == 0) {
+ QTestEventLoop::instance().enterLoop(30);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ }
+
+ QFETCH(int, parserError);
+ if (parserError == PlaylistParser::NoError) {
+ //There can be more than 1 filesFound() signal
+ QCOMPARE(spyFilesFound.count(), 1);
+ } else {
+ //If file couldn't be opened then no filesFound() signal
+ //has been sent
+ QCOMPARE(spyFilesFound.count(), 0);
+ }
+
+ //Only 1 finished() signal
+ QCOMPARE(spyFinished.count(), 1);
+}
+
+void PlaylistReaderTest::filesFound(const QList<MediaInfo> & files) {
+ QFETCH(QList<MediaInfo>, filesToFind);
+
+ QCOMPARE(files.size(), filesToFind.size());
+
+ for (int i = 0; i < filesToFind.size(); i++) {
+ //Compare the filenames
+ QCOMPARE(filesToFind[i].fileName(), files[i].fileName());
+
+ //Compare the metadatas if any
+ for (int metaData = MediaInfo::MIN; metaData <= MediaInfo::MAX;
metaData++) {
+ if (filesToFind[i].metaDataValue((MediaInfo::MetaData)
metaData).isValid()) {
+ QCOMPARE(filesToFind[i].metaDataValue((MediaInfo::MetaData) metaData),
+ files[i].metaDataValue((MediaInfo::MetaData) metaData));
+ }
+ }
+
+ //Compare the durations
+ if (filesToFind[i].durationSecs() != -1) {
+ QCOMPARE(filesToFind[i].durationSecs(), files[i].durationSecs());
+ }
+ }
+}
+
+void PlaylistReaderTest::finished(PlaylistParser::Error error, int
timeElapsed) {
+ //QFETCH(int, parserTimeElapsed);
+
+ QFETCH(int, parserError);
+ QCOMPARE(parserError, static_cast<int>(error));
+
+ PlaylistParserDebug() << "timeElapsed:" << timeElapsed;
+
+ QTestEventLoop::instance().exitLoop();
+}
=======================================
--- /dev/null
+++ /trunk/tests/libs/PlaylistParser/PlaylistReaderTest.h Thu Feb 17
07:53:14 2011
@@ -0,0 +1,77 @@
+/*
+ * QuarkPlayer, a Phonon media player
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PLAYLISTREADERTEST_H
+#define PLAYLISTREADERTEST_H
+
+#include <PlaylistParser/PlaylistParser.h>
+
+#include <QtTest/QtTest>
+#include <QtCore/QList>
+
+class MediaInfo;
+
+/**
+ * Test for PlaylistReader.
+ *
+ * French radio list:
+ * http://code.google.com/p/radioshell/wiki/ListeRadios
+ * http://flux.radio.free.fr/
+ * http://www.infomaniak.ch/societe/streaming.php
+ *
+ * @see PlaylistParser
+ * @author Tanguy Krotoff
+ */
+class PlaylistReaderTest : public QObject {
+ Q_OBJECT
+private slots:
+
+ /** Called before the first testfunction is executed. */
+ void initTestCase();
+
+ /** Called after the last testfunction was executed. */
+ void cleanupTestCase();
+
+ /** Called before each testfunction is executed. */
+ void init();
+
+ /** Called after every testfunction. */
+ void cleanup();
+
+
+ void loadPlaylist_data();
+
+ void loadPlaylist();
+
+ void filesFound(const QList<MediaInfo> & files);
+
+ void finished(PlaylistParser::Error error, int timeElapsed);
+
+private:
+
+ void loadPlaylistM3U();
+ void loadPlaylistWPL();
+ void loadPlaylistPLS();
+ void loadPlaylistASX();
+ void loadPlaylistXSPF();
+ void loadPlaylistCUE();
+
+ PlaylistReader * _reader;
+};
+
+#endif //PLAYLISTREADERTEST_H
=======================================
--- /dev/null
+++ /trunk/tests/libs/PlaylistParser/PlaylistWriterTest.cpp Thu Feb 17
07:53:14 2011
@@ -0,0 +1,290 @@
+/*
+ * QuarkPlayer, a Phonon media player
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "PlaylistWriterTest.h"
+
+#include <PlaylistParser/PlaylistParser.h>
+#include <PlaylistParser/PlaylistParserLogger.h>
+
+#include <MediaInfoFetcher/MediaInfo.h>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QFile>
+#include <QtCore/QList>
+
+QTEST_MAIN(PlaylistWriterTest)
+
+void disableMessageOutput(QtMsgType type, const char * msg) {
+ Q_UNUSED(type);
+ Q_UNUSED(msg);
+}
+
+void PlaylistWriterTest::initTestCase() {
+ //Disable qDebug() and friends
+ qInstallMsgHandler(disableMessageOutput);
+ ///
+
+ //Playlist writer
+ _writer = new PlaylistWriter(this);
+ connect(_writer, SIGNAL(finished(PlaylistParser::Error, int)),
+ SLOT(writerFinished(PlaylistParser::Error, int)));
+
+ //Playlist reader
+ _reader = new PlaylistReader(this);
+ connect(_reader, SIGNAL(filesFound(const QList<MediaInfo> &)),
+ SLOT(readerFilesFound(const QList<MediaInfo> &)));
+ connect(_reader, SIGNAL(finished(PlaylistParser::Error, int)),
+ SLOT(readerFinished(PlaylistParser::Error, int)));
+}
+
+void PlaylistWriterTest::cleanupTestCase() {
+}
+
+void PlaylistWriterTest::init() {
+}
+
+void PlaylistWriterTest::cleanup() {
+}
+
+QList<MediaInfo> mediaInfoListToSave_WPL() {
+ return QList<MediaInfo>()
+ << MediaInfo("1.mp3")
+ << MediaInfo("2.mp3")
+ << MediaInfo("3.mp3")
+ << MediaInfo("4.mp3")
+ << MediaInfo("5.mp3");
+}
+
+QList<MediaInfo> mediaInfoListToSave_ASX() {
+ //FIXME Qt bug, tested with Qt 4.7.0 MinGW Windows XP
+ //xml.readElementText() returns lower case text
+ //So all titles must be lower case in our tests
+
+ QList<MediaInfo> mediaInfoList;
+
+ MediaInfo m1("1.mp3");
+ mediaInfoList << m1;
+
+ MediaInfo m2("2.mp3");
+ m2.setMetaData(MediaInfo::Title, "title2");
+ mediaInfoList << m2;
+
+ MediaInfo m3("3.mp3");
+ mediaInfoList << m3;
+
+ MediaInfo m4("4.mp3");
+ m4.setMetaData(MediaInfo::Title, "title4");
+ mediaInfoList << m4;
+
+ MediaInfo m5("5.mp3");
+ m5.setMetaData(MediaInfo::Title, "title5");
+ mediaInfoList << m5;
+
+ return mediaInfoList;
+}
+
+QList<MediaInfo> mediaInfoListToSave_M3U() {
+ QList<MediaInfo> mediaInfoList;
+
+ MediaInfo m1("1.mp3");
+ mediaInfoList << m1;
+
+ MediaInfo m2("2.mp3");
+ m2.setMetaData(MediaInfo::Title, "Title2");
+ mediaInfoList << m2;
+
+ MediaInfo m3("3.mp3");
+ m3.setMetaData(MediaInfo::Title, "Artist3");
+ mediaInfoList << m3;
+
+ MediaInfo m4("4.mp3");
+ m4.setMetaData(MediaInfo::Title, "Artist4 - Title4");
+ mediaInfoList << m4;
+
+ MediaInfo m5("5.mp3");
+ m5.setMetaData(MediaInfo::Title, "Artist5 - Title5");
+ mediaInfoList << m5;
+
+ return mediaInfoList;
+}
+
+QList<MediaInfo> mediaInfoListToSave() {
+ QList<MediaInfo> mediaInfoList;
+
+ MediaInfo m1("1.mp3");
+ mediaInfoList << m1;
+
+ MediaInfo m2("2.mp3");
+ m2.setMetaData(MediaInfo::Title, "Title2");
+ mediaInfoList << m2;
+
+ MediaInfo m3("3.mp3");
+ m3.setMetaData(MediaInfo::Artist, "Artist3");
+ mediaInfoList << m3;
+
+ MediaInfo m4("4.mp3");
+ m4.setMetaData(MediaInfo::Title, "Title4");
+ m4.setMetaData(MediaInfo::Artist, "Artist4");
+ mediaInfoList << m4;
+
+ MediaInfo m5("5.mp3");
+ m5.setMetaData(MediaInfo::Title, "Title5");
+ m5.setMetaData(MediaInfo::Artist, "Artist5");
+ mediaInfoList << m5;
+
+ return mediaInfoList;
+}
+
+void PlaylistWriterTest::savePlaylist_data() {
+ QTest::addColumn<QString>("playlistFileName");
+ QTest::addColumn<QList<MediaInfo> >("mediaList");
+ QTest::addColumn<int>("parserError");
+ QTest::addColumn<int>("parserTimeElapsed");
+
+ //Unsupported format: The KMPlayer proprietary format
+ QTest::newRow("Unsupported Format") << "PlaylistWriterTest.KPL"
+ << QList<MediaInfo>()
+ << static_cast<int>(PlaylistParser::UnsupportedFormatError)
+ << 0;
+
+ //ASX
+ QTest::newRow("ASX") << "PlaylistWriterTest.asx"
+ << mediaInfoListToSave_ASX()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //M3U
+ QTest::newRow("M3U") << "PlaylistWriterTest.m3u"
+ << mediaInfoListToSave_M3U()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //PLS
+ QTest::newRow("PLS") << "PlaylistWriterTest.pls"
+ << mediaInfoListToSave_M3U()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //WPL
+ QTest::newRow("WPL") << "PlaylistWriterTest.wpl"
+ << mediaInfoListToSave_WPL()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+
+ //XSPF
+ QTest::newRow("XSPF") << "PlaylistWriterTest.xspf"
+ << mediaInfoListToSave()
+ << static_cast<int>(PlaylistParser::NoError)
+ << 0;
+}
+
+void PlaylistWriterTest::savePlaylist() {
+ QSignalSpy spyFinished(_writer, SIGNAL(finished(PlaylistParser::Error,
int)));
+
+ QFETCH(QString, playlistFileName);
+ QFETCH(QList<MediaInfo>, mediaList);
+ _writer->save(playlistFileName, mediaList);
+
+ //finished() signal might be already sent by save() method
+ //if the file couldn't be opened
+ if (spyFinished.count() == 0) {
+ QTestEventLoop::instance().enterLoop(30);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ }
+
+ //Only 1 finished() signal
+ QCOMPARE(spyFinished.count(), 1);
+ QFETCH(int, parserError);
+ if (parserError == PlaylistParser::NoError) {
+ loadPlaylist(playlistFileName);
+ } else {
+ }
+}
+
+void PlaylistWriterTest::writerFinished(PlaylistParser::Error error, int
timeElapsed) {
+ //QFETCH(int, parserTimeElapsed);
+
+ QFETCH(int, parserError);
+ QCOMPARE(parserError, static_cast<int>(error));
+
+ PlaylistParserDebug() << "timeElapsed:" << timeElapsed;
+
+ QTestEventLoop::instance().exitLoop();
+}
+
+void PlaylistWriterTest::loadPlaylist(const QString & playlistFileName) {
+ QSignalSpy spyFilesFound(_reader, SIGNAL(filesFound(const
QList<MediaInfo> &)));
+ QSignalSpy spyFinished(_reader, SIGNAL(finished(PlaylistParser::Error,
int)));
+
+ _reader->load(playlistFileName);
+
+ //finished() signal might be already sent by load() method
+ //if the file couldn't be opened
+ if (spyFinished.count() == 0) {
+ QTestEventLoop::instance().enterLoop(30);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ }
+
+ QFETCH(int, parserError);
+ if (parserError == PlaylistParser::NoError) {
+ //There can be more than 1 filesFound() signal
+ QCOMPARE(spyFilesFound.count(), 1);
+ } else {
+ //If file couldn't be opened then no filesFound() signal
+ //has been sent
+ QCOMPARE(spyFilesFound.count(), 0);
+ }
+
+ //Only 1 finished() signal
+ QCOMPARE(spyFinished.count(), 1);
+}
+
+void PlaylistWriterTest::readerFilesFound(const QList<MediaInfo> & files) {
+ QFETCH(QList<MediaInfo>, mediaList);
+
+ QCOMPARE(files.size(), mediaList.size());
+
+ for (int i = 0; i < mediaList.size(); i++) {
+ //Compare the filenames
+ QCOMPARE(mediaList[i].fileName(), files[i].fileName());
+
+ //Compare the metadatas if any
+ for (int metaData = MediaInfo::MIN; metaData <= MediaInfo::MAX;
metaData++) {
+ if (mediaList[i].metaDataValue((MediaInfo::MetaData)
metaData).isValid()) {
+ QCOMPARE(mediaList[i].metaDataValue((MediaInfo::MetaData) metaData),
+ files[i].metaDataValue((MediaInfo::MetaData) metaData));
+ }
+ }
+
+ //Compare the durations
+ if (mediaList[i].durationSecs() != -1) {
+ QCOMPARE(mediaList[i].durationSecs(), files[i].durationSecs());
+ }
+ }
+}
+
+void PlaylistWriterTest::readerFinished(PlaylistParser::Error error, int
timeElapsed) {
+ //QFETCH(int, parserTimeElapsed);
+
+ QFETCH(int, parserError);
+ QCOMPARE(parserError, static_cast<int>(error));
+
+ PlaylistParserDebug() << "timeElapsed:" << timeElapsed;
+
+ QTestEventLoop::instance().exitLoop();
+}
=======================================
--- /dev/null
+++ /trunk/tests/libs/PlaylistParser/PlaylistWriterTest.h Thu Feb 17
07:53:14 2011
@@ -0,0 +1,71 @@
+/*
+ * QuarkPlayer, a Phonon media player
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PLAYLISTWRITERTEST_H
+#define PLAYLISTWRITERTEST_H
+
+#include <PlaylistParser/PlaylistParser.h>
+
+#include <QtTest/QtTest>
+#include <QtCore/QList>
+
+class MediaInfo;
+
+/**
+ * Test for PlaylistWriter.
+ *
+ * @see PlaylistParser
+ * @author Tanguy Krotoff
+ */
+class PlaylistWriterTest : public QObject {
+ Q_OBJECT
+private slots:
+
+ /** Called before the first testfunction is executed. */
+ void initTestCase();
+
+ /** Called after the last testfunction was executed. */
+ void cleanupTestCase();
+
+ /** Called before each testfunction is executed. */
+ void init();
+
+ /** Called after every testfunction. */
+ void cleanup();
+
+
+ void savePlaylist_data();
+
+ void savePlaylist();
+
+ void writerFinished(PlaylistParser::Error error, int timeElapsed);
+
+ void readerFilesFound(const QList<MediaInfo> & files);
+
+ void readerFinished(PlaylistParser::Error error, int timeElapsed);
+
+private:
+
+ void loadPlaylist(const QString & playlistFileName);
+
+ PlaylistWriter * _writer;
+
+ PlaylistReader * _reader;
+};
+
+#endif //PLAYLISTWRITERTEST_H
=======================================
--- /trunk/tests/libs/PlaylistParser/PlaylistParserTest.cpp Wed Feb 16
06:06:34 2011
+++ /dev/null
@@ -1,546 +0,0 @@
-/*
- * QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "PlaylistParserTest.h"
-
-#include <PlaylistParser/PlaylistParser.h>
-#include <PlaylistParser/PlaylistParserLogger.h>
-
-#include <MediaInfoFetcher/MediaInfo.h>
-
-#include <QtCore/QCoreApplication>
-#include <QtCore/QFile>
-#include <QtCore/QList>
-
-QTEST_MAIN(PlaylistParserTest)
-
-void disableMessageOutput(QtMsgType type, const char * msg) {
- Q_UNUSED(type);
- Q_UNUSED(msg);
-}
-
-void PlaylistParserTest::initTestCase() {
- //Disable qDebug() and friends
- qInstallMsgHandler(disableMessageOutput);
- ///
-
- //Playlist reader
- _reader = new PlaylistReader(this);
- connect(_reader, SIGNAL(filesFound(const QList<MediaInfo> &)),
- SLOT(filesFound(const QList<MediaInfo> &)));
- connect(_reader, SIGNAL(finished(PlaylistParser::Error, int)),
- SLOT(finished(PlaylistParser::Error, int)));
-
- //Playlist writer
- _writer = new PlaylistWriter(this);
- connect(_writer, SIGNAL(finished(PlaylistParser::Error, int)),
- SLOT(finished(PlaylistParser::Error, int)));
-}
-
-void PlaylistParserTest::cleanupTestCase() {
-}
-
-void PlaylistParserTest::init() {
-}
-
-void PlaylistParserTest::cleanup() {
-}
-
-void PlaylistParserTest::loadPlaylist_data() {
- QTest::addColumn<QString>("playlistFileName");
-
- QTest::addColumn<QList<MediaInfo> >("filesFound");
- QTest::addColumn<int>("parserError");
- QTest::addColumn<int>("parserFileError");
- QTest::addColumn<int>("parserTimeElapsed");
-
- //Non existing file
- QTest::newRow("Non existing File") << "Non existing File"
- << QList<MediaInfo>()
- << static_cast<int>(PlaylistParser::FileError)
- << static_cast<int>(QFile::OpenError)
- << 0;
-
- //Unsupported Format
- QTest::newRow("Unsupported Format") << ":/TheKMPlayer/test.KPL"
- << QList<MediaInfo>()
- << static_cast<int>(PlaylistParser::UnsupportedFormatError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- loadPlaylistM3U();
- loadPlaylistWPL();
- loadPlaylistPLS();
- loadPlaylistASX();
- loadPlaylistXSPF();
- loadPlaylistCUE();
-}
-
-QList<MediaInfo> localM3UPlaylist() {
- return QList<MediaInfo>()
- << MediaInfo("C:\\1.mp3")
- << MediaInfo("C:\\2.mp3")
- << MediaInfo("C:\\3.mp3")
- << MediaInfo("C:\\4.mp3")
- << MediaInfo("C:\\5.mp3");
-}
-
-QList<MediaInfo> localM3UPlaylist_WithMetaDatas() {
- QList<MediaInfo> mediaInfoList;
-
- MediaInfo m1("C:\\1.mp3");
- mediaInfoList << m1;
-
- MediaInfo m2("C:\\2.mp3");
- m2.setMetaData(MediaInfo::Title, "Title2");
- mediaInfoList << m2;
-
- MediaInfo m3("C:\\3.mp3");
- //m3.setMetaData(MediaInfo::Title, "Artist3 - 3");
- mediaInfoList << m3;
-
- MediaInfo m4("C:\\4.mp3");
- m4.setMetaData(MediaInfo::Title, "Artist4 - Title4");
- mediaInfoList << m4;
-
- MediaInfo m5("C:\\5.mp3");
- m5.setMetaData(MediaInfo::Title, "Artist5 - Title5");
- mediaInfoList << m5;
-
- return mediaInfoList;
-}
-
-QList<MediaInfo> localM3UPlaylist_NoRoot() {
- return QList<MediaInfo>()
- << MediaInfo("\\1.mp3")
- << MediaInfo("\\2.mp3")
- << MediaInfo("\\3.mp3")
- << MediaInfo("\\4.mp3")
- << MediaInfo("\\5.mp3");
-}
-
-QList<MediaInfo> localM3UPlaylist_Relative() {
- return QList<MediaInfo>()
- << MediaInfo("..\\mp3\\1.mp3")
- << MediaInfo("..\\mp3\\2.mp3")
- << MediaInfo("..\\mp3\\3.mp3")
- << MediaInfo("..\\mp3\\4.mp3")
- << MediaInfo("..\\mp3\\5.mp3");
-}
-
-QList<MediaInfo> localXSPFPlaylist() {
- QList<MediaInfo> mediaInfoList;
-
- MediaInfo m1("file:///C:/1.mp3");
- mediaInfoList << m1;
-
- MediaInfo m2("file:///C:/2.mp3");
- m2.setMetaData(MediaInfo::TrackNumber, 2);
- //m2.setMetaData(MediaInfo::DiscNumber, 2);
- //m2.setMetaData(MediaInfo::BPM, 2);
- m2.setMetaData(MediaInfo::Title, "Title2");
- m2.setMetaData(MediaInfo::Album, "Album2");
- //m2.setMetaData(MediaInfo::AlbumArtist, "Album Artist2");
- //m2.setMetaData(MediaInfo::Year, 2011);
- //m2.setMetaData(MediaInfo::Genre, "Genre2");
- m2.setMetaData(MediaInfo::Comment, "Comment2");
- //m2.setMetaData(MediaInfo::Composer, "Composer2");
- //m2.setMetaData(MediaInfo::Publisher, "Publisher2");
- mediaInfoList << m2;
-
- MediaInfo m3("file:///C:/3.mp3");
- m3.setMetaData(MediaInfo::TrackNumber, 3);
- //m3.setMetaData(MediaInfo::DiscNumber, 3);
- //m3.setMetaData(MediaInfo::BPM, 3);
- m3.setMetaData(MediaInfo::Artist, "Artist3");
- m3.setMetaData(MediaInfo::Album, "Album3");
- //m3.setMetaData(MediaInfo::AlbumArtist, "Album Artist3");
- //m3.setMetaData(MediaInfo::Year, 2011);
- //m3.setMetaData(MediaInfo::Genre, "Genre3");
- m3.setMetaData(MediaInfo::Comment, "Comment3");
- //m3.setMetaData(MediaInfo::Composer, "Composer3");
- //m3.setMetaData(MediaInfo::Publisher, "Publisher3");
- mediaInfoList << m3;
-
- MediaInfo m4("file:///C:/4.mp3");
- m4.setMetaData(MediaInfo::TrackNumber, 4);
- //m4.setMetaData(MediaInfo::DiscNumber, 4);
- //m4.setMetaData(MediaInfo::BPM, 4);
- m4.setMetaData(MediaInfo::Title, "Title4");
- m4.setMetaData(MediaInfo::Artist, "Artist4");
- m4.setMetaData(MediaInfo::Album, "Album4");
- //m4.setMetaData(MediaInfo::AlbumArtist, "Album Artist4");
- //m4.setMetaData(MediaInfo::Year, 2011);
- //m4.setMetaData(MediaInfo::Genre, "Genre4");
- m4.setMetaData(MediaInfo::Comment, "Comment4");
- //m4.setMetaData(MediaInfo::Composer, "Composer4");
- //m4.setMetaData(MediaInfo::Publisher, "Publisher4");
- mediaInfoList << m4;
-
- MediaInfo m5("file:///C:/5.mp3");
- m5.setMetaData(MediaInfo::TrackNumber, 5);
- //m5.setMetaData(MediaInfo::DiscNumber, 5);
- //m5.setMetaData(MediaInfo::BPM, 5);
- m5.setMetaData(MediaInfo::Title, "Title5");
- m5.setMetaData(MediaInfo::Artist, "Artist5");
- m5.setMetaData(MediaInfo::Album, "Album5");
- //m5.setMetaData(MediaInfo::AlbumArtist, "Album Artist5");
- //m5.setMetaData(MediaInfo::Year, 2011);
- //m5.setMetaData(MediaInfo::Genre, "Genre5");
- m5.setMetaData(MediaInfo::Comment, "Comment5");
- //m5.setMetaData(MediaInfo::Composer, "Composer5");
- //m5.setMetaData(MediaInfo::Publisher, "Publisher5");
- mediaInfoList << m5;
-
- return mediaInfoList;
-}
-
-void PlaylistParserTest::loadPlaylistM3U() {
- //Foobar
- QTest::newRow("Foobar M3U") << ":/foobar2000/test.m3u"
- << localM3UPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Foobar
- QTest::newRow("Foobar M3U8") << ":/foobar2000/test.m3u8"
- << localM3UPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //TheKMPlayer
- QTest::newRow("TheKMPlayer M3U") << ":/TheKMPlayer/test.M3U"
- << localM3UPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //VLC
- QTest::newRow("VLC M3U") << ":/VLC/test.m3u"
- << localM3UPlaylist_WithMetaDatas()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //VLC
- QTest::newRow("VLC M3U8") << ":/VLC/test.m3u8"
- << localM3UPlaylist_WithMetaDatas()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Winamp
- QTest::newRow("Winamp M3U") << ":/Winamp/test.m3u"
- << localM3UPlaylist_WithMetaDatas()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Winamp
- QTest::newRow("Winamp M3U8") << ":/Winamp/test.m3u8"
- << localM3UPlaylist_WithMetaDatas()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Winamp
- QTest::newRow("Winamp M3U") << ":/Winamp/test-noroot.m3u"
- << localM3UPlaylist_NoRoot()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //WindowsMediaPlayer
- QTest::newRow("WindowsMediaPlayer M3U") << ":/WindowsMediaPlayer/test.m3u"
- << localM3UPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //WindowsMediaPlayer
- QTest::newRow("WindowsMediaPlayer M3U")
<< ":/WindowsMediaPlayer/test-relative.m3u"
- << localM3UPlaylist_Relative()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Europe1
- QTest::newRow("Europe1 M3U") << ":/Internet/webradio/europe1/europe1.m3u"
- << (QList<MediaInfo>()
- << MediaInfo("http://vipicecast.yacast.net/europe1"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Live9
- QTest::newRow("Live9 M3U") << ":/Internet/webradio/live9/192.m3u"
- << (QList<MediaInfo>()
- << MediaInfo("http://stream192.live9.fr:8050")
- << MediaInfo("http://stream192.live9.fr:8050")
- << MediaInfo("http://stream192.live9.fr:8050")
- << MediaInfo("http://stream192.live9.fr:8050")
- << MediaInfo("http://stream192.live9.fr:8050"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //France Inter
- QTest::newRow("France Inter M3U")
<< ":/Internet/webradio/franceinter/france_inter_mp3-128k.m3u"
- << (QList<MediaInfo>()
- <<
MediaInfo("http://mp3.live.tv-radio.com/franceinter/all/franceinterhautdebit.mp3"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Radio Nova
- QTest::newRow("Radio Nova M3U")
<< ":/Internet/webradio/radionova/radionova.m3u"
- << (QList<MediaInfo>()
- << MediaInfo("http://broadcast.infomaniak.net:80/radionova-high.mp3"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-}
-
-void PlaylistParserTest::loadPlaylistWPL() {
- //WindowsMediaPlayer
- /*QTest::newRow("WindowsMediaPlayer WPL")
<< ":/WindowsMediaPlayer/test.wpl"
- << localM3UPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;*/
-}
-
-void PlaylistParserTest::loadPlaylistPLS() {
- //France Inter
- QTest::newRow("France Inter PLS")
<< ":/Internet/webradio/franceinter/france_inter_mp3-128k.pls"
- << (QList<MediaInfo>()
- <<
MediaInfo("http://mp3.live.tv-radio.com/franceinter/all/franceinterhautdebit.mp3")
- <<
MediaInfo("http://mp3.live.tv-radio.com/franceinter/all/franceinterhautdebit.mp3"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-}
-
-void PlaylistParserTest::loadPlaylistASX() {
- //Live9
- QTest::newRow("Live9 ASX") << ":/Internet/webradio/live9/192.asx"
- << (QList<MediaInfo>()
- << MediaInfo("mms://wm.live9.fr/live9live"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //OUI FM
- QTest::newRow("OUI FM ASX")
<< ":/Internet/webradio/ouifm/Ouifm-hautdebit-wmp.asx"
- << (QList<MediaInfo>()
- << MediaInfo("http://www.ouifm.fr/player/IntroPubOUIFM.mp3")
- << MediaInfo("http://broadcast.infomaniak.net:80/ouifm-high.mp3"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Virgin Radio
- QTest::newRow("Virgin Radio ASX")
<< ":/Internet/webradio/virginradio/virgin.asx"
- << (QList<MediaInfo>()
- << MediaInfo("mms://viplagardere.yacast.net/encodereurope2"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //Europe1
- QTest::newRow("Europe1 ASX") << ":/Internet/webradio/europe1/europe1.asx"
- << (QList<MediaInfo>()
- << MediaInfo("mms://viplagardere.yacast.net/encodereurope1"))
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-}
-
-void PlaylistParserTest::loadPlaylistXSPF() {
- //Foobar
- QTest::newRow("Foobar XSPF") << ":/foobar2000/test.xspf"
- << localXSPFPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- //VLC
- QTest::newRow("VLC XSPF") << ":/VLC/test.xspf"
- << localXSPFPlaylist()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-}
-
-void PlaylistParserTest::loadPlaylistCUE() {
-}
-
-void PlaylistParserTest::loadPlaylist() {
- QSignalSpy spyFilesFound(_reader, SIGNAL(filesFound(const
QList<MediaInfo> &)));
- QSignalSpy spyFinished(_reader, SIGNAL(finished(PlaylistParser::Error,
int)));
-
- QFETCH(QString, playlistFileName);
- _reader->load(playlistFileName);
-
- //finished() signal might be already sent by load() method
- //if the file couldn't be opened
- if (spyFinished.count() == 0) {
- QTestEventLoop::instance().enterLoop(30);
- QVERIFY(!QTestEventLoop::instance().timeout());
- }
-
- QFETCH(int, parserError);
- if (parserError == PlaylistParser::NoError) {
- //There can be more than 1 filesFound() signal
- QCOMPARE(spyFilesFound.count(), 1);
- } else {
- //If file couldn't be opened then no filesFound() signal
- //has been sent
- QCOMPARE(spyFilesFound.count(), 0);
- }
-
- //Only 1 finished() signal
- QCOMPARE(spyFinished.count(), 1);
-}
-
-void PlaylistParserTest::filesFound(const QList<MediaInfo> & files) {
- QFETCH(QList<MediaInfo>, filesFound);
-
- QCOMPARE(files.size(), filesFound.size());
- QTest::addColumn<QList<MediaInfo> >("filesFound");
-
- for (int i = 0; i < filesFound.size(); i++) {
- //Only compare the filenames, not the metadatas
- QCOMPARE(filesFound[i].fileName(), files[i].fileName());
-
- for (int metaData = MediaInfo::MIN; metaData <= MediaInfo::MAX;
metaData++) {
- if (filesFound[i].metaDataValue((MediaInfo::MetaData)
metaData).isValid()) {
- QCOMPARE(filesFound[i].metaDataValue((MediaInfo::MetaData) metaData),
- files[i].metaDataValue((MediaInfo::MetaData) metaData));
- }
- }
- }
-}
-
-void PlaylistParserTest::finished(PlaylistParser::Error error, int
timeElapsed) {
- //QFETCH(int, parserTimeElapsed);
-
- QFETCH(int, parserError);
- QCOMPARE(parserError, static_cast<int>(error));
-
- QFETCH(int, parserFileError);
- int fileError = _reader->file().error();
- QCOMPARE(parserFileError, fileError);
-
- PlaylistParserDebug() << "timeElapsed:" << timeElapsed;
-
- QTestEventLoop::instance().exitLoop();
-}
-
-
-
-QList<MediaInfo> mediaInfoListToSave() {
- QList<MediaInfo> mediaInfoList;
-
- MediaInfo m1("media1");
- m1.setMetaData(MediaInfo::Album, "album1");
- m1.setMetaData(MediaInfo::Artist, "artist1");
- m1.setMetaData(MediaInfo::Title, "title1");
- m1.setDurationSecs(1);
- mediaInfoList << m1;
-
- MediaInfo m2("media2");
- m2.setMetaData(MediaInfo::Album, "album2");
- m2.setMetaData(MediaInfo::Artist, "artist2");
- m2.setMetaData(MediaInfo::Title, "title2");
- m2.setDurationSecs(2);
- mediaInfoList << m2;
-
- MediaInfo m3("media3");
- m3.setMetaData(MediaInfo::Album, "album3");
- m3.setMetaData(MediaInfo::Artist, "artist3");
- m3.setMetaData(MediaInfo::Title, "title3");
- m3.setDurationSecs(3);
- mediaInfoList << m3;
-
- MediaInfo m4("media4");
- m4.setMetaData(MediaInfo::Album, "album4");
- m4.setMetaData(MediaInfo::Artist, "artist4");
- m4.setMetaData(MediaInfo::Title, "title4");
- m4.setDurationSecs(4);
- mediaInfoList << m4;
-
- MediaInfo m5("media5");
- m5.setMetaData(MediaInfo::Album, "album5");
- m5.setMetaData(MediaInfo::Artist, "artist5");
- m5.setMetaData(MediaInfo::Title, "title5");
- m5.setDurationSecs(5);
- mediaInfoList << m5;
-
- return mediaInfoList;
-}
-/*
-void PlaylistParserTest::savePlaylist_data() {
- QTest::addColumn<QString>("playlistFileName");
-
- QTest::addColumn<QList<MediaInfo> >("mediaList");
- QTest::addColumn<int>("parserError");
- QTest::addColumn<int>("parserFileError");
- QTest::addColumn<int>("parserTimeElapsed");
-
- //Unsupported Format
- QTest::newRow("Unsupported Format") << "test.KPL" //Proprietary
TheKMPlayer format
- << mediaInfoListToSave()
- << static_cast<int>(PlaylistParser::UnsupportedFormatError)
- << static_cast<int>(QFile::NoError)
- << 0;
-
- savePlaylistM3U();
-}
-
-void PlaylistParserTest::savePlaylist() {
- QSignalSpy spyFinished(_reader, SIGNAL(finished(PlaylistParser::Error,
int)));
-
- QFETCH(QString, playlistFileName);
- QFETCH(QList<MediaInfo>, mediaList);
- _writer->save(playlistFileName, mediaList);
-
- //finished() signal might be already sent by load() method
- //if the file couldn't be opened
- if (spyFinished.count() == 0) {
- QTestEventLoop::instance().enterLoop(30);
- QVERIFY(!QTestEventLoop::instance().timeout());
- }
-
- QFETCH(int, parserError);
- if (parserError == PlaylistParser::NoError) {
- } else {
- }
-}
-
-void PlaylistParserTest::savePlaylistM3U() {
- //M3U
- QTest::newRow("M3U") << "test.m3u"
- << mediaInfoListToSave()
- << static_cast<int>(PlaylistParser::NoError)
- << static_cast<int>(QFile::NoError)
- << 0;
-}
-*/
=======================================
--- /trunk/tests/libs/PlaylistParser/PlaylistParserTest.h Wed Feb 16
06:06:34 2011
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef PLAYLISTPARSERTEST_H
-#define PLAYLISTPARSERTEST_H
-
-#include <PlaylistParser/PlaylistParser.h>
-
-#include <QtTest/QtTest>
-#include <QtCore/QList>
-
-class MediaInfo;
-
-/**
- * Test for PlaylistParser library.
- *
- * Playlist files made with free albums from jamendo:
- *
- * - Nine Inch Nails (NIN) - Ghosts I–IV
- * http://ghosts.nin.com/
- * - FLAC lossless (259 mb)
- * http://dl.nin.com/data/dl/Nine_Inch_Nails_-_The_Slip_-_Flac.torrent
- * - FLAC high definition 24/96 (942 mb)
- *
http://dl.nin.com/data/dl/Nine_Inch_Nails_-_The_Slip_24-96k_Flac.torrent
- * - M4A apple lossless (263 mb)
- *
http://dl.nin.com/data/dl/Nine_Inch_Nails_-_The_Slip_-_Apple_Lossless.torrent
- * - High definition WAVE 24/96 (1.5 gb)
- *
http://dl.nin.com/data/dl/Nine_Inch_Nails_-_The_Slip_-_Wave_96-24_High_Res.torrent
- *
- * - Nine Inch Nails (NIN) - The Slip http://theslip.nin.com/
- *
- * In order to test file names with special characters:
- *
- * - David TMX - fournée d'automne
- * - MP3
- *
http://imgjam.com/torrents/album/795/4795/4795-mp32.torrent/David%20TMX%20-%20fournee%20d%27automne%20--%20Jamendo%20-%20MP3%20VBR%20192k%20-%202007.03.23%20%5Bwww.jamendo.com%5D.torrent
- * - OGG
- *
http://imgjam.com/torrents/album/795/4795/4795-ogg3.torrent/David%20TMX%20-%20fournee%20d%27automne%20--%20Jamendo%20-%20OGG%20Vorbis%20q7%20-%202007.03.23%20%5Bwww.jamendo.com%5D.torrent
- *
- * - Bézèd'h - Ton jour viendra
- * - MP3
- *
http://imgjam.com/torrents/album/135/135/135-mp32.torrent/Bezed%27h%20-%20Ton%20jour%20viendra%20--%20Jamendo%20-%20MP3%20VBR%20192k%20-%202005.04.28%20%5Bwww.jamendo.com%5D.torrent
- * - OGG
- *
http://imgjam.com/torrents/album/135/135/135-ogg3.torrent/Bezed%27h%20-%20Ton%20jour%20viendra%20--%20Jamendo%20-%20OGG%20Vorbis%20q7%20-%202005.04.28%20%5Bwww.jamendo.com%5D.torrent
- *
- * French radio list:
- * http://code.google.com/p/radioshell/wiki/ListeRadios
- * http://flux.radio.free.fr/
- * http://www.infomaniak.ch/societe/streaming.php
- *
- * @see PlaylistParser
- * @author Tanguy Krotoff
- */
-class PlaylistParserTest : public QObject {
- Q_OBJECT
-private slots:
-
- /** Called before the first testfunction is executed. */
- void initTestCase();
-
- /** Called after the last testfunction was executed. */
- void cleanupTestCase();
-
- /** Called before each testfunction is executed. */
- void init();
-
- /** Called after every testfunction. */
- void cleanup();
-
-
- void loadPlaylist_data();
-
- void loadPlaylist();
-
- void filesFound(const QList<MediaInfo> & files);
-
- void finished(PlaylistParser::Error error, int timeElapsed);
-
-/*
- void savePlaylist_data();
-
- void savePlaylist();
-*/
-private:
-
- void loadPlaylistM3U();
- void loadPlaylistWPL();
- void loadPlaylistPLS();
- void loadPlaylistASX();
- void loadPlaylistXSPF();
- void loadPlaylistCUE();
-
- //void savePlaylistM3U();
-
- PlaylistReader * _reader;
-
- PlaylistWriter * _writer;
-};
-
-#endif //PLAYLISTPARSERTEST_H
=======================================
--- /trunk/libs/MediaInfoFetcher/MediaInfo.cpp Wed Nov 10 03:33:10 2010
+++ /trunk/libs/MediaInfoFetcher/MediaInfo.cpp Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -171,7 +171,11 @@
}

qint64 MediaInfo::durationSecs() const {
- return _duration / 1000.0;
+ if (_duration == -1) {
+ return _duration;
+ } else {
+ return _duration / 1000.0;
+ }
}

qint64 MediaInfo::durationMSecs() const {
=======================================
--- /trunk/libs/PlaylistParser/ASXParser.cpp Wed Nov 10 09:13:11 2010
+++ /trunk/libs/PlaylistParser/ASXParser.cpp Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -63,7 +63,12 @@
_stop = true;
}

-void ASXParser::load(QIODevice * device, const QString & location) {
+bool ASXParser::load(const QString & location) {
+ QIODevice * device = Util::openLocationReadMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QList<MediaInfo> files;
@@ -78,6 +83,7 @@

QString text(device->readAll());
device->close();
+ delete device;

//Replace all ASX tags by lowercase ASX tags,
//otherwise the XML parser can fail
@@ -124,9 +130,14 @@
case QXmlStreamReader::StartElement: {
QString element(xml.name().toString());
if (element.compare(ASX_TITLE, Qt::CaseInsensitive) == 0) {
+ //FIXME Qt bug, tested with Qt 4.7.0 MinGW Windows XP
+ //xml.readElementText() returns lower case text
QString title(xml.readElementText());
mediaInfo.setMetaData(MediaInfo::Title, title);
} else if (element.compare(ASX_REF, Qt::CaseInsensitive) == 0) {
+ //FIXME Qt bug, tested with Qt 4.7.0 MinGW Windows XP
+ //"<Ref href = "C:\1.mp3"/>"
+ //will return "C:C:\1.mp3.mp3"
QString url(xml.attributes().value(ASX_HREF).toString());
if (url.isEmpty()) {
//Yes ASX format is shit
@@ -196,9 +207,16 @@
//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
emit filesFound(files);
}
+
+ return true;
}

-void ASXParser::save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) {
+bool ASXParser::save(const QString & location, const QList<MediaInfo> &
files) {
+ QIODevice * device = Util::openLocationWriteMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QXmlStreamWriter xml(device);
@@ -236,4 +254,7 @@
xml.writeEndElement(); //asx

device->close();
-}
+ delete device;
+
+ return true;
+}
=======================================
--- /trunk/libs/PlaylistParser/ASXParser.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/ASXParser.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -49,9 +49,9 @@

QStringList fileExtensions() const;

- void load(QIODevice * device, const QString & location);
-
- void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files);
+ bool load(const QString & location);
+
+ bool save(const QString & location, const QList<MediaInfo> & files);

void stop();

=======================================
--- /trunk/libs/PlaylistParser/CUEParser.cpp Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/CUEParser.cpp Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -54,7 +54,12 @@
_stop = true;
}

-void CUEParser::load(QIODevice * device, const QString & location) {
+bool CUEParser::load(const QString & location) {
+ QIODevice * device = Util::openLocationReadMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QList<MediaInfo> files;
@@ -182,14 +187,22 @@
}

device->close();
+ delete device;

if (!files.isEmpty()) {
//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
emit filesFound(files);
}
+
+ return true;
}

-void CUEParser::save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) {
+bool CUEParser::save(const QString & location, const QList<MediaInfo> &
files) {
+ QIODevice * device = Util::openLocationWriteMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QString path(QFileInfo(location).path());
@@ -238,4 +251,7 @@
}

device->close();
-}
+ delete device;
+
+ return true;
+}
=======================================
--- /trunk/libs/PlaylistParser/CUEParser.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/CUEParser.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -39,9 +39,9 @@

QStringList fileExtensions() const;

- void load(QIODevice * device, const QString & location);
-
- void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files);
+ bool load(const QString & location);
+
+ bool save(const QString & location, const QList<MediaInfo> & files);

void stop();

=======================================
--- /trunk/libs/PlaylistParser/IPlaylistParser.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/IPlaylistParser.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2009 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
=======================================
--- /trunk/libs/PlaylistParser/IPlaylistParserImpl.h Fri Aug 13 02:18:04
2010
+++ /trunk/libs/PlaylistParser/IPlaylistParserImpl.h Thu Feb 17 07:53:14
2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2009 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -23,7 +23,6 @@

class MediaInfo;

-class QIODevice;
class QString;
class QStringList;

@@ -50,9 +49,19 @@
*/
virtual QStringList fileExtensions() const = 0;

- virtual void load(QIODevice * device, const QString & location) = 0;
-
- virtual void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) = 0;
+ /**
+ * Loads the playlist at location.
+ *
+ * @return true if success; false otherwise
+ */
+ virtual bool load(const QString & location) = 0;
+
+ /**
+ * Saves the playlist at location.
+ *
+ * @return true if success; false otherwise
+ */
+ virtual bool save(const QString & location, const QList<MediaInfo> &
files) = 0;

signals:

@@ -60,7 +69,6 @@
* @see PlaylistReader::filesFound()
*/
void filesFound(const QList<MediaInfo> & files);
-
};

#endif //IPLAYLISTPARSERIMPL_H
=======================================
--- /trunk/libs/PlaylistParser/M3UParser.cpp Wed Feb 16 06:13:11 2011
+++ /trunk/libs/PlaylistParser/M3UParser.cpp Thu Feb 17 07:53:14 2011
@@ -53,7 +53,12 @@
_stop = true;
}

-void M3UParser::load(QIODevice * device, const QString & location) {
+bool M3UParser::load(const QString & location) {
+ QIODevice * device = Util::openLocationReadMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QList<MediaInfo> files;
@@ -64,9 +69,9 @@
QRegExp rx_extm3u("^#EXTM3U$|^#M3U$");
//#EXTINF:123,Sample title
//"Sample title" can be "Artist - Title"
- QRegExp rx_extinf("^#EXTINF:([-+]?\\d+),\s?(.*)$");
+ QRegExp rx_extinf("^#EXTINF:([-+]?\\d+),\\s?(.*)$");
//#EXTINF:Sample title
- QRegExp rx_extinf_title("^#EXTINF:\s?(.*)$");
+ QRegExp rx_extinf_title("^#EXTINF:\\s?(.*)$");
//#Just a comment
QRegExp rx_comment("^#.*$");

@@ -141,14 +146,22 @@
}

device->close();
+ delete device;

if (!files.isEmpty()) {
//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
emit filesFound(files);
}
+
+ return true;
}

-void M3UParser::save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) {
+bool M3UParser::save(const QString & location, const QList<MediaInfo> &
files) {
+ QIODevice * device = Util::openLocationWriteMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QString path(QFileInfo(location).path());
@@ -198,6 +211,9 @@
}

device->close();
+ delete device;
+
+ return true;
}

bool M3UParser::isUtf8(const QString & location) {
=======================================
--- /trunk/libs/PlaylistParser/M3UParser.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/M3UParser.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -38,9 +38,9 @@

QStringList fileExtensions() const;

- void load(QIODevice * device, const QString & location);
-
- void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files);
+ bool load(const QString & location);
+
+ bool save(const QString & location, const QList<MediaInfo> & files);

void stop();

=======================================
--- /trunk/libs/PlaylistParser/PLSParser.cpp Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/PLSParser.cpp Thu Feb 17 07:53:14 2011
@@ -61,7 +61,12 @@
_stop = true;
}

-void PLSParser::load(QIODevice * device, const QString & location) {
+bool PLSParser::load(const QString & location) {
+ QIODevice * device = Util::openLocationReadMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QList<MediaInfo> files;
@@ -142,6 +147,7 @@
}

device->close();
+ delete device;

if (!mediaInfo.fileName().isEmpty()) {
//Add the last file to the list of files
@@ -152,9 +158,16 @@
//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
emit filesFound(files);
}
+
+ return true;
}

-void PLSParser::save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) {
+bool PLSParser::save(const QString & location, const QList<MediaInfo> &
files) {
+ QIODevice * device = Util::openLocationWriteMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QString path(QFileInfo(location).path());
@@ -201,4 +214,7 @@
}

device->close();
-}
+ delete device;
+
+ return true;
+}
=======================================
--- /trunk/libs/PlaylistParser/PLSParser.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/PLSParser.h Thu Feb 17 07:53:14 2011
@@ -38,9 +38,9 @@

QStringList fileExtensions() const;

- void load(QIODevice * device, const QString & location);
-
- void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files);
+ bool load(const QString & location);
+
+ bool save(const QString & location, const QList<MediaInfo> & files);

void stop();

=======================================
--- /trunk/libs/PlaylistParser/PlaylistParser.cpp Wed Nov 10 09:13:11 2010
+++ /trunk/libs/PlaylistParser/PlaylistParser.cpp Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -30,7 +30,6 @@

#include <QtCore/QtConcurrentRun>
#include <QtCore/QFuture>
-#include <QtCore/QFutureWatcher>

#include <QtCore/QStringList>
#include <QtCore/QUrl>
@@ -38,8 +37,7 @@
#include <QtCore/QMetaType>

PlaylistParser::PlaylistParser(QObject * parent)
- : IPlaylistParser(parent),
- _file(this) {
+ : IPlaylistParser(parent) {

qRegisterMetaType<QList<MediaInfo> >("QList<MediaInfo>");
qRegisterMetaType<PlaylistParser::Error>("PlaylistParser::Error");
@@ -47,6 +45,10 @@
_parser = NULL;
_error = NoError;

+ _watcher = new QFutureWatcher<bool>(this);
+ connect(_watcher, SIGNAL(finished()),
+ SLOT(concurrentFinished()));
+
//FIXME memory leak: when to delete _parserList?
//Use shared pointer?
_parserList += new M3UParser(this);
@@ -66,10 +68,6 @@
//delete parser;
}
}
-
-const QFile & PlaylistParser::file() const {
- return _file;
-}

//FIXME Change the API and make it return the parser?
void PlaylistParser::findParser(const QString & fileName) {
@@ -91,7 +89,13 @@
}

void PlaylistParser::concurrentFinished() {
- _error = NoError;
+ QFuture<bool> future = _watcher->future();
+ bool ok = future.result();
+ if (ok) {
+ _error = NoError;
+ } else {
+ _error = IOError;
+ }
emit finished(_error, _timeElapsed.elapsed());
}

@@ -114,24 +118,6 @@

_timeElapsed.start();

- _file.setFileName(fileName);
-
- //Cannot use QIODevice::Text since binary playlist formats can exist (or
exist already)
- //See QFile documentation, here a copy-paste:
- //The QIODevice::Text flag passed to open() tells Qt to convert
Windows-style line terminators ("\r\n")
- //into C++-style terminators ("\n").
- //By default, QFile assumes binary, i.e. it doesn't perform any
conversion on the bytes stored in the file.
- bool ok = _file.open(QIODevice::ReadOnly);
-
- if (ok) {
- loadIODevice(&_file, fileName);
- } else {
- _error = FileError;
- emit finished(_error, _timeElapsed.elapsed());
- }
-}
-
-void PlaylistReader::loadIODevice(QIODevice * device, const QString &
fileName) {
if (_parser) {
//Disconnect the previous parser if any
disconnect(_parser);
@@ -144,15 +130,10 @@
connect(_parser, SIGNAL(filesFound(const QList<MediaInfo> &)),
SIGNAL(filesFound(const QList<MediaInfo> &)));

- static QFutureWatcher<void> * watcher = NULL;
- if (!watcher) {
- //Lazy initialization
- watcher = new QFutureWatcher<void>(this);
- connect(watcher, SIGNAL(finished()),
- SLOT(concurrentFinished()));
- }
- QFuture<void> future = QtConcurrent::run(_parser,
&IPlaylistParserImpl::load, device, fileName);
- watcher->setFuture(future);
+ QFuture<bool> future = QtConcurrent::run(
+ _parser, &IPlaylistParserImpl::load, fileName
+ );
+ _watcher->setFuture(future);
}
}

@@ -169,34 +150,11 @@

_timeElapsed.restart();

- _file.setFileName(fileName);
-
- //Cannot use QIODevice::Text since binary playlist formats may exist (or
exist already)
- //See QFile documentation, here a copy-paste:
- //The QIODevice::Text flag passed to open() tells Qt to convert
Windows-style line terminators ("\r\n")
- //into C++-style terminators ("\n").
- //By default, QFile assumes binary, i.e. it doesn't perform any
conversion on the bytes stored in the file.
- bool ok = _file.open(QIODevice::WriteOnly);
-
- if (ok) {
- saveIODevice(&_file, fileName, mediaList);
- } else {
- _error = FileError;
- emit finished(_error, _timeElapsed.elapsed());
- }
-}
-
-void PlaylistWriter::saveIODevice(QIODevice * device, const QString &
fileName, const QList<MediaInfo> & mediaList) {
findParser(fileName);
if (_parser) {
- static QFutureWatcher<void> * watcher = NULL;
- if (!watcher) {
- //Lazy initialization
- watcher = new QFutureWatcher<void>(this);
- connect(watcher, SIGNAL(finished()),
- SLOT(concurrentFinished()));
- }
- QFuture<void> future = QtConcurrent::run(_parser,
&IPlaylistParserImpl::save, device, fileName, mediaList);
- watcher->setFuture(future);
+ QFuture<bool> future = QtConcurrent::run(
+ _parser, &IPlaylistParserImpl::save, fileName, mediaList
+ );
+ _watcher->setFuture(future);
}
}
=======================================
--- /trunk/libs/PlaylistParser/PlaylistParser.h Wed Nov 10 09:13:11 2010
+++ /trunk/libs/PlaylistParser/PlaylistParser.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -21,8 +21,8 @@

#include <PlaylistParser/IPlaylistParser.h>

+#include <QtCore/QFutureWatcher>
#include <QtCore/QList>
-#include <QtCore/QFile>
#include <QtCore/QTime>

class IPlaylistParserImpl;
@@ -53,11 +53,11 @@
UnsupportedFormatError,

/**
- * Playlist file could not be read/write using QFile.
+ * Playlist could not be read/write using QIODevice.
*
- * Use file().error() in order to get more informations.
+ * Check the log to see the exact error.
*/
- FileError,
+ IOError,
};

PlaylistParser(QObject * parent);
@@ -66,8 +66,6 @@

void stop();

- const QFile & file() const;
-
signals:

/**
@@ -107,13 +105,12 @@
IPlaylistParserImpl * _parser;

/** Error for the finished() signal. */
- Error _error;
-
- /** QFile used to read/write the playlist file. */
- QFile _file;
+ PlaylistParser::Error _error;

/** Computes the time needed to parser the playlist file. */
QTime _timeElapsed;
+
+ QFutureWatcher<bool> * _watcher;
};

class MediaInfo;
@@ -155,8 +152,6 @@
void filesFound(const QList<MediaInfo> & mediaList);

private:
-
- void loadIODevice(QIODevice * device, const QString & fileName);
};

/**
@@ -184,9 +179,6 @@
void save(const QString & fileName, const QList<MediaInfo> & mediaList);

private:
-
- void saveIODevice(QIODevice * device, const QString & fileName, const
QList<MediaInfo> & mediaList);
-
};

#endif //PLAYLISTPARSER_H
=======================================
--- /trunk/libs/PlaylistParser/Util.cpp Tue Feb 15 08:43:21 2011
+++ /trunk/libs/PlaylistParser/Util.cpp Thu Feb 17 07:53:14 2011
@@ -57,3 +57,39 @@

return tmp;
}
+
+QIODevice * Util::openLocationReadMode(const QString & location) {
+ QFile * file = new QFile(location);
+
+ //Cannot use QIODevice::Text since binary playlist formats can exist (or
exist already)
+ //See QFile documentation, here a copy-paste:
+ //The QIODevice::Text flag passed to open() tells Qt to convert
Windows-style line terminators ("\r\n")
+ //into C++-style terminators ("\n").
+ //By default, QFile assumes binary, i.e. it doesn't perform any
conversion on the bytes stored in the file.
+ bool ok = file->open(QIODevice::ReadOnly);
+ if (!ok) {
+ PlaylistParserCritical() << "Couldn't open file:" << location
<< "error:" << file->errorString();
+ delete file;
+ return NULL;
+ } else {
+ return file;
+ }
+}
+
+QIODevice * Util::openLocationWriteMode(const QString & location) {
+ QFile * file = new QFile(location);
+
+ //Cannot use QIODevice::Text since binary playlist formats may exist (or
exist already)
+ //See QFile documentation, here a copy-paste:
+ //The QIODevice::Text flag passed to open() tells Qt to convert
Windows-style line terminators ("\r\n")
+ //into C++-style terminators ("\n").
+ //By default, QFile assumes binary, i.e. it doesn't perform any
conversion on the bytes stored in the file.
+ bool ok = file->open(QIODevice::WriteOnly);
+ if (!ok) {
+ PlaylistParserCritical() << "Couldn't open file:" << location
<< "error:" << file->errorString();
+ delete file;
+ return NULL;
+ } else {
+ return file;
+ }
+}
=======================================
--- /trunk/libs/PlaylistParser/Util.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/Util.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -20,6 +20,7 @@
#define UTIL_H

class QString;
+class QIODevice;

/**
* Utility functions for the different parsers.
@@ -43,6 +44,28 @@
*/
static QString canonicalFilePath(const QString & path, const QString &
fileName);

+ /**
+ * Opens the location (filename) in read mode.
+ *
+ * Code factorization.
+ * If the QIODevice returned != NULL then it should be deleted by you.
+ *
+ * @param location location (filename) to open
+ * @return QIODevice or NULL
+ */
+ static QIODevice * openLocationReadMode(const QString & location);
+
+ /**
+ * Opens the location (filename) in write mode.
+ *
+ * Code factorization.
+ * If the QIODevice returned != NULL then it should be deleted by you.
+ *
+ * @param location location (filename) to open
+ * @return QIODevice or NULL
+ */
+ static QIODevice * openLocationWriteMode(const QString & location);
+
private:

Util();
=======================================
--- /trunk/libs/PlaylistParser/WPLParser.cpp Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/WPLParser.cpp Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -64,7 +64,12 @@
_stop = true;
}

-void WPLParser::load(QIODevice * device, const QString & location) {
+bool WPLParser::load(const QString & location) {
+ QIODevice * device = Util::openLocationReadMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QList<MediaInfo> files;
@@ -109,14 +114,22 @@
}

device->close();
+ delete device;

if (!files.isEmpty()) {
//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
emit filesFound(files);
}
+
+ return true;
}

-void WPLParser::save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) {
+bool WPLParser::save(const QString & location, const QList<MediaInfo> &
files) {
+ QIODevice * device = Util::openLocationWriteMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QString path(QFileInfo(location).path());
@@ -164,4 +177,7 @@
xml.writeEndElement(); //smil

device->close();
-}
+ delete device;
+
+ return true;
+}
=======================================
--- /trunk/libs/PlaylistParser/WPLParser.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/PlaylistParser/WPLParser.h Thu Feb 17 07:53:14 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -43,9 +43,9 @@

QStringList fileExtensions() const;

- void load(QIODevice * device, const QString & location);
-
- void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files);
+ bool load(const QString & location);
+
+ bool save(const QString & location, const QList<MediaInfo> & files);

void stop();

=======================================
--- /trunk/libs/PlaylistParser/XSPFParser.cpp Wed Feb 16 06:13:11 2011
+++ /trunk/libs/PlaylistParser/XSPFParser.cpp Thu Feb 17 07:53:14 2011
@@ -322,8 +322,11 @@
xml.writeEndElement(); //track
}

-void XSPFParser::load(QIODevice * device, const QString & location) {
- Q_UNUSED(location);
+bool XSPFParser::load(const QString & location) {
+ QIODevice * device = Util::openLocationReadMode(location);
+ if (!device) {
+ return false;
+ }

_stop = false;

@@ -386,14 +389,22 @@
}

device->close();
+ delete device;

if (!files.isEmpty()) {
//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
emit filesFound(files);
}
+
+ return true;
}

-void XSPFParser::save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files) {
+bool XSPFParser::save(const QString & location, const QList<MediaInfo> &
files) {
+ QIODevice * device = Util::openLocationWriteMode(location);
+ if (!device) {
+ return false;
+ }
+
_stop = false;

QXmlStreamWriter xml(device);
@@ -424,4 +435,7 @@
xml.writeEndElement(); //playlist

device->close();
-}
+ delete device;
+
+ return true;
+}
=======================================
--- /trunk/libs/PlaylistParser/XSPFParser.h Wed Feb 16 06:13:11 2011
+++ /trunk/libs/PlaylistParser/XSPFParser.h Thu Feb 17 07:53:14 2011
@@ -53,9 +53,9 @@

QStringList fileExtensions() const;

- void load(QIODevice * device, const QString & location);
-
- void save(QIODevice * device, const QString & location, const
QList<MediaInfo> & files);
+ bool load(const QString & location);
+
+ bool save(const QString & location, const QList<MediaInfo> & files);

void stop();

=======================================
--- /trunk/tests/libs/PlaylistParser/CMakeLists.txt Wed Nov 25 10:08:49 2009
+++ /trunk/tests/libs/PlaylistParser/CMakeLists.txt Thu Feb 17 07:53:14 2011
@@ -1,25 +1,28 @@
-project(PlaylistParserTest)
-
-set(PlaylistParserTest_SRCS
- PlaylistParserTest.cpp
-)
-
-qt4_wrap_cpp(PlaylistParserTest_SRCS
- PlaylistParserTest.h
-)
-
-qt4_add_resources(PlaylistParserTest_SRCS
- playlists.qrc
-)
-
-add_executable(PlaylistParserTest ${PlaylistParserTest_SRCS})
-add_test(PlaylistParserTest PlaylistParserTest)
-
-target_link_libraries(PlaylistParserTest
- PlaylistParser
-
- ${QT_QTCORE_LIBRARY}
- ${QT_QTTEST_LIBRARY}
-)
-
-install(TARGETS PlaylistParserTest ${INSTALL_TARGETS_DEFAULT_ARGS})
+project(PlaylistParserTests)
+
+macro(add_unit_test name)
+ set(SRCS ${ARGN})
+
+ add_executable(${name} ${SRCS})
+
+ add_test(${name} ${name})
+
+ target_link_libraries(${name}
+ PlaylistParser
+
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTTEST_LIBRARY}
+ )
+ install(TARGETS ${name} ${INSTALL_TARGETS_DEFAULT_ARGS})
+endmacro(add_unit_test name)
+
+
+set(PlaylistReaderTest_SRCS PlaylistReaderTest.cpp)
+qt4_wrap_cpp(PlaylistReaderTest_SRCS PlaylistReaderTest.h)
+qt4_add_resources(PlaylistReaderTest_SRCS playlists.qrc)
+add_unit_test(PlaylistReaderTest ${PlaylistReaderTest_SRCS})
+
+
+set(PlaylistWriterTest_SRCS PlaylistWriterTest.cpp)
+qt4_wrap_cpp(PlaylistWriterTest_SRCS PlaylistWriterTest.h)
+add_unit_test(PlaylistWriterTest ${PlaylistWriterTest_SRCS})
Reply all
Reply to author
Forward
0 new messages