mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
add dpplugin tests
This commit is contained in:
parent
71ae832bcd
commit
4a0da3f978
@ -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})
|
||||
|
94
sources/test/testdpplugin.cpp
Normal file
94
sources/test/testdpplugin.cpp
Normal file
@ -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 <KWindowSystem>
|
||||
#include <QtTest>
|
||||
|
||||
#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("<img src=\"")));
|
||||
QVERIFY(image.endsWith(QString("\"/>")));
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestDPPlugin);
|
47
sources/test/testdpplugin.h
Normal file
47
sources/test/testdpplugin.h
Normal file
@ -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 <QObject>
|
||||
|
||||
|
||||
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 */
|
Loading…
Reference in New Issue
Block a user