diff --git a/sources/extsysmonsources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp
index 985f044..fa1d161 100644
--- a/sources/extsysmonsources/batterysource.cpp
+++ b/sources/extsysmonsources/batterysource.cpp
@@ -40,6 +40,26 @@ 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();
+ 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));
+
+ qCInfo(LOG_ESS) << "Sources list" << sources;
+ return sources;
+}
+
+
QVariant BatterySource::data(QString source)
{
qCDebug(LOG_ESS) << "Source" << source;
@@ -120,22 +140,3 @@ QStringList BatterySource::sources() const
{
return m_sources;
}
-
-
-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();
- 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));
-
- qCInfo(LOG_ESS) << "Sources list" << sources;
- return sources;
-}
diff --git a/sources/extsysmonsources/batterysource.h b/sources/extsysmonsources/batterysource.h
index 09403c7..4779641 100644
--- a/sources/extsysmonsources/batterysource.h
+++ b/sources/extsysmonsources/batterysource.h
@@ -28,13 +28,13 @@ class BatterySource : public AbstractExtSysMonSource
public:
explicit BatterySource(QObject *parent, const QStringList args);
virtual ~BatterySource();
+ QStringList getSources();
QVariant data(QString source);
QVariantMap initialData(QString source) const;
void run();
QStringList sources() const;
private:
- QStringList getSources();
// configuration and values
int m_batteriesCount = 0;
QString m_acpiPath;
diff --git a/sources/extsysmonsources/gpuloadsource.cpp b/sources/extsysmonsources/gpuloadsource.cpp
index 1a4738d..b85db70 100644
--- a/sources/extsysmonsources/gpuloadsource.cpp
+++ b/sources/extsysmonsources/gpuloadsource.cpp
@@ -77,7 +77,7 @@ QVariant GPULoadSource::data(QString source)
if (source == QString("gpu/load"))
run();
- return m_value;
+ return m_values[source];
}
@@ -140,7 +140,7 @@ void GPULoadSource::updateValue()
QString load = str.remove(QString(""))
.remove(QString(""))
.remove(QChar('%'));
- m_value = load.toFloat();
+ m_values[QString("gpu/load")] = load.toFloat();
break;
}
} else if (m_device == QString("ati")) {
@@ -150,7 +150,7 @@ void GPULoadSource::updateValue()
QString load
= str.split(QChar(' '), QString::SkipEmptyParts)[3].remove(
QChar('%'));
- m_value = load.toFloat();
+ m_values[QString("gpu/load")] = load.toFloat();
break;
}
}
diff --git a/sources/extsysmonsources/gpuloadsource.h b/sources/extsysmonsources/gpuloadsource.h
index c213309..4caa8fa 100644
--- a/sources/extsysmonsources/gpuloadsource.h
+++ b/sources/extsysmonsources/gpuloadsource.h
@@ -43,7 +43,7 @@ private:
// configuration and values
QString m_device;
QProcess *m_process = nullptr;
- QVariant m_value;
+ QVariantHash m_values;
};
diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt
index eb944a1..6703c72 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
- hddtempsource)
+ batterysource gpuloadsource gputempsource hddtempsource)
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
new file mode 100644
index 0000000..636df6a
--- /dev/null
+++ b/sources/test/testbatterysource.cpp
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * 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 "testbatterysource.h"
+
+#include
+
+#include "awtestlibrary.h"
+#include "batterysource.h"
+
+
+void TestBatterySource::initTestCase()
+{
+ source = new BatterySource(this, QStringList() << acpiPath);
+}
+
+
+void TestBatterySource::cleanupTestCase()
+{
+ delete source;
+}
+
+
+void TestBatterySource::test_sources()
+{
+ QVERIFY(source->sources().count() >= 2);
+}
+
+
+void TestBatterySource::test_battery()
+{
+ if (source->sources().count() == 2)
+ 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));
+ });
+}
+
+
+QTEST_MAIN(TestBatterySource);
diff --git a/sources/test/testbatterysource.h b/sources/test/testbatterysource.h
new file mode 100644
index 0000000..c51dfc9
--- /dev/null
+++ b/sources/test/testbatterysource.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * 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 TESTBATTERYSOURCE_H
+#define TESTBATTERYSOURCE_H
+
+#include
+
+
+class BatterySource;
+
+class TestBatterySource : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ // initialization
+ void initTestCase();
+ void cleanupTestCase();
+ // test
+ void test_sources();
+ void test_battery();
+
+private:
+ BatterySource *source = nullptr;
+ QString acpiPath = QString("/sys/class/power_supply/");
+ QPair battery = QPair(0, 100);
+};
+
+
+#endif /* TESTBATTERYSOURCE_H */
diff --git a/sources/test/testextquotes.cpp b/sources/test/testextquotes.cpp
index 67aa9e4..095f5d4 100644
--- a/sources/test/testextquotes.cpp
+++ b/sources/test/testextquotes.cpp
@@ -53,9 +53,6 @@ void TestExtQuotes::test_run()
// init spy
QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &)));
QVariantHash firstValue = extQuotes->run();
- QCOMPARE(firstValue[extQuotes->tag(QString("ask"))].toDouble(), 0.0);
- QCOMPARE(firstValue[extQuotes->tag(QString("bid"))].toDouble(), 0.0);
- QCOMPARE(firstValue[extQuotes->tag(QString("price"))].toDouble(), 0.0);
// check values
QVERIFY(spy.wait(5000));
@@ -67,6 +64,9 @@ void TestExtQuotes::test_run()
cache[QString("price")]
= arguments.at(0).toHash()[extQuotes->tag(QString("price"))];
+ QCOMPARE(firstValue[extQuotes->tag(QString("ask"))].toDouble(), 0.0);
+ QCOMPARE(firstValue[extQuotes->tag(QString("bid"))].toDouble(), 0.0);
+ QCOMPARE(firstValue[extQuotes->tag(QString("price"))].toDouble(), 0.0);
for (auto type : types) {
qDebug() << "Test type" << type;
QVERIFY((cache[type].toDouble() > price.first)
diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp
index 4ecc050..959593f 100644
--- a/sources/test/testextscript.cpp
+++ b/sources/test/testextscript.cpp
@@ -60,12 +60,13 @@ void TestExtScript::test_run()
// init spy
QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &)));
QVariantHash firstValue = extScript->run();
- QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(),
- QString(""));
// check values
QVERIFY(spy.wait(5000));
QList arguments = spy.takeFirst();
+
+ QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(),
+ QString(""));
QCOMPARE(
arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(),
QString("\n%1").arg(randomString));
diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp
index 64cbc10..fb0e0d3 100644
--- a/sources/test/testextupgrade.cpp
+++ b/sources/test/testextupgrade.cpp
@@ -57,11 +57,12 @@ void TestExtUpgrade::test_run()
// init spy
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
QVariantHash firstValue = extUpgrade->run();
- QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0);
// check values
QVERIFY(spy.wait(5000));
QList arguments = spy.takeFirst();
+
+ QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0);
QCOMPARE(
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
randomStrings.count());
diff --git a/sources/test/testgpuloadsource.cpp b/sources/test/testgpuloadsource.cpp
new file mode 100644
index 0000000..0bdc1ec
--- /dev/null
+++ b/sources/test/testgpuloadsource.cpp
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * 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 "testgpuloadsource.h"
+
+#include
+
+#include "awtestlibrary.h"
+#include "gpuloadsource.h"
+
+
+void TestGPULoadSource::initTestCase()
+{
+ device = GPULoadSource::autoGpu();
+ QVERIFY(!device.isEmpty());
+
+ source = new GPULoadSource(this, QStringList() << device);
+}
+
+
+void TestGPULoadSource::cleanupTestCase()
+{
+ delete source;
+}
+
+
+void TestGPULoadSource::test_sources()
+{
+ QCOMPARE(source->sources(), QStringList() << src);
+}
+
+
+void TestGPULoadSource::test_gpuload()
+{
+ if (device == QString("disable"))
+ QSKIP("Not supported device, test will be skipped");
+
+ QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
+ float firstValue = source->data(src).toFloat();
+
+ QVERIFY(spy.wait(5000));
+ QVariantHash arguments = spy.takeFirst().at(0).toHash();
+ float secondValue = arguments[src].toFloat();
+
+ QCOMPARE(firstValue, 0.0f);
+ QVERIFY((secondValue >= load.first) && (secondValue <= load.second));
+}
+
+
+QTEST_MAIN(TestGPULoadSource);
diff --git a/sources/test/testgpuloadsource.h b/sources/test/testgpuloadsource.h
new file mode 100644
index 0000000..5e32433
--- /dev/null
+++ b/sources/test/testgpuloadsource.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * 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 TESTGPULOADSOURCE_H
+#define TESTGPULOADSOURCE_H
+
+#include
+
+
+class GPULoadSource;
+
+class TestGPULoadSource : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ // initialization
+ void initTestCase();
+ void cleanupTestCase();
+ // test
+ void test_sources();
+ void test_gpuload();
+
+private:
+ GPULoadSource *source = nullptr;
+ QString device;
+ QString src = QString("gpu/load");
+ QPair load = QPair(0.0f, 100.0f);
+};
+
+
+#endif /* TESTGPULOADSOURCE_H */
diff --git a/sources/test/testgputempsource.cpp b/sources/test/testgputempsource.cpp
index 29a8f36..a73546c 100644
--- a/sources/test/testgputempsource.cpp
+++ b/sources/test/testgputempsource.cpp
@@ -29,19 +29,19 @@ void TestGPUTemperatureSource::initTestCase()
device = GPUTemperatureSource::autoGpu();
QVERIFY(!device.isEmpty());
- gputempSource = new GPUTemperatureSource(this, QStringList() << device);
+ source = new GPUTemperatureSource(this, QStringList() << device);
}
void TestGPUTemperatureSource::cleanupTestCase()
{
- delete gputempSource;
+ delete source;
}
void TestGPUTemperatureSource::test_sources()
{
- QCOMPARE(gputempSource->sources(), QStringList() << source);
+ QCOMPARE(source->sources(), QStringList() << src);
}
@@ -50,13 +50,14 @@ void TestGPUTemperatureSource::test_gputemp()
if (device == QString("disable"))
QSKIP("Not supported device, test will be skipped");
- QSignalSpy spy(gputempSource, SIGNAL(dataReceived(const QVariantHash &)));
- float firstValue = gputempSource->data(source).toFloat();
- QCOMPARE(firstValue, 0.0f);
+ QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
+ float firstValue = source->data(src).toFloat();
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
- float secondValue = arguments[source].toFloat();
+ float secondValue = arguments[src].toFloat();
+
+ QCOMPARE(firstValue, 0.0f);
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
}
diff --git a/sources/test/testgputempsource.h b/sources/test/testgputempsource.h
index f095066..74458e0 100644
--- a/sources/test/testgputempsource.h
+++ b/sources/test/testgputempsource.h
@@ -37,10 +37,10 @@ private slots:
void test_gputemp();
private:
- GPUTemperatureSource *gputempSource = nullptr;
+ GPUTemperatureSource *source = nullptr;
QString device;
- QString source = QString("gpu/temperature");
- QPair temp = QPair(0.0f, 40.0f);
+ QString src = QString("gpu/temperature");
+ QPair temp = QPair(0.0f, 120.0f);
};
diff --git a/sources/test/testhddtempsource.cpp b/sources/test/testhddtempsource.cpp
index de4914b..bccd587 100644
--- a/sources/test/testhddtempsource.cpp
+++ b/sources/test/testhddtempsource.cpp
@@ -60,12 +60,13 @@ void TestHDDTemperatureSource::test_hddtemp()
QSignalSpy spy(hddtempSource,
SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = hddtempSource->data(device).toFloat();
- QCOMPARE(firstValue, 0.0f);
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
device.remove(QString("hdd/temperature"));
float secondValue = arguments[device].toFloat();
+
+ QCOMPARE(firstValue, 0.0f);
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
});
}
@@ -77,12 +78,13 @@ void TestHDDTemperatureSource::test_smartctl()
QSignalSpy spy(smartctlSource,
SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = smartctlSource->data(device).toFloat();
- QCOMPARE(firstValue, 0.0f);
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
device.remove(QString("hdd/temperature"));
float secondValue = arguments[device].toFloat();
+
+ QCOMPARE(firstValue, 0.0f);
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
});
}
diff --git a/sources/test/testhddtempsource.h b/sources/test/testhddtempsource.h
index b558692..b790938 100644
--- a/sources/test/testhddtempsource.h
+++ b/sources/test/testhddtempsource.h
@@ -43,7 +43,7 @@ private:
QStringList devices;
QString hddtempCmd = QString("sudo hddtemp");
QString smartctlCmd = QString("sudo smartctl -a");
- QPair temp = QPair(0.0f, 40.0f);
+ QPair temp = QPair(0.0f, 120.0f);
};