From 2c3e9276aa757dd0922773842eddb31d55e7d93d Mon Sep 17 00:00:00 2001 From: David Sansome Date: Tue, 15 Jun 2010 13:56:41 +0000 Subject: [PATCH] Fix some of the comments on r1148 --- src/core/songloader.cpp | 6 +++--- src/playlistparsers/playlistparser.cpp | 6 +----- src/playlistparsers/playlistparser.h | 3 +-- src/playlistparsers/plsparser.cpp | 2 +- src/playlistparsers/xspfparser.cpp | 3 +-- tests/songloader_test.cpp | 24 ++++++++++++------------ tests/test_utils.cpp | 2 +- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/core/songloader.cpp b/src/core/songloader.cpp index 69600c3bc..5c6a2e1cc 100644 --- a/src/core/songloader.cpp +++ b/src/core/songloader.cpp @@ -65,10 +65,10 @@ SongLoader::Result SongLoader::LoadLocal() { return Error; QByteArray data(file.read(PlaylistParser::kMagicSize)); - ParserBase* parser = playlist_parser_->TryMagic(data); + ParserBase* parser = playlist_parser_->MaybeGetParserForMagic(data); if (parser) { // It's a playlist! - file.seek(0); + file.reset(); songs_ = parser->Load(&file, QFileInfo(filename).path()); } else { // Not a playlist, so just assume it's a song @@ -252,7 +252,7 @@ void SongLoader::EndOfStreamReached() { } void SongLoader::MagicReady() { - parser_ = playlist_parser_->TryMagic(buffer_); + parser_ = playlist_parser_->MaybeGetParserForMagic(buffer_); if (!parser_) { // It doesn't look like a playlist, so just finish diff --git a/src/playlistparsers/playlistparser.cpp b/src/playlistparsers/playlistparser.cpp index 02bdc5c70..abb9b9a8e 100644 --- a/src/playlistparsers/playlistparser.cpp +++ b/src/playlistparsers/playlistparser.cpp @@ -70,7 +70,7 @@ ParserBase* PlaylistParser::ParserForExtension(const QString& suffix) const { return NULL; } -ParserBase* PlaylistParser::ParserForData(const QByteArray &data) const { +ParserBase* PlaylistParser::MaybeGetParserForMagic(const QByteArray &data) const { foreach (ParserBase* p, parsers_) { if (p->TryMagic(data)) return p; @@ -78,10 +78,6 @@ ParserBase* PlaylistParser::ParserForData(const QByteArray &data) const { return NULL; } -ParserBase* PlaylistParser::TryMagic(const QByteArray &data) const { - return ParserForData(data); -} - SongList PlaylistParser::Load(const QString &filename, ParserBase* p) const { QFileInfo info(filename); diff --git a/src/playlistparsers/playlistparser.h b/src/playlistparsers/playlistparser.h index c5a46340b..817464629 100644 --- a/src/playlistparsers/playlistparser.h +++ b/src/playlistparsers/playlistparser.h @@ -34,14 +34,13 @@ public: QStringList file_extensions() const; QString filters() const; - ParserBase* TryMagic(const QByteArray& data) const; + ParserBase* MaybeGetParserForMagic(const QByteArray& data) const; SongList Load(const QString& filename, ParserBase* parser = 0) const; void Save(const SongList& songs, const QString& filename) const; private: ParserBase* ParserForExtension(const QString& suffix) const; - ParserBase* ParserForData(const QByteArray& data) const; QList parsers_; }; diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index 9c663a78a..1341b4f1d 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -91,7 +91,7 @@ void PLSParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) s.sync(); - temp_file.seek(0); + temp_file.reset(); device->write(temp_file.readAll()); } diff --git a/src/playlistparsers/xspfparser.cpp b/src/playlistparsers/xspfparser.cpp index dca0df8dc..7a8cf5d1a 100644 --- a/src/playlistparsers/xspfparser.cpp +++ b/src/playlistparsers/xspfparser.cpp @@ -139,6 +139,5 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) } bool XSPFParser::TryMagic(const QByteArray &data) const { - QByteArray lower(data.toLower()); - return lower.contains("Init()); - } + static void SetUpTestCase() { + sGstEngine = new GstEngine; + ASSERT_TRUE(sGstEngine->Init()); + } - static void TearDownTestCase() { - delete sGstEngine; - sGstEngine = NULL; - } + static void TearDownTestCase() { + delete sGstEngine; + sGstEngine = NULL; + } protected: void SetUp() { @@ -109,7 +109,7 @@ TEST_F(SongLoaderTest, LoadRemoteMp3) { QEventLoop loop; QObject::connect(loader_.get(), SIGNAL(LoadFinished(bool)), &loop, SLOT(quit())); - loop.exec(); + loop.exec(QEventLoop::ExcludeUserInputEvents); // Check the signal was emitted with Success ASSERT_EQ(1, spy.count()); @@ -129,7 +129,7 @@ TEST_F(SongLoaderTest, LoadRemote404) { QEventLoop loop; QObject::connect(loader_.get(), SIGNAL(LoadFinished(bool)), &loop, SLOT(quit())); - loop.exec(); + loop.exec(QEventLoop::ExcludeUserInputEvents); // Check the signal was emitted with Error ASSERT_EQ(1, spy.count()); @@ -146,7 +146,7 @@ TEST_F(SongLoaderTest, LoadRemotePls) { QEventLoop loop; QObject::connect(loader_.get(), SIGNAL(LoadFinished(bool)), &loop, SLOT(quit())); - loop.exec(); + loop.exec(QEventLoop::ExcludeUserInputEvents); // Check the signal was emitted with Success ASSERT_EQ(1, spy.count()); @@ -169,7 +169,7 @@ TEST_F(SongLoaderTest, LoadRemotePlainText) { QEventLoop loop; QObject::connect(loader_.get(), SIGNAL(LoadFinished(bool)), &loop, SLOT(quit())); - loop.exec(); + loop.exec(QEventLoop::ExcludeUserInputEvents); // Check the signal was emitted with Error ASSERT_EQ(1, spy.count()); diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index eed82058f..fe27e897c 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -58,5 +58,5 @@ TemporaryResource::TemporaryResource(const QString& filename) { resource.open(QIODevice::ReadOnly); write(resource.readAll()); - seek(0); + reset(); }