Correction additional about "Removed system controller."
[profile/ivi/ico-uxf-homescreen.git] / tests / apps-framework / tst_winctl.c
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   test suite for Window Control API
11  *
12  * @date    Aug-19-2013
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <unistd.h>
19
20 #include <Ecore.h>
21 #include <Eina.h>
22
23 #include "ico_syc_common.h"
24 #include "ico_syc_winctl.h"
25
26 #include "tst_common.h"
27
28 /* ----------------------------------------------- */
29 /* Variable                                        */
30 /* ----------------------------------------------- */
31
32
33 /* ----------------------------------------------- */
34 /* Define of static function                       */
35 /* ----------------------------------------------- */
36 static void _check_win_info(const char *ev_name, ico_syc_win_info_t *info);
37 static void _check_win_attr(const char *ev_name, ico_syc_win_attr_t *attr);
38 static void _check_thumb_info(const char *ev_name, ico_syc_thumb_info_t *info);
39 static void _check_layer_attr(const char *ev_name, ico_syc_layer_attr_t *attr);
40 /* callback */
41 static void _syc_callback(const ico_syc_ev_e event,
42                           const void *detail, void *user_data);
43 /* window */
44 static void tst_show(const char *appid, int surface,
45                      ico_syc_animation_t *animation);
46 static void tst_hide(const char *appid, int surface,
47                      ico_syc_animation_t *animation);
48 static void tst_move(const char *appid, int surface,
49                      ico_syc_win_move_t *move,
50                      ico_syc_animation_t *animation, const char *type);
51 static void tst_change_active(const char *appid, int surface);
52 static void tst_change_layer(const char *appid, int surface, int layer);
53 /* thumbnail */
54 static void tst_map_thumb(int surface, int framerate);
55 static void tst_unmap_thumb(int surface);
56 /* layer */
57 static void tst_show_layer(int layer);
58 static void tst_hide_layer(int layer);
59 /* test main */
60 static Eina_Bool ico_syc_winctl_test(void *data);
61
62 /* ----------------------------------------------- */
63 /* Public API Test                                 */
64 /* ----------------------------------------------- */
65 static void 
66 _check_win_info(const char *ev_name, ico_syc_win_info_t *info)
67 {
68     printf("--- %s ", ev_name);
69     printf("(appid[%s], name[%s], surface[%d])\n",
70            info->appid, info->name, info->surface);
71
72     if (strcmp(info->appid, TST_APPID) == 0
73         && strcmp(info->name, TST_WIN_NAME) == 0
74         && info->surface == TST_SURFACE) {
75         print_ok("callback (%s)", ev_name);
76     }
77     else {
78         print_ng("callback (%s)", ev_name);
79     }
80
81     return;
82 }
83
84 static void
85 _check_win_attr(const char *ev_name, ico_syc_win_attr_t *attr)
86 {
87     printf("--- %s\n", ev_name);
88     printf("\t(appid[%s], name[%s], surface[%d], node[%d], layer[%d],\n",
89            attr->appid, attr->name, attr->surface, attr->nodeid, attr->layer);
90     printf("\t (x,y)[%d, %d], width[%d], height[%d], ",
91            attr->pos_x, attr->pos_y, attr->width, attr->height);
92     printf("raise[%d], visible[%d], active[%d])\n",
93            attr->raise, attr->visible, attr->active);
94
95     // move
96     if (strcmp(attr->name, "move") == 0) {
97         if ((attr->pos_x > 0) && (attr->pos_y > 0)) {
98             print_ok("callback (%s move (pos))", ev_name);
99         }
100         else {
101             print_ok("callback (%s move (zone))", ev_name);
102         }
103         return;
104     }
105
106     // not move
107     if (strcmp(attr->appid, TST_APPID) == 0
108         && attr->surface == TST_SURFACE && attr->nodeid == TST_NODE
109         && attr->layer == TST_LAYER && attr->pos_x == TST_POS_X
110         && attr->pos_y == TST_POS_Y && attr->width == TST_WIDTH
111         && attr->height == TST_HEIGHT && attr->raise == TST_RAISE
112         && attr->visible == TST_VISIBLE && attr->active == TST_ACTIVE) {
113         print_ok("callback (%s %s)", ev_name, attr->name);
114     }
115     else {
116         print_ng("callback (%s %s)", ev_name, attr->name);
117     }
118
119     return;
120 }
121
122 static void 
123 _check_thumb_info(const char *ev_name, ico_syc_thumb_info_t *info)
124 {
125     printf("--- %s ", ev_name);
126     printf("\t(appid[%s], surface[%d], width[%d], height[%d], ",
127            info->appid, info->surface, info->width, info->height);
128     printf("stride[%d], format[%d])\n",
129            info->stride, info->format);
130
131     if (strcmp(info->appid, TST_APPID) == 0
132         && info->surface == TST_SURFACE
133         && info->width == TST_WIDTH && info->height == TST_HEIGHT
134         && info->stride == TST_STRIDE && info->format == TST_FORMAT) {
135         print_ok("callback (%s)", ev_name);
136     }
137     else {
138         print_ng("callback (%s)", ev_name);
139     }
140
141     return;
142 }
143
144 static void 
145 _check_layer_attr(const char *ev_name, ico_syc_layer_attr_t *attr)
146 {
147     printf("--- %s ", ev_name);
148     printf("(layer[%d], visible[%d])\n",
149            attr->layer, attr->visible);
150
151     if (attr->layer == TST_LAYER && attr->visible == TST_VISIBLE) {
152         print_ok("callback (%s show)", ev_name);
153     }
154     else if (attr->layer == TST_LAYER && attr->visible == TST_INVISIBLE) {
155         print_ok("callback (%s hide)", ev_name);
156     }
157     else {
158         print_ng("callback (%s)", ev_name);
159     }
160
161     return;
162 }
163
164 static void
165 _syc_callback(const ico_syc_ev_e event,
166               const void *detail, void *user_data)
167 {
168
169     switch (event) {
170     case ICO_SYC_EV_WIN_CREATE:
171         _check_win_info("ICO_SYC_EV_WIN_CREATE", (ico_syc_win_info_t *)detail);
172         break;
173     case ICO_SYC_EV_WIN_DESTROY:
174         _check_win_info("ICO_SYC_EV_WIN_DESTROY", (ico_syc_win_info_t *)detail);
175         break;
176     case ICO_SYC_EV_WIN_ACTIVE:
177         _check_win_info("ICO_SYC_EV_WIN_ACTIVE", (ico_syc_win_info_t *)detail);
178         break;
179     case ICO_SYC_EV_WIN_ATTR_CHANGE:
180         _check_win_attr("ICO_SYC_EV_WIN_ATTR_CHANGE",
181                         (ico_syc_win_attr_t *)detail);
182         break;
183     case ICO_SYC_EV_THUMB_ERROR:
184         _check_thumb_info("ICO_SYC_EV_THUMB_ERROR",
185                           (ico_syc_thumb_info_t *)detail);
186         break;
187     case ICO_SYC_EV_THUMB_CHANGE:
188         _check_thumb_info("ICO_SYC_EV_THUMB_CHANGE",
189                           (ico_syc_thumb_info_t *)detail);
190         break;
191     case ICO_SYC_EV_THUMB_UNMAP:
192         _check_thumb_info("ICO_SYC_EV_THUMB_UNMAP",
193                           (ico_syc_thumb_info_t *)detail);
194         break;
195     case ICO_SYC_EV_LAYER_ATTR_CHANGE:
196         _check_layer_attr("ICO_SYC_EV_LAYER_ATTR_CHANGE",
197                           (ico_syc_layer_attr_t *)detail);
198         break;
199     default:
200         break;
201     }
202
203     return;
204 }
205
206 /* test show window */
207 static void
208 tst_show(const char *appid, int surface, ico_syc_animation_t *animation)
209 {
210     int ret;
211     char *func = "ico_syc_show";
212
213     ret = ico_syc_show(appid, surface, animation);
214     if (ret != 0) {
215         print_ng("%s (ret: %d)", func, ret);
216         return;
217     } 
218     print_ok("%s", func);
219
220     return;
221 }
222
223 /* test hide window */
224 static void
225 tst_hide(const char *appid, int surface, ico_syc_animation_t *animation)
226 {
227     int ret;
228     char *func = "ico_syc_hide";
229
230     ret = ico_syc_hide(appid, surface, animation);
231     if (ret != 0) {
232         print_ng("%s (ret: %d)", func, ret);
233         return;
234     } 
235     print_ok("%s", func);
236
237     return;
238 }
239
240 /* test move window */
241 static void
242 tst_move(const char *appid, int surface,
243          ico_syc_win_move_t *move,
244          ico_syc_animation_t *animation, const char *type)
245 {
246     int ret;
247     char *func = "ico_syc_move";
248
249     ret = ico_syc_move(appid, surface, move, animation);
250     if (ret != 0) {
251         print_ng("%s (%s) (ret: %d)", func, type, ret);
252         return;
253     } 
254     print_ok("%s (%s)", func, type);
255
256     return;
257 }
258
259 /* test change active window */
260 static void
261 tst_change_active(const char *appid, int surface)
262 {
263     int ret;
264     char *func = "ico_syc_change_active";
265
266     ret = ico_syc_change_active(appid, surface);
267     if (ret != 0) {
268         print_ng("%s (ret: %d)", func, ret);
269         return;
270     } 
271     print_ok("%s", func);
272
273     return;
274 }
275
276 /* test change window layer */
277 static void
278 tst_change_layer(const char *appid, int surface, int layer)
279 {
280     int ret;
281     char *func = "ico_syc_change_layer";
282
283     ret = ico_syc_change_layer(appid, surface, layer);
284     if (ret != 0) {
285         print_ng("%s (ret: %d)", func, ret);
286         return;
287     } 
288     print_ok("%s", func);
289
290     return;
291 }
292
293 /* test map thumbnail */
294 static void
295 tst_map_thumb(int surface, int framerate)
296 {
297     int ret;
298     char *func = "ico_syc_map_thumb";
299
300     ret = ico_syc_map_thumb(surface, framerate, " ");
301     if (ret != 0) {
302         print_ng("%s (ret: %d)", func, ret);
303         return;
304     } 
305     print_ok("%s", func);
306
307     return;
308 }
309
310 /* test unmap thumbnail */
311 static void
312 tst_unmap_thumb(int surface)
313 {
314     int ret;
315     char *func = "ico_syc_unmap_thumb";
316
317     ret = ico_syc_unmap_thumb(surface);
318     if (ret != 0) {
319         print_ng("%s (ret: %d)", func, ret);
320         return;
321     } 
322     print_ok("%s", func);
323
324     return;
325 }
326
327 /* test show layer */
328 static void
329 tst_show_layer(int layer)
330 {
331     int ret;
332     char *func = "ico_syc_show_layer";
333
334     ret = ico_syc_show_layer(layer);
335     if (ret != 0) {
336         print_ng("%s (ret: %d)", func, ret);
337         return;
338     } 
339     print_ok("%s", func);
340
341     return;
342 }
343
344 /* test hide layer */
345 static void
346 tst_hide_layer(int layer)
347 {
348     int ret;
349     char *func = "ico_syc_hide_layer";
350
351     ret = ico_syc_hide_layer(layer);
352     if (ret != 0) {
353         print_ng("%s (ret: %d)", func, ret);
354         return;
355     } 
356     print_ok("%s", func);
357
358     return;
359 }
360
361 /* ------------------------------- */
362 /* test main                       */
363 /* ------------------------------- */
364 static Eina_Bool
365 ico_syc_winctl_test(void *data)
366 {
367     const char *appid   = "org.test.app.testapp";
368     int surface         = 98765;
369     int layer           = 5;
370     ico_syc_win_move_t move, move_pos;
371     ico_syc_animation_t animation;
372
373     printf("\n");
374     printf("##### ico_syc_winctl API Test Start #####\n");
375
376     /* set move info (zone) */
377     move.zone = "center:bottom";
378     move.width = ICO_SYC_WIN_NOCHANGE;
379     move.height = 600;
380     /* set move info (position) */
381     move_pos.zone = NULL;
382     move_pos.pos_x = 10;
383     move_pos.pos_y = 20;
384     move_pos.width = 1024;
385     move_pos.height = ICO_SYC_WIN_NOCHANGE;
386
387     /* set animation data */
388     animation.name = "fade";
389     animation.time = 200;
390
391     /* window */
392     tst_show(appid, surface, &animation);
393     usleep(5000);
394     tst_hide(appid, surface, NULL);
395     usleep(5000);
396     tst_move(appid, surface, &move, &animation, "zone");
397     usleep(5000);
398     tst_move(appid, surface, &move_pos, NULL, "pos");
399     usleep(5000);
400     tst_change_active(appid, surface);
401     usleep(5000);
402     tst_change_layer(appid, surface, layer);
403
404     sleep(1);
405
406     /* thumbnail */
407     tst_map_thumb(surface, 200);
408     usleep(5000);
409     tst_unmap_thumb(surface);
410
411     sleep(1);
412
413     /* layer */
414     tst_show_layer(layer);
415     usleep(5000);
416     tst_hide_layer(layer);
417
418     printf("##### ico_syc_winctl API Test End #####\n");
419     printf("\n");
420
421     return ECORE_CALLBACK_CANCEL;
422 }
423
424 /* ------------------------ */
425 /* quit test callback       */
426 /* ------------------------ */
427 static Eina_Bool
428 quit_test(void *data)
429 {
430     ico_syc_disconnect();
431     ecore_main_loop_quit();
432
433     return ECORE_CALLBACK_CANCEL;
434 }
435
436 /* ----------------------------------------------- */
437 /* Main                                            */
438 /* ----------------------------------------------- */
439 /* main */
440 int
441 main(int argc, char **argv)
442 {
443     ecore_init();
444
445     ico_syc_connect(_syc_callback, NULL);
446
447     ecore_timer_add(1, ico_syc_winctl_test, NULL);
448     ecore_timer_add(5, quit_test, NULL);
449
450     ecore_main_loop_begin();
451     ecore_shutdown();
452
453     return 0;
454 }
455 /* vim: set expandtab ts=4 sw=4: */