add tests for dekstop, network and processes sources

This commit is contained in:
Evgenii Alekseev 2016-06-15 15:10:41 +03:00
parent 5d9d551afe
commit 75d101cc8b
9 changed files with 315 additions and 13 deletions

View File

@ -40,7 +40,6 @@ BatterySource::~BatterySource()
} }
QStringList BatterySource::getSources() QStringList BatterySource::getSources()
{ {
QStringList sources; QStringList sources;

View File

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

View File

@ -48,12 +48,14 @@ void TestBatterySource::test_battery()
QSKIP("No battery found, test will be skipped"); QSKIP("No battery found, test will be skipped");
QStringList batteries = source->sources(); QStringList batteries = source->sources();
std::for_each(batteries.begin(), batteries.end(), [this](const QString bat) { std::for_each(batteries.begin(), batteries.end(),
[this](const QString bat) {
QVariant value = source->data(bat); QVariant value = source->data(bat);
if (bat == QString("battery/ac")) if (bat == QString("battery/ac"))
QCOMPARE(value.type(), QVariant::Bool); QCOMPARE(value.type(), QVariant::Bool);
else else
QVERIFY((value.toFloat() >= battery.first) && (value.toFloat() <= battery.second)); QVERIFY((value.toFloat() >= battery.first)
&& (value.toFloat() <= battery.second));
}); });
} }

View File

@ -0,0 +1,60 @@
/***************************************************************************
* 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 "testdesktopsource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "desktopsource.h"
void TestDesktopSource::initTestCase()
{
source = new DesktopSource(this, QStringList());
}
void TestDesktopSource::cleanupTestCase()
{
delete source;
}
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/")); }));
}
void TestDesktopSource::test_values()
{
QVERIFY(source->data(QString("desktop/current/name")).toString().count()
> 0);
QVERIFY(source->data(QString("desktop/current/number")).toInt() >= 0);
QVERIFY(source->data(QString("desktop/total/name")).toStringList().count()
> 0);
QVERIFY(source->data(QString("desktop/total/number")).toInt() > 0);
}
QTEST_MAIN(TestDesktopSource);

View File

@ -0,0 +1,44 @@
/***************************************************************************
* 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 TESTDESKTOPSOURCE_H
#define TESTDESKTOPSOURCE_H
#include <QObject>
class DesktopSource;
class TestDesktopSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_values();
private:
DesktopSource *source = nullptr;
};
#endif /* TESTDESKTOPSOURCE_H */

View File

@ -0,0 +1,51 @@
/***************************************************************************
* 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 "testnetworksource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "networksource.h"
void TestNetworkSource::initTestCase()
{
source = new NetworkSource(this, QStringList());
}
void TestNetworkSource::cleanupTestCase()
{
delete source;
}
void TestNetworkSource::test_sources()
{
QCOMPARE(source->sources(), QStringList() << src);
}
void TestNetworkSource::test_values()
{
QVERIFY(source->data(src).toString().count() > 0);
}
QTEST_MAIN(TestNetworkSource);

View File

@ -0,0 +1,45 @@
/***************************************************************************
* 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 TESTNETWORKSOURCE_H
#define TESTNETWORKSOURCE_H
#include <QObject>
class NetworkSource;
class TestNetworkSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_values();
private:
NetworkSource *source = nullptr;
QString src = QString("network/current/name");
};
#endif /* TESTNETWORKSOURCE_H */

View File

@ -0,0 +1,57 @@
/***************************************************************************
* 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 "testprocessessource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "processessource.h"
void TestProcessesSource::initTestCase()
{
source = new ProcessesSource(this, QStringList());
}
void TestProcessesSource::cleanupTestCase()
{
delete source;
}
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/")); }));
}
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/total/count")).toInt() > 0);
}
QTEST_MAIN(TestProcessesSource);

View File

@ -0,0 +1,44 @@
/***************************************************************************
* 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 TESTPROCESSESSOURCE_H
#define TESTPROCESSESSOURCE_H
#include <QObject>
class ProcessesSource;
class TestProcessesSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_values();
private:
ProcessesSource *source = nullptr;
};
#endif /* TESTPROCESSESSOURCE_H */