on xenial help sign in
mock
commite3f4e0a8498f467523b0aeef2f38e330590d436b authorNick Dedekind <nick.dedekind@canonical.com> dateWed 1 Mar 2017, 17:22 (10 years ago) parent60b3653
5 files changed+60−139
tests/mocks/WindowManager/CMakeLists.txt+3−2 tests/mocks/WindowManager/Screens.h+3 tests/mocks/WindowManager/Workspace.cpp−77 tests/mocks/WindowManager/Workspace.h−60 tests/mocks/WindowManager/windowmanagementpolicy.h+54
tests/mocks/WindowManager/CMakeLists.txt+3−2
@@ -4,8 +4,8 @@ include_directories(
44)
55
66include_directories(
7+ ${CMAKE_CURRENT_SOURCE_DIR}
78 ${CMAKE_SOURCE_DIR}/plugins/WindowManager
8− ${libunity8-private_SOURCE_DIR}
99)
1010
1111set(WINDOWMANAGER_SRC
@@ -13,11 +13,12 @@ set(WINDOWMANAGER_SRC
1313 ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Window.cpp
1414 ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceManager.cpp
1515 ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceModel.cpp
16+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
1617 Screens.cpp
1718 Screen.cpp
1819 ScreenWindow.cpp
19− Workspace.cpp
2020 WindowManagerPlugin.cpp
21+ windowmanagementpolicy.h
2122 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
2223 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
2324 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
tests/mocks/WindowManager/Screens.h+3
@@ -40,6 +40,9 @@ public:
4040 explicit Screens(QObject *parent = 0);
4141 virtual ~Screens() noexcept = default;
4242
43+ Q_INVOKABLE Screens* createProxy() { return this; }
44+ Q_INVOKABLE void sync(Screens *) {}
45+
4346 /* QAbstractItemModel */
4447 QHash<int, QByteArray> roleNames() const override;
4548 QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
tests/mocks/WindowManager/Workspace.cppdeleted−77
@@ -1,77 +0,0 @@
1−/*
2− * Copyright (C) 2017 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "Workspace.h"
18−#include "WorkspaceModel.h"
19−#include "WorkspaceManager.h"
20−#include "TopLevelWindowModel.h"
21−
22−#include "windowmanagementpolicy.h"
23−
24−Workspace::Workspace(QObject *parent)
25− : QObject(parent)
26− , m_model(nullptr)
27− , m_active(false)
28−{
29− connect(WorkspaceManager::instance(), &WorkspaceManager::activeWorkspaceChanged, this, [this]() {
30− bool newActive = WorkspaceManager::instance()->activeWorkspace() == this;
31− if (newActive != m_active) {
32− m_active = newActive;
33− Q_EMIT activeChanged(m_active);
34− }
35− });
36−}
37−
38−Workspace::~Workspace()
39−{
40− unassign();
41−}
42−
43−void Workspace::assign(WorkspaceModel *model, const QVariant& vIndex)
44−{
45− if (m_model == model) return;
46−
47− if (m_model) {
48− disconnect(model);
49− m_model->remove(this);
50− }
51−
52− m_model = model ? model : WorkspaceManager::instance();
53−
54− if (m_model) {
55− int index = m_model->rowCount();
56− if (vIndex.isValid() && vIndex.canConvert(QVariant::Int)) {
57− index = vIndex.toInt();
58− }
59− m_model->insert(index, this);
60−
61− connect(m_model, &QObject::destroyed, this, [this]() {
62− m_model->remove(this);
63− m_model = nullptr;
64− });
65− Q_EMIT assigned();
66− }
67−}
68−
69−void Workspace::activate()
70−{
71− WorkspaceManager::instance()->setActiveWorkspace(this);
72−}
73−
74−void Workspace::unassign()
75−{
76− assign(nullptr);
77−}
tests/mocks/WindowManager/Workspace.hdeleted−60
@@ -1,60 +0,0 @@
1−/*
2− * Copyright (C) 2017 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef WORKSPACE_H
18−#define WORKSPACE_H
19−
20−#include <QObject>
21−#include <QVariant>
22−
23−#include <memory>
24−
25−class WorkspaceModel;
26−class TopLevelWindowModel;
27−
28−namespace miral { class Workspace; }
29−
30−class Workspace : public QObject
31−{
32− Q_OBJECT
33− Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
34−public:
35− ~Workspace();
36−
37− Q_INVOKABLE void assign(WorkspaceModel* model, const QVariant& index = QVariant());
38−
39− bool isActive() const { return m_active; }
40−
41−public Q_SLOT:
42− void activate();
43− void unassign();
44−
45−Q_SIGNALS:
46− void assigned();
47− void unassigned();
48−
49− void activeChanged(bool);
50−
51−private:
52− explicit Workspace(QObject *parent = 0);
53−
54− WorkspaceModel* m_model;
55− bool m_active;
56−
57− friend class WorkspaceManager;
58−};
59−
60−#endif // WORKSPACE_H
tests/mocks/WindowManager/windowmanagementpolicy.hnew file+54
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef MOCKWINDOMANAGEMENTPOLICY_H
18+#define MOCKWINDOMANAGEMENTPOLICY_H
19+
20+#include <QObject>
21+
22+namespace miral {
23+class Window;
24+class Workspace {};
25+}
26+
27+// A Fake window management policy for the mock.
28+class WindowManagementPolicy : public QObject
29+{
30+ Q_OBJECT
31+public:
32+ WindowManagementPolicy() {}
33+
34+ static WindowManagementPolicy *instance() {
35+ static WindowManagementPolicy* inst(new WindowManagementPolicy());
36+ return inst;
37+ }
38+
39+ std::shared_ptr<miral::Workspace> createWorkspace() { return std::make_shared<miral::Workspace>(); }
40+ void releaseWorkspace(const std::shared_ptr<miral::Workspace>&) {}
41+
42+ void forEachWindowInWorkspace(
43+ std::shared_ptr<miral::Workspace> const&,
44+ std::function<void(miral::Window const&)> const&) {}
45+
46+ void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace>&,
47+ const std::shared_ptr<miral::Workspace>&)
48+ {}
49+
50+public Q_SLOTS:
51+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace>&) {}
52+};
53+
54+#endif // UNITY_WINDOWMANAGEMENTPOLICY_H