Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * Copyright © 2013 DENSO CORPORATION |
| 4 | * Copyright © 2015 Collabora, Ltd. |
| 5 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 13 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 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 Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | |
| 30 | #include <unistd.h> |
| 31 | #include <signal.h> |
| 32 | #include <string.h> |
| 33 | |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 34 | #include "src/compositor.h" |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 35 | #include "weston-test-server-protocol.h" |
| 36 | #include "ivi-test.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 37 | #include "ivi-shell/ivi-layout-export.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 38 | #include "shared/helpers.h" |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 39 | |
| 40 | struct test_context; |
| 41 | |
| 42 | struct 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 | |
| 58 | extern const struct runner_test __start_test_section; |
| 59 | extern const struct runner_test __stop_test_section; |
| 60 | |
| 61 | static const struct runner_test * |
| 62 | find_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 | |
| 74 | struct 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 | |
| 81 | static void |
| 82 | runner_destroy_handler(struct wl_client *client, struct wl_resource *resource) |
| 83 | { |
| 84 | wl_resource_destroy(resource); |
| 85 | } |
| 86 | |
| 87 | struct test_context { |
| 88 | const struct ivi_controller_interface *controller_interface; |
| 89 | struct wl_resource *runner_resource; |
| 90 | }; |
| 91 | |
| 92 | static void |
| 93 | runner_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 | |
| 122 | static const struct weston_test_runner_interface runner_implementation = { |
| 123 | runner_destroy_handler, |
| 124 | runner_run_handler |
| 125 | }; |
| 126 | |
| 127 | static void |
| 128 | bind_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 | |
| 145 | static void |
| 146 | test_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 | |
| 160 | static void |
| 161 | idle_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 | |
| 189 | int |
| 190 | controller_module_init(struct weston_compositor *compositor, |
| 191 | int *argc, char *argv[], |
| 192 | const struct ivi_controller_interface *iface, |
| 193 | size_t iface_version); |
| 194 | |
| 195 | WL_EXPORT int |
| 196 | controller_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 | |
| 237 | static void |
| 238 | runner_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 | |
| 299 | RUNNER_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 Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 306 | runner_assert(ivisurf[0]); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 307 | |
| 308 | ivisurf[1] = ctl->get_surface_from_id(IVI_TEST_SURFACE_ID(1)); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 309 | runner_assert(ivisurf[1]); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 310 | |
| 311 | ivi_id = ctl->get_id_of_surface(ivisurf[0]); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 312 | runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0)); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 313 | |
| 314 | ivi_id = ctl->get_id_of_surface(ivisurf[1]); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 315 | runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1)); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | RUNNER_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 Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 325 | runner_assert(ivisurf == NULL); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | RUNNER_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 Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 337 | runner_assert(ivisurf); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 338 | |
| 339 | ret = ctl->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 340 | runner_assert(ret == IVI_SUCCEEDED); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 341 | |
| 342 | ctl->commit_changes(); |
| 343 | |
| 344 | visibility = ctl->surface_get_visibility(ivisurf); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 345 | runner_assert(visibility == true); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 346 | |
| 347 | prop = ctl->get_properties_of_surface(ivisurf); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 348 | runner_assert(prop->visibility == true); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | RUNNER_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 Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 360 | runner_assert(ivisurf); |
| 361 | |
| 362 | runner_assert(ctl->surface_get_opacity(ivisurf) == |
| 363 | wl_fixed_from_double(1.0)); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 364 | |
| 365 | ret = ctl->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5)); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 366 | runner_assert(ret == IVI_SUCCEEDED); |
| 367 | |
| 368 | runner_assert(ctl->surface_get_opacity(ivisurf) == |
| 369 | wl_fixed_from_double(1.0)); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 370 | |
| 371 | ctl->commit_changes(); |
| 372 | |
| 373 | opacity = ctl->surface_get_opacity(ivisurf); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 374 | runner_assert(opacity == wl_fixed_from_double(0.5)); |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 375 | |
| 376 | prop = ctl->get_properties_of_surface(ivisurf); |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 377 | runner_assert(prop->opacity == wl_fixed_from_double(0.5)); |
| 378 | } |
| 379 | |
| 380 | RUNNER_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 | |
| 408 | RUNNER_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 | |
| 445 | RUNNER_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 | |
| 482 | RUNNER_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 | |
| 531 | RUNNER_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 Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 565 | } |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 566 | |
| 567 | RUNNER_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 | |
| 607 | RUNNER_TEST(ivi_layout_commit_changes) |
| 608 | { |
| 609 | const struct ivi_controller_interface *ctl = ctx->controller_interface; |
| 610 | |
| 611 | ctl->commit_changes(); |
| 612 | } |
| 613 | |
| 614 | RUNNER_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 | |
| 625 | RUNNER_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 | |
| 636 | RUNNER_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 | |
| 647 | RUNNER_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 | |
| 658 | RUNNER_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 | |
| 669 | RUNNER_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 | |
| 680 | RUNNER_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 | |
| 691 | RUNNER_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 Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame^] | 700 | RUNNER_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 | |