Skip to content

Commit b4ac9e6

Browse files
committed
Tests: Support for plugin tests
Plugins can implement own tests. Added basic tests for ItemSync. Command "keys" can send key presses to modal dialogs.
1 parent 527ffbc commit b4ac9e6

22 files changed

+911
-200
lines changed

CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ endif()
5151

5252
# Tests always on with debug version
5353
if(CMAKE_BUILD_TYPE MATCHES Debug)
54+
message(STATUS "Building with tests.")
55+
5456
set(WITH_TESTS ON)
55-
add_definitions( -DCOPYQ_LOG_DEBUG )
57+
add_definitions( -DHAS_TESTS -DCOPYQ_LOG_DEBUG )
58+
59+
if (WITH_QT5)
60+
list(APPEND copyq_Qt5_Modules Test)
61+
else()
62+
set(QT_USE_QTTEST TRUE)
63+
endif()
5664
endif()
5765

5866
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")

plugins/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ macro (copyq_add_plugin)
1111
*.ui
1212
)
1313

14+
if (WITH_TESTS)
15+
file(GLOB copyq_plugin_SOURCES ${copyq_plugin_SOURCES} tests/*.cpp)
16+
endif (WITH_TESTS)
17+
1418
include_directories(${CMAKE_CURRENT_BINARY_DIR} ../../src)
1519

1620
if (WITH_QT5)
@@ -35,7 +39,7 @@ macro (copyq_add_plugin)
3539
COMPILE_DEFINITIONS "${copyq_plugin_${copyq_pkg}_DEFINITIONS}")
3640

3741
if (WITH_QT5)
38-
qt5_use_modules(${copyq_pkg} Widgets ${copyq_plugin_${copyq_pkg}_Qt5_Modules})
42+
qt5_use_modules(${copyq_pkg} Widgets ${copyq_Qt5_Modules} ${copyq_plugin_${copyq_pkg}_Qt5_Modules})
3943
else()
4044
include(${QT_USE_FILE})
4145
endif()

plugins/itemsync/itemsync.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "gui/iconwidget.h"
2929
#include "item/serialize.h"
3030

31+
#ifdef HAS_TESTS
32+
# include "tests/itemsynctests.h"
33+
#endif
34+
3135
#include <QBoxLayout>
3236
#include <QCryptographicHash>
3337
#include <QDir>
@@ -1305,7 +1309,22 @@ QVariantMap ItemSyncLoader::applySettings()
13051309

13061310
void ItemSyncLoader::loadSettings(const QVariantMap &settings)
13071311
{
1312+
#ifdef HAS_TESTS
1313+
if ( QCoreApplication::applicationName() == "copyq.test" ) {
1314+
QStringList tabPaths;
1315+
for (int i = 0; i < 10; ++i) {
1316+
tabPaths.append(testTab(i));
1317+
tabPaths.append(testDir(i));
1318+
}
1319+
QVariantList formatSettings;
1320+
m_settings[configSyncTabs] = tabPaths;
1321+
m_settings[configFormatSettings] = formatSettings;
1322+
} else {
1323+
m_settings = settings;
1324+
}
1325+
#else
13081326
m_settings = settings;
1327+
#endif
13091328

13101329
m_tabPaths.clear();
13111330
const QStringList tabPaths = m_settings.value(configSyncTabs).toStringList();
@@ -1569,6 +1588,16 @@ bool ItemSyncLoader::matches(const QModelIndex &index, const QRegExp &re) const
15691588
return re.indexIn(text) != -1;
15701589
}
15711590

1591+
QObject *ItemSyncLoader::tests(const TestInterfacePtr &test) const
1592+
{
1593+
#ifdef HAS_TESTS
1594+
return new ItemSyncTests(test);
1595+
#else
1596+
Q_UNUSED(test);
1597+
return NULL;
1598+
#endif
1599+
}
1600+
15721601
void ItemSyncLoader::removeWatcher(QObject *watcher)
15731602
{
15741603
foreach ( const QObject *model, m_watchers.keys() ) {

plugins/itemsync/itemsync.h

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class ItemSyncLoader : public QObject, public ItemLoaderInterface
140140

141141
virtual bool matches(const QModelIndex &index, const QRegExp &re) const;
142142

143+
virtual QObject *tests(const TestInterfacePtr &test) const;
144+
143145
private slots:
144146
void removeWatcher(QObject *watcher);
145147
void removeModel();

plugins/itemsync/itemsync.pro

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ SOURCES += \
1111
../../src/gui/iconwidget.cpp \
1212
../../src/item/serialize.cpp
1313
FORMS += itemsyncsettings.ui
14-
TARGET = $$qtLibraryTarget(itemsync)
14+
15+
CONFIG(debug, debug|release) {
16+
SOURCES += tests/itemsynctests.cpp
17+
HEADERS += tests/itemsynctests.h
18+
}
19+
20+
TARGET = $$qtLibraryTarget(itemsync)
1521

0 commit comments

Comments
 (0)