File indexing completed on 2024-11-10 04:22:06
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 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 "TestSqlArtist.h" 0018 0019 #include "DefaultSqlQueryMakerFactory.h" 0020 #include "core/meta/Meta.h" 0021 #include "core-impl/storage/sql/mysqlestorage/MySqlEmbeddedStorage.h" 0022 #include "SqlCollection.h" 0023 #include "SqlMountPointManagerMock.h" 0024 0025 0026 QTEST_GUILESS_MAIN( TestSqlArtist ) 0027 0028 TestSqlArtist::TestSqlArtist() 0029 : QObject() 0030 , m_collection( nullptr ) 0031 , m_storage( nullptr ) 0032 , m_tmpDir( nullptr ) 0033 { 0034 } 0035 0036 void 0037 TestSqlArtist::initTestCase() 0038 { 0039 m_tmpDir = new QTemporaryDir(); 0040 m_storage = QSharedPointer<MySqlEmbeddedStorage>( new MySqlEmbeddedStorage() ); 0041 QVERIFY( m_storage->init( m_tmpDir->path() ) ); 0042 m_collection = new Collections::SqlCollection( m_storage ); 0043 m_collection->setMountPointManager( new SqlMountPointManagerMock( this, m_storage ) ); 0044 } 0045 0046 void 0047 TestSqlArtist::cleanupTestCase() 0048 { 0049 delete m_collection; 0050 delete m_tmpDir; 0051 } 0052 0053 void 0054 TestSqlArtist::init() 0055 { 0056 //setup base data 0057 m_storage->query( "INSERT INTO artists(id, name) VALUES (1, 'The Foo');" ); 0058 m_storage->query( "INSERT INTO artists(id, name) VALUES (2, 'No The Foo');" ); 0059 m_storage->query( "INSERT INTO artists(id, name) VALUES (3, 'artist3');" ); 0060 0061 m_storage->query( "INSERT INTO composers(id, name) VALUES (1, 'composer1');" ); 0062 m_storage->query( "INSERT INTO genres(id, name) VALUES (1, 'genre1');" ); 0063 m_storage->query( "INSERT INTO years(id, name) VALUES (1, '1');" ); 0064 0065 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (1, -1, './IDoNotExist.mp3', 'uid://1');" ); 0066 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (2, -1, './IDoNotExistAsWell.mp3', 'uid://2');" ); 0067 m_storage->query( "INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (3, -1, './MeNeither.mp3', 'uid:/3');" ); 0068 } 0069 0070 void 0071 TestSqlArtist::cleanup() 0072 { 0073 m_storage->query( "TRUNCATE TABLE years;" ); 0074 m_storage->query( "TRUNCATE TABLE genres;" ); 0075 m_storage->query( "TRUNCATE TABLE composers;" ); 0076 m_storage->query( "TRUNCATE TABLE albums;" ); 0077 m_storage->query( "TRUNCATE TABLE artists;" ); 0078 m_storage->query( "TRUNCATE TABLE tracks;" ); 0079 m_storage->query( "TRUNCATE TABLE urls;" ); 0080 m_storage->query( "TRUNCATE TABLE labels;" ); 0081 m_storage->query( "TRUNCATE TABLE urls_labels;" ); 0082 } 0083 0084 void 0085 TestSqlArtist::testSortableName() 0086 { 0087 Meta::ArtistPtr artistWithThe = m_collection->registry()->getArtist( 1 ); 0088 QCOMPARE( artistWithThe->sortableName(), QString( "Foo, The" ) ); 0089 0090 Meta::ArtistPtr artistWithoutThe = m_collection->registry()->getArtist( 2 ); 0091 QCOMPARE( artistWithoutThe->sortableName(), QString( "No The Foo" ) ); 0092 } 0093 0094