From 4a0da3f978195fb816291100a06a62a3b9772289 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 22 Jun 2016 01:04:57 +0300 Subject: [PATCH] add dpplugin tests --- sources/test/CMakeLists.txt | 12 ++++- sources/test/testdpplugin.cpp | 94 +++++++++++++++++++++++++++++++++++ sources/test/testdpplugin.h | 47 ++++++++++++++++++ 3 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 sources/test/testdpplugin.cpp create mode 100644 sources/test/testdpplugin.h diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 493b378..ba199a9 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -8,6 +8,8 @@ include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/ + ${CMAKE_CURRENT_SOURCE_DIR}/../desktop-panel/plugin/ ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} ${Qt5Test_INCLUDE_DIRS} @@ -19,17 +21,23 @@ set(AWTESTLIBRARY_HEADERS awtestlibrary.h) set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp) add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS}) target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} + ${Qt_LIBRARIES} ${Kf5_LIBRARIES} ${Qt5Test_LIBRARIES}) ## modules set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather abstractformatter datetimeformatter floatformatter noformatter scriptformatter extitemaggregator - batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource) + batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource + dpplugin) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) + if (TEST_MODULE MATCHES "dpplugin") + set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../desktop-panel/plugin/dpadds.cpp + ${PROJECT_TRDPARTY_DIR}/fontdialog/fontdialog.cpp) + endif(TEST_MODULE MATCHES "dpplugin") add_executable(${SUBPROJECT}-${TEST_MODULE} ${${TEST_MODULE}_HEADERS} ${${TEST_MODULE}_SOURCES}) target_link_libraries(${SUBPROJECT}-${TEST_MODULE} ${LIBRARY_TEST_SET}) add_test(NAME ${TEST_MODULE} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-${TEST_MODULE}) diff --git a/sources/test/testdpplugin.cpp b/sources/test/testdpplugin.cpp new file mode 100644 index 0000000..9a4e166 --- /dev/null +++ b/sources/test/testdpplugin.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * 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 "testdpplugin.h" + +#include +#include + +#include "awtestlibrary.h" +#include "dpadds.h" + + +void TestDPPlugin::initTestCase() +{ + plugin = new DPAdds(this); +} + + +void TestDPPlugin::cleanupTestCase() +{ + delete plugin; +} + + +void TestDPPlugin::test_desktops() +{ + int current = plugin->currentDesktop(); + int total = plugin->numberOfDesktops(); + QVERIFY(total != 0); + QVERIFY(current < total); + + int number; + if (total == 1) + number = current; + else + number = current == (total - 1) ? current - 1 : current + 1; + QSignalSpy spy(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int))); + plugin->setCurrentDesktop(number); + QVERIFY(spy.wait(5000)); + QCOMPARE(plugin->currentDesktop(), number); + + plugin->setCurrentDesktop(current); + QVERIFY(spy.wait(5000)); + QCOMPARE(plugin->currentDesktop(), current); +} + + +void TestDPPlugin::test_dictKeys() +{ + QCOMPARE(plugin->dictKeys().count(), 4); + pattern += plugin->dictKeys().join(QString(" $")); +} + + +void TestDPPlugin::test_parsePattern() +{ + QString result = plugin->parsePattern(pattern, plugin->currentDesktop()); + QVERIFY(!result.isEmpty()); + QVERIFY(result != pattern); + for (auto key : plugin->dictKeys()) + QVERIFY(!result.contains(key)); +} + + +void TestDPPlugin::test_tooltipImage() +{ + QVariantMap data; + data[QString("tooltipColor")] = QString("#000000"); + data[QString("tooltipType")] = QString("windows"); + data[QString("tooltipWidth")] = 300; + plugin->setToolTipData(data); + + QString image = plugin->toolTipImage(plugin->currentDesktop()); + QVERIFY(image.startsWith(QString(""))); +} + + +QTEST_MAIN(TestDPPlugin); diff --git a/sources/test/testdpplugin.h b/sources/test/testdpplugin.h new file mode 100644 index 0000000..71d89d6 --- /dev/null +++ b/sources/test/testdpplugin.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * 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 TESTDPPLUGIN_H +#define TESTDPPLUGIN_H + +#include + + +class DPAdds; + +class TestDPPlugin : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_desktops(); + void test_dictKeys(); + void test_tooltipImage(); + void test_parsePattern(); + +private: + DPAdds *plugin = nullptr; + QString pattern = QString("$"); +}; + + +#endif /* TESTDPPLUGIN_H */