mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
add test for abstractextitem
This commit is contained in:
parent
2a257de1e6
commit
fd3ed61191
@ -70,10 +70,10 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||
|
||||
QString AbstractExtItem::writtableConfig() const
|
||||
{
|
||||
QStringList paths = m_fileName.split(QChar('/'));
|
||||
|
||||
QString name = paths.takeLast();
|
||||
QString dir = paths.takeLast();
|
||||
QString path = m_fileName;
|
||||
QString name = QFileInfo(path).fileName();
|
||||
path.remove(path.count() - name.count() - 1, name.count() + 1);
|
||||
QString dir = QFileInfo(path).fileName();
|
||||
|
||||
return QString("%1/awesomewidgets/%2/%3")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
|
@ -72,7 +72,7 @@ public slots:
|
||||
virtual void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QString m_fileName = QString("/dev/null");
|
||||
virtual void translate() = 0;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
|
@ -11,18 +11,24 @@ include_directories(
|
||||
${Kf5_INCLUDE}
|
||||
)
|
||||
|
||||
# extscript
|
||||
set(EXTSCRIPT_HEADERS testextscript.h)
|
||||
set(EXTSCRIPT_SOURCES testextscript.cpp)
|
||||
add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES})
|
||||
target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript)
|
||||
# abstractextitem
|
||||
set(ABSTRACTEXTITEM_HEADERS testabstractextitem.h)
|
||||
set(ABSTRACTEXTITEM_SOURCES testabstractextitem.cpp)
|
||||
add_executable(${SUBPROJECT}-abstractextitem ${ABSTRACTEXTITEM_HEADERS} ${ABSTRACTEXTITEM_SOURCES})
|
||||
target_link_libraries(${SUBPROJECT}-abstractextitem ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
add_test(NAME "AbstractExtItem" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-abstractextitem)
|
||||
# extquotes
|
||||
set(EXTQUOTES_HEADERS testextquotes.h)
|
||||
set(EXTQUOTES_SOURCES testextquotes.cpp)
|
||||
add_executable(${SUBPROJECT}-extquotes ${EXTQUOTES_HEADERS} ${EXTQUOTES_SOURCES})
|
||||
target_link_libraries(${SUBPROJECT}-extquotes ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
add_test(NAME "ExtQuotes" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extquotes)
|
||||
# extscript
|
||||
set(EXTSCRIPT_HEADERS testextscript.h)
|
||||
set(EXTSCRIPT_SOURCES testextscript.cpp)
|
||||
add_executable(${SUBPROJECT}-extscript ${EXTSCRIPT_HEADERS} ${EXTSCRIPT_SOURCES})
|
||||
target_link_libraries(${SUBPROJECT}-extscript ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
add_test(NAME "ExtScript" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-extscript)
|
||||
# extupgrade
|
||||
set(EXTUPGRADE_HEADERS testextupgrade.h)
|
||||
set(EXTUPGRADE_SOURCES testextupgrade.cpp)
|
||||
|
127
sources/test/testabstractextitem.cpp
Normal file
127
sources/test/testabstractextitem.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/***************************************************************************
|
||||
* 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 "testabstractextitem.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "extupgrade.h"
|
||||
|
||||
|
||||
void TestAbstractExtItem::initTestCase()
|
||||
{
|
||||
generateFilename();
|
||||
|
||||
extItem = new ExtUpgrade(nullptr, fileName);
|
||||
extItem->setActive(false);
|
||||
extItem->setApiVersion(1);
|
||||
extItem->setComment(comment);
|
||||
extItem->setName(name);
|
||||
extItem->setNumber(-1);
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::cleanupTestCase()
|
||||
{
|
||||
QFile::remove(fileName);
|
||||
delete extItem;
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::test_values()
|
||||
{
|
||||
QCOMPARE(extItem->isActive(), false);
|
||||
QCOMPARE(extItem->apiVersion(), 1);
|
||||
QCOMPARE(extItem->comment(), comment);
|
||||
QCOMPARE(extItem->fileName(), fileName);
|
||||
QCOMPARE(extItem->name(), name);
|
||||
QVERIFY((extItem->number() > 0) && (extItem->number() < 1000));
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::test_writtableFile()
|
||||
{
|
||||
QCOMPARE(extItem->writtableConfig(), writeFileName);
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::test_configuration()
|
||||
{
|
||||
extItem->writeConfiguration();
|
||||
|
||||
ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName);
|
||||
QCOMPARE(newExtItem->isActive(), extItem->isActive());
|
||||
QCOMPARE(newExtItem->comment(), extItem->comment());
|
||||
QCOMPARE(newExtItem->fileName(), writeFileName);
|
||||
QCOMPARE(newExtItem->name(), extItem->name());
|
||||
QCOMPARE(newExtItem->number(), extItem->number());
|
||||
|
||||
delete newExtItem;
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::test_bumpApi()
|
||||
{
|
||||
extItem->bumpApi(100500);
|
||||
|
||||
QCOMPARE(extItem->apiVersion(), 100500);
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::test_delete()
|
||||
{
|
||||
ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName);
|
||||
|
||||
QVERIFY(newExtItem->tryDelete());
|
||||
QVERIFY(!QFile::exists(writeFileName));
|
||||
|
||||
delete newExtItem;
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::test_copy()
|
||||
{
|
||||
ExtUpgrade *newExtItem = extItem->copy(QString("/dev/null"), 1);
|
||||
|
||||
QCOMPARE(newExtItem->isActive(), extItem->isActive());
|
||||
QCOMPARE(newExtItem->apiVersion(), extItem->apiVersion());
|
||||
QCOMPARE(newExtItem->comment(), extItem->comment());
|
||||
QCOMPARE(newExtItem->name(), extItem->name());
|
||||
|
||||
delete newExtItem;
|
||||
}
|
||||
|
||||
|
||||
void TestAbstractExtItem::generateFilename()
|
||||
{
|
||||
fileName = QString("%1/").arg(
|
||||
QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||
writeFileName = QString("%1/awesomewidgets/tmp/")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
int diff = 'Z' - 'A';
|
||||
int count = rand() % 20 + 1;
|
||||
for (int i = 0; i < count; i++) {
|
||||
char c = 'A' + (rand() % diff);
|
||||
fileName += QChar(c);
|
||||
writeFileName += QChar(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestAbstractExtItem);
|
54
sources/test/testabstractextitem.h
Normal file
54
sources/test/testabstractextitem.h
Normal file
@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef TESTABSTRACTEXTITEM_H
|
||||
#define TESTABSTRACTEXTITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class ExtUpgrade;
|
||||
|
||||
class TestAbstractExtItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// initialization
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_values();
|
||||
void test_writtableFile();
|
||||
void test_configuration();
|
||||
void test_bumpApi();
|
||||
void test_delete();
|
||||
void test_copy();
|
||||
|
||||
private:
|
||||
void generateFilename();
|
||||
ExtUpgrade *extItem = nullptr;
|
||||
QString comment = QString("A comment");
|
||||
QString name = QString("A name");
|
||||
QString fileName;
|
||||
QString writeFileName;
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTABSTRACTEXTITEM_H */
|
@ -117,8 +117,8 @@ 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(QString("weather"))].toString().startsWith(
|
||||
QString("<img")));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user