Commit b1dacf0c75b67178fd0bb3ca9b60f20f02bd3967

fixed bug where compilations were changed to normal albums (one per each track artist) when renaming them.
Now albums keep their compilation/non-compilation status when renaming them.

BR: 192029
ChangeLog
(1 / 0)
  
1818 last check.
1919
2020 BUGFIXES:
21 * Compilations do not become normal albums when renaming them. (BR 192029)
2122 * Fixed a bug where there would be no dynamic playlist biases available
2223 with a clean startup. (BR 227797)
2324 * Fixed a crash when pressing dynamic playlist "save" button on first startup. (BR 227073)
  
429429 else
430430 {
431431 KSharedPtr<SqlAlbum>::staticCast( m_album )->invalidateCache();
432 int id = -1;
433 SqlArtist *artist = dynamic_cast<SqlArtist*>(m_artist.data());
434 if( artist )
435 id = artist->id();
432 //the album should remain a compilation after renaming it
433 int id = 0;
434 if( m_album->hasAlbumArtist() )
435 {
436 SqlArtist *artist = dynamic_cast<SqlArtist*>(m_album->albumArtist().data());
437 if( artist )
438 id = artist->id();
439 }
436440 m_album = m_collection->registry()->getAlbum( newAlbum, -1, id );
437441 KSharedPtr<SqlAlbum>::staticCast( m_album )->invalidateCache();
438442 m_cache.clear();
683683 if( m_cache.contains( Meta::Field::ALBUM ) )
684684 {
685685 KSharedPtr<SqlAlbum>::staticCast( m_album )->invalidateCache();
686 int artistId = KSharedPtr<SqlArtist>::staticCast( m_artist )->id();
686 int artistId = 0;
687 if( m_album->hasAlbumArtist() )
688 {
689 artistId = KSharedPtr<SqlArtist>::staticCast( m_album->albumArtist() )->id();
690 }
687691 m_album = m_collection->registry()->getAlbum( m_cache.value( Meta::Field::ALBUM ).toString(), -1, artistId );
688692 KSharedPtr<SqlAlbum>::staticCast( m_album )->invalidateCache();
689693 }
  
191191 ${QT_QTTEST_LIBRARY}
192192 ${QT_QTCORE_LIBRARY}
193193 ${KDE4_KDECORE_LIBS})
194
195#-------------------------------- Test SqlTrack -----------------------
196
197set( testsqltrack_SRCS
198 TestSqlTrack.cpp
199 ${AMAROK_SOURCE_TREE}/meta/MetaUtility.cpp
200 ${AMAROK_SOURCE_TREE}/Amarok.cpp
201 ${AMAROK_SOURCE_TREE}/meta/PlaylistFileSupport.cpp
202 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/mysql-shared/MySqlStorage.cpp
203 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/mysqlecollection/MySqlEmbeddedStorage.cpp
204 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/SqlCollection.cpp
205 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/SqlMeta.cpp
206 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/SqlRegistry.cpp
207 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/DatabaseUpdater.cpp
208 ${AMAROK_SOURCE_TREE}/collection/sqlcollection/ArtistHelper.cpp
209 ${AMAROK_SOURCE_TREE}/meta/Meta.cpp
210 ${AMAROK_SOURCE_TREE}/collection/Collection.cpp
211 ${AMAROK_TEST_TREE}/mocks/AftUtilityMock.cpp
212 )
213
214
215kde4_add_unit_test( testsqltrack ${testsqltrack_SRCS} )
216
217link_database_test( testsqltrack )
  
1/****************************************************************************************
2 * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17#include "TestSqlTrack.h"
18
19
20#include "DatabaseUpdater.h"
21#include "Debug.h"
22#include "DefaultSqlQueryMakerFactory.h"
23#include "meta/Meta.h"
24#include "mysqlecollection/MySqlEmbeddedStorage.h"
25#include "SqlCollection.h"
26#include "SqlRegistry.h"
27#include "SqlMountPointManagerMock.h"
28
29#include <qtest_kde.h>
30
31QTEST_KDEMAIN_CORE( TestSqlTrack )
32
33TestSqlTrack::TestSqlTrack()
34 : QObject()
35 , m_collection( 0 )
36 , m_storage( 0 )
37 , m_tmpDir( 0 )
38 , m_registry( 0 )
39{
40}
41
42void
43TestSqlTrack::initTestCase()
44{
45 m_tmpDir = new KTempDir();
46 m_storage = new MySqlEmbeddedStorage( m_tmpDir->name() );
47 m_collection = new SqlCollection( "testId", "testcollection" );
48 m_collection->setSqlStorage( m_storage );
49 m_collection->setMountPointManager( new SqlMountPointManagerMock() );
50 m_collection->setQueryMakerFactory( new DefaultSqlQueryMakerFactory( m_collection ) );
51 DatabaseUpdater updater;
52 updater.setStorage( m_storage );
53 updater.setCollection( m_collection );
54 updater.update();
55}
56
57void
58TestSqlTrack::cleanupTestCase()
59{
60 delete m_collection;
61 //m_storage is deleted by SqlCollection
62 //m_registry is deleted by SqlCollection
63 delete m_tmpDir;
64}
65
66void
67TestSqlTrack::init()
68{
69 m_registry = new SqlRegistry( m_collection );
70 m_registry->setStorage( m_storage );
71 m_collection->setRegistry( m_registry );
72 //setup base data
73 m_storage->query( "INSERT INTO artists(id, name) VALUES (1, 'artist1');" );
74 m_storage->query( "INSERT INTO artists(id, name) VALUES (2, 'artist2');" );
75 m_storage->query( "INSERT INTO artists(id, name) VALUES (3, 'artist3');" );
76
77 m_storage->query( "INSERT INTO composers(id, name) VALUES (1, 'composer1');" );
78 m_storage->query( "INSERT INTO genres(id, name) VALUES (1, 'genre1');" );
79 m_storage->query( "INSERT INTO years(id, name) VALUES (1, '1');" );
80
81 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (1, -1, './IDoNotExist.mp3', 'uid://1');" );
82 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (2, -1, './IDoNotExistAsWell.mp3', 'uid://2');" );
83 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (3, -1, './MeNeither.mp3', 'uid:/3');" );
84
85
86}
87
88void
89TestSqlTrack::cleanup()
90{
91 delete m_registry;
92 m_collection->setRegistry( 0 );
93 m_storage->query( "TRUNCATE TABLE years;" );
94 m_storage->query( "TRUNCATE TABLE genres;" );
95 m_storage->query( "TRUNCATE TABLE composers;" );
96 m_storage->query( "TRUNCATE TABLE albums;" );
97 m_storage->query( "TRUNCATE TABLE artists;" );
98 m_storage->query( "TRUNCATE TABLE tracks;" );
99 m_storage->query( "TRUNCATE TABLE urls;" );
100}
101
102void
103TestSqlTrack::testAlbumRemaingsNonCompilationAfterChangingAlbumName()
104{
105 m_storage->query( "INSERT INTO albums(id,name,artist) VALUES (1, 'album1', 1);" );
106
107 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) "
108 "VALUES (1,1,'track1',1,1,1,1,1 );" );
109 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) "
110 "VALUES (2,2,'track2',1,1,1,1,1 );" );
111
112 Meta::TrackPtr track1 = m_registry->getTrack( "/IDoNotExist.mp3" );
113 Meta::TrackPtr track2 = m_registry->getTrack( "/IDoNotExistAsWell.mp3" );
114
115 QCOMPARE( track1->album()->name(), QString( "album1" ) );
116 QVERIFY( track1->album()->hasAlbumArtist() );
117 QVERIFY( track1->album() == track2->album() );
118
119 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() );
120 Meta::SqlTrack *sqlTrack2 = static_cast<Meta::SqlTrack*>( track2.data() );
121 sqlTrack1->setAlbum( "album2" );
122 sqlTrack2->beginMetaDataUpdate();
123 sqlTrack2->setAlbum( "album2" );
124 sqlTrack2->endMetaDataUpdate();
125
126 QCOMPARE( track1->album()->name(), QString( "album2" ) );
127 QVERIFY( track1->album()->hasAlbumArtist() );
128 QVERIFY( track1->album() == track2->album() );
129}
130
131void
132TestSqlTrack::testAlbumRemainsCompilationAfterChangingAlbumName()
133{
134 m_storage->query( "INSERT INTO albums(id,name,artist) VALUES (1, 'album1', 0);" );
135
136 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) "
137 "VALUES (1,1,'track1',1,1,1,1,1 );" );
138 m_storage->query( "INSERT INTO tracks(id,url,title,artist,album,genre,year,composer) "
139 "VALUES (2,2,'track2',1,1,1,1,1 );" );
140
141 Meta::TrackPtr track1 = m_registry->getTrack( "/IDoNotExist.mp3" );
142 Meta::TrackPtr track2 = m_registry->getTrack( "/IDoNotExistAsWell.mp3" );
143
144 QCOMPARE( track1->album()->name(), QString( "album1" ) );
145 QVERIFY( track1->album()->isCompilation() );
146 QVERIFY( track1->album() == track2->album() );
147
148 Meta::SqlTrack *sqlTrack1 = static_cast<Meta::SqlTrack*>( track1.data() );
149 Meta::SqlTrack *sqlTrack2 = static_cast<Meta::SqlTrack*>( track2.data() );
150 sqlTrack1->setAlbum( "album2" );
151 sqlTrack2->beginMetaDataUpdate();
152 sqlTrack2->setAlbum( "album2" );
153 sqlTrack2->endMetaDataUpdate();
154
155 QCOMPARE( track1->album()->name(), QString( "album2" ) );
156 QVERIFY( track1->album()->isCompilation() );
157 QVERIFY( track1->album() == track2->album() );
158}
159
160#include "TestSqlTrack.moc"
  
1/****************************************************************************************
2 * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17#ifndef TESTSQLTRACK_H
18#define TESTSQLTRACK_H
19
20#include <QtTest/QtTest>
21
22#include <KTempDir>
23
24class SqlStorage;
25class SqlCollection;
26class SqlRegistry;
27
28class TestSqlTrack : public QObject
29{
30 Q_OBJECT
31
32public:
33 TestSqlTrack();
34
35private slots:
36 void initTestCase();
37 void cleanupTestCase();
38
39 void init();
40 void cleanup();
41
42 void testAlbumRemainsCompilationAfterChangingAlbumName();
43 void testAlbumRemaingsNonCompilationAfterChangingAlbumName();
44
45private:
46 SqlCollection *m_collection;
47 SqlStorage *m_storage;
48 KTempDir *m_tmpDir;
49 SqlRegistry *m_registry;
50
51};
52
53#endif // TESTSQLTRACK_H