File indexing completed on 2024-11-10 04:22:08
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.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 "TestSqlTrack.h" 0018 0019 #include "amarokconfig.h" 0020 #include "DefaultSqlQueryMakerFactory.h" 0021 #include "core/meta/Meta.h" 0022 #include "core-impl/storage/sql/mysqlestorage/MySqlEmbeddedStorage.h" 0023 0024 #include "SqlCollection.h" 0025 #include "SqlMeta.h" 0026 #include "SqlRegistry.h" 0027 #include "SqlMountPointManagerMock.h" 0028 0029 #include "MetaNotificationSpy.h" 0030 0031 #include <QDateTime> 0032 #include <QSignalSpy> 0033 0034 0035 QTEST_GUILESS_MAIN( TestSqlTrack ) 0036 0037 TestSqlTrack::TestSqlTrack() 0038 : QObject() 0039 , m_collection( nullptr ) 0040 , m_storage( nullptr ) 0041 , m_tmpDir( nullptr ) 0042 { 0043 } 0044 0045 void 0046 TestSqlTrack::initTestCase() 0047 { 0048 AmarokConfig::instance("amarokrc"); 0049 0050 m_tmpDir = new QTemporaryDir(); 0051 m_storage = QSharedPointer<MySqlEmbeddedStorage>( new MySqlEmbeddedStorage() ); 0052 QVERIFY( m_storage->init( m_tmpDir->path() ) ); 0053 m_collection = new Collections::SqlCollection( m_storage ); 0054 m_collection->setMountPointManager( new SqlMountPointManagerMock( this, m_storage ) ); 0055 0056 // I just need the table and not the whole playlist manager 0057 m_storage->query( QString( "CREATE TABLE playlist_tracks (" 0058 " id " + m_storage->idType() + 0059 ", playlist_id INTEGER " 0060 ", track_num INTEGER " 0061 ", url " + m_storage->exactTextColumnType() + 0062 ", title " + m_storage->textColumnType() + 0063 ", album " + m_storage->textColumnType() + 0064 ", artist " + m_storage->textColumnType() + 0065 ", length INTEGER " 0066 ", uniqueid " + m_storage->textColumnType(128) + ") ENGINE = MyISAM;" ) ); 0067 0068 } 0069 0070 void 0071 TestSqlTrack::cleanupTestCase() 0072 { 0073 delete m_collection; 0074 //m_storage is deleted by SqlCollection 0075 delete m_tmpDir; 0076 } 0077 0078 void 0079 TestSqlTrack::init() 0080 { 0081 //setup base data 0082 m_storage->query( "INSERT INTO artists(id, name) VALUES (1, 'artist1');" ); 0083 m_storage->query( "INSERT INTO artists(id, name) VALUES (2, 'artist2');" ); 0084 m_storage->query( "INSERT INTO artists(id, name) VALUES (3, 'artist3');" ); 0085 0086 m_storage->query( "INSERT INTO albums(id,name,artist) VALUES(1,'album1',1);" ); 0087 m_storage->query( "INSERT INTO albums(id,name,artist) VALUES(2,'album2',1);" ); 0088 m_storage->query( "INSERT INTO albums(id,name,artist) VALUES(3,'album3',2);" ); 0089 m_storage->query( "INSERT INTO albums(id,name,artist) VALUES(4,'album-compilation',0);" ); 0090 0091 m_storage->query( "INSERT INTO composers(id, name) VALUES (1, 'composer1');" ); 0092 m_storage->query( "INSERT INTO composers(id, name) VALUES (2, 'composer2');" ); 0093 m_storage->query( "INSERT INTO composers(id, name) VALUES (3, 'composer3');" ); 0094 0095 m_storage->query( "INSERT INTO genres(id, name) VALUES (1, 'genre1');" ); 0096 m_storage->query( "INSERT INTO genres(id, name) VALUES (2, 'genre2');" ); 0097 m_storage->query( "INSERT INTO genres(id, name) VALUES (3, 'genre3');" ); 0098 0099 m_storage->query( "INSERT INTO years(id, name) VALUES (1, '1');" ); 0100 m_storage->query( "INSERT INTO years(id, name) VALUES (2, '2');" ); 0101 m_storage->query( "INSERT INTO years(id, name) VALUES (3, '3');" ); 0102 0103 m_storage->query( "INSERT INTO directories(id, deviceid, dir) VALUES (1, -1, './');" ); 0104 0105 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, directory, uniqueid) VALUES (1, -1, './IDoNotExist.mp3', 1, '1');" ); 0106 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, directory, uniqueid) VALUES (2, -1, './IDoNotExistAsWell.mp3', 1, '2');" ); 0107 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, directory, uniqueid) VALUES (3, -1, './MeNeither.mp3', 1, '3');" ); 0108 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, directory, uniqueid) VALUES (4, -1, './NothingHere.mp3', 1, '4');" ); 0109 0110 m_storage->query( "INSERT INTO tracks(id,url,title,comment,artist,album,genre,year,composer) " 0111 "VALUES(1,1,'track1','comment1',1,1,1,1,1);" ); 0112 m_storage->query( "INSERT INTO tracks(id,url,title,comment,artist,album,genre,year,composer) " 0113 "VALUES(2,2,'track2','comment2',1,2,1,1,1);" ); 0114 0115 m_collection->registry()->emptyCache(); 0116 } 0117 0118 void 0119 TestSqlTrack::cleanup() 0120 { 0121 m_storage->query( "TRUNCATE TABLE years;" ); 0122 m_storage->query( "TRUNCATE TABLE genres;" ); 0123 m_storage->query( "TRUNCATE TABLE composers;" ); 0124 m_storage->query( "TRUNCATE TABLE albums;" ); 0125 m_storage->query( "TRUNCATE TABLE artists;" ); 0126 m_storage->query( "TRUNCATE TABLE tracks;" ); 0127 m_storage->query( "TRUNCATE TABLE urls;" ); 0128 m_storage->query( "TRUNCATE TABLE directories;" ); 0129 m_storage->query( "TRUNCATE TABLE statistics;" ); 0130 m_storage->query( "TRUNCATE TABLE labels;" ); 0131 m_storage->query( "TRUNCATE TABLE urls_labels;" ); 0132 } 0133 0134 0135 void 0136 TestSqlTrack::setAllValues( Meta::SqlTrack *track ) 0137 { 0138 track->setTitle( "New Title" ); 0139 track->setAlbum( "New Album" ); 0140 track->setArtist( "New Artist" ); 0141 track->setComposer( "New Composer" ); 0142 track->setYear( 1999 ); 0143 track->setGenre( "New Genre" ); 0144 0145 track->setUrl( -1, "./new_url", 2 ); 0146 0147 track->setBpm( 32.0 ); 0148 track->setComment( "New Comment" ); 0149 0150 track->setScore( 64.0 ); 0151 track->setRating( 5 ); 0152 0153 track->setLength( 5000 ); 0154 track->setSampleRate( 4400 ); 0155 track->setBitrate( 128 ); 0156 0157 track->setTrackNumber( 4 ); 0158 track->setDiscNumber( 1 ); 0159 0160 track->setFirstPlayed( QDateTime::fromSecsSinceEpoch(100) ); 0161 track->setLastPlayed( QDateTime::fromSecsSinceEpoch(200) ); 0162 track->setPlayCount( 20 ); 0163 0164 Meta::ReplayGainTag modes[] = { Meta::ReplayGain_Track_Gain, 0165 Meta::ReplayGain_Track_Peak, 0166 Meta::ReplayGain_Album_Gain, 0167 Meta::ReplayGain_Album_Peak }; 0168 0169 for( int i=0; i<4; i++ ) 0170 track->setReplayGain( modes[i], qreal(i) ); 0171 0172 track->addLabel( "New Label" ); 0173 } 0174 0175 void 0176 TestSqlTrack::getAllValues( Meta::SqlTrack *track ) 0177 { 0178 QCOMPARE( track->name(), QString( "New Title" ) ); 0179 QCOMPARE( track->album()->name(), QString( "New Album" ) ); 0180 QCOMPARE( track->artist()->name(), QString( "New Artist" ) ); 0181 QCOMPARE( track->composer()->name(), QString( "New Composer" ) ); 0182 QCOMPARE( track->year()->name(), QString( "1999" ) ); 0183 QCOMPARE( track->genre()->name(), QString( "New Genre" ) ); 0184 0185 QCOMPARE( track->playableUrl().path(), QString( "/new_url" ) ); 0186 QCOMPARE( track->bpm(), 32.0 ); 0187 QCOMPARE( track->comment(), QString( "New Comment" ) ); 0188 0189 QCOMPARE( track->score(), 64.0 ); 0190 QCOMPARE( track->rating(), 5 ); 0191 0192 QCOMPARE( track->length(), qint64(5000) ); 0193 QCOMPARE( track->sampleRate(), 4400 ); 0194 QCOMPARE( track->bitrate(), 128 ); 0195 0196 QCOMPARE( track->trackNumber(), 4 ); 0197 QCOMPARE( track->discNumber(), 1 ); 0198 0199 QCOMPARE( track->firstPlayed(), QDateTime::fromSecsSinceEpoch(100) ); 0200 QCOMPARE( track->lastPlayed(), QDateTime::fromSecsSinceEpoch(200) ); 0201 QCOMPARE( track->playCount(), 20 ); 0202 0203 Meta::ReplayGainTag modes[] = { Meta::ReplayGain_Track_Gain, 0204 Meta::ReplayGain_Track_Peak, 0205 Meta::ReplayGain_Album_Gain, 0206 Meta::ReplayGain_Album_Peak }; 0207 0208 for( int i=0; i<4; i++ ) 0209 QCOMPARE( track->replayGain( modes[i] ), qreal(i) ); 0210 0211 QVERIFY( track->labels().count() > 0 ); 0212 QVERIFY( track->labels().contains( m_collection->registry()->getLabel("New Label") ) ); 0213 } 0214 0215 /** Check that the registry always returns the same track pointer */ 0216 void 0217 TestSqlTrack::testGetTrack() 0218 { 0219 { 0220 Meta::TrackPtr track1 = m_collection->registry()->getTrack( 1 ); 0221 Meta::TrackPtr track2 = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0222 Meta::TrackPtr track3 = m_collection->registry()->getTrackFromUid( "1" ); 0223 0224 QVERIFY( track1 ); 0225 QVERIFY( track1 == track2 ); 0226 QVERIFY( track1 == track3 ); 0227 } 0228 0229 // and also after empty cache 0230 m_collection->registry()->emptyCache(); 0231 0232 // changed order... 0233 { 0234 Meta::TrackPtr track2 = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0235 Meta::TrackPtr track3 = m_collection->registry()->getTrackFromUid( "1" ); 0236 Meta::TrackPtr track1 = m_collection->registry()->getTrack( 1 ); 0237 0238 QVERIFY( track1 ); 0239 QVERIFY( track1 == track2 ); 0240 QVERIFY( track1 == track3 ); 0241 } 0242 0243 // do again creating a new track 0244 cleanup(); 0245 m_collection->registry()->emptyCache(); 0246 0247 // changed order... 0248 { 0249 Meta::TrackPtr track1 = m_collection->registry()->getTrack( -1, "./newTrack.mp3", 2, "amarok-sqltrackuid://newuid" ); 0250 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0251 sqlTrack1->setBpm( 100 ); // have to commit the new track 0252 0253 QVERIFY( track1 ); 0254 QCOMPARE( track1->playableUrl().path(), QString("/newTrack.mp3" )); 0255 QCOMPARE( track1->uidUrl(), QString("amarok-sqltrackuid://newuid" )); 0256 } 0257 0258 m_collection->registry()->emptyCache(); 0259 0260 // changed order... 0261 { 0262 Meta::TrackPtr track1 = m_collection->registry()->getTrackFromUid("amarok-sqltrackuid://newuid"); 0263 0264 QVERIFY( track1 ); 0265 QCOMPARE( track1->playableUrl().path(), QString("/newTrack.mp3" )); 0266 QCOMPARE( track1->uidUrl(), QString("amarok-sqltrackuid://newuid" )); 0267 QCOMPARE( track1->bpm(), 100.0 ); 0268 } 0269 } 0270 0271 void 0272 TestSqlTrack::testSetAllValuesSingleNotExisting() 0273 { 0274 { 0275 // get a new track 0276 Meta::TrackPtr track1 = m_collection->registry()->getTrack( -1, "./IamANewTrack.mp3", 1, "1e34fb213489" ); 0277 0278 QSignalSpy spy( m_collection, &Collections::SqlCollection::updated); 0279 MetaNotificationSpy metaSpy; 0280 metaSpy.subscribeTo( track1 ); 0281 0282 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0283 setAllValues( sqlTrack1 ); 0284 getAllValues( sqlTrack1 ); 0285 0286 // new track should have an up-to-date create time (not more than 3 seconds old) 0287 QVERIFY( track1->createDate().secsTo(QDateTime::currentDateTime()) < 3 ); 0288 0289 QVERIFY( metaSpy.notificationsFromTracks().count() > 1 ); // we should be notified about the changes 0290 } 0291 0292 // and also after empty cache 0293 m_collection->registry()->emptyCache(); 0294 0295 { 0296 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/new_url" ); 0297 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0298 QVERIFY( track1 ); 0299 getAllValues( sqlTrack1 ); 0300 } 0301 } 0302 0303 /** Set all track values but before that create them in the registry. */ 0304 void 0305 TestSqlTrack::testSetAllValuesSingleExisting() 0306 { 0307 { 0308 Meta::GenrePtr genre = m_collection->registry()->getGenre( "New Genre" ); 0309 Meta::ComposerPtr composer = m_collection->registry()->getComposer( "New Composer" ); 0310 Meta::YearPtr year = m_collection->registry()->getYear( 1999 ); 0311 Meta::AlbumPtr album = m_collection->registry()->getAlbum( "New Album", "New Artist" ); 0312 m_collection->registry()->getLabel( "New Label" ); 0313 0314 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0315 0316 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0317 setAllValues( sqlTrack1 ); 0318 getAllValues( sqlTrack1 ); 0319 0320 // check that the existing object are really updated with the new tracklist 0321 QCOMPARE( genre->tracks().count(), 1 ); 0322 QCOMPARE( genre->tracks().first().data(), track1.data() ); 0323 0324 QCOMPARE( composer->tracks().count(), 1 ); 0325 QCOMPARE( composer->tracks().first().data(), track1.data() ); 0326 0327 QCOMPARE( year->tracks().count(), 1 ); 0328 QCOMPARE( year->tracks().first().data(), track1.data() ); 0329 0330 // the logic, how renaming the track artist influences its album is still 0331 // unfinished. For sure the track must be in an album with the defined 0332 // name 0333 QCOMPARE( sqlTrack1->album()->name(), QString("New Album") ); 0334 QCOMPARE( sqlTrack1->album()->tracks().count(), 1 ); 0335 QCOMPARE( sqlTrack1->album()->tracks().first().data(), track1.data() ); 0336 } 0337 0338 // and also after empty cache 0339 m_collection->registry()->emptyCache(); 0340 0341 { 0342 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/new_url" ); 0343 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0344 QVERIFY( track1 ); 0345 getAllValues( sqlTrack1 ); 0346 0347 Meta::GenrePtr genre = m_collection->registry()->getGenre( "New Genre" ); 0348 Meta::ComposerPtr composer = m_collection->registry()->getComposer( "New Composer" ); 0349 Meta::YearPtr year = m_collection->registry()->getYear( 1999 ); 0350 Meta::AlbumPtr album = m_collection->registry()->getAlbum( "New Album", "New Artist" ); 0351 0352 // check that the existing object are really updated with the new tracklist 0353 QCOMPARE( genre->tracks().count(), 1 ); 0354 QCOMPARE( genre->tracks().first().data(), track1.data() ); 0355 0356 QCOMPARE( composer->tracks().count(), 1 ); 0357 QCOMPARE( composer->tracks().first().data(), track1.data() ); 0358 0359 QCOMPARE( year->tracks().count(), 1 ); 0360 QCOMPARE( year->tracks().first().data(), track1.data() ); 0361 0362 // the logic, how renaming the track artist influences its album is still 0363 // unfinished. For sure the track must be in an album with the defined 0364 // name 0365 QCOMPARE( sqlTrack1->album()->name(), QString("New Album") ); 0366 QCOMPARE( sqlTrack1->album()->tracks().count(), 1 ); 0367 QCOMPARE( sqlTrack1->album()->tracks().first().data(), track1.data() ); 0368 } 0369 } 0370 0371 void 0372 TestSqlTrack::testSetAllValuesBatch() 0373 { 0374 { 0375 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0376 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0377 0378 QSignalSpy spy( m_collection, &Collections::SqlCollection::updated); 0379 MetaNotificationSpy metaSpy; 0380 metaSpy.subscribeTo( track1 ); 0381 0382 sqlTrack1->beginUpdate(); 0383 0384 setAllValues( sqlTrack1 ); 0385 QCOMPARE( metaSpy.notificationsFromTracks().count(), 1 ); // add label does one notify 0386 0387 sqlTrack1->endUpdate(); 0388 QCOMPARE( metaSpy.notificationsFromTracks().count(), 2 ); // only one notificate for all the changes 0389 0390 getAllValues( sqlTrack1 ); 0391 } 0392 0393 // and also after empty cache 0394 m_collection->registry()->emptyCache(); 0395 0396 { 0397 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/new_url" ); 0398 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0399 QVERIFY( track1 ); 0400 getAllValues( sqlTrack1 ); 0401 } 0402 } 0403 0404 void 0405 TestSqlTrack::testUnsetValues() 0406 { 0407 { 0408 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0409 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0410 0411 setAllValues( sqlTrack1 ); 0412 0413 // now unset the values again 0414 sqlTrack1->setAlbum( "" ); 0415 sqlTrack1->setArtist( "" ); 0416 sqlTrack1->setComposer( "" ); 0417 sqlTrack1->setYear( 0 ); // it is not clear what an empty year exactly is 0418 sqlTrack1->setGenre( "" ); 0419 0420 // note: Amarok is still not clear if an empty artist means track->artist() == 0 0421 QVERIFY( !track1->album() || track1->album()->name().isEmpty() ); 0422 QVERIFY( !track1->artist() || track1->artist()->name().isEmpty() ); 0423 QVERIFY( !track1->composer() || track1->composer()->name().isEmpty() ); 0424 QVERIFY( !track1->year() || track1->year()->year() == 0 ); 0425 QVERIFY( !track1->genre() || track1->genre()->name().isEmpty() ); 0426 } 0427 0428 // and also after empty cache 0429 m_collection->registry()->emptyCache(); 0430 0431 { 0432 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/new_url" ); 0433 QVERIFY( track1 ); 0434 QVERIFY( !track1->album() || track1->album()->name().isEmpty() ); 0435 QVERIFY( !track1->artist() || track1->artist()->name().isEmpty() ); 0436 QVERIFY( !track1->composer() || track1->composer()->name().isEmpty() ); 0437 QVERIFY( !track1->year() || track1->year()->year() == 0 ); 0438 QVERIFY( !track1->genre() || track1->genre()->name().isEmpty() ); 0439 } 0440 } 0441 0442 void 0443 TestSqlTrack::testFinishedPlaying() 0444 { 0445 Meta::TrackPtr track1 = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0446 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0447 0448 sqlTrack1->setLength( 5000 ); 0449 0450 QCOMPARE( sqlTrack1->score(), 0.0 ); 0451 QCOMPARE( sqlTrack1->playCount(), 0 ); 0452 QVERIFY( !sqlTrack1->firstPlayed().isValid() ); 0453 QVERIFY( !sqlTrack1->lastPlayed().isValid() ); 0454 0455 // now play the track not really 0456 sqlTrack1->finishedPlaying( 0.1 ); 0457 0458 // can't do a statement about the score here 0459 QCOMPARE( sqlTrack1->playCount(), 0 ); 0460 QVERIFY( !sqlTrack1->firstPlayed().isValid() ); 0461 QVERIFY( !sqlTrack1->lastPlayed().isValid() ); 0462 0463 // and now really play it 0464 sqlTrack1->finishedPlaying( 1.0 ); 0465 0466 QVERIFY( sqlTrack1->score() > 0.0 ); 0467 QCOMPARE( sqlTrack1->playCount(), 1 ); 0468 QVERIFY( sqlTrack1->firstPlayed().secsTo( QDateTime::currentDateTime() ) < 2 ); 0469 QVERIFY( sqlTrack1->lastPlayed().secsTo( QDateTime::currentDateTime() ) < 2 ); 0470 } 0471 0472 0473 void 0474 TestSqlTrack::testAlbumRemaingsNonCompilationAfterChangingAlbumName() 0475 { 0476 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) " 0477 "VALUES (3,3,'track1',1,1,1,1,1 );" ); 0478 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) " 0479 "VALUES (4,4,'track2',1,1,1,1,1 );" ); 0480 0481 Meta::TrackPtr track1 = m_collection->registry()->getTrack( 3 ); 0482 Meta::TrackPtr track2 = m_collection->registry()->getTrack( 4 ); 0483 0484 QCOMPARE( track1->album()->name(), QString( "album1" ) ); 0485 QVERIFY( track1->album()->hasAlbumArtist() ); 0486 QCOMPARE( track1->album().data(), track2->album().data() ); 0487 0488 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0489 sqlTrack1->setAlbum( "album2" ); 0490 Meta::SqlTrack *sqlTrack2 = static_cast<Meta::SqlTrack*>( track2.data() ); 0491 sqlTrack2->beginUpdate(); 0492 sqlTrack2->setAlbum( "album2" ); 0493 sqlTrack2->endUpdate(); 0494 0495 QCOMPARE( track1->album()->name(), QString( "album2" ) ); 0496 QVERIFY( track1->album()->hasAlbumArtist() ); 0497 QVERIFY( track1->album() == track2->album() ); 0498 } 0499 0500 void 0501 TestSqlTrack::testAlbumRemainsCompilationAfterChangingAlbumName() 0502 { 0503 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) " 0504 "VALUES (3,3,'track1',1,4,1,1,1 );" ); 0505 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) " 0506 "VALUES (4,4,'track2',1,4,1,1,1 );" ); 0507 0508 Meta::TrackPtr track1 = m_collection->registry()->getTrack( 3 ); 0509 Meta::TrackPtr track2 = m_collection->registry()->getTrack( 4 ); 0510 0511 QVERIFY( track1 ); 0512 QVERIFY( track1->album() ); 0513 QVERIFY( track2 ); 0514 QVERIFY( track2->album() ); 0515 QCOMPARE( track1->album()->name(), QString( "album-compilation" ) ); 0516 QVERIFY( track1->album()->isCompilation() ); 0517 QVERIFY( track1->album().data() == track2->album().data() ); 0518 0519 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() ); 0520 Meta::SqlTrack *sqlTrack2 = static_cast<Meta::SqlTrack*>( track2.data() ); 0521 sqlTrack1->setAlbum( "album2" ); 0522 sqlTrack2->beginUpdate(); 0523 sqlTrack2->setAlbum( "album2" ); 0524 sqlTrack2->endUpdate(); 0525 0526 QCOMPARE( track1->album()->name(), QString( "album2" ) ); 0527 QVERIFY( track1->album()->isCompilation() ); 0528 QVERIFY( track1->album() == track2->album() ); 0529 } 0530 0531 void 0532 TestSqlTrack::testRemoveLabelFromTrack() 0533 { 0534 Meta::TrackPtr track = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0535 Meta::LabelPtr label = m_collection->registry()->getLabel( "A" ); 0536 track->addLabel( label ); 0537 QCOMPARE( track->labels().count(), 1 ); 0538 0539 track->removeLabel( label ); 0540 QCOMPARE( track->labels().count(), 0 ); 0541 0542 QStringList urlsLabelsCount = m_storage->query( "SELECT COUNT(*) FROM urls_labels;" ); 0543 QCOMPARE( urlsLabelsCount.first().toInt(), 0 ); 0544 } 0545 0546 void 0547 TestSqlTrack::testRemoveLabelFromTrackWhenNotInCache() 0548 { 0549 m_storage->query( "INSERT INTO labels(id,label) VALUES (1,'A');" ); 0550 m_storage->query( "INSERT INTO urls_labels(url,label) VALUES (1,1);" ); 0551 0552 Meta::TrackPtr track = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); 0553 Meta::LabelPtr label = m_collection->registry()->getLabel( "A" ); 0554 0555 track->removeLabel( label ); 0556 QCOMPARE( track->labels().count(), 0 ); 0557 0558 QStringList urlsLabelsCount = m_storage->query( "SELECT COUNT(*) FROM urls_labels;" ); 0559 QCOMPARE( urlsLabelsCount.first().toInt(), 0 ); 0560 } 0561