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