~robertcarr/mir/client-focus-notifications

« back to all changes in this revision

Viewing changes to tests/unit-tests/frontend/test_session_mediator.cpp

  • Committer: Robert Carr
  • Date: 2013-08-01 22:01:20 UTC
  • mfrom: (706.2.208 trunk)
  • Revision ID: robert.carr@canonical.com-20130801220120-6m230b3g6x0xflzd
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include "mir/surfaces/buffer_stream.h"
20
 
#include "mir/compositor/graphic_buffer_allocator.h"
 
20
#include "mir/graphics/graphic_buffer_allocator.h"
21
21
#include "mir/frontend/session_mediator_report.h"
22
22
#include "mir/frontend/session_mediator.h"
23
23
#include "mir/frontend/resource_cache.h"
24
24
#include "mir/frontend/shell.h"
25
25
#include "mir/shell/application_session.h"
26
26
#include "mir/graphics/display.h"
 
27
#include "mir/graphics/display_configuration.h"
27
28
#include "mir/graphics/platform.h"
28
29
#include "mir/graphics/platform_ipc_package.h"
29
30
#include "mir/surfaces/surface.h"
30
31
#include "mir_test_doubles/null_display.h"
31
32
#include "mir_test_doubles/mock_surface.h"
 
33
#include "mir_test_doubles/mock_display.h"
 
34
#include "mir_test_doubles/mock_shell.h"
 
35
#include "mir_test_doubles/mock_frontend_surface.h"
32
36
#include "mir_test_doubles/mock_buffer.h"
33
37
#include "mir_test_doubles/mock_shell.h"
34
38
#include "mir_test_doubles/stub_session.h"
35
39
#include "mir_test_doubles/stub_surface_builder.h"
 
40
#include "mir_test/display_config_matchers.h"
36
41
#include "mir_test/fake_shared.h"
37
 
#include "mir/events/event_sink.h"
 
42
#include "mir/frontend/event_sink.h"
38
43
#include "mir/shell/surface.h"
39
44
 
40
45
#include <gtest/gtest.h>
49
54
namespace geom = mir::geometry;
50
55
namespace mp = mir::protobuf;
51
56
namespace msh = mir::shell;
52
 
namespace me = mir::events;
53
57
namespace mt = mir::test;
54
58
namespace mtd = mt::doubles;
55
59
 
63
67
    {
64
68
        using namespace ::testing;
65
69
 
66
 
        mock_surface = std::make_shared<mtd::MockSurface>(mt::fake_shared(surface_builder));
 
70
        mock_surface = std::make_shared<mtd::MockFrontendSurface>();
67
71
        mock_buffer = std::make_shared<NiceMock<mtd::MockBuffer>>(geom::Size(), geom::Stride(), geom::PixelFormat());
68
72
 
69
73
        EXPECT_CALL(*mock_surface, size()).Times(AnyNumber()).WillRepeatedly(Return(geom::Size()));
80
84
    }
81
85
 
82
86
    mtd::StubSurfaceBuilder surface_builder;
83
 
    std::shared_ptr<mtd::MockSurface> mock_surface;
 
87
    std::shared_ptr<mtd::MockFrontendSurface> mock_surface;
84
88
    std::shared_ptr<mtd::MockBuffer> mock_buffer;
85
89
    static int const testing_client_input_fd;
86
90
};
87
91
 
88
92
int const StubSession::testing_client_input_fd{11};
89
93
 
90
 
class MockGraphicBufferAllocator : public mc::GraphicBufferAllocator
 
94
class MockGraphicBufferAllocator : public mg::GraphicBufferAllocator
91
95
{
92
96
public:
93
97
    MockGraphicBufferAllocator()
96
100
            .WillByDefault(testing::Return(std::vector<geom::PixelFormat>()));
97
101
    }
98
102
 
99
 
    std::shared_ptr<mg::Buffer> alloc_buffer(mc::BufferProperties const&)
 
103
    std::shared_ptr<mg::Buffer> alloc_buffer(mg::BufferProperties const&)
100
104
    {
101
105
        return std::shared_ptr<mg::Buffer>();
102
106
    }
112
116
    {
113
117
        using namespace testing;
114
118
        ON_CALL(*this, create_buffer_allocator(_))
115
 
            .WillByDefault(Return(std::shared_ptr<mc::GraphicBufferAllocator>()));
 
119
            .WillByDefault(Return(std::shared_ptr<mg::GraphicBufferAllocator>()));
116
120
        ON_CALL(*this, create_display(_))
117
121
            .WillByDefault(Return(std::make_shared<mtd::NullDisplay>()));
118
122
        ON_CALL(*this, get_ipc_package())
119
123
            .WillByDefault(Return(std::make_shared<mg::PlatformIPCPackage>()));
120
124
    }
121
125
 
122
 
    MOCK_METHOD1(create_buffer_allocator, std::shared_ptr<mc::GraphicBufferAllocator>(std::shared_ptr<mg::BufferInitializer> const&));
 
126
    MOCK_METHOD1(create_buffer_allocator, std::shared_ptr<mg::GraphicBufferAllocator>(std::shared_ptr<mg::BufferInitializer> const&));
123
127
    MOCK_METHOD1(create_display,
124
128
                 std::shared_ptr<mg::Display>(
125
129
                     std::shared_ptr<mg::DisplayConfigurationPolicy> const&));
126
130
    MOCK_METHOD0(get_ipc_package, std::shared_ptr<mg::PlatformIPCPackage>());
127
131
    MOCK_METHOD0(create_internal_client, std::shared_ptr<mg::InternalClient>());
128
 
    MOCK_CONST_METHOD2(fill_ipc_package, void(std::shared_ptr<mc::BufferIPCPacker> const&,
 
132
    MOCK_CONST_METHOD2(fill_ipc_package, void(std::shared_ptr<mg::BufferIPCPacker> const&,
129
133
                                              std::shared_ptr<mg::Buffer> const&));
130
134
};
131
135
 
136
140
    {
137
141
    }
138
142
 
139
 
    std::shared_ptr<mf::Session> open_session(std::string const&, std::shared_ptr<me::EventSink> const&)
 
143
    std::shared_ptr<mf::Session> open_session(std::string const&, std::shared_ptr<mf::EventSink> const&)
140
144
    {
141
145
        return stub_session;
142
146
    }
152
156
    std::shared_ptr<mf::Session> const stub_session;
153
157
};
154
158
 
155
 
class NullEventSink : public mir::events::EventSink
 
159
class NullEventSink : public mir::frontend::EventSink
156
160
{
157
161
public:
158
162
    void handle_event(MirEvent const& ) override {}
163
167
    SessionMediatorTest()
164
168
        : stub_session{std::make_shared<StubSession>()},
165
169
          shell{std::make_shared<StubShell>(stub_session)},
166
 
          graphics_platform{std::make_shared<MockPlatform>()},
 
170
          graphics_platform{std::make_shared<testing::NiceMock<MockPlatform>>()},
167
171
          graphics_display{std::make_shared<mtd::NullDisplay>()},
168
172
          buffer_allocator{std::make_shared<testing::NiceMock<MockGraphicBufferAllocator>>()},
169
173
          report{std::make_shared<mf::NullSessionMediatorReport>()},
326
330
    mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
327
331
}
328
332
 
 
333
namespace
 
334
{
 
335
struct StubConfig : public mg::DisplayConfiguration
 
336
{
 
337
    StubConfig(std::shared_ptr<mg::DisplayConfigurationOutput> const& conf)
 
338
       : outputs{conf, conf}
 
339
    {
 
340
    }
 
341
    virtual void for_each_card(std::function<void(mg::DisplayConfigurationCard const&)>) const
 
342
    {
 
343
    }
 
344
    virtual void for_each_output(std::function<void(mg::DisplayConfigurationOutput const&)> f) const
 
345
    {
 
346
        for (auto const& disp : outputs)
 
347
        {
 
348
            f(*disp);
 
349
        }
 
350
    }
 
351
    virtual void configure_output(mg::DisplayConfigurationOutputId, bool, geom::Point, size_t)
 
352
    {
 
353
    }
 
354
 
 
355
    std::vector<std::shared_ptr<mg::DisplayConfigurationOutput>> outputs;
 
356
};
 
357
 
 
358
}
 
359
 
329
360
TEST_F(SessionMediatorTest, connect_packs_display_output)
330
361
{
331
362
    using namespace testing;
 
363
    geom::Size sz{1022, 2411};
 
364
   
 
365
    std::vector<mg::DisplayConfigurationMode> modes{{sz, 344.0f},{sz, 234.0f}};
 
366
    mg::DisplayConfigurationOutput output{
 
367
        mg::DisplayConfigurationOutputId{static_cast<int>(3)},
 
368
        mg::DisplayConfigurationCardId{static_cast<int>(2)},
 
369
        modes, sz, true, false,
 
370
        geom::Point{4,12}, 0u};
 
371
 
 
372
    StubConfig config(mt::fake_shared(output));
 
373
 
 
374
    auto mock_display = std::make_shared<mtd::MockDisplay>();
 
375
    EXPECT_CALL(*mock_display, configuration())
 
376
        .Times(1)
 
377
        .WillOnce(Return(mt::fake_shared(config)));
 
378
    mf::SessionMediator mediator{
 
379
        shell, graphics_platform, mock_display,
 
380
        buffer_allocator, report, 
 
381
        std::make_shared<NullEventSink>(),
 
382
        resource_cache};
332
383
 
333
384
    mp::ConnectParameters connect_parameters;
334
385
    mp::Connection connection;
 
386
    connection.clear_platform();
 
387
    connection.clear_display_info();
 
388
    connection.clear_display_output();
335
389
 
336
390
    std::vector<geom::PixelFormat> const pixel_formats{
337
391
        geom::PixelFormat::bgr_888,
342
396
    EXPECT_CALL(*buffer_allocator, supported_pixel_formats())
343
397
        .WillOnce(Return(pixel_formats));
344
398
 
 
399
    
345
400
    mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
346
401
 
347
 
    ASSERT_EQ(1, connection.display_output().size());
348
 
    auto output = connection.display_output(0);
349
 
 
350
 
    ASSERT_EQ(pixel_formats.size(), static_cast<size_t>(output.pixel_format_size()));
351
 
 
352
 
    for (size_t i = 0; i < pixel_formats.size(); ++i)
353
 
    {
354
 
        EXPECT_EQ(pixel_formats[i], static_cast<geom::PixelFormat>(output.pixel_format(i)))
355
 
            << "i = " << i;
356
 
    }
 
402
    EXPECT_THAT(connection, mt::ProtobufConfigMatches(config.outputs, pixel_formats));
357
403
}
358
404
 
359
405
TEST_F(SessionMediatorTest, creating_surface_packs_response_with_input_fds)
467
513
namespace
468
514
{
469
515
 
470
 
struct MockEventSink : public me::EventSink
 
516
struct MockEventSink : public mf::EventSink
471
517
{
472
518
     ~MockEventSink() noexcept(true) {}
473
519
     MOCK_METHOD1(handle_event, void(MirEvent const&));
478
524
 
479
525
class EventProducingShell : public mf::Shell
480
526
{
481
 
     std::shared_ptr<mf::Session> open_session(std::string const& /* name */, std::shared_ptr<me::EventSink> const& sink)
 
527
     std::shared_ptr<mf::Session> open_session(std::string const& /* name */, std::shared_ptr<mf::EventSink> const& sink)
482
528
     {
483
529
         event_sink = sink;
484
530
         return std::make_shared<StubSession>();
497
543
         return mf::SurfaceId{1};
498
544
     }
499
545
 
500
 
     std::shared_ptr<me::EventSink> event_sink;
 
546
     std::shared_ptr<mf::EventSink> event_sink;
501
547
};
502
548
 
503
549
struct SessionMediatorEventTest : public ::testing::Test