mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
fix battery tests
This commit is contained in:
parent
e5a9e99438
commit
423eabd857
@ -52,18 +52,22 @@ QStringList BatterySource::getSources()
|
|||||||
sources.append("battery/batrate");
|
sources.append("battery/batrate");
|
||||||
sources.append("battery/battotal");
|
sources.append("battery/battotal");
|
||||||
|
|
||||||
m_batteriesCount
|
auto directory = QDir(m_acpiPath);
|
||||||
= QDir(m_acpiPath)
|
|
||||||
.entryList(QStringList({"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++) {
|
if (directory.exists()) {
|
||||||
sources.append(QString("battery/bat%1").arg(i));
|
m_batteriesCount
|
||||||
sources.append(QString("battery/batleft%1").arg(i));
|
= directory
|
||||||
sources.append(QString("battery/batnow%1").arg(i));
|
.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)
|
||||||
sources.append(QString("battery/batrate%1").arg(i));
|
.count();
|
||||||
sources.append(QString("battery/battotal%1").arg(i));
|
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));
|
||||||
|
sources.append(QString("battery/batleft%1").arg(i));
|
||||||
|
sources.append(QString("battery/batnow%1").arg(i));
|
||||||
|
sources.append(QString("battery/batrate%1").arg(i));
|
||||||
|
sources.append(QString("battery/battotal%1").arg(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qCInfo(LOG_ESS) << "Sources list" << sources;
|
qCInfo(LOG_ESS) << "Sources list" << sources;
|
||||||
@ -123,7 +127,7 @@ QVariantMap BatterySource::initialData(const QString &_source) const
|
|||||||
data["name"] = "Full battery capacity";
|
data["name"] = "Full battery capacity";
|
||||||
data["type"] = "integer";
|
data["type"] = "integer";
|
||||||
data["units"] = "";
|
data["units"] = "";
|
||||||
} else if (_source == "battery/batleft") {
|
} else if (_source.startsWith("battery/batleft")) {
|
||||||
data["min"] = 0;
|
data["min"] = 0;
|
||||||
data["max"] = 0;
|
data["max"] = 0;
|
||||||
data["name"] = QString("Battery %1 discharge time").arg(index(_source));
|
data["name"] = QString("Battery %1 discharge time").arg(index(_source));
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include "awtestlibrary.h"
|
#include "awtestlibrary.h"
|
||||||
#include "batterysource.h"
|
#include "batterysource.h"
|
||||||
|
|
||||||
@ -39,13 +41,14 @@ void TestBatterySource::cleanupTestCase()
|
|||||||
|
|
||||||
void TestBatterySource::test_sources()
|
void TestBatterySource::test_sources()
|
||||||
{
|
{
|
||||||
QVERIFY(source->sources().count() >= 2);
|
//
|
||||||
|
QVERIFY(source->sources().count() >= 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestBatterySource::test_battery()
|
void TestBatterySource::test_battery()
|
||||||
{
|
{
|
||||||
if (source->sources().count() == 2)
|
if (source->sources().count() == 6)
|
||||||
QSKIP("No battery found, test will be skipped");
|
QSKIP("No battery found, test will be skipped");
|
||||||
|
|
||||||
QStringList batteries = source->sources();
|
QStringList batteries = source->sources();
|
||||||
@ -54,7 +57,7 @@ void TestBatterySource::test_battery()
|
|||||||
if (bat == "battery/ac")
|
if (bat == "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) || (std::isnan(value.toFloat())));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user