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