diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index 18b5639..62e0e09 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -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( diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index 72ea07c..7bdb3a1 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -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; diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 9e0c2f6..2542dc0 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -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) diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp new file mode 100644 index 0000000..dcb48d5 --- /dev/null +++ b/sources/test/testabstractextitem.cpp @@ -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 + +#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); diff --git a/sources/test/testabstractextitem.h b/sources/test/testabstractextitem.h new file mode 100644 index 0000000..4d672ed --- /dev/null +++ b/sources/test/testabstractextitem.h @@ -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 +#include + + +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 */ diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index 97f8a7f..bf41746 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -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("tag(QString("weather"))].toString().startsWith( + QString("