blob: befdf94fc637621bcc64f6770359cbb8dbfbe00a [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 */
66
67static 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
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200704/************************ tests end ********************************/
705
706static void
707run_internal_tests(void *data)
708{
709 struct test_context *ctx = data;
710
711 test_surface_bad_visibility(ctx);
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +0900712 test_surface_bad_destination_rectangle(ctx);
713 test_surface_bad_orientation(ctx);
714 test_surface_bad_dimension(ctx);
715 test_surface_bad_position(ctx);
716 test_surface_bad_source_rectangle(ctx);
717 test_surface_bad_properties(ctx);
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200718
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900719 test_layer_create(ctx);
720 test_layer_visibility(ctx);
721 test_layer_opacity(ctx);
722 test_layer_orientation(ctx);
723 test_layer_dimension(ctx);
724 test_layer_position(ctx);
725 test_layer_destination_rectangle(ctx);
726 test_layer_source_rectangle(ctx);
Nobuhiko Tanibata17d44942015-06-22 15:35:12 +0900727 test_layer_bad_remove(ctx);
728 test_layer_bad_visibility(ctx);
729 test_layer_bad_opacity(ctx);
730 test_layer_bad_destination_rectangle(ctx);
731 test_layer_bad_orientation(ctx);
732 test_layer_bad_dimension(ctx);
733 test_layer_bad_position(ctx);
734 test_layer_bad_source_rectangle(ctx);
735 test_layer_bad_properties(ctx);
736 test_commit_changes_after_visibility_set_layer_destroy(ctx);
737 test_commit_changes_after_opacity_set_layer_destroy(ctx);
738 test_commit_changes_after_orientation_set_layer_destroy(ctx);
739 test_commit_changes_after_dimension_set_layer_destroy(ctx);
740 test_commit_changes_after_position_set_layer_destroy(ctx);
741 test_commit_changes_after_source_rectangle_set_layer_destroy(ctx);
742 test_commit_changes_after_destination_rectangle_set_layer_destroy(ctx);
743 test_layer_create_duplicate(ctx);
744 test_get_layer_after_destory_layer(ctx);
Nobuhiko Tanibata9e992d92015-06-22 15:34:18 +0900745
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200746 weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
747 free(ctx);
748}
749
750int
751controller_module_init(struct weston_compositor *compositor,
752 int *argc, char *argv[],
753 const struct ivi_controller_interface *iface,
754 size_t iface_version);
755
756WL_EXPORT int
757controller_module_init(struct weston_compositor *compositor,
758 int *argc, char *argv[],
759 const struct ivi_controller_interface *iface,
760 size_t iface_version)
761{
762 struct wl_event_loop *loop;
763 struct test_context *ctx;
764
765 /* strict check, since this is an internal test module */
766 if (iface_version != sizeof(*iface)) {
767 weston_log("fatal: controller interface mismatch\n");
768 return -1;
769 }
770
771 ctx = zalloc(sizeof(*ctx));
772 if (!ctx)
773 return -1;
774
775 ctx->compositor = compositor;
776 ctx->controller_interface = iface;
777
778 loop = wl_display_get_event_loop(compositor->wl_display);
779 wl_event_loop_add_idle(loop, run_internal_tests, ctx);
780
781 return 0;
782}