diff --git a/src/presentation/applicationmodel.cpp b/src/presentation/applicationmodel.cpp index c02a4bd4..71774d94 100644 --- a/src/presentation/applicationmodel.cpp +++ b/src/presentation/applicationmodel.cpp @@ -1,112 +1,103 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "applicationmodel.h" #include "presentation/artifacteditormodel.h" -#include "presentation/availabletaskpagesmodel.h" +#include "presentation/availablepagesmodelinterface.h" #include "presentation/availablesourcesmodel.h" -#include "presentation/datasourcelistmodel.h" #include "presentation/errorhandler.h" #include "utils/dependencymanager.h" using namespace Presentation; -ApplicationModel::ApplicationModel(const Domain::DataSourceQueries::Ptr &sourceQueries, - const Domain::DataSourceRepository::Ptr &sourceRepository, - const Domain::TaskRepository::Ptr &taskRepository, - const Domain::NoteRepository::Ptr ¬eRepository, - QObject *parent) +ApplicationModel::ApplicationModel(QObject *parent) : QObject(parent), m_currentPage(Q_NULLPTR), - m_sourceQueries(sourceQueries), - m_sourceRepository(sourceRepository), - m_taskRepository(taskRepository), - m_noteRepository(noteRepository), m_errorHandler(Q_NULLPTR) { MetaTypes::registerAll(); } QObject *ApplicationModel::availableSources() { if (!m_availableSources) { auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_availableSources = model; } return m_availableSources.data(); } QObject *ApplicationModel::availablePages() { if (!m_availablePages) { auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_availablePages = model; } return m_availablePages.data(); } QObject *ApplicationModel::currentPage() { return m_currentPage; } QObject *ApplicationModel::editor() { if (!m_editor) { auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_editor = model; } return m_editor.data(); } ErrorHandler *ApplicationModel::errorHandler() const { return m_errorHandler; } void ApplicationModel::setCurrentPage(QObject *page) { if (page == m_currentPage) return; m_currentPage = page; emit currentPageChanged(page); } void ApplicationModel::setErrorHandler(ErrorHandler *errorHandler) { m_errorHandler = errorHandler; if (m_availableSources) m_availableSources.staticCast()->setErrorHandler(errorHandler); if (m_availablePages) m_availablePages.staticCast()->setErrorHandler(errorHandler); if (m_editor) m_editor.staticCast()->setErrorHandler(errorHandler); } diff --git a/src/presentation/applicationmodel.h b/src/presentation/applicationmodel.h index 609dcb5b..67b7c1c0 100644 --- a/src/presentation/applicationmodel.h +++ b/src/presentation/applicationmodel.h @@ -1,86 +1,79 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PRESENTATION_APPLICATIONMODEL_H #define PRESENTATION_APPLICATIONMODEL_H #include #include "domain/datasourcerepository.h" #include "domain/datasourcequeries.h" #include "domain/noterepository.h" #include "domain/taskrepository.h" #include "presentation/metatypes.h" namespace Presentation { class AvailablePagesModelInterface; class ErrorHandler; class ApplicationModel : public QObject { Q_OBJECT Q_PROPERTY(QObject* availableSources READ availableSources) Q_PROPERTY(QObject* availablePages READ availablePages) Q_PROPERTY(QObject* currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged) Q_PROPERTY(QObject* editor READ editor) public: - explicit ApplicationModel(const Domain::DataSourceQueries::Ptr &sourceQueries, - const Domain::DataSourceRepository::Ptr &sourceRepository, - const Domain::TaskRepository::Ptr &taskRepository, - const Domain::NoteRepository::Ptr ¬eRepository, - QObject *parent = Q_NULLPTR); + typedef QSharedPointer Ptr; + + explicit ApplicationModel(QObject *parent = Q_NULLPTR); QObject *availableSources(); QObject *availablePages(); QObject *currentPage(); QObject *editor(); ErrorHandler *errorHandler() const; public slots: void setCurrentPage(QObject *page); void setErrorHandler(ErrorHandler *errorHandler); signals: void currentPageChanged(QObject *page); private: QObjectPtr m_availableSources; QObjectPtr m_availablePages; QObject *m_currentPage; QObjectPtr m_editor; - Domain::DataSourceQueries::Ptr m_sourceQueries; - Domain::DataSourceRepository::Ptr m_sourceRepository; - Domain::TaskRepository::Ptr m_taskRepository; - Domain::NoteRepository::Ptr m_noteRepository; - ErrorHandler *m_errorHandler; }; } #endif // PRESENTATION_APPLICATIONMODEL_H diff --git a/src/renku/app/dependencies.cpp b/src/renku/app/dependencies.cpp index 85adecad..91325d01 100644 --- a/src/renku/app/dependencies.cpp +++ b/src/renku/app/dependencies.cpp @@ -1,143 +1,136 @@ /* This file is part of Renku Notes Copyright 2015 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dependencies.h" #include "akonadi/akonadicontextqueries.h" #include "akonadi/akonadicontextrepository.h" #include "akonadi/akonadidatasourcequeries.h" #include "akonadi/akonadidatasourcerepository.h" #include "akonadi/akonadinotequeries.h" #include "akonadi/akonadinoterepository.h" #include "akonadi/akonadiprojectqueries.h" #include "akonadi/akonadiprojectrepository.h" #include "akonadi/akonaditagqueries.h" #include "akonadi/akonaditagrepository.h" #include "akonadi/akonaditaskqueries.h" #include "akonadi/akonaditaskrepository.h" #include "akonadi/akonadimessaging.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadiserializer.h" #include "akonadi/akonadistorage.h" -#include "presentation/applicationmodel.h" #include "presentation/artifacteditormodel.h" #include "presentation/availablenotepagesmodel.h" #include "presentation/availablesourcesmodel.h" #include "scripting/scripthandler.h" #include "utils/dependencymanager.h" void App::initializeDependencies() { auto &deps = Utils::DependencyManager::globalInstance(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { return new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Notes, deps->create(), deps->create(), deps->create()); }); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); - deps.add(); - deps.add(); } diff --git a/src/renku/app/main.cpp b/src/renku/app/main.cpp index 9aeff71e..f2c25e89 100644 --- a/src/renku/app/main.cpp +++ b/src/renku/app/main.cpp @@ -1,91 +1,91 @@ /* This file is part of Renku Notes Copyright 2015 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" #include "widgets/editorview.h" #include "widgets/pageview.h" #include "presentation/applicationmodel.h" #include "utils/dependencymanager.h" #include "dependencies.h" #include int main(int argc, char **argv) { App::initializeDependencies(); QApplication app(argc, argv); KComponentData mainComponentData("renku"); auto widget = new QWidget; auto components = new Widgets::ApplicationComponents(widget); - components->setModel(Utils::DependencyManager::globalInstance().create()); + components->setModel(Presentation::ApplicationModel::Ptr::create()); auto layout = new QVBoxLayout; layout->addWidget(components->pageView()); widget->setLayout(layout); auto sourcesDock = new QDockWidget(QObject::tr("Sources")); sourcesDock->setObjectName("sourcesDock"); sourcesDock->setWidget(components->availableSourcesView()); auto pagesDock = new QDockWidget(QObject::tr("Pages")); pagesDock->setObjectName("pagesDock"); pagesDock->setWidget(components->availablePagesView()); auto editorDock = new QDockWidget(QObject::tr("Editor")); editorDock->setObjectName("editorDock"); editorDock->setWidget(components->editorView()); auto window = new KMainWindow; window->resize(1024, 600); window->setAutoSaveSettings("MainWindow"); window->setCentralWidget(widget); window->addDockWidget(Qt::RightDockWidgetArea, editorDock); window->addDockWidget(Qt::LeftDockWidgetArea, pagesDock); window->addDockWidget(Qt::LeftDockWidgetArea, sourcesDock); window->show(); return app.exec(); } diff --git a/src/renku/kontact/part.cpp b/src/renku/kontact/part.cpp index 0ddbe695..2a2a7601 100644 --- a/src/renku/kontact/part.cpp +++ b/src/renku/kontact/part.cpp @@ -1,82 +1,82 @@ /* This file is part of Renku Notes Copyright 2015 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "part.h" #include #include #include #include #include #include #include "../app/aboutdata.h" #include "../app/dependencies.h" #include "presentation/applicationmodel.h" #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" #include "widgets/editorview.h" #include "widgets/pageview.h" #include "utils/dependencymanager.h" K_PLUGIN_FACTORY(PartFactory, registerPlugin();) K_EXPORT_PLUGIN(PartFactory(App::getAboutData())) Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &) : KParts::ReadOnlyPart(parent) { App::initializeDependencies(); setComponentData(PartFactory::componentData()); auto splitter = new QSplitter(parentWidget); auto sidebar = new QSplitter(Qt::Vertical, parentWidget); auto components = new Widgets::ApplicationComponents(parentWidget); - components->setModel(Utils::DependencyManager::globalInstance().create()); + components->setModel(Presentation::ApplicationModel::Ptr::create()); sidebar->addWidget(components->availablePagesView()); sidebar->addWidget(components->availableSourcesView()); splitter->addWidget(sidebar); splitter->addWidget(components->pageView()); splitter->addWidget(components->editorView()); setWidget(splitter); setXMLFile(KStandardDirs::locate("data", "renku/renku_part.rc")); } Part::~Part() { } bool Part::openFile() { return false; } diff --git a/src/zanshin/app/dependencies.cpp b/src/zanshin/app/dependencies.cpp index 133835b1..b7c9c823 100644 --- a/src/zanshin/app/dependencies.cpp +++ b/src/zanshin/app/dependencies.cpp @@ -1,144 +1,137 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dependencies.h" #include "akonadi/akonadicontextqueries.h" #include "akonadi/akonadicontextrepository.h" #include "akonadi/akonadidatasourcequeries.h" #include "akonadi/akonadidatasourcerepository.h" #include "akonadi/akonadinotequeries.h" #include "akonadi/akonadinoterepository.h" #include "akonadi/akonadiprojectqueries.h" #include "akonadi/akonadiprojectrepository.h" #include "akonadi/akonaditagqueries.h" #include "akonadi/akonaditagrepository.h" #include "akonadi/akonaditaskqueries.h" #include "akonadi/akonaditaskrepository.h" #include "akonadi/akonadimessaging.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadiserializer.h" #include "akonadi/akonadistorage.h" -#include "presentation/applicationmodel.h" #include "presentation/artifacteditormodel.h" #include "presentation/availablesourcesmodel.h" #include "presentation/availabletaskpagesmodel.h" #include "scripting/scripthandler.h" #include "utils/dependencymanager.h" void App::initializeDependencies() { auto &deps = Utils::DependencyManager::globalInstance(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add([] (Utils::DependencyManager *deps) { return new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks, deps->create(), deps->create(), deps->create()); }); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); deps.add(); - deps.add(); - deps.add(); } diff --git a/src/zanshin/app/main.cpp b/src/zanshin/app/main.cpp index ae03d427..95550954 100644 --- a/src/zanshin/app/main.cpp +++ b/src/zanshin/app/main.cpp @@ -1,101 +1,101 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" #include "widgets/editorview.h" #include "widgets/pageview.h" #include "presentation/applicationmodel.h" #include "utils/dependencymanager.h" #include "dependencies.h" #include int main(int argc, char **argv) { App::initializeDependencies(); QApplication app(argc, argv); KComponentData mainComponentData("zanshin"); KSharedConfig::Ptr config = KSharedConfig::openConfig("zanshin-migratorrc"); KConfigGroup group = config->group("Migrations"); if (!group.readEntry("Migrated021Projects", false)) { std::cerr << "Migrating data from zanshin 0.2, please wait..." << std::endl; QProcess proc; proc.start("zanshin-migrator"); proc.waitForFinished(); std::cerr << "Migration done" << std::endl; } auto widget = new QWidget; auto components = new Widgets::ApplicationComponents(widget); - components->setModel(Utils::DependencyManager::globalInstance().create()); + components->setModel(Presentation::ApplicationModel::Ptr::create()); auto layout = new QVBoxLayout; layout->addWidget(components->pageView()); widget->setLayout(layout); auto sourcesDock = new QDockWidget(QObject::tr("Sources")); sourcesDock->setObjectName("sourcesDock"); sourcesDock->setWidget(components->availableSourcesView()); auto pagesDock = new QDockWidget(QObject::tr("Pages")); pagesDock->setObjectName("pagesDock"); pagesDock->setWidget(components->availablePagesView()); auto editorDock = new QDockWidget(QObject::tr("Editor")); editorDock->setObjectName("editorDock"); editorDock->setWidget(components->editorView()); auto window = new KMainWindow; window->resize(1024, 600); window->setAutoSaveSettings("MainWindow"); window->setCentralWidget(widget); window->addDockWidget(Qt::RightDockWidgetArea, editorDock); window->addDockWidget(Qt::LeftDockWidgetArea, pagesDock); window->addDockWidget(Qt::LeftDockWidgetArea, sourcesDock); window->show(); return app.exec(); } diff --git a/src/zanshin/kontact/part.cpp b/src/zanshin/kontact/part.cpp index 4d2a3180..3e1b5764 100644 --- a/src/zanshin/kontact/part.cpp +++ b/src/zanshin/kontact/part.cpp @@ -1,82 +1,82 @@ /* This file is part of Zanshin Todo. Copyright 2011 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "part.h" #include #include #include #include #include #include #include "../app/aboutdata.h" #include "../app/dependencies.h" #include "presentation/applicationmodel.h" #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" #include "widgets/editorview.h" #include "widgets/pageview.h" #include "utils/dependencymanager.h" K_PLUGIN_FACTORY(PartFactory, registerPlugin();) K_EXPORT_PLUGIN(PartFactory(App::getAboutData())) Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &) : KParts::ReadOnlyPart(parent) { App::initializeDependencies(); setComponentData(PartFactory::componentData()); auto splitter = new QSplitter(parentWidget); auto sidebar = new QSplitter(Qt::Vertical, parentWidget); auto components = new Widgets::ApplicationComponents(parentWidget); - components->setModel(Utils::DependencyManager::globalInstance().create()); + components->setModel(Presentation::ApplicationModel::Ptr::create()); sidebar->addWidget(components->availablePagesView()); sidebar->addWidget(components->availableSourcesView()); splitter->addWidget(sidebar); splitter->addWidget(components->pageView()); splitter->addWidget(components->editorView()); setWidget(splitter); setXMLFile(KStandardDirs::locate("data", "zanshin/zanshin-next_part.rc")); } Part::~Part() { } bool Part::openFile() { return false; } diff --git a/tests/features/cuke-steps.cpp b/tests/features/cuke-steps.cpp index 96cc1ab0..8adffca8 100644 --- a/tests/features/cuke-steps.cpp +++ b/tests/features/cuke-steps.cpp @@ -1,830 +1,830 @@ /* This file is part of Zanshin Copyright 2014-2015 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include "presentation/applicationmodel.h" #include "presentation/errorhandler.h" #include "presentation/querytreemodelbase.h" #include "akonadi/akonadimonitorimpl.h" #include "utils/dependencymanager.h" #include "utils/jobhandler.h" #include "testlib/akonadifakedata.h" #include "testlib/akonadifakedataxmlloader.h" #include "testlib/monitorspy.h" #include "testlib/testsafety.h" static int argc = 0; static QApplication app(argc, Q_NULLPTR); namespace CukeSteps { void initializeAppDependencies(); } namespace cucumber { namespace internal { template<> inline QString fromString(const std::string& s) { return QString::fromUtf8(s.data()); } } } using namespace cucumber; class FakeErrorHandler : public Presentation::ErrorHandler { public: void doDisplayMessage(const QString &) { } }; class ZanshinContext : public QObject { Q_OBJECT public: explicit ZanshinContext(QObject *parent = Q_NULLPTR) : QObject(parent), app(Q_NULLPTR), presentation(Q_NULLPTR), editor(Q_NULLPTR), proxyModel(new QSortFilterProxyModel(this)), m_model(Q_NULLPTR), m_sourceModel(Q_NULLPTR), monitorSpy(Q_NULLPTR) { qputenv("ZANSHIN_OVERRIDE_DATETIME", "2015-03-10"); static bool initializedDependencies = false; if (!initializedDependencies) { CukeSteps::initializeAppDependencies(); 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; proxyModel->setDynamicSortFilter(true); - auto appModel = Utils::DependencyManager::globalInstance().create(); + auto appModel = ApplicationModel::Ptr::create(); appModel->setErrorHandler(&m_errorHandler); app = appModel; auto monitor = Utils::DependencyManager::globalInstance().create(); monitorSpy = new MonitorSpy(monitor.data(), this); } ~ZanshinContext() { } void setModel(QAbstractItemModel *model) { m_sourceModel = model; if (!qobject_cast(model)) { proxyModel->setObjectName("m_proxyModel_in_ZanshinContext"); proxyModel->setSourceModel(model); proxyModel->setSortRole(Qt::DisplayRole); proxyModel->sort(0); m_model = proxyModel; } else { m_model = model; } } QAbstractItemModel *sourceModel() { return m_sourceModel; } QAbstractItemModel *model() { return m_model; } void waitForEmptyJobQueue() { while (Utils::JobHandler::jobCount() != 0) { QTest::qWait(20); } } void waitForStableState() { waitForEmptyJobQueue(); monitorSpy->waitForStableState(); } QObjectPtr app; QList indices; QPersistentModelIndex index; QObject *presentation; QObject *editor; 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) { if (role != Qt::DisplayRole) return index.data(role).toString(); QString data = index.data(role).toString(); if (index.parent().isValid()) return indexString(index.parent(), role) + " / " + data; else return data; } QModelIndex findIndex(QAbstractItemModel *model, const QString &string, int role = Qt::DisplayRole, const QModelIndex &root = QModelIndex()) { for (int row = 0; row < model->rowCount(root); row++) { const QModelIndex index = model->index(row, 0, root); if (indexString(index, role) == string) return index; if (model->rowCount(index) > 0) { const QModelIndex found = findIndex(model, string, role, index); if (found.isValid()) return found; } } return QModelIndex(); } void collectIndices(ZanshinContext *context, const QModelIndex &root = QModelIndex()) { QAbstractItemModel *model = context->model(); for (int row = 0; row < model->rowCount(root); row++) { const QModelIndex index = model->index(row, 0, root); context->indices << index; if (model->rowCount(index) > 0) collectIndices(context, index); } } void dumpIndices(const QList &indices) { qDebug() << "Dumping list of size:" << indices.size(); for (int row = 0; row < indices.size(); row++) { qDebug() << row << indexString(indices.at(row)); } } inline bool verify(bool statement, const char *str, const char *file, int line) { if (statement) return true; qDebug() << "Statement" << str << "returned FALSE"; qDebug() << "Loc:" << file << line; return false; } template inline bool compare(T const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) { if (t1 == t2) return true; qDebug() << "Compared values are not the same"; qDebug() << "Actual (" << actual << ") :" << QTest::toString(t1); qDebug() << "Expected (" << expected << ") :" << QTest::toString(t2); qDebug() << "Loc:" << file << line; return false; } } // namespace Zanshin #define COMPARE(actual, expected) \ do {\ if (!Zanshin::compare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ BOOST_REQUIRE(false);\ } while (0) #define COMPARE_OR_DUMP(actual, expected) \ do {\ if (!Zanshin::compare(actual, expected, #actual, #expected, __FILE__, __LINE__)) {\ Zanshin::dumpIndices(context->indices); \ BOOST_REQUIRE(false);\ }\ } while (0) #define VERIFY(statement) \ do {\ if (!Zanshin::verify((statement), #statement, __FILE__, __LINE__))\ BOOST_REQUIRE(false);\ } while (0) #define VERIFY_OR_DUMP(statement) \ do {\ if (!Zanshin::verify((statement), #statement, __FILE__, __LINE__)) {\ Zanshin::dumpIndices(context->indices); \ BOOST_REQUIRE(false);\ }\ } while (0) GIVEN("^I display the available data sources$") { ScenarioScope context; auto availableSources = context->app->property("availableSources").value(); VERIFY(availableSources); auto sourceListModel = availableSources->property("sourceListModel").value(); VERIFY(sourceListModel); context->presentation = availableSources; context->setModel(sourceListModel); } GIVEN("^I display the available pages$") { ScenarioScope context; context->presentation = context->app->property("availablePages").value(); context->setModel(context->presentation->property("pageListModel").value()); } GIVEN("^I display the \"(.*)\" page$") { REGEX_PARAM(QString, pageName); ScenarioScope context; auto availablePages = context->app->property("availablePages").value(); VERIFY(availablePages); auto pageListModel = availablePages->property("pageListModel").value(); VERIFY(pageListModel); context->waitForEmptyJobQueue(); QModelIndex pageIndex = Zanshin::findIndex(pageListModel, pageName); VERIFY(pageIndex.isValid()); QObject *page = Q_NULLPTR; QMetaObject::invokeMethod(availablePages, "createPageForIndex", Q_RETURN_ARG(QObject*, page), Q_ARG(QModelIndex, pageIndex)); VERIFY(page); VERIFY(context->app->setProperty("currentPage", QVariant::fromValue(page))); context->presentation = context->app->property("currentPage").value(); } GIVEN("^there is an item named \"(.+)\" in the central list$") { REGEX_PARAM(QString, itemName); ScenarioScope context; auto model = context->presentation->property("centralListModel").value(); context->setModel(model); context->waitForEmptyJobQueue(); context->index = Zanshin::findIndex(context->model(), itemName); VERIFY_OR_DUMP(context->index.isValid()); } GIVEN("^there is an item named \"(.+)\" in the available data sources$") { REGEX_PARAM(QString, itemName); ScenarioScope context; auto availableSources = context->app->property("availableSources").value(); VERIFY(availableSources); auto model = availableSources->property("sourceListModel").value(); VERIFY(model); context->waitForEmptyJobQueue(); context->setModel(model); context->index = Zanshin::findIndex(context->model(), itemName); VERIFY_OR_DUMP(context->index.isValid()); } GIVEN("^the central list contains items named:") { TABLE_PARAM(tableParam); ScenarioScope context; context->dragIndices.clear(); auto model = context->presentation->property("centralListModel").value(); context->waitForEmptyJobQueue(); context->setModel(model); for (const auto row : tableParam.hashes()) { for (const auto it : row) { const QString itemName = QString::fromUtf8(it.second.data()); QModelIndex index = Zanshin::findIndex(context->model(), itemName); VERIFY_OR_DUMP(index.isValid()); context->dragIndices << index; } } } WHEN("^I look at the central list$") { ScenarioScope context; auto model = context->presentation->property("centralListModel").value(); context->setModel(model); context->waitForStableState(); } WHEN("^I check the item$") { ScenarioScope context; VERIFY(context->model()->setData(context->index, Qt::Checked, Qt::CheckStateRole)); context->waitForStableState(); } WHEN("^I uncheck the item$") { ScenarioScope context; VERIFY(context->model()->setData(context->index, Qt::Unchecked, Qt::CheckStateRole)); context->waitForStableState(); } WHEN("^I remove the item$") { ScenarioScope context; VERIFY(QMetaObject::invokeMethod(context->presentation, "removeItem", Q_ARG(QModelIndex, context->index))); context->waitForStableState(); } WHEN("^I add a project named \"(.*)\" in the source named \"(.*)\"$") { REGEX_PARAM(QString, projectName); REGEX_PARAM(QString, sourceName); ScenarioScope context; auto availableSources = context->app->property("availableSources").value(); VERIFY(availableSources); auto sourceList = availableSources->property("sourceListModel").value(); VERIFY(sourceList); context->waitForStableState(); QModelIndex index = Zanshin::findIndex(sourceList, sourceName); VERIFY(index.isValid()); auto source = index.data(Presentation::QueryTreeModelBase::ObjectRole) .value(); VERIFY(source); VERIFY(QMetaObject::invokeMethod(context->presentation, "addProject", Q_ARG(QString, projectName), Q_ARG(Domain::DataSource::Ptr, source))); context->waitForStableState(); } WHEN("^I rename a \"(.*)\" named \"(.*)\" to \"(.*)\"$") { REGEX_PARAM(QString, objectType); REGEX_PARAM(QString, oldName); REGEX_PARAM(QString, newName); const QString pageNodeName = (objectType == "project") ? "Projects / " : (objectType == "context") ? "Contexts / " : QString(); VERIFY(!pageNodeName.isEmpty()); ScenarioScope context; auto availablePages = context->app->property("availablePages").value(); VERIFY(availablePages); auto pageListModel = availablePages->property("pageListModel").value(); VERIFY(pageListModel); context->waitForStableState(); QModelIndex pageIndex = Zanshin::findIndex(pageListModel, pageNodeName + oldName); VERIFY(pageIndex.isValid()); pageListModel->setData(pageIndex, newName); context->waitForStableState(); } WHEN("^I remove a \"(.*)\" named \"(.*)\"$") { REGEX_PARAM(QString, objectType); REGEX_PARAM(QString, objectName); const QString pageNodeName = (objectType == "project") ? "Projects / " : (objectType == "context") ? "Contexts / " : (objectType == "tag") ? "Tags / " : QString(); VERIFY(!pageNodeName.isEmpty()); ScenarioScope context; auto availablePages = context->app->property("availablePages").value(); VERIFY(availablePages); auto pageListModel = availablePages->property("pageListModel").value(); VERIFY(pageListModel); context->waitForStableState(); QModelIndex pageIndex = Zanshin::findIndex(pageListModel, pageNodeName + objectName); VERIFY(pageIndex.isValid()); VERIFY(QMetaObject::invokeMethod(availablePages, "removeItem", Q_ARG(QModelIndex, pageIndex))); context->waitForStableState(); } WHEN("^I add a \"(.*)\" named \"(.+)\"$") { REGEX_PARAM(QString, objectType); REGEX_PARAM(QString, objectName); QByteArray actionName = (objectType == "context") ? "addContext" : (objectType == "note") ? "addItem" : (objectType == "task") ? "addItem" : (objectType == "tag") ? "addTag" : QByteArray(); VERIFY(!actionName.isEmpty()); ScenarioScope context; context->waitForStableState(); VERIFY(QMetaObject::invokeMethod(context->presentation, actionName.data(), Q_ARG(QString, objectName))); context->waitForStableState(); } WHEN("^I list the items$") { ScenarioScope context; context->waitForStableState(); context->indices.clear(); Zanshin::collectIndices(context.get()); context->waitForStableState(); } WHEN("^I open the item in the editor$") { ScenarioScope context; auto artifact = context->index.data(Presentation::QueryTreeModelBase::ObjectRole) .value(); VERIFY(artifact); context->editor = context->app->property("editor").value(); VERIFY(context->editor); VERIFY(context->editor->setProperty("artifact", QVariant::fromValue(artifact))); } WHEN("^I mark it done in the editor$") { ScenarioScope context; VERIFY(context->editor->setProperty("done", true)); } WHEN("^I change the editor (.*) to \"(.*)\"$") { REGEX_PARAM(QString, field); REGEX_PARAM(QString, string); const QVariant value = (field == "text") ? string : (field == "title") ? string : (field == "start date") ? QDateTime::fromString(string, Qt::ISODate) : (field == "due date") ? QDateTime::fromString(string, Qt::ISODate) : QVariant(); const QByteArray property = (field == "text") ? field.toUtf8() : (field == "title") ? field.toUtf8() : (field == "start date") ? "startDate" : (field == "due date") ? "dueDate" : QByteArray(); VERIFY(value.isValid()); VERIFY(!property.isEmpty()); ScenarioScope context; VERIFY(context->editor->setProperty(property, value)); } WHEN("^I open the item in the editor again$") { ScenarioScope context; auto artifact = context->index.data(Presentation::QueryTreeModelBase::ObjectRole) .value(); VERIFY(artifact); VERIFY(context->editor->setProperty("artifact", QVariant::fromValue(Domain::Artifact::Ptr()))); VERIFY(context->editor->setProperty("artifact", QVariant::fromValue(artifact))); context->waitForStableState(); } WHEN("^I drop the item on \"(.*)\" in the central list") { REGEX_PARAM(QString, itemName); ScenarioScope context; VERIFY(context->index.isValid()); const QMimeData *data = context->model()->mimeData(QModelIndexList() << context->index); QAbstractItemModel *destModel = context->model(); QModelIndex dropIndex = Zanshin::findIndex(destModel, itemName); VERIFY(dropIndex.isValid()); VERIFY(destModel->dropMimeData(data, Qt::MoveAction, -1, -1, dropIndex)); context->waitForStableState(); } WHEN("^I drop the item on the blank area of the central list") { ScenarioScope context; VERIFY(context->index.isValid()); const QMimeData *data = context->model()->mimeData(QModelIndexList() << context->index); QAbstractItemModel *destModel = context->model(); VERIFY(destModel->dropMimeData(data, Qt::MoveAction, -1, -1, QModelIndex())); context->waitForStableState(); } WHEN("^I drop items on \"(.*)\" in the central list") { REGEX_PARAM(QString, itemName); ScenarioScope context; VERIFY(!context->dragIndices.isEmpty()); QModelIndexList indexes; std::transform(context->dragIndices.constBegin(), context->dragIndices.constEnd(), std::back_inserter(indexes), [] (const QPersistentModelIndex &index) { VERIFY(index.isValid()); return index; }); const QMimeData *data = context->model()->mimeData(indexes); QAbstractItemModel *destModel = context->model(); QModelIndex dropIndex = Zanshin::findIndex(destModel, itemName); VERIFY(dropIndex.isValid()); VERIFY(destModel->dropMimeData(data, Qt::MoveAction, -1, -1, dropIndex)); context->waitForStableState(); } WHEN("^I drop the item on \"(.*)\" in the page list") { REGEX_PARAM(QString, itemName); ScenarioScope context; VERIFY(context->index.isValid()); const QMimeData *data = context->model()->mimeData(QModelIndexList() << context->index); auto availablePages = context->app->property("availablePages").value(); VERIFY(availablePages); auto destModel = availablePages->property("pageListModel").value(); VERIFY(destModel); context->waitForStableState(); QModelIndex dropIndex = Zanshin::findIndex(destModel, itemName); VERIFY(dropIndex.isValid()); VERIFY(destModel->dropMimeData(data, Qt::MoveAction, -1, -1, dropIndex)); context->waitForStableState(); } WHEN("^I drop items on \"(.*)\" in the page list") { REGEX_PARAM(QString, itemName); ScenarioScope context; VERIFY(!context->dragIndices.isEmpty()); QModelIndexList indexes; std::transform(context->dragIndices.constBegin(), context->dragIndices.constEnd(), std::back_inserter(indexes), [] (const QPersistentModelIndex &index) { VERIFY(index.isValid()); return index; }); const QMimeData *data = context->model()->mimeData(indexes); auto availablePages = context->app->property("availablePages").value(); VERIFY(availablePages); auto destModel = availablePages->property("pageListModel").value(); VERIFY(destModel); context->waitForStableState(); QModelIndex dropIndex = Zanshin::findIndex(destModel, itemName); VERIFY(dropIndex.isValid()); VERIFY(destModel->dropMimeData(data, Qt::MoveAction, -1, -1, dropIndex)); context->waitForStableState(); } WHEN("^the setting key (\\S+) changes to (\\d+)$") { REGEX_PARAM(QString, keyName); REGEX_PARAM(qint64, id); ScenarioScope context; KConfigGroup config(KGlobal::config(), "General"); config.writeEntry(keyName, id); } WHEN("^the user changes the default data source to \"(.*)\"$") { REGEX_PARAM(QString, sourceName); ScenarioScope context; context->waitForStableState(); auto sourceIndex = Zanshin::findIndex(context->model(), sourceName); auto availableSources = context->app->property("availableSources").value(); VERIFY(availableSources); VERIFY(QMetaObject::invokeMethod(availableSources, "setDefaultItem", Q_ARG(QModelIndex, sourceIndex))); context->waitForStableState(); } THEN("^the list is") { TABLE_PARAM(tableParam); ScenarioScope context; auto roleNames = context->model()->roleNames(); QSet usedRoles; QStandardItemModel inputModel; for (const auto row : tableParam.hashes()) { QStandardItem *item = new QStandardItem; for (const auto it : row) { const QByteArray roleName = it.first.data(); const QString value = QString::fromUtf8(it.second.data()); const int role = roleNames.key(roleName, -1); VERIFY_OR_DUMP(role != -1); item->setData(value, role); usedRoles.insert(role); } inputModel.appendRow(item); } QSortFilterProxyModel proxy; QAbstractItemModel *referenceModel; if (!qobject_cast(context->sourceModel())) { referenceModel = &proxy; proxy.setSourceModel(&inputModel); proxy.setSortRole(Qt::DisplayRole); proxy.sort(0); proxy.setObjectName("the_list_is_proxy"); } else { referenceModel = &inputModel; } for (int row = 0; row < context->indices.size(); row++) { QModelIndex expectedIndex = referenceModel->index(row, 0); QModelIndex resultIndex = context->indices.at(row); for (auto role : usedRoles) { COMPARE_OR_DUMP(Zanshin::indexString(resultIndex, role), Zanshin::indexString(expectedIndex, role)); } } COMPARE_OR_DUMP(context->indices.size(), referenceModel->rowCount()); } THEN("^the list contains \"(.+)\"$") { REGEX_PARAM(QString, itemName); ScenarioScope context; for (int row = 0; row < context->indices.size(); row++) { if (Zanshin::indexString(context->indices.at(row)) == itemName) return; } VERIFY_OR_DUMP(false); } THEN("^the list does not contain \"(.+)\"$") { REGEX_PARAM(QString, itemName); ScenarioScope context; for (int row = 0; row < context->indices.size(); row++) { VERIFY_OR_DUMP(Zanshin::indexString(context->indices.at(row)) != itemName); } } THEN("^the task corresponding to the item is done$") { ScenarioScope context; auto artifact = context->index.data(Presentation::QueryTreeModelBase::ObjectRole).value(); VERIFY(artifact); auto task = artifact.dynamicCast(); VERIFY(task); VERIFY(task->isDone()); } THEN("^the editor shows the task as done$") { ScenarioScope context; VERIFY(context->editor->property("done").toBool()); } THEN("^the editor shows \"(.*)\" as (.*)$") { REGEX_PARAM(QString, string); REGEX_PARAM(QString, field); const QVariant value = (field == "text") ? string : (field == "title") ? string : (field == "delegate") ? string : (field == "start date") ? QDateTime::fromString(string, Qt::ISODate) : (field == "due date") ? QDateTime::fromString(string, Qt::ISODate) : QVariant(); const QByteArray property = (field == "text") ? field.toUtf8() : (field == "title") ? field.toUtf8() : (field == "delegate") ? "delegateText" : (field == "start date") ? "startDate" : (field == "due date") ? "dueDate" : QByteArray(); VERIFY(value.isValid()); VERIFY(!property.isEmpty()); ScenarioScope context; COMPARE(context->editor->property(property), value); } THEN("^the default data source is \"(.*)\"$") { REGEX_PARAM(QString, expectedName); ScenarioScope context; context->waitForStableState(); auto expectedIndex = Zanshin::findIndex(context->model(), expectedName); VERIFY(expectedIndex.isValid()); auto defaultRole = context->model()->roleNames().key("default", -1); VERIFY(expectedIndex.data(defaultRole).toBool()); } THEN("^the setting key (\\S+) is (\\d+)$") { REGEX_PARAM(QString, keyName); REGEX_PARAM(qint64, expectedId); KConfigGroup config(KGlobal::config(), "General"); const qint64 id = config.readEntry(keyName, -1); COMPARE(id, expectedId); } #include "cuke-steps.moc" diff --git a/tests/units/presentation/applicationmodeltest.cpp b/tests/units/presentation/applicationmodeltest.cpp index 23132257..8294b16c 100644 --- a/tests/units/presentation/applicationmodeltest.cpp +++ b/tests/units/presentation/applicationmodeltest.cpp @@ -1,213 +1,177 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program 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 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "utils/dependencymanager.h" #include "utils/mockobject.h" #include "presentation/applicationmodel.h" #include "presentation/artifacteditormodel.h" #include "presentation/availablepagesmodelinterface.h" #include "presentation/availablesourcesmodel.h" #include "presentation/datasourcelistmodel.h" #include "presentation/errorhandler.h" #include "testlib/fakejob.h" using namespace mockitopp; using namespace mockitopp::matcher; class FakeErrorHandler : public Presentation::ErrorHandler { public: void doDisplayMessage(const QString &message) { m_message = message; } QString m_message; }; class FakeAvailablePagesModel : public Presentation::AvailablePagesModelInterface { Q_OBJECT public: explicit FakeAvailablePagesModel(QObject *parent = Q_NULLPTR) : Presentation::AvailablePagesModelInterface(parent) {} QAbstractItemModel *pageListModel() Q_DECL_OVERRIDE { return Q_NULLPTR; } QObject *createPageForIndex(const QModelIndex &) Q_DECL_OVERRIDE { return Q_NULLPTR; } void addProject(const QString &, const Domain::DataSource::Ptr &) Q_DECL_OVERRIDE {} void addContext(const QString &) Q_DECL_OVERRIDE {} void addTag(const QString &) Q_DECL_OVERRIDE {} void removeItem(const QModelIndex &) Q_DECL_OVERRIDE {} }; class ApplicationModelTest : public QObject { Q_OBJECT public: explicit ApplicationModelTest(QObject *parent = Q_NULLPTR) : QObject(parent) { Utils::DependencyManager::globalInstance().add(); Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { return new Presentation::ArtifactEditorModel(Domain::TaskRepository::Ptr(), Domain::NoteRepository::Ptr()); }); Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { return new Presentation::AvailableSourcesModel(Domain::DataSourceQueries::Ptr(), Domain::DataSourceRepository::Ptr()); }); } private slots: void shouldProvideAvailableSourcesModel() { // GIVEN - auto sourceQueries = Domain::DataSourceQueries::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - Presentation::ApplicationModel app(sourceQueries, - sourceRepository, - taskRepository, - noteRepository); + Presentation::ApplicationModel app; // WHEN QObject *available = app.availableSources(); // THEN QVERIFY(qobject_cast(available)); } void shouldProvideAvailablePagesModel() { // GIVEN - auto sourceQueries = Domain::DataSourceQueries::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - Presentation::ApplicationModel app(sourceQueries, - sourceRepository, - taskRepository, - noteRepository); + Presentation::ApplicationModel app; // WHEN QObject *available = app.availablePages(); // THEN QVERIFY(qobject_cast(available)); } void shouldProvideCurrentPage() { // GIVEN - auto sourceQueries = Domain::DataSourceQueries::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - Presentation::ApplicationModel app(sourceQueries, - sourceRepository, - taskRepository, - noteRepository); + Presentation::ApplicationModel app; QVERIFY(!app.currentPage()); QSignalSpy spy(&app, SIGNAL(currentPageChanged(QObject*))); // WHEN auto page = new QObject(this); app.setCurrentPage(page); // THEN QCOMPARE(app.currentPage(), page); QCOMPARE(spy.count(), 1); QCOMPARE(spy.takeFirst().takeFirst().value(), page); } void shouldProvideArtifactEditorModel() { // GIVEN - auto sourceQueries = Domain::DataSourceQueries::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - Presentation::ApplicationModel app(sourceQueries, - sourceRepository, - taskRepository, - noteRepository); + Presentation::ApplicationModel app; // WHEN QObject *page = app.editor(); // THEN QVERIFY(qobject_cast(page)); } void shouldSetErrorHandlerToAllModels() { // GIVEN // An ErrorHandler FakeErrorHandler errorHandler; - - auto sourceQueries = Domain::DataSourceQueries::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - Presentation::ApplicationModel app(sourceQueries, - sourceRepository, - taskRepository, - noteRepository); + Presentation::ApplicationModel app; // WHEN app.setErrorHandler(&errorHandler); // THEN auto availableSource = static_cast(app.availableSources()); auto availablePages = static_cast(app.availablePages()); auto editor = static_cast(app.editor()); QCOMPARE(availableSource->errorHandler(), &errorHandler); QCOMPARE(availablePages->errorHandler(), &errorHandler); QCOMPARE(editor->errorHandler(), &errorHandler); // WHEN FakeErrorHandler errorHandler2; app.setErrorHandler(&errorHandler2); // THEN QCOMPARE(availableSource->errorHandler(), &errorHandler2); QCOMPARE(availablePages->errorHandler(), &errorHandler2); QCOMPARE(editor->errorHandler(), &errorHandler2); } }; QTEST_MAIN(ApplicationModelTest) #include "applicationmodeltest.moc"