• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2012 Intel Corporation
3  * Copyright © 2013 DENSO CORPORATION
4  * Copyright © 2015 Collabora, Ltd.
5  *
6  * 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:
13  *
14  * 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.
26  */
27 
28 #include "config.h"
29 
30 #include <stdint.h>
31 #include <unistd.h>
32 #include <signal.h>
33 #include <string.h>
34 #include <assert.h>
35 #include <limits.h>
36 #include <errno.h>
37 
38 #include <libweston/libweston.h>
39 #include "compositor/weston.h"
40 #include "weston-test-server-protocol.h"
41 #include "ivi-test.h"
42 #include "ivi-shell/ivi-layout-export.h"
43 #include "shared/helpers.h"
44 
45 struct test_context;
46 
47 struct runner_test {
48 	const char *name;
49 	void (*run)(struct test_context *);
50 } __attribute__ ((aligned (32)));
51 
52 #define RUNNER_TEST(name)					\
53 	static void runner_func_##name(struct test_context *);	\
54 								\
55 	const struct runner_test runner_test_##name		\
56 		__attribute__ ((section ("plugin_test_section"))) =	\
57 	{							\
58 		#name, runner_func_##name			\
59 	};							\
60 								\
61 	static void runner_func_##name(struct test_context *ctx)
62 
63 extern const struct runner_test __start_plugin_test_section;
64 extern const struct runner_test __stop_plugin_test_section;
65 
66 static const struct runner_test *
find_runner_test(const char * name)67 find_runner_test(const char *name)
68 {
69 	const struct runner_test *t;
70 
71 	for (t = &__start_plugin_test_section;
72 	     t < &__stop_plugin_test_section; t++) {
73 		if (strcmp(t->name, name) == 0)
74 			return t;
75 	}
76 
77 	return NULL;
78 }
79 
80 struct test_context {
81 	const struct ivi_layout_interface *layout_interface;
82 	struct wl_resource *runner_resource;
83 	uint32_t user_flags;
84 
85 	struct wl_listener surface_property_changed;
86 	struct wl_listener surface_created;
87 	struct wl_listener surface_removed;
88 	struct wl_listener surface_configured;
89 };
90 
91 struct test_launcher {
92 	struct weston_compositor *compositor;
93 	struct test_context context;
94 	const struct ivi_layout_interface *layout_interface;
95 };
96 
97 static void
destroy_runner(struct wl_resource * resource)98 destroy_runner(struct wl_resource *resource)
99 {
100 	struct test_launcher *launcher = wl_resource_get_user_data(resource);
101 	struct test_context *ctx = &launcher->context;
102 
103 	assert(ctx->runner_resource == NULL ||
104 	       ctx->runner_resource == resource);
105 
106 	ctx->layout_interface = NULL;
107 	ctx->runner_resource = NULL;
108 }
109 
110 static void
runner_destroy_handler(struct wl_client * client,struct wl_resource * resource)111 runner_destroy_handler(struct wl_client *client, struct wl_resource *resource)
112 {
113 	wl_resource_destroy(resource);
114 }
115 
116 static void
runner_run_handler(struct wl_client * client,struct wl_resource * resource,const char * test_name)117 runner_run_handler(struct wl_client *client, struct wl_resource *resource,
118 		   const char *test_name)
119 {
120 	struct test_launcher *launcher;
121 	const struct runner_test *t;
122 	struct test_context *ctx;
123 
124 	launcher = wl_resource_get_user_data(resource);
125 	ctx = &launcher->context;
126 
127 	assert(ctx->runner_resource == NULL ||
128 	       ctx->runner_resource == resource);
129 
130 	ctx->layout_interface = launcher->layout_interface;
131 	ctx->runner_resource = resource;
132 
133 	t = find_runner_test(test_name);
134 	if (!t) {
135 		weston_log("Error: runner test \"%s\" not found.\n",
136 			   test_name);
137 		wl_resource_post_error(resource,
138 				       WESTON_TEST_RUNNER_ERROR_UNKNOWN_TEST,
139 				       "weston_test_runner: unknown: '%s'",
140 				       test_name);
141 		return;
142 	}
143 
144 	weston_log("weston_test_runner.run(\"%s\")\n", test_name);
145 
146 	t->run(ctx);
147 
148 	weston_test_runner_send_finished(resource);
149 }
150 
151 static const struct weston_test_runner_interface runner_implementation = {
152 	runner_destroy_handler,
153 	runner_run_handler
154 };
155 
156 static void
bind_runner(struct wl_client * client,void * data,uint32_t version,uint32_t id)157 bind_runner(struct wl_client *client, void *data,
158 	    uint32_t version, uint32_t id)
159 {
160 	struct test_launcher *launcher = data;
161 	struct wl_resource *resource;
162 
163 	resource = wl_resource_create(client, &weston_test_runner_interface,
164 				      1, id);
165 	if (!resource) {
166 		wl_client_post_no_memory(client);
167 		return;
168 	}
169 
170 	wl_resource_set_implementation(resource, &runner_implementation,
171 				       launcher, destroy_runner);
172 
173 	if (launcher->context.runner_resource != NULL) {
174 		weston_log("test FATAL: "
175 			   "attempting to run several tests in parallel.\n");
176 		wl_resource_post_error(resource,
177 				       WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
178 				       "attempt to run parallel tests");
179 	}
180 }
181 
182 WL_EXPORT int
wet_module_init(struct weston_compositor * compositor,int * argc,char * argv[])183 wet_module_init(struct weston_compositor *compositor,
184 		       int *argc, char *argv[])
185 {
186 	struct test_launcher *launcher;
187 	const struct ivi_layout_interface *iface;
188 
189 	iface = ivi_layout_get_api(compositor);
190 
191 	if (!iface) {
192 		weston_log("fatal: cannot use ivi_layout_interface.\n");
193 		return -1;
194 	}
195 
196 	launcher = zalloc(sizeof *launcher);
197 	if (!launcher)
198 		return -1;
199 
200 	launcher->compositor = compositor;
201 	launcher->layout_interface = iface;
202 
203 	if (wl_global_create(compositor->wl_display,
204 			     &weston_test_runner_interface, 1,
205 			     launcher, bind_runner) == NULL)
206 		return -1;
207 
208 	return 0;
209 }
210 
211 static void
runner_assert_fail(const char * cond,const char * file,int line,const char * func,struct test_context * ctx)212 runner_assert_fail(const char *cond, const char *file, int line,
213 		   const char *func, struct test_context *ctx)
214 {
215 	weston_log("Assert failure in %s:%d, %s: '%s'\n",
216 		   file, line, func, cond);
217 
218 	assert(ctx->runner_resource);
219 	wl_resource_post_error(ctx->runner_resource,
220 			       WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
221 			       "Assert failure in %s:%d, %s: '%s'\n",
222 			       file, line, func, cond);
223 }
224 
225 #define runner_assert(cond) ({					\
226 	bool b_ = (cond);					\
227 	if (!b_)						\
228 		runner_assert_fail(#cond, __FILE__, __LINE__,	\
229 				   __func__, ctx);		\
230 	b_;							\
231 })
232 
233 #define runner_assert_or_return(cond) do {			\
234 	bool b_ = (cond);					\
235 	if (!b_) {						\
236 		runner_assert_fail(#cond, __FILE__, __LINE__,	\
237 				   __func__, ctx);		\
238 		return;						\
239 	}							\
240 } while (0)
241 
242 
243 /*************************** tests **********************************/
244 
245 /*
246  * This is a IVI controller module requiring ivi-shell.so.
247  * This module is specially written to execute tests that target the
248  * ivi_layout API.
249  *
250  * The test program containing the fixture setup and initiating the tests is
251  * test-ivi-layout-client (ivi-layout-test-client.c).
252  * That program uses the weston-test-runner framework to execute each TEST()
253  * in ivi-layout-test-client.c with a fresh connection to the single
254  * compositor instance.
255  *
256  * Each TEST() in ivi-layout-test-client.c will bind to weston_test_runner global
257  * interface. A TEST() will set up the client state, and issue
258  * weston_test_runner.run request to execute the compositor-side of the test.
259  *
260  * The compositor-side parts of the tests are in this file. They are specified
261  * by RUNNER_TEST() macro, where the name argument matches the name string
262  * passed to weston_test_runner.run.
263  *
264  * A RUNNER_TEST() function simply returns when it succeeds. If it fails,
265  * a fatal protocol error is sent to the client from runner_assert() or
266  * runner_assert_or_return().
267  *
268  * A single TEST() in ivi-layout-test-client.c may use multiple RUNNER_TEST()s to
269  * achieve multiple test points over a client action sequence.
270  */
271 
RUNNER_TEST(surface_create_p1)272 RUNNER_TEST(surface_create_p1)
273 {
274 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
275 	struct ivi_layout_surface *ivisurf[2];
276 	uint32_t ivi_id;
277 
278 	ivisurf[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
279 	runner_assert(ivisurf[0]);
280 
281 	ivisurf[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(1));
282 	runner_assert(ivisurf[1]);
283 
284 	ivi_id = lyt->get_id_of_surface(ivisurf[0]);
285 	runner_assert(ivi_id == IVI_TEST_SURFACE_ID(0));
286 
287 	ivi_id = lyt->get_id_of_surface(ivisurf[1]);
288 	runner_assert(ivi_id == IVI_TEST_SURFACE_ID(1));
289 }
290 
RUNNER_TEST(surface_create_p2)291 RUNNER_TEST(surface_create_p2)
292 {
293 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
294 	struct ivi_layout_surface *ivisurf;
295 
296 	/* the ivi_surface was destroyed by the client */
297 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
298 	runner_assert(ivisurf == NULL);
299 }
300 
RUNNER_TEST(surface_visibility)301 RUNNER_TEST(surface_visibility)
302 {
303 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
304 	struct ivi_layout_surface *ivisurf;
305 	int32_t ret;
306 	const struct ivi_layout_surface_properties *prop;
307 
308 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
309 	runner_assert(ivisurf);
310 
311 	ret = lyt->surface_set_visibility(ivisurf, true);
312 	runner_assert(ret == IVI_SUCCEEDED);
313 
314 	lyt->commit_changes();
315 
316 	prop = lyt->get_properties_of_surface(ivisurf);
317 	runner_assert(prop->visibility == true);
318 }
319 
RUNNER_TEST(surface_opacity)320 RUNNER_TEST(surface_opacity)
321 {
322 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
323 	struct ivi_layout_surface *ivisurf;
324 	int32_t ret;
325 	const struct ivi_layout_surface_properties *prop;
326 
327 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
328 	runner_assert(ivisurf);
329 
330 	prop = lyt->get_properties_of_surface(ivisurf);
331 	runner_assert(prop->opacity == wl_fixed_from_double(1.0));
332 
333 	ret = lyt->surface_set_opacity(ivisurf, wl_fixed_from_double(0.5));
334 	runner_assert(ret == IVI_SUCCEEDED);
335 
336 	runner_assert(prop->opacity == wl_fixed_from_double(1.0));
337 
338 	lyt->commit_changes();
339 
340 	runner_assert(prop->opacity == wl_fixed_from_double(0.5));
341 }
342 
RUNNER_TEST(surface_dimension)343 RUNNER_TEST(surface_dimension)
344 {
345 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
346 	struct ivi_layout_surface *ivisurf;
347 	const struct ivi_layout_surface_properties *prop;
348 
349 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
350 	runner_assert(ivisurf != NULL);
351 
352 	prop = lyt->get_properties_of_surface(ivisurf);
353 	runner_assert_or_return(prop);
354 	runner_assert(prop->dest_width == 1);
355 	runner_assert(prop->dest_height == 1);
356 
357 	runner_assert(IVI_SUCCEEDED ==
358 		      lyt->surface_set_destination_rectangle(ivisurf, prop->dest_x,
359 		      prop->dest_y, 200, 300));
360 
361 	runner_assert(prop->dest_width == 1);
362 	runner_assert(prop->dest_height == 1);
363 
364 	lyt->commit_changes();
365 
366 	prop = lyt->get_properties_of_surface(ivisurf);
367 	runner_assert_or_return(prop);
368 	runner_assert(prop->dest_width == 200);
369 	runner_assert(prop->dest_height == 300);
370 }
371 
RUNNER_TEST(surface_position)372 RUNNER_TEST(surface_position)
373 {
374 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
375 	struct ivi_layout_surface *ivisurf;
376 	const struct ivi_layout_surface_properties *prop;
377 
378 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
379 	runner_assert(ivisurf != NULL);
380 
381 	prop = lyt->get_properties_of_surface(ivisurf);
382 	runner_assert_or_return(prop);
383 	runner_assert(prop->dest_x == 0);
384 	runner_assert(prop->dest_y == 0);
385 
386 	runner_assert(lyt->surface_set_destination_rectangle(
387 		      ivisurf, 20, 30,
388 		      prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
389 
390 	runner_assert(prop->dest_x == 0);
391 	runner_assert(prop->dest_y == 0);
392 
393 	lyt->commit_changes();
394 
395 	prop = lyt->get_properties_of_surface(ivisurf);
396 	runner_assert_or_return(prop);
397 	runner_assert(prop->dest_x == 20);
398 	runner_assert(prop->dest_y == 30);
399 }
400 
RUNNER_TEST(surface_destination_rectangle)401 RUNNER_TEST(surface_destination_rectangle)
402 {
403 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
404 	struct ivi_layout_surface *ivisurf;
405 	const struct ivi_layout_surface_properties *prop;
406 
407 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
408 	runner_assert(ivisurf != NULL);
409 
410 	prop = lyt->get_properties_of_surface(ivisurf);
411 	runner_assert_or_return(prop);
412 	runner_assert(prop->dest_width == 1);
413 	runner_assert(prop->dest_height == 1);
414 	runner_assert(prop->dest_x == 0);
415 	runner_assert(prop->dest_y == 0);
416 
417 	runner_assert(lyt->surface_set_destination_rectangle(
418 		      ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
419 
420 	prop = lyt->get_properties_of_surface(ivisurf);
421 	runner_assert_or_return(prop);
422 	runner_assert(prop->dest_width == 1);
423 	runner_assert(prop->dest_height == 1);
424 	runner_assert(prop->dest_x == 0);
425 	runner_assert(prop->dest_y == 0);
426 
427 	lyt->commit_changes();
428 
429 	prop = lyt->get_properties_of_surface(ivisurf);
430 	runner_assert_or_return(prop);
431 	runner_assert(prop->dest_width == 200);
432 	runner_assert(prop->dest_height == 300);
433 	runner_assert(prop->dest_x == 20);
434 	runner_assert(prop->dest_y == 30);
435 }
436 
RUNNER_TEST(surface_source_rectangle)437 RUNNER_TEST(surface_source_rectangle)
438 {
439 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
440 	struct ivi_layout_surface *ivisurf;
441 	const struct ivi_layout_surface_properties *prop;
442 
443 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
444 	runner_assert(ivisurf != NULL);
445 
446 	prop = lyt->get_properties_of_surface(ivisurf);
447 	runner_assert_or_return(prop);
448 	runner_assert(prop->source_width == 0);
449 	runner_assert(prop->source_height == 0);
450 	runner_assert(prop->source_x == 0);
451 	runner_assert(prop->source_y == 0);
452 
453 	runner_assert(lyt->surface_set_source_rectangle(
454 		      ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
455 
456 	prop = lyt->get_properties_of_surface(ivisurf);
457 	runner_assert_or_return(prop);
458 	runner_assert(prop->source_width == 0);
459 	runner_assert(prop->source_height == 0);
460 	runner_assert(prop->source_x == 0);
461 	runner_assert(prop->source_y == 0);
462 
463 	lyt->commit_changes();
464 
465 	prop = lyt->get_properties_of_surface(ivisurf);
466 	runner_assert_or_return(prop);
467 	runner_assert(prop->source_width == 200);
468 	runner_assert(prop->source_height == 300);
469 	runner_assert(prop->source_x == 20);
470 	runner_assert(prop->source_y == 30);
471 }
472 
RUNNER_TEST(surface_bad_opacity)473 RUNNER_TEST(surface_bad_opacity)
474 {
475 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
476 	struct ivi_layout_surface *ivisurf;
477 	const struct ivi_layout_surface_properties *prop;
478 
479 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
480 	runner_assert(ivisurf != NULL);
481 
482 	runner_assert(lyt->surface_set_opacity(
483 		      NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
484 
485 	runner_assert(lyt->surface_set_opacity(
486 		      ivisurf, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
487 
488 	runner_assert(lyt->surface_set_opacity(
489 		      ivisurf, wl_fixed_from_double(-1)) == IVI_FAILED);
490 
491 	lyt->commit_changes();
492 
493 	prop = lyt->get_properties_of_surface(ivisurf);
494 	runner_assert(prop->opacity == wl_fixed_from_double(0.3));
495 
496 	runner_assert(lyt->surface_set_opacity(
497 		      ivisurf, wl_fixed_from_double(1.1)) == IVI_FAILED);
498 
499 	lyt->commit_changes();
500 
501 	runner_assert(prop->opacity == wl_fixed_from_double(0.3));
502 
503 	runner_assert(lyt->surface_set_opacity(
504 		      NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
505 
506 	lyt->commit_changes();
507 }
508 
RUNNER_TEST(surface_on_many_layer)509 RUNNER_TEST(surface_on_many_layer)
510 {
511 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
512 	struct ivi_layout_surface *ivisurf;
513 	struct ivi_layout_layer *ivilayers[IVI_TEST_LAYER_COUNT] = {};
514 	struct ivi_layout_layer **array;
515 	int32_t length = 0;
516 	uint32_t i;
517 
518 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
519 	runner_assert(ivisurf != NULL);
520 
521 	for (i = 0; i < IVI_TEST_LAYER_COUNT; i++) {
522 		ivilayers[i] = lyt->layer_create_with_dimension(
523 				IVI_TEST_LAYER_ID(i), 200, 300);
524 		runner_assert(lyt->layer_add_surface(
525 				ivilayers[i], ivisurf) == IVI_SUCCEEDED);
526 	}
527 
528 	lyt->commit_changes();
529 
530 	runner_assert(lyt->get_layers_under_surface(
531 		      ivisurf, &length, &array) == IVI_SUCCEEDED);
532 	runner_assert(IVI_TEST_LAYER_COUNT == length);
533 	for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
534 		runner_assert(array[i] == ivilayers[i]);
535 
536 	if (length > 0)
537 		free(array);
538 
539 	for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
540 		lyt->layer_remove_surface(ivilayers[i], ivisurf);
541 
542 	array = NULL;
543 
544 	lyt->commit_changes();
545 
546 	runner_assert(lyt->get_layers_under_surface(
547 		      ivisurf, &length, &array) == IVI_SUCCEEDED);
548 	runner_assert(length == 0 && array == NULL);
549 
550 	for (i = 0; i < IVI_TEST_LAYER_COUNT; i++)
551 		lyt->layer_destroy(ivilayers[i]);
552 }
553 
RUNNER_TEST(ivi_layout_commit_changes)554 RUNNER_TEST(ivi_layout_commit_changes)
555 {
556 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
557 
558 	lyt->commit_changes();
559 }
560 
RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)561 RUNNER_TEST(commit_changes_after_visibility_set_surface_destroy)
562 {
563 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
564 	struct ivi_layout_surface *ivisurf;
565 
566 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
567 	runner_assert(ivisurf != NULL);
568 	runner_assert(lyt->surface_set_visibility(
569 		      ivisurf, true) == IVI_SUCCEEDED);
570 }
571 
RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)572 RUNNER_TEST(commit_changes_after_opacity_set_surface_destroy)
573 {
574 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
575 	struct ivi_layout_surface *ivisurf;
576 
577 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
578 	runner_assert(ivisurf != NULL);
579 	runner_assert(lyt->surface_set_opacity(
580 		      ivisurf, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
581 }
582 
RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)583 RUNNER_TEST(commit_changes_after_source_rectangle_set_surface_destroy)
584 {
585 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
586 	struct ivi_layout_surface *ivisurf;
587 
588 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
589 	runner_assert(ivisurf != NULL);
590 	runner_assert(lyt->surface_set_source_rectangle(
591 		      ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
592 }
593 
RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)594 RUNNER_TEST(commit_changes_after_destination_rectangle_set_surface_destroy)
595 {
596 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
597 	struct ivi_layout_surface *ivisurf;
598 
599 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
600 	runner_assert(ivisurf != NULL);
601 	runner_assert(lyt->surface_set_destination_rectangle(
602 		      ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
603 }
604 
RUNNER_TEST(get_surface_after_destroy_surface)605 RUNNER_TEST(get_surface_after_destroy_surface)
606 {
607 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
608 	struct ivi_layout_surface *ivisurf;
609 
610 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
611 	runner_assert(ivisurf == NULL);
612 }
613 
RUNNER_TEST(layer_render_order)614 RUNNER_TEST(layer_render_order)
615 {
616 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
617 	struct ivi_layout_layer *ivilayer;
618 	struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
619 	struct ivi_layout_surface **array;
620 	int32_t length = 0;
621 	uint32_t i;
622 
623 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
624 
625 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
626 		ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
627 
628 	runner_assert(lyt->layer_set_render_order(
629 		      ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
630 
631 	lyt->commit_changes();
632 
633 	runner_assert(lyt->get_surfaces_on_layer(
634 		      ivilayer, &length, &array) == IVI_SUCCEEDED);
635 	runner_assert(IVI_TEST_SURFACE_COUNT == length);
636 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
637 		runner_assert(array[i] == ivisurfs[i]);
638 
639 	if (length > 0)
640 		free(array);
641 
642 	runner_assert(lyt->layer_set_render_order(
643 		      ivilayer, NULL, 0) == IVI_SUCCEEDED);
644 
645 	array = NULL;
646 
647 	lyt->commit_changes();
648 
649 	runner_assert(lyt->get_surfaces_on_layer(
650 		      ivilayer, &length, &array) == IVI_SUCCEEDED);
651 	runner_assert(length == 0 && array == NULL);
652 
653 	lyt->layer_destroy(ivilayer);
654 }
655 
RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)656 RUNNER_TEST(test_layer_render_order_destroy_one_surface_p1)
657 {
658 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
659 	struct ivi_layout_layer *ivilayer;
660 	struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
661 	struct ivi_layout_surface **array;
662 	int32_t length = 0;
663 	int32_t i;
664 
665 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
666 
667 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
668 		ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
669 
670 	runner_assert(lyt->layer_set_render_order(
671 		      ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
672 
673 	lyt->commit_changes();
674 
675 	runner_assert(lyt->get_surfaces_on_layer(
676 		      ivilayer, &length, &array) == IVI_SUCCEEDED);
677 	runner_assert(IVI_TEST_SURFACE_COUNT == length);
678 	for (i = 0; i < length; i++)
679 		runner_assert(array[i] == ivisurfs[i]);
680 
681 	if (length > 0)
682 		free(array);
683 }
684 
RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)685 RUNNER_TEST(test_layer_render_order_destroy_one_surface_p2)
686 {
687 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
688 	struct ivi_layout_layer *ivilayer;
689 	struct ivi_layout_surface *ivisurfs[2] = {};
690 	struct ivi_layout_surface **array;
691 	int32_t length = 0;
692 	int32_t i;
693 
694 	ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
695 	ivisurfs[0] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
696 	ivisurfs[1] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(2));
697 
698 	runner_assert(lyt->get_surfaces_on_layer(
699 		      ivilayer, &length, &array) == IVI_SUCCEEDED);
700 	runner_assert(2 == length);
701 	for (i = 0; i < length; i++)
702 		runner_assert(array[i] == ivisurfs[i]);
703 
704 	if (length > 0)
705 		free(array);
706 
707 	lyt->layer_destroy(ivilayer);
708 }
709 
RUNNER_TEST(layer_bad_render_order)710 RUNNER_TEST(layer_bad_render_order)
711 {
712 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
713 	struct ivi_layout_layer *ivilayer;
714 	struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
715 	struct ivi_layout_surface **array = NULL;
716 	int32_t length = 0;
717 	uint32_t i;
718 
719 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
720 
721 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
722 		ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
723 
724 	runner_assert(lyt->layer_set_render_order(
725 		      NULL, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_FAILED);
726 
727 	lyt->commit_changes();
728 
729 	runner_assert(lyt->get_surfaces_on_layer(
730 		      NULL, &length, &array) == IVI_FAILED);
731 	runner_assert(length == 0 && array == NULL);
732 
733 	runner_assert(lyt->get_surfaces_on_layer(
734 		      ivilayer, NULL, &array) == IVI_FAILED);
735 	runner_assert(array == NULL);
736 
737 	runner_assert(lyt->get_surfaces_on_layer(
738 		      ivilayer, &length, NULL) == IVI_FAILED);
739 	runner_assert(length == 0);
740 
741 	lyt->layer_destroy(ivilayer);
742 }
743 
RUNNER_TEST(layer_add_surfaces)744 RUNNER_TEST(layer_add_surfaces)
745 {
746 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
747 	struct ivi_layout_layer *ivilayer;
748 	struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
749 	struct ivi_layout_surface **array;
750 	int32_t length = 0;
751 	uint32_t i;
752 
753 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
754 
755 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++) {
756 		ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
757 		runner_assert(lyt->layer_add_surface(
758 				      ivilayer, ivisurfs[i]) == IVI_SUCCEEDED);
759 	}
760 
761 	lyt->commit_changes();
762 
763 	runner_assert(lyt->get_surfaces_on_layer(
764 		      ivilayer, &length, &array) == IVI_SUCCEEDED);
765 	runner_assert(IVI_TEST_SURFACE_COUNT == length);
766 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
767 		runner_assert(array[i] == ivisurfs[i]);
768 
769 	if (length > 0)
770 		free(array);
771 
772 	runner_assert(lyt->layer_set_render_order(
773 		      ivilayer, NULL, 0) == IVI_SUCCEEDED);
774 
775 	for (i = IVI_TEST_SURFACE_COUNT; i-- > 0;)
776 		runner_assert(lyt->layer_add_surface(
777 				      ivilayer, ivisurfs[i]) == IVI_SUCCEEDED);
778 
779 	lyt->commit_changes();
780 
781 	runner_assert(lyt->get_surfaces_on_layer(
782 		      ivilayer, &length, &array) == IVI_SUCCEEDED);
783 	runner_assert(IVI_TEST_SURFACE_COUNT == length);
784 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
785 		runner_assert(array[i] == ivisurfs[IVI_TEST_SURFACE_COUNT - (i + 1)]);
786 
787 	if (length > 0)
788 		free(array);
789 
790 	lyt->layer_destroy(ivilayer);
791 }
792 
RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)793 RUNNER_TEST(commit_changes_after_render_order_set_surface_destroy)
794 {
795 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
796 	struct ivi_layout_layer *ivilayer;
797 	struct ivi_layout_surface *ivisurfs[IVI_TEST_SURFACE_COUNT] = {};
798 	int i;
799 
800 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
801 
802 	for (i = 0; i < IVI_TEST_SURFACE_COUNT; i++)
803 		ivisurfs[i] = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(i));
804 
805 	runner_assert(lyt->layer_set_render_order(
806 		      ivilayer, ivisurfs, IVI_TEST_SURFACE_COUNT) == IVI_SUCCEEDED);
807 }
808 
RUNNER_TEST(cleanup_layer)809 RUNNER_TEST(cleanup_layer)
810 {
811 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
812 	struct ivi_layout_layer *ivilayer;
813 
814 	ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
815 	lyt->layer_destroy(ivilayer);
816 }
817 
818 static void
test_surface_properties_changed_notification_callback(struct wl_listener * listener,void * data)819 test_surface_properties_changed_notification_callback(struct wl_listener *listener, void *data)
820 
821 {
822 	struct test_context *ctx =
823 			container_of(listener, struct test_context,
824 					surface_property_changed);
825 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
826 	struct ivi_layout_surface *ivisurf = data;
827 
828 	runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
829 
830 	ctx->user_flags = 1;
831 }
832 
RUNNER_TEST(surface_properties_changed_notification)833 RUNNER_TEST(surface_properties_changed_notification)
834 {
835 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
836 	const uint32_t id_surface = IVI_TEST_SURFACE_ID(0);
837 	struct ivi_layout_surface *ivisurf;
838 
839 	ctx->user_flags = 0;
840 
841 	ivisurf = lyt->get_surface_from_id(id_surface);
842 	runner_assert(ivisurf != NULL);
843 
844 	ctx->surface_property_changed.notify = test_surface_properties_changed_notification_callback;
845 
846 	runner_assert(lyt->surface_add_listener(
847 		      ivisurf, &ctx->surface_property_changed) == IVI_SUCCEEDED);
848 
849 	lyt->commit_changes();
850 
851 	runner_assert(ctx->user_flags == 0);
852 
853 	runner_assert(lyt->surface_set_destination_rectangle(
854 		      ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
855 
856 	lyt->commit_changes();
857 
858 	runner_assert(ctx->user_flags == 1);
859 
860 	ctx->user_flags = 0;
861 	runner_assert(lyt->surface_set_destination_rectangle(
862 		      ivisurf, 20, 30, 200, 300) == IVI_SUCCEEDED);
863 
864 	lyt->commit_changes();
865 
866 	runner_assert(ctx->user_flags == 0);
867 
868 	// remove surface property changed listener.
869 	wl_list_remove(&ctx->surface_property_changed.link);
870 	ctx->user_flags = 0;
871 	runner_assert(lyt->surface_set_destination_rectangle(
872 		      ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
873 
874 	lyt->commit_changes();
875 
876 	runner_assert(ctx->user_flags == 0);
877 }
878 
879 static void
test_surface_configure_notification_callback(struct wl_listener * listener,void * data)880 test_surface_configure_notification_callback(struct wl_listener *listener, void *data)
881 {
882 	struct test_context *ctx =
883 			container_of(listener, struct test_context,
884 					surface_configured);
885 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
886 	struct ivi_layout_surface *ivisurf = data;
887 
888 	runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
889 
890 	ctx->user_flags = 1;
891 }
892 
RUNNER_TEST(surface_configure_notification_p1)893 RUNNER_TEST(surface_configure_notification_p1)
894 {
895 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
896 
897 	ctx->surface_configured.notify = test_surface_configure_notification_callback;
898 	runner_assert(IVI_SUCCEEDED == lyt->add_listener_configure_surface(&ctx->surface_configured));
899 	lyt->commit_changes();
900 
901 	ctx->user_flags = 0;
902 }
903 
RUNNER_TEST(surface_configure_notification_p2)904 RUNNER_TEST(surface_configure_notification_p2)
905 {
906 	runner_assert(ctx->user_flags == 1);
907 
908 	// remove surface configured listener.
909 	wl_list_remove(&ctx->surface_configured.link);
910 	ctx->user_flags = 0;
911 }
912 
RUNNER_TEST(surface_configure_notification_p3)913 RUNNER_TEST(surface_configure_notification_p3)
914 {
915 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
916 
917 	lyt->commit_changes();
918 	runner_assert(ctx->user_flags == 0);
919 }
920 
921 static void
test_surface_create_notification_callback(struct wl_listener * listener,void * data)922 test_surface_create_notification_callback(struct wl_listener *listener, void *data)
923 {
924 	struct test_context *ctx =
925 			container_of(listener, struct test_context,
926 					surface_created);
927 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
928 	struct ivi_layout_surface *ivisurf = data;
929 
930 	runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
931 
932 	ctx->user_flags = 1;
933 }
934 
RUNNER_TEST(surface_create_notification_p1)935 RUNNER_TEST(surface_create_notification_p1)
936 {
937 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
938 
939 	ctx->surface_created.notify = test_surface_create_notification_callback;
940 	runner_assert(lyt->add_listener_create_surface(
941 			&ctx->surface_created) == IVI_SUCCEEDED);
942 
943 	ctx->user_flags = 0;
944 }
945 
RUNNER_TEST(surface_create_notification_p2)946 RUNNER_TEST(surface_create_notification_p2)
947 {
948 	runner_assert(ctx->user_flags == 1);
949 
950 	// remove surface created listener.
951 	wl_list_remove(&ctx->surface_created.link);
952 	ctx->user_flags = 0;
953 }
954 
RUNNER_TEST(surface_create_notification_p3)955 RUNNER_TEST(surface_create_notification_p3)
956 {
957 	runner_assert(ctx->user_flags == 0);
958 }
959 
960 static void
test_surface_remove_notification_callback(struct wl_listener * listener,void * data)961 test_surface_remove_notification_callback(struct wl_listener *listener, void *data)
962 {
963 	struct test_context *ctx =
964 			container_of(listener, struct test_context,
965 					surface_removed);
966 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
967 	struct ivi_layout_surface *ivisurf = data;
968 
969 	runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
970 
971 	ctx->user_flags = 1;
972 }
973 
RUNNER_TEST(surface_remove_notification_p1)974 RUNNER_TEST(surface_remove_notification_p1)
975 {
976 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
977 
978 	ctx->surface_removed.notify = test_surface_remove_notification_callback;
979 	runner_assert(lyt->add_listener_remove_surface(&ctx->surface_removed)
980 			== IVI_SUCCEEDED);
981 
982 	ctx->user_flags = 0;
983 }
984 
RUNNER_TEST(surface_remove_notification_p2)985 RUNNER_TEST(surface_remove_notification_p2)
986 {
987 	runner_assert(ctx->user_flags == 1);
988 
989 	// remove surface removed listener.
990 	wl_list_remove(&ctx->surface_removed.link);
991 	ctx->user_flags = 0;
992 }
993 
RUNNER_TEST(surface_remove_notification_p3)994 RUNNER_TEST(surface_remove_notification_p3)
995 {
996 	runner_assert(ctx->user_flags == 0);
997 }
998 
999 static void
test_surface_bad_properties_changed_notification_callback(struct wl_listener * listener,void * data)1000 test_surface_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
1001 {
1002 }
1003 
RUNNER_TEST(surface_bad_properties_changed_notification)1004 RUNNER_TEST(surface_bad_properties_changed_notification)
1005 {
1006 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
1007 	struct ivi_layout_surface *ivisurf;
1008 
1009 	ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
1010 	runner_assert(ivisurf != NULL);
1011 
1012 	ctx->surface_property_changed.notify = test_surface_bad_properties_changed_notification_callback;
1013 
1014 	runner_assert(lyt->surface_add_listener(
1015 		      NULL, &ctx->surface_property_changed) == IVI_FAILED);
1016 	runner_assert(lyt->surface_add_listener(
1017 		      ivisurf, NULL) == IVI_FAILED);
1018 }
1019