diff --git a/sources/extsysmonsources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp index fa1d161..1f2e337 100644 --- a/sources/extsysmonsources/batterysource.cpp +++ b/sources/extsysmonsources/batterysource.cpp @@ -40,17 +40,16 @@ BatterySource::~BatterySource() } - QStringList BatterySource::getSources() { QStringList sources; sources.append(QString("battery/ac")); sources.append(QString("battery/bat")); m_batteriesCount - = QDir(m_acpiPath) - .entryList(QStringList() << QString("BAT*"), - QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) - .count(); + = QDir(m_acpiPath) + .entryList(QStringList() << QString("BAT*"), + QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) + .count(); qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; for (int i = 0; i < m_batteriesCount; i++) sources.append(QString("battery/bat%1").arg(i)); diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 6703c72..d7aabaa 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -26,7 +26,7 @@ set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather abstractformatter datetimeformatter floatformatter noformatter scriptformatter extitemaggregator - batterysource gpuloadsource gputempsource hddtempsource) + batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource processessource) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testbatterysource.cpp b/sources/test/testbatterysource.cpp index 636df6a..74f1f9f 100644 --- a/sources/test/testbatterysource.cpp +++ b/sources/test/testbatterysource.cpp @@ -48,13 +48,15 @@ void TestBatterySource::test_battery() QSKIP("No battery found, test will be skipped"); QStringList batteries = source->sources(); - std::for_each(batteries.begin(), batteries.end(), [this](const QString bat) { - QVariant value = source->data(bat); - if (bat == QString("battery/ac")) - QCOMPARE(value.type(), QVariant::Bool); - else - QVERIFY((value.toFloat() >= battery.first) && (value.toFloat() <= battery.second)); - }); + std::for_each(batteries.begin(), batteries.end(), + [this](const QString bat) { + QVariant value = source->data(bat); + if (bat == QString("battery/ac")) + QCOMPARE(value.type(), QVariant::Bool); + else + QVERIFY((value.toFloat() >= battery.first) + && (value.toFloat() <= battery.second)); + }); } diff --git a/sources/test/testdesktopsource.cpp b/sources/test/testdesktopsource.cpp new file mode 100644 index 0000000..602efd8 --- /dev/null +++ b/sources/test/testdesktopsource.cpp @@ -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 + +#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); diff --git a/sources/test/testdesktopsource.h b/sources/test/testdesktopsource.h new file mode 100644 index 0000000..7fd0a60 --- /dev/null +++ b/sources/test/testdesktopsource.h @@ -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 + + +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 */ diff --git a/sources/test/testnetworksource.cpp b/sources/test/testnetworksource.cpp new file mode 100644 index 0000000..9f2994b --- /dev/null +++ b/sources/test/testnetworksource.cpp @@ -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 + +#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); diff --git a/sources/test/testnetworksource.h b/sources/test/testnetworksource.h new file mode 100644 index 0000000..e69334c --- /dev/null +++ b/sources/test/testnetworksource.h @@ -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 + + +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 */ diff --git a/sources/test/testprocessessource.cpp b/sources/test/testprocessessource.cpp new file mode 100644 index 0000000..11280b5 --- /dev/null +++ b/sources/test/testprocessessource.cpp @@ -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 + +#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); diff --git a/sources/test/testprocessessource.h b/sources/test/testprocessessource.h new file mode 100644 index 0000000..c81b871 --- /dev/null +++ b/sources/test/testprocessessource.h @@ -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 + + +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 */