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" |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 32 | #include "weston-test-client-helper.h" |
| 33 | #include "ivi-application-client-protocol.h" |
| 34 | #include "ivi-test.h" |
| 35 | |
| 36 | struct runner { |
| 37 | struct client *client; |
| 38 | struct weston_test_runner *test_runner; |
| 39 | int done; |
| 40 | }; |
| 41 | |
| 42 | static void |
| 43 | runner_finished_handler(void *data, struct weston_test_runner *test_runner) |
| 44 | { |
| 45 | struct runner *runner = data; |
| 46 | |
| 47 | runner->done = 1; |
| 48 | } |
| 49 | |
| 50 | static const struct weston_test_runner_listener test_runner_listener = { |
| 51 | runner_finished_handler |
| 52 | }; |
| 53 | |
| 54 | static struct runner * |
| 55 | client_create_runner(struct client *client) |
| 56 | { |
| 57 | struct runner *runner; |
| 58 | struct global *g; |
| 59 | struct global *global_runner = NULL; |
| 60 | |
| 61 | runner = xzalloc(sizeof(*runner)); |
| 62 | runner->client = client; |
| 63 | |
| 64 | wl_list_for_each(g, &client->global_list, link) { |
| 65 | if (strcmp(g->interface, "weston_test_runner")) |
| 66 | continue; |
| 67 | |
| 68 | if (global_runner) |
| 69 | assert(0 && "multiple weston_test_runner objects"); |
| 70 | |
| 71 | global_runner = g; |
| 72 | } |
| 73 | |
| 74 | assert(global_runner && "no weston_test_runner found"); |
| 75 | assert(global_runner->version == 1); |
| 76 | |
| 77 | runner->test_runner = wl_registry_bind(client->wl_registry, |
| 78 | global_runner->name, |
| 79 | &weston_test_runner_interface, |
| 80 | 1); |
| 81 | assert(runner->test_runner); |
| 82 | |
| 83 | weston_test_runner_add_listener(runner->test_runner, |
| 84 | &test_runner_listener, runner); |
| 85 | |
| 86 | return runner; |
| 87 | } |
| 88 | |
| 89 | static void |
| 90 | runner_destroy(struct runner *runner) |
| 91 | { |
| 92 | weston_test_runner_destroy(runner->test_runner); |
| 93 | client_roundtrip(runner->client); |
| 94 | free(runner); |
| 95 | } |
| 96 | |
| 97 | static void |
| 98 | runner_run(struct runner *runner, const char *test_name) |
| 99 | { |
| 100 | fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name); |
| 101 | |
| 102 | runner->done = 0; |
| 103 | weston_test_runner_run(runner->test_runner, test_name); |
| 104 | |
| 105 | while (!runner->done) { |
| 106 | if (wl_display_dispatch(runner->client->wl_display) < 0) |
| 107 | assert(0 && "runner wait"); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static struct ivi_application * |
| 112 | get_ivi_application(struct client *client) |
| 113 | { |
| 114 | struct global *g; |
| 115 | struct global *global_iviapp = NULL; |
| 116 | static struct ivi_application *iviapp; |
| 117 | |
| 118 | if (iviapp) |
| 119 | return iviapp; |
| 120 | |
| 121 | wl_list_for_each(g, &client->global_list, link) { |
| 122 | if (strcmp(g->interface, "ivi_application")) |
| 123 | continue; |
| 124 | |
| 125 | if (global_iviapp) |
| 126 | assert(0 && "multiple ivi_application objects"); |
| 127 | |
| 128 | global_iviapp = g; |
| 129 | } |
| 130 | |
| 131 | assert(global_iviapp && "no ivi_application found"); |
| 132 | |
| 133 | assert(global_iviapp->version == 1); |
| 134 | |
| 135 | iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name, |
| 136 | &ivi_application_interface, 1); |
| 137 | assert(iviapp); |
| 138 | |
| 139 | return iviapp; |
| 140 | } |
| 141 | |
| 142 | struct ivi_window { |
| 143 | struct wl_surface *wl_surface; |
| 144 | struct ivi_surface *ivi_surface; |
| 145 | uint32_t ivi_id; |
| 146 | }; |
| 147 | |
| 148 | static struct ivi_window * |
| 149 | client_create_ivi_window(struct client *client, uint32_t ivi_id) |
| 150 | { |
| 151 | struct ivi_application *iviapp; |
| 152 | struct ivi_window *wnd; |
| 153 | |
| 154 | iviapp = get_ivi_application(client); |
| 155 | |
| 156 | wnd = xzalloc(sizeof(*wnd)); |
| 157 | wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor); |
| 158 | wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id, |
| 159 | wnd->wl_surface); |
| 160 | wnd->ivi_id = ivi_id; |
| 161 | |
| 162 | return wnd; |
| 163 | } |
| 164 | |
| 165 | static void |
| 166 | ivi_window_destroy(struct ivi_window *wnd) |
| 167 | { |
| 168 | ivi_surface_destroy(wnd->ivi_surface); |
| 169 | wl_surface_destroy(wnd->wl_surface); |
| 170 | free(wnd); |
| 171 | } |
| 172 | |
| 173 | /******************************** tests ********************************/ |
| 174 | |
| 175 | /* |
| 176 | * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST() |
| 177 | * is forked and exec'd as usual with the weston-test-runner framework. |
| 178 | * |
| 179 | * These tests make use of weston_test_runner global interface exposed by |
| 180 | * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side |
| 181 | * checks. |
| 182 | * |
| 183 | * See ivi_layout-test-plugin.c for further details. |
| 184 | */ |
| 185 | |
| 186 | /** |
| 187 | * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c. |
| 188 | * Each RUNNER_TEST name listed here uses the same simple initial client setup. |
| 189 | */ |
| 190 | const char * const basic_test_names[] = { |
| 191 | "surface_visibility", |
| 192 | "surface_opacity", |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame^] | 193 | "surface_orientation", |
| 194 | "surface_dimension", |
| 195 | "surface_position", |
| 196 | "surface_destination_rectangle", |
| 197 | "surface_source_rectangle", |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | TEST_P(ivi_layout_runner, basic_test_names) |
| 201 | { |
| 202 | /* an element from basic_test_names */ |
| 203 | const char * const *test_name = data; |
| 204 | struct client *client; |
| 205 | struct runner *runner; |
| 206 | struct ivi_window *wnd; |
| 207 | |
| 208 | client = create_client(); |
| 209 | runner = client_create_runner(client); |
| 210 | |
| 211 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 212 | |
| 213 | runner_run(runner, *test_name); |
| 214 | |
| 215 | ivi_window_destroy(wnd); |
| 216 | runner_destroy(runner); |
| 217 | } |
| 218 | |
| 219 | TEST(ivi_layout_surface_create) |
| 220 | { |
| 221 | struct client *client; |
| 222 | struct runner *runner; |
| 223 | struct ivi_window *winds[2]; |
| 224 | |
| 225 | client = create_client(); |
| 226 | runner = client_create_runner(client); |
| 227 | |
| 228 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 229 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 230 | |
| 231 | runner_run(runner, "surface_create_p1"); |
| 232 | |
| 233 | ivi_window_destroy(winds[0]); |
| 234 | |
| 235 | runner_run(runner, "surface_create_p2"); |
| 236 | |
| 237 | ivi_window_destroy(winds[1]); |
| 238 | runner_destroy(runner); |
| 239 | } |