blob: bb9cce9b3c452aa6940536c33a1b15948ec39b31 [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;
Nobuhiko Tanibata495c6ef2015-06-22 15:36:11 +090042 uint32_t user_flags;
Pekka Paalanen46804ca2015-03-27 11:55:21 +020043};
44
45static void
46iassert_fail(const char *cond, const char *file, int line,
47 const char *func, struct test_context *ctx)
48{
49 weston_log("Assert failure in %s:%d, %s: '%s'\n",
50 file, line, func, cond);
51 weston_compositor_exit_with_code(ctx->compositor, EXIT_FAILURE);
52}
53
54#define iassert(cond) ({ \
55 bool b_ = (cond); \
56 if (!b_) \
57 iassert_fail(#cond, __FILE__, __LINE__, __func__, ctx); \
58 b_; \
59})
60
61/************************ tests begin ******************************/
62
63/*
64 * These are all internal ivi_layout API tests that do not require
65 * any client objects.
66 */
Pekka Paalanen46804ca2015-03-27 11:55:21 +020067static void
68test_surface_bad_visibility(struct test_context *ctx)
69{
70 const struct ivi_controller_interface *ctl = ctx->controller_interface;
71 bool visibility;
72
73 iassert(ctl->surface_set_visibility(NULL, true) == IVI_FAILED);
74
75 ctl->commit_changes();
76
77 visibility = ctl->surface_get_visibility(NULL);
78 iassert(visibility == false);
79}
80
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +090081static void
82test_surface_bad_destination_rectangle(struct test_context *ctx)
83{
84 const struct ivi_controller_interface *ctl = ctx->controller_interface;
85
86 iassert(ctl->surface_set_destination_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
87}
88
89static void
90test_surface_bad_orientation(struct test_context *ctx)
91{
92 const struct ivi_controller_interface *ctl = ctx->controller_interface;
93
94 iassert(ctl->surface_set_orientation(NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
95
96 iassert(ctl->surface_get_orientation(NULL) == WL_OUTPUT_TRANSFORM_NORMAL);
97}
98
99static void
100test_surface_bad_dimension(struct test_context *ctx)
101{
102 const struct ivi_controller_interface *ctl = ctx->controller_interface;
103 struct ivi_layout_surface *ivisurf = NULL;
104 int32_t dest_width;
105 int32_t dest_height;
106
107 iassert(ctl->surface_set_dimension(NULL, 200, 300) == IVI_FAILED);
108
109 ctl->commit_changes();
110
111 iassert(ctl->surface_get_dimension(NULL, &dest_width, &dest_height) == IVI_FAILED);
112 iassert(ctl->surface_get_dimension(ivisurf, NULL, &dest_height) == IVI_FAILED);
113 iassert(ctl->surface_get_dimension(ivisurf, &dest_width, NULL) == IVI_FAILED);
114}
115
116static void
117test_surface_bad_position(struct test_context *ctx)
118{
119 const struct ivi_controller_interface *ctl = ctx->controller_interface;
120 struct ivi_layout_surface *ivisurf = NULL;
121 int32_t dest_x;
122 int32_t dest_y;
123
124 iassert(ctl->surface_set_position(NULL, 20, 30) == IVI_FAILED);
125
126 ctl->commit_changes();
127
128 iassert(ctl->surface_get_position(NULL, &dest_x, &dest_y) == IVI_FAILED);
129 iassert(ctl->surface_get_position(ivisurf, NULL, &dest_y) == IVI_FAILED);
130 iassert(ctl->surface_get_position(ivisurf, &dest_x, NULL) == IVI_FAILED);
131}
132
133static void
134test_surface_bad_source_rectangle(struct test_context *ctx)
135{
136 const struct ivi_controller_interface *ctl = ctx->controller_interface;
137
138 iassert(ctl->surface_set_source_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
139}
140
141static void
142test_surface_bad_properties(struct test_context *ctx)
143{
144 const struct ivi_controller_interface *ctl = ctx->controller_interface;
145
146 iassert(ctl->get_properties_of_surface(NULL) == NULL);
147}
148
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900149static void
150test_layer_create(struct test_context *ctx)
151{
152 const struct ivi_controller_interface *ctl = ctx->controller_interface;
153 uint32_t id1;
154 uint32_t id2;
155 struct ivi_layout_layer *ivilayer;
156 struct ivi_layout_layer *new_ivilayer;
157
158 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
159 iassert(ivilayer != NULL);
160
161 iassert(IVI_TEST_LAYER_ID(0) == ctl->get_id_of_layer(ivilayer));
162
163 new_ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
164 iassert(ivilayer == new_ivilayer);
165
166 id1 = ctl->get_id_of_layer(ivilayer);
167 id2 = ctl->get_id_of_layer(new_ivilayer);
168 iassert(id1 == id2);
169
170 ctl->layer_destroy(ivilayer);
171 iassert(ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0)) == NULL);
172}
173
174static void
175test_layer_visibility(struct test_context *ctx)
176{
177 const struct ivi_controller_interface *ctl = ctx->controller_interface;
178 struct ivi_layout_layer *ivilayer;
179 const struct ivi_layout_layer_properties *prop;
180
181 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
182 iassert(ivilayer != NULL);
183
184 iassert(ctl->layer_get_visibility(ivilayer) == false);
185
186 iassert(ctl->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
187
188 iassert(ctl->layer_get_visibility(ivilayer) == false);
189
190 ctl->commit_changes();
191
192 iassert(ctl->layer_get_visibility(ivilayer) == true);
193
194 prop = ctl->get_properties_of_layer(ivilayer);
195 iassert(prop->visibility == true);
196
197 ctl->layer_destroy(ivilayer);
198}
199
200static void
201test_layer_opacity(struct test_context *ctx)
202{
203 const struct ivi_controller_interface *ctl = ctx->controller_interface;
204 struct ivi_layout_layer *ivilayer;
205 const struct ivi_layout_layer_properties *prop;
206
207 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
208 iassert(ivilayer != NULL);
209
210 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(1.0));
211
212 iassert(ctl->layer_set_opacity(
213 ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
214
215 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(1.0));
216
217 ctl->commit_changes();
218
219 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.5));
220
221 prop = ctl->get_properties_of_layer(ivilayer);
222 iassert(prop->opacity == wl_fixed_from_double(0.5));
223
224 ctl->layer_destroy(ivilayer);
225}
226
227static void
228test_layer_orientation(struct test_context *ctx)
229{
230 const struct ivi_controller_interface *ctl = ctx->controller_interface;
231 struct ivi_layout_layer *ivilayer;
232 const struct ivi_layout_layer_properties *prop;
233
234 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
235 iassert(ivilayer != NULL);
236
237 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_NORMAL);
238
239 iassert(ctl->layer_set_orientation(
240 ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
241
242 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_NORMAL);
243
244 ctl->commit_changes();
245
246 iassert(ctl->layer_get_orientation(ivilayer) == WL_OUTPUT_TRANSFORM_90);
247
248 prop = ctl->get_properties_of_layer(ivilayer);
249 iassert(prop->orientation == WL_OUTPUT_TRANSFORM_90);
250
251 ctl->layer_destroy(ivilayer);
252}
253
254static void
255test_layer_dimension(struct test_context *ctx)
256{
257 const struct ivi_controller_interface *ctl = ctx->controller_interface;
258 struct ivi_layout_layer *ivilayer;
259 const struct ivi_layout_layer_properties *prop;
260 int32_t dest_width;
261 int32_t dest_height;
262
263 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
264 iassert(ivilayer != NULL);
265
266 iassert(ctl->layer_get_dimension(
267 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
268 iassert(dest_width == 200);
269 iassert(dest_height == 300);
270
271 iassert(ctl->layer_set_dimension(ivilayer, 400, 600) == IVI_SUCCEEDED);
272
273 iassert(ctl->layer_get_dimension(
274 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
275 iassert(dest_width == 200);
276 iassert(dest_height == 300);
277
278 ctl->commit_changes();
279
280 iassert(IVI_SUCCEEDED == ctl->layer_get_dimension(
281 ivilayer, &dest_width, &dest_height));
282 iassert(dest_width == 400);
283 iassert(dest_height == 600);
284
285 prop = ctl->get_properties_of_layer(ivilayer);
286 iassert(prop->dest_width == 400);
287 iassert(prop->dest_height == 600);
288
289 ctl->layer_destroy(ivilayer);
290}
291
292static void
293test_layer_position(struct test_context *ctx)
294{
295 const struct ivi_controller_interface *ctl = ctx->controller_interface;
296 struct ivi_layout_layer *ivilayer;
297 const struct ivi_layout_layer_properties *prop;
298 int32_t dest_x;
299 int32_t dest_y;
300
301 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
302 iassert(ivilayer != NULL);
303
304 iassert(ctl->layer_get_position(
305 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
306 iassert(dest_x == 0);
307 iassert(dest_y == 0);
308
309 iassert(ctl->layer_set_position(ivilayer, 20, 30) == IVI_SUCCEEDED);
310
311 iassert(ctl->layer_get_position(
312 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
313 iassert(dest_x == 0);
314 iassert(dest_y == 0);
315
316 ctl->commit_changes();
317
318 iassert(ctl->layer_get_position(
319 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
320 iassert(dest_x == 20);
321 iassert(dest_y == 30);
322
323 prop = ctl->get_properties_of_layer(ivilayer);
324 iassert(prop->dest_x == 20);
325 iassert(prop->dest_y == 30);
326
327 ctl->layer_destroy(ivilayer);
328}
329
330static void
331test_layer_destination_rectangle(struct test_context *ctx)
332{
333 const struct ivi_controller_interface *ctl = ctx->controller_interface;
334 struct ivi_layout_layer *ivilayer;
335 const struct ivi_layout_layer_properties *prop;
336 int32_t dest_width;
337 int32_t dest_height;
338 int32_t dest_x;
339 int32_t dest_y;
340
341 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
342 iassert(ivilayer != NULL);
343
344 prop = ctl->get_properties_of_layer(ivilayer);
345 iassert(prop->dest_width == 200);
346 iassert(prop->dest_height == 300);
347 iassert(prop->dest_x == 0);
348 iassert(prop->dest_y == 0);
349
350 iassert(ctl->layer_set_destination_rectangle(
351 ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);
352
353 prop = ctl->get_properties_of_layer(ivilayer);
354 iassert(prop->dest_width == 200);
355 iassert(prop->dest_height == 300);
356 iassert(prop->dest_x == 0);
357 iassert(prop->dest_y == 0);
358
359 ctl->commit_changes();
360
361 iassert(ctl->layer_get_dimension(
362 ivilayer, &dest_width, &dest_height) == IVI_SUCCEEDED);
363 iassert(dest_width == 400);
364 iassert(dest_height == 600);
365
366 iassert(ctl->layer_get_position(
367 ivilayer, &dest_x, &dest_y) == IVI_SUCCEEDED);
368 iassert(dest_x == 20);
369 iassert(dest_y == 30);
370
371 prop = ctl->get_properties_of_layer(ivilayer);
372 iassert(prop->dest_width == 400);
373 iassert(prop->dest_height == 600);
374 iassert(prop->dest_x == 20);
375 iassert(prop->dest_y == 30);
376
377 ctl->layer_destroy(ivilayer);
378}
379
380static void
381test_layer_source_rectangle(struct test_context *ctx)
382{
383 const struct ivi_controller_interface *ctl = ctx->controller_interface;
384 struct ivi_layout_layer *ivilayer;
385 const struct ivi_layout_layer_properties *prop;
386
387 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
388 iassert(ivilayer != NULL);
389
390 prop = ctl->get_properties_of_layer(ivilayer);
391 iassert(prop->source_width == 200);
392 iassert(prop->source_height == 300);
393 iassert(prop->source_x == 0);
394 iassert(prop->source_y == 0);
395
396 iassert(ctl->layer_set_source_rectangle(
397 ivilayer, 20, 30, 400, 600) == IVI_SUCCEEDED);
398
399 prop = ctl->get_properties_of_layer(ivilayer);
400 iassert(prop->source_width == 200);
401 iassert(prop->source_height == 300);
402 iassert(prop->source_x == 0);
403 iassert(prop->source_y == 0);
404
405 ctl->commit_changes();
406
407 prop = ctl->get_properties_of_layer(ivilayer);
408 iassert(prop->source_width == 400);
409 iassert(prop->source_height == 600);
410 iassert(prop->source_x == 20);
411 iassert(prop->source_y == 30);
412
413 ctl->layer_destroy(ivilayer);
414}
415
Nobuhiko Tanibata17d44942015-06-22 15:35:12 +0900416static void
417test_layer_bad_remove(struct test_context *ctx)
418{
419 const struct ivi_controller_interface *ctl = ctx->controller_interface;
420 ctl->layer_destroy(NULL);
421}
422
423static void
424test_layer_bad_visibility(struct test_context *ctx)
425{
426 const struct ivi_controller_interface *ctl = ctx->controller_interface;
427
428 iassert(ctl->layer_set_visibility(NULL, true) == IVI_FAILED);
429
430 ctl->commit_changes();
431
432 iassert(ctl->layer_get_visibility(NULL) == false);
433}
434
435static void
436test_layer_bad_opacity(struct test_context *ctx)
437{
438 const struct ivi_controller_interface *ctl = ctx->controller_interface;
439 struct ivi_layout_layer *ivilayer;
440
441 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
442 iassert(ivilayer != NULL);
443
444 iassert(ctl->layer_set_opacity(
445 NULL, wl_fixed_from_double(0.3)) == IVI_FAILED);
446
447 iassert(ctl->layer_set_opacity(
448 ivilayer, wl_fixed_from_double(0.3)) == IVI_SUCCEEDED);
449
450 iassert(ctl->layer_set_opacity(
451 ivilayer, wl_fixed_from_double(-1)) == IVI_FAILED);
452
453 ctl->commit_changes();
454
455 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.3));
456
457 iassert(ctl->layer_set_opacity(
458 ivilayer, wl_fixed_from_double(1.1)) == IVI_FAILED);
459
460 ctl->commit_changes();
461
462 iassert(ctl->layer_get_opacity(ivilayer) == wl_fixed_from_double(0.3));
463
464 iassert(ctl->layer_set_opacity(
465 NULL, wl_fixed_from_double(0.5)) == IVI_FAILED);
466
467 ctl->commit_changes();
468
469 iassert(ctl->layer_get_opacity(NULL) == wl_fixed_from_double(0.0));
470
471 ctl->layer_destroy(ivilayer);
472}
473
474static void
475test_layer_bad_destination_rectangle(struct test_context *ctx)
476{
477 const struct ivi_controller_interface *ctl = ctx->controller_interface;
478
479 iassert(ctl->layer_set_destination_rectangle(
480 NULL, 20, 30, 200, 300) == IVI_FAILED);
481}
482
483static void
484test_layer_bad_orientation(struct test_context *ctx)
485{
486 const struct ivi_controller_interface *ctl = ctx->controller_interface;
487
488 iassert(ctl->layer_set_orientation(
489 NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
490
491 ctl->commit_changes();
492
493 iassert(ctl->layer_get_orientation(NULL) == WL_OUTPUT_TRANSFORM_NORMAL);
494}
495
496static void
497test_layer_bad_dimension(struct test_context *ctx)
498{
499 const struct ivi_controller_interface *ctl = ctx->controller_interface;
500 struct ivi_layout_layer *ivilayer;
501 int32_t dest_width;
502 int32_t dest_height;
503
504 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
505 iassert(ivilayer != NULL);
506
507 iassert(ctl->layer_set_dimension(NULL, 200, 300) == IVI_FAILED);
508
509 ctl->commit_changes();
510
511 iassert(ctl->layer_get_dimension(
512 NULL, &dest_width, &dest_height) == IVI_FAILED);
513 iassert(ctl->layer_get_dimension(
514 ivilayer, NULL, &dest_height) == IVI_FAILED);
515 iassert(ctl->layer_get_dimension(
516 ivilayer, &dest_width, NULL) == IVI_FAILED);
517
518 ctl->layer_destroy(ivilayer);
519}
520
521static void
522test_layer_bad_position(struct test_context *ctx)
523{
524 const struct ivi_controller_interface *ctl = ctx->controller_interface;
525 struct ivi_layout_layer *ivilayer;
526 int32_t dest_x;
527 int32_t dest_y;
528
529 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
530 iassert(ivilayer != NULL);
531
532 iassert(ctl->layer_set_position(NULL, 20, 30) == IVI_FAILED);
533
534 ctl->commit_changes();
535
536 iassert(ctl->layer_get_position(NULL, &dest_x, &dest_y) == IVI_FAILED);
537 iassert(ctl->layer_get_position(ivilayer, NULL, &dest_y) == IVI_FAILED);
538 iassert(ctl->layer_get_position(ivilayer, &dest_x, NULL) == IVI_FAILED);
539
540 ctl->layer_destroy(ivilayer);
541}
542
543static void
544test_layer_bad_source_rectangle(struct test_context *ctx)
545{
546 const struct ivi_controller_interface *ctl = ctx->controller_interface;
547
548 iassert(ctl->layer_set_source_rectangle(
549 NULL, 20, 30, 200, 300) == IVI_FAILED);
550}
551
552static void
553test_layer_bad_properties(struct test_context *ctx)
554{
555 const struct ivi_controller_interface *ctl = ctx->controller_interface;
556
557 iassert(ctl->get_properties_of_layer(NULL) == NULL);
558}
559
560static void
561test_commit_changes_after_visibility_set_layer_destroy(struct test_context *ctx)
562{
563 const struct ivi_controller_interface *ctl = ctx->controller_interface;
564 struct ivi_layout_layer *ivilayer;
565
566 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
567 iassert(ivilayer != NULL);
568
569 iassert(ctl->layer_set_visibility(ivilayer, true) == IVI_SUCCEEDED);
570 ctl->layer_destroy(ivilayer);
571 ctl->commit_changes();
572}
573
574static void
575test_commit_changes_after_opacity_set_layer_destroy(struct test_context *ctx)
576{
577 const struct ivi_controller_interface *ctl = ctx->controller_interface;
578 struct ivi_layout_layer *ivilayer;
579
580 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
581 iassert(ivilayer != NULL);
582
583 iassert(ctl->layer_set_opacity(
584 ivilayer, wl_fixed_from_double(0.5)) == IVI_SUCCEEDED);
585 ctl->layer_destroy(ivilayer);
586 ctl->commit_changes();
587}
588
589static void
590test_commit_changes_after_orientation_set_layer_destroy(struct test_context *ctx)
591{
592 const struct ivi_controller_interface *ctl = ctx->controller_interface;
593 struct ivi_layout_layer *ivilayer;
594
595 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
596 iassert(ivilayer != NULL);
597
598 iassert(ctl->layer_set_orientation(
599 ivilayer, WL_OUTPUT_TRANSFORM_90) == IVI_SUCCEEDED);
600 ctl->layer_destroy(ivilayer);
601 ctl->commit_changes();
602}
603
604static void
605test_commit_changes_after_dimension_set_layer_destroy(struct test_context *ctx)
606{
607 const struct ivi_controller_interface *ctl = ctx->controller_interface;
608 struct ivi_layout_layer *ivilayer;
609
610 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
611 iassert(ivilayer != NULL);
612
613 iassert(ctl->layer_set_dimension(ivilayer, 200, 300) == IVI_SUCCEEDED);
614 ctl->layer_destroy(ivilayer);
615 ctl->commit_changes();
616}
617
618static void
619test_commit_changes_after_position_set_layer_destroy(struct test_context *ctx)
620{
621 const struct ivi_controller_interface *ctl = ctx->controller_interface;
622 struct ivi_layout_layer *ivilayer;
623
624 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
625 iassert(ivilayer != NULL);
626
627 iassert(ctl->layer_set_position(ivilayer, 20, 30) == IVI_SUCCEEDED);
628 ctl->layer_destroy(ivilayer);
629 ctl->commit_changes();
630}
631
632static void
633test_commit_changes_after_source_rectangle_set_layer_destroy(struct test_context *ctx)
634{
635 const struct ivi_controller_interface *ctl = ctx->controller_interface;
636 struct ivi_layout_layer *ivilayer;
637
638 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
639 iassert(ivilayer != NULL);
640
641 iassert(ctl->layer_set_source_rectangle(
642 ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
643 ctl->layer_destroy(ivilayer);
644 ctl->commit_changes();
645}
646
647static void
648test_commit_changes_after_destination_rectangle_set_layer_destroy(struct test_context *ctx)
649{
650 const struct ivi_controller_interface *ctl = ctx->controller_interface;
651 struct ivi_layout_layer *ivilayer;
652
653 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
654 iassert(ivilayer != NULL);
655
656 iassert(ctl->layer_set_destination_rectangle(
657 ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
658 ctl->layer_destroy(ivilayer);
659 ctl->commit_changes();
660}
661
662static void
663test_layer_create_duplicate(struct test_context *ctx)
664{
665 const struct ivi_controller_interface *ctl = ctx->controller_interface;
666 struct ivi_layout_layer *ivilayer;
667 struct ivi_layout_layer *duplicatelayer;
668
669 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
670 iassert(ivilayer != NULL);
671
672 if (ivilayer != NULL)
673 iassert(ivilayer->ref_count == 1);
674
675 duplicatelayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
676 iassert(ivilayer == duplicatelayer);
677
678 if (ivilayer != NULL)
679 iassert(ivilayer->ref_count == 2);
680
681 ctl->layer_destroy(ivilayer);
682
683 if (ivilayer != NULL)
684 iassert(ivilayer->ref_count == 1);
685
686 ctl->layer_destroy(ivilayer);
687}
688
689static void
690test_get_layer_after_destory_layer(struct test_context *ctx)
691{
692 const struct ivi_controller_interface *ctl = ctx->controller_interface;
693 struct ivi_layout_layer *ivilayer;
694
695 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
696 iassert(ivilayer != NULL);
697
698 ctl->layer_destroy(ivilayer);
699
700 ivilayer = ctl->get_layer_from_id(IVI_TEST_LAYER_ID(0));
701 iassert(ivilayer == NULL);
702}
703
Nobuhiko Tanibatae78a7af2015-06-22 15:35:25 +0900704static void
705test_screen_id(struct test_context *ctx)
706{
707 const struct ivi_controller_interface *ctl = ctx->controller_interface;
708 struct ivi_layout_screen **iviscrns;
709 int32_t screen_length = 0;
710 uint32_t id_screen;
711 int32_t i;
712
713 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
714 iassert(screen_length > 0);
715
716 for (i = 0; i < screen_length; ++i) {
717 id_screen = ctl->get_id_of_screen(iviscrns[i]);
718 iassert(ctl->get_screen_from_id(id_screen) == iviscrns[i]);
719 }
720
721 if (screen_length > 0)
722 free(iviscrns);
723}
724
725static void
726test_screen_resolution(struct test_context *ctx)
727{
728 const struct ivi_controller_interface *ctl = ctx->controller_interface;
729 struct ivi_layout_screen **iviscrns;
730 int32_t screen_length = 0;
731 struct weston_output *output;
732 int32_t width;
733 int32_t height;
734 int32_t i;
735
736 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
737 iassert(screen_length > 0);
738
739 for (i = 0; i < screen_length; ++i) {
740 output = ctl->screen_get_output(iviscrns[i]);
741 iassert(output != NULL);
742 iassert(ctl->get_screen_resolution(
743 iviscrns[i], &width, &height) == IVI_SUCCEEDED);
744 iassert(width == output->current_mode->width);
745 iassert(height == output->current_mode->height);
746 }
747
748 if (screen_length > 0)
749 free(iviscrns);
750}
751
752static void
753test_screen_render_order(struct test_context *ctx)
754{
755#define LAYER_NUM (3)
756 const struct ivi_controller_interface *ctl = ctx->controller_interface;
757 struct ivi_layout_screen **iviscrns;
758 int32_t screen_length = 0;
759 struct ivi_layout_screen *iviscrn;
760 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
761 struct ivi_layout_layer **array;
762 int32_t length = 0;
763 uint32_t i;
764
765 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
766 iassert(screen_length > 0);
767
768 if (screen_length <= 0)
769 return;
770
771 iviscrn = iviscrns[0];
772
773 for (i = 0; i < LAYER_NUM; i++)
774 ivilayers[i] = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
775
776 iassert(ctl->screen_set_render_order(iviscrn, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
777
778 ctl->commit_changes();
779
780 iassert(ctl->get_layers_on_screen(iviscrn, &length, &array) == IVI_SUCCEEDED);
781 iassert(length == LAYER_NUM);
782 for (i = 0; i < LAYER_NUM; i++)
783 iassert(array[i] == ivilayers[i]);
784
785 if (length > 0)
786 free(array);
787
788 array = NULL;
789
790 iassert(ctl->screen_set_render_order(iviscrn, NULL, 0) == IVI_SUCCEEDED);
791
792 ctl->commit_changes();
793
794 iassert(ctl->get_layers_on_screen(iviscrn, &length, &array) == IVI_SUCCEEDED);
795 iassert(length == 0 && array == NULL);
796
797 for (i = 0; i < LAYER_NUM; i++)
798 ctl->layer_destroy(ivilayers[i]);
799
800 free(iviscrns);
801#undef LAYER_NUM
802}
803
Nobuhiko Tanibata83c20bc2015-06-22 15:35:39 +0900804static void
805test_screen_bad_resolution(struct test_context *ctx)
806{
807 const struct ivi_controller_interface *ctl = ctx->controller_interface;
808 struct ivi_layout_screen **iviscrns;
809 int32_t screen_length = 0;
810 struct ivi_layout_screen *iviscrn;
811 int32_t width;
812 int32_t height;
813
814 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
815 iassert(screen_length > 0);
816
817 if (screen_length <= 0)
818 return;
819
820 iviscrn = iviscrns[0];
821 iassert(ctl->get_screen_resolution(NULL, &width, &height) == IVI_FAILED);
822 iassert(ctl->get_screen_resolution(iviscrn, NULL, &height) == IVI_FAILED);
823 iassert(ctl->get_screen_resolution(iviscrn, &width, NULL) == IVI_FAILED);
824 free(iviscrns);
825}
826
827static void
828test_screen_bad_render_order(struct test_context *ctx)
829{
830#define LAYER_NUM (3)
831 const struct ivi_controller_interface *ctl = ctx->controller_interface;
832 struct ivi_layout_screen **iviscrns;
833 int32_t screen_length;
834 struct ivi_layout_screen *iviscrn;
835 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
836 struct ivi_layout_layer **array;
837 int32_t length = 0;
838 uint32_t i;
839
840 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
841 iassert(screen_length > 0);
842
843 if (screen_length <= 0)
844 return;
845
846 iviscrn = iviscrns[0];
847
848 for (i = 0; i < LAYER_NUM; i++)
849 ivilayers[i] = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
850
851 iassert(ctl->screen_set_render_order(NULL, ivilayers, LAYER_NUM) == IVI_FAILED);
852
853 ctl->commit_changes();
854
855 iassert(ctl->get_layers_on_screen(NULL, &length, &array) == IVI_FAILED);
856 iassert(ctl->get_layers_on_screen(iviscrn, NULL, &array) == IVI_FAILED);
857 iassert(ctl->get_layers_on_screen(iviscrn, &length, NULL) == IVI_FAILED);
858
859 for (i = 0; i < LAYER_NUM; i++)
860 ctl->layer_destroy(ivilayers[i]);
861
862 free(iviscrns);
863#undef LAYER_NUM
864}
865
866static void
867test_commit_changes_after_render_order_set_layer_destroy(
868 struct test_context *ctx)
869{
870#define LAYER_NUM (3)
871 const struct ivi_controller_interface *ctl = ctx->controller_interface;
872 struct ivi_layout_screen **iviscrns;
873 int32_t screen_length;
874 struct ivi_layout_screen *iviscrn;
875 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
876 uint32_t i;
877
878 iassert(ctl->get_screens(&screen_length, &iviscrns) == IVI_SUCCEEDED);
879 iassert(screen_length > 0);
880
881 if (screen_length <= 0)
882 return;
883
884 iviscrn = iviscrns[0];
885
886 for (i = 0; i < LAYER_NUM; i++)
887 ivilayers[i] = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(i), 200, 300);
888
889 iassert(ctl->screen_set_render_order(iviscrn, ivilayers, LAYER_NUM) == IVI_SUCCEEDED);
890
891 ctl->layer_destroy(ivilayers[1]);
892
893 ctl->commit_changes();
894
895 ctl->layer_destroy(ivilayers[0]);
896 ctl->layer_destroy(ivilayers[2]);
897
898 free(iviscrns);
899#undef LAYER_NUM
900}
901
Nobuhiko Tanibata495c6ef2015-06-22 15:36:11 +0900902static void
903test_layer_properties_changed_notification_callback(struct ivi_layout_layer *ivilayer,
904 const struct ivi_layout_layer_properties *prop,
905 enum ivi_layout_notification_mask mask,
906 void *userdata)
907{
908 struct test_context *ctx = userdata;
909 const struct ivi_controller_interface *ctl = ctx->controller_interface;
910
911 iassert(ctl->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
912 iassert(prop->source_width == 200);
913 iassert(prop->source_height == 300);
914
915 if (ctl->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
916 prop->source_width == 200 && prop->source_height == 300)
917 ctx->user_flags = 1;
918}
919
920static void
921test_layer_properties_changed_notification(struct test_context *ctx)
922{
923 const struct ivi_controller_interface *ctl = ctx->controller_interface;
924 struct ivi_layout_layer *ivilayer;
925
926 ctx->user_flags = 0;
927
928 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
929
930 iassert(ctl->layer_add_notification(ivilayer, test_layer_properties_changed_notification_callback, ctx) == IVI_SUCCEEDED);
931
932 ctl->commit_changes();
933
934 iassert(ctx->user_flags == 0);
935
936 iassert(ctl->layer_set_destination_rectangle(
937 ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
938
939 ctl->commit_changes();
940
941 iassert(ctx->user_flags == 1);
942
943 ctx->user_flags = 0;
944 iassert(ctl->layer_set_destination_rectangle(
945 ivilayer, 20, 30, 200, 300) == IVI_SUCCEEDED);
946
947 ctl->commit_changes();
948
949 iassert(ctx->user_flags == 0);
950
951 ctl->layer_remove_notification(ivilayer);
952
953 ctx->user_flags = 0;
954 ctl->commit_changes();
955
956 iassert(ctx->user_flags == 0);
957
958 ctl->layer_destroy(ivilayer);
959}
960
961static void
962test_layer_create_notification_callback(struct ivi_layout_layer *ivilayer,
963 void *userdata)
964{
965 struct test_context *ctx = userdata;
966 const struct ivi_controller_interface *ctl = ctx->controller_interface;
967 const struct ivi_layout_layer_properties *prop = ctl->get_properties_of_layer(ivilayer);
968
969 iassert(ctl->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
970 iassert(prop->source_width == 200);
971 iassert(prop->source_height == 300);
972
973 if (ctl->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
974 prop->source_width == 200 && prop->source_height == 300)
975 ctx->user_flags = 1;
976}
977
978static void
979test_layer_create_notification(struct test_context *ctx)
980{
981#define LAYER_NUM (2)
982 const struct ivi_controller_interface *ctl = ctx->controller_interface;
983 static const uint32_t layers[LAYER_NUM] = {IVI_TEST_LAYER_ID(0), IVI_TEST_LAYER_ID(1)};
984 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
985
986 ctx->user_flags = 0;
987
988 iassert(ctl->add_notification_create_layer(
989 test_layer_create_notification_callback, ctx) == IVI_SUCCEEDED);
990 ivilayers[0] = ctl->layer_create_with_dimension(layers[0], 200, 300);
991
992 iassert(ctx->user_flags == 1);
993
994 ctx->user_flags = 0;
995 ctl->remove_notification_create_layer(test_layer_create_notification_callback, ctx);
996
997 ivilayers[1] = ctl->layer_create_with_dimension(layers[1], 400, 500);
998
999 iassert(ctx->user_flags == 0);
1000
1001 ctl->layer_destroy(ivilayers[0]);
1002 ctl->layer_destroy(ivilayers[1]);
1003#undef LAYER_NUM
1004}
1005
1006static void
1007test_layer_remove_notification_callback(struct ivi_layout_layer *ivilayer,
1008 void *userdata)
1009{
1010 struct test_context *ctx = userdata;
1011 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1012 const struct ivi_layout_layer_properties *prop =
1013 ctl->get_properties_of_layer(ivilayer);
1014
1015 iassert(ctl->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
1016 iassert(prop->source_width == 200);
1017 iassert(prop->source_height == 300);
1018
1019 if (ctl->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0) &&
1020 prop->source_width == 200 && prop->source_height == 300)
1021 ctx->user_flags = 1;
1022}
1023
1024static void
1025test_layer_remove_notification(struct test_context *ctx)
1026{
1027#define LAYER_NUM (2)
1028 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1029 static const uint32_t layers[LAYER_NUM] = {IVI_TEST_LAYER_ID(0), IVI_TEST_LAYER_ID(1)};
1030 struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
1031
1032 ctx->user_flags = 0;
1033
1034 ivilayers[0] = ctl->layer_create_with_dimension(layers[0], 200, 300);
1035 iassert(ctl->add_notification_remove_layer(
1036 test_layer_remove_notification_callback, ctx) == IVI_SUCCEEDED);
1037 ctl->layer_destroy(ivilayers[0]);
1038
1039 iassert(ctx->user_flags == 1);
1040
1041 ctx->user_flags = 0;
1042 ivilayers[1] = ctl->layer_create_with_dimension(layers[1], 250, 350);
1043 ctl->remove_notification_remove_layer(test_layer_remove_notification_callback, ctx);
1044 ctl->layer_destroy(ivilayers[1]);
1045
1046 iassert(ctx->user_flags == 0);
1047#undef LAYER_NUM
1048}
1049
Nobuhiko Tanibataffcc4522015-06-22 15:37:41 +09001050static void
1051test_layer_bad_properties_changed_notification_callback(struct ivi_layout_layer *ivilayer,
1052 const struct ivi_layout_layer_properties *prop,
1053 enum ivi_layout_notification_mask mask,
1054 void *userdata)
1055{
1056}
1057
1058static void
1059test_layer_bad_properties_changed_notification(struct test_context *ctx)
1060{
1061 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1062 struct ivi_layout_layer *ivilayer;
1063
1064 ivilayer = ctl->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
1065
1066 iassert(ctl->layer_add_notification(
1067 NULL, test_layer_bad_properties_changed_notification_callback, NULL) == IVI_FAILED);
1068 iassert(ctl->layer_add_notification(ivilayer, NULL, NULL) == IVI_FAILED);
1069
1070 ctl->layer_destroy(ivilayer);
1071}
1072
1073static void
1074test_surface_bad_configure_notification(struct test_context *ctx)
1075{
1076 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1077
1078 iassert(ctl->add_notification_configure_surface(NULL, NULL) == IVI_FAILED);
1079}
1080
1081static void
1082test_layer_bad_create_notification(struct test_context *ctx)
1083{
1084 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1085
1086 iassert(ctl->add_notification_create_layer(NULL, NULL) == IVI_FAILED);
1087}
1088
1089static void
1090test_surface_bad_create_notification(struct test_context *ctx)
1091{
1092 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1093
1094 iassert(ctl->add_notification_create_surface(NULL, NULL) == IVI_FAILED);
1095}
1096
1097static void
1098test_layer_bad_remove_notification(struct test_context *ctx)
1099{
1100 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1101
1102 iassert(ctl->add_notification_remove_layer(NULL, NULL) == IVI_FAILED);
1103}
1104
1105static void
1106test_surface_bad_remove_notification(struct test_context *ctx)
1107{
1108 const struct ivi_controller_interface *ctl = ctx->controller_interface;
1109
1110 iassert(ctl->add_notification_remove_surface(NULL, NULL) == IVI_FAILED);
1111}
1112
Pekka Paalanen46804ca2015-03-27 11:55:21 +02001113/************************ tests end ********************************/
1114
1115static void
1116run_internal_tests(void *data)
1117{
1118 struct test_context *ctx = data;
1119
1120 test_surface_bad_visibility(ctx);
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +09001121 test_surface_bad_destination_rectangle(ctx);
1122 test_surface_bad_orientation(ctx);
1123 test_surface_bad_dimension(ctx);
1124 test_surface_bad_position(ctx);
1125 test_surface_bad_source_rectangle(ctx);
1126 test_surface_bad_properties(ctx);
Pekka Paalanen46804ca2015-03-27 11:55:21 +02001127
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +09001128 test_layer_create(ctx);
1129 test_layer_visibility(ctx);
1130 test_layer_opacity(ctx);
1131 test_layer_orientation(ctx);
1132 test_layer_dimension(ctx);
1133 test_layer_position(ctx);
1134 test_layer_destination_rectangle(ctx);
1135 test_layer_source_rectangle(ctx);
Nobuhiko Tanibata17d44942015-06-22 15:35:12 +09001136 test_layer_bad_remove(ctx);
1137 test_layer_bad_visibility(ctx);
1138 test_layer_bad_opacity(ctx);
1139 test_layer_bad_destination_rectangle(ctx);
1140 test_layer_bad_orientation(ctx);
1141 test_layer_bad_dimension(ctx);
1142 test_layer_bad_position(ctx);
1143 test_layer_bad_source_rectangle(ctx);
1144 test_layer_bad_properties(ctx);
1145 test_commit_changes_after_visibility_set_layer_destroy(ctx);
1146 test_commit_changes_after_opacity_set_layer_destroy(ctx);
1147 test_commit_changes_after_orientation_set_layer_destroy(ctx);
1148 test_commit_changes_after_dimension_set_layer_destroy(ctx);
1149 test_commit_changes_after_position_set_layer_destroy(ctx);
1150 test_commit_changes_after_source_rectangle_set_layer_destroy(ctx);
1151 test_commit_changes_after_destination_rectangle_set_layer_destroy(ctx);
1152 test_layer_create_duplicate(ctx);
1153 test_get_layer_after_destory_layer(ctx);
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +09001154
Nobuhiko Tanibatae78a7af2015-06-22 15:35:25 +09001155 test_screen_id(ctx);
1156 test_screen_resolution(ctx);
1157 test_screen_render_order(ctx);
Nobuhiko Tanibata83c20bc2015-06-22 15:35:39 +09001158 test_screen_bad_resolution(ctx);
1159 test_screen_bad_render_order(ctx);
1160 test_commit_changes_after_render_order_set_layer_destroy(ctx);
1161
Nobuhiko Tanibata495c6ef2015-06-22 15:36:11 +09001162 test_layer_properties_changed_notification(ctx);
1163 test_layer_create_notification(ctx);
1164 test_layer_remove_notification(ctx);
Nobuhiko Tanibataffcc4522015-06-22 15:37:41 +09001165 test_layer_bad_properties_changed_notification(ctx);
1166 test_surface_bad_configure_notification(ctx);
1167 test_layer_bad_create_notification(ctx);
1168 test_surface_bad_create_notification(ctx);
1169 test_layer_bad_remove_notification(ctx);
1170 test_surface_bad_remove_notification(ctx);
Nobuhiko Tanibatae78a7af2015-06-22 15:35:25 +09001171
Pekka Paalanen46804ca2015-03-27 11:55:21 +02001172 weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
1173 free(ctx);
1174}
1175
1176int
1177controller_module_init(struct weston_compositor *compositor,
1178 int *argc, char *argv[],
1179 const struct ivi_controller_interface *iface,
1180 size_t iface_version);
1181
1182WL_EXPORT int
1183controller_module_init(struct weston_compositor *compositor,
1184 int *argc, char *argv[],
1185 const struct ivi_controller_interface *iface,
1186 size_t iface_version)
1187{
1188 struct wl_event_loop *loop;
1189 struct test_context *ctx;
1190
1191 /* strict check, since this is an internal test module */
1192 if (iface_version != sizeof(*iface)) {
1193 weston_log("fatal: controller interface mismatch\n");
1194 return -1;
1195 }
1196
1197 ctx = zalloc(sizeof(*ctx));
1198 if (!ctx)
1199 return -1;
1200
1201 ctx->compositor = compositor;
1202 ctx->controller_interface = iface;
1203
1204 loop = wl_display_get_event_loop(compositor->wl_display);
1205 wl_event_loop_add_idle(loop, run_internal_tests, ctx);
1206
1207 return 0;
1208}