initial plasma6 support

This commit is contained in:
2024-03-07 12:09:46 +02:00
parent eecb128865
commit 4d01b87088
176 changed files with 2569 additions and 3795 deletions

View File

@ -13,23 +13,23 @@ include_directories(
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Qt5Test_INCLUDE_DIRS}
${Kf5_INCLUDE}
${Kf6_INCLUDE}
)
# library
set(AWTESTLIBRARY_HEADERS awtestlibrary.h)
set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp)
add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS})
target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES} ${Kf5_LIBRARIES})
target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt6Test_LIBRARIES} ${Kf6_LIBRARIES})
set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES}
${Qt_LIBRARIES} ${Kf5_LIBRARIES} ${Qt5Test_LIBRARIES})
${Qt_LIBRARIES} ${Kf6_LIBRARIES} ${Qt6Test_LIBRARIES})
# modules
set(TEST_MODULES
abstractextitem extquotes extscript extupgrade extweather
abstractformatter datetimeformatter floatformatter jsonformatter listformatter noformatter scriptformatter stringformatter
extitemaggregator
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource
batterysource desktopsource networksource playersource processessource
awbugreporter awconfighelper awkeycache awkeys awpatternfunctions awtelemetryhandler awupdatehelper
dpplugin)
foreach (TEST_MODULE ${TEST_MODULES})

View File

@ -18,6 +18,7 @@
#include "testawpatternfunctions.h"
#include <QRegularExpression>
#include <QtTest>
#include "awpatternfunctions.h"
@ -57,7 +58,7 @@ void TestAWPatternFunctions::test_findKeys()
QStringList allKeys;
for (int i = 0; i < count; i++) {
auto key = AWTestLibrary::randomString(1, 20);
while (allKeys.indexOf(QRegExp(QString("^%1.*").arg(key))) != -1)
while (allKeys.indexOf(QRegularExpression(QString("^%1.*").arg(key))) != -1)
key = AWTestLibrary::randomString(1, 20);
allKeys.append(key);
}

View File

@ -49,15 +49,15 @@ void TestAWDateTimeFormatter::test_values()
void TestAWDateTimeFormatter::test_conversion()
{
QDateTime now = QDateTime::currentDateTime();
QCOMPARE(formatter->convert(now), now.toString(format));
auto now = QDateTime::currentDateTime();
QCOMPARE(formatter->convert(now), QLocale::system().toString(now, format));
}
void TestAWDateTimeFormatter::test_copy()
{
formatter->setTranslateString(false);
AWDateTimeFormatter *newFormatter = formatter->copy("/dev/null", 1);
auto *newFormatter = formatter->copy("/dev/null", 1);
QCOMPARE(newFormatter->format(), formatter->format());
QCOMPARE(newFormatter->translateString(), formatter->translateString());

View File

@ -1,66 +0,0 @@
/***************************************************************************
* 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()
{
AWTestLibrary::init();
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 == "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);

View File

@ -1,48 +0,0 @@
/***************************************************************************
* 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>
#include <QPair>
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 = "gpu/load";
QPair<float, float> load = QPair<float, float>(0.0f, 100.0f);
};
#endif /* TESTGPULOADSOURCE_H */

View File

@ -1,67 +0,0 @@
/***************************************************************************
* 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 "testgputempsource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "gpuloadsource.h"
#include "gputempsource.h"
void TestGPUTemperatureSource::initTestCase()
{
AWTestLibrary::init();
device = GPULoadSource::autoGpu();
QVERIFY(!device.isEmpty());
source = new GPUTemperatureSource(this, QStringList() << device);
}
void TestGPUTemperatureSource::cleanupTestCase()
{
delete source;
}
void TestGPUTemperatureSource::test_sources()
{
QCOMPARE(source->sources(), QStringList() << src);
}
void TestGPUTemperatureSource::test_gputemp()
{
if (device == "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 >= temp.first) && (secondValue <= temp.second));
}
QTEST_MAIN(TestGPUTemperatureSource);

View File

@ -1,48 +0,0 @@
/***************************************************************************
* 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 TESTGPUTEMPSOURCE_H
#define TESTGPUTEMPSOURCE_H
#include <QObject>
#include <QPair>
class GPUTemperatureSource;
class TestGPUTemperatureSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_gputemp();
private:
GPUTemperatureSource *source = nullptr;
QString device;
QString src = "gpu/temperature";
QPair<float, float> temp = QPair<float, float>(0.0f, 120.0f);
};
#endif /* TESTGPUTEMPSOURCE_H */

View File

@ -1,96 +0,0 @@
/***************************************************************************
* 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 "testhddtempsource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "hddtempsource.h"
void TestHDDTemperatureSource::initTestCase()
{
AWTestLibrary::init();
devices = HDDTemperatureSource::allHdd();
hddtempSource = new HDDTemperatureSource(this, QStringList() << devices.join(',') << hddtempCmd);
smartctlSource = new HDDTemperatureSource(this, QStringList() << devices.join(',') << smartctlCmd);
}
void TestHDDTemperatureSource::cleanupTestCase()
{
delete hddtempSource;
delete smartctlSource;
}
void TestHDDTemperatureSource::test_sources()
{
if (devices.isEmpty())
QSKIP("No hdd devices found, test will be skipped");
std::for_each(devices.begin(), devices.end(), [](QString &device) { device.prepend("hdd/temperature"); });
QCOMPARE(hddtempSource->sources(), devices);
QCOMPARE(smartctlSource->sources(), devices);
}
void TestHDDTemperatureSource::test_hddtemp()
{
if (devices.isEmpty())
QSKIP("No hdd devices found, test will be skipped");
std::for_each(devices.begin(), devices.end(), [this](QString device) {
QSignalSpy spy(hddtempSource, SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = hddtempSource->data(device).toFloat();
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
device.remove("hdd/temperature");
float secondValue = arguments[device].toFloat();
QCOMPARE(firstValue, 0.0f);
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
});
}
void TestHDDTemperatureSource::test_smartctl()
{
if (devices.isEmpty())
QSKIP("No hdd devices found, test will be skipped");
std::for_each(devices.begin(), devices.end(), [this](QString &device) {
QSignalSpy spy(smartctlSource, SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = smartctlSource->data(device).toFloat();
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
device.remove("hdd/temperature");
float secondValue = arguments[device].toFloat();
QCOMPARE(firstValue, 0.0f);
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
});
}
QTEST_MAIN(TestHDDTemperatureSource);

View File

@ -1,51 +0,0 @@
/***************************************************************************
* 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 TESTHDDTEMPSOURCE_H
#define TESTHDDTEMPSOURCE_H
#include <QObject>
#include <QPair>
class HDDTemperatureSource;
class TestHDDTemperatureSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_hddtemp();
void test_smartctl();
private:
HDDTemperatureSource *hddtempSource = nullptr;
HDDTemperatureSource *smartctlSource = nullptr;
QStringList devices;
QString hddtempCmd = "sudo hddtemp";
QString smartctlCmd = "sudo smartctl -a";
QPair<float, float> temp = QPair<float, float>(0.0f, 120.0f);
};
#endif /* TESTHDDTEMPSOURCE_H */

View File

@ -39,13 +39,13 @@ void TestNetworkSource::cleanupTestCase()
void TestNetworkSource::test_sources()
{
QCOMPARE(source->sources(), QStringList() << src << "network/current/ssid");
QCOMPARE(source->sources(), QStringList({"device", "ssid"}));
}
void TestNetworkSource::test_values()
{
QVERIFY(source->data(src).toString().count() > 0);
QVERIFY(source->data("device").toString().length() > 0);
}

View File

@ -38,7 +38,6 @@ private slots:
private:
NetworkSource *source = nullptr;
QString src = "network/current/name";
};

View File

@ -43,23 +43,23 @@ void TestPlayerSource::test_buildString()
{
QString randomString = AWTestLibrary::randomString(1, 40);
QString str = PlayerSource::buildString("", randomString, 20);
QCOMPARE(str.count(), 20);
QCOMPARE(str.length(), 20);
str = PlayerSource::buildString(str, randomString, 20);
QCOMPARE(str.count(), 20);
QCOMPARE(str.length(), 20);
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
QCOMPARE(str.count(), 20);
QCOMPARE(str.length(), 20);
}
void TestPlayerSource::test_stripString()
{
QString str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 40), 20);
QCOMPARE(str.count(), 20);
QCOMPARE(str.length(), 20);
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
QCOMPARE(str.count(), 20);
QCOMPARE(str.length(), 20);
}
@ -85,7 +85,7 @@ void TestPlayerSource::test_mpd()
// init spy
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
QVariant firstValue = source->data("player/title");
QVariant firstValue = source->data("title");
if (!source->isMpdSocketConnected())
QSKIP("No mpd found");
@ -95,10 +95,10 @@ void TestPlayerSource::test_mpd()
QVariantHash secondValue = arguments.at(0).toHash();
// actually nothing to test here just print warning if no information found
if (secondValue["player/title"].toString() == "unknown")
if (secondValue["title"].toString() == "unknown")
QSKIP("No mpd found");
QVERIFY(secondValue["player/progress"].toInt() < secondValue["player/duration"].toInt());
QVERIFY(secondValue["progress"].toInt() < secondValue["duration"].toInt());
}
@ -109,9 +109,9 @@ void TestPlayerSource::test_mpris()
PlayerSource *source = new PlayerSource(this, args);
_test_sources(source);
QString value = source->data("player/title").toString();
int progress = source->data("player/progress").toInt();
int duration = source->data("player/duration").toInt();
QString value = source->data("title").toString();
int progress = source->data("progress").toInt();
int duration = source->data("duration").toInt();
// actually nothing to test here just print warning if no information found
if (value == "unknown")

View File

@ -45,9 +45,9 @@ void TestProcessesSource::test_sources()
void TestProcessesSource::test_values()
{
QVERIFY(source->data("ps/running/count").toInt() > 0);
QVERIFY(source->data("ps/running/list").toStringList().count() > 0);
QVERIFY(source->data("ps/total/count").toInt() > 0);
QVERIFY(source->data("running").toInt() > 0);
QVERIFY(source->data("list").toStringList().count() > 0);
QVERIFY(source->data("count").toInt() > 0);
}