mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-06 02:15:52 +00:00
add tests for extupgrade
This commit is contained in:
148
sources/test/testextupgrade.cpp
Normal file
148
sources/test/testextupgrade.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
/***************************************************************************
|
||||
* 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 "testextupgrade.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "extupgrade.h"
|
||||
|
||||
|
||||
void TestExtUpgrade::initTestCase()
|
||||
{
|
||||
generateRandomStrings();
|
||||
|
||||
extUpgrade = new ExtUpgrade(nullptr);
|
||||
extUpgrade->setInterval(1);
|
||||
extUpgrade->setExecutable(cmd);
|
||||
extUpgrade->setNumber(0);
|
||||
|
||||
extUpgrade->run();
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::cleanupTestCase()
|
||||
{
|
||||
delete extUpgrade;
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_values()
|
||||
{
|
||||
QCOMPARE(extUpgrade->interval(), 1);
|
||||
QCOMPARE(extUpgrade->number(), 0);
|
||||
QCOMPARE(extUpgrade->executable(), cmd);
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_run()
|
||||
{
|
||||
// init spy
|
||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
QVariantHash firstValue = extUpgrade->run();
|
||||
QCOMPARE(firstValue[extUpgrade->tag(QString("pkgcount"))].toInt(), 0);
|
||||
|
||||
// check values
|
||||
QVERIFY(spy.wait(5000));
|
||||
QList<QVariant> arguments = spy.takeFirst();
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
|
||||
randomStrings.count());
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_null()
|
||||
{
|
||||
int null = rand() % randomStrings.count();
|
||||
extUpgrade->setNull(null);
|
||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
extUpgrade->run();
|
||||
|
||||
// check values
|
||||
QVERIFY(spy.wait(5000));
|
||||
QList<QVariant> arguments = spy.takeFirst();
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
|
||||
randomStrings.count() - null);
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_filter()
|
||||
{
|
||||
QSet<QString> filters;
|
||||
int count = rand() % randomStrings.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
int index = rand() % randomStrings.count();
|
||||
filters << randomStrings.at(index);
|
||||
}
|
||||
|
||||
extUpgrade->setFilter(
|
||||
QString("(^%1$)").arg(filters.toList().join(QString("$|^"))));
|
||||
// init spy
|
||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||
extUpgrade->run();
|
||||
|
||||
// check values
|
||||
QVERIFY(spy.wait(5000));
|
||||
QList<QVariant> arguments = spy.takeFirst();
|
||||
QCOMPARE(
|
||||
arguments.at(0).toHash()[extUpgrade->tag(QString("pkgcount"))].toInt(),
|
||||
filters.count());
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::test_copy()
|
||||
{
|
||||
ExtUpgrade *newExtUpgrade = extUpgrade->copy(QString("/dev/null"), 1);
|
||||
|
||||
QCOMPARE(newExtUpgrade->interval(), extUpgrade->interval());
|
||||
QCOMPARE(newExtUpgrade->executable(), extUpgrade->executable());
|
||||
QCOMPARE(newExtUpgrade->filter(), extUpgrade->filter());
|
||||
QCOMPARE(newExtUpgrade->null(), extUpgrade->null());
|
||||
QCOMPARE(newExtUpgrade->number(), 1);
|
||||
|
||||
delete newExtUpgrade;
|
||||
}
|
||||
|
||||
|
||||
QString TestExtUpgrade::generateRandomString() const
|
||||
{
|
||||
QString string;
|
||||
int diff = 'Z' - 'A';
|
||||
int count = rand() % 100 + 1;
|
||||
for (int i = 0; i < count; i++) {
|
||||
char c = 'A' + (rand() % diff);
|
||||
string += QChar(c);
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
void TestExtUpgrade::generateRandomStrings()
|
||||
{
|
||||
randomStrings.clear();
|
||||
|
||||
int count = rand() % 100 + 1;
|
||||
for (int i = 0; i < count; i++)
|
||||
randomStrings.append(generateRandomString());
|
||||
cmd = QString("echo -e '%1'").arg(randomStrings.join(QString("\n")));
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestExtUpgrade);
|
Reference in New Issue
Block a user