mirror of
https://github.com/QuasarApp/SoundBand.git
synced 2025-04-28 00:04:33 +00:00
added sql tests
This commit is contained in:
parent
52499cfb33
commit
ed78c6f01f
@ -244,7 +244,7 @@ bool MySql::removeSong(const SongHeader &header){
|
||||
}
|
||||
|
||||
bool MySql::addPlayList(const QString &newPlayList, const QString& desc){
|
||||
QString qyer = QString("INSERT INTO playlists(name, description) VALUE('%0','%1')").arg(newPlayList, desc);
|
||||
QString qyer = QString("INSERT INTO playlists(name, description) VALUES('%0', '%1')").arg(newPlayList, desc);
|
||||
if(!qyery->exec(qyer)){
|
||||
sqlErrorLog(qyer);
|
||||
return false;
|
||||
@ -254,14 +254,14 @@ bool MySql::addPlayList(const QString &newPlayList, const QString& desc){
|
||||
|
||||
bool MySql::addToPlayList(const SongHeader &header, const QString &newPlaylist){
|
||||
if(header.id > -1){
|
||||
QString qyer = QString("INSERT INTO playlistsdata(song, playlist) VALUE(%0,'%1')").arg(header.id).arg(newPlaylist);
|
||||
QString qyer = QString("INSERT INTO playlistsdata(song, playlist) VALUES(%0,'%1')").arg(header.id).arg(newPlaylist);
|
||||
if(!qyery->exec(qyer)){
|
||||
sqlErrorLog(qyer);
|
||||
return false;
|
||||
}
|
||||
}else if(!header.name.isEmpty() && header.size > 0){
|
||||
QString qyer = QString("INSERT INTO playlistsdata(song, playlist) "
|
||||
"VALUE(SELECT(id from songs where name='%0' and size='%1'),'%2')")
|
||||
"VALUES((SELECT id from songs where name='%0' and size='%1'),'%2')")
|
||||
.arg(header.name).arg(header.size).arg(newPlaylist);
|
||||
|
||||
if(!qyery->exec(qyer)){
|
||||
@ -276,14 +276,14 @@ bool MySql::addToPlayList(const SongHeader &header, const QString &newPlaylist){
|
||||
|
||||
bool MySql::removeFromPlayList(const SongHeader &header, const QString &playList){
|
||||
if(header.id > -1){
|
||||
QString qyer = QString("DELETE from playlistsdata where song=%0 and playlist='%1')").arg(header.id).arg(playList);
|
||||
QString qyer = QString("DELETE from playlistsdata where song=%0 and playlist='%1'").arg(header.id).arg(playList);
|
||||
if(!qyery->exec(qyer)){
|
||||
sqlErrorLog(qyer);
|
||||
return false;
|
||||
}
|
||||
}else if(!header.name.isEmpty() && header.size > 0){
|
||||
QString qyer = QString("DELETE from playlistsdata where "
|
||||
"song=SELECT(id from songs where name='%0' and size='%1') and playlist='%2')")
|
||||
"song=(SELECT id from songs where name='%0' and size='%1') and playlist='%2'")
|
||||
.arg(header.name).arg(header.size).arg(playList);
|
||||
|
||||
if(!qyery->exec(qyer)){
|
||||
@ -305,6 +305,26 @@ bool MySql::removePlayList(const QString &playList){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MySql::getPlayLists(QStringList &list){
|
||||
QString qyer = QString("SELECT name from playlists");
|
||||
if(!qyery->exec(qyer)){
|
||||
sqlErrorLog(qyer);
|
||||
return false;
|
||||
}
|
||||
|
||||
list.clear();
|
||||
|
||||
while(qyery->next()){
|
||||
list.push_back(qyery->value(0).toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MySql::clear(){
|
||||
qyery->exec("vacuum");
|
||||
}
|
||||
|
||||
MySql::~MySql(){
|
||||
delete db;
|
||||
QSqlDatabase::removeDatabase(dataBaseName);
|
||||
|
@ -111,6 +111,15 @@ public:
|
||||
*/
|
||||
static bool exec(QSqlQuery *q, const QString& sqlFile);
|
||||
|
||||
/**
|
||||
* @brief getPlayLists show all created playlists.
|
||||
* @param list - list of play lists.
|
||||
* @return trye if all done
|
||||
*/
|
||||
bool getPlayLists(QStringList &list);
|
||||
|
||||
void clear();
|
||||
|
||||
~MySql();
|
||||
};
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ private slots:
|
||||
|
||||
void player_tests();
|
||||
|
||||
void database_tests();
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -47,7 +49,7 @@ void SyncTest::sycn_tests()
|
||||
sync->stop();
|
||||
QVERIFY(!sync->play(2));
|
||||
|
||||
QVERIFY(QFile(DATABASE_NAME).size() == 2068480);
|
||||
QVERIFY(QFile(DATABASE_NAME).size() == 2084864);
|
||||
|
||||
delete sync;
|
||||
|
||||
@ -95,6 +97,70 @@ void SyncTest::player_tests()
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SyncTest::database_tests()
|
||||
{
|
||||
syncLib::MySql sql("test1");
|
||||
syncLib::SongHeader header;
|
||||
syncLib::Song song;
|
||||
|
||||
QVERIFY(!sql.load(header,song));
|
||||
|
||||
QVERIFY(!sql.addToPlayList(header,"none"));
|
||||
|
||||
header.id = sql.save(":/song/test_song");
|
||||
QVERIFY(header.id > 0);
|
||||
|
||||
QVERIFY(sql.load(header,song));
|
||||
|
||||
header = static_cast<syncLib::SongHeader>(song);
|
||||
QVERIFY(sql.load(header,song));
|
||||
|
||||
QVERIFY(sql.addPlayList("play","desc of play"));
|
||||
|
||||
QVERIFY(sql.addToPlayList(header,"play"));
|
||||
|
||||
QVERIFY(!sql.addToPlayList(header,"play"));
|
||||
|
||||
QVERIFY(sql.removeFromPlayList(header,"play"));
|
||||
|
||||
header.id = -1;
|
||||
QVERIFY(sql.addToPlayList(header,"play"));
|
||||
|
||||
QVERIFY(!sql.addToPlayList(header,"play"));
|
||||
|
||||
QList<syncLib::SongHeader> list;
|
||||
sql.updateAvailableSongs(list);
|
||||
|
||||
QVERIFY(list.size() == 1);
|
||||
list.clear();
|
||||
sql.updateAvailableSongs(list,"play");
|
||||
|
||||
QVERIFY(list.size() == 1);
|
||||
|
||||
sql.updateAvailableSongs(list,"play2");
|
||||
QVERIFY(list.size() == 0);
|
||||
|
||||
QVERIFY(sql.removeFromPlayList(header,"play"));
|
||||
|
||||
QVERIFY(sql.removeSong(header));
|
||||
|
||||
sql.updateAvailableSongs(list);
|
||||
QVERIFY(list.size() == 0);
|
||||
|
||||
QStringList playlists;
|
||||
sql.getPlayLists(playlists);
|
||||
QVERIFY(playlists.size() == 1);
|
||||
|
||||
QVERIFY(sql.removePlayList("play"));
|
||||
|
||||
sql.getPlayLists(playlists);
|
||||
QVERIFY(playlists.size() == 0);
|
||||
|
||||
sql.clear();
|
||||
QVERIFY(QFile("test1").size() == 32768);
|
||||
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(SyncTest)
|
||||
|
Loading…
x
Reference in New Issue
Block a user