blob: b82e9cbbc6eb094321abad479571efcbec5020bf [file] [log] [blame]
Pekka Paalanen46804ca2015-03-27 11:55:21 +02001/*
2 * Copyright © 2013 DENSO CORPORATION
3 * Copyright © 2015 Collabora, Ltd.
4 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07005 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
Pekka Paalanen46804ca2015-03-27 11:55:21 +020012 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070013 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
Pekka Paalanen46804ca2015-03-27 11:55:21 +020025 */
26
27#include "config.h"
28
29#include <unistd.h>
30#include <signal.h>
31#include <string.h>
32#include <stdbool.h>
33
Jon Cruz4678bab2015-06-15 15:37:07 -070034#include "src/compositor.h"
35#include "ivi-shell/ivi-layout-export.h"
Nobuhiko Tanibata17d44942015-06-22 15:35:12 +090036#include "ivi-shell/ivi-layout-private.h"
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +090037#include "ivi-test.h"
Pekka Paalanen46804ca2015-03-27 11:55:21 +020038
39struct test_context {
40 struct weston_compositor *compositor;
41 const struct ivi_controller_interface *controller_interface;
42};
43
44static void
45iassert_fail(const char *cond, const char *file, int line,
46 const char *func, struct test_context *ctx)
47{
48 weston_log("Assert failure in %s:%d, %s: '%s'\n",
49 file, line, func, cond);
50 weston_compositor_exit_with_code(ctx->compositor, EXIT_FAILURE);
51}
52
53#define iassert(cond) ({ \
54 bool b_ = (cond); \
55 if (!b_) \
56 iassert_fail(#cond, __FILE__, __LINE__, __func__, ctx); \
57 b_; \
58})
59
60/************************ tests begin ******************************/
61
62/*
63 * These are all internal ivi_layout API tests that do not require
64 * any client objects.
65 */
Pekka Paalanen46804ca2015-03-27 11:55:21 +020066static void
67test_surface_bad_visibility(struct test_context *ctx)
68{
69 const struct ivi_controller_interface *ctl = ctx->controller_interface;
70 bool visibility;
71
72 iassert(ctl->surface_set_visibility(NULL, true) == IVI_FAILED);
73
74 ctl->commit_changes();
75
76 visibility = ctl->surface_get_visibility(NULL);
77 iassert(visibility == false);
78}
79
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +090080static void
81test_surface_bad_destination_rectangle(struct test_context *ctx)
82{
83 const struct ivi_controller_interface *ctl = ctx->controller_interface;
84
85 iassert(ctl->surface_set_destination_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
86}
87
88static void
89test_surface_bad_orientation(struct test_context *ctx)
90{
91 const struct ivi_controller_interface *ctl = ctx->controller_interface;
92
93 iassert(ctl->surface_set_orientation(NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
94
95 iassert(ctl->surface_get_orientation(NULL) == WL_OUTPUT_TRANSFORM_NORMAL);
96}
97
98static void
99test_surface_bad_dimension(struct test_context *ctx)
100{
101 const struct ivi_controller_interface *ctl = ctx->controller_interface;
102 struct ivi_layout_surface *ivisurf = NULL;
103 int32_t dest_width;
104 int32_t dest_height;
105
106 iassert(ctl->surface_set_dimension(NULL, 200, 300) == IVI_FAILED);
107
108 ctl->commit_changes();
109
110 iassert(ctl->surface_get_dimension(NULL, &dest_width, &dest_height) == IVI_FAILED);
111 iassert(ctl->surface_get_dimension(ivisurf, NULL, &dest_height) == IVI_FAILED);
112 iassert(ctl->surface_get_dimension(ivisurf, &dest_width, NULL) == IVI_FAILED);
113}
114
115static void
116test_surface_bad_position(struct test_context *ctx)
117{
118 const struct ivi_controller_interface *ctl = ctx->controller_interface;
119 struct ivi_layout_surface *ivisurf = NULL;
120 int32_t dest_x;
121 int32_t dest_y;
122
123 iassert(ctl->surface_set_position(NULL, 20, 30) == IVI_FAILED);
124
125 ctl->commit_changes();
126
127 iassert(ctl->surface_get_position(NULL, &dest_x, &dest_y) == IVI_FAILED);
128 iassert(ctl->surface_get_position(ivisurf, NULL, &dest_y) == IVI_FAILED);
129 iassert(ctl->surface_get_position(ivisurf, &dest_x, NULL) == IVI_FAILED);
130}
131
132static void
133test_surface_bad_source_rectangle(struct test_context *ctx)
134{
135 const struct ivi_controller_interface *ctl = ctx->controller_interface;
136
137 iassert(ctl->surface_set_source_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
138}
139
140static void
141test_surface_bad_properties(struct test_context *ctx)
142{
143 const struct ivi_controller_interface *ctl = ctx->controller_interface;
144
145 iassert(ctl->get_properties_of_surface(NULL) == NULL);
146}
147
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900148static void
149test_layer_create(struct test_context *ctx)
150{
151 const struct ivi_controller_interface *ctl = ctx->controller_interface;
152 uint32_t id1;
153 uint32_t id2;
154 struct ivi_layout_layer *ivilayer;
155 struct ivi_layout_layer *new_ivilayer;
156
157 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
158 iassert(ivilayer != NULL);
159
160 iassert(IVI_TEST_LAYER_ID(0) == ctl->get_id_of_layer(ivilayer));
161
162 new_ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
163 iassert(ivilayer == new_ivilayer);
164
165 id1 = ctl->get_id_of_layer(ivilayer);
166 id2 = ctl->get_id_of_layer(new_ivilayer);
167 iassert(id1 == id2);
168
169 ctl->layer_destroy(ivilayer);
170 iassert(ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0)) == NULL);
171}
172
173static void
174test_layer_visibility(struct test_context *ctx)
175{
176 const struct ivi_controller_interface *ctl = ctx->controller_interface;
177 struct ivi_layout_layer *ivilayer;
178 const struct ivi_layout_layer_properties *prop;
179
180 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
181 iassert(ivilayer != NULL);
182
183 iassert(ctl->layer_get_visibility(ivilayer) == false);
184
185 iassert(ctl->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
186
187 iassert(ctl->layer_get_visibility(ivilayer) == false);
188
189 ctl->commit_changes();
190
191 iassert(ctl->layer_get_visibility(ivilayer) == true);
192
193 prop = ctl->get_properties_of_layer(ivilayer);
194 iassert(prop->visibility == true);
195
196 ctl->layer_destroy(ivilayer);
197}
198
199static void
200test_layer_opacity(struct test_context *ctx)
201{
202 const struct ivi_controller_interface *ctl = ctx->controller_interface;
203 struct ivi_layout_layer *ivilayer;
204 const struct ivi_layout_layer_properties *prop;
205
206 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
207 iassert(ivilayer != NULL);
208
209 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(1.0));
210
211 iassert(ctl->layer_set_opacity(
212 ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
213
214 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(1.0));
215
216 ctl->commit_changes();
217
218 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.5));
219
220 prop = ctl->get_properties_of_layer(ivilayer);
221 iassert(prop->opacity == wl_fixed_from_double(0.5));
222
223 ctl->layer_destroy(ivilayer);
224}
225
226static void
227test_layer_orientation(struct test_context *ctx)
228{
229 const struct ivi_controller_interface *ctl = ctx->controller_interface;
230 struct ivi_layout_layer *ivilayer;
231 const struct ivi_layout_layer_properties *prop;
232
233 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
234 iassert(ivilayer != NULL);
235
236 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_NORMAL);
237
238 iassert(ctl->layer_set_orientation(
239 ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
240
241 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_NORMAL);
242
243 ctl->commit_changes();
244
245 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_90);
246
247 prop = ctl->get_properties_of_layer(ivilayer);
248 iassert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
249
250 ctl->layer_destroy(ivilayer);
251}
252
253static void
254test_layer_dimension(struct test_context *ctx)
255{
256 const struct ivi_controller_interface *ctl = ctx->controller_interface;
257 struct ivi_layout_layer *ivilayer;
258 const struct ivi_layout_layer_properties *prop;
259 int32_t dest_width;
260 int32_t dest_height;
261
262 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
263 iassert(ivilayer != NULL);
264
265 iassert(ctl->layer_get_dimension(
266 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
267 iassert(dest_width == 200);
268 iassert(dest_height == 300);
269
270 iassert(ctl->layer_set_dimension(ivilayer, 400, 600) == IVI_SUCCEEDED);
271
272 iassert(ctl->layer_get_dimension(
273 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
274 iassert(dest_width == 200);
275 iassert(dest_height == 300);
276
277 ctl->commit_changes();
278
279 iassert(IVI_SUCCEEDED == ctl->layer_get_dimension(
280 ivilayer, &dest_width, &dest_height));
281 iassert(dest_width == 400);
282 iassert(dest_height == 600);
283
284 prop = ctl->get_properties_of_layer(ivilayer);
285 iassert(prop->dest_width == 400);
286 iassert(prop->dest_height == 600);
287
288 ctl->layer_destroy(ivilayer);
289}
290
291static void
292test_layer_position(struct test_context *ctx)
293{
294 const struct ivi_controller_interface *ctl = ctx->controller_interface;
295 struct ivi_layout_layer *ivilayer;
296 const struct ivi_layout_layer_properties *prop;
297 int32_t dest_x;
298 int32_t dest_y;
299
300 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
301 iassert(ivilayer != NULL);
302
303 iassert(ctl->layer_get_position(
304 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
305 iassert(dest_x == 0);
306 iassert(dest_y == 0);
307
308 iassert(ctl->layer_set_position(ivilayer, 20, 30) == IVI_SUCCEEDED);
309
310 iassert(ctl->layer_get_position(
311 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
312 iassert(dest_x == 0);
313 iassert(dest_y == 0);
314
315 ctl->commit_changes();
316
317 iassert(ctl->layer_get_position(
318 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
319 iassert(dest_x == 20);
320 iassert(dest_y == 30);
321
322 prop = ctl->get_properties_of_layer(ivilayer);
323 iassert(prop->dest_x == 20);
324 iassert(prop->dest_y == 30);
325
326 ctl->layer_destroy(ivilayer);
327}
328
329static void
330test_layer_destination_rectangle(struct test_context *ctx)
331{
332 const struct ivi_controller_interface *ctl = ctx->controller_interface;
333 struct ivi_layout_layer *ivilayer;
334 const struct ivi_layout_layer_properties *prop;
335 int32_t dest_width;
336 int32_t dest_height;
337 int32_t dest_x;
338 int32_t dest_y;
339
340 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
341 iassert(ivilayer != NULL);
342
343 prop = ctl->get_properties_of_layer(ivilayer);
344 iassert(prop->dest_width == 200);
345 iassert(prop->dest_height == 300);
346 iassert(prop->dest_x == 0);
347 iassert(prop->dest_y == 0);
348
349 iassert(ctl->layer_set_destination_rectangle(
350 ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);
351
352 prop = ctl->get_properties_of_layer(ivilayer);
353 iassert(prop->dest_width == 200);
354 iassert(prop->dest_height == 300);
355 iassert(prop->dest_x == 0);
356 iassert(prop->dest_y == 0);
357
358 ctl->commit_changes();
359
360 iassert(ctl->layer_get_dimension(
361 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
362 iassert(dest_width == 400);
363 iassert(dest_height == 600);
364
365 iassert(ctl->layer_get_position(
366 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
367 iassert(dest_x == 20);
368 iassert(dest_y == 30);
369
370 prop = ctl->get_properties_of_layer(ivilayer);
371 iassert(prop->dest_width == 400);
372 iassert(prop->dest_height == 600);
373 iassert(prop->dest_x == 20);
374 iassert(prop->dest_y == 30);
375
376 ctl->layer_destroy(ivilayer);
377}
378
379static void
380test_layer_source_rectangle(struct test_context *ctx)
381{
382 const struct ivi_controller_interface *ctl = ctx->controller_interface;
383 struct ivi_layout_layer *ivilayer;
384 const struct ivi_layout_layer_properties *prop;
385
386 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
387 iassert(ivilayer != NULL);
388
389 prop = ctl->get_properties_of_layer(ivilayer);
390 iassert(prop->source_width == 200);
391 iassert(prop->source_height == 300);
392 iassert(prop->source_x == 0);
393 iassert(prop->source_y == 0);
394
395 iassert(ctl->layer_set_source_rectangle(
396 ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);
397
398 prop = ctl->get_properties_of_layer(ivilayer);
399 iassert(prop->source_width == 200);
400 iassert(prop->source_height == 300);
401 iassert(prop->source_x == 0);
402 iassert(prop->source_y == 0);
403
404 ctl->commit_changes();
405
406 prop = ctl->get_properties_of_layer(ivilayer);
407 iassert(prop->source_width == 400);
408 iassert(prop->source_height == 600);
409 iassert(prop->source_x == 20);
410 iassert(prop->source_y == 30);
411
412 ctl->layer_destroy(ivilayer);
413}
414
Nobuhiko Tanibata17d44942015-06-22 15:35:12 +0900415static void
416test_layer_bad_remove(struct test_context *ctx)
417{
418 const struct ivi_controller_interface *ctl = ctx->controller_interface;
419 ctl->layer_destroy(NULL);
420}
421
422static void
423test_layer_bad_visibility(struct test_context *ctx)
424{
425 const struct ivi_controller_interface *ctl = ctx->controller_interface;
426
427 iassert(ctl->layer_set_visibility(NULL, true) == IVI_FAILED);
428
429 ctl->commit_changes();
430
431 iassert(ctl->layer_get_visibility(NULL) == false);
432}
433
434static void
435test_layer_bad_opacity(struct test_context *ctx)
436{
437 const struct ivi_controller_interface *ctl = ctx->controller_interface;
438 struct ivi_layout_layer *ivilayer;
439
440 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
441 iassert(ivilayer != NULL);
442
443 iassert(ctl->layer_set_opacity(
444 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
445
446 iassert(ctl->layer_set_opacity(
447 ivilayer, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
448
449 iassert(ctl->layer_set_opacity(
450 ivilayer, wl_fixed_from_double(-1)) == IVI_FAILED);
451
452 ctl->commit_changes();
453
454 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.3));
455
456 iassert(ctl->layer_set_opacity(
457 ivilayer, wl_fixed_from_double(1.1)) == IVI_FAILED);
458
459 ctl->commit_changes();
460
461 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.3));
462
463 iassert(ctl->layer_set_opacity(
464 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
465
466 ctl->commit_changes();
467
468 iassert(ctl->layer_get_opacity(NULL) == wl_fixed_from_double(0.0));
469
470 ctl->layer_destroy(ivilayer);
471}
472
473static void
474test_layer_bad_destination_rectangle(struct test_context *ctx)
475{
476 const struct ivi_controller_interface *ctl = ctx->controller_interface;
477
478 iassert(ctl->layer_set_destination_rectangle(
479 NULL, 20, 30, 200, 300) == IVI_FAILED);
480}
481
482static void
483test_layer_bad_orientation(struct test_context *ctx)
484{
485 const struct ivi_controller_interface *ctl = ctx->controller_interface;
486
487 iassert(ctl->layer_set_orientation(
488 NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
489
490 ctl->commit_changes();
491
492 iassert(ctl->layer_get_orientation(NULL) == WL_OUTPUT_TRANSFORM_NORMAL);
493}
494
495static void
496test_layer_bad_dimension(struct test_context *ctx)
497{
498 const struct ivi_controller_interface *ctl = ctx->controller_interface;
499 struct ivi_layout_layer *ivilayer;
500 int32_t dest_width;
501 int32_t dest_height;
502
503 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
504 iassert(ivilayer != NULL);
505
506 iassert(ctl->layer_set_dimension(NULL, 200, 300) == IVI_FAILED);
507
508 ctl->commit_changes();
509
510 iassert(ctl->layer_get_dimension(
511 NULL, &dest_width, &dest_height) == IVI_FAILED);
512 iassert(ctl->layer_get_dimension(
513 ivilayer, NULL, &dest_height) == IVI_FAILED);
514 iassert(ctl->layer_get_dimension(
515 ivilayer, &dest_width, NULL) == IVI_FAILED);
516
517 ctl->layer_destroy(ivilayer);
518}
519
520static void
521test_layer_bad_position(struct test_context *ctx)
522{
523 const struct ivi_controller_interface *ctl = ctx->controller_interface;
524 struct ivi_layout_layer *ivilayer;
525 int32_t dest_x;
526 int32_t dest_y;
527
528 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
529 iassert(ivilayer != NULL);
530
531 iassert(ctl->layer_set_position(NULL, 20, 30) == IVI_FAILED);
532
533 ctl->commit_changes();
534
535 iassert(ctl->layer_get_position(NULL, &dest_x, &dest_y) == IVI_FAILED);
536 iassert(ctl->layer_get_position(ivilayer, NULL, &dest_y) == IVI_FAILED);
537 iassert(ctl->layer_get_position(ivilayer, &dest_x, NULL) == IVI_FAILED);
538
539 ctl->layer_destroy(ivilayer);
540}
541
542static void
543test_layer_bad_source_rectangle(struct test_context *ctx)
544{
545 const struct ivi_controller_interface *ctl = ctx->controller_interface;
546
547 iassert(ctl->layer_set_source_rectangle(
548 NULL, 20, 30, 200, 300) == IVI_FAILED);
549}
550
551static void
552test_layer_bad_properties(struct test_context *ctx)
553{
554 const struct ivi_controller_interface *ctl = ctx->controller_interface;
555
556 iassert(ctl->get_properties_of_layer(NULL) == NULL);
557}
558
559static void
560test_commit_changes_after_visibility_set_layer_destroy(struct test_context *ctx)
561{
562 const struct ivi_controller_interface *ctl = ctx->controller_interface;
563 struct ivi_layout_layer *ivilayer;
564
565 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
566 iassert(ivilayer != NULL);
567
568 iassert(ctl->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
569 ctl->layer_destroy(ivilayer);
570 ctl->commit_changes();
571}
572
573static void
574test_commit_changes_after_opacity_set_layer_destroy(struct test_context *ctx)
575{
576 const struct ivi_controller_interface *ctl = ctx->controller_interface;
577 struct ivi_layout_layer *ivilayer;
578
579 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
580 iassert(ivilayer != NULL);
581
582 iassert(ctl->layer_set_opacity(
583 ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
584 ctl->layer_destroy(ivilayer);
585 ctl->commit_changes();
586}
587
588static void
589test_commit_changes_after_orientation_set_layer_destroy(struct test_context *ctx)
590{
591 const struct ivi_controller_interface *ctl = ctx->controller_interface;
592 struct ivi_layout_layer *ivilayer;
593
594 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
595 iassert(ivilayer != NULL);
596
597 iassert(ctl->layer_set_orientation(
598 ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
599 ctl->layer_destroy(ivilayer);
600 ctl->commit_changes();
601}
602
603static void
604test_commit_changes_after_dimension_set_layer_destroy(struct test_context *ctx)
605{
606 const struct ivi_controller_interface *ctl = ctx->controller_interface;
607 struct ivi_layout_layer *ivilayer;
608
609 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
610 iassert(ivilayer != NULL);
611
612 iassert(ctl->layer_set_dimension(ivilayer, 200, 300) == IVI_SUCCEEDED);
613 ctl->layer_destroy(ivilayer);
614 ctl->commit_changes();
615}
616
617static void
618test_commit_changes_after_position_set_layer_destroy(struct test_context *ctx)
619{
620 const struct ivi_controller_interface *ctl = ctx->controller_interface;
621 struct ivi_layout_layer *ivilayer;
622
623 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
624 iassert(ivilayer != NULL);
625
626 iassert(ctl->layer_set_position(ivilayer, 20, 30) == IVI_SUCCEEDED);
627 ctl->layer_destroy(ivilayer);
628 ctl->commit_changes();
629}
630
631static void
632test_commit_changes_after_source_rectangle_set_layer_destroy(struct test_context *ctx)
633{
634 const struct ivi_controller_interface *ctl = ctx->controller_interface;
635 struct ivi_layout_layer *ivilayer;
636
637 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
638 iassert(ivilayer != NULL);
639
640 iassert(ctl->layer_set_source_rectangle(
641 ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
642 ctl->layer_destroy(ivilayer);
643 ctl->commit_changes();
644}
645
646static void
647test_commit_changes_after_destination_rectangle_set_layer_destroy(struct test_context *ctx)
648{
649 const struct ivi_controller_interface *ctl = ctx->controller_interface;
650 struct ivi_layout_layer *ivilayer;
651
652 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
653 iassert(ivilayer != NULL);
654
655 iassert(ctl->layer_set_destination_rectangle(
656 ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
657 ctl->layer_destroy(ivilayer);
658 ctl->commit_changes();
659}
660
661static void
662test_layer_create_duplicate(struct test_context *ctx)
663{
664 const struct ivi_controller_interface *ctl = ctx->controller_interface;
665 struct ivi_layout_layer *ivilayer;
666 struct ivi_layout_layer *duplicatelayer;
667
668 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
669 iassert(ivilayer != NULL);
670
671 if (ivilayer != NULL)
672 iassert(ivilayer->ref_count == 1);
673
674 duplicatelayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
675 iassert(ivilayer == duplicatelayer);
676
677 if (ivilayer != NULL)
678 iassert(ivilayer->ref_count == 2);
679
680 ctl->layer_destroy(ivilayer);
681
682 if (ivilayer != NULL)
683 iassert(ivilayer->ref_count == 1);
684
685 ctl->layer_destroy(ivilayer);
686}
687
688static void
689test_get_layer_after_destory_layer(struct test_context *ctx)
690{
691 const struct ivi_controller_interface *ctl = ctx->controller_interface;
692 struct ivi_layout_layer *ivilayer;
693
694 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
695 iassert(ivilayer != NULL);
696
697 ctl->layer_destroy(ivilayer);
698
699 ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
700 iassert(ivilayer == NULL);
701}
702
Nobuhiko Tanibatae78a7af2015-06-22 15:35:25 +0900703static void
704test_screen_id(struct test_context *ctx)
705{
706 const struct ivi_controller_interface *ctl = ctx->controller_interface;
707 struct ivi_layout_screen **iviscrns;
708 int32_t screen_length = 0;
709 uint32_t id_screen;
710 int32_t i;
711
712 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
713 iassert(screen_length > 0);
714
715 for (i = 0; i < screen_length; ++i) {
716 id_screen = ctl->get_id_of_screen(iviscrns[i]);
717 iassert(ctl->get_screen_from_id(id_screen) == iviscrns[i]);
718 }
719
720 if (screen_length > 0)
721 free(iviscrns);
722}
723
724static void
725test_screen_resolution(struct test_context *ctx)
726{
727 const struct ivi_controller_interface *ctl = ctx->controller_interface;
728 struct ivi_layout_screen **iviscrns;
729 int32_t screen_length = 0;
730 struct weston_output *output;
731 int32_t width;
732 int32_t height;
733 int32_t i;
734
735 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
736 iassert(screen_length > 0);
737
738 for (i = 0; i < screen_length; ++i) {
739 output = ctl->screen_get_output(iviscrns[i]);
740 iassert(output != NULL);
741 iassert(ctl->get_screen_resolution(
742 iviscrns[i], &width, &height) == IVI_SUCCEEDED);
743 iassert(width == output->current_mode->width);
744 iassert(height == output->current_mode->height);
745 }
746
747 if (screen_length > 0)
748 free(iviscrns);
749}
750
751static void
752test_screen_render_order(struct test_context *ctx)
753{
754#define LAYER_NUM (3)
755 const struct ivi_controller_interface *ctl = ctx->controller_interface;
756 struct ivi_layout_screen **iviscrns;
757 int32_t screen_length = 0;
758 struct ivi_layout_screen *iviscrn;
759 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
760 struct ivi_layout_layer **array;
761 int32_t length = 0;
762 uint32_t i;
763
764 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
765 iassert(screen_length > 0);
766
767 if (screen_length <= 0)
768 return;
769
770 iviscrn = iviscrns[0];
771
772 for (i = 0; i < LAYER_NUM; i++)
773 ivilayers[i] = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
774
775 iassert(ctl->screen_set_render_order(iviscrn, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
776
777 ctl->commit_changes();
778
779 iassert(ctl->get_layers_on_screen(iviscrn, &length, &array) == IVI_SUCCEEDED);
780 iassert(length == LAYER_NUM);
781 for (i = 0; i < LAYER_NUM; i++)
782 iassert(array[i] == ivilayers[i]);
783
784 if (length > 0)
785 free(array);
786
787 array = NULL;
788
789 iassert(ctl->screen_set_render_order(iviscrn, NULL, 0) == IVI_SUCCEEDED);
790
791 ctl->commit_changes();
792
793 iassert(ctl->get_layers_on_screen(iviscrn, &length, &array) == IVI_SUCCEEDED);
794 iassert(length == 0 && array == NULL);
795
796 for (i = 0; i < LAYER_NUM; i++)
797 ctl->layer_destroy(ivilayers[i]);
798
799 free(iviscrns);
800#undef LAYER_NUM
801}
802
Nobuhiko Tanibata83c20bc2015-06-22 15:35:39 +0900803static void
804test_screen_bad_resolution(struct test_context *ctx)
805{
806 const struct ivi_controller_interface *ctl = ctx->controller_interface;
807 struct ivi_layout_screen **iviscrns;
808 int32_t screen_length = 0;
809 struct ivi_layout_screen *iviscrn;
810 int32_t width;
811 int32_t height;
812
813 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
814 iassert(screen_length > 0);
815
816 if (screen_length <= 0)
817 return;
818
819 iviscrn = iviscrns[0];
820 iassert(ctl->get_screen_resolution(NULL, &width, &height) == IVI_FAILED);
821 iassert(ctl->get_screen_resolution(iviscrn, NULL, &height) == IVI_FAILED);
822 iassert(ctl->get_screen_resolution(iviscrn, &width, NULL) == IVI_FAILED);
823 free(iviscrns);
824}
825
826static void
827test_screen_bad_render_order(struct test_context *ctx)
828{
829#define LAYER_NUM (3)
830 const struct ivi_controller_interface *ctl = ctx->controller_interface;
831 struct ivi_layout_screen **iviscrns;
832 int32_t screen_length;
833 struct ivi_layout_screen *iviscrn;
834 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
835 struct ivi_layout_layer **array;
836 int32_t length = 0;
837 uint32_t i;
838
839 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
840 iassert(screen_length > 0);
841
842 if (screen_length <= 0)
843 return;
844
845 iviscrn = iviscrns[0];
846
847 for (i = 0; i < LAYER_NUM; i++)
848 ivilayers[i] = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
849
850 iassert(ctl->screen_set_render_order(NULL, ivilayers, LAYER_NUM) == IVI_FAILED);
851
852 ctl->commit_changes();
853
854 iassert(ctl->get_layers_on_screen(NULL, &length, &array) == IVI_FAILED);
855 iassert(ctl->get_layers_on_screen(iviscrn, NULL, &array) == IVI_FAILED);
856 iassert(ctl->get_layers_on_screen(iviscrn, &length, NULL) == IVI_FAILED);
857
858 for (i = 0; i < LAYER_NUM; i++)
859 ctl->layer_destroy(ivilayers[i]);
860
861 free(iviscrns);
862#undef LAYER_NUM
863}
864
865static void
866test_commit_changes_after_render_order_set_layer_destroy(
867 struct test_context *ctx)
868{
869#define LAYER_NUM (3)
870 const struct ivi_controller_interface *ctl = ctx->controller_interface;
871 struct ivi_layout_screen **iviscrns;
872 int32_t screen_length;
873 struct ivi_layout_screen *iviscrn;
874 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
875 uint32_t i;
876
877 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
878 iassert(screen_length > 0);
879
880 if (screen_length <= 0)
881 return;
882
883 iviscrn = iviscrns[0];
884
885 for (i = 0; i < LAYER_NUM; i++)
886 ivilayers[i] = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
887
888 iassert(ctl->screen_set_render_order(iviscrn, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
889
890 ctl->layer_destroy(ivilayers[1]);
891
892 ctl->commit_changes();
893
894 ctl->layer_destroy(ivilayers[0]);
895 ctl->layer_destroy(ivilayers[2]);
896
897 free(iviscrns);
898#undef LAYER_NUM
899}
900
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200901/************************ tests end ********************************/
902
903static void
904run_internal_tests(void *data)
905{
906 struct test_context *ctx = data;
907
908 test_surface_bad_visibility(ctx);
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +0900909 test_surface_bad_destination_rectangle(ctx);
910 test_surface_bad_orientation(ctx);
911 test_surface_bad_dimension(ctx);
912 test_surface_bad_position(ctx);
913 test_surface_bad_source_rectangle(ctx);
914 test_surface_bad_properties(ctx);
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200915
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900916 test_layer_create(ctx);
917 test_layer_visibility(ctx);
918 test_layer_opacity(ctx);
919 test_layer_orientation(ctx);
920 test_layer_dimension(ctx);
921 test_layer_position(ctx);
922 test_layer_destination_rectangle(ctx);
923 test_layer_source_rectangle(ctx);
Nobuhiko Tanibata17d44942015-06-22 15:35:12 +0900924 test_layer_bad_remove(ctx);
925 test_layer_bad_visibility(ctx);
926 test_layer_bad_opacity(ctx);
927 test_layer_bad_destination_rectangle(ctx);
928 test_layer_bad_orientation(ctx);
929 test_layer_bad_dimension(ctx);
930 test_layer_bad_position(ctx);
931 test_layer_bad_source_rectangle(ctx);
932 test_layer_bad_properties(ctx);
933 test_commit_changes_after_visibility_set_layer_destroy(ctx);
934 test_commit_changes_after_opacity_set_layer_destroy(ctx);
935 test_commit_changes_after_orientation_set_layer_destroy(ctx);
936 test_commit_changes_after_dimension_set_layer_destroy(ctx);
937 test_commit_changes_after_position_set_layer_destroy(ctx);
938 test_commit_changes_after_source_rectangle_set_layer_destroy(ctx);
939 test_commit_changes_after_destination_rectangle_set_layer_destroy(ctx);
940 test_layer_create_duplicate(ctx);
941 test_get_layer_after_destory_layer(ctx);
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900942
Nobuhiko Tanibatae78a7af2015-06-22 15:35:25 +0900943 test_screen_id(ctx);
944 test_screen_resolution(ctx);
945 test_screen_render_order(ctx);
Nobuhiko Tanibata83c20bc2015-06-22 15:35:39 +0900946 test_screen_bad_resolution(ctx);
947 test_screen_bad_render_order(ctx);
948 test_commit_changes_after_render_order_set_layer_destroy(ctx);
949
Nobuhiko Tanibatae78a7af2015-06-22 15:35:25 +0900950
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200951 weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
952 free(ctx);
953}
954
955int
956controller_module_init(struct weston_compositor *compositor,
957 int *argc, char *argv[],
958 const struct ivi_controller_interface *iface,
959 size_t iface_version);
960
961WL_EXPORT int
962controller_module_init(struct weston_compositor *compositor,
963 int *argc, char *argv[],
964 const struct ivi_controller_interface *iface,
965 size_t iface_version)
966{
967 struct wl_event_loop *loop;
968 struct test_context *ctx;
969
970 /* strict check, since this is an internal test module */
971 if (iface_version != sizeof(*iface)) {
972 weston_log("fatal: controller interface mismatch\n");
973 return -1;
974 }
975
976 ctx = zalloc(sizeof(*ctx));
977 if (!ctx)
978 return -1;
979
980 ctx->compositor = compositor;
981 ctx->controller_interface = iface;
982
983 loop = wl_display_get_event_loop(compositor->wl_display);
984 wl_event_loop_add_idle(loop, run_internal_tests, ctx);
985
986 return 0;
987}