~andreas-pokorny/mir/fix-1261647

« back to all changes in this revision

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

  • Committer: Andreas Pokorny
  • Date: 2014-04-03 08:33:16 UTC
  • mfrom: (1499.1.27 development-branch)
  • Revision ID: andreas.pokorny@canonical.com-20140403083316-5be7di0ejxhgllbh
mergedĀ developmentĀ branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include "mir_test_framework/display_server_test_fixture.h"
41
41
#include "mir_test_framework/input_testing_server_configuration.h"
42
42
#include "mir_test_framework/input_testing_client_configuration.h"
 
43
#include "mir_test_framework/declarative_placement_strategy.h"
43
44
 
44
45
#include <gtest/gtest.h>
45
46
#include <gmock/gmock.h>
64
65
 
65
66
namespace
66
67
{
67
 
typedef std::map<std::string, geom::Rectangle> GeometryMap;
68
 
typedef std::map<std::string, ms::DepthId> DepthMap;
69
 
 
70
 
struct StaticPlacementStrategy : public msh::PlacementStrategy
71
 
{
72
 
    StaticPlacementStrategy(std::shared_ptr<msh::PlacementStrategy> const& underlying_strategy,
73
 
                            GeometryMap const& positions,
74
 
                            DepthMap const& depths)
75
 
        : underlying_strategy(underlying_strategy),
76
 
          surface_geometry_by_name(positions),
77
 
          surface_depths_by_name(depths)
78
 
    {
79
 
    }
80
 
 
81
 
    StaticPlacementStrategy(std::shared_ptr<msh::PlacementStrategy> const& underlying_strategy,
82
 
                            GeometryMap const& positions)
83
 
        : StaticPlacementStrategy(underlying_strategy, positions, DepthMap())
84
 
    {
85
 
    }
86
 
 
87
 
    msh::SurfaceCreationParameters place(msh::Session const& session, msh::SurfaceCreationParameters const& request_parameters)
88
 
    {
89
 
        auto placed = request_parameters;
90
 
        auto const& name = request_parameters.name;
91
 
 
92
 
        auto it = surface_geometry_by_name.find(name);
93
 
        if (it != surface_geometry_by_name.end())
94
 
        {
95
 
            auto const& geometry = it->second;
96
 
            placed.top_left = geometry.top_left;
97
 
            placed.size = geometry.size;
98
 
        }
99
 
        else
100
 
        {
101
 
            placed = underlying_strategy->place(session, placed);
102
 
        }
103
 
        placed.depth = surface_depths_by_name[name];
104
 
 
105
 
        return placed;
106
 
    }
107
 
 
108
 
    std::shared_ptr<msh::PlacementStrategy> const underlying_strategy;
109
 
    GeometryMap surface_geometry_by_name;
110
 
    DepthMap surface_depths_by_name;
111
 
};
112
68
 
113
69
std::shared_ptr<mtf::InputTestingServerConfiguration>
114
70
make_event_producing_server(mtf::CrossProcessSync const& client_ready_fence,
115
71
    int number_of_clients,
116
72
    std::function<void(mtf::InputTestingServerConfiguration& server)> const& produce_events,
117
 
    GeometryMap const& client_geometry_map, DepthMap const& client_depth_map)
 
73
    mtf::SurfaceGeometries const& client_geometries, mtf::SurfaceDepths const& client_depths)
118
74
{
119
75
    struct ServerConfiguration : mtf::InputTestingServerConfiguration
120
76
    {
121
77
        mtf::CrossProcessSync input_cb_setup_fence;
122
78
        int const number_of_clients;
123
79
        std::function<void(mtf::InputTestingServerConfiguration& server)> const produce_events;
124
 
        GeometryMap const client_geometry;
125
 
        DepthMap const client_depth;
 
80
        mtf::SurfaceGeometries const client_geometries;
 
81
        mtf::SurfaceDepths const client_depths;
126
82
 
127
83
        ServerConfiguration(mtf::CrossProcessSync const& input_cb_setup_fence, int number_of_clients,
128
84
                            std::function<void(mtf::InputTestingServerConfiguration& server)> const& produce_events,
129
 
                            GeometryMap const& client_geometry, DepthMap const& client_depth)
 
85
                            mtf::SurfaceGeometries const& client_geometries, mtf::SurfaceDepths const& client_depths)
130
86
                : input_cb_setup_fence(input_cb_setup_fence),
131
87
                  number_of_clients(number_of_clients),
132
88
                  produce_events(produce_events),
133
 
                  client_geometry(client_geometry),
134
 
                  client_depth(client_depth)
 
89
                  client_geometries(client_geometries),
 
90
                  client_depths(client_depths)
135
91
        {
136
92
        }
137
93
 
138
94
        std::shared_ptr<msh::PlacementStrategy> the_shell_placement_strategy() override
139
95
        {
140
 
            return std::make_shared<StaticPlacementStrategy>(InputTestingServerConfiguration::the_shell_placement_strategy(),
141
 
                client_geometry, client_depth);
 
96
            return std::make_shared<mtf::DeclarativePlacementStrategy>(
 
97
                InputTestingServerConfiguration::the_shell_placement_strategy(),
 
98
                client_geometries, client_depths);
142
99
        }
143
100
 
144
101
        void inject_input()
149
106
        }
150
107
    };
151
108
    return std::make_shared<ServerConfiguration>(client_ready_fence, number_of_clients,
152
 
        produce_events, client_geometry_map, client_depth_map);
 
109
        produce_events, client_geometries, client_depths);
153
110
}
154
111
 
155
112
std::shared_ptr<mtf::InputTestingServerConfiguration>
157
114
                            std::function<void(mtf::InputTestingServerConfiguration& server)> const& produce_events)
158
115
{
159
116
    return make_event_producing_server(client_ready_fence, number_of_clients,
160
 
        produce_events, GeometryMap(), DepthMap());
 
117
        produce_events, mtf::SurfaceGeometries(), mtf::SurfaceDepths());
161
118
}
162
119
 
163
120
std::shared_ptr<mtf::InputTestingClientConfiguration>
329
286
    static std::string const test_client_2 = "2";
330
287
    mtf::CrossProcessSync fence;
331
288
 
332
 
    static GeometryMap positions;
 
289
    static mtf::SurfaceGeometries positions;
333
290
    positions[test_client_1] = geom::Rectangle{geom::Point{0, 0},
334
291
                                               geom::Size{client_width, client_height}};
335
292
    positions[test_client_2] = geom::Rectangle{geom::Point{screen_width/2, screen_height/2},
342
299
            server.fake_event_hub->synthesize_event(mis::a_motion_event().with_movement(screen_width/2-1, screen_height/2-1));
343
300
            // In the bounds of the second surface
344
301
            server.fake_event_hub->synthesize_event(mis::a_motion_event().with_movement(screen_width/2, screen_height/2));
345
 
        }, positions, DepthMap());
 
302
        }, positions, mtf::SurfaceDepths());
346
303
    launch_server_process(*server_config);
347
304
 
348
305
    auto client_1 = make_event_expecting_client(test_client_1, fence,
378
335
    {
379
336
    }
380
337
 
381
 
    std::shared_ptr<msh::Surface> create_surface(msh::Session* session,
382
 
                                                 msh::SurfaceCreationParameters const& params,
383
 
                                                 mf::SurfaceId id,
384
 
                                                 std::shared_ptr<mf::EventSink> const& sink)
 
338
    std::shared_ptr<msh::Surface> create_surface(
 
339
        msh::Session* session,
 
340
        msh::SurfaceCreationParameters const& params,
 
341
        std::shared_ptr<ms::SurfaceObserver> const& observer) override
385
342
    {
386
 
        auto surface = underlying_factory->create_surface(session, params, id, sink);
 
343
        auto surface = underlying_factory->create_surface(session, params, observer);
387
344
 
388
345
        surface->set_input_region(input_rectangles);
389
346
 
390
347
        return surface;
391
348
    }
392
349
 
 
350
    void destroy_surface(std::shared_ptr<msh::Surface> const& surface) override
 
351
    {
 
352
        underlying_factory->destroy_surface(surface);
 
353
    }
 
354
 
393
355
    std::shared_ptr<msh::SurfaceFactory> const underlying_factory;
394
356
    std::vector<geom::Rectangle> const input_rectangles;
395
357
};
423
385
 
424
386
        std::shared_ptr<msh::PlacementStrategy> the_shell_placement_strategy() override
425
387
        {
426
 
            static GeometryMap positions;
 
388
            static mtf::SurfaceGeometries positions;
427
389
            positions[test_client_name] = screen_geometry;
428
390
 
429
 
            return std::make_shared<StaticPlacementStrategy>(InputTestingServerConfiguration::the_shell_placement_strategy(), positions);
 
391
            return std::make_shared<mtf::DeclarativePlacementStrategy>(
 
392
                InputTestingServerConfiguration::the_shell_placement_strategy(), positions, mtf::SurfaceDepths());
430
393
        }
431
394
        std::shared_ptr<msh::SurfaceFactory> the_shell_surface_factory() override
432
395
        {
488
451
    static geom::Rectangle const screen_geometry{geom::Point{0, 0},
489
452
        geom::Size{screen_width, screen_height}};
490
453
 
491
 
    static GeometryMap positions;
 
454
    static mtf::SurfaceGeometries positions;
492
455
    positions[test_client_name_1] = screen_geometry;
493
456
 
494
457
    auto smaller_geometry = screen_geometry;
495
458
    smaller_geometry.size.width = geom::Width{screen_width/2};
496
459
    positions[test_client_name_2] = smaller_geometry;
497
460
 
498
 
    static DepthMap depths;
 
461
    static mtf::SurfaceDepths depths;
499
462
    depths[test_client_name_1] = ms::DepthId{0};
500
463
    depths[test_client_name_2] = ms::DepthId{1};
501
464
 
564
527
    static std::string const test_client_2_name = "2";
565
528
    mtf::CrossProcessSync fence, first_client_ready_fence, second_client_done_fence;
566
529
 
567
 
    static DepthMap depths;
 
530
    static mtf::SurfaceDepths depths;
568
531
    depths[test_client_name] = ms::DepthId{0};
569
532
    depths[test_client_2_name] = ms::DepthId{1};
570
533
 
585
548
            });
586
549
 
587
550
            server.fake_event_hub->synthesize_event(mis::a_motion_event().with_movement(1,1));
588
 
        }, GeometryMap(), depths);
 
551
        }, mtf::SurfaceGeometries(), depths);
589
552
    launch_server_process(*server_config);
590
553
 
591
554
    auto client_config_1 = make_event_expecting_client(test_client_name, fence,
620
583
    static std::string const test_client = "tc";
621
584
    mtf::CrossProcessSync fence;
622
585
 
623
 
    static GeometryMap positions;
 
586
    static mtf::SurfaceGeometries positions;
624
587
    positions[test_client] = geom::Rectangle{geom::Point{screen_width/2, screen_height/2},
625
588
                                             geom::Size{client_width, client_height}};
626
589
 
632
595
                session->default_surface()->move_to(geom::Point{screen_width/2-40, screen_height/2-80});
633
596
            });
634
597
            server.fake_event_hub->synthesize_event(mis::a_motion_event().with_movement(screen_width/2+40, screen_height/2+90));
635
 
        }, positions, DepthMap());
 
598
        }, positions, mtf::SurfaceDepths());
636
599
    launch_server_process(*server_config);
637
600
 
638
601
    auto client = make_event_expecting_client(test_client, fence,