mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-06 10:25:52 +00:00
massive refactoring
This commit is contained in:
@ -73,29 +73,29 @@ QPair<QString, QString> AWTestLibrary::randomFilenames()
|
||||
}
|
||||
|
||||
|
||||
int AWTestLibrary::randomInt(const int max)
|
||||
int AWTestLibrary::randomInt(const int _max)
|
||||
{
|
||||
return qrand() % max;
|
||||
return qrand() % _max;
|
||||
}
|
||||
|
||||
|
||||
QString AWTestLibrary::randomString(const int min, const int max)
|
||||
QString AWTestLibrary::randomString(const int _min, const int _max)
|
||||
{
|
||||
QString output;
|
||||
|
||||
int count = min + randomInt(max - min);
|
||||
int count = _min + randomInt(_max - _min);
|
||||
for (int i = 0; i < count; i++)
|
||||
output += QChar(randomChar());
|
||||
output += randomChar();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWTestLibrary::randomStringList(const int max)
|
||||
QStringList AWTestLibrary::randomStringList(const int _max)
|
||||
{
|
||||
QStringList output;
|
||||
|
||||
int count = 1 + randomInt(max);
|
||||
int count = 1 + randomInt(_max);
|
||||
for (int i = 0; i < count; i++)
|
||||
output.append(randomString());
|
||||
|
||||
@ -103,14 +103,14 @@ QStringList AWTestLibrary::randomStringList(const int max)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWTestLibrary::randomSelect(const QStringList available)
|
||||
QStringList AWTestLibrary::randomSelect(const QStringList &_available)
|
||||
{
|
||||
QSet<QString> output;
|
||||
|
||||
int count = 1 + randomInt(available.count());
|
||||
int count = 1 + randomInt(_available.count());
|
||||
for (int i = 0; i < count; i++) {
|
||||
int index = randomInt(available.count());
|
||||
output << available.at(index);
|
||||
int index = randomInt(_available.count());
|
||||
output << _available.at(index);
|
||||
}
|
||||
|
||||
return output.toList();
|
||||
|
@ -30,10 +30,10 @@ bool isKWinActive();
|
||||
char randomChar();
|
||||
double randomDouble();
|
||||
QPair<QString, QString> randomFilenames();
|
||||
int randomInt(const int max = 100);
|
||||
QString randomString(const int min = 1, const int max = 100);
|
||||
QStringList randomStringList(const int max = 100);
|
||||
QStringList randomSelect(const QStringList available);
|
||||
int randomInt(const int _max = 100);
|
||||
QString randomString(const int _min = 1, const int _max = 100);
|
||||
QStringList randomStringList(const int _max = 100);
|
||||
QStringList randomSelect(const QStringList &_available);
|
||||
};
|
||||
|
||||
|
||||
|
@ -109,7 +109,7 @@ void TestAbstractExtItem::test_delete()
|
||||
|
||||
void TestAbstractExtItem::test_copy()
|
||||
{
|
||||
ExtUpgrade *newExtItem = extItem->copy(QString("/dev/null"), 1);
|
||||
ExtUpgrade *newExtItem = extItem->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newExtItem->isActive(), extItem->isActive());
|
||||
QCOMPARE(newExtItem->apiVersion(), extItem->apiVersion());
|
||||
|
@ -49,14 +49,14 @@ void TestAbstractFormatter::test_type()
|
||||
formatter->setStrType(type);
|
||||
QCOMPARE(formatter->strType(), type);
|
||||
|
||||
formatter->setStrType(QString("NoFormat"));
|
||||
formatter->setStrType("NoFormat");
|
||||
QCOMPARE(formatter->strType(), QString("NoFormat"));
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractFormatter::test_copy()
|
||||
{
|
||||
AWNoFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWNoFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->type(), formatter->type());
|
||||
QCOMPARE(newFormatter->name(), formatter->name());
|
||||
|
@ -34,34 +34,34 @@ void TestAWKeys::initTestCase()
|
||||
|
||||
// tooltip init
|
||||
QVariantMap tooltipSettings;
|
||||
tooltipSettings[QString("tooltipNumber")] = 1000;
|
||||
tooltipSettings[QString("useTooltipBackground")] = true;
|
||||
tooltipSettings[QString("tooltipBackground")] = QString("#ffffff");
|
||||
tooltipSettings[QString("cpuTooltip")] = true;
|
||||
tooltipSettings[QString("cpuclTooltip")] = true;
|
||||
tooltipSettings[QString("memTooltip")] = true;
|
||||
tooltipSettings[QString("swapTooltip")] = true;
|
||||
tooltipSettings[QString("downkbTooltip")] = true;
|
||||
tooltipSettings[QString("upkbTooltip")] = true;
|
||||
tooltipSettings[QString("batTooltip")] = true;
|
||||
tooltipSettings[QString("cpuTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("cpuclTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("memTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("swapTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("downkbTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("upkbTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("batTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("batInTooltipColor")] = QString("#ffffff");
|
||||
tooltipSettings[QString("acOnline")] = QString("(*)");
|
||||
tooltipSettings[QString("notify")] = false;
|
||||
tooltipSettings["tooltipNumber"] = 1000;
|
||||
tooltipSettings["useTooltipBackground"] = true;
|
||||
tooltipSettings["tooltipBackground"] = "#ffffff";
|
||||
tooltipSettings["cpuTooltip"] = true;
|
||||
tooltipSettings["cpuclTooltip"] = true;
|
||||
tooltipSettings["memTooltip"] = true;
|
||||
tooltipSettings["swapTooltip"] = true;
|
||||
tooltipSettings["downkbTooltip"] = true;
|
||||
tooltipSettings["upkbTooltip"] = true;
|
||||
tooltipSettings["batTooltip"] = true;
|
||||
tooltipSettings["cpuTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["cpuclTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["memTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["swapTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["downkbTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["upkbTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["batTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["batInTooltipColor"] = "#ffffff";
|
||||
tooltipSettings["acOnline"] = "(*)";
|
||||
tooltipSettings["notify"] = false;
|
||||
plugin->initDataAggregator(tooltipSettings);
|
||||
|
||||
// aggregator init
|
||||
plugin->setAggregatorProperty("acOffline", QString("( )"));
|
||||
plugin->setAggregatorProperty("acOnline", QString("(*)"));
|
||||
plugin->setAggregatorProperty("customTime", QString("$hh"));
|
||||
plugin->setAggregatorProperty("customUptime", QString("$hh"));
|
||||
plugin->setAggregatorProperty("tempUnits", QString("Celsius"));
|
||||
plugin->setAggregatorProperty("acOffline", "( )");
|
||||
plugin->setAggregatorProperty("acOnline", "(*)");
|
||||
plugin->setAggregatorProperty("customTime", "$hh");
|
||||
plugin->setAggregatorProperty("customUptime", "$hh");
|
||||
plugin->setAggregatorProperty("tempUnits", "Celsius");
|
||||
plugin->setAggregatorProperty("translate", false);
|
||||
|
||||
plugin->initKeys(pattern, interval, 0, false);
|
||||
@ -90,7 +90,7 @@ void TestAWKeys::test_dictKeys()
|
||||
QEXPECT_FAIL("", "Sorted and non-sorted lists should differ", Continue);
|
||||
QCOMPARE(keys, sorted);
|
||||
|
||||
pattern = QString("$%1").arg(sorted.join(QString("\n$")));
|
||||
pattern = QString("$%1").arg(sorted.join("\n$"));
|
||||
}
|
||||
|
||||
|
||||
@ -120,7 +120,7 @@ void TestAWKeys::test_tooltip()
|
||||
|
||||
QVERIFY(spy.wait(5 * interval));
|
||||
QString text = spy.takeFirst().at(0).toString();
|
||||
QVERIFY(text.startsWith(QString("<img")));
|
||||
QVERIFY(text.startsWith("<img"));
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +147,7 @@ void TestAWKeys::test_infoByKey()
|
||||
QString info = plugin->infoByKey(key);
|
||||
QVERIFY(!info.isEmpty());
|
||||
// append non-empty field count
|
||||
if (info != QString("(none)"))
|
||||
if (info != "(none)")
|
||||
notEmpty++;
|
||||
}
|
||||
QVERIFY(notEmpty > 0);
|
||||
@ -176,9 +176,8 @@ void TestAWKeys::test_dbus()
|
||||
|
||||
// create connection and message
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
QDBusMessage request
|
||||
= QDBusMessage::createMethodCall(AWDBUS_SERVICE, QString("/%1").arg(id),
|
||||
AWDBUS_SERVICE, QString("WhoAmI"));
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(
|
||||
AWDBUS_SERVICE, QString("/%1").arg(id), AWDBUS_SERVICE, "WhoAmI");
|
||||
// send message to dbus
|
||||
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
|
||||
|
||||
|
@ -40,10 +40,8 @@ void TestAWPatternFunctions::test_findFunctionCalls()
|
||||
QString name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10));
|
||||
QString code = AWTestLibrary::randomString(1, 20);
|
||||
QStringList args = AWTestLibrary::randomStringList(20);
|
||||
QString function = QString("$%1<%2>{{%3}}")
|
||||
.arg(name)
|
||||
.arg(args.join(QChar(',')))
|
||||
.arg(code);
|
||||
QString function
|
||||
= QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code);
|
||||
|
||||
QString pattern = AWTestLibrary::randomString() + function
|
||||
+ AWTestLibrary::randomString();
|
||||
@ -72,10 +70,9 @@ void TestAWPatternFunctions::test_findKeys()
|
||||
auto keys = AWTestLibrary::randomSelect(allKeys);
|
||||
auto bars = AWTestLibrary::randomSelect(allKeys);
|
||||
std::for_each(bars.begin(), bars.end(),
|
||||
[](QString &bar) { bar.prepend(QString("bar")); });
|
||||
QString pattern = QString("$%1 $%2")
|
||||
.arg(keys.join(QString(" $")))
|
||||
.arg(bars.join(QString(" $")));
|
||||
[](QString &bar) { bar.prepend("bar"); });
|
||||
QString pattern
|
||||
= QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
|
||||
|
||||
allKeys.append(bars);
|
||||
allKeys.sort();
|
||||
@ -99,7 +96,7 @@ void TestAWPatternFunctions::test_findLambdas()
|
||||
{
|
||||
QStringList lambdas = AWTestLibrary::randomStringList(20);
|
||||
QString pattern = AWTestLibrary::randomString()
|
||||
+ QString("${{%1}}").arg(lambdas.join(QString("}}${{")))
|
||||
+ QString("${{%1}}").arg(lambdas.join("}}${{"))
|
||||
+ AWTestLibrary::randomString();
|
||||
|
||||
QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas);
|
||||
|
@ -64,13 +64,13 @@ void TestAWTelemetryHandler::test_getLast()
|
||||
|
||||
void TestAWTelemetryHandler::test_uploadTelemetry()
|
||||
{
|
||||
QSignalSpy spy(plugin, SIGNAL(replyReceived(QString &)));
|
||||
QSignalSpy spy(plugin, SIGNAL(replyReceived(const QString &)));
|
||||
plugin->uploadTelemetry(telemetryValidGroup, telemetryData);
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantList arguments = spy.takeFirst();
|
||||
|
||||
QCOMPARE(arguments.at(0).toString(), QString("saved"));
|
||||
QCOMPARE(arguments.at(0).toString(), telemetryStatus);
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,8 +42,9 @@ private:
|
||||
AWTelemetryHandler *plugin = nullptr;
|
||||
QString telemetryData;
|
||||
QString telemetryGroup;
|
||||
QString telemetryId = QString("autotest");
|
||||
QString telemetryValidGroup = QString("awwidgetconfig");
|
||||
QString telemetryId = "autotest";
|
||||
QString telemetryStatus = "saved";
|
||||
QString telemetryValidGroup = "awwidgetconfig";
|
||||
};
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ void TestBatterySource::test_battery()
|
||||
std::for_each(batteries.begin(), batteries.end(),
|
||||
[this](const QString bat) {
|
||||
QVariant value = source->data(bat);
|
||||
if (bat == QString("battery/ac"))
|
||||
if (bat == "battery/ac")
|
||||
QCOMPARE(value.type(), QVariant::Bool);
|
||||
else
|
||||
QVERIFY((value.toFloat() >= battery.first)
|
||||
|
@ -39,7 +39,7 @@ private slots:
|
||||
|
||||
private:
|
||||
BatterySource *source = nullptr;
|
||||
QString acpiPath = QString("/sys/class/power_supply/");
|
||||
QString acpiPath = "/sys/class/power_supply/";
|
||||
QPair<int, int> battery = QPair<int, int>(0, 100);
|
||||
};
|
||||
|
||||
|
@ -28,8 +28,8 @@
|
||||
void TestAWDateTimeFormatter::initTestCase()
|
||||
{
|
||||
AWTestLibrary::init();
|
||||
format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(QChar(',')))
|
||||
.join(QChar(' '));
|
||||
format
|
||||
= AWTestLibrary::randomSelect(QString(TIME_KEYS).split(',')).join(' ');
|
||||
|
||||
formatter = new AWDateTimeFormatter(nullptr);
|
||||
formatter->setFormat(format);
|
||||
@ -58,8 +58,7 @@ void TestAWDateTimeFormatter::test_conversion()
|
||||
void TestAWDateTimeFormatter::test_copy()
|
||||
{
|
||||
formatter->setTranslateString(false);
|
||||
AWDateTimeFormatter *newFormatter
|
||||
= formatter->copy(QString("/dev/null"), 1);
|
||||
AWDateTimeFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->format(), formatter->format());
|
||||
QCOMPARE(newFormatter->translateString(), formatter->translateString());
|
||||
|
@ -45,12 +45,10 @@ void TestDesktopSource::test_sources()
|
||||
|
||||
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);
|
||||
QVERIFY(source->data("desktop/current/name").toString().count() > 0);
|
||||
QVERIFY(source->data("desktop/current/number").toInt() >= 0);
|
||||
QVERIFY(source->data("desktop/total/name").toStringList().count() > 0);
|
||||
QVERIFY(source->data("desktop/total/number").toInt() > 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ void TestDPPlugin::test_dictKeys()
|
||||
QSKIP("KWin inactive, skip Destkop panel tests");
|
||||
|
||||
QCOMPARE(plugin->dictKeys().count(), 4);
|
||||
pattern += plugin->dictKeys().join(QString(" $"));
|
||||
pattern += plugin->dictKeys().join(" $");
|
||||
}
|
||||
|
||||
|
||||
@ -104,14 +104,14 @@ void TestDPPlugin::test_tooltipImage()
|
||||
QSKIP("KWin inactive, skip Destkop panel tests");
|
||||
|
||||
QVariantMap data;
|
||||
data[QString("tooltipColor")] = QString("#000000");
|
||||
data[QString("tooltipType")] = QString("windows");
|
||||
data[QString("tooltipWidth")] = 300;
|
||||
data["tooltipColor"] = "#000000";
|
||||
data["tooltipType"] = "windows";
|
||||
data["tooltipWidth"] = 300;
|
||||
plugin->setToolTipData(data);
|
||||
|
||||
QString image = plugin->toolTipImage(plugin->currentDesktop());
|
||||
QVERIFY(image.startsWith(QString("<img src=\"")));
|
||||
QVERIFY(image.endsWith(QString("\"/>")));
|
||||
QVERIFY(image.startsWith("<img src=\""));
|
||||
QVERIFY(image.endsWith("\"/>"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,7 +42,7 @@ private slots:
|
||||
private:
|
||||
DPAdds *plugin = nullptr;
|
||||
bool m_isKwinActive = false;
|
||||
QString pattern = QString("$");
|
||||
QString pattern = "$";
|
||||
};
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ private slots:
|
||||
|
||||
private:
|
||||
ExtItemAggregator<AWNoFormatter> *aggregator = nullptr;
|
||||
QString type = QString("tmp");
|
||||
QString type = "tmp";
|
||||
};
|
||||
|
||||
|
||||
|
@ -94,7 +94,7 @@ void TestExtQuotes::test_derivatives()
|
||||
|
||||
void TestExtQuotes::test_copy()
|
||||
{
|
||||
ExtQuotes *newExtQuotes = extQuotes->copy(QString("/dev/null"), 1);
|
||||
ExtQuotes *newExtQuotes = extQuotes->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newExtQuotes->interval(), extQuotes->interval());
|
||||
QCOMPARE(newExtQuotes->ticker(), extQuotes->ticker());
|
||||
|
@ -42,9 +42,10 @@ private slots:
|
||||
private:
|
||||
ExtQuotes *extQuotes = nullptr;
|
||||
QVariantHash cache;
|
||||
QString ticker = QString("EURUSD=X");
|
||||
QStringList types = QStringList()
|
||||
<< QString("ask") << QString("bid") << QString("price");
|
||||
QString ticker = "EURUSD=X";
|
||||
QStringList types = QStringList() << "ask"
|
||||
<< "bid"
|
||||
<< "price";
|
||||
// we assume that price will not be differ more than in 2 times
|
||||
QPair<double, double> price = QPair<double, double>(0.5, 2.0);
|
||||
};
|
||||
|
@ -34,7 +34,7 @@ void TestExtScript::initTestCase()
|
||||
extScript->setExecutable(randomString);
|
||||
extScript->setNumber(0);
|
||||
extScript->setRedirect(ExtScript::Redirect::stderr2stdout);
|
||||
extScript->setPrefix(QString("echo"));
|
||||
extScript->setPrefix("echo");
|
||||
|
||||
extScript->run();
|
||||
}
|
||||
@ -66,11 +66,9 @@ void TestExtScript::test_run()
|
||||
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));
|
||||
QCOMPARE(firstValue[extScript->tag("custom")].toString(), QString());
|
||||
QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(),
|
||||
QString("\n%1").arg(randomString));
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +77,7 @@ void TestExtScript::test_filters()
|
||||
if (extScript->jsonFiltersFile().isEmpty())
|
||||
QSKIP("No json filters found for scripts, skip fitlers test");
|
||||
|
||||
extScript->setFilters(QStringList() << QString("newline"));
|
||||
extScript->setFilters(QStringList() << "newline");
|
||||
// init spy
|
||||
QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
extScript->run();
|
||||
@ -87,15 +85,14 @@ void TestExtScript::test_filters()
|
||||
// check values
|
||||
QVERIFY(spy.wait(5000));
|
||||
QList<QVariant> arguments = spy.takeFirst();
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(),
|
||||
QString("<br>%1").arg(randomString));
|
||||
QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(),
|
||||
QString("<br>%1").arg(randomString));
|
||||
}
|
||||
|
||||
|
||||
void TestExtScript::test_copy()
|
||||
{
|
||||
ExtScript *newExtScript = extScript->copy(QString("/dev/null"), 1);
|
||||
ExtScript *newExtScript = extScript->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newExtScript->interval(), extScript->interval());
|
||||
QCOMPARE(newExtScript->executable(), extScript->executable());
|
||||
|
@ -28,7 +28,7 @@ void TestExtUpgrade::initTestCase()
|
||||
{
|
||||
AWTestLibrary::init();
|
||||
randomStrings = AWTestLibrary::randomStringList();
|
||||
cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n")));
|
||||
cmd = QString("echo -e '%1'").arg(randomStrings.join("\n"));
|
||||
|
||||
extUpgrade = new ExtUpgrade(nullptr);
|
||||
extUpgrade->setInterval(1);
|
||||
@ -63,10 +63,9 @@ void TestExtUpgrade::test_run()
|
||||
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());
|
||||
QCOMPARE(firstValue[extUpgrade->tag("pkgcount")].toInt(), 0);
|
||||
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(),
|
||||
randomStrings.count());
|
||||
}
|
||||
|
||||
|
||||
@ -80,16 +79,15 @@ void TestExtUpgrade::test_null()
|
||||
// check values
|
||||
QVERIFY(spy.wait(5000));
|
||||
QList<QVariant> arguments = spy.takeFirst();
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
|
||||
randomStrings.count() - null);
|
||||
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(),
|
||||
randomStrings.count() - null);
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_filter()
|
||||
{
|
||||
QStringList filters = AWTestLibrary::randomSelect(randomStrings);
|
||||
extUpgrade->setFilter(QString("(^%1$)").arg(filters.join(QString("$|^"))));
|
||||
extUpgrade->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
|
||||
// init spy
|
||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
extUpgrade->run();
|
||||
@ -97,15 +95,14 @@ void TestExtUpgrade::test_filter()
|
||||
// check values
|
||||
QVERIFY(spy.wait(5000));
|
||||
QList<QVariant> arguments = spy.takeFirst();
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
|
||||
filters.count());
|
||||
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(),
|
||||
filters.count());
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_copy()
|
||||
{
|
||||
ExtUpgrade *newExtUpgrade = extUpgrade->copy(QString("/dev/null"), 1);
|
||||
ExtUpgrade *newExtUpgrade = extUpgrade->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newExtUpgrade->interval(), extUpgrade->interval());
|
||||
QCOMPARE(newExtUpgrade->executable(), extUpgrade->executable());
|
||||
|
@ -89,14 +89,13 @@ void TestExtWeather::test_image()
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||
QVERIFY(
|
||||
arguments[extWeather->tag(QString("weather"))].toString().startsWith(
|
||||
QString("<img")));
|
||||
arguments[extWeather->tag("weather")].toString().startsWith("<img"));
|
||||
}
|
||||
|
||||
|
||||
void TestExtWeather::test_copy()
|
||||
{
|
||||
ExtWeather *newExtWeather = extWeather->copy(QString("/dev/null"), 1);
|
||||
ExtWeather *newExtWeather = extWeather->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newExtWeather->interval(), extWeather->interval());
|
||||
QCOMPARE(newExtWeather->city(), extWeather->city());
|
||||
@ -120,24 +119,20 @@ void TestExtWeather::run()
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||
QEXPECT_FAIL("", "WeatherID should not be 0", Continue);
|
||||
QCOMPARE(arguments[extWeather->tag(QString("weatherId"))].toInt(), 0);
|
||||
QVERIFY((arguments[extWeather->tag(QString("humidity"))].toInt()
|
||||
>= humidity.first)
|
||||
&& (arguments[extWeather->tag(QString("humidity"))].toInt()
|
||||
<= humidity.second));
|
||||
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toInt()
|
||||
> pressure.first)
|
||||
&& (arguments[extWeather->tag(QString("pressure"))].toInt()
|
||||
< pressure.second));
|
||||
QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat()
|
||||
> temp.first)
|
||||
&& (arguments[extWeather->tag(QString("temperature"))].toFloat()
|
||||
< temp.second));
|
||||
QCOMPARE(arguments[extWeather->tag("weatherId")].toInt(), 0);
|
||||
QVERIFY(
|
||||
(arguments[extWeather->tag("humidity")].toInt() >= humidity.first)
|
||||
&& (arguments[extWeather->tag("humidity")].toInt() <= humidity.second));
|
||||
QVERIFY(
|
||||
(arguments[extWeather->tag("pressure")].toInt() > pressure.first)
|
||||
&& (arguments[extWeather->tag("pressure")].toInt() < pressure.second));
|
||||
QVERIFY(
|
||||
(arguments[extWeather->tag("temperature")].toFloat() > temp.first)
|
||||
&& (arguments[extWeather->tag("temperature")].toFloat() < temp.second));
|
||||
// image should be only one symbol here
|
||||
if (extWeather->jsonMapFile().isEmpty())
|
||||
QSKIP("No json map found for weather, skip image test");
|
||||
QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(),
|
||||
1);
|
||||
QCOMPARE(arguments[extWeather->tag("weather")].toString().count(), 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,8 +44,8 @@ private slots:
|
||||
private:
|
||||
void run();
|
||||
ExtWeather *extWeather = nullptr;
|
||||
QString city = QString("London");
|
||||
QString country = QString("uk");
|
||||
QString city = "London";
|
||||
QString country = "uk";
|
||||
// humidity is in percents
|
||||
QPair<int, int> humidity = QPair<int, int>(0, 100);
|
||||
// pressure should be about 1 atm
|
||||
|
@ -62,13 +62,13 @@ void TestAWFloatFormatter::test_fillChar()
|
||||
{
|
||||
// assign
|
||||
char c = AWTestLibrary::randomChar();
|
||||
formatter->setFillChar(QChar(c));
|
||||
formatter->setFillChar(c);
|
||||
QCOMPARE(formatter->fillChar(), QChar(c));
|
||||
formatter->setCount(101);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomInt());
|
||||
QVERIFY(output.startsWith(QChar(c)));
|
||||
QVERIFY(output.startsWith(c));
|
||||
|
||||
// reset
|
||||
formatter->setFillChar(QChar());
|
||||
@ -121,7 +121,7 @@ void TestAWFloatFormatter::test_precision()
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
output.remove(QString("0."));
|
||||
output.remove("0.");
|
||||
QCOMPARE(output.count(), precision);
|
||||
|
||||
// reset
|
||||
@ -168,7 +168,7 @@ void TestAWFloatFormatter::test_summand()
|
||||
void TestAWFloatFormatter::test_copy()
|
||||
{
|
||||
doRandom();
|
||||
AWFloatFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWFloatFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->count(), formatter->count());
|
||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||
@ -186,7 +186,7 @@ void TestAWFloatFormatter::test_copy()
|
||||
void TestAWFloatFormatter::doRandom()
|
||||
{
|
||||
formatter->setCount(AWTestLibrary::randomInt());
|
||||
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
|
||||
formatter->setFillChar(AWTestLibrary::randomChar());
|
||||
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
|
||||
formatter->setFormat(AWTestLibrary::randomChar());
|
||||
formatter->setMultiplier(AWTestLibrary::randomDouble());
|
||||
|
@ -48,7 +48,7 @@ void TestGPULoadSource::test_sources()
|
||||
|
||||
void TestGPULoadSource::test_gpuload()
|
||||
{
|
||||
if (device == QString("disable"))
|
||||
if (device == "disable")
|
||||
QSKIP("Not supported device, test will be skipped");
|
||||
|
||||
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
|
@ -40,7 +40,7 @@ private slots:
|
||||
private:
|
||||
GPULoadSource *source = nullptr;
|
||||
QString device;
|
||||
QString src = QString("gpu/load");
|
||||
QString src = "gpu/load";
|
||||
QPair<float, float> load = QPair<float, float>(0.0f, 100.0f);
|
||||
};
|
||||
|
||||
|
@ -21,13 +21,14 @@
|
||||
#include <QtTest>
|
||||
|
||||
#include "awtestlibrary.h"
|
||||
#include "gpuloadsource.h"
|
||||
#include "gputempsource.h"
|
||||
|
||||
|
||||
void TestGPUTemperatureSource::initTestCase()
|
||||
{
|
||||
AWTestLibrary::init();
|
||||
device = GPUTemperatureSource::autoGpu();
|
||||
device = GPULoadSource::autoGpu();
|
||||
QVERIFY(!device.isEmpty());
|
||||
|
||||
source = new GPUTemperatureSource(this, QStringList() << device);
|
||||
@ -48,7 +49,7 @@ void TestGPUTemperatureSource::test_sources()
|
||||
|
||||
void TestGPUTemperatureSource::test_gputemp()
|
||||
{
|
||||
if (device == QString("disable"))
|
||||
if (device == "disable")
|
||||
QSKIP("Not supported device, test will be skipped");
|
||||
|
||||
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
|
@ -40,7 +40,7 @@ private slots:
|
||||
private:
|
||||
GPUTemperatureSource *source = nullptr;
|
||||
QString device;
|
||||
QString src = QString("gpu/temperature");
|
||||
QString src = "gpu/temperature";
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 120.0f);
|
||||
};
|
||||
|
||||
|
@ -31,9 +31,9 @@ void TestHDDTemperatureSource::initTestCase()
|
||||
QVERIFY(devices.count() > 0);
|
||||
|
||||
hddtempSource = new HDDTemperatureSource(
|
||||
this, QStringList() << devices.join(QChar(',')) << hddtempCmd);
|
||||
this, QStringList() << devices.join(',') << hddtempCmd);
|
||||
smartctlSource = new HDDTemperatureSource(
|
||||
this, QStringList() << devices.join(QChar(',')) << smartctlCmd);
|
||||
this, QStringList() << devices.join(',') << smartctlCmd);
|
||||
}
|
||||
|
||||
|
||||
@ -46,9 +46,8 @@ void TestHDDTemperatureSource::cleanupTestCase()
|
||||
|
||||
void TestHDDTemperatureSource::test_sources()
|
||||
{
|
||||
std::for_each(devices.begin(), devices.end(), [](QString &device) {
|
||||
device.prepend(QString("hdd/temperature"));
|
||||
});
|
||||
std::for_each(devices.begin(), devices.end(),
|
||||
[](QString &device) { device.prepend("hdd/temperature"); });
|
||||
|
||||
QCOMPARE(hddtempSource->sources(), devices);
|
||||
QCOMPARE(smartctlSource->sources(), devices);
|
||||
@ -64,7 +63,7 @@ void TestHDDTemperatureSource::test_hddtemp()
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||
device.remove(QString("hdd/temperature"));
|
||||
device.remove("hdd/temperature");
|
||||
float secondValue = arguments[device].toFloat();
|
||||
|
||||
QCOMPARE(firstValue, 0.0f);
|
||||
@ -82,7 +81,7 @@ void TestHDDTemperatureSource::test_smartctl()
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||
device.remove(QString("hdd/temperature"));
|
||||
device.remove("hdd/temperature");
|
||||
float secondValue = arguments[device].toFloat();
|
||||
|
||||
QCOMPARE(firstValue, 0.0f);
|
||||
|
@ -42,8 +42,8 @@ private:
|
||||
HDDTemperatureSource *hddtempSource = nullptr;
|
||||
HDDTemperatureSource *smartctlSource = nullptr;
|
||||
QStringList devices;
|
||||
QString hddtempCmd = QString("sudo hddtemp");
|
||||
QString smartctlCmd = QString("sudo smartctl -a");
|
||||
QString hddtempCmd = "sudo hddtemp";
|
||||
QString smartctlCmd = "sudo smartctl -a";
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 120.0f);
|
||||
};
|
||||
|
||||
|
@ -54,7 +54,7 @@ void TestAWJsonFormatter::test_conversion()
|
||||
|
||||
void TestAWJsonFormatter::test_copy()
|
||||
{
|
||||
AWJsonFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWJsonFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->path(), formatter->path());
|
||||
QCOMPARE(newFormatter->number(), 1);
|
||||
|
@ -71,7 +71,7 @@ void TestAWListFormatter::test_filter()
|
||||
QStringList value = AWTestLibrary::randomStringList();
|
||||
QStringList filters = AWTestLibrary::randomSelect(value);
|
||||
value.sort();
|
||||
formatter->setFilter(QString("(^%1$)").arg(filters.join(QString("$|^"))));
|
||||
formatter->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
|
||||
|
||||
QCOMPARE(formatter->convert(value).split(separator).count(),
|
||||
filters.count());
|
||||
@ -80,7 +80,7 @@ void TestAWListFormatter::test_filter()
|
||||
|
||||
void TestAWListFormatter::test_copy()
|
||||
{
|
||||
AWListFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWListFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->number(), 1);
|
||||
QCOMPARE(newFormatter->filter(), formatter->filter());
|
||||
|
@ -38,7 +38,7 @@ private slots:
|
||||
|
||||
private:
|
||||
NetworkSource *source = nullptr;
|
||||
QString src = QString("network/current/name");
|
||||
QString src = "network/current/name";
|
||||
};
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ void TestAWNoFormatter::test_conversion()
|
||||
|
||||
void TestAWNoFormatter::test_copy()
|
||||
{
|
||||
AWNoFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWNoFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->number(), 1);
|
||||
|
||||
|
@ -35,44 +35,42 @@ void TestPlayerSource::cleanupTestCase()
|
||||
}
|
||||
|
||||
|
||||
void TestPlayerSource::_test_sources(const PlayerSource *source)
|
||||
void TestPlayerSource::_test_sources(const PlayerSource *_source)
|
||||
{
|
||||
QVERIFY(source->sources().count() == 11);
|
||||
QVERIFY(_source->sources().count() == 11);
|
||||
}
|
||||
|
||||
|
||||
void TestPlayerSource::test_buildString()
|
||||
{
|
||||
QString randomString = AWTestLibrary::randomString(1, 40);
|
||||
QString str = PlayerSource::buildString(QString(), randomString, 20);
|
||||
QString str = PlayerSource::buildString("", randomString, 20);
|
||||
QCOMPARE(str.count(), 20);
|
||||
|
||||
str = PlayerSource::buildString(str, randomString, 20);
|
||||
QCOMPARE(str.count(), 20);
|
||||
|
||||
str = PlayerSource::buildString(QString(),
|
||||
AWTestLibrary::randomString(1, 10), 20);
|
||||
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
|
||||
QCOMPARE(str.count(), 20);
|
||||
}
|
||||
|
||||
|
||||
void TestPlayerSource::test_stripString()
|
||||
{
|
||||
QString str = PlayerSource::buildString(
|
||||
QString(), AWTestLibrary::randomString(1, 40), 20);
|
||||
QString str
|
||||
= PlayerSource::buildString("", AWTestLibrary::randomString(1, 40), 20);
|
||||
QCOMPARE(str.count(), 20);
|
||||
|
||||
str = PlayerSource::buildString(QString(),
|
||||
AWTestLibrary::randomString(1, 10), 20);
|
||||
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
|
||||
QCOMPARE(str.count(), 20);
|
||||
}
|
||||
|
||||
|
||||
void TestPlayerSource::test_autoMpris()
|
||||
{
|
||||
QStringList args(QStringList() << QString("mpris") << mpdAddress
|
||||
<< QString::number(mpdPort)
|
||||
<< QString("auto") << QString::number(10));
|
||||
QStringList args(QStringList()
|
||||
<< "mpris" << mpdAddress << QString::number(mpdPort)
|
||||
<< "auto" << QString::number(10));
|
||||
PlayerSource *source = new PlayerSource(this, args);
|
||||
|
||||
bool empty = source->getAutoMpris().isEmpty();
|
||||
@ -86,14 +84,14 @@ void TestPlayerSource::test_autoMpris()
|
||||
void TestPlayerSource::test_mpd()
|
||||
{
|
||||
QStringList args(QStringList()
|
||||
<< QString("mpd") << mpdAddress << QString::number(mpdPort)
|
||||
<< QString("auto") << QString::number(10));
|
||||
<< "mpd" << mpdAddress << QString::number(mpdPort)
|
||||
<< "auto" << QString::number(10));
|
||||
PlayerSource *source = new PlayerSource(this, args);
|
||||
_test_sources(source);
|
||||
|
||||
// init spy
|
||||
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
QVariant firstValue = source->data(QString("player/title"));
|
||||
QVariant firstValue = source->data("player/title");
|
||||
if (!source->isMpdSocketConnected())
|
||||
QSKIP("No mpd found");
|
||||
|
||||
@ -103,28 +101,28 @@ void TestPlayerSource::test_mpd()
|
||||
QVariantHash secondValue = arguments.at(0).toHash();
|
||||
|
||||
// actually nothing to test here just print warning if no information found
|
||||
if (secondValue[QString("player/title")].toString() == QString("unknown"))
|
||||
if (secondValue["player/title"].toString() == "unknown")
|
||||
QSKIP("No mpd found");
|
||||
|
||||
QVERIFY(secondValue[QString("player/progress")].toInt()
|
||||
< secondValue[QString("player/duration")].toInt());
|
||||
QVERIFY(secondValue["player/progress"].toInt()
|
||||
< secondValue["player/duration"].toInt());
|
||||
}
|
||||
|
||||
|
||||
void TestPlayerSource::test_mpris()
|
||||
{
|
||||
QStringList args(QStringList() << QString("mpris") << mpdAddress
|
||||
<< QString::number(mpdPort)
|
||||
<< QString("auto") << QString::number(10));
|
||||
QStringList args(QStringList()
|
||||
<< "mpris" << mpdAddress << QString::number(mpdPort)
|
||||
<< "auto" << QString::number(10));
|
||||
PlayerSource *source = new PlayerSource(this, args);
|
||||
_test_sources(source);
|
||||
|
||||
QString value = source->data(QString("player/title")).toString();
|
||||
int progress = source->data(QString("player/progress")).toInt();
|
||||
int duration = source->data(QString("player/duration")).toInt();
|
||||
QString value = source->data("player/title").toString();
|
||||
int progress = source->data("player/progress").toInt();
|
||||
int duration = source->data("player/duration").toInt();
|
||||
|
||||
// actually nothing to test here just print warning if no information found
|
||||
if (value == QString("unknown"))
|
||||
if (value == "unknown")
|
||||
QSKIP("No mpris found");
|
||||
|
||||
QVERIFY(progress < duration);
|
||||
|
@ -33,7 +33,7 @@ private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void _test_sources(const PlayerSource *source);
|
||||
void _test_sources(const PlayerSource *_source);
|
||||
void test_buildString();
|
||||
void test_stripString();
|
||||
void test_autoMpris();
|
||||
@ -41,7 +41,7 @@ private slots:
|
||||
void test_mpris();
|
||||
|
||||
private:
|
||||
QString mpdAddress = QString("localhost");
|
||||
QString mpdAddress = "localhost";
|
||||
int mpdPort = 6600;
|
||||
};
|
||||
|
||||
|
@ -45,10 +45,9 @@ void TestProcessesSource::test_sources()
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,7 +93,7 @@ void TestAWScriptFormatter::test_hasReturn()
|
||||
|
||||
void TestAWScriptFormatter::test_copy()
|
||||
{
|
||||
AWScriptFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWScriptFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->appendCode(), formatter->appendCode());
|
||||
QCOMPARE(newFormatter->code(), formatter->code());
|
||||
|
@ -41,7 +41,7 @@ private slots:
|
||||
|
||||
private:
|
||||
AWScriptFormatter *formatter = nullptr;
|
||||
QString code = QString("output = value");
|
||||
QString code = "output = value";
|
||||
QString codeWithReturn = QString("%1; return output;").arg(code);
|
||||
QString fullCode = QString("(function(value) { %1 })").arg(codeWithReturn);
|
||||
};
|
||||
|
@ -65,13 +65,13 @@ void TestAWStringFormatter::test_fillChar()
|
||||
{
|
||||
// assign
|
||||
char c = AWTestLibrary::randomChar();
|
||||
formatter->setFillChar(QChar(c));
|
||||
formatter->setFillChar(c);
|
||||
QCOMPARE(formatter->fillChar(), QChar(c));
|
||||
formatter->setCount(101);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QVERIFY(output.startsWith(QChar(c)));
|
||||
QVERIFY(output.startsWith(c));
|
||||
|
||||
// reset
|
||||
formatter->setFillChar(QChar());
|
||||
@ -100,7 +100,7 @@ void TestAWStringFormatter::test_forceWidth()
|
||||
void TestAWStringFormatter::test_copy()
|
||||
{
|
||||
doRandom();
|
||||
AWStringFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
AWStringFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
||||
|
||||
QCOMPARE(newFormatter->count(), formatter->count());
|
||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||
@ -114,7 +114,7 @@ void TestAWStringFormatter::test_copy()
|
||||
void TestAWStringFormatter::doRandom()
|
||||
{
|
||||
formatter->setCount(AWTestLibrary::randomInt());
|
||||
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
|
||||
formatter->setFillChar(AWTestLibrary::randomChar());
|
||||
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user