File indexing completed on 2024-05-12 04:49:41
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 "TestMetaTrack.h" 0021 0022 #include "amarokconfig.h" 0023 #include "config-amarok-test.h" 0024 #include "core/meta/Meta.h" 0025 #include "core/meta/Statistics.h" 0026 #include "core-impl/collections/support/CollectionManager.h" 0027 0028 #include <QTest> 0029 0030 0031 QTEST_GUILESS_MAIN( TestMetaTrack ) 0032 0033 TestMetaTrack::TestMetaTrack() 0034 : m_trackPath( dataPath( "/data/audio/Platz 01.mp3" ) ) 0035 {} 0036 0037 TestMetaTrack::~TestMetaTrack() 0038 { 0039 } 0040 0041 QString 0042 TestMetaTrack::dataPath( const QString &relPath ) 0043 { 0044 return QDir::toNativeSeparators( QString( AMAROK_TEST_DIR ) + '/' + relPath ); 0045 } 0046 0047 void TestMetaTrack::initTestCase() 0048 { 0049 AmarokConfig::instance("amarokrc"); 0050 0051 QString oldPath = m_trackPath; 0052 m_trackPath = m_tempDir.path() + "TestMetaTrack-testTrack.mp3"; 0053 QVERIFY( QFile::copy( oldPath, m_trackPath ) ); 0054 0055 m_testTrack1 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(m_trackPath) ); 0056 0057 // If the pointer is 0, it makes no sense to continue. We would crash with a qFatal(). 0058 QVERIFY2( m_testTrack1, "The pointer to the test track is 0." ); 0059 0060 // we need to enable this, otherwise testSetAndGetScore, testSetAndGetRating fails 0061 AmarokConfig::setWriteBackStatistics( true ); 0062 } 0063 0064 void TestMetaTrack::testPrettyName() 0065 { 0066 QCOMPARE( m_testTrack1->prettyName(), QString( "Platz 01" ) ); 0067 } 0068 0069 void TestMetaTrack::testPlayableUrl() 0070 { 0071 QCOMPARE( m_testTrack1->playableUrl().path(), m_trackPath ); 0072 } 0073 0074 void TestMetaTrack::testPrettyUrl() 0075 { 0076 QCOMPARE( m_testTrack1->prettyUrl(), m_trackPath ); 0077 } 0078 0079 void TestMetaTrack::testUidUrl() 0080 { 0081 QCOMPARE( m_testTrack1->uidUrl(), QUrl::fromLocalFile(m_trackPath ).url() ); 0082 } 0083 0084 void TestMetaTrack::testIsPlayable() 0085 { 0086 QCOMPARE( m_testTrack1->isPlayable(), true ); 0087 } 0088 0089 void TestMetaTrack::testAlbum() 0090 { 0091 QCOMPARE( m_testTrack1->album()->name() , QString( "" ) ); 0092 } 0093 0094 void TestMetaTrack::testArtist() 0095 { 0096 QCOMPARE( m_testTrack1->artist()->name(), QString( "Free Music Charts" ) ); 0097 } 0098 0099 void TestMetaTrack::testComposer() 0100 { 0101 QCOMPARE( m_testTrack1->composer()->name(), QString( "" ) ); 0102 } 0103 0104 void TestMetaTrack::testGenre() 0105 { 0106 QCOMPARE( m_testTrack1->genre()->name(), QString( "Vocal" ) ); 0107 } 0108 0109 void TestMetaTrack::testYear() 0110 { 0111 QCOMPARE( m_testTrack1->year()->name(), QString( "2010" ) ); 0112 } 0113 0114 void TestMetaTrack::testComment() 0115 { 0116 QCOMPARE( m_testTrack1->comment(), QString( "" ) ); 0117 } 0118 0119 void TestMetaTrack::testSetAndGetScore() 0120 { 0121 Meta::StatisticsPtr statistics = m_testTrack1->statistics(); 0122 QCOMPARE( statistics->score(), 0.0 ); 0123 0124 /* now the code actually stores the score in track and then it reads it back. 0125 * the precision it uses is pretty low and it was failing the qFuzzyCompare<double> 0126 * Just make it use qFuzzyCompare<float>() */ 0127 0128 statistics->setScore( 3 ); 0129 QCOMPARE( float( statistics->score() ), float( 3.0 ) ); 0130 0131 statistics->setScore( 12.55 ); 0132 QCOMPARE( float( statistics->score() ), float( 12.55 ) ); 0133 0134 statistics->setScore( 100 ); 0135 QCOMPARE( float( statistics->score() ), float( 100.0 ) ); 0136 0137 statistics->setScore( 0 ); 0138 QCOMPARE( float( statistics->score() ), float( 0.0 ) ); 0139 } 0140 0141 void TestMetaTrack::testSetAndGetRating() 0142 { 0143 Meta::StatisticsPtr statistics = m_testTrack1->statistics(); 0144 QCOMPARE( statistics->rating(), 0 ); 0145 0146 statistics->setRating( 3 ); 0147 QCOMPARE( statistics->rating(), 3 ); 0148 0149 statistics->setRating( 10 ); 0150 QCOMPARE( statistics->rating(), 10 ); 0151 0152 statistics->setRating( 0 ); 0153 QCOMPARE( statistics->rating(), 0 ); 0154 } 0155 0156 void TestMetaTrack::testLength() 0157 { 0158 QCOMPARE( m_testTrack1->length(), 12000LL ); 0159 } 0160 0161 void TestMetaTrack::testFilesize() 0162 { 0163 QCOMPARE( m_testTrack1->filesize(), 389454 ); 0164 } 0165 0166 void TestMetaTrack::testSampleRate() 0167 { 0168 QCOMPARE( m_testTrack1->sampleRate(), 44100 ); 0169 } 0170 0171 void TestMetaTrack::testBitrate() 0172 { 0173 QCOMPARE( m_testTrack1->bitrate(), 257 ); 0174 } 0175 0176 void TestMetaTrack::testTrackNumber() 0177 { 0178 QCOMPARE( m_testTrack1->trackNumber(), 0 ); 0179 } 0180 0181 void TestMetaTrack::testDiscNumber() 0182 { 0183 QCOMPARE( m_testTrack1->discNumber(), 0 ); 0184 } 0185 0186 void TestMetaTrack::testLastPlayed() 0187 { 0188 QCOMPARE( m_testTrack1->statistics()->lastPlayed().toSecsSinceEpoch(), 4294967295U ); // portability? 0189 } 0190 0191 void TestMetaTrack::testFirstPlayed() 0192 { 0193 QCOMPARE( m_testTrack1->statistics()->firstPlayed().toSecsSinceEpoch(), 4294967295U ); // portability? 0194 } 0195 0196 void TestMetaTrack::testPlayCount() 0197 { 0198 QCOMPARE( m_testTrack1->statistics()->playCount(), 0 ); 0199 } 0200 0201 void TestMetaTrack::testReplayGain() 0202 { 0203 QCOMPARE( int(m_testTrack1->replayGain( Meta::ReplayGain_Track_Gain ) * 1000), -6655 ); 0204 QCOMPARE( int(m_testTrack1->replayGain( Meta::ReplayGain_Album_Gain ) * 1000), -6655 ); 0205 QCOMPARE( int(m_testTrack1->replayGain( Meta::ReplayGain_Track_Peak ) * 10000), 41263 ); 0206 QCOMPARE( int(m_testTrack1->replayGain( Meta::ReplayGain_Album_Peak ) * 10000), 41263 ); 0207 } 0208 0209 void TestMetaTrack::testType() 0210 { 0211 QCOMPARE( m_testTrack1->type(), QString( "mp3" ) ); 0212 } 0213 0214 void TestMetaTrack::testInCollection() 0215 { 0216 QVERIFY( !m_testTrack1->inCollection() ); 0217 } 0218 0219 void TestMetaTrack::testCollection() 0220 { 0221 QVERIFY( !m_testTrack1->collection() ); 0222 } 0223 0224 void TestMetaTrack::testSetAndGetCachedLyrics() 0225 { 0226 /* TODO: setCachedLyrics is not yet implemented 0227 QCOMPARE( m_testTrack1->cachedLyrics(), QString( "" ) ); 0228 0229 m_testTrack1->setCachedLyrics( "test" ); 0230 QCOMPARE( m_testTrack1->cachedLyrics(), QString( "test" ) ); 0231 0232 m_testTrack1->setCachedLyrics( "aäaüoöß" ); 0233 QCOMPARE( m_testTrack1->cachedLyrics(), QString( "aäaüoöß" ) ); 0234 0235 m_testTrack1->setCachedLyrics( "" ); 0236 QCOMPARE( m_testTrack1->cachedLyrics(), QString( "" ) ); 0237 */ 0238 } 0239 0240 void TestMetaTrack::testOperatorEquals() 0241 { 0242 QVERIFY( m_testTrack1 == m_testTrack1 ); 0243 QVERIFY( m_testTrack1 != m_testTrack2 ); 0244 } 0245 0246 void TestMetaTrack::testLessThan() 0247 { 0248 Meta::TrackPtr albumTrack1, albumTrack2, albumTrack3; 0249 0250 albumTrack1 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(dataPath( "data/audio/album/Track01.ogg" )) ); 0251 albumTrack2 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(dataPath( "data/audio/album/Track02.ogg" )) ); 0252 albumTrack3 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(dataPath( "data/audio/album/Track03.ogg" )) ); 0253 0254 QVERIFY( albumTrack1 ); 0255 QVERIFY( albumTrack2 ); 0256 QVERIFY( albumTrack3 ); 0257 0258 QVERIFY( !Meta::Track::lessThan( m_testTrack1, m_testTrack1 ) ); 0259 0260 QVERIFY( Meta::Track::lessThan( albumTrack1, albumTrack2 ) ); 0261 QVERIFY( Meta::Track::lessThan( albumTrack2, albumTrack3 ) ); 0262 QVERIFY( Meta::Track::lessThan( albumTrack1, albumTrack3 ) ); 0263 QVERIFY( !Meta::Track::lessThan( albumTrack3, albumTrack2 ) ); 0264 QVERIFY( !Meta::Track::lessThan( albumTrack3, albumTrack1 ) ); 0265 QVERIFY( !Meta::Track::lessThan( albumTrack3, albumTrack3 ) ); 0266 }