2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 DENSO CORPORATION
4 * Copyright © 2015 Collabora, Ltd.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include "compositor.h"
37 #include "compositor/weston.h"
38 #include "weston-test-server-protocol.h"
40 #include "ivi-shell/ivi-layout-export.h"
41 #include "shared/helpers.h"
47 void (*run)(struct test_context *);
48 } __attribute__ ((aligned (32)));
50 #define RUNNER_TEST(name) \
51 static void runner_func_##name(struct test_context *); \
53 const struct runner_test runner_test_##name \
54 __attribute__ ((section ("test_section"))) = \
56 #name, runner_func_##name \
59 static void runner_func_##name(struct test_context *ctx)
61 extern const struct runner_test __start_test_section;
62 extern const struct runner_test __stop_test_section;
64 static const struct runner_test *
65 find_runner_test(const char *name)
67 const struct runner_test *t;
69 for (t = &__start_test_section; t < &__stop_test_section; t++) {
70 if (strcmp(t->name, name) == 0)
77 struct test_launcher {
78 struct weston_compositor *compositor;
80 struct weston_process process;
81 const struct ivi_layout_interface *layout_interface;
85 const struct ivi_layout_interface *layout_interface;
86 struct wl_resource *runner_resource;
89 struct wl_listener surface_property_changed;
90 struct wl_listener surface_created;
91 struct wl_listener surface_removed;
92 struct wl_listener surface_configured;
95 static struct test_context static_context;
98 destroy_runner(struct wl_resource *resource)
100 assert(static_context.runner_resource == NULL ||
101 static_context.runner_resource == resource);
103 static_context.layout_interface = NULL;
104 static_context.runner_resource = NULL;
108 runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
110 wl_resource_destroy(resource);
114 runner_run_handler(struct wl_client *client, struct wl_resource *resource,
115 const char *test_name)
117 struct test_launcher *launcher;
118 const struct runner_test *t;
120 assert(static_context.runner_resource == NULL ||
121 static_context.runner_resource == resource);
123 launcher = wl_resource_get_user_data(resource);
124 static_context.layout_interface = launcher->layout_interface;
125 static_context.runner_resource = resource;
127 t = find_runner_test(test_name);
129 weston_log("Error: runner test \"%s\" not found.\n",
131 wl_resource_post_error(resource,
132 WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
133 "weston_test_runner: unknown: '%s'",
138 weston_log("weston_test_runner.run(\"%s\")\n", test_name);
140 t->run(&static_context);
142 weston_test_runner_send_finished(resource);
145 static const struct weston_test_runner_interface runner_implementation = {
146 runner_destroy_handler,
151 bind_runner(struct wl_client *client, void *data,
152 uint32_t version, uint32_t id)
154 struct test_launcher *launcher = data;
155 struct wl_resource *resource;
157 resource = wl_resource_create(client, &weston_test_runner_interface,
160 wl_client_post_no_memory(client);
164 wl_resource_set_implementation(resource, &runner_implementation,
165 launcher, destroy_runner);
167 if (static_context.runner_resource != NULL) {
168 weston_log("test FATAL: "
169 "attempting to run several tests in parallel.\n");
170 wl_resource_post_error(resource,
171 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
172 "attempt to run parallel tests");
177 test_client_sigchld(struct weston_process *process, int status)
179 struct test_launcher *launcher =
180 container_of(process, struct test_launcher, process);
181 struct weston_compositor *c = launcher->compositor;
183 /* Chain up from weston-test-runner's exit code so that automake
184 * knows the exit status and can report e.g. skipped tests. */
185 if (WIFEXITED(status))
186 weston_compositor_exit_with_code(c, WEXITSTATUS(status));
188 weston_compositor_exit_with_code(c, EXIT_FAILURE);
192 idle_launch_client(void *data)
194 struct test_launcher *launcher = data;
200 weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
201 weston_compositor_exit_with_code(launcher->compositor,
207 sigfillset(&allsigs);
208 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
209 execl(launcher->exe, launcher->exe, NULL);
210 weston_log("compositor: executing '%s' failed: %m\n",
215 launcher->process.pid = pid;
216 launcher->process.cleanup = test_client_sigchld;
217 weston_watch_process(&launcher->process);
221 wet_module_init(struct weston_compositor *compositor,
222 int *argc, char *argv[])
224 struct wl_event_loop *loop;
225 struct test_launcher *launcher;
227 const struct ivi_layout_interface *iface;
229 iface = ivi_layout_get_api(compositor);
232 weston_log("fatal: cannot use ivi_layout_interface.\n");
236 path = getenv("WESTON_BUILD_DIR");
238 weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
242 launcher = zalloc(sizeof *launcher);
246 launcher->compositor = compositor;
247 launcher->layout_interface = iface;
248 snprintf(launcher->exe, sizeof launcher->exe,
249 "%s/ivi-layout.ivi", path);
251 if (wl_global_create(compositor->wl_display,
252 &weston_test_runner_interface, 1,
253 launcher, bind_runner) == NULL)
256 loop = wl_display_get_event_loop(compositor->wl_display);
257 wl_event_loop_add_idle(loop, idle_launch_client, launcher);
263 runner_assert_fail(const char *cond, const char *file, int line,
264 const char *func, struct test_context *ctx)
266 weston_log("Assert failure in %s:%d, %s: '%s'\n",
267 file, line, func, cond);
269 assert(ctx->runner_resource);
270 wl_resource_post_error(ctx->runner_resource,
271 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
272 "Assert failure in %s:%d, %s: '%s'\n",
273 file, line, func, cond);
276 #define runner_assert(cond) ({ \
279 runner_assert_fail(#cond, __FILE__, __LINE__, \
284 #define runner_assert_or_return(cond) do { \
287 runner_assert_fail(#cond, __FILE__, __LINE__, \
294 /*************************** tests **********************************/
297 * This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
298 * This module is specially written to execute tests that target the
301 * This module is listed in TESTS in Makefile.am. weston-tests-env handles
302 * this module specially by loading it in ivi-shell.
304 * Once Weston init completes, this module launches one test program:
305 * ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
306 * framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
307 * connection to the single compositor instance.
309 * Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
310 * interface. A TEST() will set up the client state, and issue
311 * weston_test_runner.run request to execute the compositor-side of the test.
313 * The compositor-side parts of the tests are in this file. They are specified
314 * by RUNNER_TEST() macro, where the name argument matches the name string
315 * passed to weston_test_runner.run.
317 * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
318 * a fatal protocol error is sent to the client from runner_assert() or
319 * runner_assert_or_return(). This module catches the test program exit
320 * code and passes it out of Weston to the test harness.
322 * A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
323 * achieve multiple test points over a client action sequence.
326 RUNNER_TEST(surface_create_p1)
328 const struct ivi_layout_interface *lyt = ctx->layout_interface;
329 struct ivi_layout_surface *ivisurf[2];
332 ivisurf[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
333 runner_assert(ivisurf[0]);
335 ivisurf[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
336 runner_assert(ivisurf[1]);
338 ivi_id = lyt->get_id_of_surface(ivisurf[0]);
339 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
341 ivi_id = lyt->get_id_of_surface(ivisurf[1]);
342 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
345 RUNNER_TEST(surface_create_p2)
347 const struct ivi_layout_interface *lyt = ctx->layout_interface;
348 struct ivi_layout_surface *ivisurf;
350 /* the ivi_surface was destroyed by the client */
351 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
352 runner_assert(ivisurf == NULL);
355 RUNNER_TEST(surface_visibility)
357 const struct ivi_layout_interface *lyt = ctx->layout_interface;
358 struct ivi_layout_surface *ivisurf;
360 const struct ivi_layout_surface_properties *prop;
362 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
363 runner_assert(ivisurf);
365 ret = lyt->surface_set_visibility(ivisurf, true);
366 runner_assert(ret == IVI_SUCCEEDED);
368 lyt->commit_changes();
370 prop = lyt->get_properties_of_surface(ivisurf);
371 runner_assert(prop->visibility == true);
374 RUNNER_TEST(surface_opacity)
376 const struct ivi_layout_interface *lyt = ctx->layout_interface;
377 struct ivi_layout_surface *ivisurf;
379 const struct ivi_layout_surface_properties *prop;
381 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
382 runner_assert(ivisurf);
384 prop = lyt->get_properties_of_surface(ivisurf);
385 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
387 ret = lyt->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
388 runner_assert(ret == IVI_SUCCEEDED);
390 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
392 lyt->commit_changes();
394 runner_assert(prop->opacity == wl_fixed_from_double(0.5));
397 RUNNER_TEST(surface_dimension)
399 const struct ivi_layout_interface *lyt = ctx->layout_interface;
400 struct ivi_layout_surface *ivisurf;
401 const struct ivi_layout_surface_properties *prop;
403 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
404 runner_assert(ivisurf != NULL);
406 prop = lyt->get_properties_of_surface(ivisurf);
407 runner_assert_or_return(prop);
408 runner_assert(prop->dest_width == 1);
409 runner_assert(prop->dest_height == 1);
411 runner_assert(IVI_SUCCEEDED ==
412 lyt->surface_set_destination_rectangle(ivisurf, prop->dest_x,
413 prop->dest_y, 200, 300));
415 runner_assert(prop->dest_width == 1);
416 runner_assert(prop->dest_height == 1);
418 lyt->commit_changes();
420 prop = lyt->get_properties_of_surface(ivisurf);
421 runner_assert_or_return(prop);
422 runner_assert(prop->dest_width == 200);
423 runner_assert(prop->dest_height == 300);
426 RUNNER_TEST(surface_position)
428 const struct ivi_layout_interface *lyt = ctx->layout_interface;
429 struct ivi_layout_surface *ivisurf;
430 const struct ivi_layout_surface_properties *prop;
432 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
433 runner_assert(ivisurf != NULL);
435 prop = lyt->get_properties_of_surface(ivisurf);
436 runner_assert_or_return(prop);
437 runner_assert(prop->dest_x == 0);
438 runner_assert(prop->dest_y == 0);
440 runner_assert(lyt->surface_set_destination_rectangle(
442 prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
444 runner_assert(prop->dest_x == 0);
445 runner_assert(prop->dest_y == 0);
447 lyt->commit_changes();
449 prop = lyt->get_properties_of_surface(ivisurf);
450 runner_assert_or_return(prop);
451 runner_assert(prop->dest_x == 20);
452 runner_assert(prop->dest_y == 30);
455 RUNNER_TEST(surface_destination_rectangle)
457 const struct ivi_layout_interface *lyt = ctx->layout_interface;
458 struct ivi_layout_surface *ivisurf;
459 const struct ivi_layout_surface_properties *prop;
461 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
462 runner_assert(ivisurf != NULL);
464 prop = lyt->get_properties_of_surface(ivisurf);
465 runner_assert_or_return(prop);
466 runner_assert(prop->dest_width == 1);
467 runner_assert(prop->dest_height == 1);
468 runner_assert(prop->dest_x == 0);
469 runner_assert(prop->dest_y == 0);
471 runner_assert(lyt->surface_set_destination_rectangle(
472 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
474 prop = lyt->get_properties_of_surface(ivisurf);
475 runner_assert_or_return(prop);
476 runner_assert(prop->dest_width == 1);
477 runner_assert(prop->dest_height == 1);
478 runner_assert(prop->dest_x == 0);
479 runner_assert(prop->dest_y == 0);
481 lyt->commit_changes();
483 prop = lyt->get_properties_of_surface(ivisurf);
484 runner_assert_or_return(prop);
485 runner_assert(prop->dest_width == 200);
486 runner_assert(prop->dest_height == 300);
487 runner_assert(prop->dest_x == 20);
488 runner_assert(prop->dest_y == 30);
491 RUNNER_TEST(surface_source_rectangle)
493 const struct ivi_layout_interface *lyt = ctx->layout_interface;
494 struct ivi_layout_surface *ivisurf;
495 const struct ivi_layout_surface_properties *prop;
497 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
498 runner_assert(ivisurf != NULL);
500 prop = lyt->get_properties_of_surface(ivisurf);
501 runner_assert_or_return(prop);
502 runner_assert(prop->source_width == 0);
503 runner_assert(prop->source_height == 0);
504 runner_assert(prop->source_x == 0);
505 runner_assert(prop->source_y == 0);
507 runner_assert(lyt->surface_set_source_rectangle(
508 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
510 prop = lyt->get_properties_of_surface(ivisurf);
511 runner_assert_or_return(prop);
512 runner_assert(prop->source_width == 0);
513 runner_assert(prop->source_height == 0);
514 runner_assert(prop->source_x == 0);
515 runner_assert(prop->source_y == 0);
517 lyt->commit_changes();
519 prop = lyt->get_properties_of_surface(ivisurf);
520 runner_assert_or_return(prop);
521 runner_assert(prop->source_width == 200);
522 runner_assert(prop->source_height == 300);
523 runner_assert(prop->source_x == 20);
524 runner_assert(prop->source_y == 30);
527 RUNNER_TEST(surface_bad_opacity)
529 const struct ivi_layout_interface *lyt = ctx->layout_interface;
530 struct ivi_layout_surface *ivisurf;
531 const struct ivi_layout_surface_properties *prop;
533 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
534 runner_assert(ivisurf != NULL);
536 runner_assert(lyt->surface_set_opacity(
537 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
539 runner_assert(lyt->surface_set_opacity(
540 ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
542 runner_assert(lyt->surface_set_opacity(
543 ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
545 lyt->commit_changes();
547 prop = lyt->get_properties_of_surface(ivisurf);
548 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
550 runner_assert(lyt->surface_set_opacity(
551 ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
553 lyt->commit_changes();
555 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
557 runner_assert(lyt->surface_set_opacity(
558 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
560 lyt->commit_changes();
563 RUNNER_TEST(surface_on_many_layer)
565 const struct ivi_layout_interface *lyt = ctx->layout_interface;
566 struct ivi_layout_surface *ivisurf;
567 struct ivi_layout_layer *ivilayers[IVI_TEST_LAYER_COUNT] = {};
568 struct ivi_layout_layer **array;
572 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
573 runner_assert(ivisurf != NULL);
575 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++) {
576 ivilayers[i] = lyt->layer_create_with_dimension(
577 IVI_TEST_LAYER_ID(i), 200, 300);
578 runner_assert(lyt->layer_add_surface(
579 ivilayers[i], ivisurf) == IVI_SUCCEEDED);
582 lyt->commit_changes();
584 runner_assert(lyt->get_layers_under_surface(
585 ivisurf, &length, &array) == IVI_SUCCEEDED);
586 runner_assert(IVI_TEST_LAYER_COUNT == length);
587 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
588 runner_assert(array[i] == ivilayers[i]);
593 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
594 lyt->layer_remove_surface(ivilayers[i], ivisurf);
598 lyt->commit_changes();
600 runner_assert(lyt->get_layers_under_surface(
601 ivisurf, &length, &array) == IVI_SUCCEEDED);
602 runner_assert(length == 0 && array == NULL);
604 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
605 lyt->layer_destroy(ivilayers[i]);
608 RUNNER_TEST(ivi_layout_commit_changes)
610 const struct ivi_layout_interface *lyt = ctx->layout_interface;
612 lyt->commit_changes();
615 RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
617 const struct ivi_layout_interface *lyt = ctx->layout_interface;
618 struct ivi_layout_surface *ivisurf;
620 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
621 runner_assert(ivisurf != NULL);
622 runner_assert(lyt->surface_set_visibility(
623 ivisurf, true) == IVI_SUCCEEDED);
626 RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
628 const struct ivi_layout_interface *lyt = ctx->layout_interface;
629 struct ivi_layout_surface *ivisurf;
631 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
632 runner_assert(ivisurf != NULL);
633 runner_assert(lyt->surface_set_opacity(
634 ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
637 RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
639 const struct ivi_layout_interface *lyt = ctx->layout_interface;
640 struct ivi_layout_surface *ivisurf;
642 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
643 runner_assert(ivisurf != NULL);
644 runner_assert(lyt->surface_set_source_rectangle(
645 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
648 RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
650 const struct ivi_layout_interface *lyt = ctx->layout_interface;
651 struct ivi_layout_surface *ivisurf;
653 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
654 runner_assert(ivisurf != NULL);
655 runner_assert(lyt->surface_set_destination_rectangle(
656 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
659 RUNNER_TEST(get_surface_after_destroy_surface)
661 const struct ivi_layout_interface *lyt = ctx->layout_interface;
662 struct ivi_layout_surface *ivisurf;
664 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
665 runner_assert(ivisurf == NULL);
668 RUNNER_TEST(layer_render_order)
670 const struct ivi_layout_interface *lyt = ctx->layout_interface;
671 struct ivi_layout_layer *ivilayer;
672 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
673 struct ivi_layout_surface **array;
677 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
679 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
680 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
682 runner_assert(lyt->layer_set_render_order(
683 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
685 lyt->commit_changes();
687 runner_assert(lyt->get_surfaces_on_layer(
688 ivilayer, &length, &array) == IVI_SUCCEEDED);
689 runner_assert(IVI_TEST_SURFACE_COUNT == length);
690 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
691 runner_assert(array[i] == ivisurfs[i]);
696 runner_assert(lyt->layer_set_render_order(
697 ivilayer, NULL, 0) == IVI_SUCCEEDED);
701 lyt->commit_changes();
703 runner_assert(lyt->get_surfaces_on_layer(
704 ivilayer, &length, &array) == IVI_SUCCEEDED);
705 runner_assert(length == 0 && array == NULL);
707 lyt->layer_destroy(ivilayer);
710 RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
712 const struct ivi_layout_interface *lyt = ctx->layout_interface;
713 struct ivi_layout_layer *ivilayer;
714 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
715 struct ivi_layout_surface **array;
719 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
721 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
722 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
724 runner_assert(lyt->layer_set_render_order(
725 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
727 lyt->commit_changes();
729 runner_assert(lyt->get_surfaces_on_layer(
730 ivilayer, &length, &array) == IVI_SUCCEEDED);
731 runner_assert(IVI_TEST_SURFACE_COUNT == length);
732 for (i = 0; i < length; i++)
733 runner_assert(array[i] == ivisurfs[i]);
739 RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
741 const struct ivi_layout_interface *lyt = ctx->layout_interface;
742 struct ivi_layout_layer *ivilayer;
743 struct ivi_layout_surface *ivisurfs[2] = {};
744 struct ivi_layout_surface **array;
748 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
749 ivisurfs[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
750 ivisurfs[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
752 runner_assert(lyt->get_surfaces_on_layer(
753 ivilayer, &length, &array) == IVI_SUCCEEDED);
754 runner_assert(2 == length);
755 for (i = 0; i < length; i++)
756 runner_assert(array[i] == ivisurfs[i]);
761 lyt->layer_destroy(ivilayer);
764 RUNNER_TEST(layer_bad_render_order)
766 const struct ivi_layout_interface *lyt = ctx->layout_interface;
767 struct ivi_layout_layer *ivilayer;
768 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
769 struct ivi_layout_surface **array = NULL;
773 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
775 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
776 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
778 runner_assert(lyt->layer_set_render_order(
779 NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
781 lyt->commit_changes();
783 runner_assert(lyt->get_surfaces_on_layer(
784 NULL, &length, &array) == IVI_FAILED);
785 runner_assert(length == 0 && array == NULL);
787 runner_assert(lyt->get_surfaces_on_layer(
788 ivilayer, NULL, &array) == IVI_FAILED);
789 runner_assert(array == NULL);
791 runner_assert(lyt->get_surfaces_on_layer(
792 ivilayer, &length, NULL) == IVI_FAILED);
793 runner_assert(length == 0);
795 lyt->layer_destroy(ivilayer);
798 RUNNER_TEST(layer_add_surfaces)
800 const struct ivi_layout_interface *lyt = ctx->layout_interface;
801 struct ivi_layout_layer *ivilayer;
802 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
803 struct ivi_layout_surface **array;
807 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
809 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++) {
810 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
811 runner_assert(lyt->layer_add_surface(
812 ivilayer, ivisurfs[i]) == IVI_SUCCEEDED);
815 lyt->commit_changes();
817 runner_assert(lyt->get_surfaces_on_layer(
818 ivilayer, &length, &array) == IVI_SUCCEEDED);
819 runner_assert(IVI_TEST_SURFACE_COUNT == length);
820 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
821 runner_assert(array[i] == ivisurfs[i]);
826 runner_assert(lyt->layer_set_render_order(
827 ivilayer, NULL, 0) == IVI_SUCCEEDED);
829 for (i = IVI_TEST_SURFACE_COUNT; i-- > 0;)
830 runner_assert(lyt->layer_add_surface(
831 ivilayer, ivisurfs[i]) == IVI_SUCCEEDED);
833 lyt->commit_changes();
835 runner_assert(lyt->get_surfaces_on_layer(
836 ivilayer, &length, &array) == IVI_SUCCEEDED);
837 runner_assert(IVI_TEST_SURFACE_COUNT == length);
838 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
839 runner_assert(array[i] == ivisurfs[IVI_TEST_SURFACE_COUNT - (i + 1)]);
844 lyt->layer_destroy(ivilayer);
847 RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
849 const struct ivi_layout_interface *lyt = ctx->layout_interface;
850 struct ivi_layout_layer *ivilayer;
851 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
854 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
856 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
857 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
859 runner_assert(lyt->layer_set_render_order(
860 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
863 RUNNER_TEST(cleanup_layer)
865 const struct ivi_layout_interface *lyt = ctx->layout_interface;
866 struct ivi_layout_layer *ivilayer;
868 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
869 lyt->layer_destroy(ivilayer);
873 test_surface_properties_changed_notification_callback(struct wl_listener *listener, void *data)
876 struct test_context *ctx =
877 container_of(listener, struct test_context,
878 surface_property_changed);
879 const struct ivi_layout_interface *lyt = ctx->layout_interface;
880 struct ivi_layout_surface *ivisurf = data;
882 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
887 RUNNER_TEST(surface_properties_changed_notification)
889 const struct ivi_layout_interface *lyt = ctx->layout_interface;
890 const uint32_t id_surface = IVI_TEST_SURFACE_ID(0);
891 struct ivi_layout_surface *ivisurf;
895 ivisurf = lyt->get_surface_from_id(id_surface);
896 runner_assert(ivisurf != NULL);
898 ctx->surface_property_changed.notify = test_surface_properties_changed_notification_callback;
900 runner_assert(lyt->surface_add_listener(
901 ivisurf, &ctx->surface_property_changed) == IVI_SUCCEEDED);
903 lyt->commit_changes();
905 runner_assert(ctx->user_flags == 0);
907 runner_assert(lyt->surface_set_destination_rectangle(
908 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
910 lyt->commit_changes();
912 runner_assert(ctx->user_flags == 1);
915 runner_assert(lyt->surface_set_destination_rectangle(
916 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
918 lyt->commit_changes();
920 runner_assert(ctx->user_flags == 0);
922 // remove surface property changed listener.
923 wl_list_remove(&ctx->surface_property_changed.link);
925 runner_assert(lyt->surface_set_destination_rectangle(
926 ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
928 lyt->commit_changes();
930 runner_assert(ctx->user_flags == 0);
934 test_surface_configure_notification_callback(struct wl_listener *listener, void *data)
936 struct test_context *ctx =
937 container_of(listener, struct test_context,
939 const struct ivi_layout_interface *lyt = ctx->layout_interface;
940 struct ivi_layout_surface *ivisurf = data;
942 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
947 RUNNER_TEST(surface_configure_notification_p1)
949 const struct ivi_layout_interface *lyt = ctx->layout_interface;
951 ctx->surface_configured.notify = test_surface_configure_notification_callback;
952 runner_assert(IVI_SUCCEEDED == lyt->add_listener_configure_surface(&ctx->surface_configured));
953 lyt->commit_changes();
958 RUNNER_TEST(surface_configure_notification_p2)
960 runner_assert(ctx->user_flags == 1);
962 // remove surface configured listener.
963 wl_list_remove(&ctx->surface_configured.link);
967 RUNNER_TEST(surface_configure_notification_p3)
969 const struct ivi_layout_interface *lyt = ctx->layout_interface;
971 lyt->commit_changes();
972 runner_assert(ctx->user_flags == 0);
976 test_surface_create_notification_callback(struct wl_listener *listener, void *data)
978 struct test_context *ctx =
979 container_of(listener, struct test_context,
981 const struct ivi_layout_interface *lyt = ctx->layout_interface;
982 struct ivi_layout_surface *ivisurf = data;
984 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
989 RUNNER_TEST(surface_create_notification_p1)
991 const struct ivi_layout_interface *lyt = ctx->layout_interface;
993 ctx->surface_created.notify = test_surface_create_notification_callback;
994 runner_assert(lyt->add_listener_create_surface(
995 &ctx->surface_created) == IVI_SUCCEEDED);
1000 RUNNER_TEST(surface_create_notification_p2)
1002 runner_assert(ctx->user_flags == 1);
1004 // remove surface created listener.
1005 wl_list_remove(&ctx->surface_created.link);
1006 ctx->user_flags = 0;
1009 RUNNER_TEST(surface_create_notification_p3)
1011 runner_assert(ctx->user_flags == 0);
1015 test_surface_remove_notification_callback(struct wl_listener *listener, void *data)
1017 struct test_context *ctx =
1018 container_of(listener, struct test_context,
1020 const struct ivi_layout_interface *lyt = ctx->layout_interface;
1021 struct ivi_layout_surface *ivisurf = data;
1023 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
1025 ctx->user_flags = 1;
1028 RUNNER_TEST(surface_remove_notification_p1)
1030 const struct ivi_layout_interface *lyt = ctx->layout_interface;
1032 ctx->surface_removed.notify = test_surface_remove_notification_callback;
1033 runner_assert(lyt->add_listener_remove_surface(&ctx->surface_removed)
1036 ctx->user_flags = 0;
1039 RUNNER_TEST(surface_remove_notification_p2)
1041 runner_assert(ctx->user_flags == 1);
1043 // remove surface removed listener.
1044 wl_list_remove(&ctx->surface_removed.link);
1045 ctx->user_flags = 0;
1048 RUNNER_TEST(surface_remove_notification_p3)
1050 runner_assert(ctx->user_flags == 0);
1054 test_surface_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
1058 RUNNER_TEST(surface_bad_properties_changed_notification)
1060 const struct ivi_layout_interface *lyt = ctx->layout_interface;
1061 struct ivi_layout_surface *ivisurf;
1063 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
1064 runner_assert(ivisurf != NULL);
1066 ctx->surface_property_changed.notify = test_surface_bad_properties_changed_notification_callback;
1068 runner_assert(lyt->surface_add_listener(
1069 NULL, &ctx->surface_property_changed) == IVI_FAILED);
1070 runner_assert(lyt->surface_add_listener(
1071 ivisurf, NULL) == IVI_FAILED);