Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Collabora, Ltd. |
| 3 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 11 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 31 | #include "shared/helpers.h" |
Bryce Harrington | e99e4bf | 2016-03-16 14:15:18 -0700 | [diff] [blame^] | 32 | #include "shared/xalloc.h" |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 33 | #include "weston-test-client-helper.h" |
| 34 | #include "ivi-application-client-protocol.h" |
| 35 | #include "ivi-test.h" |
| 36 | |
| 37 | struct runner { |
| 38 | struct client *client; |
| 39 | struct weston_test_runner *test_runner; |
| 40 | int done; |
| 41 | }; |
| 42 | |
| 43 | static void |
| 44 | runner_finished_handler(void *data, struct weston_test_runner *test_runner) |
| 45 | { |
| 46 | struct runner *runner = data; |
| 47 | |
| 48 | runner->done = 1; |
| 49 | } |
| 50 | |
| 51 | static const struct weston_test_runner_listener test_runner_listener = { |
| 52 | runner_finished_handler |
| 53 | }; |
| 54 | |
| 55 | static struct runner * |
| 56 | client_create_runner(struct client *client) |
| 57 | { |
| 58 | struct runner *runner; |
| 59 | struct global *g; |
| 60 | struct global *global_runner = NULL; |
| 61 | |
| 62 | runner = xzalloc(sizeof(*runner)); |
| 63 | runner->client = client; |
| 64 | |
| 65 | wl_list_for_each(g, &client->global_list, link) { |
| 66 | if (strcmp(g->interface, "weston_test_runner")) |
| 67 | continue; |
| 68 | |
| 69 | if (global_runner) |
| 70 | assert(0 && "multiple weston_test_runner objects"); |
| 71 | |
| 72 | global_runner = g; |
| 73 | } |
| 74 | |
| 75 | assert(global_runner && "no weston_test_runner found"); |
| 76 | assert(global_runner->version == 1); |
| 77 | |
| 78 | runner->test_runner = wl_registry_bind(client->wl_registry, |
| 79 | global_runner->name, |
| 80 | &weston_test_runner_interface, |
| 81 | 1); |
| 82 | assert(runner->test_runner); |
| 83 | |
| 84 | weston_test_runner_add_listener(runner->test_runner, |
| 85 | &test_runner_listener, runner); |
| 86 | |
| 87 | return runner; |
| 88 | } |
| 89 | |
| 90 | static void |
| 91 | runner_destroy(struct runner *runner) |
| 92 | { |
| 93 | weston_test_runner_destroy(runner->test_runner); |
| 94 | client_roundtrip(runner->client); |
| 95 | free(runner); |
| 96 | } |
| 97 | |
| 98 | static void |
| 99 | runner_run(struct runner *runner, const char *test_name) |
| 100 | { |
| 101 | fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name); |
| 102 | |
| 103 | runner->done = 0; |
| 104 | weston_test_runner_run(runner->test_runner, test_name); |
| 105 | |
| 106 | while (!runner->done) { |
| 107 | if (wl_display_dispatch(runner->client->wl_display) < 0) |
| 108 | assert(0 && "runner wait"); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static struct ivi_application * |
| 113 | get_ivi_application(struct client *client) |
| 114 | { |
| 115 | struct global *g; |
| 116 | struct global *global_iviapp = NULL; |
| 117 | static struct ivi_application *iviapp; |
| 118 | |
| 119 | if (iviapp) |
| 120 | return iviapp; |
| 121 | |
| 122 | wl_list_for_each(g, &client->global_list, link) { |
| 123 | if (strcmp(g->interface, "ivi_application")) |
| 124 | continue; |
| 125 | |
| 126 | if (global_iviapp) |
| 127 | assert(0 && "multiple ivi_application objects"); |
| 128 | |
| 129 | global_iviapp = g; |
| 130 | } |
| 131 | |
| 132 | assert(global_iviapp && "no ivi_application found"); |
| 133 | |
| 134 | assert(global_iviapp->version == 1); |
| 135 | |
| 136 | iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name, |
| 137 | &ivi_application_interface, 1); |
| 138 | assert(iviapp); |
| 139 | |
| 140 | return iviapp; |
| 141 | } |
| 142 | |
| 143 | struct ivi_window { |
| 144 | struct wl_surface *wl_surface; |
| 145 | struct ivi_surface *ivi_surface; |
| 146 | uint32_t ivi_id; |
| 147 | }; |
| 148 | |
| 149 | static struct ivi_window * |
| 150 | client_create_ivi_window(struct client *client, uint32_t ivi_id) |
| 151 | { |
| 152 | struct ivi_application *iviapp; |
| 153 | struct ivi_window *wnd; |
| 154 | |
| 155 | iviapp = get_ivi_application(client); |
| 156 | |
| 157 | wnd = xzalloc(sizeof(*wnd)); |
| 158 | wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor); |
| 159 | wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id, |
| 160 | wnd->wl_surface); |
| 161 | wnd->ivi_id = ivi_id; |
| 162 | |
| 163 | return wnd; |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | ivi_window_destroy(struct ivi_window *wnd) |
| 168 | { |
| 169 | ivi_surface_destroy(wnd->ivi_surface); |
| 170 | wl_surface_destroy(wnd->wl_surface); |
| 171 | free(wnd); |
| 172 | } |
| 173 | |
| 174 | /******************************** tests ********************************/ |
| 175 | |
| 176 | /* |
| 177 | * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST() |
| 178 | * is forked and exec'd as usual with the weston-test-runner framework. |
| 179 | * |
| 180 | * These tests make use of weston_test_runner global interface exposed by |
| 181 | * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side |
| 182 | * checks. |
| 183 | * |
| 184 | * See ivi_layout-test-plugin.c for further details. |
| 185 | */ |
| 186 | |
| 187 | /** |
| 188 | * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c. |
| 189 | * Each RUNNER_TEST name listed here uses the same simple initial client setup. |
| 190 | */ |
| 191 | const char * const basic_test_names[] = { |
| 192 | "surface_visibility", |
| 193 | "surface_opacity", |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 194 | "surface_orientation", |
| 195 | "surface_dimension", |
| 196 | "surface_position", |
| 197 | "surface_destination_rectangle", |
| 198 | "surface_source_rectangle", |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 199 | "surface_bad_opacity", |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 200 | "surface_properties_changed_notification", |
Nobuhiko Tanibata | 0af22d4 | 2015-06-22 15:36:21 +0900 | [diff] [blame] | 201 | "surface_bad_properties_changed_notification", |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | const char * const surface_property_commit_changes_test_names[] = { |
| 205 | "commit_changes_after_visibility_set_surface_destroy", |
| 206 | "commit_changes_after_opacity_set_surface_destroy", |
| 207 | "commit_changes_after_orientation_set_surface_destroy", |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 208 | "commit_changes_after_source_rectangle_set_surface_destroy", |
| 209 | "commit_changes_after_destination_rectangle_set_surface_destroy", |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 210 | }; |
| 211 | |
Nobuhiko Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame] | 212 | const char * const render_order_test_names[] = { |
| 213 | "layer_render_order", |
Nobuhiko Tanibata | 0671b4d | 2015-06-22 15:34:42 +0900 | [diff] [blame] | 214 | "layer_bad_render_order", |
Nobuhiko Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame] | 215 | }; |
| 216 | |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 217 | TEST_P(ivi_layout_runner, basic_test_names) |
| 218 | { |
| 219 | /* an element from basic_test_names */ |
| 220 | const char * const *test_name = data; |
| 221 | struct client *client; |
| 222 | struct runner *runner; |
| 223 | struct ivi_window *wnd; |
| 224 | |
| 225 | client = create_client(); |
| 226 | runner = client_create_runner(client); |
| 227 | |
| 228 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 229 | |
| 230 | runner_run(runner, *test_name); |
| 231 | |
| 232 | ivi_window_destroy(wnd); |
| 233 | runner_destroy(runner); |
| 234 | } |
| 235 | |
| 236 | TEST(ivi_layout_surface_create) |
| 237 | { |
| 238 | struct client *client; |
| 239 | struct runner *runner; |
| 240 | struct ivi_window *winds[2]; |
| 241 | |
| 242 | client = create_client(); |
| 243 | runner = client_create_runner(client); |
| 244 | |
| 245 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 246 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 247 | |
| 248 | runner_run(runner, "surface_create_p1"); |
| 249 | |
| 250 | ivi_window_destroy(winds[0]); |
| 251 | |
| 252 | runner_run(runner, "surface_create_p2"); |
| 253 | |
| 254 | ivi_window_destroy(winds[1]); |
| 255 | runner_destroy(runner); |
| 256 | } |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 257 | |
| 258 | TEST_P(commit_changes_after_properties_set_surface_destroy, surface_property_commit_changes_test_names) |
| 259 | { |
| 260 | /* an element from surface_property_commit_changes_test_names */ |
| 261 | const char * const *test_name = data; |
| 262 | struct client *client; |
| 263 | struct runner *runner; |
| 264 | struct ivi_window *wnd; |
| 265 | |
| 266 | client = create_client(); |
| 267 | runner = client_create_runner(client); |
| 268 | |
| 269 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 270 | |
| 271 | runner_run(runner, *test_name); |
| 272 | |
| 273 | ivi_window_destroy(wnd); |
| 274 | |
| 275 | runner_run(runner, "ivi_layout_commit_changes"); |
| 276 | |
| 277 | runner_destroy(runner); |
| 278 | } |
| 279 | |
| 280 | TEST(get_surface_after_destroy_ivi_surface) |
| 281 | { |
| 282 | struct client *client; |
| 283 | struct runner *runner; |
| 284 | struct ivi_window *wnd; |
| 285 | |
| 286 | client = create_client(); |
| 287 | runner = client_create_runner(client); |
| 288 | |
| 289 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 290 | |
| 291 | ivi_surface_destroy(wnd->ivi_surface); |
| 292 | |
| 293 | runner_run(runner, "get_surface_after_destroy_surface"); |
| 294 | |
| 295 | wl_surface_destroy(wnd->wl_surface); |
| 296 | free(wnd); |
| 297 | runner_destroy(runner); |
| 298 | } |
| 299 | |
| 300 | TEST(get_surface_after_destroy_wl_surface) |
| 301 | { |
| 302 | struct client *client; |
| 303 | struct runner *runner; |
| 304 | struct ivi_window *wnd; |
| 305 | |
| 306 | client = create_client(); |
| 307 | runner = client_create_runner(client); |
| 308 | |
| 309 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 310 | |
| 311 | wl_surface_destroy(wnd->wl_surface); |
| 312 | |
| 313 | runner_run(runner, "get_surface_after_destroy_surface"); |
| 314 | |
| 315 | ivi_surface_destroy(wnd->ivi_surface); |
| 316 | free(wnd); |
| 317 | runner_destroy(runner); |
| 318 | } |
Nobuhiko Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame] | 319 | |
| 320 | TEST_P(ivi_layout_layer_render_order_runner, render_order_test_names) |
| 321 | { |
| 322 | /* an element from render_order_test_names */ |
| 323 | const char * const *test_name = data; |
| 324 | struct client *client; |
| 325 | struct runner *runner; |
| 326 | struct ivi_window *winds[3]; |
| 327 | |
| 328 | client = create_client(); |
| 329 | runner = client_create_runner(client); |
| 330 | |
| 331 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 332 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 333 | winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2)); |
| 334 | |
| 335 | runner_run(runner, *test_name); |
| 336 | |
| 337 | ivi_window_destroy(winds[0]); |
| 338 | ivi_window_destroy(winds[1]); |
| 339 | ivi_window_destroy(winds[2]); |
| 340 | runner_destroy(runner); |
| 341 | } |
Nobuhiko Tanibata | 0671b4d | 2015-06-22 15:34:42 +0900 | [diff] [blame] | 342 | |
| 343 | TEST(destroy_surface_after_layer_render_order) |
| 344 | { |
| 345 | struct client *client; |
| 346 | struct runner *runner; |
| 347 | struct ivi_window *winds[3]; |
| 348 | |
| 349 | client = create_client(); |
| 350 | runner = client_create_runner(client); |
| 351 | |
| 352 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 353 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 354 | winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2)); |
| 355 | |
| 356 | runner_run(runner, "test_layer_render_order_destroy_one_surface_p1"); |
| 357 | |
| 358 | ivi_window_destroy(winds[1]); |
| 359 | |
| 360 | runner_run(runner, "test_layer_render_order_destroy_one_surface_p2"); |
| 361 | |
| 362 | ivi_window_destroy(winds[0]); |
| 363 | ivi_window_destroy(winds[2]); |
| 364 | runner_destroy(runner); |
| 365 | } |
| 366 | |
| 367 | TEST(commit_changes_after_render_order_set_surface_destroy) |
| 368 | { |
| 369 | struct client *client; |
| 370 | struct runner *runner; |
| 371 | struct ivi_window *winds[3]; |
| 372 | |
| 373 | client = create_client(); |
| 374 | runner = client_create_runner(client); |
| 375 | |
| 376 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 377 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 378 | winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2)); |
| 379 | |
| 380 | runner_run(runner, "commit_changes_after_render_order_set_surface_destroy"); |
| 381 | |
| 382 | ivi_window_destroy(winds[1]); |
| 383 | |
| 384 | runner_run(runner, "ivi_layout_commit_changes"); |
| 385 | runner_run(runner, "cleanup_layer"); |
| 386 | |
| 387 | ivi_window_destroy(winds[0]); |
| 388 | ivi_window_destroy(winds[2]); |
| 389 | runner_destroy(runner); |
| 390 | } |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 391 | |
| 392 | TEST(ivi_layout_surface_configure_notification) |
| 393 | { |
| 394 | struct client *client; |
| 395 | struct runner *runner; |
| 396 | struct ivi_window *wind; |
| 397 | struct wl_buffer *buffer; |
| 398 | |
| 399 | client = create_client(); |
| 400 | runner = client_create_runner(client); |
| 401 | |
| 402 | runner_run(runner, "surface_configure_notification_p1"); |
| 403 | |
| 404 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 405 | |
| 406 | buffer = create_shm_buffer(client, 200, 300, NULL); |
| 407 | |
| 408 | wl_surface_attach(wind->wl_surface, buffer, 0, 0); |
| 409 | wl_surface_damage(wind->wl_surface, 0, 0, 20, 30); |
| 410 | wl_surface_commit(wind->wl_surface); |
| 411 | |
| 412 | runner_run(runner, "surface_configure_notification_p2"); |
| 413 | |
| 414 | wl_surface_attach(wind->wl_surface, buffer, 0, 0); |
| 415 | wl_surface_damage(wind->wl_surface, 0, 0, 40, 50); |
| 416 | wl_surface_commit(wind->wl_surface); |
| 417 | |
| 418 | runner_run(runner, "surface_configure_notification_p3"); |
| 419 | |
| 420 | wl_buffer_destroy(buffer); |
| 421 | ivi_window_destroy(wind); |
| 422 | runner_destroy(runner); |
| 423 | } |
| 424 | |
| 425 | TEST(ivi_layout_surface_create_notification) |
| 426 | { |
| 427 | struct client *client; |
| 428 | struct runner *runner; |
| 429 | struct ivi_window *wind; |
| 430 | |
| 431 | client = create_client(); |
| 432 | runner = client_create_runner(client); |
| 433 | |
| 434 | runner_run(runner, "surface_create_notification_p1"); |
| 435 | |
| 436 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 437 | |
| 438 | runner_run(runner, "surface_create_notification_p2"); |
| 439 | |
| 440 | ivi_window_destroy(wind); |
| 441 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 442 | runner_run(runner, "surface_create_notification_p3"); |
| 443 | |
| 444 | ivi_window_destroy(wind); |
| 445 | runner_destroy(runner); |
| 446 | } |
| 447 | |
| 448 | TEST(ivi_layout_surface_remove_notification) |
| 449 | { |
| 450 | struct client *client; |
| 451 | struct runner *runner; |
| 452 | struct ivi_window *wind; |
| 453 | |
| 454 | client = create_client(); |
| 455 | runner = client_create_runner(client); |
| 456 | |
| 457 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 458 | runner_run(runner, "surface_remove_notification_p1"); |
| 459 | ivi_window_destroy(wind); |
| 460 | |
| 461 | runner_run(runner, "surface_remove_notification_p2"); |
| 462 | |
| 463 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 464 | ivi_window_destroy(wind); |
| 465 | runner_run(runner, "surface_remove_notification_p3"); |
| 466 | |
| 467 | runner_destroy(runner); |
| 468 | } |