Correction additional about "Removed system controller."
[profile/ivi/ico-uxf-homescreen.git] / tests / apps-framework / tst_userctl.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 User Control API
11  *
12  * @date    Sep-5-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_userctl.h"
25
26 #include "tst_common.h"
27
28 /* ----------------------------------------------- */
29 /* Variable                                        */
30 /* ----------------------------------------------- */
31
32 /* ----------------------------------------------- */
33 /* Define of static function                       */
34 /* ----------------------------------------------- */
35 static void _check_userlist(const char *ev_name, ico_syc_userlist_t *list);
36 static void _syc_callback(const ico_syc_ev_e event,
37                           const void *detail, void *user_data);
38 static void tst_change_user(void);
39 static void tst_get_userlist(void);
40 static void tst_get_lastinfo(void);
41 static void tst_set_lastinfo(void);
42 static Eina_Bool  ico_syc_userctl_test(void *data);
43
44 /* ----------------------------------------------- */
45 /* Public API Test                                 */
46 /* ----------------------------------------------- */
47 static void
48 _check_userlist(const char *ev_name, ico_syc_userlist_t *list)
49 {
50     int check_flag = 0;
51     char *name;
52     int id;
53
54     printf("--- %s userlist[%d] (", ev_name, list->user_num);
55     for (id = 0; id < list->user_num; id++) {
56         if (id > 0) printf(", ");
57         name = *(list->userlist);
58         printf("%s", name);
59         if (strcmp(name, TST_USER_A) != 0 && strcmp(name, TST_USER_B) != 0
60             && strcmp(name, TST_USER_C) != 0) {
61             check_flag++;
62         }
63         list->userlist++;
64     }
65     printf("), login[%s]\n", list->user_login);
66
67     if (strcmp(list->user_login, TST_USER_A) != 0) {
68         check_flag++;
69     }
70
71     if (check_flag == 0) {
72         print_ok("callback (%s)", ev_name);
73     }
74     else {
75         print_ng("callback (%s)", ev_name);
76     }
77
78     return;
79 }
80
81 static void
82 _syc_callback(const ico_syc_ev_e event,
83               const void *detail, void *user_data)
84 {
85     switch (event) {
86     case ICO_SYC_EV_USERLIST:
87         _check_userlist("ICO_SYC_EV_USERLIST", (ico_syc_userlist_t *)detail);
88         break;
89     case ICO_SYC_EV_AUTH_FAIL:
90         if (detail == NULL) {
91             printf("--- ICO_SYC_EV_AUTH_FAIL (detail is NULL)\n");
92             print_ok("callback (ICO_SYC_EV_AUTH_FAIL)");
93         }
94         else {
95             printf("--- ICO_SYC_EV_AUTH_FAIL (detail is not NULL)\n");
96             print_ng("callback (ICO_SYC_EV_AUTH_FAIL)");
97         }
98         break;
99     case ICO_SYC_EV_LASTINFO:
100         printf("--- lastinfo: %s\n", (char *)detail);
101         if (strcmp((char *)detail, TST_LASTINFO) == 0) {
102             print_ok("callback (ICO_SYC_EV_LASTINFO)");
103         }
104         else {
105             print_ng("callback (ICO_SYC_EV_LASTINFO)");
106         }
107         break;
108     default:
109         break;
110     }
111
112     return;
113 }
114
115 /* test change user */
116 static void
117 tst_change_user(void)
118 {
119     (void)ico_syc_change_user("Alice", "");
120     print_ok("(void)ico_syc_change_user");
121
122     return;
123 }
124
125 /* test get userlist */
126 static void
127 tst_get_userlist(void)
128 {
129     (void)ico_syc_get_userlist();
130     print_ok("(void)ico_syc_get_userlist");
131
132     return;
133 }
134
135 /* test get lastinfo */
136 static void
137 tst_get_lastinfo(void)
138 {
139     (void)ico_syc_get_lastinfo();
140     print_ok("(void)ico_syc_get_lastinfo");
141
142     return;
143 }
144
145 /* test set lastinfo */
146 static void
147 tst_set_lastinfo(void)
148 {
149     (void)ico_syc_set_lastinfo(TST_LASTINFO);
150     print_ok("(void)ico_syc_set_lastinfo");
151
152     return;
153 }
154
155 /* test main */
156 static Eina_Bool 
157 ico_syc_userctl_test(void *data)
158 {
159     printf("\n");
160     printf("##### ico_syc_userctl API Test Start #####\n");
161
162     tst_change_user();
163     usleep(5000);
164     tst_get_userlist();
165     usleep(5000);
166     tst_set_lastinfo();
167     usleep(5000);
168     tst_get_lastinfo();
169
170     printf("##### ico_syc_userctl API Test End #####\n");
171     printf("\n");
172
173     return ECORE_CALLBACK_CANCEL;
174 }
175
176 /* ------------------------ */
177 /* quit test callback       */
178 /* ------------------------ */
179 static Eina_Bool
180 quit_test(void *data)
181 {
182     ico_syc_disconnect();
183     ecore_main_loop_quit();
184
185     return ECORE_CALLBACK_CANCEL;
186 }
187
188 /* ----------------------------------------------- */
189 /* Main                                            */
190 /* ----------------------------------------------- */
191 /* main */
192 int
193 main(int argc, char **argv)
194 {
195     ecore_init();
196
197     ico_syc_connect(_syc_callback, NULL);
198
199     ecore_timer_add(1, ico_syc_userctl_test, NULL);
200     ecore_timer_add(5, quit_test, NULL);
201
202     ecore_main_loop_begin();
203     ecore_shutdown();
204
205     return 0;
206 }
207 /* vim: set expandtab ts=4 sw=4: */