File indexing completed on 2024-04-28 04:48:12
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "TestBansheeImporter.h" 0018 0019 #include "MetaValues.h" 0020 #include "importers/banshee/BansheeConfigWidget.h" 0021 #include "importers/banshee/BansheeProvider.h" 0022 0023 #include <QTest> 0024 0025 0026 QTEST_MAIN( TestBansheeImporter ) 0027 0028 using namespace StatSyncing; 0029 0030 ProviderPtr 0031 TestBansheeImporter::getProvider() 0032 { 0033 QVariantMap cfg = BansheeConfigWidget( QVariantMap() ).config(); 0034 cfg.insert( "dbPath", QApplication::applicationDirPath() 0035 + "/importers_files/banshee.db" ); 0036 0037 return ProviderPtr( new BansheeProvider( cfg, nullptr ) ); 0038 } 0039 0040 ProviderPtr 0041 TestBansheeImporter::getWritableProvider() 0042 { 0043 QDir base( QCoreApplication::applicationDirPath() ); 0044 base.mkpath( "importers_tmp" ); 0045 0046 const QString dst = base.filePath( "importers_tmp/banshee.db" ); 0047 QFile( dst ).remove(); 0048 QFile( base.filePath( "importers_files/banshee.db" ) ).copy( dst ); 0049 0050 QVariantMap cfg = BansheeConfigWidget( QVariantMap() ).config(); 0051 cfg.insert( "dbPath", dst ); 0052 0053 return ProviderPtr( new BansheeProvider( cfg, nullptr ) ); 0054 } 0055 0056 qint64 0057 TestBansheeImporter::reliableStatistics() const 0058 { 0059 return Meta::valLastPlayed | Meta::valPlaycount | Meta::valRating; 0060 } 0061 0062 bool 0063 TestBansheeImporter::hasOddRatings() const 0064 { 0065 return false; 0066 } 0067 0068 void 0069 TestBansheeImporter::init() 0070 { 0071 m_cfg = BansheeConfigWidget( QVariantMap() ).config(); 0072 } 0073 0074 void 0075 TestBansheeImporter::providerShouldHandleNonexistentDbFile() 0076 { 0077 m_cfg.insert( "dbPath", "/wdawd\\wdadwgd/das4hutyf" ); 0078 0079 BansheeProvider provider( m_cfg, nullptr ); 0080 QVERIFY( provider.artists().isEmpty() ); 0081 } 0082 0083 void 0084 TestBansheeImporter::providerShouldHandleInvalidDbFile() 0085 { 0086 m_cfg.insert( "dbPath", QApplication::applicationFilePath() ); 0087 0088 BansheeProvider provider( m_cfg, nullptr ); 0089 QVERIFY( provider.artists().isEmpty() ); 0090 } 0091 0092 void 0093 TestBansheeImporter::providerShouldHandleErroneousConfigValues() 0094 { 0095 m_cfg.insert( "dbPath", "\\wd%aw@d/sdsd2'vodk0-=$$" ); 0096 m_cfg.insert( "name", QColor( Qt::white ) ); 0097 0098 BansheeProvider provider( m_cfg, nullptr ); 0099 QVERIFY( provider.artists().isEmpty() ); 0100 } 0101 0102 void 0103 TestBansheeImporter::artistTracksShouldNotReturnTracksNotFromPrimarySource() 0104 { 0105 ProviderPtr provider( getProvider() ); 0106 0107 const QString artist = "wrongSource"; 0108 QVERIFY( provider->artists().contains( artist ) ); 0109 QVERIFY( provider->artistTracks( artist ).isEmpty() ); 0110 }