File indexing completed on 2024-04-28 04:48:13
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 "TestITunesImporter.h" 0018 0019 #include "MetaValues.h" 0020 #include "importers/itunes/ITunesConfigWidget.h" 0021 #include "importers/itunes/ITunesProvider.h" 0022 0023 #include <QTest> 0024 0025 0026 QTEST_MAIN( TestITunesImporter ) 0027 0028 using namespace StatSyncing; 0029 0030 ProviderPtr 0031 TestITunesImporter::getProvider() 0032 { 0033 QVariantMap cfg = ITunesConfigWidget( QVariantMap() ).config(); 0034 cfg.insert( "dbPath", QApplication::applicationDirPath() 0035 + "/importers_files/iTunes_Music_Library.xml" ); 0036 0037 return ProviderPtr( new ITunesProvider( cfg, nullptr ) ); 0038 } 0039 0040 ProviderPtr 0041 TestITunesImporter::getWritableProvider() 0042 { 0043 QDir base( QCoreApplication::applicationDirPath() ); 0044 base.mkpath( "importers_tmp" ); 0045 0046 const QString dst = base.filePath( "importers_tmp/iTunes_Music_Library.xml" ); 0047 QFile( dst ).remove(); 0048 QFile( base.filePath( "importers_files/iTunes_Music_Library.xml" ) ).copy( dst ); 0049 0050 QVariantMap cfg = ITunesConfigWidget( QVariantMap() ).config(); 0051 cfg.insert( "dbPath", dst); 0052 0053 return ProviderPtr( new ITunesProvider( cfg, nullptr ) ); 0054 } 0055 0056 qint64 0057 TestITunesImporter::reliableStatistics() const 0058 { 0059 return Meta::valLastPlayed | Meta::valRating | Meta::valPlaycount; 0060 } 0061 0062 bool 0063 TestITunesImporter::hasOddRatings() const 0064 { 0065 return false; // iTunes actually *has* odd ratings, as it's rating value is in range 0066 // 0-100, but it represents ratings as multipliers of 20. 0067 } 0068 0069 void 0070 TestITunesImporter::init() 0071 { 0072 m_cfg = ITunesConfigWidget( QVariantMap() ).config(); 0073 } 0074 0075 void 0076 TestITunesImporter::providerShouldHandleNonexistentDbFile() 0077 { 0078 m_cfg.insert( "dbPath", "/wdawd\\wdadwgd/das4hutyf" ); 0079 0080 ITunesProvider provider( m_cfg, nullptr ); 0081 QVERIFY( provider.artists().isEmpty() ); 0082 } 0083 0084 void 0085 TestITunesImporter::providerShouldHandleInvalidDbFile() 0086 { 0087 m_cfg.insert( "dbPath", QApplication::applicationFilePath() ); 0088 0089 ITunesProvider provider( m_cfg, nullptr ); 0090 QVERIFY( provider.artists().isEmpty() ); 0091 } 0092 0093 void 0094 TestITunesImporter::providerShouldHandleErroneousConfigValues() 0095 { 0096 m_cfg.insert( "dbPath", "\\wd%aw@d/sdsd2'vodk0-=$$" ); 0097 m_cfg.insert( "name", QColor( Qt::white ) ); 0098 0099 ITunesProvider provider( m_cfg, nullptr ); 0100 QVERIFY( provider.artists().isEmpty() ); 0101 } 0102 0103 void 0104 TestITunesImporter::providerShouldHandleIllFormedDbFile() 0105 { 0106 m_cfg.insert( "dbPath", QApplication::applicationDirPath() 0107 + "/importers_files/illFormedLibrary.xml" ); 0108 0109 ITunesProvider provider( m_cfg, nullptr ); 0110 QVERIFY( provider.artistTracks( "NonSuch" ).empty() ); 0111 }