awesome-widgets/sources/test/testextupgrade.cpp
2023-05-17 03:42:40 +03:00

115 lines
3.7 KiB
C++

/***************************************************************************
* 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 "awtestlibrary.h"
#include "extupgrade.h"
void TestExtUpgrade::initTestCase()
{
AWTestLibrary::init();
randomStrings = AWTestLibrary::randomStringList();
cmd = QString("echo -e '%1'").arg(randomStrings.join("\n"));
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();
// check values
QVERIFY(spy.wait(5000));
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(firstValue[extUpgrade->tag("pkgcount")].toInt(), 0);
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count());
}
void TestExtUpgrade::test_null()
{
int null = AWTestLibrary::randomInt(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("pkgcount")].toInt(), randomStrings.count() - null);
}
void TestExtUpgrade::test_filter()
{
QStringList filters = AWTestLibrary::randomSelect(randomStrings);
extUpgrade->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
// 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("pkgcount")].toInt(), filters.count());
}
void TestExtUpgrade::test_copy()
{
ExtUpgrade *newExtUpgrade = extUpgrade->copy("/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;
}
QTEST_MAIN(TestExtUpgrade);