blob: 19eab81a07bef4f0d3094cd6270ea5015e903220 [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
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030030#include <stdint.h>
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020031#include <unistd.h>
32#include <signal.h>
33#include <string.h>
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090034#include <assert.h>
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020035
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030036#include "compositor.h"
Pekka Paalanen58f98c92016-06-03 16:45:21 +030037#include "compositor/weston.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020038#include "weston-test-server-protocol.h"
39#include "ivi-test.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070040#include "ivi-shell/ivi-layout-export.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070041#include "shared/helpers.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020042
43struct test_context;
44
45struct runner_test {
46 const char *name;
47 void (*run)(struct test_context *);
48} __attribute__ ((aligned (32)));
49
50#define RUNNER_TEST(name) \
51 static void runner_func_##name(struct test_context *); \
52 \
53 const struct runner_test runner_test_##name \
54 __attribute__ ((section ("test_section"))) = \
55 { \
56 #name, runner_func_##name \
57 }; \
58 \
59 static void runner_func_##name(struct test_context *ctx)
60
61extern const struct runner_test __start_test_section;
62extern const struct runner_test __stop_test_section;
63
64static const struct runner_test *
65find_runner_test(const char *name)
66{
67 const struct runner_test *t;
68
69 for (t = &__start_test_section; t < &__stop_test_section; t++) {
70 if (strcmp(t->name, name) == 0)
71 return t;
72 }
73
74 return NULL;
75}
76
77struct test_launcher {
78 struct weston_compositor *compositor;
79 char exe[2048];
80 struct weston_process process;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000081 const struct ivi_layout_interface *layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020082};
83
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090084struct test_context {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000085 const struct ivi_layout_interface *layout_interface;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090086 struct wl_resource *runner_resource;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +090087 uint32_t user_flags;
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +000088
89 struct wl_listener surface_property_changed;
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +000090 struct wl_listener surface_created;
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +000091 struct wl_listener surface_removed;
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +000092 struct wl_listener surface_configured;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090093};
94
95static struct test_context static_context;
96
97static void
98destroy_runner(struct wl_resource *resource)
99{
100 assert(static_context.runner_resource == NULL ||
101 static_context.runner_resource == resource);
102
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000103 static_context.layout_interface = NULL;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900104 static_context.runner_resource = NULL;
105}
106
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200107static void
108runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
109{
110 wl_resource_destroy(resource);
111}
112
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200113static void
114runner_run_handler(struct wl_client *client, struct wl_resource *resource,
115 const char *test_name)
116{
117 struct test_launcher *launcher;
118 const struct runner_test *t;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900119
120 assert(static_context.runner_resource == NULL ||
121 static_context.runner_resource == resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200122
123 launcher = wl_resource_get_user_data(resource);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000124 static_context.layout_interface = launcher->layout_interface;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900125 static_context.runner_resource = resource;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200126
127 t = find_runner_test(test_name);
128 if (!t) {
129 weston_log("Error: runner test \"%s\" not found.\n",
130 test_name);
131 wl_resource_post_error(resource,
132 WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
133 "weston_test_runner: unknown: '%s'",
134 test_name);
135 return;
136 }
137
138 weston_log("weston_test_runner.run(\"%s\")\n", test_name);
139
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900140 t->run(&static_context);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200141
142 weston_test_runner_send_finished(resource);
143}
144
145static const struct weston_test_runner_interface runner_implementation = {
146 runner_destroy_handler,
147 runner_run_handler
148};
149
150static void
151bind_runner(struct wl_client *client, void *data,
152 uint32_t version, uint32_t id)
153{
154 struct test_launcher *launcher = data;
155 struct wl_resource *resource;
156
157 resource = wl_resource_create(client, &weston_test_runner_interface,
158 1, id);
159 if (!resource) {
160 wl_client_post_no_memory(client);
161 return;
162 }
163
164 wl_resource_set_implementation(resource, &runner_implementation,
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900165 launcher, destroy_runner);
166
167 if (static_context.runner_resource != NULL) {
168 weston_log("test FATAL: "
169 "attempting to run several tests in parallel.\n");
170 wl_resource_post_error(resource,
171 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
172 "attempt to run parallel tests");
173 }
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200174}
175
176static void
177test_client_sigchld(struct weston_process *process, int status)
178{
179 struct test_launcher *launcher =
180 container_of(process, struct test_launcher, process);
181 struct weston_compositor *c = launcher->compositor;
182
183 /* Chain up from weston-test-runner's exit code so that automake
184 * knows the exit status and can report e.g. skipped tests. */
185 if (WIFEXITED(status))
186 weston_compositor_exit_with_code(c, WEXITSTATUS(status));
187 else
188 weston_compositor_exit_with_code(c, EXIT_FAILURE);
189}
190
191static void
192idle_launch_client(void *data)
193{
194 struct test_launcher *launcher = data;
195 pid_t pid;
196 sigset_t allsigs;
197
198 pid = fork();
199 if (pid == -1) {
200 weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
201 weston_compositor_exit_with_code(launcher->compositor,
202 EXIT_FAILURE);
203 return;
204 }
205
206 if (pid == 0) {
207 sigfillset(&allsigs);
208 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
209 execl(launcher->exe, launcher->exe, NULL);
210 weston_log("compositor: executing '%s' failed: %m\n",
211 launcher->exe);
212 _exit(EXIT_FAILURE);
213 }
214
215 launcher->process.pid = pid;
216 launcher->process.cleanup = test_client_sigchld;
217 weston_watch_process(&launcher->process);
218}
219
220int
221controller_module_init(struct weston_compositor *compositor,
222 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000223 const struct ivi_layout_interface *iface,
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200224 size_t iface_version);
225
226WL_EXPORT int
227controller_module_init(struct weston_compositor *compositor,
228 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000229 const struct ivi_layout_interface *iface,
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200230 size_t iface_version)
231{
232 struct wl_event_loop *loop;
233 struct test_launcher *launcher;
234 const char *path;
235
236 /* strict check, since this is an internal test module */
237 if (iface_version != sizeof(*iface)) {
238 weston_log("fatal: controller interface mismatch\n");
239 return -1;
240 }
241
242 path = getenv("WESTON_BUILD_DIR");
243 if (!path) {
244 weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
245 return -1;
246 }
247
248 launcher = zalloc(sizeof *launcher);
249 if (!launcher)
250 return -1;
251
252 launcher->compositor = compositor;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000253 launcher->layout_interface = iface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200254 snprintf(launcher->exe, sizeof launcher->exe,
255 "%s/ivi-layout.ivi", path);
256
257 if (wl_global_create(compositor->wl_display,
258 &weston_test_runner_interface, 1,
259 launcher, bind_runner) == NULL)
260 return -1;
261
262 loop = wl_display_get_event_loop(compositor->wl_display);
263 wl_event_loop_add_idle(loop, idle_launch_client, launcher);
264
265 return 0;
266}
267
268static void
269runner_assert_fail(const char *cond, const char *file, int line,
270 const char *func, struct test_context *ctx)
271{
272 weston_log("Assert failure in %s:%d, %s: '%s'\n",
273 file, line, func, cond);
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900274
275 assert(ctx->runner_resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200276 wl_resource_post_error(ctx->runner_resource,
277 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
278 "Assert failure in %s:%d, %s: '%s'\n",
279 file, line, func, cond);
280}
281
282#define runner_assert(cond) ({ \
283 bool b_ = (cond); \
284 if (!b_) \
285 runner_assert_fail(#cond, __FILE__, __LINE__, \
286 __func__, ctx); \
287 b_; \
288})
289
290#define runner_assert_or_return(cond) do { \
291 bool b_ = (cond); \
292 if (!b_) { \
293 runner_assert_fail(#cond, __FILE__, __LINE__, \
294 __func__, ctx); \
295 return; \
296 } \
297} while (0)
298
299
300/*************************** tests **********************************/
301
302/*
303 * This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
304 * This module is specially written to execute tests that target the
305 * ivi_layout API.
306 *
307 * This module is listed in TESTS in Makefile.am. weston-tests-env handles
308 * this module specially by loading it in ivi-shell.
309 *
310 * Once Weston init completes, this module launches one test program:
311 * ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
312 * framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
313 * connection to the single compositor instance.
314 *
315 * Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
316 * interface. A TEST() will set up the client state, and issue
317 * weston_test_runner.run request to execute the compositor-side of the test.
318 *
319 * The compositor-side parts of the tests are in this file. They are specified
320 * by RUNNER_TEST() macro, where the name argument matches the name string
321 * passed to weston_test_runner.run.
322 *
323 * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
324 * a fatal protocol error is sent to the client from runner_assert() or
325 * runner_assert_or_return(). This module catches the test program exit
326 * code and passes it out of Weston to the test harness.
327 *
328 * A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
329 * achieve multiple test points over a client action sequence.
330 */
331
332RUNNER_TEST(surface_create_p1)
333{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000334 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200335 struct ivi_layout_surface *ivisurf[2];
336 uint32_t ivi_id;
337
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000338 ivisurf[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900339 runner_assert(ivisurf[0]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200340
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000341 ivisurf[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900342 runner_assert(ivisurf[1]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200343
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000344 ivi_id = lyt->get_id_of_surface(ivisurf[0]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900345 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200346
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000347 ivi_id = lyt->get_id_of_surface(ivisurf[1]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900348 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200349}
350
351RUNNER_TEST(surface_create_p2)
352{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000353 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200354 struct ivi_layout_surface *ivisurf;
355
356 /* the ivi_surface was destroyed by the client */
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000357 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900358 runner_assert(ivisurf == NULL);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200359}
360
361RUNNER_TEST(surface_visibility)
362{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000363 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200364 struct ivi_layout_surface *ivisurf;
365 int32_t ret;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200366 const struct ivi_layout_surface_properties *prop;
367
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000368 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900369 runner_assert(ivisurf);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200370
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000371 ret = lyt->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900372 runner_assert(ret == IVI_SUCCEEDED);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200373
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000374 lyt->commit_changes();
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200375
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000376 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900377 runner_assert(prop->visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200378}
379
380RUNNER_TEST(surface_opacity)
381{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000382 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200383 struct ivi_layout_surface *ivisurf;
384 int32_t ret;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200385 const struct ivi_layout_surface_properties *prop;
386
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000387 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900388 runner_assert(ivisurf);
389
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000390 prop = lyt->get_properties_of_surface(ivisurf);
391 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200392
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000393 ret = lyt->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900394 runner_assert(ret == IVI_SUCCEEDED);
395
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000396 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200397
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000398 lyt->commit_changes();
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200399
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900400 runner_assert(prop->opacity == wl_fixed_from_double(0.5));
401}
402
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900403RUNNER_TEST(surface_dimension)
404{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000405 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900406 struct ivi_layout_surface *ivisurf;
407 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900408
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000409 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900410 runner_assert(ivisurf != NULL);
411
Ucan, Emre \(ADITG/SW1\)c507f672016-03-04 12:50:28 +0000412 prop = lyt->get_properties_of_surface(ivisurf);
413 runner_assert_or_return(prop);
414 runner_assert(prop->dest_width == 1);
415 runner_assert(prop->dest_height == 1);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900416
417 runner_assert(IVI_SUCCEEDED ==
Ucan, Emre \(ADITG/SW1\)45d39422016-03-04 12:50:50 +0000418 lyt->surface_set_destination_rectangle(ivisurf, prop->dest_x,
419 prop->dest_y, 200, 300));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900420
Ucan, Emre \(ADITG/SW1\)c507f672016-03-04 12:50:28 +0000421 runner_assert(prop->dest_width == 1);
422 runner_assert(prop->dest_height == 1);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900423
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000424 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900425
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000426 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900427 runner_assert_or_return(prop);
428 runner_assert(prop->dest_width == 200);
429 runner_assert(prop->dest_height == 300);
430}
431
432RUNNER_TEST(surface_position)
433{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000434 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900435 struct ivi_layout_surface *ivisurf;
436 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900437
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000438 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900439 runner_assert(ivisurf != NULL);
440
Ucan, Emre \(ADITG/SW1\)b2ff2552016-03-04 12:50:20 +0000441 prop = lyt->get_properties_of_surface(ivisurf);
442 runner_assert_or_return(prop);
443 runner_assert(prop->dest_x == 0);
444 runner_assert(prop->dest_y == 0);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900445
Ucan, Emre \(ADITG/SW1\)161da402016-03-04 12:50:43 +0000446 runner_assert(lyt->surface_set_destination_rectangle(
447 ivisurf, 20, 30,
448 prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900449
Ucan, Emre \(ADITG/SW1\)b2ff2552016-03-04 12:50:20 +0000450 runner_assert(prop->dest_x == 0);
451 runner_assert(prop->dest_y == 0);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900452
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000453 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900454
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000455 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900456 runner_assert_or_return(prop);
457 runner_assert(prop->dest_x == 20);
458 runner_assert(prop->dest_y == 30);
459}
460
461RUNNER_TEST(surface_destination_rectangle)
462{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000463 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900464 struct ivi_layout_surface *ivisurf;
465 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900466
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000467 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900468 runner_assert(ivisurf != NULL);
469
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000470 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900471 runner_assert_or_return(prop);
472 runner_assert(prop->dest_width == 1);
473 runner_assert(prop->dest_height == 1);
474 runner_assert(prop->dest_x == 0);
475 runner_assert(prop->dest_y == 0);
476
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000477 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900478 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
479
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000480 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900481 runner_assert_or_return(prop);
482 runner_assert(prop->dest_width == 1);
483 runner_assert(prop->dest_height == 1);
484 runner_assert(prop->dest_x == 0);
485 runner_assert(prop->dest_y == 0);
486
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000487 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900488
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000489 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900490 runner_assert_or_return(prop);
491 runner_assert(prop->dest_width == 200);
492 runner_assert(prop->dest_height == 300);
493 runner_assert(prop->dest_x == 20);
494 runner_assert(prop->dest_y == 30);
495}
496
497RUNNER_TEST(surface_source_rectangle)
498{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000499 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900500 struct ivi_layout_surface *ivisurf;
501 const struct ivi_layout_surface_properties *prop;
502
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000503 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900504 runner_assert(ivisurf != NULL);
505
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000506 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900507 runner_assert_or_return(prop);
508 runner_assert(prop->source_width == 0);
509 runner_assert(prop->source_height == 0);
510 runner_assert(prop->source_x == 0);
511 runner_assert(prop->source_y == 0);
512
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000513 runner_assert(lyt->surface_set_source_rectangle(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900514 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
515
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000516 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900517 runner_assert_or_return(prop);
518 runner_assert(prop->source_width == 0);
519 runner_assert(prop->source_height == 0);
520 runner_assert(prop->source_x == 0);
521 runner_assert(prop->source_y == 0);
522
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000523 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900524
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000525 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900526 runner_assert_or_return(prop);
527 runner_assert(prop->source_width == 200);
528 runner_assert(prop->source_height == 300);
529 runner_assert(prop->source_x == 20);
530 runner_assert(prop->source_y == 30);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200531}
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900532
533RUNNER_TEST(surface_bad_opacity)
534{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000535 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900536 struct ivi_layout_surface *ivisurf;
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000537 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900538
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000539 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900540 runner_assert(ivisurf != NULL);
541
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000542 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900543 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
544
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000545 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900546 ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
547
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000548 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900549 ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
550
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000551 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900552
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000553 prop = lyt->get_properties_of_surface(ivisurf);
554 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900555
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000556 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900557 ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
558
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000559 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900560
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000561 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900562
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000563 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900564 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
565
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000566 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900567}
568
Ucan, Emre (ADITG/SW1)37d25bb2016-06-07 09:40:21 +0000569RUNNER_TEST(surface_on_many_layer)
570{
571 const struct ivi_layout_interface *lyt = ctx->layout_interface;
572 struct ivi_layout_surface *ivisurf;
573 struct ivi_layout_layer *ivilayers[IVI_TEST_LAYER_COUNT] = {};
574 struct ivi_layout_layer **array;
575 int32_t length = 0;
576 uint32_t i;
577
578 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
579 runner_assert(ivisurf != NULL);
580
581 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++) {
582 ivilayers[i] = lyt->layer_create_with_dimension(
583 IVI_TEST_LAYER_ID(i), 200, 300);
584 runner_assert(lyt->layer_add_surface(
585 ivilayers[i], ivisurf) == IVI_SUCCEEDED);
586 }
587
588 lyt->commit_changes();
589
590 runner_assert(lyt->get_layers_under_surface(
591 ivisurf, &length, &array) == IVI_SUCCEEDED);
592 runner_assert(IVI_TEST_LAYER_COUNT == length);
593 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
594 runner_assert(array[i] == ivilayers[i]);
595
596 if (length > 0)
597 free(array);
598
599 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
600 lyt->layer_remove_surface(ivilayers[i], ivisurf);
601
602 array = NULL;
603
604 lyt->commit_changes();
605
606 runner_assert(lyt->get_layers_under_surface(
607 ivisurf, &length, &array) == IVI_SUCCEEDED);
608 runner_assert(length == 0 && array == NULL);
609
610 for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
611 lyt->layer_destroy(ivilayers[i]);
612}
613
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900614RUNNER_TEST(ivi_layout_commit_changes)
615{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000616 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900617
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000618 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900619}
620
621RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
622{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000623 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900624 struct ivi_layout_surface *ivisurf;
625
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000626 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900627 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000628 runner_assert(lyt->surface_set_visibility(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900629 ivisurf, true) == IVI_SUCCEEDED);
630}
631
632RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
633{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000634 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900635 struct ivi_layout_surface *ivisurf;
636
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000637 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900638 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000639 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900640 ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
641}
642
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900643RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
644{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000645 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900646 struct ivi_layout_surface *ivisurf;
647
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000648 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900649 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000650 runner_assert(lyt->surface_set_source_rectangle(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900651 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
652}
653
654RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
655{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000656 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900657 struct ivi_layout_surface *ivisurf;
658
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000659 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900660 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000661 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900662 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
663}
664
665RUNNER_TEST(get_surface_after_destroy_surface)
666{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000667 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900668 struct ivi_layout_surface *ivisurf;
669
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000670 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900671 runner_assert(ivisurf == NULL);
672}
673
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900674RUNNER_TEST(layer_render_order)
675{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000676 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900677 struct ivi_layout_layer *ivilayer;
678 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
679 struct ivi_layout_surface **array;
680 int32_t length = 0;
681 uint32_t i;
682
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000683 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900684
685 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000686 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900687
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000688 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900689 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
690
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000691 lyt->commit_changes();
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900692
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000693 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900694 ivilayer, &length, &array) == IVI_SUCCEEDED);
695 runner_assert(IVI_TEST_SURFACE_COUNT == length);
696 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
697 runner_assert(array[i] == ivisurfs[i]);
698
699 if (length > 0)
700 free(array);
701
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000702 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900703 ivilayer, NULL, 0) == IVI_SUCCEEDED);
704
705 array = NULL;
706
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000707 lyt->commit_changes();
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900708
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000709 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900710 ivilayer, &length, &array) == IVI_SUCCEEDED);
711 runner_assert(length == 0 && array == NULL);
712
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000713 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900714}
715
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900716RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
717{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000718 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900719 struct ivi_layout_layer *ivilayer;
720 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
721 struct ivi_layout_surface **array;
722 int32_t length = 0;
723 int32_t i;
724
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000725 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900726
727 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000728 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900729
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000730 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900731 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
732
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000733 lyt->commit_changes();
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900734
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000735 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900736 ivilayer, &length, &array) == IVI_SUCCEEDED);
737 runner_assert(IVI_TEST_SURFACE_COUNT == length);
738 for (i = 0; i < length; i++)
739 runner_assert(array[i] == ivisurfs[i]);
740
741 if (length > 0)
742 free(array);
743}
744
745RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
746{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000747 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900748 struct ivi_layout_layer *ivilayer;
749 struct ivi_layout_surface *ivisurfs[2] = {};
750 struct ivi_layout_surface **array;
751 int32_t length = 0;
752 int32_t i;
753
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000754 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
755 ivisurfs[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
756 ivisurfs[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900757
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000758 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900759 ivilayer, &length, &array) == IVI_SUCCEEDED);
760 runner_assert(2 == length);
761 for (i = 0; i < length; i++)
762 runner_assert(array[i] == ivisurfs[i]);
763
764 if (length > 0)
765 free(array);
766
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000767 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900768}
769
770RUNNER_TEST(layer_bad_render_order)
771{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000772 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900773 struct ivi_layout_layer *ivilayer;
774 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
775 struct ivi_layout_surface **array = NULL;
776 int32_t length = 0;
777 uint32_t i;
778
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000779 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900780
781 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000782 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900783
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000784 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900785 NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
786
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000787 lyt->commit_changes();
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900788
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000789 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900790 NULL, &length, &array) == IVI_FAILED);
791 runner_assert(length == 0 && array == NULL);
792
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000793 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900794 ivilayer, NULL, &array) == IVI_FAILED);
795 runner_assert(array == NULL);
796
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000797 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900798 ivilayer, &length, NULL) == IVI_FAILED);
799 runner_assert(length == 0);
800
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000801 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900802}
803
Ucan, Emre (ADITG/SW1)5d6aa9b2017-01-18 15:25:35 +0000804RUNNER_TEST(layer_add_surfaces)
805{
806 const struct ivi_layout_interface *lyt = ctx->layout_interface;
807 struct ivi_layout_layer *ivilayer;
808 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
809 struct ivi_layout_surface **array;
810 int32_t length = 0;
811 uint32_t i;
812
813 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
814
815 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++) {
816 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
817 runner_assert(lyt->layer_add_surface(
818 ivilayer, ivisurfs[i]) == IVI_SUCCEEDED);
819 }
820
821 lyt->commit_changes();
822
823 runner_assert(lyt->get_surfaces_on_layer(
824 ivilayer, &length, &array) == IVI_SUCCEEDED);
825 runner_assert(IVI_TEST_SURFACE_COUNT == length);
826 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
827 runner_assert(array[i] == ivisurfs[i]);
828
829 if (length > 0)
830 free(array);
831
832 runner_assert(lyt->layer_set_render_order(
833 ivilayer, NULL, 0) == IVI_SUCCEEDED);
834
835 for (i = IVI_TEST_SURFACE_COUNT; i-- > 0;)
836 runner_assert(lyt->layer_add_surface(
837 ivilayer, ivisurfs[i]) == IVI_SUCCEEDED);
838
839 lyt->commit_changes();
840
841 runner_assert(lyt->get_surfaces_on_layer(
842 ivilayer, &length, &array) == IVI_SUCCEEDED);
843 runner_assert(IVI_TEST_SURFACE_COUNT == length);
844 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
845 runner_assert(array[i] == ivisurfs[IVI_TEST_SURFACE_COUNT - (i + 1)]);
846
847 if (length > 0)
848 free(array);
849
850 lyt->layer_destroy(ivilayer);
851}
852
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900853RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
854{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000855 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900856 struct ivi_layout_layer *ivilayer;
857 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
858 int i;
859
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000860 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900861
862 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000863 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900864
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000865 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900866 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
867}
868
869RUNNER_TEST(cleanup_layer)
870{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000871 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900872 struct ivi_layout_layer *ivilayer;
873
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000874 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
875 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900876}
877
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900878static void
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000879test_surface_properties_changed_notification_callback(struct wl_listener *listener, void *data)
880
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900881{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000882 struct test_context *ctx =
883 container_of(listener, struct test_context,
884 surface_property_changed);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000885 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000886 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900887
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000888 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900889
890 ctx->user_flags = 1;
891}
892
893RUNNER_TEST(surface_properties_changed_notification)
894{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000895 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900896 const uint32_t id_surface = IVI_TEST_SURFACE_ID(0);
897 struct ivi_layout_surface *ivisurf;
898
899 ctx->user_flags = 0;
900
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000901 ivisurf = lyt->get_surface_from_id(id_surface);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900902 runner_assert(ivisurf != NULL);
903
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000904 ctx->surface_property_changed.notify = test_surface_properties_changed_notification_callback;
905
906 runner_assert(lyt->surface_add_listener(
907 ivisurf, &ctx->surface_property_changed) == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900908
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000909 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900910
911 runner_assert(ctx->user_flags == 0);
912
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000913 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900914 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
915
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000916 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900917
918 runner_assert(ctx->user_flags == 1);
919
920 ctx->user_flags = 0;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000921 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900922 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
923
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000924 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900925
926 runner_assert(ctx->user_flags == 0);
927
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000928 // remove surface property changed listener.
929 wl_list_remove(&ctx->surface_property_changed.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900930 ctx->user_flags = 0;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000931 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900932 ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
933
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000934 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900935
936 runner_assert(ctx->user_flags == 0);
937}
938
939static void
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000940test_surface_configure_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900941{
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000942 struct test_context *ctx =
943 container_of(listener, struct test_context,
944 surface_configured);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000945 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000946 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900947
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000948 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900949
950 ctx->user_flags = 1;
951}
952
953RUNNER_TEST(surface_configure_notification_p1)
954{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000955 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900956
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000957 ctx->surface_configured.notify = test_surface_configure_notification_callback;
958 runner_assert(IVI_SUCCEEDED == lyt->add_listener_configure_surface(&ctx->surface_configured));
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000959 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900960
961 ctx->user_flags = 0;
962}
963
964RUNNER_TEST(surface_configure_notification_p2)
965{
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900966 runner_assert(ctx->user_flags == 1);
967
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000968 // remove surface configured listener.
969 wl_list_remove(&ctx->surface_configured.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900970 ctx->user_flags = 0;
971}
972
973RUNNER_TEST(surface_configure_notification_p3)
974{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000975 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900976
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000977 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900978 runner_assert(ctx->user_flags == 0);
979}
980
981static void
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000982test_surface_create_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900983{
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000984 struct test_context *ctx =
985 container_of(listener, struct test_context,
986 surface_created);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000987 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000988 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900989
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000990 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900991
992 ctx->user_flags = 1;
993}
994
995RUNNER_TEST(surface_create_notification_p1)
996{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000997 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900998
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000999 ctx->surface_created.notify = test_surface_create_notification_callback;
1000 runner_assert(lyt->add_listener_create_surface(
1001 &ctx->surface_created) == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001002
1003 ctx->user_flags = 0;
1004}
1005
1006RUNNER_TEST(surface_create_notification_p2)
1007{
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001008 runner_assert(ctx->user_flags == 1);
1009
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001010 // remove surface created listener.
1011 wl_list_remove(&ctx->surface_created.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001012 ctx->user_flags = 0;
1013}
1014
1015RUNNER_TEST(surface_create_notification_p3)
1016{
1017 runner_assert(ctx->user_flags == 0);
1018}
1019
1020static void
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001021test_surface_remove_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001022{
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001023 struct test_context *ctx =
1024 container_of(listener, struct test_context,
1025 surface_removed);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001026 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001027 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001028
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001029 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001030
1031 ctx->user_flags = 1;
1032}
1033
1034RUNNER_TEST(surface_remove_notification_p1)
1035{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001036 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001037
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001038 ctx->surface_removed.notify = test_surface_remove_notification_callback;
1039 runner_assert(lyt->add_listener_remove_surface(&ctx->surface_removed)
1040 == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001041
1042 ctx->user_flags = 0;
1043}
1044
1045RUNNER_TEST(surface_remove_notification_p2)
1046{
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001047 runner_assert(ctx->user_flags == 1);
1048
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001049 // remove surface removed listener.
1050 wl_list_remove(&ctx->surface_removed.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +09001051 ctx->user_flags = 0;
1052}
1053
1054RUNNER_TEST(surface_remove_notification_p3)
1055{
1056 runner_assert(ctx->user_flags == 0);
1057}
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001058
1059static void
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001060test_surface_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001061{
1062}
1063
1064RUNNER_TEST(surface_bad_properties_changed_notification)
1065{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001066 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001067 struct ivi_layout_surface *ivisurf;
1068
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001069 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001070 runner_assert(ivisurf != NULL);
1071
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001072 ctx->surface_property_changed.notify = test_surface_bad_properties_changed_notification_callback;
1073
1074 runner_assert(lyt->surface_add_listener(
1075 NULL, &ctx->surface_property_changed) == IVI_FAILED);
1076 runner_assert(lyt->surface_add_listener(
1077 ivisurf, NULL) == IVI_FAILED);
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001078}