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 #ifndef TEST_IMPORTER_BASE 0018 #define TEST_IMPORTER_BASE 0019 0020 #include <QExplicitlySharedDataPointer> 0021 #include <QObject> 0022 #include <QSet> 0023 0024 namespace StatSyncing 0025 { 0026 class Provider; 0027 typedef QSharedPointer<Provider> ProviderPtr; 0028 } 0029 0030 /** 0031 * A base class for Importer tests. It relies on convention to thoroughly test 0032 * a provider. It uses the provider returned by @see TestImporterBase::provider() 0033 * pure virtual method, which should be initialized with a database containing tracks 0034 * found in tests/importers/files/testcollection . Additionally, some of these tracks 0035 * must have their statistics set in the following way: 0036 * 0037 * title, artist, firstPlayed, lastPlayed, rating, playcount 0038 * title0, testStatistics, 1378125780, 1378125781, 1, 20 0039 * title1, testStatistics, 1378125782, 1378125783, 2, 15 0040 * title2, testStatistics, 1378125784, 1378125785, 3, 14 0041 * title3, testStatistics, 1378125786, 1378125787, 4, 13 0042 * title4, testStatistics, 1378125788, 1378125789, 5, 11 0043 * title5, testStatistics, 1378125790, 1378125791, 6, 10 0044 * title6, testStatistics, 1378125792, 1378125793, 7, 7 0045 * title7, testStatistics, 1378125794, 1378125795, 8, 5 0046 * title8, testStatistics, 1378125796, 1378125797, 9, 3 0047 * title9, testStatistics, 1378125798, 1378125799, 10, 2 0048 * 0049 * title, artist, firstPlayed, lastPlayed, rating, playcount 0050 * title0, testStatisticsNotSet, , , , 0051 * title1, testStatisticsNotSet, , 1378125783, 2, 15 0052 * title2, testStatisticsNotSet, , , 3, 14 0053 * title3, testStatisticsNotSet, , 1378125787, , 13 0054 * title4, testStatisticsNotSet, , , 5, 0055 * title5, testStatisticsNotSet, 1378125790, 1378125791, 6, 10 0056 * title6, testStatisticsNotSet, 1378125792, , , 7 0057 * title7, testStatisticsNotSet, 1378125794, 1378125795, 8, 5 0058 * title8, testStatisticsNotSet, 1378125796, , 9, 0059 * title9, testStatisticsNotSet, 1378125798, 1378125799, , 2 0060 * 0061 * title, artist, labels 0062 * title0, testStatistics, 'singleTag' 0063 * title1, testStatistics, 'multiple', 'tags' 0064 * title2, testStatistics, 'caseSensitive', 'casesensitive' 0065 * title3, testStatistics, '☢' 0066 */ 0067 class TestImporterBase : public QObject 0068 { 0069 Q_OBJECT 0070 0071 public: 0072 TestImporterBase(); 0073 0074 protected: 0075 /** 0076 * This method should return provider already configured for testing. 0077 */ 0078 virtual StatSyncing::ProviderPtr getProvider() = 0; 0079 0080 /** 0081 * This method should return a provider ready for writing. The database used should 0082 * be a temporary copy. 0083 */ 0084 virtual StatSyncing::ProviderPtr getWritableProvider(); 0085 0086 /** 0087 * Return a binary or of Meta::val* representing statistics supported 0088 * by the provider being tested. 0089 */ 0090 virtual qint64 reliableStatistics() const = 0; 0091 0092 /** 0093 * Returns true if the provider is capable of expressing odd-number ratings 0094 * (half-stars). Otherwise tests treat a half-star like a whole star (i.e. 0095 * a song normally with a rating 3 is assumed to have a rating 4). 0096 */ 0097 virtual bool hasOddRatings() const; 0098 0099 private: 0100 void checkStatistics( const QString &artist ); 0101 void labels( const StatSyncing::ProviderPtr &provider, const QString &trackName ); 0102 0103 QSet<QString> m_lbl; 0104 0105 private Q_SLOTS: 0106 void titleShouldBeCaseSensitive(); 0107 void artistShouldBeCaseSensitive(); 0108 void albumShouldBeCaseSensitive(); 0109 void composerShouldBeCaseSensitive(); 0110 0111 void titleShouldSupportUTF(); 0112 void artistShouldSupportUTF(); 0113 void albumShouldSupportUTF(); 0114 void composerShouldSupportUTF(); 0115 0116 void titleShouldSupportMultipleWords(); 0117 void artistShouldSupportMultipleWords(); 0118 void albumShouldSupportMultipleWords(); 0119 void composerShouldSupportMultipleWords(); 0120 0121 void titleShouldBeWhitespaceTrimmed(); 0122 void artistShouldBeWhitespaceTrimmed(); 0123 void albumShouldBeWhitespaceTrimmed(); 0124 void composerShouldBeWhitespaceTrimmed(); 0125 0126 void albumShouldBeUnsetIfTagIsUnset(); 0127 void composerShouldBeUnsetIfTagIsUnset(); 0128 void yearShouldBeUnsetIfTagIsUnset(); 0129 void trackShouldBeUnsetIfTagIsUnset(); 0130 void discShouldBeUnsetIfTagIsUnset(); 0131 0132 void tracksShouldHaveStatistics_data(); 0133 void tracksShouldHaveStatistics(); 0134 0135 void tracksShouldBehaveNicelyWithNoStatistics_data(); 0136 void tracksShouldBehaveNicelyWithNoStatistics(); 0137 0138 void tracksShouldWorkWithSingleLabel(); 0139 void tracksShouldWorkWithMultipleLabels(); 0140 void tracksShouldWorkWithCaseSensitiveLabels(); 0141 void tracksShouldWorkWithUTFLabels(); 0142 0143 void providerShouldReturnNoTracksForNonexistentArtist(); 0144 void providerShouldNotBreakOnLittleBobbyTables(); 0145 0146 // Write capabilities 0147 void commitAfterSettingAllStatisticsShouldSaveThem_data(); 0148 void commitAfterSettingAllStatisticsShouldSaveThem(); 0149 void commitAfterSettingFirstPlayedShouldSaveIt_data(); 0150 void commitAfterSettingFirstPlayedShouldSaveIt(); 0151 void commitAfterSettingLastPlayedShouldSaveIt_data(); 0152 void commitAfterSettingLastPlayedShouldSaveIt(); 0153 void commitAfterSettingRatingShouldSaveIt_data(); 0154 void commitAfterSettingRatingShouldSaveIt(); 0155 void commitAfterSettingPlaycountShouldSaveIt_data(); 0156 void commitAfterSettingPlaycountShouldSaveIt(); 0157 void commitAfterSettingLabelsShouldSaveThem_data(); 0158 void commitAfterSettingLabelsShouldSaveThem(); 0159 }; 0160 0161 #endif // TEST_IMPORTER_BASE