From 00d0d7259b624c4caae8d2bac517aaf2328bebdb Mon Sep 17 00:00:00 2001 From: MasatoNakamoto Date: Tue, 26 Dec 2017 12:54:33 +0300 Subject: [PATCH] fix tests --- sync/mysql.cpp | 2 +- sync/song.cpp | 9 +++++++-- sync/song.h | 1 + sync/tests/res.qrc | 2 ++ sync/tests/tst_synctest.cpp | 7 +++++-- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sync/mysql.cpp b/sync/mysql.cpp index 5035982..474f2f3 100644 --- a/sync/mysql.cpp +++ b/sync/mysql.cpp @@ -166,7 +166,7 @@ int MySql::save(const QString &url){ song.size = bytes.size(); song.source = bytes; - if(!song.isValid()){ + if(!song.isNameValid()){ return -1; } diff --git a/sync/song.cpp b/sync/song.cpp index 33e672c..d447a93 100644 --- a/sync/song.cpp +++ b/sync/song.cpp @@ -28,12 +28,17 @@ unsigned int SongHeader::getSize() const{ return size.size(); } -bool SongHeader::isValid() const{ +bool SongHeader::isNameValid() const{ bool CheckSongs = false; for (QString i: ValidSongs){ CheckSongs = CheckSongs || name.endsWith(i); } - return id > -1 && !name.isEmpty() && size > 0 && CheckSongs; + return CheckSongs; +} + +bool SongHeader::isValid() const{ + + return id > -1 && !name.isEmpty() && size > 0 && isNameValid(); } diff --git a/sync/song.h b/sync/song.h index c2f56b3..8910a38 100644 --- a/sync/song.h +++ b/sync/song.h @@ -37,6 +37,7 @@ public: SongHeader& operator = (const SongHeader& right); bool operator == (const SongHeader& right); virtual unsigned int getSize() const; + bool isNameValid() const; virtual bool isValid() const; virtual ~SongHeader(); friend QDataStream& operator << (QDataStream& stream, const SongHeader& song); diff --git a/sync/tests/res.qrc b/sync/tests/res.qrc index 44dfe76..1c364de 100644 --- a/sync/tests/res.qrc +++ b/sync/tests/res.qrc @@ -1,5 +1,7 @@ res/under ground.mp3 + res/under ground.mp3 + diff --git a/sync/tests/tst_synctest.cpp b/sync/tests/tst_synctest.cpp index 6e43446..0dabec7 100644 --- a/sync/tests/tst_synctest.cpp +++ b/sync/tests/tst_synctest.cpp @@ -41,7 +41,10 @@ void SyncTest::sycn_tests() QVERIFY(sync != nullptr); - QVERIFY(sync->play(":/song/test_song")); + QVERIFY(!sync->play(":/song/test_song")); + + QVERIFY(sync->play(":/song/test_song.mp3")); + sync->stop(); QVERIFY(sync->play(1)); @@ -109,7 +112,7 @@ void SyncTest::database_tests() QVERIFY(!sql.addToPlayList(header,"none")); - header.id = sql.save(":/song/test_song"); + header.id = sql.save(":/song/test_song.mp3"); QVERIFY(header.id > 0); QVERIFY(sql.load(header,song));