diff --git a/tests/features/CMakeLists.txt b/tests/features/CMakeLists.txt --- a/tests/features/CMakeLists.txt +++ b/tests/features/CMakeLists.txt @@ -6,10 +6,13 @@ set(CUCUMBER_CWD ${CMAKE_CURRENT_SOURCE_DIR}/..) set(zanshin-cuke-steps "${CMAKE_CURRENT_BINARY_DIR}/step_definitions/zanshin-cuke-steps 2>&1") + + + # cucumber with akonadi fake rules + configure_file(cucumber-run.sh.in cucumber-run.sh) - find_program(_akonaditest akonaditest) - set(cucumber-run-cmd ${_akonaditest} -c ${CMAKE_CURRENT_SOURCE_DIR}/testenv/config.xml sh ${CMAKE_CURRENT_BINARY_DIR}/cucumber-run.sh 2> ${CMAKE_CURRENT_BINARY_DIR}/akonaditest.log) + set(cucumber-run-cmd sh ${CMAKE_CURRENT_BINARY_DIR}/cucumber-run.sh ${CMAKE_CURRENT_SOURCE_DIR}/testenv/kdehome/testdata.xml) add_custom_target(cucumber-run COMMAND ${cucumber-run-cmd} @@ -21,6 +24,23 @@ WORKING_DIRECTORY ${CUCUMBER_CWD} ) + # Default test target add_test(zanshin-features-done make cucumber-run-done) + # cucumber within akonaditest rules + + configure_file(cucumber-akonadi-run.sh.in cucumber-akonadi-run.sh) + find_program(_akonaditest akonaditest) + set(cucumber-akonadi-run-cmd ${_akonaditest} -c ${CMAKE_CURRENT_SOURCE_DIR}/testenv/config.xml sh ${CMAKE_CURRENT_BINARY_DIR}/cucumber-akonadi-run.sh 2> ${CMAKE_CURRENT_BINARY_DIR}/akonaditest.log) + + add_custom_target(cucumber-akonadi-run + COMMAND ${cucumber-akonadi-run-cmd} + WORKING_DIRECTORY ${CUCUMBER_CWD} + ) + + add_custom_target(cucumber-akonadi-run-done + COMMAND ${cucumber-akonadi-run-cmd} --tags ~@wip + WORKING_DIRECTORY ${CUCUMBER_CWD} + ) + endif() diff --git a/tests/features/cucumber-run.sh.in b/tests/features/cucumber-akonadi-run.sh.in copy from tests/features/cucumber-run.sh.in copy to tests/features/cucumber-akonadi-run.sh.in diff --git a/tests/features/cucumber-run.sh.in b/tests/features/cucumber-run.sh.in --- a/tests/features/cucumber-run.sh.in +++ b/tests/features/cucumber-run.sh.in @@ -8,15 +8,8 @@ trap "restorepwd" EXIT -echo -echo "======================" -echo - -# Make sure the resource is fully synchronized -# It wasn't necessary until the big code style change in akonadiserver -# Not so innocuous heh ;-) -KNUT_RESOURCE="org.freedesktop.Akonadi.Resource.akonadi_knut_resource_0.$AKONADI_INSTANCE" -qdbus $KNUT_RESOURCE / org.freedesktop.Akonadi.Resource.synchronize +export ZANSHIN_USER_XMLDATA=$1 +shift cd @CUCUMBER_CWD@ @zanshin-cuke-steps@ & diff --git a/tests/features/step_definitions/main.cpp b/tests/features/step_definitions/main.cpp --- a/tests/features/step_definitions/main.cpp +++ b/tests/features/step_definitions/main.cpp @@ -22,6 +22,8 @@ #include "utils/dependencymanager.h" #include "utils/jobhandler.h" +#include "testlib/akonadifakedata.h" +#include "testlib/akonadifakedataxmlloader.h" #include "testlib/monitorspy.h" #include "testlib/testsafety.h" @@ -63,11 +65,42 @@ { qputenv("ZANSHIN_OVERRIDE_DATETIME", "2015-03-10"); - App::initializeDependencies(); - - if (!TestLib::TestSafety::checkTestIsIsolated()) { - qDebug() << "FATAL ERROR! SEE ABOVE\n\n"; - exit(1); + static bool initializedDependencies = false; + + if (!initializedDependencies) { + App::initializeDependencies(); + + QString xmlFile = QString::fromLocal8Bit(qgetenv("ZANSHIN_USER_XMLDATA")); + if (!xmlFile.isEmpty()) { + auto searchCollection = Akonadi::Collection(1); + searchCollection.setParentCollection(Akonadi::Collection::root()); + searchCollection.setName("Search"); + m_data.createCollection(searchCollection); + + MonitorSpy::setExpirationDelay(200); + auto loader = Testlib::AkonadiFakeDataXmlLoader(&m_data); + loader.load(xmlFile); + + // Swap regular dependencies for the fake data ones + auto &deps = Utils::DependencyManager::globalInstance(); + deps.add( + [this] (Utils::DependencyManager *) { + return m_data.createMonitor(); + } + ); + deps.add( + [this] (Utils::DependencyManager *) { + return m_data.createStorage(); + } + ); + } else if (!TestLib::TestSafety::checkTestIsIsolated()) { + qDebug() << "FATAL ERROR! SEE ABOVE\n\n"; + exit(1); + } + + initializedDependencies = true; } using namespace Presentation; @@ -136,13 +169,17 @@ QList dragIndices; private: + static Testlib::AkonadiFakeData m_data; + QSortFilterProxyModel *proxyModel; QAbstractItemModel *m_model; QAbstractItemModel *m_sourceModel; MonitorSpy *monitorSpy; FakeErrorHandler m_errorHandler; }; +Testlib::AkonadiFakeData ZanshinContext::m_data = {}; + namespace Zanshin { QString indexString(const QModelIndex &index, int role = Qt::DisplayRole)