blob: 5ac0135b1d67dfdf5c50396d596f67f55b26bff3 [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;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +090085 uint32_t user_flags;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090086};
87
88static struct test_context static_context;
89
90static void
91destroy_runner(struct wl_resource *resource)
92{
93 assert(static_context.runner_resource == NULL ||
94 static_context.runner_resource == resource);
95
96 static_context.controller_interface = NULL;
97 static_context.runner_resource = NULL;
98}
99
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200100static void
101runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
102{
103 wl_resource_destroy(resource);
104}
105
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200106static void
107runner_run_handler(struct wl_client *client, struct wl_resource *resource,
108 const char *test_name)
109{
110 struct test_launcher *launcher;
111 const struct runner_test *t;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900112
113 assert(static_context.runner_resource == NULL ||
114 static_context.runner_resource == resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200115
116 launcher = wl_resource_get_user_data(resource);
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900117 static_context.controller_interface = launcher->controller_interface;
118 static_context.runner_resource = resource;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200119
120 t = find_runner_test(test_name);
121 if (!t) {
122 weston_log("Error: runner test \"%s\" not found.\n",
123 test_name);
124 wl_resource_post_error(resource,
125 WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
126 "weston_test_runner: unknown: '%s'",
127 test_name);
128 return;
129 }
130
131 weston_log("weston_test_runner.run(\"%s\")\n", test_name);
132
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900133 t->run(&static_context);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200134
135 weston_test_runner_send_finished(resource);
136}
137
138static const struct weston_test_runner_interface runner_implementation = {
139 runner_destroy_handler,
140 runner_run_handler
141};
142
143static void
144bind_runner(struct wl_client *client, void *data,
145 uint32_t version, uint32_t id)
146{
147 struct test_launcher *launcher = data;
148 struct wl_resource *resource;
149
150 resource = wl_resource_create(client, &weston_test_runner_interface,
151 1, id);
152 if (!resource) {
153 wl_client_post_no_memory(client);
154 return;
155 }
156
157 wl_resource_set_implementation(resource, &runner_implementation,
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900158 launcher, destroy_runner);
159
160 if (static_context.runner_resource != NULL) {
161 weston_log("test FATAL: "
162 "attempting to run several tests in parallel.\n");
163 wl_resource_post_error(resource,
164 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
165 "attempt to run parallel tests");
166 }
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200167}
168
169static void
170test_client_sigchld(struct weston_process *process, int status)
171{
172 struct test_launcher *launcher =
173 container_of(process, struct test_launcher, process);
174 struct weston_compositor *c = launcher->compositor;
175
176 /* Chain up from weston-test-runner's exit code so that automake
177 * knows the exit status and can report e.g. skipped tests. */
178 if (WIFEXITED(status))
179 weston_compositor_exit_with_code(c, WEXITSTATUS(status));
180 else
181 weston_compositor_exit_with_code(c, EXIT_FAILURE);
182}
183
184static void
185idle_launch_client(void *data)
186{
187 struct test_launcher *launcher = data;
188 pid_t pid;
189 sigset_t allsigs;
190
191 pid = fork();
192 if (pid == -1) {
193 weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
194 weston_compositor_exit_with_code(launcher->compositor,
195 EXIT_FAILURE);
196 return;
197 }
198
199 if (pid == 0) {
200 sigfillset(&allsigs);
201 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
202 execl(launcher->exe, launcher->exe, NULL);
203 weston_log("compositor: executing '%s' failed: %m\n",
204 launcher->exe);
205 _exit(EXIT_FAILURE);
206 }
207
208 launcher->process.pid = pid;
209 launcher->process.cleanup = test_client_sigchld;
210 weston_watch_process(&launcher->process);
211}
212
213int
214controller_module_init(struct weston_compositor *compositor,
215 int *argc, char *argv[],
216 const struct ivi_controller_interface *iface,
217 size_t iface_version);
218
219WL_EXPORT int
220controller_module_init(struct weston_compositor *compositor,
221 int *argc, char *argv[],
222 const struct ivi_controller_interface *iface,
223 size_t iface_version)
224{
225 struct wl_event_loop *loop;
226 struct test_launcher *launcher;
227 const char *path;
228
229 /* strict check, since this is an internal test module */
230 if (iface_version != sizeof(*iface)) {
231 weston_log("fatal: controller interface mismatch\n");
232 return -1;
233 }
234
235 path = getenv("WESTON_BUILD_DIR");
236 if (!path) {
237 weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
238 return -1;
239 }
240
241 launcher = zalloc(sizeof *launcher);
242 if (!launcher)
243 return -1;
244
245 launcher->compositor = compositor;
246 launcher->controller_interface = iface;
247 snprintf(launcher->exe, sizeof launcher->exe,
248 "%s/ivi-layout.ivi", path);
249
250 if (wl_global_create(compositor->wl_display,
251 &weston_test_runner_interface, 1,
252 launcher, bind_runner) == NULL)
253 return -1;
254
255 loop = wl_display_get_event_loop(compositor->wl_display);
256 wl_event_loop_add_idle(loop, idle_launch_client, launcher);
257
258 return 0;
259}
260
261static void
262runner_assert_fail(const char *cond, const char *file, int line,
263 const char *func, struct test_context *ctx)
264{
265 weston_log("Assert failure in %s:%d, %s: '%s'\n",
266 file, line, func, cond);
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900267
268 assert(ctx->runner_resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200269 wl_resource_post_error(ctx->runner_resource,
270 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
271 "Assert failure in %s:%d, %s: '%s'\n",
272 file, line, func, cond);
273}
274
275#define runner_assert(cond) ({ \
276 bool b_ = (cond); \
277 if (!b_) \
278 runner_assert_fail(#cond, __FILE__, __LINE__, \
279 __func__, ctx); \
280 b_; \
281})
282
283#define runner_assert_or_return(cond) do { \
284 bool b_ = (cond); \
285 if (!b_) { \
286 runner_assert_fail(#cond, __FILE__, __LINE__, \
287 __func__, ctx); \
288 return; \
289 } \
290} while (0)
291
292
293/*************************** tests **********************************/
294
295/*
296 * This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
297 * This module is specially written to execute tests that target the
298 * ivi_layout API.
299 *
300 * This module is listed in TESTS in Makefile.am. weston-tests-env handles
301 * this module specially by loading it in ivi-shell.
302 *
303 * Once Weston init completes, this module launches one test program:
304 * ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
305 * framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
306 * connection to the single compositor instance.
307 *
308 * Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
309 * interface. A TEST() will set up the client state, and issue
310 * weston_test_runner.run request to execute the compositor-side of the test.
311 *
312 * The compositor-side parts of the tests are in this file. They are specified
313 * by RUNNER_TEST() macro, where the name argument matches the name string
314 * passed to weston_test_runner.run.
315 *
316 * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
317 * a fatal protocol error is sent to the client from runner_assert() or
318 * runner_assert_or_return(). This module catches the test program exit
319 * code and passes it out of Weston to the test harness.
320 *
321 * A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
322 * achieve multiple test points over a client action sequence.
323 */
324
325RUNNER_TEST(surface_create_p1)
326{
327 const struct ivi_controller_interface *ctl = ctx->controller_interface;
328 struct ivi_layout_surface *ivisurf[2];
329 uint32_t ivi_id;
330
331 ivisurf[0] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900332 runner_assert(ivisurf[0]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200333
334 ivisurf[1] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900335 runner_assert(ivisurf[1]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200336
337 ivi_id = ctl->get_id_of_surface(ivisurf[0]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900338 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200339
340 ivi_id = ctl->get_id_of_surface(ivisurf[1]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900341 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200342}
343
344RUNNER_TEST(surface_create_p2)
345{
346 const struct ivi_controller_interface *ctl = ctx->controller_interface;
347 struct ivi_layout_surface *ivisurf;
348
349 /* the ivi_surface was destroyed by the client */
350 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900351 runner_assert(ivisurf == NULL);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200352}
353
354RUNNER_TEST(surface_visibility)
355{
356 const struct ivi_controller_interface *ctl = ctx->controller_interface;
357 struct ivi_layout_surface *ivisurf;
358 int32_t ret;
359 bool visibility;
360 const struct ivi_layout_surface_properties *prop;
361
362 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900363 runner_assert(ivisurf);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200364
365 ret = ctl->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900366 runner_assert(ret == IVI_SUCCEEDED);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200367
368 ctl->commit_changes();
369
370 visibility = ctl->surface_get_visibility(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900371 runner_assert(visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200372
373 prop = ctl->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900374 runner_assert(prop->visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200375}
376
377RUNNER_TEST(surface_opacity)
378{
379 const struct ivi_controller_interface *ctl = ctx->controller_interface;
380 struct ivi_layout_surface *ivisurf;
381 int32_t ret;
382 wl_fixed_t opacity;
383 const struct ivi_layout_surface_properties *prop;
384
385 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900386 runner_assert(ivisurf);
387
388 runner_assert(ctl->surface_get_opacity(ivisurf) ==
389 wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200390
391 ret = ctl->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900392 runner_assert(ret == IVI_SUCCEEDED);
393
394 runner_assert(ctl->surface_get_opacity(ivisurf) ==
395 wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200396
397 ctl->commit_changes();
398
399 opacity = ctl->surface_get_opacity(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900400 runner_assert(opacity == wl_fixed_from_double(0.5));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200401
402 prop = ctl->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900403 runner_assert(prop->opacity == wl_fixed_from_double(0.5));
404}
405
406RUNNER_TEST(surface_orientation)
407{
408 const struct ivi_controller_interface *ctl = ctx->controller_interface;
409 struct ivi_layout_surface *ivisurf;
410 const struct ivi_layout_surface_properties *prop;
411
412 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
413 runner_assert(ivisurf != NULL);
414
415 runner_assert(ctl->surface_get_orientation(ivisurf) ==
416 WL_OUTPUT_TRANSFORM_NORMAL);
417
418 runner_assert(ctl->surface_set_orientation(
419 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
420
421 runner_assert(ctl->surface_get_orientation(ivisurf) ==
422 WL_OUTPUT_TRANSFORM_NORMAL);
423
424 ctl->commit_changes();
425
426 runner_assert(ctl->surface_get_orientation(
427 ivisurf) == WL_OUTPUT_TRANSFORM_90);
428
429 prop = ctl->get_properties_of_surface(ivisurf);
430 runner_assert_or_return(prop);
431 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
432}
433
434RUNNER_TEST(surface_dimension)
435{
436 const struct ivi_controller_interface *ctl = ctx->controller_interface;
437 struct ivi_layout_surface *ivisurf;
438 const struct ivi_layout_surface_properties *prop;
439 int32_t dest_width;
440 int32_t dest_height;
441
442 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
443 runner_assert(ivisurf != NULL);
444
445 runner_assert(ctl->surface_get_dimension(
446 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
447 runner_assert(dest_width == 1);
448 runner_assert(dest_height == 1);
449
450 runner_assert(IVI_SUCCEEDED ==
451 ctl->surface_set_dimension(ivisurf, 200, 300));
452
453 runner_assert(ctl->surface_get_dimension(
454 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
455 runner_assert(dest_width == 1);
456 runner_assert(dest_height == 1);
457
458 ctl->commit_changes();
459
460 runner_assert(ctl->surface_get_dimension(
461 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
462 runner_assert(dest_width == 200);
463 runner_assert(dest_height == 300);
464
465 prop = ctl->get_properties_of_surface(ivisurf);
466 runner_assert_or_return(prop);
467 runner_assert(prop->dest_width == 200);
468 runner_assert(prop->dest_height == 300);
469}
470
471RUNNER_TEST(surface_position)
472{
473 const struct ivi_controller_interface *ctl = ctx->controller_interface;
474 struct ivi_layout_surface *ivisurf;
475 const struct ivi_layout_surface_properties *prop;
476 int32_t dest_x;
477 int32_t dest_y;
478
479 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
480 runner_assert(ivisurf != NULL);
481
482 runner_assert(ctl->surface_get_position(
483 ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
484 runner_assert(dest_x == 0);
485 runner_assert(dest_y == 0);
486
487 runner_assert(ctl->surface_set_position(
488 ivisurf, 20, 30) == IVI_SUCCEEDED);
489
490 runner_assert(ctl->surface_get_position(
491 ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
492 runner_assert(dest_x == 0);
493 runner_assert(dest_y == 0);
494
495 ctl->commit_changes();
496
497 runner_assert(ctl->surface_get_position(
498 ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
499 runner_assert(dest_x == 20);
500 runner_assert(dest_y == 30);
501
502 prop = ctl->get_properties_of_surface(ivisurf);
503 runner_assert_or_return(prop);
504 runner_assert(prop->dest_x == 20);
505 runner_assert(prop->dest_y == 30);
506}
507
508RUNNER_TEST(surface_destination_rectangle)
509{
510 const struct ivi_controller_interface *ctl = ctx->controller_interface;
511 struct ivi_layout_surface *ivisurf;
512 const struct ivi_layout_surface_properties *prop;
513 int32_t dest_width;
514 int32_t dest_height;
515 int32_t dest_x;
516 int32_t dest_y;
517
518 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
519 runner_assert(ivisurf != NULL);
520
521 prop = ctl->get_properties_of_surface(ivisurf);
522 runner_assert_or_return(prop);
523 runner_assert(prop->dest_width == 1);
524 runner_assert(prop->dest_height == 1);
525 runner_assert(prop->dest_x == 0);
526 runner_assert(prop->dest_y == 0);
527
528 runner_assert(ctl->surface_set_destination_rectangle(
529 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
530
531 prop = ctl->get_properties_of_surface(ivisurf);
532 runner_assert_or_return(prop);
533 runner_assert(prop->dest_width == 1);
534 runner_assert(prop->dest_height == 1);
535 runner_assert(prop->dest_x == 0);
536 runner_assert(prop->dest_y == 0);
537
538 ctl->commit_changes();
539
540 runner_assert(ctl->surface_get_dimension(
541 ivisurf, &dest_width, &dest_height) == IVI_SUCCEEDED);
542 runner_assert(dest_width == 200);
543 runner_assert(dest_height == 300);
544
545 runner_assert(ctl->surface_get_position(ivisurf, &dest_x, &dest_y) == IVI_SUCCEEDED);
546 runner_assert(dest_x == 20);
547 runner_assert(dest_y == 30);
548
549 prop = ctl->get_properties_of_surface(ivisurf);
550 runner_assert_or_return(prop);
551 runner_assert(prop->dest_width == 200);
552 runner_assert(prop->dest_height == 300);
553 runner_assert(prop->dest_x == 20);
554 runner_assert(prop->dest_y == 30);
555}
556
557RUNNER_TEST(surface_source_rectangle)
558{
559 const struct ivi_controller_interface *ctl = ctx->controller_interface;
560 struct ivi_layout_surface *ivisurf;
561 const struct ivi_layout_surface_properties *prop;
562
563 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
564 runner_assert(ivisurf != NULL);
565
566 prop = ctl->get_properties_of_surface(ivisurf);
567 runner_assert_or_return(prop);
568 runner_assert(prop->source_width == 0);
569 runner_assert(prop->source_height == 0);
570 runner_assert(prop->source_x == 0);
571 runner_assert(prop->source_y == 0);
572
573 runner_assert(ctl->surface_set_source_rectangle(
574 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
575
576 prop = ctl->get_properties_of_surface(ivisurf);
577 runner_assert_or_return(prop);
578 runner_assert(prop->source_width == 0);
579 runner_assert(prop->source_height == 0);
580 runner_assert(prop->source_x == 0);
581 runner_assert(prop->source_y == 0);
582
583 ctl->commit_changes();
584
585 prop = ctl->get_properties_of_surface(ivisurf);
586 runner_assert_or_return(prop);
587 runner_assert(prop->source_width == 200);
588 runner_assert(prop->source_height == 300);
589 runner_assert(prop->source_x == 20);
590 runner_assert(prop->source_y == 30);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200591}
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900592
593RUNNER_TEST(surface_bad_opacity)
594{
595 const struct ivi_controller_interface *ctl = ctx->controller_interface;
596 struct ivi_layout_surface *ivisurf;
597 wl_fixed_t opacity;
598
599 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
600 runner_assert(ivisurf != NULL);
601
602 runner_assert(ctl->surface_set_opacity(
603 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
604
605 runner_assert(ctl->surface_set_opacity(
606 ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
607
608 runner_assert(ctl->surface_set_opacity(
609 ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
610
611 ctl->commit_changes();
612
613 opacity = ctl->surface_get_opacity(ivisurf);
614 runner_assert(opacity == wl_fixed_from_double(0.3));
615
616 runner_assert(ctl->surface_set_opacity(
617 ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
618
619 ctl->commit_changes();
620
621 opacity = ctl->surface_get_opacity(ivisurf);
622 runner_assert(opacity == wl_fixed_from_double(0.3));
623
624 runner_assert(ctl->surface_set_opacity(
625 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
626
627 ctl->commit_changes();
628
629 opacity = ctl->surface_get_opacity(NULL);
630 runner_assert(opacity == wl_fixed_from_double(0.0));
631}
632
633RUNNER_TEST(ivi_layout_commit_changes)
634{
635 const struct ivi_controller_interface *ctl = ctx->controller_interface;
636
637 ctl->commit_changes();
638}
639
640RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
641{
642 const struct ivi_controller_interface *ctl = ctx->controller_interface;
643 struct ivi_layout_surface *ivisurf;
644
645 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
646 runner_assert(ivisurf != NULL);
647 runner_assert(ctl->surface_set_visibility(
648 ivisurf, true) == IVI_SUCCEEDED);
649}
650
651RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
652{
653 const struct ivi_controller_interface *ctl = ctx->controller_interface;
654 struct ivi_layout_surface *ivisurf;
655
656 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
657 runner_assert(ivisurf != NULL);
658 runner_assert(ctl->surface_set_opacity(
659 ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
660}
661
662RUNNER_TEST(commit_changes_after_orientation_set_surface_destroy)
663{
664 const struct ivi_controller_interface *ctl = ctx->controller_interface;
665 struct ivi_layout_surface *ivisurf;
666
667 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
668 runner_assert(ivisurf != NULL);
669 runner_assert(ctl->surface_set_orientation(
670 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
671}
672
673RUNNER_TEST(commit_changes_after_dimension_set_surface_destroy)
674{
675 const struct ivi_controller_interface *ctl = ctx->controller_interface;
676 struct ivi_layout_surface *ivisurf;
677
678 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
679 runner_assert(ivisurf != NULL);
680 runner_assert(ctl->surface_set_dimension(
681 ivisurf, 200, 300) == IVI_SUCCEEDED);
682}
683
684RUNNER_TEST(commit_changes_after_position_set_surface_destroy)
685{
686 const struct ivi_controller_interface *ctl = ctx->controller_interface;
687 struct ivi_layout_surface *ivisurf;
688
689 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
690 runner_assert(ivisurf != NULL);
691 runner_assert(ctl->surface_set_position(
692 ivisurf, 20, 30) == IVI_SUCCEEDED);
693}
694
695RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
696{
697 const struct ivi_controller_interface *ctl = ctx->controller_interface;
698 struct ivi_layout_surface *ivisurf;
699
700 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
701 runner_assert(ivisurf != NULL);
702 runner_assert(ctl->surface_set_source_rectangle(
703 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
704}
705
706RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
707{
708 const struct ivi_controller_interface *ctl = ctx->controller_interface;
709 struct ivi_layout_surface *ivisurf;
710
711 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
712 runner_assert(ivisurf != NULL);
713 runner_assert(ctl->surface_set_destination_rectangle(
714 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
715}
716
717RUNNER_TEST(get_surface_after_destroy_surface)
718{
719 const struct ivi_controller_interface *ctl = ctx->controller_interface;
720 struct ivi_layout_surface *ivisurf;
721
722 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
723 runner_assert(ivisurf == NULL);
724}
725
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900726RUNNER_TEST(layer_render_order)
727{
728 const struct ivi_controller_interface *ctl = ctx->controller_interface;
729 struct ivi_layout_layer *ivilayer;
730 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
731 struct ivi_layout_surface **array;
732 int32_t length = 0;
733 uint32_t i;
734
735 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
736
737 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
738 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
739
740 runner_assert(ctl->layer_set_render_order(
741 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
742
743 ctl->commit_changes();
744
745 runner_assert(ctl->get_surfaces_on_layer(
746 ivilayer, &length, &array) == IVI_SUCCEEDED);
747 runner_assert(IVI_TEST_SURFACE_COUNT == length);
748 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
749 runner_assert(array[i] == ivisurfs[i]);
750
751 if (length > 0)
752 free(array);
753
754 runner_assert(ctl->layer_set_render_order(
755 ivilayer, NULL, 0) == IVI_SUCCEEDED);
756
757 array = NULL;
758
759 ctl->commit_changes();
760
761 runner_assert(ctl->get_surfaces_on_layer(
762 ivilayer, &length, &array) == IVI_SUCCEEDED);
763 runner_assert(length == 0 && array == NULL);
764
765 ctl->layer_destroy(ivilayer);
766}
767
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900768RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
769{
770 const struct ivi_controller_interface *ctl = ctx->controller_interface;
771 struct ivi_layout_layer *ivilayer;
772 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
773 struct ivi_layout_surface **array;
774 int32_t length = 0;
775 int32_t i;
776
777 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
778
779 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
780 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
781
782 runner_assert(ctl->layer_set_render_order(
783 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
784
785 ctl->commit_changes();
786
787 runner_assert(ctl->get_surfaces_on_layer(
788 ivilayer, &length, &array) == IVI_SUCCEEDED);
789 runner_assert(IVI_TEST_SURFACE_COUNT == length);
790 for (i = 0; i < length; i++)
791 runner_assert(array[i] == ivisurfs[i]);
792
793 if (length > 0)
794 free(array);
795}
796
797RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
798{
799 const struct ivi_controller_interface *ctl = ctx->controller_interface;
800 struct ivi_layout_layer *ivilayer;
801 struct ivi_layout_surface *ivisurfs[2] = {};
802 struct ivi_layout_surface **array;
803 int32_t length = 0;
804 int32_t i;
805
806 ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
807 ivisurfs[0] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
808 ivisurfs[1] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
809
810 runner_assert(ctl->get_surfaces_on_layer(
811 ivilayer, &length, &array) == IVI_SUCCEEDED);
812 runner_assert(2 == length);
813 for (i = 0; i < length; i++)
814 runner_assert(array[i] == ivisurfs[i]);
815
816 if (length > 0)
817 free(array);
818
819 ctl->layer_destroy(ivilayer);
820}
821
822RUNNER_TEST(layer_bad_render_order)
823{
824 const struct ivi_controller_interface *ctl = ctx->controller_interface;
825 struct ivi_layout_layer *ivilayer;
826 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
827 struct ivi_layout_surface **array = NULL;
828 int32_t length = 0;
829 uint32_t i;
830
831 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
832
833 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
834 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
835
836 runner_assert(ctl->layer_set_render_order(
837 NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
838
839 ctl->commit_changes();
840
841 runner_assert(ctl->get_surfaces_on_layer(
842 NULL, &length, &array) == IVI_FAILED);
843 runner_assert(length == 0 && array == NULL);
844
845 runner_assert(ctl->get_surfaces_on_layer(
846 ivilayer, NULL, &array) == IVI_FAILED);
847 runner_assert(array == NULL);
848
849 runner_assert(ctl->get_surfaces_on_layer(
850 ivilayer, &length, NULL) == IVI_FAILED);
851 runner_assert(length == 0);
852
853 ctl->layer_destroy(ivilayer);
854}
855
856RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
857{
858 const struct ivi_controller_interface *ctl = ctx->controller_interface;
859 struct ivi_layout_layer *ivilayer;
860 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
861 int i;
862
863 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
864
865 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
866 ivisurfs[i] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
867
868 runner_assert(ctl->layer_set_render_order(
869 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
870}
871
872RUNNER_TEST(cleanup_layer)
873{
874 const struct ivi_controller_interface *ctl = ctx->controller_interface;
875 struct ivi_layout_layer *ivilayer;
876
877 ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
878 ctl->layer_destroy(ivilayer);
879}
880
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900881static void
882test_surface_properties_changed_notification_callback(struct ivi_layout_surface *ivisurf,
883 const struct ivi_layout_surface_properties *prop,
884 enum ivi_layout_notification_mask mask,
885 void *userdata)
886{
887 struct test_context *ctx = userdata;
888 const struct ivi_controller_interface *ctl = ctx->controller_interface;
889
890 runner_assert_or_return(ctl->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
891
892 ctx->user_flags = 1;
893}
894
895RUNNER_TEST(surface_properties_changed_notification)
896{
897 const struct ivi_controller_interface *ctl = ctx->controller_interface;
898 const uint32_t id_surface = IVI_TEST_SURFACE_ID(0);
899 struct ivi_layout_surface *ivisurf;
900
901 ctx->user_flags = 0;
902
903 ivisurf = ctl->get_surface_from_id(id_surface);
904 runner_assert(ivisurf != NULL);
905
906 runner_assert(ctl->surface_add_notification(
907 ivisurf, test_surface_properties_changed_notification_callback, ctx) == IVI_SUCCEEDED);
908
909 ctl->commit_changes();
910
911 runner_assert(ctx->user_flags == 0);
912
913 runner_assert(ctl->surface_set_destination_rectangle(
914 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
915
916 ctl->commit_changes();
917
918 runner_assert(ctx->user_flags == 1);
919
920 ctx->user_flags = 0;
921 runner_assert(ctl->surface_set_destination_rectangle(
922 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
923
924 ctl->commit_changes();
925
926 runner_assert(ctx->user_flags == 0);
927
928 ctl->surface_remove_notification(ivisurf);
929 ctx->user_flags = 0;
930 runner_assert(ctl->surface_set_destination_rectangle(
931 ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
932
933 ctl->commit_changes();
934
935 runner_assert(ctx->user_flags == 0);
936}
937
938static void
939test_surface_configure_notification_callback(struct ivi_layout_surface *ivisurf,
940 void *userdata)
941{
942 struct test_context *ctx = userdata;
943 const struct ivi_controller_interface *ctl = ctx->controller_interface;
944
945 runner_assert_or_return(ctl->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
946
947 ctx->user_flags = 1;
948}
949
950RUNNER_TEST(surface_configure_notification_p1)
951{
952 const struct ivi_controller_interface *ctl = ctx->controller_interface;
953
954 runner_assert(IVI_SUCCEEDED == ctl->add_notification_configure_surface(test_surface_configure_notification_callback, ctx));
955 ctl->commit_changes();
956
957 ctx->user_flags = 0;
958}
959
960RUNNER_TEST(surface_configure_notification_p2)
961{
962 const struct ivi_controller_interface *ctl = ctx->controller_interface;
963
964 runner_assert(ctx->user_flags == 1);
965
966 ctl->remove_notification_configure_surface(test_surface_configure_notification_callback, ctx);
967 ctx->user_flags = 0;
968}
969
970RUNNER_TEST(surface_configure_notification_p3)
971{
972 const struct ivi_controller_interface *ctl = ctx->controller_interface;
973
974 ctl->commit_changes();
975 runner_assert(ctx->user_flags == 0);
976}
977
978static void
979test_surface_create_notification_callback(struct ivi_layout_surface *ivisurf,
980 void *userdata)
981{
982 struct test_context *ctx = userdata;
983 const struct ivi_controller_interface *ctl = ctx->controller_interface;
984
985 runner_assert_or_return(ctl->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
986
987 ctx->user_flags = 1;
988}
989
990RUNNER_TEST(surface_create_notification_p1)
991{
992 const struct ivi_controller_interface *ctl = ctx->controller_interface;
993
994 runner_assert(ctl->add_notification_create_surface(
995 test_surface_create_notification_callback, ctx) == IVI_SUCCEEDED);
996
997 ctx->user_flags = 0;
998}
999
1000RUNNER_TEST(surface_create_notification_p2)
1001{
1002 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1003
1004 runner_assert(ctx->user_flags == 1);
1005
1006 ctl->remove_notification_create_surface(
1007 test_surface_create_notification_callback, ctx);
1008 ctx->user_flags = 0;
1009}
1010
1011RUNNER_TEST(surface_create_notification_p3)
1012{
1013 runner_assert(ctx->user_flags == 0);
1014}
1015
1016static void
1017test_surface_remove_notification_callback(struct ivi_layout_surface *ivisurf,
1018 void *userdata)
1019{
1020 struct test_context *ctx = userdata;
1021 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1022
1023 runner_assert_or_return(ctl->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
1024
1025 ctx->user_flags = 1;
1026}
1027
1028RUNNER_TEST(surface_remove_notification_p1)
1029{
1030 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1031
1032 runner_assert(ctl->add_notification_remove_surface(
1033 test_surface_remove_notification_callback, ctx) == IVI_SUCCEEDED);
1034
1035 ctx->user_flags = 0;
1036}
1037
1038RUNNER_TEST(surface_remove_notification_p2)
1039{
1040 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1041
1042 runner_assert(ctx->user_flags == 1);
1043
1044 ctl->remove_notification_remove_surface(test_surface_remove_notification_callback, ctx);
1045 ctx->user_flags = 0;
1046}
1047
1048RUNNER_TEST(surface_remove_notification_p3)
1049{
1050 runner_assert(ctx->user_flags == 0);
1051}
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001052
1053static void
1054test_surface_bad_properties_changed_notification_callback(struct ivi_layout_surface *ivisurf,
1055 const struct ivi_layout_surface_properties *prop,
1056 enum ivi_layout_notification_mask mask,
1057 void *userdata)
1058{
1059}
1060
1061RUNNER_TEST(surface_bad_properties_changed_notification)
1062{
1063 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1064 struct ivi_layout_surface *ivisurf;
1065
1066 ivisurf = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
1067 runner_assert(ivisurf != NULL);
1068
1069 runner_assert(ctl->surface_add_notification(
1070 NULL, test_surface_bad_properties_changed_notification_callback, NULL) == IVI_FAILED);
1071 runner_assert(ctl->surface_add_notification(
1072 ivisurf, NULL, NULL) == IVI_FAILED);
1073}