1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/****************************************************************************************
* Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "TestSqlCollection.h"
#include <core/collections/Collection.h>
#include <core-impl/collections/db/sql/SqlCollection.h>
#include <core-impl/collections/db/sql/DatabaseUpdater.h>
#include <core-impl/storage/sql/mysqlestorage/MySqlEmbeddedStorage.h>
#include "SqlMountPointManagerMock.h"
#include <QSignalSpy>
QTEST_GUILESS_MAIN( TestSqlCollection )
QTemporaryDir *TestSqlCollection::s_tmpDir = nullptr;
TestSqlCollection::TestSqlCollection()
{
std::atexit([]() { delete TestSqlCollection::s_tmpDir; } );
}
void
TestSqlCollection::initTestCase()
{
if( !s_tmpDir )
s_tmpDir = new QTemporaryDir();
m_storage = QSharedPointer<MySqlEmbeddedStorage>( new MySqlEmbeddedStorage() );
QVERIFY( m_storage->init( s_tmpDir->path() ) );
m_collection = new Collections::SqlCollection( m_storage );
m_mpmMock = new SqlMountPointManagerMock( this, m_storage );
m_collection->setMountPointManager( m_mpmMock );
m_storage->query( QStringLiteral("INSERT INTO urls(id, deviceid, rpath) VALUES (1, 1, './IDoNotExist.mp3');") );
m_storage->query( QStringLiteral("INSERT INTO urls(id, deviceid, rpath) VALUES (2, 2, './IDoNotExistAsWell.mp3');") );
m_storage->query( QStringLiteral("INSERT INTO tracks(id, url,title) VALUES ( 1,1,'test1');") );
}
void
TestSqlCollection::cleanupTestCase()
{
delete m_collection;
//m_mpMock is deleted by SqlCollection
}
void
TestSqlCollection::testDeviceAddedWithTracks()
{
QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
m_mpmMock->emitDeviceAdded( 1 );
QCOMPARE( spy.count(), 1 );
}
void
TestSqlCollection::testDeviceAddedWithoutTracks()
{
QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
m_mpmMock->emitDeviceAdded( 2 );
QCOMPARE( spy.count(), 0 );
}
void
TestSqlCollection::testDeviceRemovedWithTracks()
{
QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
m_mpmMock->emitDeviceRemoved( 1 );
QCOMPARE( spy.count(), 1 );
}
void
TestSqlCollection::testDeviceRemovedWithoutTracks()
{
QSignalSpy spy( m_collection, &Collections::SqlCollection::updated);
m_mpmMock->emitDeviceRemoved( 0 );
QCOMPARE( spy.count(), 0 );
}
|