File indexing completed on 2024-12-29 04:26:32
0001 /*************************************************************************** 0002 * Copyright (c) 2009 Sven Krohlas <sven@asbest-online.de> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0018 ***************************************************************************/ 0019 0020 #include "TestSqlUserPlaylistProvider.h" 0021 0022 #include "EngineController.h" 0023 #include "config-amarok-test.h" 0024 #include "core/meta/Meta.h" 0025 #include "core/support/Components.h" 0026 #include "core-impl/collections/support/CollectionManager.h" 0027 #include "playlistmanager/sql/SqlUserPlaylistProvider.h" 0028 0029 #include <QTest> 0030 #include <QDir> 0031 0032 0033 QTEST_MAIN( TestSqlUserPlaylistProvider ) 0034 0035 TestSqlUserPlaylistProvider::TestSqlUserPlaylistProvider() 0036 {} 0037 0038 QString 0039 TestSqlUserPlaylistProvider::dataPath( const QString &relPath ) 0040 { 0041 return QDir::toNativeSeparators( QString( AMAROK_TEST_DIR ) + '/' + relPath ); 0042 } 0043 0044 void TestSqlUserPlaylistProvider::initTestCase() 0045 { 0046 m_testSqlUserPlaylistProvider = new Playlists::SqlUserPlaylistProvider( true ); 0047 m_testSqlUserPlaylistProvider->deletePlaylists( m_testSqlUserPlaylistProvider->playlists() ); 0048 } 0049 0050 void TestSqlUserPlaylistProvider::cleanupTestCase() 0051 { 0052 delete m_testSqlUserPlaylistProvider; 0053 } 0054 0055 void TestSqlUserPlaylistProvider::testPlaylists() 0056 { 0057 Playlists::PlaylistList tempList = m_testSqlUserPlaylistProvider->playlists(); 0058 QCOMPARE( tempList.size(), 0 ); 0059 } 0060 0061 void TestSqlUserPlaylistProvider::testSave() 0062 { 0063 Meta::TrackList tempTrackList; 0064 QUrl trackUrl; 0065 trackUrl = QUrl::fromLocalFile(dataPath( "data/audio/Platz 01.mp3" )); 0066 tempTrackList.append( CollectionManager::instance()->trackForUrl( trackUrl ) ); 0067 0068 Playlists::PlaylistPtr testPlaylist = 0069 m_testSqlUserPlaylistProvider->save( tempTrackList, "Amarok Test Playlist" ); 0070 0071 QCOMPARE( testPlaylist->name(), QString( "Amarok Test Playlist" ) ); 0072 QCOMPARE( testPlaylist->tracks().size(), 1 ); 0073 0074 Playlists::PlaylistList tempList = m_testSqlUserPlaylistProvider->playlists(); 0075 QCOMPARE( tempList.size(), 1 ); 0076 } 0077 0078 void TestSqlUserPlaylistProvider::testRename() 0079 { 0080 Playlists::PlaylistList tempList = m_testSqlUserPlaylistProvider->playlists(); 0081 m_testSqlUserPlaylistProvider->renamePlaylist( tempList.at( 0 ), "New Test Name" ); 0082 QCOMPARE( tempList.at( 0 )->name(), QString( "New Test Name" ) ); 0083 } 0084 0085 void TestSqlUserPlaylistProvider::testDelete() 0086 { 0087 Playlists::PlaylistList tempList = m_testSqlUserPlaylistProvider->playlists(); 0088 m_testSqlUserPlaylistProvider->deletePlaylists( tempList ); 0089 QCOMPARE( m_testSqlUserPlaylistProvider->playlists().size(), 0 ); 0090 }