Correction additional about "Removed system controller."
[profile/ivi/ico-uxf-homescreen.git] / tests / apps-framework / tst_appresctl.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 App Resource Control API
11  *
12  * @date    Aug-6-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_appresctl.h"
24 #include "ico_syc_common.h"
25
26 #include "tst_common.h"
27
28 /* ----------------------------------------------- */
29 /* Variable                                        */
30 /* ----------------------------------------------- */
31 static struct ico_syc_res_context *res_context  = NULL;
32
33 /* ----------------------------------------------- */
34 /* Define of static function                       */
35 /* ----------------------------------------------- */
36 static void _check_res_info(const char *ev_name, ico_syc_res_info_t *info);
37 static void _check_input_region(const char *ev_name,
38                                 ico_syc_input_region_t *region);
39 static void _syc_callback(const ico_syc_ev_e event,
40                           const void *detail, void *user_data);
41 static void tst_acquire_res(const ico_syc_res_window_t *window,
42                             const ico_syc_res_sound_t *sound,
43                             const ico_syc_res_input_t *input,
44                             int type);
45 static void tst_release_res(void);
46 static void tst_set_input_region(const ico_syc_input_region_t *region, int attr);
47 static void tst_unset_input_region(const ico_syc_input_region_t *region);
48 static Eina_Bool ico_syc_appresctl_test(void *data);
49
50 /* ----------------------------------------------- */
51 /* Public API Test                                 */
52 /* ----------------------------------------------- */
53 static void
54 _check_res_info(const char *ev_name, ico_syc_res_info_t *info)
55 {
56     ico_syc_res_window_t *window = NULL;
57     ico_syc_res_sound_t *sound   = NULL;
58     ico_syc_res_input_t *input   = NULL;
59     int check_flag = 0;
60
61     printf("--- %s\n", ev_name);
62
63     window = info->window;
64     sound = info->sound;
65     input = info->input;
66     if (window != NULL) {
67         ico_syc_res_window_t *w = window;
68         printf("\t(window ECU[%s].display[%s].layer[%s].layout[%s].area[%s], app[%s], role[%s], resId[%d]",
69                w->ECU, w->display, w->layer, w->layout, w->area,
70                w->dispatchApp, w->role, w->resourceId);
71
72         if ((0 != strcmp(w->ECU,         TST_ECU)) ||
73             (0 != strcmp(w->display,     TST_display)) ||
74             (0 != strcmp(w->layer,       TST_layer)) ||
75             (0 != strcmp(w->layout,      TST_layout)) ||
76             (0 != strcmp(w->area,        TST_area)) ||
77             (0 != strcmp(w->dispatchApp, TST_dispatchApp)) ||
78             (0 != strcmp(w->role,        TST_role)) ||
79             (w->resourceId != TST_resourceId)) {
80             check_flag = 1;
81         }
82     }
83     if (sound != NULL) {
84         printf("\t sound zone[%s], name[%s], id[%s], adjust[%d]\n",
85                sound->zone, sound->name, sound->id, sound->adjust);
86         if (strcmp(sound->zone, TST_ZONE_B) != 0
87             || strcmp(sound->name, TST_NAME_B) != 0
88             || strcmp(sound->id, TST_ID_B) != 0
89             || sound->adjust != TST_ADJUST) {
90             check_flag = 1;
91         }
92     }
93     if (input != NULL) {
94         printf("\t input name[%s], event[%d])\n", input->name, input->event);
95         if (strcmp(input->name, TST_NAME_C) != 0
96             || input->event != TST_INPUT_EV) {
97             check_flag = 1;
98         }
99     }
100
101     if (check_flag == 0) {
102         print_ok("callback (%s)", ev_name);
103     }
104     else {
105         print_ng("callback (%s)", ev_name);
106     }
107
108     return;
109 }
110
111 static void
112 _check_input_region(const char *ev_name, ico_syc_input_region_t *region)
113 {
114     printf("--- %s\n", ev_name);
115     printf("\t(winname[%s], (x,y)[%d, %d], width[%d], height[%d], hot[%d,%d], "
116            "cursor[%d.%d-%d,%d], attr[%d])\n",
117            region->winname, region->pos_x, region->pos_y,
118            region->width, region->height, region->hotspot_x, region->hotspot_y,
119            region->cursor_x, region->cursor_y, region->cursor_width,
120            region->cursor_height, region->attr);
121
122     if ((strcmp(region->winname, TST_WIN_NAME) == 0)
123         && region->pos_x == TST_POS_X && region->pos_y == TST_POS_Y
124         && region->width == TST_REG_WIDTH && region->height == TST_REG_HEIGHT
125         && region->hotspot_x == TST_REG_HOT_X && region->hotspot_y == TST_REG_HOT_Y
126         && region->cursor_x == TST_REG_CUR_X && region->cursor_y == TST_REG_CUR_Y
127         && region->cursor_width == TST_REG_CUR_WIDTH
128         && region->cursor_height == TST_REG_CUR_HEIGHT
129         && region->attr == TST_REG_ATTR)    {
130         print_ok("callback (%s)", ev_name);
131     }
132     else {
133         print_ng("callback (%s)", ev_name);
134     }
135
136     return;
137 }
138
139 static void
140 _syc_callback(const ico_syc_ev_e event,
141               const void *detail, void *user_data)
142 {
143     switch (event) {
144     case ICO_SYC_EV_RES_ACQUIRE:
145         _check_res_info("ICO_SYC_EV_RES_ACQUIRE", (ico_syc_res_info_t *)detail);
146         break;
147     case ICO_SYC_EV_RES_DEPRIVE:
148         _check_res_info("ICO_SYC_EV_RES_DEPRIVE", (ico_syc_res_info_t *)detail);
149         break;
150     case ICO_SYC_EV_RES_WAITING:
151         _check_res_info("ICO_SYC_EV_RES_WAITING", (ico_syc_res_info_t *)detail);
152         break;
153     case ICO_SYC_EV_RES_REVERT:
154         _check_res_info("ICO_SYC_EV_RES_REVERT", (ico_syc_res_info_t *)detail);
155         break;
156     case ICO_SYC_EV_RES_RELEASE:
157         _check_res_info("ICO_SYC_EV_RES_RELEASE", (ico_syc_res_info_t *)detail);
158         break;
159     case ICO_SYC_EV_INPUT_SET:
160         _check_input_region("ICO_SYC_EV_INPUT_SET",
161                             (ico_syc_input_region_t *)detail);
162         break;
163     case ICO_SYC_EV_INPUT_UNSET:
164         _check_input_region("ICO_SYC_EV_INPUT_UNSET",
165                             (ico_syc_input_region_t *)detail);
166         break;
167     default:
168         break;
169     }
170
171     return;
172 }
173
174 /* test acquire resource */
175 static void
176 tst_acquire_res(const ico_syc_res_window_t *window,
177                 const ico_syc_res_sound_t *sound,
178                 const ico_syc_res_input_t *input,
179                 int type)
180 {
181     char *func = "ico_syc_acquire_res";
182
183     res_context = ico_syc_acquire_res(window, sound, input, type);
184     if (res_context == NULL) {
185         print_ng("%s (context is NULL)", func);
186         return;
187     }
188     print_ok("%s", func);
189
190     return;
191 }
192
193 /* test release resource */
194 static void
195 tst_release_res(void)
196 {
197     int ret;
198     char *func = "ico_syc_release_res";
199
200     ret = ico_syc_release_res(res_context);
201     if (ret != 0) {
202         print_ng("%s (ret: %d)", func, ret);
203         return;
204     }
205     print_ok("%s", func);
206
207     return;
208 }
209
210 /* test set input region */
211 static void
212 tst_set_input_region(const ico_syc_input_region_t *region, int attr)
213 {
214     int ret;
215     char *func = "ico_syc_set_input_region";
216
217     ret = ico_syc_set_input_region(region, attr);
218     if (ret != 0) {
219         print_ng("%s (ret: %d)", func, ret);
220         return;
221     }
222     print_ok("%s", func);
223
224     return;
225 }
226
227 /* test unset input region */
228 static void
229 tst_unset_input_region(const ico_syc_input_region_t *region)
230 {
231     int ret;
232     char *func = "ico_syc_unset_input_region";
233
234     ret = ico_syc_unset_input_region(region);
235     if (ret != 0) {
236         print_ng("%s (ret: %d)", func, ret);
237         return;
238     }
239     print_ok("%s", func);
240
241     return;
242 }
243
244 /* ------------------------ */
245 /* test main                */
246 /* ------------------------ */
247 static 
248 Eina_Bool ico_syc_appresctl_test(void *data)
249 {
250     printf("\n");
251     printf("##### ico_syc_appresctl API Test Start #####\n");
252
253     /* window/sound resource */
254     ico_syc_res_window_t window;
255     ico_syc_res_sound_t sound;
256     int type            = ICO_SYC_RES_BASIC;
257     /* input resource */
258     ico_syc_res_input_t input;
259     /* input region */
260     ico_syc_input_region_t region;
261     int attr            = 1;
262
263     /* set window resource info */
264     window.ECU         = "Center";
265     window.display     = "Center";
266     window.layer       = "OnScreen";
267     window.layout      = "Full";
268     window.area        = "Full";
269     window.dispatchApp = "zzzzzzzz";
270     window.role        = "Message";
271     window.resourceId  = 8888;
272     /* set sound resource info */
273     sound.zone          = "all";
274     sound.name          = "sound B";
275     sound.id            = "id B";
276     sound.adjust        = ICO_SYC_SOUND_MUTE;
277     /* set sound resource info */
278     input.name          = "input C";
279     input.event         = 100;
280     /* set input region info */
281     strcpy(region.winname, TST_WIN_NAME);
282     region.pos_x        = 10;
283     region.pos_y        = 10;
284     region.width        = 200;
285     region.height       = 100;
286     region.hotspot_x    = 28;
287     region.hotspot_y    = 16;
288     region.cursor_x     = 35;
289     region.cursor_y     = 25;
290     region.cursor_width = 150;
291     region.cursor_height= 80;
292     region.attr         = 98765432;
293
294     /* acquire window/sound/input */
295     tst_acquire_res((const ico_syc_res_window_t *)&window,
296                     (const ico_syc_res_sound_t *)&sound,
297                     (const ico_syc_res_input_t *)&input,
298                     type);
299     usleep(5000);
300     /* set input region */
301     tst_set_input_region(&region, attr);
302
303     sleep(2);
304
305     /* release window/sound/input */
306     tst_release_res();
307     usleep(5000);
308     /* unset input region */
309     tst_unset_input_region(&region);
310
311     sleep(3);
312
313     printf("##### ico_syc_appresctl API Test End #####\n");
314     printf("\n");
315
316
317     return ECORE_CALLBACK_CANCEL;
318 }
319
320 /* ------------------------ */
321 /* quit test callback       */
322 /* ------------------------ */
323 static Eina_Bool
324 quit_test(void *data)
325 {
326     ico_syc_disconnect();
327     ecore_main_loop_quit();
328
329     return ECORE_CALLBACK_CANCEL;
330 }
331
332 /* ----------------------------------------------- */
333 /* Main                                            */
334 /* ----------------------------------------------- */
335 /* main */
336 int
337 main(int argc, char **argv)
338 {
339     ecore_init();
340
341     ico_syc_connect(_syc_callback, NULL);
342
343     ecore_timer_add(1, ico_syc_appresctl_test, NULL);
344     ecore_timer_add(5, quit_test, NULL);
345
346     ecore_main_loop_begin();
347     ecore_shutdown();
348
349     return 0;
350 }
351 /* vim: set expandtab ts=4 sw=4: */