mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-15 06:45:48 +00:00
add tests for battery and gpuload sources
+ some tests refactoring
This commit is contained in:
@ -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)
|
||||
|
61
sources/test/testbatterysource.cpp
Normal file
61
sources/test/testbatterysource.cpp
Normal file
@ -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 <QtTest>
|
||||
|
||||
#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);
|
46
sources/test/testbatterysource.h
Normal file
46
sources/test/testbatterysource.h
Normal file
@ -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 <QObject>
|
||||
|
||||
|
||||
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<int, int> battery = QPair<int, int>(0, 100);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTBATTERYSOURCE_H */
|
@ -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)
|
||||
|
@ -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<QVariant> 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));
|
||||
|
@ -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<QVariant> arguments = spy.takeFirst();
|
||||
|
||||
QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0);
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
|
||||
randomStrings.count());
|
||||
|
65
sources/test/testgpuloadsource.cpp
Normal file
65
sources/test/testgpuloadsource.cpp
Normal file
@ -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 <QtTest>
|
||||
|
||||
#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);
|
47
sources/test/testgpuloadsource.h
Normal file
47
sources/test/testgpuloadsource.h
Normal file
@ -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 <QObject>
|
||||
|
||||
|
||||
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<float, float> load = QPair<float, float>(0.0f, 100.0f);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTGPULOADSOURCE_H */
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,10 @@ private slots:
|
||||
void test_gputemp();
|
||||
|
||||
private:
|
||||
GPUTemperatureSource *gputempSource = nullptr;
|
||||
GPUTemperatureSource *source = nullptr;
|
||||
QString device;
|
||||
QString source = QString("gpu/temperature");
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 40.0f);
|
||||
QString src = QString("gpu/temperature");
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 120.0f);
|
||||
};
|
||||
|
||||
|
||||
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
QStringList devices;
|
||||
QString hddtempCmd = QString("sudo hddtemp");
|
||||
QString smartctlCmd = QString("sudo smartctl -a");
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 40.0f);
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 120.0f);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user