blob: aaba7246f33d8452ffe8bd7ae9cfc0591ed021b9 [file] [log] [blame]
Pekka Paalanenf5b74f72015-03-25 12:50:31 +02001/*
2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 DENSO CORPORATION
4 * Copyright © 2015 Collabora, Ltd.
5 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020013 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070014 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020026 */
27
28#include "config.h"
29
30#include <unistd.h>
31#include <signal.h>
32#include <string.h>
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090033#include <assert.h>
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020034
Jon Cruz4678bab2015-06-15 15:37:07 -070035#include "src/compositor.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020036#include "weston-test-server-protocol.h"
37#include "ivi-test.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070038#include "ivi-shell/ivi-layout-export.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070039#include "shared/helpers.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020040
41struct test_context;
42
43struct runner_test {
44 const char *name;
45 void (*run)(struct test_context *);
46} __attribute__ ((aligned (32)));
47
48#define RUNNER_TEST(name) \
49 static void runner_func_##name(struct test_context *); \
50 \
51 const struct runner_test runner_test_##name \
52 __attribute__ ((section ("test_section"))) = \
53 { \
54 #name, runner_func_##name \
55 }; \
56 \
57 static void runner_func_##name(struct test_context *ctx)
58
59extern const struct runner_test __start_test_section;
60extern const struct runner_test __stop_test_section;
61
62static const struct runner_test *
63find_runner_test(const char *name)
64{
65 const struct runner_test *t;
66
67 for (t = &__start_test_section; t < &__stop_test_section; t++) {
68 if (strcmp(t->name, name) == 0)
69 return t;
70 }
71
72 return NULL;
73}
74
75struct test_launcher {
76 struct weston_compositor *compositor;
77 char exe[2048];
78 struct weston_process process;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000079 const struct ivi_layout_interface *layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020080};
81
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090082struct test_context {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000083 const struct ivi_layout_interface *layout_interface;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090084 struct wl_resource *runner_resource;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +090085 uint32_t user_flags;
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +000086
87 struct wl_listener surface_property_changed;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090088};
89
90static struct test_context static_context;
91
92static void
93destroy_runner(struct wl_resource *resource)
94{
95 assert(static_context.runner_resource == NULL ||
96 static_context.runner_resource == resource);
97
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000098 static_context.layout_interface = NULL;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090099 static_context.runner_resource = NULL;
100}
101
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200102static void
103runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
104{
105 wl_resource_destroy(resource);
106}
107
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200108static void
109runner_run_handler(struct wl_client *client, struct wl_resource *resource,
110 const char *test_name)
111{
112 struct test_launcher *launcher;
113 const struct runner_test *t;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900114
115 assert(static_context.runner_resource == NULL ||
116 static_context.runner_resource == resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200117
118 launcher = wl_resource_get_user_data(resource);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000119 static_context.layout_interface = launcher->layout_interface;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900120 static_context.runner_resource = resource;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200121
122 t = find_runner_test(test_name);
123 if (!t) {
124 weston_log("Error: runner test \"%s\" not found.\n",
125 test_name);
126 wl_resource_post_error(resource,
127 WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
128 "weston_test_runner: unknown: '%s'",
129 test_name);
130 return;
131 }
132
133 weston_log("weston_test_runner.run(\"%s\")\n", test_name);
134
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900135 t->run(&static_context);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200136
137 weston_test_runner_send_finished(resource);
138}
139
140static const struct weston_test_runner_interface runner_implementation = {
141 runner_destroy_handler,
142 runner_run_handler
143};
144
145static void
146bind_runner(struct wl_client *client, void *data,
147 uint32_t version, uint32_t id)
148{
149 struct test_launcher *launcher = data;
150 struct wl_resource *resource;
151
152 resource = wl_resource_create(client, &weston_test_runner_interface,
153 1, id);
154 if (!resource) {
155 wl_client_post_no_memory(client);
156 return;
157 }
158
159 wl_resource_set_implementation(resource, &runner_implementation,
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900160 launcher, destroy_runner);
161
162 if (static_context.runner_resource != NULL) {
163 weston_log("test FATAL: "
164 "attempting to run several tests in parallel.\n");
165 wl_resource_post_error(resource,
166 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
167 "attempt to run parallel tests");
168 }
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200169}
170
171static void
172test_client_sigchld(struct weston_process *process, int status)
173{
174 struct test_launcher *launcher =
175 container_of(process, struct test_launcher, process);
176 struct weston_compositor *c = launcher->compositor;
177
178 /* Chain up from weston-test-runner's exit code so that automake
179 * knows the exit status and can report e.g. skipped tests. */
180 if (WIFEXITED(status))
181 weston_compositor_exit_with_code(c, WEXITSTATUS(status));
182 else
183 weston_compositor_exit_with_code(c, EXIT_FAILURE);
184}
185
186static void
187idle_launch_client(void *data)
188{
189 struct test_launcher *launcher = data;
190 pid_t pid;
191 sigset_t allsigs;
192
193 pid = fork();
194 if (pid == -1) {
195 weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
196 weston_compositor_exit_with_code(launcher->compositor,
197 EXIT_FAILURE);
198 return;
199 }
200
201 if (pid == 0) {
202 sigfillset(&allsigs);
203 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
204 execl(launcher->exe, launcher->exe, NULL);
205 weston_log("compositor: executing '%s' failed: %m\n",
206 launcher->exe);
207 _exit(EXIT_FAILURE);
208 }
209
210 launcher->process.pid = pid;
211 launcher->process.cleanup = test_client_sigchld;
212 weston_watch_process(&launcher->process);
213}
214
215int
216controller_module_init(struct weston_compositor *compositor,
217 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000218 const struct ivi_layout_interface *iface,
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200219 size_t iface_version);
220
221WL_EXPORT int
222controller_module_init(struct weston_compositor *compositor,
223 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000224 const struct ivi_layout_interface *iface,
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200225 size_t iface_version)
226{
227 struct wl_event_loop *loop;
228 struct test_launcher *launcher;
229 const char *path;
230
231 /* strict check, since this is an internal test module */
232 if (iface_version != sizeof(*iface)) {
233 weston_log("fatal: controller interface mismatch\n");
234 return -1;
235 }
236
237 path = getenv("WESTON_BUILD_DIR");
238 if (!path) {
239 weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
240 return -1;
241 }
242
243 launcher = zalloc(sizeof *launcher);
244 if (!launcher)
245 return -1;
246
247 launcher->compositor = compositor;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000248 launcher->layout_interface = iface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200249 snprintf(launcher->exe, sizeof launcher->exe,
250 "%s/ivi-layout.ivi", path);
251
252 if (wl_global_create(compositor->wl_display,
253 &weston_test_runner_interface, 1,
254 launcher, bind_runner) == NULL)
255 return -1;
256
257 loop = wl_display_get_event_loop(compositor->wl_display);
258 wl_event_loop_add_idle(loop, idle_launch_client, launcher);
259
260 return 0;
261}
262
263static void
264runner_assert_fail(const char *cond, const char *file, int line,
265 const char *func, struct test_context *ctx)
266{
267 weston_log("Assert failure in %s:%d, %s: '%s'\n",
268 file, line, func, cond);
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900269
270 assert(ctx->runner_resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200271 wl_resource_post_error(ctx->runner_resource,
272 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
273 "Assert failure in %s:%d, %s: '%s'\n",
274 file, line, func, cond);
275}
276
277#define runner_assert(cond) ({ \
278 bool b_ = (cond); \
279 if (!b_) \
280 runner_assert_fail(#cond, __FILE__, __LINE__, \
281 __func__, ctx); \
282 b_; \
283})
284
285#define runner_assert_or_return(cond) do { \
286 bool b_ = (cond); \
287 if (!b_) { \
288 runner_assert_fail(#cond, __FILE__, __LINE__, \
289 __func__, ctx); \
290 return; \
291 } \
292} while (0)
293
294
295/*************************** tests **********************************/
296
297/*
298 * This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
299 * This module is specially written to execute tests that target the
300 * ivi_layout API.
301 *
302 * This module is listed in TESTS in Makefile.am. weston-tests-env handles
303 * this module specially by loading it in ivi-shell.
304 *
305 * Once Weston init completes, this module launches one test program:
306 * ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
307 * framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
308 * connection to the single compositor instance.
309 *
310 * Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
311 * interface. A TEST() will set up the client state, and issue
312 * weston_test_runner.run request to execute the compositor-side of the test.
313 *
314 * The compositor-side parts of the tests are in this file. They are specified
315 * by RUNNER_TEST() macro, where the name argument matches the name string
316 * passed to weston_test_runner.run.
317 *
318 * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
319 * a fatal protocol error is sent to the client from runner_assert() or
320 * runner_assert_or_return(). This module catches the test program exit
321 * code and passes it out of Weston to the test harness.
322 *
323 * A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
324 * achieve multiple test points over a client action sequence.
325 */
326
327RUNNER_TEST(surface_create_p1)
328{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000329 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200330 struct ivi_layout_surface *ivisurf[2];
331 uint32_t ivi_id;
332
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000333 ivisurf[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900334 runner_assert(ivisurf[0]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200335
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000336 ivisurf[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900337 runner_assert(ivisurf[1]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200338
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000339 ivi_id = lyt->get_id_of_surface(ivisurf[0]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900340 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200341
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000342 ivi_id = lyt->get_id_of_surface(ivisurf[1]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900343 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200344}
345
346RUNNER_TEST(surface_create_p2)
347{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000348 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200349 struct ivi_layout_surface *ivisurf;
350
351 /* the ivi_surface was destroyed by the client */
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000352 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900353 runner_assert(ivisurf == NULL);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200354}
355
356RUNNER_TEST(surface_visibility)
357{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000358 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200359 struct ivi_layout_surface *ivisurf;
360 int32_t ret;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200361 const struct ivi_layout_surface_properties *prop;
362
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000363 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900364 runner_assert(ivisurf);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200365
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000366 ret = lyt->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900367 runner_assert(ret == IVI_SUCCEEDED);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200368
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000369 lyt->commit_changes();
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200370
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000371 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900372 runner_assert(prop->visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200373}
374
375RUNNER_TEST(surface_opacity)
376{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000377 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200378 struct ivi_layout_surface *ivisurf;
379 int32_t ret;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200380 const struct ivi_layout_surface_properties *prop;
381
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000382 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900383 runner_assert(ivisurf);
384
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000385 prop = lyt->get_properties_of_surface(ivisurf);
386 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200387
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000388 ret = lyt->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900389 runner_assert(ret == IVI_SUCCEEDED);
390
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000391 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 lyt->commit_changes();
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200394
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900395 runner_assert(prop->opacity == wl_fixed_from_double(0.5));
396}
397
398RUNNER_TEST(surface_orientation)
399{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000400 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900401 struct ivi_layout_surface *ivisurf;
402 const struct ivi_layout_surface_properties *prop;
403
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000404 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900405 runner_assert(ivisurf != NULL);
406
Ucan, Emre \(ADITG/SW1\)4d9001b2016-03-04 12:50:35 +0000407 prop = lyt->get_properties_of_surface(ivisurf);
408 runner_assert_or_return(prop);
409 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_NORMAL);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900410
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000411 runner_assert(lyt->surface_set_orientation(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900412 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
413
Ucan, Emre \(ADITG/SW1\)4d9001b2016-03-04 12:50:35 +0000414 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_NORMAL);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900415
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000416 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900417
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900418 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
419}
420
421RUNNER_TEST(surface_dimension)
422{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000423 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900424 struct ivi_layout_surface *ivisurf;
425 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900426
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000427 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900428 runner_assert(ivisurf != NULL);
429
Ucan, Emre \(ADITG/SW1\)c507f672016-03-04 12:50:28 +0000430 prop = lyt->get_properties_of_surface(ivisurf);
431 runner_assert_or_return(prop);
432 runner_assert(prop->dest_width == 1);
433 runner_assert(prop->dest_height == 1);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900434
435 runner_assert(IVI_SUCCEEDED ==
Ucan, Emre \(ADITG/SW1\)45d39422016-03-04 12:50:50 +0000436 lyt->surface_set_destination_rectangle(ivisurf, prop->dest_x,
437 prop->dest_y, 200, 300));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900438
Ucan, Emre \(ADITG/SW1\)c507f672016-03-04 12:50:28 +0000439 runner_assert(prop->dest_width == 1);
440 runner_assert(prop->dest_height == 1);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900441
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000442 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900443
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000444 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900445 runner_assert_or_return(prop);
446 runner_assert(prop->dest_width == 200);
447 runner_assert(prop->dest_height == 300);
448}
449
450RUNNER_TEST(surface_position)
451{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000452 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900453 struct ivi_layout_surface *ivisurf;
454 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900455
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000456 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900457 runner_assert(ivisurf != NULL);
458
Ucan, Emre \(ADITG/SW1\)b2ff2552016-03-04 12:50:20 +0000459 prop = lyt->get_properties_of_surface(ivisurf);
460 runner_assert_or_return(prop);
461 runner_assert(prop->dest_x == 0);
462 runner_assert(prop->dest_y == 0);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900463
Ucan, Emre \(ADITG/SW1\)161da402016-03-04 12:50:43 +0000464 runner_assert(lyt->surface_set_destination_rectangle(
465 ivisurf, 20, 30,
466 prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900467
Ucan, Emre \(ADITG/SW1\)b2ff2552016-03-04 12:50:20 +0000468 runner_assert(prop->dest_x == 0);
469 runner_assert(prop->dest_y == 0);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900470
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000471 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900472
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000473 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900474 runner_assert_or_return(prop);
475 runner_assert(prop->dest_x == 20);
476 runner_assert(prop->dest_y == 30);
477}
478
479RUNNER_TEST(surface_destination_rectangle)
480{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000481 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900482 struct ivi_layout_surface *ivisurf;
483 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900484
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000485 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900486 runner_assert(ivisurf != NULL);
487
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000488 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900489 runner_assert_or_return(prop);
490 runner_assert(prop->dest_width == 1);
491 runner_assert(prop->dest_height == 1);
492 runner_assert(prop->dest_x == 0);
493 runner_assert(prop->dest_y == 0);
494
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000495 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900496 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
497
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000498 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900499 runner_assert_or_return(prop);
500 runner_assert(prop->dest_width == 1);
501 runner_assert(prop->dest_height == 1);
502 runner_assert(prop->dest_x == 0);
503 runner_assert(prop->dest_y == 0);
504
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000505 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900506
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000507 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900508 runner_assert_or_return(prop);
509 runner_assert(prop->dest_width == 200);
510 runner_assert(prop->dest_height == 300);
511 runner_assert(prop->dest_x == 20);
512 runner_assert(prop->dest_y == 30);
513}
514
515RUNNER_TEST(surface_source_rectangle)
516{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000517 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900518 struct ivi_layout_surface *ivisurf;
519 const struct ivi_layout_surface_properties *prop;
520
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000521 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900522 runner_assert(ivisurf != NULL);
523
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000524 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900525 runner_assert_or_return(prop);
526 runner_assert(prop->source_width == 0);
527 runner_assert(prop->source_height == 0);
528 runner_assert(prop->source_x == 0);
529 runner_assert(prop->source_y == 0);
530
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000531 runner_assert(lyt->surface_set_source_rectangle(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900532 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
533
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000534 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900535 runner_assert_or_return(prop);
536 runner_assert(prop->source_width == 0);
537 runner_assert(prop->source_height == 0);
538 runner_assert(prop->source_x == 0);
539 runner_assert(prop->source_y == 0);
540
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000541 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900542
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000543 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900544 runner_assert_or_return(prop);
545 runner_assert(prop->source_width == 200);
546 runner_assert(prop->source_height == 300);
547 runner_assert(prop->source_x == 20);
548 runner_assert(prop->source_y == 30);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200549}
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900550
551RUNNER_TEST(surface_bad_opacity)
552{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000553 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900554 struct ivi_layout_surface *ivisurf;
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000555 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900556
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000557 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900558 runner_assert(ivisurf != NULL);
559
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000560 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900561 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
562
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 ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
565
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000566 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900567 ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
568
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000569 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900570
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000571 prop = lyt->get_properties_of_surface(ivisurf);
572 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900573
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000574 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900575 ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
576
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000577 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900578
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000579 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900580
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000581 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900582 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
583
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000584 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900585}
586
587RUNNER_TEST(ivi_layout_commit_changes)
588{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000589 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900590
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000591 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900592}
593
594RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
595{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000596 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900597 struct ivi_layout_surface *ivisurf;
598
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000599 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900600 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000601 runner_assert(lyt->surface_set_visibility(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900602 ivisurf, true) == IVI_SUCCEEDED);
603}
604
605RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
606{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000607 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900608 struct ivi_layout_surface *ivisurf;
609
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000610 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900611 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000612 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900613 ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
614}
615
616RUNNER_TEST(commit_changes_after_orientation_set_surface_destroy)
617{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000618 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900619 struct ivi_layout_surface *ivisurf;
620
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000621 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900622 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000623 runner_assert(lyt->surface_set_orientation(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900624 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
625}
626
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900627RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
628{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000629 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900630 struct ivi_layout_surface *ivisurf;
631
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000632 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900633 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000634 runner_assert(lyt->surface_set_source_rectangle(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900635 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
636}
637
638RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
639{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000640 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900641 struct ivi_layout_surface *ivisurf;
642
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000643 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900644 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000645 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900646 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
647}
648
649RUNNER_TEST(get_surface_after_destroy_surface)
650{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000651 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900652 struct ivi_layout_surface *ivisurf;
653
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000654 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900655 runner_assert(ivisurf == NULL);
656}
657
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900658RUNNER_TEST(layer_render_order)
659{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000660 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900661 struct ivi_layout_layer *ivilayer;
662 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
663 struct ivi_layout_surface **array;
664 int32_t length = 0;
665 uint32_t i;
666
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000667 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900668
669 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000670 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900671
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000672 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900673 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
674
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000675 lyt->commit_changes();
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900676
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000677 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900678 ivilayer, &length, &array) == IVI_SUCCEEDED);
679 runner_assert(IVI_TEST_SURFACE_COUNT == length);
680 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
681 runner_assert(array[i] == ivisurfs[i]);
682
683 if (length > 0)
684 free(array);
685
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000686 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900687 ivilayer, NULL, 0) == IVI_SUCCEEDED);
688
689 array = NULL;
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(length == 0 && array == NULL);
696
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000697 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900698}
699
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900700RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
701{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000702 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900703 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 int32_t i;
708
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000709 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900710
711 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000712 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900713
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000714 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900715 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
716
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000717 lyt->commit_changes();
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900718
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000719 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900720 ivilayer, &length, &array) == IVI_SUCCEEDED);
721 runner_assert(IVI_TEST_SURFACE_COUNT == length);
722 for (i = 0; i < length; i++)
723 runner_assert(array[i] == ivisurfs[i]);
724
725 if (length > 0)
726 free(array);
727}
728
729RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
730{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000731 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900732 struct ivi_layout_layer *ivilayer;
733 struct ivi_layout_surface *ivisurfs[2] = {};
734 struct ivi_layout_surface **array;
735 int32_t length = 0;
736 int32_t i;
737
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000738 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
739 ivisurfs[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
740 ivisurfs[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900741
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000742 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900743 ivilayer, &length, &array) == IVI_SUCCEEDED);
744 runner_assert(2 == length);
745 for (i = 0; i < length; i++)
746 runner_assert(array[i] == ivisurfs[i]);
747
748 if (length > 0)
749 free(array);
750
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000751 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900752}
753
754RUNNER_TEST(layer_bad_render_order)
755{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000756 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900757 struct ivi_layout_layer *ivilayer;
758 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
759 struct ivi_layout_surface **array = NULL;
760 int32_t length = 0;
761 uint32_t i;
762
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000763 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900764
765 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000766 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900767
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000768 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900769 NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
770
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000771 lyt->commit_changes();
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900772
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000773 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900774 NULL, &length, &array) == IVI_FAILED);
775 runner_assert(length == 0 && array == NULL);
776
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000777 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900778 ivilayer, NULL, &array) == IVI_FAILED);
779 runner_assert(array == NULL);
780
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000781 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900782 ivilayer, &length, NULL) == IVI_FAILED);
783 runner_assert(length == 0);
784
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000785 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900786}
787
788RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
789{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000790 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900791 struct ivi_layout_layer *ivilayer;
792 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
793 int i;
794
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000795 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900796
797 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000798 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900799
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000800 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900801 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
802}
803
804RUNNER_TEST(cleanup_layer)
805{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000806 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900807 struct ivi_layout_layer *ivilayer;
808
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000809 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
810 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900811}
812
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900813static void
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000814test_surface_properties_changed_notification_callback(struct wl_listener *listener, void *data)
815
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900816{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000817 struct test_context *ctx =
818 container_of(listener, struct test_context,
819 surface_property_changed);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000820 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000821 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900822
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000823 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900824
825 ctx->user_flags = 1;
826}
827
828RUNNER_TEST(surface_properties_changed_notification)
829{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000830 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900831 const uint32_t id_surface = IVI_TEST_SURFACE_ID(0);
832 struct ivi_layout_surface *ivisurf;
833
834 ctx->user_flags = 0;
835
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000836 ivisurf = lyt->get_surface_from_id(id_surface);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900837 runner_assert(ivisurf != NULL);
838
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000839 ctx->surface_property_changed.notify = test_surface_properties_changed_notification_callback;
840
841 runner_assert(lyt->surface_add_listener(
842 ivisurf, &ctx->surface_property_changed) == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900843
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000844 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900845
846 runner_assert(ctx->user_flags == 0);
847
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000848 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900849 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
850
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000851 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900852
853 runner_assert(ctx->user_flags == 1);
854
855 ctx->user_flags = 0;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000856 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900857 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
858
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000859 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900860
861 runner_assert(ctx->user_flags == 0);
862
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000863 // remove surface property changed listener.
864 wl_list_remove(&ctx->surface_property_changed.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900865 ctx->user_flags = 0;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000866 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900867 ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
868
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000869 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900870
871 runner_assert(ctx->user_flags == 0);
872}
873
874static void
875test_surface_configure_notification_callback(struct ivi_layout_surface *ivisurf,
876 void *userdata)
877{
878 struct test_context *ctx = userdata;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000879 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900880
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000881 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900882
883 ctx->user_flags = 1;
884}
885
886RUNNER_TEST(surface_configure_notification_p1)
887{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000888 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900889
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000890 runner_assert(IVI_SUCCEEDED == lyt->add_notification_configure_surface(test_surface_configure_notification_callback, ctx));
891 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900892
893 ctx->user_flags = 0;
894}
895
896RUNNER_TEST(surface_configure_notification_p2)
897{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000898 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900899
900 runner_assert(ctx->user_flags == 1);
901
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000902 lyt->remove_notification_configure_surface(test_surface_configure_notification_callback, ctx);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900903 ctx->user_flags = 0;
904}
905
906RUNNER_TEST(surface_configure_notification_p3)
907{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000908 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900909
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000910 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900911 runner_assert(ctx->user_flags == 0);
912}
913
914static void
915test_surface_create_notification_callback(struct ivi_layout_surface *ivisurf,
916 void *userdata)
917{
918 struct test_context *ctx = userdata;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000919 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900920
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000921 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900922
923 ctx->user_flags = 1;
924}
925
926RUNNER_TEST(surface_create_notification_p1)
927{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000928 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900929
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000930 runner_assert(lyt->add_notification_create_surface(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900931 test_surface_create_notification_callback, ctx) == IVI_SUCCEEDED);
932
933 ctx->user_flags = 0;
934}
935
936RUNNER_TEST(surface_create_notification_p2)
937{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000938 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900939
940 runner_assert(ctx->user_flags == 1);
941
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000942 lyt->remove_notification_create_surface(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900943 test_surface_create_notification_callback, ctx);
944 ctx->user_flags = 0;
945}
946
947RUNNER_TEST(surface_create_notification_p3)
948{
949 runner_assert(ctx->user_flags == 0);
950}
951
952static void
953test_surface_remove_notification_callback(struct ivi_layout_surface *ivisurf,
954 void *userdata)
955{
956 struct test_context *ctx = userdata;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000957 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900958
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000959 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900960
961 ctx->user_flags = 1;
962}
963
964RUNNER_TEST(surface_remove_notification_p1)
965{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000966 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900967
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000968 runner_assert(lyt->add_notification_remove_surface(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900969 test_surface_remove_notification_callback, ctx) == IVI_SUCCEEDED);
970
971 ctx->user_flags = 0;
972}
973
974RUNNER_TEST(surface_remove_notification_p2)
975{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000976 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900977
978 runner_assert(ctx->user_flags == 1);
979
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000980 lyt->remove_notification_remove_surface(test_surface_remove_notification_callback, ctx);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900981 ctx->user_flags = 0;
982}
983
984RUNNER_TEST(surface_remove_notification_p3)
985{
986 runner_assert(ctx->user_flags == 0);
987}
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +0900988
989static void
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000990test_surface_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +0900991{
992}
993
994RUNNER_TEST(surface_bad_properties_changed_notification)
995{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000996 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +0900997 struct ivi_layout_surface *ivisurf;
998
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000999 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001000 runner_assert(ivisurf != NULL);
1001
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001002 ctx->surface_property_changed.notify = test_surface_bad_properties_changed_notification_callback;
1003
1004 runner_assert(lyt->surface_add_listener(
1005 NULL, &ctx->surface_property_changed) == IVI_FAILED);
1006 runner_assert(lyt->surface_add_listener(
1007 ivisurf, NULL) == IVI_FAILED);
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001008}