add last sources test for playersource

This commit is contained in:
2016-06-18 05:08:14 +03:00
parent 0f1763cb81
commit 71ae832bcd
7 changed files with 245 additions and 60 deletions

View File

@ -26,7 +26,7 @@ set(TEST_MODULES
abstractextitem extquotes extscript extupgrade extweather
abstractformatter datetimeformatter floatformatter noformatter scriptformatter
extitemaggregator
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource processessource)
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource)
foreach (TEST_MODULE ${TEST_MODULES})
set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h)
set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp)

View File

@ -40,9 +40,10 @@ void TestDesktopSource::test_sources()
{
QCOMPARE(source->sources().count(), 4);
// FIXME there is segfault here sometimes o_0
// QVERIFY(std::all_of(
// source->sources().cbegin(), source->sources().cend(),
// [](const QString &src) { return src.startsWith(QString("desktop/")); }));
// QVERIFY(std::all_of(
// source->sources().cbegin(), source->sources().cend(),
// [](const QString &src) { return
// src.startsWith(QString("desktop/")); }));
}

View File

@ -0,0 +1,131 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets 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 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "testplayersource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "playersource.h"
void TestPlayerSource::initTestCase()
{
}
void TestPlayerSource::cleanupTestCase()
{
}
void TestPlayerSource::_test_sources(const PlayerSource *source)
{
QVERIFY(source->sources().count() == 11);
}
void TestPlayerSource::test_buildString()
{
QString randomString = AWTestLibrary::randomString(40);
QString str = PlayerSource::buildString(QString(), randomString, 20);
QCOMPARE(str.count(), 20);
str = PlayerSource::buildString(str, randomString, 20);
QCOMPARE(str.count(), 20);
QCOMPARE(randomString.indexOf(str), 1);
str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10),
20);
QCOMPARE(str.count(), 20);
}
void TestPlayerSource::test_stripString()
{
QString str = PlayerSource::buildString(
QString(), AWTestLibrary::randomString(40), 20);
QCOMPARE(str.count(), 20);
str = PlayerSource::buildString(QString(), AWTestLibrary::randomString(10),
20);
QCOMPARE(str.count(), 20);
}
void TestPlayerSource::test_autoMpris()
{
QStringList args(QStringList() << QString("mpris") << mpdAddress
<< QString::number(mpdPort)
<< QString("auto") << QString::number(10));
PlayerSource *source = new PlayerSource(this, args);
QWARN("Will fail if no MPRIS supported player is run");
QVERIFY(!source->getAutoMpris().isEmpty());
}
void TestPlayerSource::test_mpd()
{
QStringList args(QStringList() << QString("mpd") << mpdAddress
<< QString::number(mpdPort)
<< QString("auto") << QString::number(10));
PlayerSource *source = new PlayerSource(this, args);
_test_sources(source);
// init spy
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
QVariant firstValue = source->data(QString("player/title"));
// check values
QVERIFY(spy.wait(5000));
QList<QVariant> arguments = spy.takeFirst();
QVariantHash secondValue = arguments.at(0).toHash();
// actually nothing to test here just print warning if no information found
if (secondValue[QString("player/title")].toString() == QString("unknown")) {
QWARN("No mpd found");
} else {
QVERIFY(secondValue[QString("player/progress")].toInt()
< secondValue[QString("player/duration")].toInt());
}
}
void TestPlayerSource::test_mpris()
{
QStringList args(QStringList() << QString("mpris") << mpdAddress
<< QString::number(mpdPort)
<< QString("auto") << QString::number(10));
PlayerSource *source = new PlayerSource(this, args);
_test_sources(source);
QString value = source->data(QString("player/title")).toString();
int progress = source->data(QString("player/progress")).toInt();
int duration = source->data(QString("player/duration")).toInt();
// actually nothing to test here just print warning if no information found
if (value == QString("unknown")) {
QWARN("No mpris found");
} else {
QVERIFY(progress < duration);
}
}
QTEST_MAIN(TestPlayerSource);

View File

@ -0,0 +1,49 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets 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 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef TESTPLAYERSOURCE_H
#define TESTPLAYERSOURCE_H
#include <QObject>
class PlayerSource;
class TestPlayerSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void _test_sources(const PlayerSource *source);
void test_buildString();
void test_stripString();
void test_autoMpris();
void test_mpd();
void test_mpris();
private:
QString mpdAddress = QString("localhost");
int mpdPort = 6600;
};
#endif /* TESTPLAYERSOURCE_H */

View File

@ -40,16 +40,18 @@ void TestProcessesSource::test_sources()
{
QCOMPARE(source->sources().count(), 3);
// FIXME there is segfault here sometimes o_0
// QVERIFY(std::all_of(
// source->sources().cbegin(), source->sources().cend(),
// [](const QString &src) { return src.startsWith(QString("ps/")); }));
// QVERIFY(std::all_of(
// source->sources().cbegin(), source->sources().cend(),
// [](const QString &src) { return src.startsWith(QString("ps/"));
// }));
}
void TestProcessesSource::test_values()
{
QVERIFY(source->data(QString("ps/running/count")).toInt() > 0);
QVERIFY(source->data(QString("ps/running/list")).toStringList().count() > 0);
QVERIFY(source->data(QString("ps/running/list")).toStringList().count()
> 0);
QVERIFY(source->data(QString("ps/total/count")).toInt() > 0);
}