blob: fc7527ee4236c126ffe63e8d71bec930a73f1e3b [file] [log] [blame]
Pekka Paalanen46804ca2015-03-27 11:55:21 +02001/*
2 * Copyright © 2013 DENSO CORPORATION
3 * Copyright © 2015 Collabora, Ltd.
4 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07005 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
Pekka Paalanen46804ca2015-03-27 11:55:21 +020012 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070013 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
Pekka Paalanen46804ca2015-03-27 11:55:21 +020025 */
26
27#include "config.h"
28
29#include <unistd.h>
30#include <signal.h>
31#include <string.h>
32#include <stdbool.h>
33
Jon Cruz4678bab2015-06-15 15:37:07 -070034#include "src/compositor.h"
35#include "ivi-shell/ivi-layout-export.h"
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +090036#include "ivi-test.h"
Pekka Paalanen46804ca2015-03-27 11:55:21 +020037
38struct test_context {
39 struct weston_compositor *compositor;
40 const struct ivi_controller_interface *controller_interface;
41};
42
43static void
44iassert_fail(const char *cond, const char *file, int line,
45 const char *func, struct test_context *ctx)
46{
47 weston_log("Assert failure in %s:%d, %s: '%s'\n",
48 file, line, func, cond);
49 weston_compositor_exit_with_code(ctx->compositor, EXIT_FAILURE);
50}
51
52#define iassert(cond) ({ \
53 bool b_ = (cond); \
54 if (!b_) \
55 iassert_fail(#cond, __FILE__, __LINE__, __func__, ctx); \
56 b_; \
57})
58
59/************************ tests begin ******************************/
60
61/*
62 * These are all internal ivi_layout API tests that do not require
63 * any client objects.
64 */
65
66static void
67test_surface_bad_visibility(struct test_context *ctx)
68{
69 const struct ivi_controller_interface *ctl = ctx->controller_interface;
70 bool visibility;
71
72 iassert(ctl->surface_set_visibility(NULL, true) == IVI_FAILED);
73
74 ctl->commit_changes();
75
76 visibility = ctl->surface_get_visibility(NULL);
77 iassert(visibility == false);
78}
79
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +090080static void
81test_surface_bad_destination_rectangle(struct test_context *ctx)
82{
83 const struct ivi_controller_interface *ctl = ctx->controller_interface;
84
85 iassert(ctl->surface_set_destination_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
86}
87
88static void
89test_surface_bad_orientation(struct test_context *ctx)
90{
91 const struct ivi_controller_interface *ctl = ctx->controller_interface;
92
93 iassert(ctl->surface_set_orientation(NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
94
95 iassert(ctl->surface_get_orientation(NULL) == WL_OUTPUT_TRANSFORM_NORMAL);
96}
97
98static void
99test_surface_bad_dimension(struct test_context *ctx)
100{
101 const struct ivi_controller_interface *ctl = ctx->controller_interface;
102 struct ivi_layout_surface *ivisurf = NULL;
103 int32_t dest_width;
104 int32_t dest_height;
105
106 iassert(ctl->surface_set_dimension(NULL, 200, 300) == IVI_FAILED);
107
108 ctl->commit_changes();
109
110 iassert(ctl->surface_get_dimension(NULL, &dest_width, &dest_height) == IVI_FAILED);
111 iassert(ctl->surface_get_dimension(ivisurf, NULL, &dest_height) == IVI_FAILED);
112 iassert(ctl->surface_get_dimension(ivisurf, &dest_width, NULL) == IVI_FAILED);
113}
114
115static void
116test_surface_bad_position(struct test_context *ctx)
117{
118 const struct ivi_controller_interface *ctl = ctx->controller_interface;
119 struct ivi_layout_surface *ivisurf = NULL;
120 int32_t dest_x;
121 int32_t dest_y;
122
123 iassert(ctl->surface_set_position(NULL, 20, 30) == IVI_FAILED);
124
125 ctl->commit_changes();
126
127 iassert(ctl->surface_get_position(NULL, &dest_x, &dest_y) == IVI_FAILED);
128 iassert(ctl->surface_get_position(ivisurf, NULL, &dest_y) == IVI_FAILED);
129 iassert(ctl->surface_get_position(ivisurf, &dest_x, NULL) == IVI_FAILED);
130}
131
132static void
133test_surface_bad_source_rectangle(struct test_context *ctx)
134{
135 const struct ivi_controller_interface *ctl = ctx->controller_interface;
136
137 iassert(ctl->surface_set_source_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
138}
139
140static void
141test_surface_bad_properties(struct test_context *ctx)
142{
143 const struct ivi_controller_interface *ctl = ctx->controller_interface;
144
145 iassert(ctl->get_properties_of_surface(NULL) == NULL);
146}
147
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900148static void
149test_layer_create(struct test_context *ctx)
150{
151 const struct ivi_controller_interface *ctl = ctx->controller_interface;
152 uint32_t id1;
153 uint32_t id2;
154 struct ivi_layout_layer *ivilayer;
155 struct ivi_layout_layer *new_ivilayer;
156
157 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
158 iassert(ivilayer != NULL);
159
160 iassert(IVI_TEST_LAYER_ID(0) == ctl->get_id_of_layer(ivilayer));
161
162 new_ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
163 iassert(ivilayer == new_ivilayer);
164
165 id1 = ctl->get_id_of_layer(ivilayer);
166 id2 = ctl->get_id_of_layer(new_ivilayer);
167 iassert(id1 == id2);
168
169 ctl->layer_destroy(ivilayer);
170 iassert(ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0)) == NULL);
171}
172
173static void
174test_layer_visibility(struct test_context *ctx)
175{
176 const struct ivi_controller_interface *ctl = ctx->controller_interface;
177 struct ivi_layout_layer *ivilayer;
178 const struct ivi_layout_layer_properties *prop;
179
180 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
181 iassert(ivilayer != NULL);
182
183 iassert(ctl->layer_get_visibility(ivilayer) == false);
184
185 iassert(ctl->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
186
187 iassert(ctl->layer_get_visibility(ivilayer) == false);
188
189 ctl->commit_changes();
190
191 iassert(ctl->layer_get_visibility(ivilayer) == true);
192
193 prop = ctl->get_properties_of_layer(ivilayer);
194 iassert(prop->visibility == true);
195
196 ctl->layer_destroy(ivilayer);
197}
198
199static void
200test_layer_opacity(struct test_context *ctx)
201{
202 const struct ivi_controller_interface *ctl = ctx->controller_interface;
203 struct ivi_layout_layer *ivilayer;
204 const struct ivi_layout_layer_properties *prop;
205
206 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
207 iassert(ivilayer != NULL);
208
209 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(1.0));
210
211 iassert(ctl->layer_set_opacity(
212 ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
213
214 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(1.0));
215
216 ctl->commit_changes();
217
218 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.5));
219
220 prop = ctl->get_properties_of_layer(ivilayer);
221 iassert(prop->opacity == wl_fixed_from_double(0.5));
222
223 ctl->layer_destroy(ivilayer);
224}
225
226static void
227test_layer_orientation(struct test_context *ctx)
228{
229 const struct ivi_controller_interface *ctl = ctx->controller_interface;
230 struct ivi_layout_layer *ivilayer;
231 const struct ivi_layout_layer_properties *prop;
232
233 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
234 iassert(ivilayer != NULL);
235
236 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_NORMAL);
237
238 iassert(ctl->layer_set_orientation(
239 ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
240
241 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_NORMAL);
242
243 ctl->commit_changes();
244
245 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_90);
246
247 prop = ctl->get_properties_of_layer(ivilayer);
248 iassert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
249
250 ctl->layer_destroy(ivilayer);
251}
252
253static void
254test_layer_dimension(struct test_context *ctx)
255{
256 const struct ivi_controller_interface *ctl = ctx->controller_interface;
257 struct ivi_layout_layer *ivilayer;
258 const struct ivi_layout_layer_properties *prop;
259 int32_t dest_width;
260 int32_t dest_height;
261
262 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
263 iassert(ivilayer != NULL);
264
265 iassert(ctl->layer_get_dimension(
266 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
267 iassert(dest_width == 200);
268 iassert(dest_height == 300);
269
270 iassert(ctl->layer_set_dimension(ivilayer, 400, 600) == IVI_SUCCEEDED);
271
272 iassert(ctl->layer_get_dimension(
273 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
274 iassert(dest_width == 200);
275 iassert(dest_height == 300);
276
277 ctl->commit_changes();
278
279 iassert(IVI_SUCCEEDED == ctl->layer_get_dimension(
280 ivilayer, &dest_width, &dest_height));
281 iassert(dest_width == 400);
282 iassert(dest_height == 600);
283
284 prop = ctl->get_properties_of_layer(ivilayer);
285 iassert(prop->dest_width == 400);
286 iassert(prop->dest_height == 600);
287
288 ctl->layer_destroy(ivilayer);
289}
290
291static void
292test_layer_position(struct test_context *ctx)
293{
294 const struct ivi_controller_interface *ctl = ctx->controller_interface;
295 struct ivi_layout_layer *ivilayer;
296 const struct ivi_layout_layer_properties *prop;
297 int32_t dest_x;
298 int32_t dest_y;
299
300 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
301 iassert(ivilayer != NULL);
302
303 iassert(ctl->layer_get_position(
304 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
305 iassert(dest_x == 0);
306 iassert(dest_y == 0);
307
308 iassert(ctl->layer_set_position(ivilayer, 20, 30) == IVI_SUCCEEDED);
309
310 iassert(ctl->layer_get_position(
311 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
312 iassert(dest_x == 0);
313 iassert(dest_y == 0);
314
315 ctl->commit_changes();
316
317 iassert(ctl->layer_get_position(
318 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
319 iassert(dest_x == 20);
320 iassert(dest_y == 30);
321
322 prop = ctl->get_properties_of_layer(ivilayer);
323 iassert(prop->dest_x == 20);
324 iassert(prop->dest_y == 30);
325
326 ctl->layer_destroy(ivilayer);
327}
328
329static void
330test_layer_destination_rectangle(struct test_context *ctx)
331{
332 const struct ivi_controller_interface *ctl = ctx->controller_interface;
333 struct ivi_layout_layer *ivilayer;
334 const struct ivi_layout_layer_properties *prop;
335 int32_t dest_width;
336 int32_t dest_height;
337 int32_t dest_x;
338 int32_t dest_y;
339
340 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
341 iassert(ivilayer != NULL);
342
343 prop = ctl->get_properties_of_layer(ivilayer);
344 iassert(prop->dest_width == 200);
345 iassert(prop->dest_height == 300);
346 iassert(prop->dest_x == 0);
347 iassert(prop->dest_y == 0);
348
349 iassert(ctl->layer_set_destination_rectangle(
350 ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);
351
352 prop = ctl->get_properties_of_layer(ivilayer);
353 iassert(prop->dest_width == 200);
354 iassert(prop->dest_height == 300);
355 iassert(prop->dest_x == 0);
356 iassert(prop->dest_y == 0);
357
358 ctl->commit_changes();
359
360 iassert(ctl->layer_get_dimension(
361 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
362 iassert(dest_width == 400);
363 iassert(dest_height == 600);
364
365 iassert(ctl->layer_get_position(
366 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
367 iassert(dest_x == 20);
368 iassert(dest_y == 30);
369
370 prop = ctl->get_properties_of_layer(ivilayer);
371 iassert(prop->dest_width == 400);
372 iassert(prop->dest_height == 600);
373 iassert(prop->dest_x == 20);
374 iassert(prop->dest_y == 30);
375
376 ctl->layer_destroy(ivilayer);
377}
378
379static void
380test_layer_source_rectangle(struct test_context *ctx)
381{
382 const struct ivi_controller_interface *ctl = ctx->controller_interface;
383 struct ivi_layout_layer *ivilayer;
384 const struct ivi_layout_layer_properties *prop;
385
386 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
387 iassert(ivilayer != NULL);
388
389 prop = ctl->get_properties_of_layer(ivilayer);
390 iassert(prop->source_width == 200);
391 iassert(prop->source_height == 300);
392 iassert(prop->source_x == 0);
393 iassert(prop->source_y == 0);
394
395 iassert(ctl->layer_set_source_rectangle(
396 ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);
397
398 prop = ctl->get_properties_of_layer(ivilayer);
399 iassert(prop->source_width == 200);
400 iassert(prop->source_height == 300);
401 iassert(prop->source_x == 0);
402 iassert(prop->source_y == 0);
403
404 ctl->commit_changes();
405
406 prop = ctl->get_properties_of_layer(ivilayer);
407 iassert(prop->source_width == 400);
408 iassert(prop->source_height == 600);
409 iassert(prop->source_x == 20);
410 iassert(prop->source_y == 30);
411
412 ctl->layer_destroy(ivilayer);
413}
414
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200415/************************ tests end ********************************/
416
417static void
418run_internal_tests(void *data)
419{
420 struct test_context *ctx = data;
421
422 test_surface_bad_visibility(ctx);
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +0900423 test_surface_bad_destination_rectangle(ctx);
424 test_surface_bad_orientation(ctx);
425 test_surface_bad_dimension(ctx);
426 test_surface_bad_position(ctx);
427 test_surface_bad_source_rectangle(ctx);
428 test_surface_bad_properties(ctx);
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200429
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900430 test_layer_create(ctx);
431 test_layer_visibility(ctx);
432 test_layer_opacity(ctx);
433 test_layer_orientation(ctx);
434 test_layer_dimension(ctx);
435 test_layer_position(ctx);
436 test_layer_destination_rectangle(ctx);
437 test_layer_source_rectangle(ctx);
438
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200439 weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
440 free(ctx);
441}
442
443int
444controller_module_init(struct weston_compositor *compositor,
445 int *argc, char *argv[],
446 const struct ivi_controller_interface *iface,
447 size_t iface_version);
448
449WL_EXPORT int
450controller_module_init(struct weston_compositor *compositor,
451 int *argc, char *argv[],
452 const struct ivi_controller_interface *iface,
453 size_t iface_version)
454{
455 struct wl_event_loop *loop;
456 struct test_context *ctx;
457
458 /* strict check, since this is an internal test module */
459 if (iface_version != sizeof(*iface)) {
460 weston_log("fatal: controller interface mismatch\n");
461 return -1;
462 }
463
464 ctx = zalloc(sizeof(*ctx));
465 if (!ctx)
466 return -1;
467
468 ctx->compositor = compositor;
469 ctx->controller_interface = iface;
470
471 loop = wl_display_get_event_loop(compositor->wl_display);
472 wl_event_loop_add_idle(loop, run_internal_tests, ctx);
473
474 return 0;
475}