ivi_layout-internal-test.c 27 KB
Newer Older
1 2 3 4
/*
 * Copyright © 2013 DENSO CORPORATION
 * Copyright © 2015 Collabora, Ltd.
 *
5 6 7 8 9 10 11
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
12
 *
13 14 15 16 17 18 19 20 21 22 23 24
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
25 26 27 28 29 30 31 32
 */

#include "config.h"

#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdbool.h>
33
#include <stdint.h>
34

Pekka Paalanen's avatar
Pekka Paalanen committed
35
#include "compositor.h"
36
#include "ivi-shell/ivi-layout-export.h"
37
#include "ivi-shell/ivi-layout-private.h"
38
#include "ivi-test.h"
39
#include "shared/helpers.h"
40 41 42

struct test_context {
	struct weston_compositor *compositor;
43
	const struct ivi_layout_interface *layout_interface;
44
	uint32_t user_flags;
45 46

	struct wl_listener layer_property_changed;
47
	struct wl_listener layer_created;
48
	struct wl_listener layer_removed;
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
};

static void
iassert_fail(const char *cond, const char *file, int line,
	     const char *func, struct test_context *ctx)
{
	weston_log("Assert failure in %s:%d, %s: '%s'\n",
		   file, line, func, cond);
	weston_compositor_exit_with_code(ctx->compositor, EXIT_FAILURE);
}

#define iassert(cond) ({						\
	bool b_ = (cond);						\
	if (!b_)							\
		iassert_fail(#cond, __FILE__, __LINE__, __func__, ctx);	\
	b_;								\
})

/************************ tests begin ******************************/

/*
 * These are all internal ivi_layout API tests that do not require
 * any client objects.
 */
static void
test_surface_bad_visibility(struct test_context *ctx)
{
76
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
77

78
	iassert(lyt->surface_set_visibility(NULL, true) == IVI_FAILED);
79

80
	lyt->commit_changes();
81 82
}

83 84 85
static void
test_surface_bad_destination_rectangle(struct test_context *ctx)
{
86
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
87

88
	iassert(lyt->surface_set_destination_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
89 90 91 92 93
}

static void
test_surface_bad_orientation(struct test_context *ctx)
{
94
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
95

96
	iassert(lyt->surface_set_orientation(NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
97 98 99 100 101
}

static void
test_surface_bad_source_rectangle(struct test_context *ctx)
{
102
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
103

104
	iassert(lyt->surface_set_source_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
105 106 107 108 109
}

static void
test_surface_bad_properties(struct test_context *ctx)
{
110
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
111

112
	iassert(lyt->get_properties_of_surface(NULL) == NULL);
113 114
}

115 116 117
static void
test_layer_create(struct test_context *ctx)
{
118
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
119 120 121 122 123
	uint32_t id1;
	uint32_t id2;
	struct ivi_layout_layer *ivilayer;
	struct ivi_layout_layer *new_ivilayer;

124
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
125 126
	iassert(ivilayer != NULL);

127
	iassert(IVI_TEST_LAYER_ID(0) == lyt->get_id_of_layer(ivilayer));
128

129
	new_ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
130 131
	iassert(ivilayer == new_ivilayer);

132 133
	id1 = lyt->get_id_of_layer(ivilayer);
	id2 = lyt->get_id_of_layer(new_ivilayer);
134 135
	iassert(id1 == id2);

136 137
	lyt->layer_destroy(ivilayer);
	iassert(lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0)) == NULL);
138 139 140 141 142
}

static void
test_layer_visibility(struct test_context *ctx)
{
143
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
144 145 146
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

147
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
148 149
	iassert(ivilayer != NULL);

150 151 152
	prop = lyt->get_properties_of_layer(ivilayer);

	iassert(prop->visibility == false);
153

154
	iassert(lyt->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
155

156
	iassert(prop->visibility == false);
157

158
	lyt->commit_changes();
159 160 161

	iassert(prop->visibility == true);

162
	lyt->layer_destroy(ivilayer);
163 164 165 166 167
}

static void
test_layer_opacity(struct test_context *ctx)
{
168
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
169 170 171
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

172
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
173 174
	iassert(ivilayer != NULL);

175 176
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->opacity == wl_fixed_from_double(1.0));
177

178
	iassert(lyt->layer_set_opacity(
179 180
		ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);

181
	iassert(prop->opacity == wl_fixed_from_double(1.0));
182

183
	lyt->commit_changes();
184 185 186

	iassert(prop->opacity == wl_fixed_from_double(0.5));

187
	lyt->layer_destroy(ivilayer);
188 189 190 191 192
}

static void
test_layer_orientation(struct test_context *ctx)
{
193
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
194 195 196
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

197
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
198 199
	iassert(ivilayer != NULL);

200 201
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->orientation == WL_OUTPUT_TRANSFORM_NORMAL);
202

203
	iassert(lyt->layer_set_orientation(
204 205
		ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);

206
	iassert(prop->orientation == WL_OUTPUT_TRANSFORM_NORMAL);
207

208
	lyt->commit_changes();
209 210 211

	iassert(prop->orientation == WL_OUTPUT_TRANSFORM_90);

212
	lyt->layer_destroy(ivilayer);
213 214 215 216 217
}

static void
test_layer_dimension(struct test_context *ctx)
{
218
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
219 220 221
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

222
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
223 224
	iassert(ivilayer != NULL);

225 226 227
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
228

229 230
	iassert(lyt->layer_set_destination_rectangle(ivilayer, prop->dest_x, prop->dest_y,
			400, 600) == IVI_SUCCEEDED);
231

232 233
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
234

235
	lyt->commit_changes();
236 237 238 239

	iassert(prop->dest_width == 400);
	iassert(prop->dest_height == 600);

240
	lyt->layer_destroy(ivilayer);
241 242 243 244 245
}

static void
test_layer_position(struct test_context *ctx)
{
246
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
247 248 249
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

250
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
251 252
	iassert(ivilayer != NULL);

253 254 255
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);
256

257 258
	iassert(lyt->layer_set_destination_rectangle(ivilayer, 20, 30,
			prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
259

260 261
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);
262

263
	lyt->commit_changes();
264

265
	prop = lyt->get_properties_of_layer(ivilayer);
266 267 268
	iassert(prop->dest_x == 20);
	iassert(prop->dest_y == 30);

269
	lyt->layer_destroy(ivilayer);
270 271 272 273 274
}

static void
test_layer_destination_rectangle(struct test_context *ctx)
{
275
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
276 277 278
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

279
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
280 281
	iassert(ivilayer != NULL);

282
	prop = lyt->get_properties_of_layer(ivilayer);
283 284 285 286 287
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);

288
	iassert(lyt->layer_set_destination_rectangle(
289 290
		ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);

291
	prop = lyt->get_properties_of_layer(ivilayer);
292 293 294 295 296
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);

297
	lyt->commit_changes();
298 299 300 301 302 303

	iassert(prop->dest_width == 400);
	iassert(prop->dest_height == 600);
	iassert(prop->dest_x == 20);
	iassert(prop->dest_y == 30);

304
	lyt->layer_destroy(ivilayer);
305 306 307 308 309
}

static void
test_layer_source_rectangle(struct test_context *ctx)
{
310
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
311 312 313
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

314
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
315 316
	iassert(ivilayer != NULL);

317
	prop = lyt->get_properties_of_layer(ivilayer);
318 319 320 321 322
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);
	iassert(prop->source_x == 0);
	iassert(prop->source_y == 0);

323
	iassert(lyt->layer_set_source_rectangle(
324 325
		ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);

326
	prop = lyt->get_properties_of_layer(ivilayer);
327 328 329 330 331
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);
	iassert(prop->source_x == 0);
	iassert(prop->source_y == 0);

332
	lyt->commit_changes();
333

334
	prop = lyt->get_properties_of_layer(ivilayer);
335 336 337 338 339
	iassert(prop->source_width == 400);
	iassert(prop->source_height == 600);
	iassert(prop->source_x == 20);
	iassert(prop->source_y == 30);

340
	lyt->layer_destroy(ivilayer);
341 342
}

343 344 345
static void
test_layer_bad_remove(struct test_context *ctx)
{
346 347
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
	lyt->layer_destroy(NULL);
348 349 350 351 352
}

static void
test_layer_bad_visibility(struct test_context *ctx)
{
353
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
354

355
	iassert(lyt->layer_set_visibility(NULL, true) == IVI_FAILED);
356

357
	lyt->commit_changes();
358 359 360 361 362
}

static void
test_layer_bad_opacity(struct test_context *ctx)
{
363
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
364
	struct ivi_layout_layer *ivilayer;
365
	const struct ivi_layout_layer_properties *prop;
366

367
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
368 369
	iassert(ivilayer != NULL);

370
	iassert(lyt->layer_set_opacity(
371 372
		NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);

373
	iassert(lyt->layer_set_opacity(
374 375
		ivilayer, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);

376
	iassert(lyt->layer_set_opacity(
377 378
		ivilayer, wl_fixed_from_double(-1)) == IVI_FAILED);

379
	lyt->commit_changes();
380

381 382
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->opacity == wl_fixed_from_double(0.3));
383

384
	iassert(lyt->layer_set_opacity(
385 386
		ivilayer, wl_fixed_from_double(1.1)) == IVI_FAILED);

387
	lyt->commit_changes();
388

389
	iassert(prop->opacity == wl_fixed_from_double(0.3));
390

391
	iassert(lyt->layer_set_opacity(
392 393
		NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);

394
	lyt->commit_changes();
395

396
	lyt->layer_destroy(ivilayer);
397 398 399 400 401
}

static void
test_layer_bad_destination_rectangle(struct test_context *ctx)
{
402
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
403

404
	iassert(lyt->layer_set_destination_rectangle(
405 406 407 408 409 410
		NULL, 20, 30, 200, 300) == IVI_FAILED);
}

static void
test_layer_bad_orientation(struct test_context *ctx)
{
411
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
412

413
	iassert(lyt->layer_set_orientation(
414 415
		NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);

416
	lyt->commit_changes();
417 418 419 420 421
}

static void
test_layer_bad_source_rectangle(struct test_context *ctx)
{
422
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
423

424
	iassert(lyt->layer_set_source_rectangle(
425 426 427 428 429 430
		NULL, 20, 30, 200, 300) == IVI_FAILED);
}

static void
test_layer_bad_properties(struct test_context *ctx)
{
431
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
432

433
	iassert(lyt->get_properties_of_layer(NULL) == NULL);
434 435 436 437 438
}

static void
test_commit_changes_after_visibility_set_layer_destroy(struct test_context *ctx)
{
439
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
440 441
	struct ivi_layout_layer *ivilayer;

442
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
443 444
	iassert(ivilayer != NULL);

445 446 447
	iassert(lyt->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
448 449 450 451 452
}

static void
test_commit_changes_after_opacity_set_layer_destroy(struct test_context *ctx)
{
453
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
454 455
	struct ivi_layout_layer *ivilayer;

456
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
457 458
	iassert(ivilayer != NULL);

459
	iassert(lyt->layer_set_opacity(
460
		    ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
461 462
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
463 464 465 466 467
}

static void
test_commit_changes_after_orientation_set_layer_destroy(struct test_context *ctx)
{
468
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
469 470
	struct ivi_layout_layer *ivilayer;

471
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
472 473
	iassert(ivilayer != NULL);

474
	iassert(lyt->layer_set_orientation(
475
		    ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
476 477
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
478 479 480 481 482
}

static void
test_commit_changes_after_source_rectangle_set_layer_destroy(struct test_context *ctx)
{
483
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
484 485
	struct ivi_layout_layer *ivilayer;

486
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
487 488
	iassert(ivilayer != NULL);

489
	iassert(lyt->layer_set_source_rectangle(
490
		    ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
491 492
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
493 494 495 496 497
}

static void
test_commit_changes_after_destination_rectangle_set_layer_destroy(struct test_context *ctx)
{
498
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
499 500
	struct ivi_layout_layer *ivilayer;

501
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
502 503
	iassert(ivilayer != NULL);

504
	iassert(lyt->layer_set_destination_rectangle(
505
		    ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
506 507
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
508 509 510 511 512
}

static void
test_layer_create_duplicate(struct test_context *ctx)
{
513
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
514 515 516
	struct ivi_layout_layer *ivilayer;
	struct ivi_layout_layer *duplicatelayer;

517
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
518 519 520 521 522
	iassert(ivilayer != NULL);

	if (ivilayer != NULL)
		iassert(ivilayer->ref_count == 1);

523
	duplicatelayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
524 525 526 527 528
	iassert(ivilayer == duplicatelayer);

	if (ivilayer != NULL)
		iassert(ivilayer->ref_count == 2);

529
	lyt->layer_destroy(ivilayer);
530 531 532 533

	if (ivilayer != NULL)
		iassert(ivilayer->ref_count == 1);

534
	lyt->layer_destroy(ivilayer);
535 536 537 538 539
}

static void
test_get_layer_after_destory_layer(struct test_context *ctx)
{
540
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
541 542
	struct ivi_layout_layer *ivilayer;

543
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
544 545
	iassert(ivilayer != NULL);

546
	lyt->layer_destroy(ivilayer);
547

548
	ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
549 550 551
	iassert(ivilayer == NULL);
}

552 553 554 555
static void
test_screen_render_order(struct test_context *ctx)
{
#define LAYER_NUM (3)
556
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
557
	struct weston_output *output;
558 559 560 561 562
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	struct ivi_layout_layer **array;
	int32_t length = 0;
	uint32_t i;

563
	if (wl_list_empty(&ctx->compositor->output_list))
564 565
		return;

566
	output = wl_container_of(ctx->compositor->output_list.next, output, link);
567 568

	for (i = 0; i < LAYER_NUM; i++)
569
		ivilayers[i] = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
570

571
	iassert(lyt->screen_set_render_order(output, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
572

573
	lyt->commit_changes();
574

575
	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
576 577 578 579 580 581 582 583 584
	iassert(length == LAYER_NUM);
	for (i = 0; i < LAYER_NUM; i++)
		iassert(array[i] == ivilayers[i]);

	if (length > 0)
		free(array);

	array = NULL;

585
	iassert(lyt->screen_set_render_order(output, NULL, 0) == IVI_SUCCEEDED);
586

587
	lyt->commit_changes();
588

589
	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
590 591 592
	iassert(length == 0 && array == NULL);

	for (i = 0; i < LAYER_NUM; i++)
593
		lyt->layer_destroy(ivilayers[i]);
594 595 596 597

#undef LAYER_NUM
}

598 599 600 601
static void
test_screen_bad_render_order(struct test_context *ctx)
{
#define LAYER_NUM (3)
602
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
603
	struct weston_output *output;
604 605 606 607 608
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	struct ivi_layout_layer **array;
	int32_t length = 0;
	uint32_t i;

609
	if (wl_list_empty(&ctx->compositor->output_list))
610 611
		return;

612
	output = wl_container_of(ctx->compositor->output_list.next, output, link);
613 614

	for (i = 0; i < LAYER_NUM; i++)
615
		ivilayers[i] = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
616

617
	iassert(lyt->screen_set_render_order(NULL, ivilayers, LAYER_NUM) == IVI_FAILED);
618

619
	lyt->commit_changes();
620

621
	iassert(lyt->get_layers_on_screen(NULL, &length, &array) == IVI_FAILED);
622 623
	iassert(lyt->get_layers_on_screen(output, NULL, &array) == IVI_FAILED);
	iassert(lyt->get_layers_on_screen(output, &length, NULL) == IVI_FAILED);
624 625

	for (i = 0; i < LAYER_NUM; i++)
626
		lyt->layer_destroy(ivilayers[i]);
627 628 629 630 631 632 633 634 635

#undef LAYER_NUM
}

static void
test_commit_changes_after_render_order_set_layer_destroy(
	struct test_context *ctx)
{
#define LAYER_NUM (3)
636
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
637
	struct weston_output *output;
638 639 640
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	uint32_t i;

641
	if (wl_list_empty(&ctx->compositor->output_list))
642 643
		return;

644
	output = wl_container_of(ctx->compositor->output_list.next, output, link);
645 646

	for (i = 0; i < LAYER_NUM; i++)
647
		ivilayers[i] = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
648

649
	iassert(lyt->screen_set_render_order(output, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
650

651
	lyt->layer_destroy(ivilayers[1]);
652

653
	lyt->commit_changes();
654

655 656
	lyt->layer_destroy(ivilayers[0]);
	lyt->layer_destroy(ivilayers[2]);
657 658 659
#undef LAYER_NUM
}

660
static void
661
test_layer_properties_changed_notification_callback(struct wl_listener *listener, void *data)
662
{
663 664 665
	struct test_context *ctx =
			container_of(listener, struct test_context,
					layer_property_changed);
666
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
667 668
	struct ivi_layout_layer *ivilayer = data;
	const struct ivi_layout_layer_properties *prop = lyt->get_properties_of_layer(ivilayer);
669

670
	iassert(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
671 672 673
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);

674
	if (lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
675 676 677 678 679 680 681
	    prop->source_width == 200 && prop->source_height == 300)
		ctx->user_flags = 1;
}

static void
test_layer_properties_changed_notification(struct test_context *ctx)
{
682
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
683 684 685 686
	struct ivi_layout_layer *ivilayer;

	ctx->user_flags = 0;

687
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
688

689 690 691
	ctx->layer_property_changed.notify = test_layer_properties_changed_notification_callback;

	iassert(lyt->layer_add_listener(ivilayer, &ctx->layer_property_changed) == IVI_SUCCEEDED);
692

693
	lyt->commit_changes();
694 695 696

	iassert(ctx->user_flags == 0);

697
	iassert(lyt->layer_set_destination_rectangle(
698 699
		ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);

700
	lyt->commit_changes();
701 702 703 704

	iassert(ctx->user_flags == 1);

	ctx->user_flags = 0;
705
	iassert(lyt->layer_set_destination_rectangle(
706 707
		ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);

708
	lyt->commit_changes();
709 710 711

	iassert(ctx->user_flags == 0);

712 713
	// remove layer property changed listener.
	wl_list_remove(&ctx->layer_property_changed.link);
714 715

	ctx->user_flags = 0;
716
	lyt->commit_changes();
717 718 719

	iassert(ctx->user_flags == 0);

720
	lyt->layer_destroy(ivilayer);
721 722 723
}

static void
724
test_layer_create_notification_callback(struct wl_listener *listener, void *data)
725
{
726 727 728
	struct test_context *ctx =
			container_of(listener, struct test_context,
					layer_created);
729
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
730
	struct ivi_layout_layer *ivilayer = data;
731
	const struct ivi_layout_layer_properties *prop = lyt->get_properties_of_layer(ivilayer);
732

733
	iassert(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
734 735 736
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);

737
	if (lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
738 739 740 741 742 743 744 745
	    prop->source_width == 200 && prop->source_height == 300)
		ctx->user_flags = 1;
}

static void
test_layer_create_notification(struct test_context *ctx)
{
#define LAYER_NUM (2)
746
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
747 748 749 750
	static const uint32_t layers[LAYER_NUM] = {IVI_TEST_LAYER_ID(0), IVI_TEST_LAYER_ID(1)};
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};

	ctx->user_flags = 0;
751
	ctx->layer_created.notify = test_layer_create_notification_callback;
752

753
	iassert(lyt->add_listener_create_layer(&ctx->layer_created) == IVI_SUCCEEDED);
754
	ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300);
755 756 757 758

	iassert(ctx->user_flags == 1);

	ctx->user_flags = 0;
759 760
	// remove layer created listener.
	wl_list_remove(&ctx->layer_created.link);
761

762
	ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 400, 500);
763 764 765

	iassert(ctx->user_flags == 0);

766 767
	lyt->layer_destroy(ivilayers[0]);
	lyt->layer_destroy(ivilayers[1]);
768 769 770 771
#undef LAYER_NUM
}

static void
772
test_layer_remove_notification_callback(struct wl_listener *listener, void *data)
773
{
774 775 776
	struct test_context *ctx =
			container_of(listener, struct test_context,
					layer_removed);
777
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
778
	struct ivi_layout_layer *ivilayer = data;
779
	const struct ivi_layout_layer_properties *prop =
780
		lyt->get_properties_of_layer(ivilayer);
781

782
	iassert(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
783 784 785
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);

786
	if (lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
787 788 789 790 791 792 793 794
	    prop->source_width == 200 && prop->source_height == 300)
		ctx->user_flags = 1;
}

static void
test_layer_remove_notification(struct test_context *ctx)
{
#define LAYER_NUM (2)
795
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
796 797 798 799
	static const uint32_t layers[LAYER_NUM] = {IVI_TEST_LAYER_ID(0), IVI_TEST_LAYER_ID(1)};
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};

	ctx->user_flags = 0;
800
	ctx->layer_removed.notify = test_layer_remove_notification_callback;
801

802
	ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300);
803
	iassert(lyt->add_listener_remove_layer(&ctx->layer_removed) == IVI_SUCCEEDED);
804
	lyt->layer_destroy(ivilayers[0]);
805 806 807 808

	iassert(ctx->user_flags == 1);

	ctx->user_flags = 0;
809
	ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 250, 350);
810 811 812

	// remove layer property changed listener.
	wl_list_remove(&ctx->layer_removed.link);
813
	lyt->layer_destroy(ivilayers[1]);
814 815 816 817 818

	iassert(ctx->user_flags == 0);
#undef LAYER_NUM
}

819
static void
820
test_layer_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
821 822 823 824 825 826
{
}

static void
test_layer_bad_properties_changed_notification(struct test_context *ctx)
{
827
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
828 829
	struct ivi_layout_layer *ivilayer;

830
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
831

832 833 834 835
	ctx->layer_property_changed.notify = test_layer_bad_properties_changed_notification_callback;

	iassert(lyt->layer_add_listener(NULL, &ctx->layer_property_changed) == IVI_FAILED);
	iassert(lyt->layer_add_listener(ivilayer, NULL) == IVI_FAILED);
836

837
	lyt->layer_destroy(ivilayer);
838 839 840 841 842
}

static void
test_surface_bad_configure_notification(struct test_context *ctx)
{
843
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
844

845
	iassert(lyt->add_listener_configure_surface(NULL) == IVI_FAILED);
846 847 848 849 850
}

static void
test_layer_bad_create_notification(struct test_context *ctx)
{
851
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
852

853
	iassert(lyt->add_listener_create_layer(NULL) == IVI_FAILED);
854 855 856 857 858
}

static void
test_surface_bad_create_notification(struct test_context *ctx)
{
859
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
860

861
	iassert(lyt->add_listener_create_surface(NULL) == IVI_FAILED);
862 863 864 865 866
}

static void
test_layer_bad_remove_notification(struct test_context *ctx)
{
867
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
868

869
	iassert(lyt->add_listener_remove_layer(NULL) == IVI_FAILED);
870 871 872 873 874
}

static void
test_surface_bad_remove_notification(struct test_context *ctx)
{
875
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
876

877
	iassert(lyt->add_listener_remove_surface(NULL) == IVI_FAILED);
878 879
}

880 881 882 883 884 885 886 887
/************************ tests end ********************************/

static void
run_internal_tests(void *data)
{
	struct test_context *ctx = data;

	test_surface_bad_visibility(ctx);
888 889 890 891
	test_surface_bad_destination_rectangle(ctx);
	test_surface_bad_orientation(ctx);
	test_surface_bad_source_rectangle(ctx);
	test_surface_bad_properties(ctx);
892

893 894 895 896 897 898 899 900
	test_layer_create(ctx);
	test_layer_visibility(ctx);
	test_layer_opacity(ctx);
	test_layer_orientation(ctx);
	test_layer_dimension(ctx);
	test_layer_position(ctx);
	test_layer_destination_rectangle(ctx);
	test_layer_source_rectangle(ctx);
901 902 903 904 905 906 907 908 909 910 911 912 913 914
	test_layer_bad_remove(ctx);
	test_layer_bad_visibility(ctx);
	test_layer_bad_opacity(ctx);
	test_layer_bad_destination_rectangle(ctx);
	test_layer_bad_orientation(ctx);
	test_layer_bad_source_rectangle(ctx);
	test_layer_bad_properties(ctx);
	test_commit_changes_after_visibility_set_layer_destroy(ctx);
	test_commit_changes_after_opacity_set_layer_destroy(ctx);
	test_commit_changes_after_orientation_set_layer_destroy(ctx);
	test_commit_changes_after_source_rectangle_set_layer_destroy(ctx);
	test_commit_changes_after_destination_rectangle_set_layer_destroy(ctx);
	test_layer_create_duplicate(ctx);
	test_get_layer_after_destory_layer(ctx);
915

916
	test_screen_render_order(ctx);
917 918 919
	test_screen_bad_render_order(ctx);
	test_commit_changes_after_render_order_set_layer_destroy(ctx);

920 921 922
	test_layer_properties_changed_notification(ctx);
	test_layer_create_notification(ctx);
	test_layer_remove_notification(ctx);
923 924 925 926 927 928
	test_layer_bad_properties_changed_notification(ctx);
	test_surface_bad_configure_notification(ctx);
	test_layer_bad_create_notification(ctx);
	test_surface_bad_create_notification(ctx);
	test_layer_bad_remove_notification(ctx);
	test_surface_bad_remove_notification(ctx);
929

930 931 932 933 934 935 936
	weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
	free(ctx);
}

int
controller_module_init(struct weston_compositor *compositor,
		       int *argc, char *argv[],
937
		       const struct ivi_layout_interface *iface,
938 939 940 941 942
		       size_t iface_version);

WL_EXPORT int
controller_module_init(struct weston_compositor *compositor,
		       int *argc, char *argv[],
943
		       const struct ivi_layout_interface *iface,
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
		       size_t iface_version)
{
	struct wl_event_loop *loop;
	struct test_context *ctx;

	/* strict check, since this is an internal test module */
	if (iface_version != sizeof(*iface)) {
		weston_log("fatal: controller interface mismatch\n");
		return -1;
	}

	ctx = zalloc(sizeof(*ctx));
	if (!ctx)
		return -1;

	ctx->compositor = compositor;
960
	ctx->layout_interface = iface;
961 962 963 964 965 966

	loop = wl_display_get_event_loop(compositor->wl_display);
	wl_event_loop_add_idle(loop, run_internal_tests, ctx);

	return 0;
}