mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
more correct test class for extscripts
This commit is contained in:
parent
ea7c15d865
commit
72f0d4587b
@ -35,8 +35,8 @@ AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys)
|
|||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
editButton = ui->buttonBox->addButton(i18n("Edit"),
|
editButton
|
||||||
QDialogButtonBox::ActionRole);
|
= ui->buttonBox->addButton(i18n("Edit"), QDialogButtonBox::ActionRole);
|
||||||
init();
|
init();
|
||||||
|
|
||||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
@ -95,8 +95,8 @@ bool AWFormatterHelper::writeFormatters(const QStringList keys) const
|
|||||||
qCDebug(LOG_AW) << "Remove formatters" << keys;
|
qCDebug(LOG_AW) << "Remove formatters" << keys;
|
||||||
|
|
||||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||||
.arg(QStandardPaths::writableLocation(
|
.arg(QStandardPaths::writableLocation(
|
||||||
QStandardPaths::GenericDataLocation));
|
QStandardPaths::GenericDataLocation));
|
||||||
QSettings settings(fileName, QSettings::IniFormat);
|
QSettings settings(fileName, QSettings::IniFormat);
|
||||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||||
|
|
||||||
|
@ -194,12 +194,14 @@ QString AWKeyOperations::infoByKey(QString key) const
|
|||||||
else if (key.startsWith(QString("custom")))
|
else if (key.startsWith(QString("custom")))
|
||||||
return extScripts->itemByTag(key, QString("custom"))->uniq();
|
return extScripts->itemByTag(key, QString("custom"))->uniq();
|
||||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
||||||
return QString("%1").arg(m_devices[QString(
|
return QString("%1").arg(
|
||||||
"disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
m_devices[QString("disk")]
|
||||||
|
[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||||
else if (key.contains(QRegExp(
|
else if (key.contains(QRegExp(
|
||||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
||||||
return QString("%1").arg(m_devices[QString(
|
return QString("%1").arg(
|
||||||
"mount")][key
|
m_devices[QString("mount")]
|
||||||
|
[key
|
||||||
.remove(QRegExp(QString(
|
.remove(QRegExp(QString(
|
||||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||||
.toInt()]);
|
.toInt()]);
|
||||||
@ -207,8 +209,9 @@ QString AWKeyOperations::infoByKey(QString key) const
|
|||||||
return QString("%1").arg(
|
return QString("%1").arg(
|
||||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
||||||
return QString("%1").arg(m_devices[QString(
|
return QString("%1").arg(
|
||||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
m_devices[QString("net")]
|
||||||
|
[key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||||
else if (key.startsWith(QString("pkgcount")))
|
else if (key.startsWith(QString("pkgcount")))
|
||||||
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
|
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
|
||||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
||||||
|
@ -61,6 +61,9 @@ public:
|
|||||||
void setName(const QString _name = QString("none"));
|
void setName(const QString _name = QString("none"));
|
||||||
void setNumber(int _number = -1);
|
void setNumber(int _number = -1);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataReceived(const QVariantHash &data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void readConfiguration();
|
virtual void readConfiguration();
|
||||||
virtual QVariantHash run() = 0;
|
virtual QVariantHash run() = 0;
|
||||||
|
@ -32,7 +32,8 @@ class AWDateTimeFormatter : public AWAbstractFormatter
|
|||||||
Q_PROPERTY(QString format READ format WRITE setFormat)
|
Q_PROPERTY(QString format READ format WRITE setFormat)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWDateTimeFormatter(QWidget *parent, const QString filePath = QString());
|
explicit AWDateTimeFormatter(QWidget *parent,
|
||||||
|
const QString filePath = QString());
|
||||||
virtual ~AWDateTimeFormatter();
|
virtual ~AWDateTimeFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWDateTimeFormatter *copy(const QString _fileName, const int _number);
|
AWDateTimeFormatter *copy(const QString _fileName, const int _number);
|
||||||
|
@ -37,7 +37,8 @@ class AWFloatFormatter : public AWAbstractFormatter
|
|||||||
Q_PROPERTY(double summand READ summand WRITE setSummand)
|
Q_PROPERTY(double summand READ summand WRITE setSummand)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWFloatFormatter(QWidget *parent, const QString filePath = QString());
|
explicit AWFloatFormatter(QWidget *parent,
|
||||||
|
const QString filePath = QString());
|
||||||
virtual ~AWFloatFormatter();
|
virtual ~AWFloatFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWFloatFormatter *copy(const QString _fileName, const int _number);
|
AWFloatFormatter *copy(const QString _fileName, const int _number);
|
||||||
|
@ -35,7 +35,8 @@ class AWScriptFormatter : public AWAbstractFormatter
|
|||||||
Q_PROPERTY(QString program READ program)
|
Q_PROPERTY(QString program READ program)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWScriptFormatter(QWidget *parent, const QString filePath = QString());
|
explicit AWScriptFormatter(QWidget *parent,
|
||||||
|
const QString filePath = QString());
|
||||||
virtual ~AWScriptFormatter();
|
virtual ~AWScriptFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWScriptFormatter *copy(const QString _fileName, const int _number);
|
AWScriptFormatter *copy(const QString _fileName, const int _number);
|
||||||
|
@ -38,8 +38,7 @@ class ExtQuotes : public AbstractExtItem
|
|||||||
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExtQuotes(QWidget *parent,
|
explicit ExtQuotes(QWidget *parent, const QString filePath = QString());
|
||||||
const QString filePath = QString());
|
|
||||||
virtual ~ExtQuotes();
|
virtual ~ExtQuotes();
|
||||||
ExtQuotes *copy(const QString _fileName, const int _number);
|
ExtQuotes *copy(const QString _fileName, const int _number);
|
||||||
// get methods
|
// get methods
|
||||||
|
@ -263,6 +263,9 @@ QVariantHash ExtScript::run()
|
|||||||
{
|
{
|
||||||
if (!isActive())
|
if (!isActive())
|
||||||
return value;
|
return value;
|
||||||
|
if (process->state() != QProcess::NotRunning)
|
||||||
|
qCWarning(LOG_LIB) << "Another process is already running"
|
||||||
|
<< process->state();
|
||||||
|
|
||||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||||
QStringList cmdList;
|
QStringList cmdList;
|
||||||
@ -375,6 +378,7 @@ void ExtScript::updateValue()
|
|||||||
|
|
||||||
// filters
|
// filters
|
||||||
value[tag(QString("custom"))] = applyFilters(strValue);
|
value[tag(QString("custom"))] = applyFilters(strValue);
|
||||||
|
emit(dataReceived(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +39,7 @@ class ExtScript : public AbstractExtItem
|
|||||||
public:
|
public:
|
||||||
enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap };
|
enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap };
|
||||||
|
|
||||||
explicit ExtScript(QWidget *parent,
|
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
||||||
const QString filePath = QString());
|
|
||||||
virtual ~ExtScript();
|
virtual ~ExtScript();
|
||||||
ExtScript *copy(const QString _fileName, const int _number);
|
ExtScript *copy(const QString _fileName, const int _number);
|
||||||
// get methods
|
// get methods
|
||||||
|
@ -36,8 +36,7 @@ class ExtUpgrade : public AbstractExtItem
|
|||||||
Q_PROPERTY(int null READ null WRITE setNull)
|
Q_PROPERTY(int null READ null WRITE setNull)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExtUpgrade(QWidget *parent,
|
explicit ExtUpgrade(QWidget *parent, const QString filePath = QString());
|
||||||
const QString filePath = QString());
|
|
||||||
virtual ~ExtUpgrade();
|
virtual ~ExtUpgrade();
|
||||||
ExtUpgrade *copy(const QString _fileName, const int _number);
|
ExtUpgrade *copy(const QString _fileName, const int _number);
|
||||||
// get methods
|
// get methods
|
||||||
|
@ -42,8 +42,7 @@ class ExtWeather : public AbstractExtItem
|
|||||||
Q_PROPERTY(int ts READ ts WRITE setTs)
|
Q_PROPERTY(int ts READ ts WRITE setTs)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExtWeather(QWidget *parent,
|
explicit ExtWeather(QWidget *parent, const QString filePath = QString());
|
||||||
const QString filePath = QString());
|
|
||||||
virtual ~ExtWeather();
|
virtual ~ExtWeather();
|
||||||
ExtWeather *copy(const QString _fileName, const int _number);
|
ExtWeather *copy(const QString _fileName, const int _number);
|
||||||
QString weatherFromInt(const int _id) const;
|
QString weatherFromInt(const int _id) const;
|
||||||
|
@ -52,8 +52,7 @@ public:
|
|||||||
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
||||||
enum class Type { Horizontal, Vertical, Circle, Graph, Bars };
|
enum class Type { Horizontal, Vertical, Circle, Graph, Bars };
|
||||||
|
|
||||||
explicit GraphicalItem(QWidget *parent,
|
explicit GraphicalItem(QWidget *parent, const QString filePath = QString());
|
||||||
const QString filePath = QString());
|
|
||||||
virtual ~GraphicalItem();
|
virtual ~GraphicalItem();
|
||||||
GraphicalItem *copy(const QString _fileName, const int _number);
|
GraphicalItem *copy(const QString _fileName, const int _number);
|
||||||
QString image(const QVariant &value);
|
QString image(const QVariant &value);
|
||||||
|
@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const
|
|||||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||||
[&toolTipScene, &screen](WindowData data) {
|
[&toolTipScene, &screen](WindowData data) {
|
||||||
QPixmap desktop = screen->grabWindow(data.id);
|
QPixmap desktop = screen->grabWindow(data.id);
|
||||||
toolTipScene->addPixmap(desktop)
|
toolTipScene->addPixmap(desktop)->setOffset(
|
||||||
->setOffset(data.rect.left(), data.rect.top());
|
data.rect.left(), data.rect.top());
|
||||||
});
|
});
|
||||||
} else if (m_tooltipType == QString("windows")) {
|
} else if (m_tooltipType == QString("windows")) {
|
||||||
QScreen *screen = QGuiApplication::primaryScreen();
|
QScreen *screen = QGuiApplication::primaryScreen();
|
||||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||||
[&toolTipScene, &screen](WindowData data) {
|
[&toolTipScene, &screen](WindowData data) {
|
||||||
QPixmap desktop = screen->grabWindow(data.id);
|
QPixmap desktop = screen->grabWindow(data.id);
|
||||||
toolTipScene->addPixmap(desktop)
|
toolTipScene->addPixmap(desktop)->setOffset(
|
||||||
->setOffset(data.rect.left(), data.rect.top());
|
data.rect.left(), data.rect.top());
|
||||||
});
|
});
|
||||||
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
|
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
|
||||||
[&toolTipScene, &screen](WindowData data) {
|
[&toolTipScene, &screen](WindowData data) {
|
||||||
QPixmap window = screen->grabWindow(data.id);
|
QPixmap window = screen->grabWindow(data.id);
|
||||||
toolTipScene->addPixmap(window)
|
toolTipScene->addPixmap(window)->setOffset(
|
||||||
->setOffset(data.rect.left(), data.rect.top());
|
data.rect.left(), data.rect.top());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const
|
|||||||
.arg(currentMark, m_mark.count(), QLatin1Char(' '))
|
.arg(currentMark, m_mark.count(), QLatin1Char(' '))
|
||||||
.replace(QString(" "), QString(" "));
|
.replace(QString(" "), QString(" "));
|
||||||
else if (key == QString("name"))
|
else if (key == QString("name"))
|
||||||
return KWindowSystem::desktopName(desktop)
|
return KWindowSystem::desktopName(desktop).replace(QString(" "),
|
||||||
.replace(QString(" "), QString(" "));
|
QString(" "));
|
||||||
else if (key == QString("number"))
|
else if (key == QString("number"))
|
||||||
return QString::number(desktop);
|
return QString::number(desktop);
|
||||||
else if (key == QString("total"))
|
else if (key == QString("total"))
|
||||||
|
@ -125,8 +125,8 @@ void ExtendedSysMon::readConfiguration()
|
|||||||
|
|
||||||
settings.beginGroup(QString("Configuration"));
|
settings.beginGroup(QString("Configuration"));
|
||||||
rawConfig[QString("ACPIPATH")]
|
rawConfig[QString("ACPIPATH")]
|
||||||
= settings.value(QString("ACPIPATH"),
|
= settings
|
||||||
QString("/sys/class/power_supply/"))
|
.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"))
|
||||||
.toString();
|
.toString();
|
||||||
rawConfig[QString("GPUDEV")]
|
rawConfig[QString("GPUDEV")]
|
||||||
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
||||||
|
@ -29,11 +29,12 @@ void TestExtScript::initTestCase()
|
|||||||
extScript = new ExtScript(nullptr);
|
extScript = new ExtScript(nullptr);
|
||||||
extScript->setInterval(1);
|
extScript->setInterval(1);
|
||||||
extScript->setExecutable(QString("hello world"));
|
extScript->setExecutable(QString("hello world"));
|
||||||
|
extScript->setNumber(0);
|
||||||
extScript->setRedirect(ExtScript::Redirect::stderr2stdout);
|
extScript->setRedirect(ExtScript::Redirect::stderr2stdout);
|
||||||
extScript->setPrefix(QString("echo"));
|
extScript->setPrefix(QString("echo"));
|
||||||
|
|
||||||
while (true)
|
QVariantHash value = extScript->run();
|
||||||
qDebug() <<extScript->run();
|
qDebug() << "Init values in first run" << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,26 +47,43 @@ void TestExtScript::cleanupTestCase()
|
|||||||
void TestExtScript::test_values()
|
void TestExtScript::test_values()
|
||||||
{
|
{
|
||||||
QCOMPARE(extScript->interval(), 1);
|
QCOMPARE(extScript->interval(), 1);
|
||||||
|
QCOMPARE(extScript->number(), 0);
|
||||||
QCOMPARE(extScript->executable(), QString("hello world"));
|
QCOMPARE(extScript->executable(), QString("hello world"));
|
||||||
|
QCOMPARE(extScript->strRedirect(), QString("stderr2stdout"));
|
||||||
QCOMPARE(extScript->prefix(), QString("echo"));
|
QCOMPARE(extScript->prefix(), QString("echo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtScript::test_firstRun()
|
void TestExtScript::test_run()
|
||||||
{
|
{
|
||||||
|
// init spy
|
||||||
|
QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extScript->run();
|
QVariantHash firstValue = extScript->run();
|
||||||
qDebug() << firstValue;
|
QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(),
|
||||||
QTest::qSleep(20000);
|
QString(""));
|
||||||
QCOMPARE(firstValue[extScript->tag(QString("custom"))].toString(), QString(""));
|
|
||||||
QTest::qSleep(20000);
|
// check values
|
||||||
|
QVERIFY(spy.wait(5000));
|
||||||
|
QList<QVariant> arguments = spy.takeFirst();
|
||||||
|
QCOMPARE(
|
||||||
|
arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(),
|
||||||
|
QString("\nhello world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtScript::test_secondRun()
|
void TestExtScript::test_filters()
|
||||||
{
|
{
|
||||||
QVariantHash secondValue = extScript->run();
|
extScript->setFilters(QStringList() << QString("newline"));
|
||||||
qDebug() << secondValue;
|
// init spy
|
||||||
QCOMPARE(secondValue[extScript->tag(QString("custom"))].toString(), QString("hello world"));
|
QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
|
extScript->run();
|
||||||
|
|
||||||
|
// check values
|
||||||
|
QVERIFY(spy.wait(5000));
|
||||||
|
QList<QVariant> arguments = spy.takeFirst();
|
||||||
|
QCOMPARE(
|
||||||
|
arguments.at(0).toHash()[extScript->tag(QString("custom"))].toString(),
|
||||||
|
QString("<br>hello world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class ExtScript;
|
class ExtScript;
|
||||||
|
class QSignalSpy;
|
||||||
|
|
||||||
class TestExtScript : public QObject
|
class TestExtScript : public QObject
|
||||||
{
|
{
|
||||||
@ -35,8 +36,8 @@ private slots:
|
|||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
// test
|
// test
|
||||||
void test_values();
|
void test_values();
|
||||||
void test_firstRun();
|
void test_run();
|
||||||
void test_secondRun();
|
void test_filters();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExtScript *extScript = nullptr;
|
ExtScript *extScript = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user