~albaguirre/mir/backport-fixes-to-0.11

« back to all changes in this revision

Viewing changes to tests/acceptance-tests/server_configuration_wrapping.cpp

  • Committer: Tarmac
  • Author(s): Alan Griffiths
  • Date: 2015-01-28 20:21:34 UTC
  • mfrom: (2257.1.31 mir3)
  • Revision ID: tarmac-20150128202134-dn97lf8gwk0xcqbc
shell, frontend: Provide a mir::shell::Shell customization point.

Approved by PS Jenkins bot, Kevin DuBois, Alexandros Frantzis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright © 2014 Canonical Ltd.
 
2
 * Copyright © 2014-2015 Canonical Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify it
5
5
 * under the terms of the GNU General Public License version 3,
16
16
 * Authored By: Alan Griffiths <alan@octopull.co.uk>
17
17
 */
18
18
 
19
 
#include "mir/shell/session_coordinator_wrapper.h"
20
 
#include "mir/shell/surface_coordinator_wrapper.h"
 
19
#include "mir/input/cursor_listener.h"
 
20
#include "mir/shell/shell_wrapper.h"
21
21
 
22
22
#include "mir_test_framework/headless_test.h"
23
23
 
26
26
#include <gtest/gtest.h>
27
27
#include <gmock/gmock.h>
28
28
 
 
29
namespace mi = mir::input;
29
30
namespace ms = mir::scene;
30
31
namespace msh = mir::shell;
31
32
namespace mtf = mir_test_framework;
34
35
 
35
36
namespace
36
37
{
37
 
struct MySurfaceCoordinator : msh::SurfaceCoordinatorWrapper
 
38
struct MyShell : msh::ShellWrapper
38
39
{
39
 
    using msh::SurfaceCoordinatorWrapper::SurfaceCoordinatorWrapper;
40
 
    MOCK_METHOD1(raise, void(std::weak_ptr<ms::Surface> const&));
 
40
    using msh::ShellWrapper::ShellWrapper;
 
41
    MOCK_METHOD1(handle_surface_created, void(std::shared_ptr<ms::Session> const&));
41
42
};
42
43
 
43
 
struct MySessionCoordinator : msh::SessionCoordinatorWrapper
 
44
struct MyCursorListener : mi::CursorListener
44
45
{
45
 
    using msh::SessionCoordinatorWrapper::SessionCoordinatorWrapper;
46
 
 
47
 
    MOCK_METHOD0(unset_focus, void());
 
46
    MyCursorListener(std::shared_ptr<mi::CursorListener> const& wrapped) :
 
47
        wrapped{wrapped} {}
 
48
 
 
49
    MOCK_METHOD2(cursor_moved_to, void(float abs_x, float abs_y));
 
50
 
 
51
    std::shared_ptr<mi::CursorListener> const wrapped;
48
52
};
49
53
 
50
54
struct ServerConfigurationWrapping : mir_test_framework::HeadlessTest
51
55
{
52
56
    void SetUp() override
53
57
    {
54
 
        server.wrap_surface_coordinator([]
55
 
            (std::shared_ptr<ms::SurfaceCoordinator> const& wrapped)
 
58
        server.wrap_shell([]
 
59
            (std::shared_ptr<msh::Shell> const& wrapped)
56
60
            {
57
 
                return std::make_shared<MySurfaceCoordinator>(wrapped);
 
61
                return std::make_shared<MyShell>(wrapped);
58
62
            });
59
63
 
60
 
        server.wrap_session_coordinator([]
61
 
            (std::shared_ptr<ms::SessionCoordinator> const& wrapped)
 
64
        server.wrap_cursor_listener([]
 
65
            (std::shared_ptr<mi::CursorListener> const& wrapped)
62
66
            {
63
 
                return std::make_shared<MySessionCoordinator>(wrapped);
 
67
                return std::make_shared<MyCursorListener>(wrapped);
64
68
            });
65
69
 
66
70
        server.apply_settings();
67
71
 
68
 
        surface_coordinator = server.the_surface_coordinator();
69
 
        session_coordinator = server.the_session_coordinator();
 
72
        shell = server.the_shell();
 
73
        cursor_listener = server.the_cursor_listener();
70
74
    }
71
75
 
72
 
    std::shared_ptr<ms::SurfaceCoordinator> surface_coordinator;
73
 
    std::shared_ptr<ms::SessionCoordinator> session_coordinator;
 
76
    std::shared_ptr<msh::Shell> shell;
 
77
    std::shared_ptr<mi::CursorListener> cursor_listener;
74
78
};
75
79
}
76
80
 
77
 
TEST_F(ServerConfigurationWrapping, surface_coordinator_is_of_wrapper_type)
78
 
{
79
 
    auto const my_surface_coordinator = std::dynamic_pointer_cast<MySurfaceCoordinator>(surface_coordinator);
80
 
 
81
 
    EXPECT_THAT(my_surface_coordinator, Ne(nullptr));
82
 
}
83
 
 
84
 
TEST_F(ServerConfigurationWrapping, can_override_surface_coordinator_methods)
85
 
{
86
 
    auto const my_surface_coordinator = std::dynamic_pointer_cast<MySurfaceCoordinator>(surface_coordinator);
87
 
 
88
 
    EXPECT_CALL(*my_surface_coordinator, raise(_)).Times(1);
89
 
    surface_coordinator->raise({});
90
 
}
91
 
 
92
 
TEST_F(ServerConfigurationWrapping, returns_same_surface_coordinator_from_cache)
93
 
{
94
 
    ASSERT_THAT(server.the_surface_coordinator(), Eq(surface_coordinator));
95
 
}
96
 
 
97
 
TEST_F(ServerConfigurationWrapping, session_coordinator_is_of_wrapper_type)
98
 
{
99
 
    auto const my_session_coordinator = std::dynamic_pointer_cast<MySessionCoordinator>(session_coordinator);
100
 
 
101
 
    EXPECT_THAT(my_session_coordinator, Ne(nullptr));
102
 
}
103
 
 
104
 
TEST_F(ServerConfigurationWrapping, can_override_session_coordinator_methods)
105
 
{
106
 
    auto const my_session_coordinator = std::dynamic_pointer_cast<MySessionCoordinator>(session_coordinator);
107
 
 
108
 
    EXPECT_CALL(*my_session_coordinator, unset_focus()).Times(1);
109
 
    session_coordinator->unset_focus();
110
 
}
111
 
 
112
 
TEST_F(ServerConfigurationWrapping, returns_same_session_coordinator_from_cache)
113
 
{
114
 
    ASSERT_THAT(server.the_session_coordinator(), Eq(session_coordinator));
 
81
TEST_F(ServerConfigurationWrapping, shell_is_of_wrapper_type)
 
82
{
 
83
    auto const my_shell = std::dynamic_pointer_cast<MyShell>(shell);
 
84
 
 
85
    EXPECT_THAT(my_shell, Ne(nullptr));
 
86
}
 
87
 
 
88
TEST_F(ServerConfigurationWrapping, can_override_shell_methods)
 
89
{
 
90
    auto const my_shell = std::dynamic_pointer_cast<MyShell>(shell);
 
91
 
 
92
    EXPECT_CALL(*my_shell, handle_surface_created(_)).Times(1);
 
93
    shell->handle_surface_created({});
 
94
}
 
95
 
 
96
TEST_F(ServerConfigurationWrapping, returns_same_shell_from_cache)
 
97
{
 
98
    ASSERT_THAT(server.the_shell(), Eq(shell));
 
99
}
 
100
 
 
101
TEST_F(ServerConfigurationWrapping, cursor_listener_is_of_wrapper_type)
 
102
{
 
103
    auto const my_cursor_listener = std::dynamic_pointer_cast<MyCursorListener>(cursor_listener);
 
104
 
 
105
    EXPECT_THAT(my_cursor_listener, Ne(nullptr));
 
106
}
 
107
 
 
108
TEST_F(ServerConfigurationWrapping, can_override_cursor_listener_methods)
 
109
{
 
110
    float const abs_x{1};
 
111
    float const abs_y(2);
 
112
 
 
113
    auto const my_cursor_listener = std::dynamic_pointer_cast<MyCursorListener>(cursor_listener);
 
114
 
 
115
    EXPECT_CALL(*my_cursor_listener, cursor_moved_to(abs_x, abs_y)).Times(1);
 
116
    cursor_listener->cursor_moved_to(abs_x, abs_y);
 
117
}
 
118
 
 
119
TEST_F(ServerConfigurationWrapping, returns_same_cursor_listener_from_cache)
 
120
{
 
121
    ASSERT_THAT(server.the_cursor_listener(), Eq(cursor_listener));
115
122
}