blob: d24c9a18f388eaca4b1fc7a1b8208c4bec94c88d [file] [log] [blame]
Pekka Paalanenf5b74f72015-03-25 12:50:31 +02001/*
2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 DENSO CORPORATION
4 * Copyright © 2015 Collabora, Ltd.
5 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07006 * 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:
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020013 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070014 * 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.
17 *
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
25 * SOFTWARE.
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020026 */
27
28#include "config.h"
29
30#include <unistd.h>
31#include <signal.h>
32#include <string.h>
33
Jon Cruz4678bab2015-06-15 15:37:07 -070034#include "src/compositor.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020035#include "weston-test-server-protocol.h"
36#include "ivi-test.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070037#include "ivi-shell/ivi-layout-export.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070038#include "shared/helpers.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020039
40struct test_context;
41
42struct runner_test {
43 const char *name;
44 void (*run)(struct test_context *);
45} __attribute__ ((aligned (32)));
46
47#define RUNNER_TEST(name) \
48 static void runner_func_##name(struct test_context *); \
49 \
50 const struct runner_test runner_test_##name \
51 __attribute__ ((section ("test_section"))) = \
52 { \
53 #name, runner_func_##name \
54 }; \
55 \
56 static void runner_func_##name(struct test_context *ctx)
57
58extern const struct runner_test __start_test_section;
59extern const struct runner_test __stop_test_section;
60
61static const struct runner_test *
62find_runner_test(const char *name)
63{
64 const struct runner_test *t;
65
66 for (t = &__start_test_section; t < &__stop_test_section; t++) {
67 if (strcmp(t->name, name) == 0)
68 return t;
69 }
70
71 return NULL;
72}
73
74struct test_launcher {
75 struct weston_compositor *compositor;
76 char exe[2048];
77 struct weston_process process;
78 const struct ivi_controller_interface *controller_interface;
79};
80
81static void
82runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
83{
84 wl_resource_destroy(resource);
85}
86
87struct test_context {
88 const struct ivi_controller_interface *controller_interface;
89 struct wl_resource *runner_resource;
90};
91
92static void
93runner_run_handler(struct wl_client *client, struct wl_resource *resource,
94 const char *test_name)
95{
96 struct test_launcher *launcher;
97 const struct runner_test *t;
98 struct test_context ctx;
99
100 launcher = wl_resource_get_user_data(resource);
101 ctx.controller_interface = launcher->controller_interface;
102 ctx.runner_resource = resource;
103
104 t = find_runner_test(test_name);
105 if (!t) {
106 weston_log("Error: runner test \"%s\" not found.\n",
107 test_name);
108 wl_resource_post_error(resource,
109 WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
110 "weston_test_runner: unknown: '%s'",
111 test_name);
112 return;
113 }
114
115 weston_log("weston_test_runner.run(\"%s\")\n", test_name);
116
117 t->run(&ctx);
118
119 weston_test_runner_send_finished(resource);
120}
121
122static const struct weston_test_runner_interface runner_implementation = {
123 runner_destroy_handler,
124 runner_run_handler
125};
126
127static void
128bind_runner(struct wl_client *client, void *data,
129 uint32_t version, uint32_t id)
130{
131 struct test_launcher *launcher = data;
132 struct wl_resource *resource;
133
134 resource = wl_resource_create(client, &weston_test_runner_interface,
135 1, id);
136 if (!resource) {
137 wl_client_post_no_memory(client);
138 return;
139 }
140
141 wl_resource_set_implementation(resource, &runner_implementation,
142 launcher, NULL);
143}
144
145static void
146test_client_sigchld(struct weston_process *process, int status)
147{
148 struct test_launcher *launcher =
149 container_of(process, struct test_launcher, process);
150 struct weston_compositor *c = launcher->compositor;
151
152 /* Chain up from weston-test-runner's exit code so that automake
153 * knows the exit status and can report e.g. skipped tests. */
154 if (WIFEXITED(status))
155 weston_compositor_exit_with_code(c, WEXITSTATUS(status));
156 else
157 weston_compositor_exit_with_code(c, EXIT_FAILURE);
158}
159
160static void
161idle_launch_client(void *data)
162{
163 struct test_launcher *launcher = data;
164 pid_t pid;
165 sigset_t allsigs;
166
167 pid = fork();
168 if (pid == -1) {
169 weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
170 weston_compositor_exit_with_code(launcher->compositor,
171 EXIT_FAILURE);
172 return;
173 }
174
175 if (pid == 0) {
176 sigfillset(&allsigs);
177 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
178 execl(launcher->exe, launcher->exe, NULL);
179 weston_log("compositor: executing '%s' failed: %m\n",
180 launcher->exe);
181 _exit(EXIT_FAILURE);
182 }
183
184 launcher->process.pid = pid;
185 launcher->process.cleanup = test_client_sigchld;
186 weston_watch_process(&launcher->process);
187}
188
189int
190controller_module_init(struct weston_compositor *compositor,
191 int *argc, char *argv[],
192 const struct ivi_controller_interface *iface,
193 size_t iface_version);
194
195WL_EXPORT int
196controller_module_init(struct weston_compositor *compositor,
197 int *argc, char *argv[],
198 const struct ivi_controller_interface *iface,
199 size_t iface_version)
200{
201 struct wl_event_loop *loop;
202 struct test_launcher *launcher;
203 const char *path;
204
205 /* strict check, since this is an internal test module */
206 if (iface_version != sizeof(*iface)) {
207 weston_log("fatal: controller interface mismatch\n");
208 return -1;
209 }
210
211 path = getenv("WESTON_BUILD_DIR");
212 if (!path) {
213 weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
214 return -1;
215 }
216
217 launcher = zalloc(sizeof *launcher);
218 if (!launcher)
219 return -1;
220
221 launcher->compositor = compositor;
222 launcher->controller_interface = iface;
223 snprintf(launcher->exe, sizeof launcher->exe,
224 "%s/ivi-layout.ivi", path);
225
226 if (wl_global_create(compositor->wl_display,
227 &weston_test_runner_interface, 1,
228 launcher, bind_runner) == NULL)
229 return -1;
230
231 loop = wl_display_get_event_loop(compositor->wl_display);
232 wl_event_loop_add_idle(loop, idle_launch_client, launcher);
233
234 return 0;
235}
236
237static void
238runner_assert_fail(const char *cond, const char *file, int line,
239 const char *func, struct test_context *ctx)
240{
241 weston_log("Assert failure in %s:%d, %s: '%s'\n",
242 file, line, func, cond);
243 wl_resource_post_error(ctx->runner_resource,
244 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
245 "Assert failure in %s:%d, %s: '%s'\n",
246 file, line, func, cond);
247}
248
249#define runner_assert(cond) ({ \
250 bool b_ = (cond); \
251 if (!b_) \
252 runner_assert_fail(#cond, __FILE__, __LINE__, \
253 __func__, ctx); \
254 b_; \
255})
256
257#define runner_assert_or_return(cond) do { \
258 bool b_ = (cond); \
259 if (!b_) { \
260 runner_assert_fail(#cond, __FILE__, __LINE__, \
261 __func__, ctx); \
262 return; \
263 } \
264} while (0)
265
266
267/*************************** tests **********************************/
268
269/*
270 * This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
271 * This module is specially written to execute tests that target the
272 * ivi_layout API.
273 *
274 * This module is listed in TESTS in Makefile.am. weston-tests-env handles
275 * this module specially by loading it in ivi-shell.
276 *
277 * Once Weston init completes, this module launches one test program:
278 * ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
279 * framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
280 * connection to the single compositor instance.
281 *
282 * Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
283 * interface. A TEST() will set up the client state, and issue
284 * weston_test_runner.run request to execute the compositor-side of the test.
285 *
286 * The compositor-side parts of the tests are in this file. They are specified
287 * by RUNNER_TEST() macro, where the name argument matches the name string
288 * passed to weston_test_runner.run.
289 *
290 * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
291 * a fatal protocol error is sent to the client from runner_assert() or
292 * runner_assert_or_return(). This module catches the test program exit
293 * code and passes it out of Weston to the test harness.
294 *
295 * A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
296 * achieve multiple test points over a client action sequence.
297 */
298
299RUNNER_TEST(surface_create_p1)
300{
301 const struct ivi_controller_interface *ctl = ctx->controller_interface;
302 struct ivi_layout_surface *ivisurf[2];
303 uint32_t ivi_id;
304
305 ivisurf[0] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900306 runner_assert(ivisurf[0]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200307
308 ivisurf[1] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900309 runner_assert(ivisurf[1]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200310
311 ivi_id = ctl->get_id_of_surface(ivisurf[0]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900312 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200313
314 ivi_id = ctl->get_id_of_surface(ivisurf[1]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900315 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200316}
317
318RUNNER_TEST(surface_create_p2)
319{
320 const struct ivi_controller_interface *ctl = ctx->controller_interface;
321 struct ivi_layout_surface *ivisurf;
322
323 /* the ivi_surface was destroyed by the client */
324 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900325 runner_assert(ivisurf == NULL);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200326}
327
328RUNNER_TEST(surface_visibility)
329{
330 const struct ivi_controller_interface *ctl = ctx->controller_interface;
331 struct ivi_layout_surface *ivisurf;
332 int32_t ret;
333 bool visibility;
334 const struct ivi_layout_surface_properties *prop;
335
336 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900337 runner_assert(ivisurf);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200338
339 ret = ctl->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900340 runner_assert(ret == IVI_SUCCEEDED);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200341
342 ctl->commit_changes();
343
344 visibility = ctl->surface_get_visibility(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900345 runner_assert(visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200346
347 prop = ctl->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900348 runner_assert(prop->visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200349}
350
351RUNNER_TEST(surface_opacity)
352{
353 const struct ivi_controller_interface *ctl = ctx->controller_interface;
354 struct ivi_layout_surface *ivisurf;
355 int32_t ret;
356 wl_fixed_t opacity;
357 const struct ivi_layout_surface_properties *prop;
358
359 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900360 runner_assert(ivisurf);
361
362 runner_assert(ctl->surface_get_opacity(ivisurf) ==
363 wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200364
365 ret = ctl->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900366 runner_assert(ret == IVI_SUCCEEDED);
367
368 runner_assert(ctl->surface_get_opacity(ivisurf) ==
369 wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200370
371 ctl->commit_changes();
372
373 opacity = ctl->surface_get_opacity(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900374 runner_assert(opacity == wl_fixed_from_double(0.5));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200375
376 prop = ctl->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900377 runner_assert(prop->opacity == wl_fixed_from_double(0.5));
378}
379
380RUNNER_TEST(surface_orientation)
381{
382 const struct ivi_controller_interface *ctl = ctx->controller_interface;
383 struct ivi_layout_surface *ivisurf;
384 const struct ivi_layout_surface_properties *prop;
385
386 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
387 runner_assert(ivisurf != NULL);
388
389 runner_assert(ctl->surface_get_orientation(ivisurf) ==
390 WL_OUTPUT_TRANSFORM_NORMAL);
391
392 runner_assert(ctl->surface_set_orientation(
393 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
394
395 runner_assert(ctl->surface_get_orientation(ivisurf) ==
396 WL_OUTPUT_TRANSFORM_NORMAL);
397
398 ctl->commit_changes();
399
400 runner_assert(ctl->surface_get_orientation(
401 ivisurf) == WL_OUTPUT_TRANSFORM_90);
402
403 prop = ctl->get_properties_of_surface(ivisurf);
404 runner_assert_or_return(prop);
405 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
406}
407
408RUNNER_TEST(surface_dimension)
409{
410 const struct ivi_controller_interface *ctl = ctx->controller_interface;
411 struct ivi_layout_surface *ivisurf;
412 const struct ivi_layout_surface_properties *prop;
413 int32_t dest_width;
414 int32_t dest_height;
415
416 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
417 runner_assert(ivisurf != NULL);
418
419 runner_assert(ctl->surface_get_dimension(
420 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
421 runner_assert(dest_width == 1);
422 runner_assert(dest_height == 1);
423
424 runner_assert(IVI_SUCCEEDED ==
425 ctl->surface_set_dimension(ivisurf, 200, 300));
426
427 runner_assert(ctl->surface_get_dimension(
428 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
429 runner_assert(dest_width == 1);
430 runner_assert(dest_height == 1);
431
432 ctl->commit_changes();
433
434 runner_assert(ctl->surface_get_dimension(
435 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
436 runner_assert(dest_width == 200);
437 runner_assert(dest_height == 300);
438
439 prop = ctl->get_properties_of_surface(ivisurf);
440 runner_assert_or_return(prop);
441 runner_assert(prop->dest_width == 200);
442 runner_assert(prop->dest_height == 300);
443}
444
445RUNNER_TEST(surface_position)
446{
447 const struct ivi_controller_interface *ctl = ctx->controller_interface;
448 struct ivi_layout_surface *ivisurf;
449 const struct ivi_layout_surface_properties *prop;
450 int32_t dest_x;
451 int32_t dest_y;
452
453 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
454 runner_assert(ivisurf != NULL);
455
456 runner_assert(ctl->surface_get_position(
457 ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
458 runner_assert(dest_x == 0);
459 runner_assert(dest_y == 0);
460
461 runner_assert(ctl->surface_set_position(
462 ivisurf, 20, 30) == IVI_SUCCEEDED);
463
464 runner_assert(ctl->surface_get_position(
465 ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
466 runner_assert(dest_x == 0);
467 runner_assert(dest_y == 0);
468
469 ctl->commit_changes();
470
471 runner_assert(ctl->surface_get_position(
472 ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
473 runner_assert(dest_x == 20);
474 runner_assert(dest_y == 30);
475
476 prop = ctl->get_properties_of_surface(ivisurf);
477 runner_assert_or_return(prop);
478 runner_assert(prop->dest_x == 20);
479 runner_assert(prop->dest_y == 30);
480}
481
482RUNNER_TEST(surface_destination_rectangle)
483{
484 const struct ivi_controller_interface *ctl = ctx->controller_interface;
485 struct ivi_layout_surface *ivisurf;
486 const struct ivi_layout_surface_properties *prop;
487 int32_t dest_width;
488 int32_t dest_height;
489 int32_t dest_x;
490 int32_t dest_y;
491
492 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
493 runner_assert(ivisurf != NULL);
494
495 prop = ctl->get_properties_of_surface(ivisurf);
496 runner_assert_or_return(prop);
497 runner_assert(prop->dest_width == 1);
498 runner_assert(prop->dest_height == 1);
499 runner_assert(prop->dest_x == 0);
500 runner_assert(prop->dest_y == 0);
501
502 runner_assert(ctl->surface_set_destination_rectangle(
503 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
504
505 prop = ctl->get_properties_of_surface(ivisurf);
506 runner_assert_or_return(prop);
507 runner_assert(prop->dest_width == 1);
508 runner_assert(prop->dest_height == 1);
509 runner_assert(prop->dest_x == 0);
510 runner_assert(prop->dest_y == 0);
511
512 ctl->commit_changes();
513
514 runner_assert(ctl->surface_get_dimension(
515 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
516 runner_assert(dest_width == 200);
517 runner_assert(dest_height == 300);
518
519 runner_assert(ctl->surface_get_position(ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
520 runner_assert(dest_x == 20);
521 runner_assert(dest_y == 30);
522
523 prop = ctl->get_properties_of_surface(ivisurf);
524 runner_assert_or_return(prop);
525 runner_assert(prop->dest_width == 200);
526 runner_assert(prop->dest_height == 300);
527 runner_assert(prop->dest_x == 20);
528 runner_assert(prop->dest_y == 30);
529}
530
531RUNNER_TEST(surface_source_rectangle)
532{
533 const struct ivi_controller_interface *ctl = ctx->controller_interface;
534 struct ivi_layout_surface *ivisurf;
535 const struct ivi_layout_surface_properties *prop;
536
537 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
538 runner_assert(ivisurf != NULL);
539
540 prop = ctl->get_properties_of_surface(ivisurf);
541 runner_assert_or_return(prop);
542 runner_assert(prop->source_width == 0);
543 runner_assert(prop->source_height == 0);
544 runner_assert(prop->source_x == 0);
545 runner_assert(prop->source_y == 0);
546
547 runner_assert(ctl->surface_set_source_rectangle(
548 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
549
550 prop = ctl->get_properties_of_surface(ivisurf);
551 runner_assert_or_return(prop);
552 runner_assert(prop->source_width == 0);
553 runner_assert(prop->source_height == 0);
554 runner_assert(prop->source_x == 0);
555 runner_assert(prop->source_y == 0);
556
557 ctl->commit_changes();
558
559 prop = ctl->get_properties_of_surface(ivisurf);
560 runner_assert_or_return(prop);
561 runner_assert(prop->source_width == 200);
562 runner_assert(prop->source_height == 300);
563 runner_assert(prop->source_x == 20);
564 runner_assert(prop->source_y == 30);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200565}
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900566
567RUNNER_TEST(surface_bad_opacity)
568{
569 const struct ivi_controller_interface *ctl = ctx->controller_interface;
570 struct ivi_layout_surface *ivisurf;
571 wl_fixed_t opacity;
572
573 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
574 runner_assert(ivisurf != NULL);
575
576 runner_assert(ctl->surface_set_opacity(
577 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
578
579 runner_assert(ctl->surface_set_opacity(
580 ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
581
582 runner_assert(ctl->surface_set_opacity(
583 ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
584
585 ctl->commit_changes();
586
587 opacity = ctl->surface_get_opacity(ivisurf);
588 runner_assert(opacity == wl_fixed_from_double(0.3));
589
590 runner_assert(ctl->surface_set_opacity(
591 ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
592
593 ctl->commit_changes();
594
595 opacity = ctl->surface_get_opacity(ivisurf);
596 runner_assert(opacity == wl_fixed_from_double(0.3));
597
598 runner_assert(ctl->surface_set_opacity(
599 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
600
601 ctl->commit_changes();
602
603 opacity = ctl->surface_get_opacity(NULL);
604 runner_assert(opacity == wl_fixed_from_double(0.0));
605}
606
607RUNNER_TEST(ivi_layout_commit_changes)
608{
609 const struct ivi_controller_interface *ctl = ctx->controller_interface;
610
611 ctl->commit_changes();
612}
613
614RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
615{
616 const struct ivi_controller_interface *ctl = ctx->controller_interface;
617 struct ivi_layout_surface *ivisurf;
618
619 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
620 runner_assert(ivisurf != NULL);
621 runner_assert(ctl->surface_set_visibility(
622 ivisurf, true) == IVI_SUCCEEDED);
623}
624
625RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
626{
627 const struct ivi_controller_interface *ctl = ctx->controller_interface;
628 struct ivi_layout_surface *ivisurf;
629
630 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
631 runner_assert(ivisurf != NULL);
632 runner_assert(ctl->surface_set_opacity(
633 ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
634}
635
636RUNNER_TEST(commit_changes_after_orientation_set_surface_destroy)
637{
638 const struct ivi_controller_interface *ctl = ctx->controller_interface;
639 struct ivi_layout_surface *ivisurf;
640
641 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
642 runner_assert(ivisurf != NULL);
643 runner_assert(ctl->surface_set_orientation(
644 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
645}
646
647RUNNER_TEST(commit_changes_after_dimension_set_surface_destroy)
648{
649 const struct ivi_controller_interface *ctl = ctx->controller_interface;
650 struct ivi_layout_surface *ivisurf;
651
652 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
653 runner_assert(ivisurf != NULL);
654 runner_assert(ctl->surface_set_dimension(
655 ivisurf, 200, 300) == IVI_SUCCEEDED);
656}
657
658RUNNER_TEST(commit_changes_after_position_set_surface_destroy)
659{
660 const struct ivi_controller_interface *ctl = ctx->controller_interface;
661 struct ivi_layout_surface *ivisurf;
662
663 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
664 runner_assert(ivisurf != NULL);
665 runner_assert(ctl->surface_set_position(
666 ivisurf, 20, 30) == IVI_SUCCEEDED);
667}
668
669RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
670{
671 const struct ivi_controller_interface *ctl = ctx->controller_interface;
672 struct ivi_layout_surface *ivisurf;
673
674 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
675 runner_assert(ivisurf != NULL);
676 runner_assert(ctl->surface_set_source_rectangle(
677 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
678}
679
680RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
681{
682 const struct ivi_controller_interface *ctl = ctx->controller_interface;
683 struct ivi_layout_surface *ivisurf;
684
685 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
686 runner_assert(ivisurf != NULL);
687 runner_assert(ctl->surface_set_destination_rectangle(
688 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
689}
690
691RUNNER_TEST(get_surface_after_destroy_surface)
692{
693 const struct ivi_controller_interface *ctl = ctx->controller_interface;
694 struct ivi_layout_surface *ivisurf;
695
696 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
697 runner_assert(ivisurf == NULL);
698}
699
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900700RUNNER_TEST(layer_render_order)
701{
702 const struct ivi_controller_interface *ctl = ctx->controller_interface;
703 struct ivi_layout_layer *ivilayer;
704 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
705 struct ivi_layout_surface **array;
706 int32_t length = 0;
707 uint32_t i;
708
709 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
710
711 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
712 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
713
714 runner_assert(ctl->layer_set_render_order(
715 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
716
717 ctl->commit_changes();
718
719 runner_assert(ctl->get_surfaces_on_layer(
720 ivilayer, &length, &array) == IVI_SUCCEEDED);
721 runner_assert(IVI_TEST_SURFACE_COUNT == length);
722 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
723 runner_assert(array[i] == ivisurfs[i]);
724
725 if (length > 0)
726 free(array);
727
728 runner_assert(ctl->layer_set_render_order(
729 ivilayer, NULL, 0) == IVI_SUCCEEDED);
730
731 array = NULL;
732
733 ctl->commit_changes();
734
735 runner_assert(ctl->get_surfaces_on_layer(
736 ivilayer, &length, &array) == IVI_SUCCEEDED);
737 runner_assert(length == 0 && array == NULL);
738
739 ctl->layer_destroy(ivilayer);
740}
741
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900742RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
743{
744 const struct ivi_controller_interface *ctl = ctx->controller_interface;
745 struct ivi_layout_layer *ivilayer;
746 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
747 struct ivi_layout_surface **array;
748 int32_t length = 0;
749 int32_t i;
750
751 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
752
753 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
754 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
755
756 runner_assert(ctl->layer_set_render_order(
757 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
758
759 ctl->commit_changes();
760
761 runner_assert(ctl->get_surfaces_on_layer(
762 ivilayer, &length, &array) == IVI_SUCCEEDED);
763 runner_assert(IVI_TEST_SURFACE_COUNT == length);
764 for (i = 0; i < length; i++)
765 runner_assert(array[i] == ivisurfs[i]);
766
767 if (length > 0)
768 free(array);
769}
770
771RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
772{
773 const struct ivi_controller_interface *ctl = ctx->controller_interface;
774 struct ivi_layout_layer *ivilayer;
775 struct ivi_layout_surface *ivisurfs[2] = {};
776 struct ivi_layout_surface **array;
777 int32_t length = 0;
778 int32_t i;
779
780 ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
781 ivisurfs[0] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
782 ivisurfs[1] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
783
784 runner_assert(ctl->get_surfaces_on_layer(
785 ivilayer, &length, &array) == IVI_SUCCEEDED);
786 runner_assert(2 == length);
787 for (i = 0; i < length; i++)
788 runner_assert(array[i] == ivisurfs[i]);
789
790 if (length > 0)
791 free(array);
792
793 ctl->layer_destroy(ivilayer);
794}
795
796RUNNER_TEST(layer_bad_render_order)
797{
798 const struct ivi_controller_interface *ctl = ctx->controller_interface;
799 struct ivi_layout_layer *ivilayer;
800 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
801 struct ivi_layout_surface **array = NULL;
802 int32_t length = 0;
803 uint32_t i;
804
805 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
806
807 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
808 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
809
810 runner_assert(ctl->layer_set_render_order(
811 NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
812
813 ctl->commit_changes();
814
815 runner_assert(ctl->get_surfaces_on_layer(
816 NULL, &length, &array) == IVI_FAILED);
817 runner_assert(length == 0 && array == NULL);
818
819 runner_assert(ctl->get_surfaces_on_layer(
820 ivilayer, NULL, &array) == IVI_FAILED);
821 runner_assert(array == NULL);
822
823 runner_assert(ctl->get_surfaces_on_layer(
824 ivilayer, &length, NULL) == IVI_FAILED);
825 runner_assert(length == 0);
826
827 ctl->layer_destroy(ivilayer);
828}
829
830RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
831{
832 const struct ivi_controller_interface *ctl = ctx->controller_interface;
833 struct ivi_layout_layer *ivilayer;
834 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
835 int i;
836
837 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
838
839 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
840 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
841
842 runner_assert(ctl->layer_set_render_order(
843 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
844}
845
846RUNNER_TEST(cleanup_layer)
847{
848 const struct ivi_controller_interface *ctl = ctx->controller_interface;
849 struct ivi_layout_layer *ivilayer;
850
851 ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
852 ctl->layer_destroy(ivilayer);
853}
854