~alan-griffiths/miral/basic-Unity8-compatibility

« back to all changes in this revision

Viewing changes to test/test_server.cpp

  • Committer: Alan Griffiths
  • Date: 2016-11-15 12:55:56 UTC
  • mfrom: (445 miral)
  • mto: This revision was merged to the branch mainline in revision 446.
  • Revision ID: alan@octopull.co.uk-20161115125556-kyfbub5xoj1kheb9
mergeĀ :parent

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include "test_server.h"
 
20
#include "../miral/basic_window_manager.h"
20
21
 
21
22
#include <miral/canonical_window_manager.h>
22
23
#include <miral/set_window_managment_policy.h>
39
40
using namespace miral;
40
41
using namespace testing;
41
42
namespace mtf = mir_test_framework;
 
43
namespace msh = mir::shell;
42
44
 
43
45
namespace
44
46
{
46
48
char const* dummy_args[2] = { "TestServer", nullptr };
47
49
}
48
50
 
 
51
struct miral::TestServer::TestWindowManagerPolicy : CanonicalWindowManagerPolicy
 
52
{
 
53
    TestWindowManagerPolicy(WindowManagerTools const& tools, TestServer& test_fixture) :
 
54
        CanonicalWindowManagerPolicy{tools}
 
55
    {
 
56
        test_fixture.tools = tools;
 
57
        test_fixture.policy = this;
 
58
    }
 
59
 
 
60
    bool handle_keyboard_event(MirKeyboardEvent const*) override { return false; }
 
61
    bool handle_pointer_event(MirPointerEvent const*) override { return false; }
 
62
    bool handle_touch_event(MirTouchEvent const*) override { return false; }
 
63
};
 
64
 
49
65
miral::TestServer::TestServer() :
50
66
    runner{1, dummy_args}
51
67
{
84
100
                            return std::make_shared<mtf::HeadlessDisplayBufferCompositorFactory>();
85
101
                        });
86
102
#endif
 
103
 
 
104
                    server.override_the_window_manager_builder([this, &server](msh::FocusController* focus_controller)
 
105
                        -> std::shared_ptr<msh::WindowManager>
 
106
                        {
 
107
                            auto const display_layout = server.the_shell_display_layout();
 
108
 
 
109
#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 24, 0)
 
110
                            auto const persistent_surface_store = server.the_persistent_surface_store();
 
111
#else
 
112
                            std::shared_ptr<mir::shell::PersistentSurfaceStore> const persistent_surface_store;
 
113
#endif
 
114
 
 
115
                            auto builder = [this](WindowManagerTools const& tools) -> std::unique_ptr<miral::WindowManagementPolicy>
 
116
                                {
 
117
                                    return std::make_unique<TestWindowManagerPolicy>(tools, *this);
 
118
                                };
 
119
 
 
120
                            auto wm = std::make_shared<miral::BasicWindowManager>(focus_controller, display_layout, persistent_surface_store, builder);
 
121
                            window_manager = wm;
 
122
                            return wm;
 
123
                        });
87
124
                };
88
125
 
89
126
            try
90
127
            {
91
 
                runner.run_with({init, set_window_managment_policy<TestWindowManagerPolicy>(*this)});
 
128
                runner.run_with({init});
92
129
            }
93
130
            catch (std::exception const& e)
94
131
            {
136
173
    return toolkit::Connection{mir_connect_sync(connect_string, name.c_str())};
137
174
}
138
175
 
 
176
void miral::TestServer::invoke_tools(std::function<void(WindowManagerTools& tools)> const& f)
 
177
{
 
178
    tools.invoke_under_lock([&]{f(tools); });
 
179
}
 
180
 
 
181
void miral::TestServer::invoke_window_manager(std::function<void(mir::shell::WindowManager& wm)> const& f)
 
182
{
 
183
    if (auto const wm = window_manager.lock())
 
184
        f(*wm);
 
185
    else
 
186
        BOOST_THROW_EXCEPTION(std::runtime_error{"Server not running"});
 
187
 
 
188
}
 
189
 
139
190
void miral::TestRuntimeEnvironment::add_to_environment(char const* key, char const* value)
140
191
{
141
192
    env.emplace_back(key, value);
142
193
}
143
194
 
144
 
struct miral::TestServer::TestWindowManagerPolicy : CanonicalWindowManagerPolicy
145
 
{
146
 
    TestWindowManagerPolicy(WindowManagerTools const& tools, TestServer& test_fixture) :
147
 
        CanonicalWindowManagerPolicy{tools}
148
 
    {
149
 
        test_fixture.tools = tools;
150
 
    }
151
 
 
152
 
    bool handle_keyboard_event(MirKeyboardEvent const*) override { return false; }
153
 
    bool handle_pointer_event(MirPointerEvent const*) override { return false; }
154
 
    bool handle_touch_event(MirTouchEvent const*) override { return false; }
155
 
};
156
 
 
157
195
using miral::TestServer;
158
196
 
159
197
// Minimal test to ensure the server runs and exits