ivi-layout-internal-test.c 28.3 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

35
#include <libweston/libweston.h>
36
#include "compositor/weston.h"
37
#include "ivi-shell/ivi-layout-export.h"
38
#include "ivi-shell/ivi-layout-private.h"
39
#include "ivi-test.h"
40
#include "shared/helpers.h"
41 42 43

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

	struct wl_listener layer_property_changed;
48
	struct wl_listener layer_created;
49
	struct wl_listener layer_removed;
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 76
};

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)
{
77
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
78

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

81
	lyt->commit_changes();
82 83
}

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

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

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

97
	iassert(lyt->surface_set_source_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
98 99 100 101 102
}

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

105
	iassert(lyt->get_properties_of_surface(NULL) == NULL);
106 107
}

108 109 110
static void
test_layer_create(struct test_context *ctx)
{
111
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
112 113 114 115 116
	uint32_t id1;
	uint32_t id2;
	struct ivi_layout_layer *ivilayer;
	struct ivi_layout_layer *new_ivilayer;

117
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
118 119
	iassert(ivilayer != NULL);

120
	iassert(IVI_TEST_LAYER_ID(0) == lyt->get_id_of_layer(ivilayer));
121

122
	new_ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
123 124
	iassert(ivilayer == new_ivilayer);

125 126
	id1 = lyt->get_id_of_layer(ivilayer);
	id2 = lyt->get_id_of_layer(new_ivilayer);
127 128
	iassert(id1 == id2);

129 130
	lyt->layer_destroy(ivilayer);
	iassert(lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0)) == NULL);
131 132 133 134 135
}

static void
test_layer_visibility(struct test_context *ctx)
{
136
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
137 138 139
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

140
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
141 142
	iassert(ivilayer != NULL);

143 144 145
	prop = lyt->get_properties_of_layer(ivilayer);

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

147
	iassert(lyt->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
148

149
	iassert(prop->visibility == false);
150

151
	lyt->commit_changes();
152 153 154

	iassert(prop->visibility == true);

155
	lyt->layer_destroy(ivilayer);
156 157 158 159 160
}

static void
test_layer_opacity(struct test_context *ctx)
{
161
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
162 163 164
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

165
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
166 167
	iassert(ivilayer != NULL);

168 169
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->opacity == wl_fixed_from_double(1.0));
170

171
	iassert(lyt->layer_set_opacity(
172 173
		ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);

174
	iassert(prop->opacity == wl_fixed_from_double(1.0));
175

176
	lyt->commit_changes();
177 178 179

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

180
	lyt->layer_destroy(ivilayer);
181 182 183 184 185
}

static void
test_layer_dimension(struct test_context *ctx)
{
186
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
187 188 189
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

190
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
191 192
	iassert(ivilayer != NULL);

193 194 195
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
196

197 198
	iassert(lyt->layer_set_destination_rectangle(ivilayer, prop->dest_x, prop->dest_y,
			400, 600) == IVI_SUCCEEDED);
199

200 201
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
202

203
	lyt->commit_changes();
204 205 206 207

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

208
	lyt->layer_destroy(ivilayer);
209 210 211 212 213
}

static void
test_layer_position(struct test_context *ctx)
{
214
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
215 216 217
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

218
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
219 220
	iassert(ivilayer != NULL);

221 222 223
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);
224

225 226
	iassert(lyt->layer_set_destination_rectangle(ivilayer, 20, 30,
			prop->dest_width, prop->dest_height) == IVI_SUCCEEDED);
227

228 229
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);
230

231
	lyt->commit_changes();
232

233
	prop = lyt->get_properties_of_layer(ivilayer);
234 235 236
	iassert(prop->dest_x == 20);
	iassert(prop->dest_y == 30);

237
	lyt->layer_destroy(ivilayer);
238 239 240 241 242
}

static void
test_layer_destination_rectangle(struct test_context *ctx)
{
243
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
244 245 246
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

247
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
248 249
	iassert(ivilayer != NULL);

250
	prop = lyt->get_properties_of_layer(ivilayer);
251 252 253 254 255
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);

256
	iassert(lyt->layer_set_destination_rectangle(
257 258
		ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);

259
	prop = lyt->get_properties_of_layer(ivilayer);
260 261 262 263 264
	iassert(prop->dest_width == 200);
	iassert(prop->dest_height == 300);
	iassert(prop->dest_x == 0);
	iassert(prop->dest_y == 0);

265
	lyt->commit_changes();
266 267 268 269 270 271

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

272
	lyt->layer_destroy(ivilayer);
273 274 275 276 277
}

static void
test_layer_source_rectangle(struct test_context *ctx)
{
278
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
279 280 281
	struct ivi_layout_layer *ivilayer;
	const struct ivi_layout_layer_properties *prop;

282
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
283 284
	iassert(ivilayer != NULL);

285
	prop = lyt->get_properties_of_layer(ivilayer);
286 287 288 289 290
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);
	iassert(prop->source_x == 0);
	iassert(prop->source_y == 0);

291
	iassert(lyt->layer_set_source_rectangle(
292 293
		ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);

294
	prop = lyt->get_properties_of_layer(ivilayer);
295 296 297 298 299
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);
	iassert(prop->source_x == 0);
	iassert(prop->source_y == 0);

300
	lyt->commit_changes();
301

302
	prop = lyt->get_properties_of_layer(ivilayer);
303 304 305 306 307
	iassert(prop->source_width == 400);
	iassert(prop->source_height == 600);
	iassert(prop->source_x == 20);
	iassert(prop->source_y == 30);

308
	lyt->layer_destroy(ivilayer);
309 310
}

311 312 313
static void
test_layer_bad_remove(struct test_context *ctx)
{
314 315
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
	lyt->layer_destroy(NULL);
316 317 318 319 320
}

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

323
	iassert(lyt->layer_set_visibility(NULL, true) == IVI_FAILED);
324

325
	lyt->commit_changes();
326 327 328 329 330
}

static void
test_layer_bad_opacity(struct test_context *ctx)
{
331
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
332
	struct ivi_layout_layer *ivilayer;
333
	const struct ivi_layout_layer_properties *prop;
334

335
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
336 337
	iassert(ivilayer != NULL);

338
	iassert(lyt->layer_set_opacity(
339 340
		NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);

341
	iassert(lyt->layer_set_opacity(
342 343
		ivilayer, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);

344
	iassert(lyt->layer_set_opacity(
345 346
		ivilayer, wl_fixed_from_double(-1)) == IVI_FAILED);

347
	lyt->commit_changes();
348

349 350
	prop = lyt->get_properties_of_layer(ivilayer);
	iassert(prop->opacity == wl_fixed_from_double(0.3));
351

352
	iassert(lyt->layer_set_opacity(
353 354
		ivilayer, wl_fixed_from_double(1.1)) == IVI_FAILED);

355
	lyt->commit_changes();
356

357
	iassert(prop->opacity == wl_fixed_from_double(0.3));
358

359
	iassert(lyt->layer_set_opacity(
360 361
		NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);

362
	lyt->commit_changes();
363

364
	lyt->layer_destroy(ivilayer);
365 366 367 368 369
}

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

372
	iassert(lyt->layer_set_destination_rectangle(
373 374 375 376 377 378
		NULL, 20, 30, 200, 300) == IVI_FAILED);
}

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

381
	iassert(lyt->layer_set_source_rectangle(
382 383 384 385 386 387
		NULL, 20, 30, 200, 300) == IVI_FAILED);
}

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

390
	iassert(lyt->get_properties_of_layer(NULL) == NULL);
391 392 393 394 395
}

static void
test_commit_changes_after_visibility_set_layer_destroy(struct test_context *ctx)
{
396
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
397 398
	struct ivi_layout_layer *ivilayer;

399
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
400 401
	iassert(ivilayer != NULL);

402 403 404
	iassert(lyt->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
405 406 407 408 409
}

static void
test_commit_changes_after_opacity_set_layer_destroy(struct test_context *ctx)
{
410
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
411 412
	struct ivi_layout_layer *ivilayer;

413
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
414 415
	iassert(ivilayer != NULL);

416
	iassert(lyt->layer_set_opacity(
417
		    ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
418 419
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
420 421 422 423 424
}

static void
test_commit_changes_after_source_rectangle_set_layer_destroy(struct test_context *ctx)
{
425
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
426 427
	struct ivi_layout_layer *ivilayer;

428
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
429 430
	iassert(ivilayer != NULL);

431
	iassert(lyt->layer_set_source_rectangle(
432
		    ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
433 434
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
435 436 437 438 439
}

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

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

446
	iassert(lyt->layer_set_destination_rectangle(
447
		    ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
448 449
	lyt->layer_destroy(ivilayer);
	lyt->commit_changes();
450 451 452 453 454
}

static void
test_layer_create_duplicate(struct test_context *ctx)
{
455
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
456 457 458
	struct ivi_layout_layer *ivilayer;
	struct ivi_layout_layer *duplicatelayer;

459
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
460 461 462 463 464
	iassert(ivilayer != NULL);

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

465
	duplicatelayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
466 467 468 469 470
	iassert(ivilayer == duplicatelayer);

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

471
	lyt->layer_destroy(ivilayer);
472 473 474 475

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

476
	lyt->layer_destroy(ivilayer);
477 478 479 480 481
}

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

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

488
	lyt->layer_destroy(ivilayer);
489

490
	ivilayer = lyt->get_layer_from_id(IVI_TEST_LAYER_ID(0));
491 492 493
	iassert(ivilayer == NULL);
}

494 495 496 497
static void
test_screen_render_order(struct test_context *ctx)
{
#define LAYER_NUM (3)
498
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
499
	struct weston_output *output;
500 501 502 503 504
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	struct ivi_layout_layer **array;
	int32_t length = 0;
	uint32_t i;

505
	if (!iassert(!wl_list_empty(&ctx->compositor->output_list)))
506 507
		return;

508
	output = wl_container_of(ctx->compositor->output_list.next, output, link);
509 510

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

513
	iassert(lyt->screen_set_render_order(output, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
514

515
	lyt->commit_changes();
516

517
	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
518 519 520 521 522 523 524 525 526
	iassert(length == LAYER_NUM);
	for (i = 0; i < LAYER_NUM; i++)
		iassert(array[i] == ivilayers[i]);

	if (length > 0)
		free(array);

	array = NULL;

527
	iassert(lyt->screen_set_render_order(output, NULL, 0) == IVI_SUCCEEDED);
528

529
	lyt->commit_changes();
530

531
	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
532 533 534
	iassert(length == 0 && array == NULL);

	for (i = 0; i < LAYER_NUM; i++)
535
		lyt->layer_destroy(ivilayers[i]);
536 537 538 539

#undef LAYER_NUM
}

540 541 542 543
static void
test_screen_bad_render_order(struct test_context *ctx)
{
#define LAYER_NUM (3)
544
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
545
	struct weston_output *output;
546 547 548 549 550
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	struct ivi_layout_layer **array;
	int32_t length = 0;
	uint32_t i;

551
	if (!iassert(!wl_list_empty(&ctx->compositor->output_list)))
552 553
		return;

554
	output = wl_container_of(ctx->compositor->output_list.next, output, link);
555 556

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

559
	iassert(lyt->screen_set_render_order(NULL, ivilayers, LAYER_NUM) == IVI_FAILED);
560

561
	lyt->commit_changes();
562

563
	iassert(lyt->get_layers_on_screen(NULL, &length, &array) == IVI_FAILED);
564 565
	iassert(lyt->get_layers_on_screen(output, NULL, &array) == IVI_FAILED);
	iassert(lyt->get_layers_on_screen(output, &length, NULL) == IVI_FAILED);
566 567

	for (i = 0; i < LAYER_NUM; i++)
568
		lyt->layer_destroy(ivilayers[i]);
569 570 571 572

#undef LAYER_NUM
}

573 574 575 576 577 578 579 580 581 582 583
static void
test_screen_add_layers(struct test_context *ctx)
{
#define LAYER_NUM (3)
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
	struct weston_output *output;
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	struct ivi_layout_layer **array;
	int32_t length = 0;
	uint32_t i;

584
	if (!iassert(!wl_list_empty(&ctx->compositor->output_list)))
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
		return;

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

	for (i = 0; i < LAYER_NUM; i++) {
		ivilayers[i] = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
		iassert(lyt->screen_add_layer(output, ivilayers[i]) == IVI_SUCCEEDED);
	}

	lyt->commit_changes();

	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
	iassert(length == LAYER_NUM);
	for (i = 0; i < (uint32_t)length; i++)
		iassert(array[i] == ivilayers[i]);

	if (length > 0)
		free(array);

	array = NULL;

	iassert(lyt->screen_set_render_order(output, NULL, 0) == IVI_SUCCEEDED);
	for (i = LAYER_NUM; i-- > 0;)
		iassert(lyt->screen_add_layer(output, ivilayers[i]) == IVI_SUCCEEDED);

	lyt->commit_changes();

	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
	iassert(length == LAYER_NUM);
	for (i = 0; i < (uint32_t)length; i++)
		iassert(array[i] == ivilayers[LAYER_NUM - (i + 1)]);

	if (length > 0)
		free(array);

	for (i = 0; i < LAYER_NUM; i++)
		lyt->layer_destroy(ivilayers[i]);

#undef LAYER_NUM
}

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
static void
test_screen_remove_layer(struct test_context *ctx)
{
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
	struct ivi_layout_layer *ivilayer;
	struct weston_output *output;
	struct ivi_layout_layer **array;
	int32_t length = 0;

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

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

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

	iassert(lyt->screen_add_layer(output, ivilayer) == IVI_SUCCEEDED);
	lyt->commit_changes();

	iassert(lyt->get_layers_on_screen(output, &length, &array) == IVI_SUCCEEDED);
	iassert(length == 1);
	iassert(array[0] == ivilayer);

	iassert(lyt->screen_remove_layer(output, ivilayer) == IVI_SUCCEEDED);
	lyt->commit_changes();

	if (length > 0)
		free(array);

	array = NULL;

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

	lyt->layer_destroy(ivilayer);
}

static void
test_screen_bad_remove_layer(struct test_context *ctx)
{
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
	struct ivi_layout_layer *ivilayer;
	struct weston_output *output;

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

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

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

	iassert(lyt->screen_remove_layer(NULL, ivilayer) == IVI_FAILED);
	lyt->commit_changes();

	iassert(lyt->screen_remove_layer(output, NULL) == IVI_FAILED);
	lyt->commit_changes();

	iassert(lyt->screen_remove_layer(NULL, NULL) == IVI_FAILED);
	lyt->commit_changes();

	lyt->layer_destroy(ivilayer);
}


693 694 695 696 697
static void
test_commit_changes_after_render_order_set_layer_destroy(
	struct test_context *ctx)
{
#define LAYER_NUM (3)
698
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
699
	struct weston_output *output;
700 701 702
	struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
	uint32_t i;

703
	if (!iassert(!wl_list_empty(&ctx->compositor->output_list)))
704 705
		return;

706
	output = wl_container_of(ctx->compositor->output_list.next, output, link);
707 708

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

711
	iassert(lyt->screen_set_render_order(output, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
712

713
	lyt->layer_destroy(ivilayers[1]);
714

715
	lyt->commit_changes();
716

717 718
	lyt->layer_destroy(ivilayers[0]);
	lyt->layer_destroy(ivilayers[2]);
719 720 721
#undef LAYER_NUM
}

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

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

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

static void
test_layer_properties_changed_notification(struct test_context *ctx)
{
744
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
745 746 747 748
	struct ivi_layout_layer *ivilayer;

	ctx->user_flags = 0;

749
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
750

751 752 753
	ctx->layer_property_changed.notify = test_layer_properties_changed_notification_callback;

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

755
	lyt->commit_changes();
756 757 758

	iassert(ctx->user_flags == 0);

759
	iassert(lyt->layer_set_destination_rectangle(
760 761
		ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);

762
	lyt->commit_changes();
763 764 765 766

	iassert(ctx->user_flags == 1);

	ctx->user_flags = 0;
767
	iassert(lyt->layer_set_destination_rectangle(
768 769
		ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);

770
	lyt->commit_changes();
771 772 773

	iassert(ctx->user_flags == 0);

774 775
	// remove layer property changed listener.
	wl_list_remove(&ctx->layer_property_changed.link);
776 777

	ctx->user_flags = 0;
778
	lyt->commit_changes();
779 780 781

	iassert(ctx->user_flags == 0);

782
	lyt->layer_destroy(ivilayer);
783 784 785
}

static void
786
test_layer_create_notification_callback(struct wl_listener *listener, void *data)
787
{
788 789 790
	struct test_context *ctx =
			container_of(listener, struct test_context,
					layer_created);
791
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
792
	struct ivi_layout_layer *ivilayer = data;
793
	const struct ivi_layout_layer_properties *prop = lyt->get_properties_of_layer(ivilayer);
794

795
	iassert(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
796 797 798
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);

799
	if (lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
800 801 802 803 804 805 806 807
	    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)
808
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
809 810 811 812
	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;
813
	ctx->layer_created.notify = test_layer_create_notification_callback;
814

815
	iassert(lyt->add_listener_create_layer(&ctx->layer_created) == IVI_SUCCEEDED);
816
	ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300);
817 818 819 820

	iassert(ctx->user_flags == 1);

	ctx->user_flags = 0;
821 822
	// remove layer created listener.
	wl_list_remove(&ctx->layer_created.link);
823

824
	ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 400, 500);
825 826 827

	iassert(ctx->user_flags == 0);

828 829
	lyt->layer_destroy(ivilayers[0]);
	lyt->layer_destroy(ivilayers[1]);
830 831 832 833
#undef LAYER_NUM
}

static void
834
test_layer_remove_notification_callback(struct wl_listener *listener, void *data)
835
{
836 837 838
	struct test_context *ctx =
			container_of(listener, struct test_context,
					layer_removed);
839
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
840
	struct ivi_layout_layer *ivilayer = data;
841
	const struct ivi_layout_layer_properties *prop =
842
		lyt->get_properties_of_layer(ivilayer);
843

844
	iassert(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
845 846 847
	iassert(prop->source_width == 200);
	iassert(prop->source_height == 300);

848
	if (lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
849 850 851 852 853 854 855 856
	    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)
857
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
858 859 860 861
	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;
862
	ctx->layer_removed.notify = test_layer_remove_notification_callback;
863

864
	ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300);
865
	iassert(lyt->add_listener_remove_layer(&ctx->layer_removed) == IVI_SUCCEEDED);
866
	lyt->layer_destroy(ivilayers[0]);
867 868 869 870

	iassert(ctx->user_flags == 1);

	ctx->user_flags = 0;
871
	ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 250, 350);
872 873 874

	// remove layer property changed listener.
	wl_list_remove(&ctx->layer_removed.link);
875
	lyt->layer_destroy(ivilayers[1]);
876 877 878 879 880

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

881
static void
882
test_layer_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
883 884 885 886 887 888
{
}

static void
test_layer_bad_properties_changed_notification(struct test_context *ctx)
{
889
	const struct ivi_layout_interface *lyt = ctx->layout_interface;
890 891
	struct ivi_layout_layer *ivilayer;

892
	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
893

894 895 896 897
	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);
898

899
	lyt->layer_destroy(ivilayer);
900 901 902 903 904
}

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

907
	iassert(lyt->add_listener_configure_surface(NULL) == IVI_FAILED);
908 909 910 911 912
}

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

915
	iassert(lyt->add_listener_create_layer(NULL) == IVI_FAILED);
916 917 918 919 920
}

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

923
	iassert(lyt->add_listener_create_surface(NULL) == IVI_FAILED);
924 925 926 927 928
}

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

931
	iassert(lyt->add_listener_remove_layer(NULL) == IVI_FAILED);
932 933 934 935 936
}

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

939
	iassert(lyt->add_listener_remove_surface(NULL) == IVI_FAILED);
940 941
}

942 943 944 945 946 947 948 949
/************************ tests end ********************************/

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

	test_surface_bad_visibility(ctx);
950 951 952
	test_surface_bad_destination_rectangle(ctx);
	test_surface_bad_source_rectangle(ctx);
	test_surface_bad_properties(ctx);
953

954 955 956 957 958 959 960
	test_layer_create(ctx);
	test_layer_visibility(ctx);
	test_layer_opacity(ctx);
	test_layer_dimension(ctx);
	test_layer_position(ctx);
	test_layer_destination_rectangle(ctx);
	test_layer_source_rectangle(ctx);
961 962 963 964 965 966 967 968 969 970 971 972
	test_layer_bad_remove(ctx);
	test_layer_bad_visibility(ctx);
	test_layer_bad_opacity(ctx);
	test_layer_bad_destination_rectangle(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_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);
973

974
	test_screen_render_order(ctx);
975
	test_screen_bad_render_order(ctx);
976
	test_screen_add_layers(ctx);
977 978
	test_screen_remove_layer(ctx);
	test_screen_bad_remove_layer(ctx);
979 980
	test_commit_changes_after_render_order_set_layer_destroy(ctx);

981 982 983
	test_layer_properties_changed_notification(ctx);
	test_layer_create_notification(ctx);
	test_layer_remove_notification(ctx);
984 985 986 987 988 989
	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);
990

991 992 993 994 995
	weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
	free(ctx);
}

WL_EXPORT int
996 997
wet_module_init(struct weston_compositor *compositor,
		       int *argc, char *argv[])
998 999 1000
{
	struct wl_event_loop *loop;
	struct test_context *ctx;
1001 1002 1003
	const struct ivi_layout_interface *iface;

	iface = ivi_layout_get_api(compositor);
1004

1005 1006
	if (!iface) {
		weston_log("fatal: cannot use ivi_layout_interface.\n");
1007 1008 1009 1010 1011 1012 1013 1014
		return -1;
	}

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

	ctx->compositor = compositor;
1015
	ctx->layout_interface = iface;
1016 1017 1018 1019 1020 1021

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

	return 0;
}