blob: 4cae3c597c2a1be331939b349a8bd81b8546045a [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 Paalanen58f98c92016-06-03 16:45:21 +030036#include "compositor/weston.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020037#include "weston-test-server-protocol.h"
38#include "ivi-test.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070039#include "ivi-shell/ivi-layout-export.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070040#include "shared/helpers.h"
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020041
42struct test_context;
43
44struct runner_test {
45 const char *name;
46 void (*run)(struct test_context *);
47} __attribute__ ((aligned (32)));
48
49#define RUNNER_TEST(name) \
50 static void runner_func_##name(struct test_context *); \
51 \
52 const struct runner_test runner_test_##name \
53 __attribute__ ((section ("test_section"))) = \
54 { \
55 #name, runner_func_##name \
56 }; \
57 \
58 static void runner_func_##name(struct test_context *ctx)
59
60extern const struct runner_test __start_test_section;
61extern const struct runner_test __stop_test_section;
62
63static const struct runner_test *
64find_runner_test(const char *name)
65{
66 const struct runner_test *t;
67
68 for (t = &__start_test_section; t < &__stop_test_section; t++) {
69 if (strcmp(t->name, name) == 0)
70 return t;
71 }
72
73 return NULL;
74}
75
76struct test_launcher {
77 struct weston_compositor *compositor;
78 char exe[2048];
79 struct weston_process process;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000080 const struct ivi_layout_interface *layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +020081};
82
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090083struct test_context {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +000084 const struct ivi_layout_interface *layout_interface;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090085 struct wl_resource *runner_resource;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +090086 uint32_t user_flags;
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +000087
88 struct wl_listener surface_property_changed;
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +000089 struct wl_listener surface_created;
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +000090 struct wl_listener surface_removed;
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +000091 struct wl_listener surface_configured;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +090092};
93
94static struct test_context static_context;
95
96static void
97destroy_runner(struct wl_resource *resource)
98{
99 assert(static_context.runner_resource == NULL ||
100 static_context.runner_resource == resource);
101
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000102 static_context.layout_interface = NULL;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900103 static_context.runner_resource = NULL;
104}
105
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200106static void
107runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
108{
109 wl_resource_destroy(resource);
110}
111
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200112static void
113runner_run_handler(struct wl_client *client, struct wl_resource *resource,
114 const char *test_name)
115{
116 struct test_launcher *launcher;
117 const struct runner_test *t;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900118
119 assert(static_context.runner_resource == NULL ||
120 static_context.runner_resource == resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200121
122 launcher = wl_resource_get_user_data(resource);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000123 static_context.layout_interface = launcher->layout_interface;
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900124 static_context.runner_resource = resource;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200125
126 t = find_runner_test(test_name);
127 if (!t) {
128 weston_log("Error: runner test \"%s\" not found.\n",
129 test_name);
130 wl_resource_post_error(resource,
131 WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
132 "weston_test_runner: unknown: '%s'",
133 test_name);
134 return;
135 }
136
137 weston_log("weston_test_runner.run(\"%s\")\n", test_name);
138
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900139 t->run(&static_context);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200140
141 weston_test_runner_send_finished(resource);
142}
143
144static const struct weston_test_runner_interface runner_implementation = {
145 runner_destroy_handler,
146 runner_run_handler
147};
148
149static void
150bind_runner(struct wl_client *client, void *data,
151 uint32_t version, uint32_t id)
152{
153 struct test_launcher *launcher = data;
154 struct wl_resource *resource;
155
156 resource = wl_resource_create(client, &weston_test_runner_interface,
157 1, id);
158 if (!resource) {
159 wl_client_post_no_memory(client);
160 return;
161 }
162
163 wl_resource_set_implementation(resource, &runner_implementation,
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900164 launcher, destroy_runner);
165
166 if (static_context.runner_resource != NULL) {
167 weston_log("test FATAL: "
168 "attempting to run several tests in parallel.\n");
169 wl_resource_post_error(resource,
170 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
171 "attempt to run parallel tests");
172 }
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200173}
174
175static void
176test_client_sigchld(struct weston_process *process, int status)
177{
178 struct test_launcher *launcher =
179 container_of(process, struct test_launcher, process);
180 struct weston_compositor *c = launcher->compositor;
181
182 /* Chain up from weston-test-runner's exit code so that automake
183 * knows the exit status and can report e.g. skipped tests. */
184 if (WIFEXITED(status))
185 weston_compositor_exit_with_code(c, WEXITSTATUS(status));
186 else
187 weston_compositor_exit_with_code(c, EXIT_FAILURE);
188}
189
190static void
191idle_launch_client(void *data)
192{
193 struct test_launcher *launcher = data;
194 pid_t pid;
195 sigset_t allsigs;
196
197 pid = fork();
198 if (pid == -1) {
199 weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
200 weston_compositor_exit_with_code(launcher->compositor,
201 EXIT_FAILURE);
202 return;
203 }
204
205 if (pid == 0) {
206 sigfillset(&allsigs);
207 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
208 execl(launcher->exe, launcher->exe, NULL);
209 weston_log("compositor: executing '%s' failed: %m\n",
210 launcher->exe);
211 _exit(EXIT_FAILURE);
212 }
213
214 launcher->process.pid = pid;
215 launcher->process.cleanup = test_client_sigchld;
216 weston_watch_process(&launcher->process);
217}
218
219int
220controller_module_init(struct weston_compositor *compositor,
221 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000222 const struct ivi_layout_interface *iface,
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200223 size_t iface_version);
224
225WL_EXPORT int
226controller_module_init(struct weston_compositor *compositor,
227 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000228 const struct ivi_layout_interface *iface,
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200229 size_t iface_version)
230{
231 struct wl_event_loop *loop;
232 struct test_launcher *launcher;
233 const char *path;
234
235 /* strict check, since this is an internal test module */
236 if (iface_version != sizeof(*iface)) {
237 weston_log("fatal: controller interface mismatch\n");
238 return -1;
239 }
240
241 path = getenv("WESTON_BUILD_DIR");
242 if (!path) {
243 weston_log("test setup failure: WESTON_BUILD_DIR not set\n");
244 return -1;
245 }
246
247 launcher = zalloc(sizeof *launcher);
248 if (!launcher)
249 return -1;
250
251 launcher->compositor = compositor;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000252 launcher->layout_interface = iface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200253 snprintf(launcher->exe, sizeof launcher->exe,
254 "%s/ivi-layout.ivi", path);
255
256 if (wl_global_create(compositor->wl_display,
257 &weston_test_runner_interface, 1,
258 launcher, bind_runner) == NULL)
259 return -1;
260
261 loop = wl_display_get_event_loop(compositor->wl_display);
262 wl_event_loop_add_idle(loop, idle_launch_client, launcher);
263
264 return 0;
265}
266
267static void
268runner_assert_fail(const char *cond, const char *file, int line,
269 const char *func, struct test_context *ctx)
270{
271 weston_log("Assert failure in %s:%d, %s: '%s'\n",
272 file, line, func, cond);
Nobuhiko Tanibataa10352e2015-06-22 15:35:49 +0900273
274 assert(ctx->runner_resource);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200275 wl_resource_post_error(ctx->runner_resource,
276 WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
277 "Assert failure in %s:%d, %s: '%s'\n",
278 file, line, func, cond);
279}
280
281#define runner_assert(cond) ({ \
282 bool b_ = (cond); \
283 if (!b_) \
284 runner_assert_fail(#cond, __FILE__, __LINE__, \
285 __func__, ctx); \
286 b_; \
287})
288
289#define runner_assert_or_return(cond) do { \
290 bool b_ = (cond); \
291 if (!b_) { \
292 runner_assert_fail(#cond, __FILE__, __LINE__, \
293 __func__, ctx); \
294 return; \
295 } \
296} while (0)
297
298
299/*************************** tests **********************************/
300
301/*
302 * This is a controller module: a plugin to ivi-shell.so, i.e. a sub-plugin.
303 * This module is specially written to execute tests that target the
304 * ivi_layout API.
305 *
306 * This module is listed in TESTS in Makefile.am. weston-tests-env handles
307 * this module specially by loading it in ivi-shell.
308 *
309 * Once Weston init completes, this module launches one test program:
310 * ivi-layout.ivi (ivi_layout-test.c). That program uses the weston-test-runner
311 * framework to fork and exec each TEST() in ivi_layout-test.c with a fresh
312 * connection to the single compositor instance.
313 *
314 * Each TEST() in ivi_layout-test.c will bind to weston_test_runner global
315 * interface. A TEST() will set up the client state, and issue
316 * weston_test_runner.run request to execute the compositor-side of the test.
317 *
318 * The compositor-side parts of the tests are in this file. They are specified
319 * by RUNNER_TEST() macro, where the name argument matches the name string
320 * passed to weston_test_runner.run.
321 *
322 * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
323 * a fatal protocol error is sent to the client from runner_assert() or
324 * runner_assert_or_return(). This module catches the test program exit
325 * code and passes it out of Weston to the test harness.
326 *
327 * A single TEST() in ivi_layout-test.c may use multiple RUNNER_TEST()s to
328 * achieve multiple test points over a client action sequence.
329 */
330
331RUNNER_TEST(surface_create_p1)
332{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000333 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200334 struct ivi_layout_surface *ivisurf[2];
335 uint32_t ivi_id;
336
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000337 ivisurf[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900338 runner_assert(ivisurf[0]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200339
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000340 ivisurf[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900341 runner_assert(ivisurf[1]);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200342
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000343 ivi_id = lyt->get_id_of_surface(ivisurf[0]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900344 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200345
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000346 ivi_id = lyt->get_id_of_surface(ivisurf[1]);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900347 runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200348}
349
350RUNNER_TEST(surface_create_p2)
351{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000352 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200353 struct ivi_layout_surface *ivisurf;
354
355 /* the ivi_surface was destroyed by the client */
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000356 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900357 runner_assert(ivisurf == NULL);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200358}
359
360RUNNER_TEST(surface_visibility)
361{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000362 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200363 struct ivi_layout_surface *ivisurf;
364 int32_t ret;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200365 const struct ivi_layout_surface_properties *prop;
366
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000367 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900368 runner_assert(ivisurf);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200369
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000370 ret = lyt->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900371 runner_assert(ret == IVI_SUCCEEDED);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200372
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000373 lyt->commit_changes();
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200374
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000375 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900376 runner_assert(prop->visibility == true);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200377}
378
379RUNNER_TEST(surface_opacity)
380{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000381 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200382 struct ivi_layout_surface *ivisurf;
383 int32_t ret;
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200384 const struct ivi_layout_surface_properties *prop;
385
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000386 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900387 runner_assert(ivisurf);
388
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000389 prop = lyt->get_properties_of_surface(ivisurf);
390 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200391
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000392 ret = lyt->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900393 runner_assert(ret == IVI_SUCCEEDED);
394
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000395 runner_assert(prop->opacity == wl_fixed_from_double(1.0));
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200396
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000397 lyt->commit_changes();
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200398
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900399 runner_assert(prop->opacity == wl_fixed_from_double(0.5));
400}
401
402RUNNER_TEST(surface_orientation)
403{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000404 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900405 struct ivi_layout_surface *ivisurf;
406 const struct ivi_layout_surface_properties *prop;
407
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000408 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900409 runner_assert(ivisurf != NULL);
410
Ucan, Emre \(ADITG/SW1\)4d9001b2016-03-04 12:50:35 +0000411 prop = lyt->get_properties_of_surface(ivisurf);
412 runner_assert_or_return(prop);
413 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_NORMAL);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900414
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000415 runner_assert(lyt->surface_set_orientation(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900416 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
417
Ucan, Emre \(ADITG/SW1\)4d9001b2016-03-04 12:50:35 +0000418 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_NORMAL);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900419
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000420 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900421
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900422 runner_assert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
423}
424
425RUNNER_TEST(surface_dimension)
426{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000427 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900428 struct ivi_layout_surface *ivisurf;
429 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900430
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000431 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900432 runner_assert(ivisurf != NULL);
433
Ucan, Emre \(ADITG/SW1\)c507f672016-03-04 12:50:28 +0000434 prop = lyt->get_properties_of_surface(ivisurf);
435 runner_assert_or_return(prop);
436 runner_assert(prop->dest_width == 1);
437 runner_assert(prop->dest_height == 1);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900438
439 runner_assert(IVI_SUCCEEDED ==
Ucan, Emre \(ADITG/SW1\)45d39422016-03-04 12:50:50 +0000440 lyt->surface_set_destination_rectangle(ivisurf, prop->dest_x,
441 prop->dest_y, 200, 300));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900442
Ucan, Emre \(ADITG/SW1\)c507f672016-03-04 12:50:28 +0000443 runner_assert(prop->dest_width == 1);
444 runner_assert(prop->dest_height == 1);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900445
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000446 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900447
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000448 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900449 runner_assert_or_return(prop);
450 runner_assert(prop->dest_width == 200);
451 runner_assert(prop->dest_height == 300);
452}
453
454RUNNER_TEST(surface_position)
455{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000456 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900457 struct ivi_layout_surface *ivisurf;
458 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900459
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000460 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900461 runner_assert(ivisurf != NULL);
462
Ucan, Emre \(ADITG/SW1\)b2ff2552016-03-04 12:50:20 +0000463 prop = lyt->get_properties_of_surface(ivisurf);
464 runner_assert_or_return(prop);
465 runner_assert(prop->dest_x == 0);
466 runner_assert(prop->dest_y == 0);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900467
Ucan, Emre \(ADITG/SW1\)161da402016-03-04 12:50:43 +0000468 runner_assert(lyt->surface_set_destination_rectangle(
469 ivisurf, 20, 30,
470 prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900471
Ucan, Emre \(ADITG/SW1\)b2ff2552016-03-04 12:50:20 +0000472 runner_assert(prop->dest_x == 0);
473 runner_assert(prop->dest_y == 0);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900474
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000475 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900476
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000477 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900478 runner_assert_or_return(prop);
479 runner_assert(prop->dest_x == 20);
480 runner_assert(prop->dest_y == 30);
481}
482
483RUNNER_TEST(surface_destination_rectangle)
484{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000485 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900486 struct ivi_layout_surface *ivisurf;
487 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900488
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000489 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900490 runner_assert(ivisurf != NULL);
491
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000492 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900493 runner_assert_or_return(prop);
494 runner_assert(prop->dest_width == 1);
495 runner_assert(prop->dest_height == 1);
496 runner_assert(prop->dest_x == 0);
497 runner_assert(prop->dest_y == 0);
498
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000499 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900500 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
501
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000502 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900503 runner_assert_or_return(prop);
504 runner_assert(prop->dest_width == 1);
505 runner_assert(prop->dest_height == 1);
506 runner_assert(prop->dest_x == 0);
507 runner_assert(prop->dest_y == 0);
508
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000509 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900510
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000511 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900512 runner_assert_or_return(prop);
513 runner_assert(prop->dest_width == 200);
514 runner_assert(prop->dest_height == 300);
515 runner_assert(prop->dest_x == 20);
516 runner_assert(prop->dest_y == 30);
517}
518
519RUNNER_TEST(surface_source_rectangle)
520{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000521 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900522 struct ivi_layout_surface *ivisurf;
523 const struct ivi_layout_surface_properties *prop;
524
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000525 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900526 runner_assert(ivisurf != NULL);
527
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000528 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900529 runner_assert_or_return(prop);
530 runner_assert(prop->source_width == 0);
531 runner_assert(prop->source_height == 0);
532 runner_assert(prop->source_x == 0);
533 runner_assert(prop->source_y == 0);
534
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000535 runner_assert(lyt->surface_set_source_rectangle(
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900536 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
537
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000538 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900539 runner_assert_or_return(prop);
540 runner_assert(prop->source_width == 0);
541 runner_assert(prop->source_height == 0);
542 runner_assert(prop->source_x == 0);
543 runner_assert(prop->source_y == 0);
544
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000545 lyt->commit_changes();
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900546
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000547 prop = lyt->get_properties_of_surface(ivisurf);
Nobuhiko Tanibata23d95822015-06-22 15:33:17 +0900548 runner_assert_or_return(prop);
549 runner_assert(prop->source_width == 200);
550 runner_assert(prop->source_height == 300);
551 runner_assert(prop->source_x == 20);
552 runner_assert(prop->source_y == 30);
Pekka Paalanenf5b74f72015-03-25 12:50:31 +0200553}
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900554
555RUNNER_TEST(surface_bad_opacity)
556{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000557 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900558 struct ivi_layout_surface *ivisurf;
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000559 const struct ivi_layout_surface_properties *prop;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900560
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000561 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900562 runner_assert(ivisurf != NULL);
563
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000564 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900565 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
566
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000567 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900568 ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
569
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000570 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900571 ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
572
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000573 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900574
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000575 prop = lyt->get_properties_of_surface(ivisurf);
576 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900577
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000578 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900579 ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
580
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000581 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900582
Ucan, Emre \(ADITG/SW1\)995e6fb2016-03-04 12:50:12 +0000583 runner_assert(prop->opacity == wl_fixed_from_double(0.3));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900584
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000585 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900586 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
587
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000588 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900589}
590
591RUNNER_TEST(ivi_layout_commit_changes)
592{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000593 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900594
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000595 lyt->commit_changes();
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900596}
597
598RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
599{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000600 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900601 struct ivi_layout_surface *ivisurf;
602
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000603 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900604 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000605 runner_assert(lyt->surface_set_visibility(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900606 ivisurf, true) == IVI_SUCCEEDED);
607}
608
609RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
610{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000611 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900612 struct ivi_layout_surface *ivisurf;
613
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000614 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900615 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000616 runner_assert(lyt->surface_set_opacity(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900617 ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
618}
619
620RUNNER_TEST(commit_changes_after_orientation_set_surface_destroy)
621{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000622 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900623 struct ivi_layout_surface *ivisurf;
624
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000625 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900626 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000627 runner_assert(lyt->surface_set_orientation(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900628 ivisurf, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
629}
630
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900631RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
632{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000633 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900634 struct ivi_layout_surface *ivisurf;
635
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000636 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900637 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000638 runner_assert(lyt->surface_set_source_rectangle(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900639 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
640}
641
642RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
643{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000644 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900645 struct ivi_layout_surface *ivisurf;
646
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000647 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900648 runner_assert(ivisurf != NULL);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000649 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900650 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
651}
652
653RUNNER_TEST(get_surface_after_destroy_surface)
654{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000655 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900656 struct ivi_layout_surface *ivisurf;
657
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000658 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibatac74bafa2015-06-22 15:33:26 +0900659 runner_assert(ivisurf == NULL);
660}
661
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900662RUNNER_TEST(layer_render_order)
663{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000664 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900665 struct ivi_layout_layer *ivilayer;
666 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
667 struct ivi_layout_surface **array;
668 int32_t length = 0;
669 uint32_t i;
670
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000671 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900672
673 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000674 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900675
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000676 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900677 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
678
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000679 lyt->commit_changes();
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900680
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000681 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900682 ivilayer, &length, &array) == IVI_SUCCEEDED);
683 runner_assert(IVI_TEST_SURFACE_COUNT == length);
684 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
685 runner_assert(array[i] == ivisurfs[i]);
686
687 if (length > 0)
688 free(array);
689
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000690 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900691 ivilayer, NULL, 0) == IVI_SUCCEEDED);
692
693 array = NULL;
694
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000695 lyt->commit_changes();
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900696
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000697 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900698 ivilayer, &length, &array) == IVI_SUCCEEDED);
699 runner_assert(length == 0 && array == NULL);
700
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000701 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibatad3643932015-06-22 15:34:09 +0900702}
703
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900704RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
705{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000706 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900707 struct ivi_layout_layer *ivilayer;
708 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
709 struct ivi_layout_surface **array;
710 int32_t length = 0;
711 int32_t i;
712
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000713 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900714
715 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000716 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900717
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000718 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900719 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
720
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000721 lyt->commit_changes();
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900722
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000723 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900724 ivilayer, &length, &array) == IVI_SUCCEEDED);
725 runner_assert(IVI_TEST_SURFACE_COUNT == length);
726 for (i = 0; i < length; i++)
727 runner_assert(array[i] == ivisurfs[i]);
728
729 if (length > 0)
730 free(array);
731}
732
733RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
734{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000735 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900736 struct ivi_layout_layer *ivilayer;
737 struct ivi_layout_surface *ivisurfs[2] = {};
738 struct ivi_layout_surface **array;
739 int32_t length = 0;
740 int32_t i;
741
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000742 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
743 ivisurfs[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
744 ivisurfs[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900745
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000746 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900747 ivilayer, &length, &array) == IVI_SUCCEEDED);
748 runner_assert(2 == length);
749 for (i = 0; i < length; i++)
750 runner_assert(array[i] == ivisurfs[i]);
751
752 if (length > 0)
753 free(array);
754
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000755 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900756}
757
758RUNNER_TEST(layer_bad_render_order)
759{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000760 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900761 struct ivi_layout_layer *ivilayer;
762 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
763 struct ivi_layout_surface **array = NULL;
764 int32_t length = 0;
765 uint32_t i;
766
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000767 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900768
769 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000770 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900771
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000772 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900773 NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
774
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000775 lyt->commit_changes();
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900776
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 NULL, &length, &array) == IVI_FAILED);
779 runner_assert(length == 0 && 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, NULL, &array) == IVI_FAILED);
783 runner_assert(array == NULL);
784
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000785 runner_assert(lyt->get_surfaces_on_layer(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900786 ivilayer, &length, NULL) == IVI_FAILED);
787 runner_assert(length == 0);
788
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000789 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900790}
791
792RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
793{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000794 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900795 struct ivi_layout_layer *ivilayer;
796 struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
797 int i;
798
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000799 ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900800
801 for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000802 ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900803
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000804 runner_assert(lyt->layer_set_render_order(
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900805 ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
806}
807
808RUNNER_TEST(cleanup_layer)
809{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000810 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900811 struct ivi_layout_layer *ivilayer;
812
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000813 ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
814 lyt->layer_destroy(ivilayer);
Nobuhiko Tanibata0671b4d2015-06-22 15:34:42 +0900815}
816
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900817static void
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000818test_surface_properties_changed_notification_callback(struct wl_listener *listener, void *data)
819
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900820{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000821 struct test_context *ctx =
822 container_of(listener, struct test_context,
823 surface_property_changed);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000824 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000825 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900826
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000827 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900828
829 ctx->user_flags = 1;
830}
831
832RUNNER_TEST(surface_properties_changed_notification)
833{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000834 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900835 const uint32_t id_surface = IVI_TEST_SURFACE_ID(0);
836 struct ivi_layout_surface *ivisurf;
837
838 ctx->user_flags = 0;
839
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000840 ivisurf = lyt->get_surface_from_id(id_surface);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900841 runner_assert(ivisurf != NULL);
842
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000843 ctx->surface_property_changed.notify = test_surface_properties_changed_notification_callback;
844
845 runner_assert(lyt->surface_add_listener(
846 ivisurf, &ctx->surface_property_changed) == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900847
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000848 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900849
850 runner_assert(ctx->user_flags == 0);
851
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000852 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900853 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
854
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000855 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900856
857 runner_assert(ctx->user_flags == 1);
858
859 ctx->user_flags = 0;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000860 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900861 ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
862
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000863 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900864
865 runner_assert(ctx->user_flags == 0);
866
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000867 // remove surface property changed listener.
868 wl_list_remove(&ctx->surface_property_changed.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900869 ctx->user_flags = 0;
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000870 runner_assert(lyt->surface_set_destination_rectangle(
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900871 ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
872
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000873 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900874
875 runner_assert(ctx->user_flags == 0);
876}
877
878static void
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000879test_surface_configure_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900880{
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000881 struct test_context *ctx =
882 container_of(listener, struct test_context,
883 surface_configured);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000884 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000885 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900886
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000887 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900888
889 ctx->user_flags = 1;
890}
891
892RUNNER_TEST(surface_configure_notification_p1)
893{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000894 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900895
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000896 ctx->surface_configured.notify = test_surface_configure_notification_callback;
897 runner_assert(IVI_SUCCEEDED == lyt->add_listener_configure_surface(&ctx->surface_configured));
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000898 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900899
900 ctx->user_flags = 0;
901}
902
903RUNNER_TEST(surface_configure_notification_p2)
904{
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900905 runner_assert(ctx->user_flags == 1);
906
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000907 // remove surface configured listener.
908 wl_list_remove(&ctx->surface_configured.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900909 ctx->user_flags = 0;
910}
911
912RUNNER_TEST(surface_configure_notification_p3)
913{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000914 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900915
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000916 lyt->commit_changes();
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900917 runner_assert(ctx->user_flags == 0);
918}
919
920static void
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000921test_surface_create_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900922{
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000923 struct test_context *ctx =
924 container_of(listener, struct test_context,
925 surface_created);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000926 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000927 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900928
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000929 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900930
931 ctx->user_flags = 1;
932}
933
934RUNNER_TEST(surface_create_notification_p1)
935{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000936 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900937
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000938 ctx->surface_created.notify = test_surface_create_notification_callback;
939 runner_assert(lyt->add_listener_create_surface(
940 &ctx->surface_created) == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900941
942 ctx->user_flags = 0;
943}
944
945RUNNER_TEST(surface_create_notification_p2)
946{
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900947 runner_assert(ctx->user_flags == 1);
948
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000949 // remove surface created listener.
950 wl_list_remove(&ctx->surface_created.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900951 ctx->user_flags = 0;
952}
953
954RUNNER_TEST(surface_create_notification_p3)
955{
956 runner_assert(ctx->user_flags == 0);
957}
958
959static void
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000960test_surface_remove_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900961{
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000962 struct test_context *ctx =
963 container_of(listener, struct test_context,
964 surface_removed);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000965 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000966 struct ivi_layout_surface *ivisurf = data;
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900967
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000968 runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900969
970 ctx->user_flags = 1;
971}
972
973RUNNER_TEST(surface_remove_notification_p1)
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)67f0aa82016-04-04 08:05:18 +0000977 ctx->surface_removed.notify = test_surface_remove_notification_callback;
978 runner_assert(lyt->add_listener_remove_surface(&ctx->surface_removed)
979 == IVI_SUCCEEDED);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900980
981 ctx->user_flags = 0;
982}
983
984RUNNER_TEST(surface_remove_notification_p2)
985{
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900986 runner_assert(ctx->user_flags == 1);
987
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000988 // remove surface removed listener.
989 wl_list_remove(&ctx->surface_removed.link);
Nobuhiko Tanibata915303a2015-06-22 15:35:58 +0900990 ctx->user_flags = 0;
991}
992
993RUNNER_TEST(surface_remove_notification_p3)
994{
995 runner_assert(ctx->user_flags == 0);
996}
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +0900997
998static void
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +0000999test_surface_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001000{
1001}
1002
1003RUNNER_TEST(surface_bad_properties_changed_notification)
1004{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001005 const struct ivi_layout_interface *lyt = ctx->layout_interface;
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001006 struct ivi_layout_surface *ivisurf;
1007
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001008 ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001009 runner_assert(ivisurf != NULL);
1010
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001011 ctx->surface_property_changed.notify = test_surface_bad_properties_changed_notification_callback;
1012
1013 runner_assert(lyt->surface_add_listener(
1014 NULL, &ctx->surface_property_changed) == IVI_FAILED);
1015 runner_assert(lyt->surface_add_listener(
1016 ivisurf, NULL) == IVI_FAILED);
Nobuhiko Tanibata0af22d42015-06-22 15:36:21 +09001017}