File indexing completed on 2024-05-12 04:49:40
0001 /*************************************************************************** 0002 * Copyright (c) 2009 Sven Krohlas <sven@asbest-online.de> * 0003 * Copyright (c) 2013 Matěj Laitl <matej@laitl.cz> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #include "TestTrackLoader.h" 0022 0023 #include "amarokconfig.h" 0024 #include "config-amarok-test.h" 0025 #include "core/meta/Meta.h" 0026 #include "core-impl/collections/support/CollectionManager.h" 0027 #include "core-impl/meta/proxy/MetaProxy.h" 0028 #include "core-impl/playlists/types/file/PlaylistFileSupport.h" 0029 #include "core-impl/support/TrackLoader.h" 0030 0031 #include <QSignalSpy> 0032 #include <QTest> 0033 0034 #include <ThreadWeaver/Queue> 0035 0036 QTEST_GUILESS_MAIN( TestTrackLoader ) 0037 0038 void 0039 TestTrackLoader::initTestCase() 0040 { 0041 AmarokConfig::instance("amarokrc"); 0042 0043 qRegisterMetaType<Meta::TrackPtr>(); 0044 qRegisterMetaType<Meta::TrackList>(); 0045 CollectionManager::instance(); // create in the main thread 0046 } 0047 0048 void 0049 TestTrackLoader::cleanupTestCase() 0050 { 0051 // Wait for other jobs, like MetaProxys fetching meta data, to finish 0052 ThreadWeaver::Queue::instance()->finish(); 0053 } 0054 0055 void 0056 TestTrackLoader::testFullMetadataInit() 0057 { 0058 typedef QPair<QString, int> StringIntPair; 0059 QList<StringIntPair> pathsCounts; 0060 pathsCounts << qMakePair( dataPath( "data/audio/album" ), 3 ) 0061 << qMakePair( dataPath( "data/audio/album2" ), 2 ) 0062 << qMakePair( dataPath( "data/playlists/test.asx" ), 1 ) 0063 << qMakePair( dataPath( "data/playlists/test.m3u" ), 10 ) 0064 << qMakePair( dataPath( "data/playlists/test.pls" ), 4 ) 0065 << qMakePair( dataPath( "data/playlists/test.xspf" ), 23 ); 0066 0067 // it is more probable to get unresolved MetaProxy::Track for small runs: 0068 for( const StringIntPair &pair : pathsCounts ) 0069 { 0070 TrackLoader *loader = new TrackLoader( TrackLoader::FullMetadataRequired ); 0071 QSignalSpy spy( loader, &TrackLoader::finished ); 0072 loader->init( QUrl::fromLocalFile( pair.first ) ); 0073 0074 QVERIFY2( spy.wait( 15000 ), "loader did not finish within timeout" ); 0075 0076 Meta::TrackList found = spy.first().first().value<Meta::TrackList>(); 0077 QCOMPARE( found.count(), pair.second ); 0078 for( const Meta::TrackPtr &track : found ) 0079 { 0080 MetaProxy::TrackPtr proxyTrack = MetaProxy::TrackPtr::dynamicCast( track ); 0081 if( !proxyTrack ) 0082 { 0083 qDebug() << track->prettyUrl() << "is not a MetaProxy::Track. Strange and we cannot test it"; 0084 continue; 0085 } 0086 QVERIFY2( proxyTrack->isResolved(), proxyTrack->prettyUrl().toLocal8Bit().data() ); 0087 } 0088 delete loader; 0089 } 0090 } 0091 0092 void 0093 TestTrackLoader::testInit() 0094 { 0095 TrackLoader *loader1 = new TrackLoader(); 0096 QSignalSpy spy1( loader1, &TrackLoader::finished ); 0097 loader1->init( QUrl::fromLocalFile( dataPath( "data/audio" ) ) ); // test the convenience overload 0098 0099 QVERIFY2( spy1.wait( 5000 ), "loader1 did not finish within timeout" ); 0100 0101 Meta::TrackList found = spy1.first().first().value<Meta::TrackList>(); 0102 QCOMPARE( found.count(), 15 ); 0103 QVERIFY2( found.at( 0 )->uidUrl().endsWith( "audio/album/Track01.ogg" ), found.at( 0 )->uidUrl().toLocal8Bit().data() ); 0104 QVERIFY2( found.at( 1 )->uidUrl().endsWith( "audio/album/Track02.ogg" ), found.at( 1 )->uidUrl().toLocal8Bit().data() ); 0105 QVERIFY2( found.at( 2 )->uidUrl().endsWith( "audio/album/Track03.ogg" ), found.at( 2 )->uidUrl().toLocal8Bit().data() ); 0106 QVERIFY2( found.at( 3 )->uidUrl().endsWith( "audio/album2/Track01.ogg" ), found.at( 3 )->uidUrl().toLocal8Bit().data() ); 0107 QVERIFY2( found.at( 4 )->uidUrl().endsWith( "audio/album2/Track02.ogg" ), found.at( 4 )->uidUrl().toLocal8Bit().data() ); 0108 QVERIFY2( found.at( 5 )->uidUrl().endsWith( "audio/Platz 01.mp3" ), found.at( 5 )->uidUrl().toLocal8Bit().data() ); 0109 QVERIFY2( found.at( 10 )->uidUrl().endsWith( "audio/Platz 06.mp3" ), found.at( 10 )->uidUrl().toLocal8Bit().data() ); 0110 QVERIFY2( found.at( 14 )->uidUrl().endsWith( "audio/Platz 10.mp3" ), found.at( 14 )->uidUrl().toLocal8Bit().data() ); 0111 0112 TrackLoader *loader2 = new TrackLoader(); 0113 QSignalSpy spy2( loader2, &TrackLoader::finished ); 0114 loader2->init( QList<QUrl>() << QUrl::fromLocalFile( dataPath( "data/audio/album2" ) ) ); 0115 0116 QVERIFY2( spy2.wait( 5000 ), "loader2 did not finish within timeout" ); 0117 0118 found = spy2.first().first().value<Meta::TrackList>(); 0119 QCOMPARE( found.count(), 2 ); 0120 QVERIFY2( found.at( 0 )->uidUrl().endsWith( "audio/album2/Track01.ogg" ), found.at( 0 )->uidUrl().toLocal8Bit().data() ); 0121 QVERIFY2( found.at( 1 )->uidUrl().endsWith( "audio/album2/Track02.ogg" ), found.at( 1 )->uidUrl().toLocal8Bit().data() ); 0122 } 0123 0124 void 0125 TestTrackLoader::testInitWithPlaylists() 0126 { 0127 TrackLoader *loader = new TrackLoader(); 0128 QSignalSpy spy( loader, &TrackLoader::finished ); 0129 QList<QUrl> urls; 0130 urls << QUrl::fromLocalFile( dataPath( "data/playlists/test.asx" ) ) 0131 << QUrl::fromLocalFile( dataPath( "data/audio/album" ) ) 0132 << QUrl::fromLocalFile( dataPath( "data/playlists/test.xspf" ) ); 0133 loader->init( urls ); 0134 0135 QVERIFY2( spy.wait( 5000 ), "loader did not finish within timeout" ); 0136 0137 Meta::TrackList found = spy.first().first().value<Meta::TrackList>(); 0138 QCOMPARE( found.count(), 1 + 3 + 23 ); 0139 QVERIFY( found.at( 0 )->uidUrl().endsWith( "/audio/album/Track01.ogg" ) ); // "audio/album" folder 0140 QVERIFY( found.at( 1 )->uidUrl().endsWith( "/audio/album/Track02.ogg" ) ); 0141 QVERIFY( found.at( 2 )->uidUrl().endsWith( "/audio/album/Track03.ogg" ) ); 0142 QCOMPARE( found.at( 3 )->uidUrl(), QString( "http://85.214.44.27:8000" ) ); // test.asx playlist 0143 QCOMPARE( found.at( 4 )->uidUrl(), QString( "http://he3.magnatune.com/all/01-Sunset-Ammonite.ogg" ) ); // start of test.xspf playlist 0144 QCOMPARE( found.at( 5 )->uidUrl(), QString( "http://he3.magnatune.com/all/02-Heaven-Ammonite.ogg" ) ); 0145 } 0146 0147 void 0148 TestTrackLoader::testDirectlyPassingPlaylists() 0149 { 0150 using namespace Playlists; 0151 TrackLoader *loader = new TrackLoader(); 0152 QSignalSpy spy( loader, &TrackLoader::finished ); 0153 PlaylistList playlists; 0154 playlists << PlaylistPtr::staticCast( loadPlaylistFile( QUrl::fromLocalFile( dataPath( "data/playlists/test.asx" ) ) ) ) 0155 << PlaylistPtr::staticCast( loadPlaylistFile( QUrl::fromLocalFile( dataPath( "data/playlists/test.xspf" ) ) ) ); 0156 loader->init( playlists ); 0157 0158 QVERIFY2( spy.wait( 5000 ), "loader did not finish within timeout" ); 0159 0160 Meta::TrackList found = spy.first().first().value<Meta::TrackList>(); 0161 QCOMPARE( found.count(), 1 + 23 ); 0162 QCOMPARE( found.at( 0 )->uidUrl(), QString( "http://85.214.44.27:8000" ) ); // test.asx playlist 0163 QCOMPARE( found.at( 1 )->uidUrl(), QString( "http://he3.magnatune.com/all/01-Sunset-Ammonite.ogg" ) ); // start of test.xspf playlist 0164 QCOMPARE( found.at( 2 )->uidUrl(), QString( "http://he3.magnatune.com/all/02-Heaven-Ammonite.ogg" ) ); 0165 } 0166 0167 QString 0168 TestTrackLoader::dataPath( const QString &relPath ) 0169 { 0170 return QDir::toNativeSeparators( QString( AMAROK_TEST_DIR ) + '/' + relPath ); 0171 }