~mir-team/mir/development-branch

« back to all changes in this revision

Viewing changes to tests/integration-tests/client/test_mirsurface.cpp

merge trunk and resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    return arg.type == mir_surface_type_menu;
80
80
}
81
81
 
 
82
MATCHER(IsATooltip, "")
 
83
{
 
84
    return arg.type == mir_surface_type_tip;
 
85
}
 
86
 
 
87
MATCHER(IsADialog, "")
 
88
{
 
89
    return arg.type == mir_surface_type_dialog;
 
90
}
 
91
 
82
92
MATCHER_P(HasParent, parent, "")
83
93
{
84
94
    return arg.parent_id.is_set() && arg.parent_id.value().as_value() == parent->id();
85
95
}
86
96
 
87
 
MATCHER_P(MatchesAttachment, rect, "")
88
 
{
89
 
    return arg.attachment_rect.is_set() &&
90
 
           arg.attachment_rect.value().top_left.x.as_int() == rect.left &&
91
 
           arg.attachment_rect.value().top_left.y.as_int() == rect.top &&
92
 
           arg.attachment_rect.value().size.width.as_uint32_t() == rect.width &&
93
 
           arg.attachment_rect.value().size.height.as_uint32_t() == rect.height;
 
97
MATCHER(NoParentSet, "")
 
98
{
 
99
    return arg.parent_id.is_set() == false;
 
100
}
 
101
 
 
102
MATCHER_P(MatchesAuxRect, rect, "")
 
103
{
 
104
    return arg.aux_rect.is_set() &&
 
105
           arg.aux_rect.value().top_left.x.as_int() == rect.left &&
 
106
           arg.aux_rect.value().top_left.y.as_int() == rect.top &&
 
107
           arg.aux_rect.value().size.width.as_uint32_t() == rect.width &&
 
108
           arg.aux_rect.value().size.height.as_uint32_t() == rect.height;
94
109
}
95
110
 
96
111
MATCHER_P(MatchesEdge, edge, "")
139
154
    std::shared_ptr<MockSurfaceCoordinator> mock_surface_coordinator;
140
155
};
141
156
 
142
 
 
143
157
TEST_F(ClientMirSurface, sends_optional_params)
144
158
{
145
159
    EXPECT_CALL(*mock_surface_coordinator, add_surface(AllOf(MatchesRequired(&spec), MatchesOptional(&spec)),_));
150
164
    ASSERT_THAT(surf.get(), IsValid());
151
165
    spec.parent = surf.get();
152
166
 
153
 
    // The second time around we don't care if the surface gets created,
154
 
    // but we'd like to validate that the server received the output id specified
155
 
    int const arbitrary_output_id = 3000;
156
 
    spec.output_id = arbitrary_output_id;
157
 
 
158
167
    EXPECT_CALL(*mock_surface_coordinator, add_surface(MatchesOptional(&spec),_));
159
168
    create_surface(&spec);
160
169
}
170
179
 
171
180
    auto spec_deleter = [](MirSurfaceSpec* spec) {mir_surface_spec_release(spec);};
172
181
    std::unique_ptr<MirSurfaceSpec, decltype(spec_deleter)> menu_spec{
173
 
        mir_connection_create_spec_for_menu_surface(connection, 640, 480,
 
182
        mir_connection_create_spec_for_menu(connection, 640, 480,
174
183
            mir_pixel_format_abgr_8888, parent.get(), &attachment_rect,
175
184
            edge),
176
185
        spec_deleter
179
188
    ASSERT_THAT(menu_spec, NotNull());
180
189
 
181
190
    EXPECT_CALL(*mock_surface_coordinator, add_surface(AllOf(IsAMenu(),
182
 
        HasParent(parent.get()), MatchesAttachment(attachment_rect), MatchesEdge(edge)),_));
 
191
        HasParent(parent.get()), MatchesAuxRect(attachment_rect), MatchesEdge(edge)),_));
183
192
    create_surface(menu_spec.get());
184
193
}
 
194
 
 
195
TEST_F(ClientMirSurface, as_tooltip_sends_correct_params)
 
196
{
 
197
    EXPECT_CALL(*mock_surface_coordinator, add_surface(_,_));
 
198
    auto parent = create_surface(&spec);
 
199
    ASSERT_THAT(parent.get(), IsValid());
 
200
 
 
201
    MirRectangle target_zone_rect{100, 200, 300, 400};
 
202
 
 
203
    auto spec_deleter = [](MirSurfaceSpec* spec) {mir_surface_spec_release(spec);};
 
204
    std::unique_ptr<MirSurfaceSpec, decltype(spec_deleter)> tooltip_spec{
 
205
        mir_connection_create_spec_for_tooltip(connection, 640, 480,
 
206
            mir_pixel_format_abgr_8888, parent.get(), &target_zone_rect),
 
207
        spec_deleter
 
208
    };
 
209
 
 
210
    ASSERT_THAT(tooltip_spec, NotNull());
 
211
 
 
212
    EXPECT_CALL(*mock_surface_coordinator, add_surface(AllOf(IsATooltip(),
 
213
        HasParent(parent.get()), MatchesAuxRect(target_zone_rect)),_));
 
214
    create_surface(tooltip_spec.get());
 
215
}
 
216
 
 
217
TEST_F(ClientMirSurface, as_dialog_sends_correct_params)
 
218
{
 
219
    auto spec_deleter = [](MirSurfaceSpec* spec) {mir_surface_spec_release(spec);};
 
220
    std::unique_ptr<MirSurfaceSpec, decltype(spec_deleter)> dialog_spec{
 
221
        mir_connection_create_spec_for_dialog(connection, 640, 480, mir_pixel_format_abgr_8888),
 
222
        spec_deleter
 
223
    };
 
224
 
 
225
    ASSERT_THAT(dialog_spec, NotNull());
 
226
 
 
227
    EXPECT_CALL(*mock_surface_coordinator, add_surface(AllOf(IsADialog(),
 
228
        NoParentSet()),_));
 
229
    create_surface(dialog_spec.get());
 
230
}
 
231
 
 
232
TEST_F(ClientMirSurface, as_modal_dialog_sends_correct_params)
 
233
{
 
234
    EXPECT_CALL(*mock_surface_coordinator, add_surface(_,_));
 
235
    auto parent = create_surface(&spec);
 
236
    ASSERT_THAT(parent.get(), IsValid());
 
237
 
 
238
    auto spec_deleter = [](MirSurfaceSpec* spec) {mir_surface_spec_release(spec);};
 
239
    std::unique_ptr<MirSurfaceSpec, decltype(spec_deleter)> dialog_spec{
 
240
        mir_connection_create_spec_for_modal_dialog(connection, 640, 480,
 
241
            mir_pixel_format_abgr_8888, parent.get()),
 
242
        spec_deleter
 
243
    };
 
244
 
 
245
    ASSERT_THAT(dialog_spec, NotNull());
 
246
 
 
247
    EXPECT_CALL(*mock_surface_coordinator, add_surface(AllOf(IsADialog(),
 
248
        HasParent(parent.get())),_));
 
249
    create_surface(dialog_spec.get());
 
250
}