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 "TestSqlCollection.h"
0018 
0019 #include <core/collections/Collection.h>
0020 #include <core-impl/collections/db/sql/SqlCollection.h>
0021 #include <core-impl/collections/db/sql/DatabaseUpdater.h>
0022 #include <core-impl/storage/sql/mysqlestorage/MySqlEmbeddedStorage.h>
0023 
0024 #include "SqlMountPointManagerMock.h"
0025 
0026 #include <QSignalSpy>
0027 
0028 
0029 QTEST_GUILESS_MAIN( TestSqlCollection )
0030 
0031 TestSqlCollection::TestSqlCollection()
0032 {
0033 }
0034 
0035 void
0036 TestSqlCollection::initTestCase()
0037 {
0038     m_tmpDir = new QTemporaryDir();
0039     m_storage = QSharedPointer<MySqlEmbeddedStorage>( new MySqlEmbeddedStorage() );
0040     QVERIFY( m_storage->init( m_tmpDir->path() ) );
0041     m_collection = new Collections::SqlCollection( m_storage );
0042     m_mpmMock = new SqlMountPointManagerMock( this, m_storage );
0043     m_collection->setMountPointManager( m_mpmMock );
0044 
0045     m_storage->query( "INSERT INTO urls(id, deviceid, rpath) VALUES (1, 1, './IDoNotExist.mp3');" );
0046     m_storage->query( "INSERT INTO urls(id, deviceid, rpath) VALUES (2, 2, './IDoNotExistAsWell.mp3');" );
0047 
0048     m_storage->query( "INSERT INTO tracks(id, url,title) VALUES ( 1,1,'test1');" );
0049 }
0050 
0051 void
0052 TestSqlCollection::cleanupTestCase()
0053 {
0054     delete m_collection;
0055     //m_mpMock is deleted by SqlCollection
0056     delete m_tmpDir;
0057 
0058 }
0059 
0060 void
0061 TestSqlCollection::testDeviceAddedWithTracks()
0062 {
0063     QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
0064     m_mpmMock->emitDeviceAdded( 1 );
0065     QCOMPARE( spy.count(), 1 );
0066 }
0067 
0068 void
0069 TestSqlCollection::testDeviceAddedWithoutTracks()
0070 {
0071     QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
0072     m_mpmMock->emitDeviceAdded( 2 );
0073     QCOMPARE( spy.count(), 0 );
0074 }
0075 
0076 void
0077 TestSqlCollection::testDeviceRemovedWithTracks()
0078 {
0079     QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
0080     m_mpmMock->emitDeviceRemoved( 1 );
0081     QCOMPARE( spy.count(), 1 );
0082 }
0083 
0084 void
0085 TestSqlCollection::testDeviceRemovedWithoutTracks()
0086 {
0087     QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
0088     m_mpmMock->emitDeviceRemoved( 0 );
0089     QCOMPARE( spy.count(), 0 );
0090 }
0091