~afrantzis/mir/expose-display-buffer-only-for-power-mode-on

« back to all changes in this revision

Viewing changes to tests/unit-tests/shell/test_organising_surface_factory.cpp

  • Committer: Tarmac
  • Author(s): Alan Griffiths
  • Date: 2014-04-04 15:05:56 UTC
  • mfrom: (1526.2.16 mir)
  • Revision ID: tarmac-20140404150556-wlj2g9jama5yrvro
shell: Eliminate shell::SurfaceFactory and shell::Surface and use scene::SurfaceCoordinator and scene::Surface instead.

Approved by Andreas Pokorny, Gerry Boland, Alexandros Frantzis, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 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 version 3 as
6
 
 * published by the Free Software Foundation.
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
 
 * Authored by: Robert Carr <robert.carr@canonical.com>
17
 
 */
18
 
 
19
 
#include "src/server/shell/organising_surface_factory.h"
20
 
#include "mir/shell/placement_strategy.h"
21
 
#include "mir/shell/surface_creation_parameters.h"
22
 
#include "mir/shell/session.h"
23
 
#include "mir/scene/surface.h"
24
 
#include "mir/scene/surface_event_source.h"
25
 
#include "mir/scene/surface_coordinator.h"
26
 
 
27
 
#include "mir_test_doubles/stub_shell_session.h"
28
 
#include "mir_test_doubles/null_event_sink.h"
29
 
 
30
 
#include <gtest/gtest.h>
31
 
#include <gmock/gmock.h>
32
 
 
33
 
namespace mf = mir::frontend;
34
 
namespace ms = mir::scene;
35
 
namespace msh = mir::shell;
36
 
namespace geom = mir::geometry;
37
 
namespace mtd = mir::test::doubles;
38
 
 
39
 
namespace
40
 
{
41
 
struct MockSurfaceCoordinator : public ms::SurfaceCoordinator
42
 
{
43
 
    MOCK_METHOD2(add_surface, std::shared_ptr<ms::Surface>(
44
 
        msh::SurfaceCreationParameters const&,
45
 
        std::shared_ptr<ms::SurfaceObserver> const&));
46
 
 
47
 
    void remove_surface(std::weak_ptr<ms::Surface> const& /*surface*/) override {}
48
 
    void raise(std::weak_ptr<ms::Surface> const& /*surface*/)  override {}
49
 
};
50
 
 
51
 
struct MockPlacementStrategy : public msh::PlacementStrategy
52
 
{
53
 
    MOCK_METHOD2(place, msh::SurfaceCreationParameters(msh::Session const&, msh::SurfaceCreationParameters const&));
54
 
};
55
 
 
56
 
struct OrganisingSurfaceFactorySetup : public testing::Test
57
 
{
58
 
    void SetUp()
59
 
    {
60
 
        using namespace ::testing;
61
 
        ON_CALL(*surface_coordinator, add_surface(_, _)).WillByDefault(Return(null_surface));
62
 
    }
63
 
    std::shared_ptr<ms::Surface> null_surface;
64
 
    std::shared_ptr<MockSurfaceCoordinator> surface_coordinator = std::make_shared<MockSurfaceCoordinator>();
65
 
    std::shared_ptr<ms::SurfaceObserver> const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), std::make_shared<mtd::NullEventSink>());
66
 
    std::shared_ptr<MockPlacementStrategy> placement_strategy = std::make_shared<MockPlacementStrategy>();
67
 
};
68
 
 
69
 
} // namespace
70
 
 
71
 
TEST_F(OrganisingSurfaceFactorySetup, offers_create_surface_parameters_to_placement_strategy)
72
 
{
73
 
    using namespace ::testing;
74
 
 
75
 
    msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);
76
 
 
77
 
    mtd::StubShellSession session;
78
 
    EXPECT_CALL(*surface_coordinator, add_surface(_, _)).Times(1);
79
 
 
80
 
    auto params = msh::a_surface();
81
 
    EXPECT_CALL(*placement_strategy, place(Ref(session), Ref(params))).Times(1)
82
 
        .WillOnce(Return(msh::a_surface()));
83
 
 
84
 
    factory.create_surface(&session, params, observer);
85
 
}
86
 
 
87
 
TEST_F(OrganisingSurfaceFactorySetup, forwards_create_surface_parameters_from_placement_strategy_to_underlying_factory)
88
 
{
89
 
    using namespace ::testing;
90
 
 
91
 
    msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);
92
 
 
93
 
    auto params = msh::a_surface();
94
 
    auto placed_params = params;
95
 
    placed_params.size.width = geom::Width{100};
96
 
 
97
 
    EXPECT_CALL(*placement_strategy, place(_, Ref(params))).Times(1)
98
 
        .WillOnce(Return(placed_params));
99
 
    EXPECT_CALL(*surface_coordinator, add_surface(placed_params, _));
100
 
 
101
 
    factory.create_surface(nullptr, params, observer);
102
 
}