Tizen 2.1 base
[platform/core/system/sync-agent.git] / test / client / oma-dm / oma_dm_client.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <glib.h>
21
22 #define COMPONENT_TAG APP
23 #define LOG_TAG "OMA_DM_CLIENT"
24
25 #include <sync_agent.h>
26
27 #define SMASUNG_SERVER "RSate"
28 #define SESSION_ID      "11111"
29
30 GMainLoop *g_mainloop;
31 gchar g_policy_type[256];
32 static int selected_ui_num = -1;
33
34 static gboolean _process_cmd_input(GIOChannel * gio, GIOCondition condition, gpointer data);
35 static void _select_ui_input();
36
37 static void _print_admin_ui_test();
38 static void _print_alert_ui_test();
39 static void _print_cp_ui_test();
40 static void _print_fota_ui_test();
41 static void _print_noti_ui_test();
42 static void _print_reg_ui_test();
43 static void _printf_dmacc_control_ui_test();
44
45 /* Admin wrapping test api */
46 static gboolean __test_admin_get_fumo_config();
47 static gboolean __test_admin_set_fumo_config();
48 static gboolean __test_admin_get_profile();
49 static gboolean __test_admin_set_profile();
50 static gboolean __test_admin_reset_profile();
51 static gboolean __test_admin_user_initiate();
52
53 /* Alert wrapping test api */
54 /*static gboolean __test_alert_display();*/
55 static gboolean __test_alert_confirmation();
56 static gboolean __test_alert_inputtext();
57 static gboolean __test_alert_single_choice();
58 static gboolean __test_alert_multiple_choice();
59
60 /* CP wrapping test api */
61 static gboolean __test_cp_check_pin_code();
62
63 /* Fota wrapping test api */
64 static gboolean __test_fota_software_update();
65 static gboolean __test_fota_cancel();
66 static gboolean __test_fota_download();
67 static gboolean __test_fota_install();
68 static gboolean __test_fota_set_interval();
69
70 /* Noti wrapping test api */
71 static gboolean __test_noti_software_update();
72 static gboolean __test_noti_cancel();
73 static gboolean __test_noti_download();
74 static gboolean __test_noti_install();
75 static gboolean __test_noti_set_interval();
76
77 /* Registration wrapping test api */
78 static gboolean __test_reg_account_registration();
79
80 /* Add/Remove Dmacc */
81 static gboolean __test_add_dmacc();
82 static gboolean __test_remove_dmacc();
83
84 static gboolean _process_cmd_input(GIOChannel * gio, GIOCondition condition, gpointer data)
85 {
86         _INNER_FUNC_ENTER;
87
88         gsize read;
89         gchar *buf;
90         GError *error;
91
92         buf = g_policy_type;
93
94         /* Reads data from a GIOChannel. */
95         GIOError status = g_io_channel_read(gio, buf, 256, &read);
96         retvm_if(status != G_IO_ERROR_NONE, FALSE, "Error reading:");
97         _DEBUG_TRACE("read data : %s (size : %d)", buf, read);
98
99         buf[read] = '\0';
100
101         /* Removes leading and trailing whitespace from a string. */
102         g_strstrip(buf);
103
104         _DEBUG_TRACE("user input cmd is %s", buf);
105
106         if (buf[0] == '0') {
107                 // quit g main loop
108                 _DEBUG_TRACE("exiting...");
109                 g_main_loop_quit(g_mainloop);
110         } else {
111                 switch (selected_ui_num) {
112                         _DEBUG_TRACE("buf[0] : %c", buf[0]);
113                 case 1: /* Admin UI */
114                         {
115                                 switch (buf[0]) {
116                                         gboolean test_result = FALSE;
117                                 case '1':
118                                         {
119                                                 test_result = __test_admin_get_fumo_config();
120                                                 printf("Admin UI - get fumo config : result = %s\n\n", test_result ? "success" : "fail");
121                                         }
122                                         break;
123                                 case '2':
124                                         {
125                                                 test_result = __test_admin_set_fumo_config();
126                                                 printf("Admin UI - set fumo config : result = %s\n\n", test_result ? "success" : "fail");
127                                         }
128                                         break;
129                                 case '3':
130                                         {
131                                                 test_result = __test_admin_get_profile();
132                                                 printf("Admin UI - get profile : result = %s\n\n", test_result ? "success" : "fail");
133                                         }
134                                         break;
135                                 case '4':
136                                         {
137                                                 test_result = __test_admin_set_profile();
138                                                 printf("Admin UI - set profile : result = %s\n\n", test_result ? "success" : "fail");
139                                         }
140                                         break;
141                                 case '5':
142                                         {
143                                                 test_result = __test_admin_reset_profile();
144                                                 printf("Admin UI - reset profile : result = %s\n\n", test_result ? "success" : "fail");
145                                         }
146                                         break;
147                                 case '6':
148                                         {
149                                                 test_result = __test_admin_user_initiate();
150                                                 printf("Admin UI - user initiate : result = %s\n\n", test_result ? "success" : "fail");
151                                         }
152                                         break;
153                                 default:
154                                         _DEBUG_TRACE("Admin UI - Wrong Choice: enter your choice again...");
155                                         break;
156                                 }
157
158                                 // display menu
159                                 _print_admin_ui_test();
160                         }
161                         break;
162                 case 2: /* Alert UI */
163                         {
164                                 switch (buf[0]) {
165                                         gboolean test_result = FALSE;
166                                 case '1':
167                                         {
168                                                 /*test_result = __test_alert_display(); */
169                                                 /*do not push event */
170                                                 printf("Alert UI - display : result = success");
171                                                 /*
172                                                  *      show UI
173                                                  *
174                                                  *      after
175                                                  *
176                                                  * must do destroy UI
177                                                  *
178                                                  * */
179                                         }
180                                         break;
181                                 case '2':
182                                         {
183                                                 test_result = __test_alert_confirmation();
184                                                 printf("Alert UI - confirmation : result = %s\n\n", test_result ? "success" : "fail");
185                                         }
186                                         break;
187                                 case '3':
188                                         {
189                                                 test_result = __test_alert_inputtext();
190                                                 printf("Alert UI - input text : result = %s\n\n", test_result ? "success" : "fail");
191                                         }
192                                         break;
193                                 case '4':
194                                         {
195                                                 test_result = __test_alert_single_choice();
196                                                 printf("Alert UI - single choice : result = %s\n\n", test_result ? "success" : "fail");
197                                         }
198                                         break;
199                                 case '5':
200                                         {
201                                                 test_result = __test_alert_multiple_choice();
202                                                 printf("Alert UI - multiple choice : result = %s\n\n", test_result ? "success" : "fail");
203                                         }
204                                         break;
205                                 default:
206                                         _DEBUG_TRACE("Alert UI - Wrong Choice: enter your choice again...");
207                                         break;
208                                 }
209
210                                 // display menu
211                                 _print_alert_ui_test();
212                         }
213                         break;
214                 case 3: /* CP UI */
215                         {
216                                 switch (buf[0]) {
217                                         gboolean test_result = FALSE;
218                                 case '1':
219                                         {
220                                                 test_result = __test_cp_check_pin_code();
221                                                 printf("CP UI - check pin code : result = %s\n\n", test_result ? "success" : "fail");
222                                         }
223                                         break;
224                                 default:
225                                         _DEBUG_TRACE("CP UI - Wrong Choice: enter your choice again...");
226                                         break;
227                                 }
228
229                                 // display menu
230                                 _print_cp_ui_test();
231                         }
232                         break;
233                 case 4: /* Fota UI */
234                         {
235                                 switch (buf[0]) {
236                                         gboolean test_result = FALSE;
237                                 case '1':
238                                         {
239                                                 test_result = __test_fota_software_update();
240                                                 printf("Fota UI - software update : result = %s\n\n", test_result ? "success" : "fail");
241                                         }
242                                         break;
243                                 case '2':
244                                         {
245                                                 test_result = __test_fota_cancel();
246                                                 printf("Fota UI - cancel : result = %s\n\n", test_result ? "success" : "fail");
247                                         }
248                                         break;
249                                 case '3':
250                                         {
251                                                 test_result = __test_fota_download();
252                                                 printf("Fota UI - download : result = %s\n\n", test_result ? "success" : "fail");
253                                         }
254                                         break;
255                                 case '4':
256                                         {
257                                                 test_result = __test_fota_install();
258                                                 printf("Fota UI - install : result = %s\n\n", test_result ? "success" : "fail");
259                                         }
260                                         break;
261                                 case '5':
262                                         {
263                                                 test_result = __test_fota_set_interval();
264                                                 printf("Fota UI - set interval : result = %s\n\n", test_result ? "success" : "fail");
265                                         }
266                                         break;
267                                 default:
268                                         _DEBUG_TRACE("Fota UI - Wrong Choice: enter your choice again...");
269                                         break;
270                                 }
271
272                                 // display menu
273                                 _print_fota_ui_test();
274                         }
275                         break;
276                 case 5: /* Noti UI */
277                         {
278                                 switch (buf[0]) {
279                                         gboolean test_result = FALSE;
280                                 case '1':
281                                         {
282                                                 test_result = __test_noti_software_update();
283                                                 printf("Noti UI - software update : result = %s\n\n", test_result ? "success" : "fail");
284                                         }
285                                         break;
286                                 case '2':
287                                         {
288                                                 test_result = __test_noti_cancel();
289                                                 printf("Noti UI - cancel : result = %s\n\n", test_result ? "success" : "fail");
290                                         }
291                                         break;
292                                 case '3':
293                                         {
294                                                 test_result = __test_noti_download();
295                                                 printf("Noti UI - download : result = %s\n\n", test_result ? "success" : "fail");
296                                         }
297                                         break;
298                                 case '4':
299                                         {
300                                                 test_result = __test_noti_install();
301                                                 printf("Noti UI - install : result = %s\n\n", test_result ? "success" : "fail");
302                                         }
303                                         break;
304                                 case '5':
305                                         {
306                                                 test_result = __test_noti_set_interval();
307                                                 printf("Noti UI - set interval : result = %s\n\n", test_result ? "success" : "fail");
308                                         }
309                                         break;
310                                 default:
311                                         _DEBUG_TRACE("Noti UI - Wrong Choice: enter your choice again...");
312                                         break;
313                                 }
314
315                                 // display menu
316                                 _print_noti_ui_test();
317                         }
318                         break;
319                 case 6: /* Registration UI */
320                         {
321                                 switch (buf[0]) {
322                                         gboolean test_result = FALSE;
323                                 case '1':
324                                         {
325                                                 test_result = __test_reg_account_registration();
326                                                 printf("Registration UI - account registration : result = %s\n\n", test_result ? "success" : "fail");
327                                         }
328                                         break;
329                                 default:
330                                         _DEBUG_TRACE("Registration UI - Wrong Choice: enter your choice again...");
331                                         break;
332                                 }
333
334                                 // display menu
335                                 _print_reg_ui_test();
336                         }
337                         break;
338                 case 7:
339                         switch (buf[0]) {
340                                 gboolean test_result = FALSE;
341                         case '1':
342                                 {
343                                         test_result = __test_add_dmacc();
344                                         printf("DMACC CONTROL UI - add dm acc : result = %s\n\n", test_result ? "success" : "fail");
345                                 }
346                                 break;
347                         case '2':
348                                 {
349                                         test_result = __test_remove_dmacc();
350                                 }
351                                 break;
352                         default:
353                                 printf("DMACC CONTROL UI - remove dm acc : result = %s\n\n", test_result ? "success" : "fail");
354                                 break;
355                         }
356
357                         // display menu
358                         _printf_dmacc_control_ui_test();
359                         break;
360
361                 default:
362                         break;
363                 }
364         }
365
366         _INNER_FUNC_EXIT;
367
368         return TRUE;
369 }
370
371 static void _select_ui_input()
372 {
373         _INNER_FUNC_ENTER;
374
375         printf(" ####### oma dm client test ##########\n");
376         printf("select UI\n");
377         printf(" Press '0': to exit\n");
378         printf(" Press '1': Admin UI\n");
379         printf(" Press '2': Alert UI\n");
380         printf(" Press '3': CP UI\n");
381         printf(" Press '4': Fota UI\n");
382         printf(" Press '5': Noti UI\n");
383         printf(" Press '6': Registration UI\n");
384         printf(" Press '7': Dmacc control UI\n");
385         printf(" Enter your choice : ");
386
387         scanf("%d", &selected_ui_num);
388         _DEBUG_TRACE("selected ui : %d", selected_ui_num);
389
390         if (selected_ui_num == 0) {
391                 _DEBUG_TRACE("Exit !!");
392                 exit(0);
393         }
394
395         _INNER_FUNC_EXIT;
396 }
397
398 static void _print_admin_ui_test()
399 {
400         _INNER_FUNC_ENTER;
401
402         printf(" ####### Admin UI Test ##########\n");
403         printf(" Press '0': to exit\n");
404         printf(" Press '1': get fumo config\n");
405         printf(" Press '2': set fumo config\n");
406         printf(" Press '3': get profile\n");
407         printf(" Press '4': set profile\n");
408         printf(" Press '5': reset profile\n");
409         printf(" Press '6': user initiate\n");
410         printf(" Enter your choice : ");
411
412         _INNER_FUNC_EXIT;
413
414         return;
415 }
416
417 static void _print_alert_ui_test()
418 {
419         _INNER_FUNC_ENTER;
420
421         printf(" ####### Alert UI Test ##########\n");
422         printf(" Press '0': to exit\n");
423         printf(" Press '1': display\n");
424         printf(" Press '2': confirmation\n");
425         printf(" Press '3': input text\n");
426         printf(" Press '4': single choice\n");
427         printf(" Press '5': multiple choice\n");
428         printf(" Enter your choice : ");
429
430         _INNER_FUNC_EXIT;
431
432         return;
433 }
434
435 static void _print_cp_ui_test()
436 {
437         _INNER_FUNC_ENTER;
438
439         printf(" ####### CP UI Test ##########\n");
440         printf(" Press '0': to exit\n");
441         printf(" Press '1': check pin code\n");
442         printf(" Enter your choice : ");
443
444         _INNER_FUNC_EXIT;
445
446         return;
447 }
448
449 static void _print_fota_ui_test()
450 {
451         _INNER_FUNC_ENTER;
452
453         printf(" ####### Fota UI Test ##########\n");
454         printf(" Press '0': to exit\n");
455         printf(" Press '1': software update\n");
456         printf(" Press '2': cancel\n");
457         printf(" Press '3': download\n");
458         printf(" Press '4': install\n");
459         printf(" Press '5': set interval\n");
460         printf(" Enter your choice : ");
461
462         _INNER_FUNC_EXIT;
463
464         return;
465 }
466
467 static void _print_noti_ui_test()
468 {
469         _INNER_FUNC_ENTER;
470
471         printf(" ####### Noti UI Test ##########\n");
472         printf(" Press '0': to exit\n");
473         printf(" Press '1': software update\n");
474         printf(" Press '2': cancel\n");
475         printf(" Press '3': download\n");
476         printf(" Press '4': install\n");
477         printf(" Press '5': set interval\n");
478         printf(" Enter your choice : ");
479
480         _INNER_FUNC_EXIT;
481
482         return;
483 }
484
485 static void _print_reg_ui_test()
486 {
487         _INNER_FUNC_ENTER;
488
489         printf(" ####### Registration UI Test ##########\n");
490         printf(" Press '0': to exit\n");
491         printf(" Press '1': account registration\n");
492         printf(" Enter your choice : ");
493
494         _INNER_FUNC_EXIT;
495
496         return;
497 }
498
499 static void _printf_dmacc_control_ui_test()
500 {
501         _INNER_FUNC_ENTER;
502
503         printf(" ####### Dmacc Control UI Test ##########\n");
504         printf(" Press '0': to exit\n");
505         printf(" Press '1': add dm acc(fota)\n");
506         printf(" Press '2': remove dm acc(fota)\n");
507         printf(" Enter your choice : ");
508
509         _INNER_FUNC_EXIT;
510
511         return;
512 }
513
514 /* Admin wrapping test api */
515 static gboolean __test_admin_get_fumo_config()
516 {
517         _INNER_FUNC_ENTER;
518
519         gboolean is_test_successful = TRUE;
520         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
521         int wifi_only = -1;
522
523         result = sync_agent_dm_admin_get_fumo_config(&wifi_only);
524         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
525                 _DEBUG_VERBOSE("sync_agent_admin_get_fumo_config() failed !!");
526                 is_test_successful = FALSE;
527         } else {
528                 _DEBUG_VERBOSE("sync_agent_admin_get_fumo_config() success !!");
529                 is_test_successful = TRUE;
530         }
531
532         _INNER_FUNC_EXIT;
533
534         return is_test_successful;
535 }
536
537 static gboolean __test_admin_set_fumo_config()
538 {
539         _INNER_FUNC_ENTER;
540
541         gboolean is_test_successful = TRUE;
542         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
543
544         int wifi_only = 0;      /* FIXME */
545
546         result = sync_agent_dm_admin_set_fumo_config(wifi_only);
547         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
548                 _DEBUG_VERBOSE("sync_agent_admin_set_fumo_config() failed !!");
549                 is_test_successful = FALSE;
550         } else {
551                 _DEBUG_VERBOSE("sync_agent_admin_set_fumo_config() success !!");
552                 is_test_successful = TRUE;
553         }
554
555         _INNER_FUNC_EXIT;
556
557         return is_test_successful;
558 }
559
560 static gboolean __test_admin_get_profile()
561 {
562         _INNER_FUNC_ENTER;
563
564         gboolean is_test_successful = TRUE;
565         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
566
567         int profile_type = UI_GCF_TYPE; /* FIXME */
568         sync_agent_dm_setting_data_s *setting_data = (sync_agent_dm_setting_data_s *) calloc(1, sizeof(sync_agent_dm_setting_data_s));
569         if (setting_data == NULL) {
570                 _DEBUG_ERROR("calloc failed !!");
571                 return false;
572         }
573
574         result = sync_agent_dm_admin_get_profile(profile_type, &setting_data);
575         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
576                 _DEBUG_VERBOSE("sync_agent_admin_get_profile() failed !!");
577                 is_test_successful = FALSE;
578         } else {
579                 _DEBUG_VERBOSE("sync_agent_admin_get_profile() success !!");
580                 is_test_successful = TRUE;
581         }
582
583         /* free part */
584         if (setting_data != NULL) {
585                 if (setting_data->profile_name != NULL)
586                         g_free(setting_data->profile_name);
587                 if (setting_data->imei != NULL)
588                         g_free(setting_data->imei);
589                 if (setting_data->server_url != NULL)
590                         g_free(setting_data->server_url);
591                 if (setting_data->server_pwd != NULL)
592                         g_free(setting_data->server_pwd);
593                 if (setting_data->client_id != NULL)
594                         g_free(setting_data->client_id);
595                 if (setting_data->client_pwd != NULL)
596                         g_free(setting_data->client_pwd);
597                 if (setting_data->client_auth_type != NULL)
598                         g_free(setting_data->client_auth_type);
599                 if (setting_data->server_auth_type != NULL)
600                         g_free(setting_data->server_auth_type);
601
602                 g_free(setting_data);
603         }
604
605         _INNER_FUNC_EXIT;
606
607         return is_test_successful;
608 }
609
610 static gboolean __test_admin_set_profile()
611 {
612         _INNER_FUNC_ENTER;
613
614         gboolean is_test_successful = TRUE;
615         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
616
617         int profile_type = UI_GCF_TYPE; /* FIXME */
618         sync_agent_dm_setting_data_s *setting_data = (sync_agent_dm_setting_data_s *) calloc(1, sizeof(sync_agent_dm_setting_data_s));
619         if (setting_data == NULL) {
620                 _DEBUG_ERROR("calloc failed !!");
621                 return false;
622         }
623
624         /* FIXME */
625         /* fumo */
626         setting_data->server_url = strdup("https://XXX");
627         setting_data->server_id = strdup("XXX");
628         setting_data->server_pwd = strdup("XXX==");
629         setting_data->client_id = strdup("IMEI:XXX");
630         setting_data->client_pwd = strdup("XXX");
631         setting_data->client_auth_type = strdup("DIGEST");
632         setting_data->server_auth_type = strdup("DIGEST");
633
634         /* lawmo */
635 //      setting_data->server_url = strdup("https://XXX");
636 //      setting_data->server_id = strdup("XXX");
637 //      setting_data->server_pwd = strdup("XXX==");
638 //      setting_data->client_id = strdup("IMEI:XXX");
639 //      setting_data->client_pwd = strdup("XXX");
640 //      setting_data->client_auth_type = strdup("DIGEST");
641 //      setting_data->server_auth_type = strdup("DIGEST");
642
643         /* gcf */
644 //      setting_data->server_url = strdup("http://XXX");
645 //      setting_data->server_id = strdup("XXX");
646 //      setting_data->server_pwd = strdup("XXX");
647 //      setting_data->client_id = strdup("XXX");
648 //      setting_data->client_pwd = strdup("XXX");
649 //      setting_data->client_auth_type = strdup("DIGEST");
650 //      setting_data->server_auth_type = strdup("DIGEST");
651
652         result = sync_agent_dm_admin_set_profile(profile_type, setting_data);
653         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
654                 _DEBUG_VERBOSE("sync_agent_admin_set_profile() failed !!");
655                 is_test_successful = FALSE;
656         } else {
657                 _DEBUG_VERBOSE("sync_agent_admin_set_profile() success !!");
658                 is_test_successful = TRUE;
659         }
660
661         /* free part */
662         if (setting_data != NULL) {
663                 if (setting_data->server_url != NULL)
664                         g_free(setting_data->server_url);
665                 if (setting_data->server_id != NULL)
666                         g_free(setting_data->server_id);
667                 if (setting_data->server_pwd != NULL)
668                         g_free(setting_data->server_pwd);
669                 if (setting_data->client_id != NULL)
670                         g_free(setting_data->client_id);
671                 if (setting_data->client_pwd != NULL)
672                         g_free(setting_data->client_pwd);
673                 if (setting_data->client_auth_type != NULL)
674                         g_free(setting_data->client_auth_type);
675                 if (setting_data->server_auth_type != NULL)
676                         g_free(setting_data->server_auth_type);
677
678                 g_free(setting_data);
679         }
680
681         _INNER_FUNC_EXIT;
682
683         return is_test_successful;
684 }
685
686 static gboolean __test_admin_reset_profile()
687 {
688         _INNER_FUNC_ENTER;
689
690         gboolean is_test_successful = TRUE;
691         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
692
693         int profile_type = UI_GCF_TYPE; /* FIXME */
694
695         result = sync_agent_dm_admin_reset_profile(profile_type);
696         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
697                 _DEBUG_VERBOSE("sync_agent_admin_reset_profile() failed !!");
698                 is_test_successful = FALSE;
699         } else {
700                 _DEBUG_VERBOSE("sync_agent_admin_reset_profile() success !!");
701                 is_test_successful = TRUE;
702         }
703
704         _INNER_FUNC_EXIT;
705
706         return is_test_successful;
707 }
708
709 static gboolean __test_admin_user_initiate()
710 {
711         _INNER_FUNC_ENTER;
712
713         gboolean is_test_successful = TRUE;
714         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
715
716         sync_agent_dm_service_server_type_e server_type = UI_GCF_TYPE;
717
718         result = sync_agent_dm_admin_user_initiate(server_type);
719         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
720                 _DEBUG_VERBOSE("sync_agent_admin_reset_profile() failed !!");
721                 is_test_successful = FALSE;
722         } else {
723                 _DEBUG_VERBOSE("sync_agent_admin_reset_profile() success !!");
724                 is_test_successful = TRUE;
725         }
726
727         _INNER_FUNC_EXIT;
728
729         return is_test_successful;
730 }
731
732                                                                                        /* Alert wrapping test api *//*
733                                                                                           static gboolean __test_alert_display()
734                                                                                           {
735                                                                                           _INNER_FUNC_ENTER;
736
737                                                                                           gboolean is_test_successful = TRUE;
738                                                                                           sync_agent_dm_error_e result = SYNC_AGENT_DM_FAIL;
739
740                                                                                           int response_type = UI_RESPONSE_TYPE_OK;                 FIXME
741
742                                                                                           result = sync_agent_alert_display(response_type);
743                                                                                           if (result != SYNC_AGENT_DM_SUCCESS) {
744                                                                                           _DEBUG_VERBOSE("sync_agent_alert_display() failed !!");
745                                                                                           is_test_successful = FALSE;
746                                                                                           } else {
747                                                                                           _DEBUG_VERBOSE("sync_agent_alert_display() success !!");
748                                                                                           is_test_successful = TRUE;
749                                                                                           }
750
751                                                                                           _INNER_FUNC_EXIT;
752
753                                                                                           return is_test_successful;
754                                                                                           } */
755
756 static gboolean __test_alert_confirmation()
757 {
758         _INNER_FUNC_ENTER;
759
760         gboolean is_test_successful = TRUE;
761         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
762
763         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
764
765         result = sync_agent_dm_alert_confirmation(response_type);
766         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
767                 _DEBUG_VERBOSE("sync_agent_alert_confirmation() failed !!");
768                 is_test_successful = FALSE;
769         } else {
770                 _DEBUG_VERBOSE("sync_agent_alert_confirmation() success !!");
771                 is_test_successful = TRUE;
772         }
773
774         _INNER_FUNC_EXIT;
775
776         return is_test_successful;
777 }
778
779 static gboolean __test_alert_inputtext()
780 {
781         _INNER_FUNC_ENTER;
782
783         gboolean is_test_successful = TRUE;
784         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
785
786         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
787         char *input_text = strdup("alert input text");  /* FIXME */
788
789         result = sync_agent_dm_alert_inputtext(response_type, input_text);
790         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
791                 _DEBUG_VERBOSE("sync_agent_alert_inputtext() failed !!");
792                 is_test_successful = FALSE;
793         } else {
794                 _DEBUG_VERBOSE("sync_agent_alert_inputtext() success !!");
795                 is_test_successful = TRUE;
796         }
797
798         /* free part */
799         if (input_text != NULL)
800                 g_free(input_text);
801
802         _INNER_FUNC_EXIT;
803
804         return is_test_successful;
805 }
806
807 static gboolean __test_alert_single_choice()
808 {
809         _INNER_FUNC_ENTER;
810
811         gboolean is_test_successful = TRUE;
812         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
813
814         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
815         int selected_count = 1;
816         char *selected_number = strdup("1");    /* FIXME */
817
818         result = sync_agent_dm_alert_single_choice(response_type, selected_count, selected_number);
819         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
820                 _DEBUG_VERBOSE("sync_agent_alert_single_choice() failed !!");
821                 is_test_successful = FALSE;
822         } else {
823                 _DEBUG_VERBOSE("sync_agent_alert_single_choice() success !!");
824                 is_test_successful = TRUE;
825         }
826
827         /* free part */
828         if (selected_number != NULL)
829                 g_free(selected_number);
830
831         _INNER_FUNC_EXIT;
832
833         return is_test_successful;
834 }
835
836 static gboolean __test_alert_multiple_choice()
837 {
838         _INNER_FUNC_ENTER;
839
840         gboolean is_test_successful = TRUE;
841         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
842
843         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
844         GList *selected_list = NULL;
845
846         /* FIXME - add selected number */
847         selected_list = g_list_append(selected_list, strdup("1"));
848         selected_list = g_list_append(selected_list, strdup("2"));
849         selected_list = g_list_append(selected_list, strdup("3"));
850
851         result = sync_agent_dm_alert_multiple_choice(response_type, selected_list);
852         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
853                 _DEBUG_VERBOSE("sync_agent_alert_multiple_choice() failed !!");
854                 is_test_successful = FALSE;
855         } else {
856                 _DEBUG_VERBOSE("sync_agent_alert_multiple_choice() success !!");
857                 is_test_successful = TRUE;
858         }
859
860         /* free part */
861         if (selected_list != NULL) {
862                 GList *iter = NULL;
863                 char *data = NULL;
864                 for (iter = selected_list; iter != NULL;) {
865                         data = (char *)(iter->data);
866                         iter = g_list_next(iter);
867                         selected_list = g_list_remove(selected_list, data);
868                         if (data != NULL)
869                                 g_free((char *)data);
870                 }
871
872                 g_list_free(selected_list);
873         }
874
875         _INNER_FUNC_EXIT;
876
877         return is_test_successful;
878 }
879
880 /* CP wrapping test api */
881 static gboolean __test_cp_check_pin_code()
882 {
883         _INNER_FUNC_ENTER;
884
885         gboolean is_test_successful = TRUE;
886         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
887
888         int ext_id = 1;         /* FIXME */
889         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME - RESPONSE_TYPE_CANCEL => ext_id : -1 / pin_code : NULL */
890         char *pin_code = "1234";        /* FIXME */
891
892         int user_pin_val = 0;   //fail
893
894         result = sync_agent_dm_cp_check_pin_code(ext_id, response_type, pin_code, &user_pin_val);
895         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
896                 _DEBUG_VERBOSE("sync_agent_cp_check_pin_code() failed !!");
897
898                 _DEBUG_VERBOSE("user pin valiation : %d", user_pin_val);
899
900                 is_test_successful = FALSE;
901         } else {
902                 _DEBUG_VERBOSE("sync_agent_cp_check_pin_code() success !!");
903
904                 _DEBUG_VERBOSE("user pin valiation : %d", user_pin_val);
905
906                 is_test_successful = TRUE;
907         }
908
909         _INNER_FUNC_EXIT;
910
911         return is_test_successful;
912 }
913
914 /* Fota wrapping test api */
915 static gboolean __test_fota_software_update()
916 {
917         _INNER_FUNC_ENTER;
918
919         gboolean is_test_successful = TRUE;
920         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
921
922         sync_agent_dm_service_server_type_e server_type = UI_SAMSUNG_FUMO_TYPE; /* FIXME */
923
924         result = sync_agent_dm_fota_software_update(server_type);
925         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
926                 _DEBUG_VERBOSE("sync_agent_fota_software_update() failed !!");
927                 is_test_successful = FALSE;
928         } else {
929                 _DEBUG_VERBOSE("sync_agent_fota_software_update() success !!");
930                 is_test_successful = TRUE;
931         }
932
933         _INNER_FUNC_EXIT;
934
935         return is_test_successful;
936 }
937
938 static gboolean __test_fota_cancel()
939 {
940         _INNER_FUNC_ENTER;
941
942         gboolean is_test_successful = TRUE;
943         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
944
945         result = sync_agent_dm_fota_cancel();
946         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
947                 _DEBUG_VERBOSE("sync_agent_fota_cancel() failed !!");
948                 is_test_successful = FALSE;
949         } else {
950                 _DEBUG_VERBOSE("sync_agent_fota_cancel() success !!");
951                 is_test_successful = TRUE;
952         }
953
954         _INNER_FUNC_EXIT;
955
956         return is_test_successful;
957 }
958
959 static gboolean __test_fota_download()
960 {
961         _INNER_FUNC_ENTER;
962
963         gboolean is_test_successful = TRUE;
964         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
965
966         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
967
968         result = sync_agent_dm_fota_download(response_type);
969         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
970                 _DEBUG_VERBOSE("sync_agent_fota_download() failed !!");
971                 is_test_successful = FALSE;
972         } else {
973                 _DEBUG_VERBOSE("sync_agent_fota_download() success !!");
974                 is_test_successful = TRUE;
975         }
976
977         _INNER_FUNC_EXIT;
978
979         return is_test_successful;
980 }
981
982 static gboolean __test_fota_install()
983 {
984         _INNER_FUNC_ENTER;
985
986         gboolean is_test_successful = TRUE;
987         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
988
989         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
990
991         result = sync_agent_dm_fota_install(response_type);
992         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
993                 _DEBUG_VERBOSE("sync_agent_fota_install() failed !!");
994                 is_test_successful = FALSE;
995         } else {
996                 _DEBUG_VERBOSE("sync_agent_fota_install() success !!");
997                 is_test_successful = TRUE;
998         }
999
1000         _INNER_FUNC_EXIT;
1001
1002         return is_test_successful;
1003 }
1004
1005 static gboolean __test_fota_set_interval()
1006 {
1007         _INNER_FUNC_ENTER;
1008
1009         gboolean is_test_successful = TRUE;
1010         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1011
1012         int interval_type = UI_RESPONSE_TYPE_REMINDER_INTERVAL_1_HOUR;  /* FIXME */
1013
1014         result = sync_agent_dm_fota_set_interval(interval_type);
1015         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1016                 _DEBUG_VERBOSE("sync_agent_fota_set_interval() failed !!");
1017                 is_test_successful = FALSE;
1018         } else {
1019                 _DEBUG_VERBOSE("sync_agent_fota_set_interval() success !!");
1020                 is_test_successful = TRUE;
1021         }
1022
1023         _INNER_FUNC_EXIT;
1024
1025         return is_test_successful;
1026 }
1027
1028 /* Noti wrapping test api */
1029 static gboolean __test_noti_software_update()
1030 {
1031         _INNER_FUNC_ENTER;
1032
1033         gboolean is_test_successful = TRUE;
1034         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1035
1036         result = sync_agent_dm_fota_update_noti(SMASUNG_SERVER, SESSION_ID);
1037         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1038                 _DEBUG_VERBOSE("sync_agent_push_software_update() failed !!");
1039                 is_test_successful = FALSE;
1040         } else {
1041                 _DEBUG_VERBOSE("sync_agent_push_software_update() success !!");
1042                 is_test_successful = TRUE;
1043         }
1044
1045         _INNER_FUNC_EXIT;
1046
1047         return is_test_successful;
1048 }
1049
1050 static gboolean __test_noti_cancel()
1051 {
1052         _INNER_FUNC_ENTER;
1053
1054         gboolean is_test_successful = TRUE;
1055         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1056
1057         result = sync_agent_dm_fota_cancel_noti();
1058         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1059                 _DEBUG_VERBOSE("sync_agent_push_cancel() failed !!");
1060                 is_test_successful = FALSE;
1061         } else {
1062                 _DEBUG_VERBOSE("sync_agent_push_cancel() success !!");
1063                 is_test_successful = TRUE;
1064         }
1065
1066         _INNER_FUNC_EXIT;
1067
1068         return is_test_successful;
1069 }
1070
1071 static gboolean __test_noti_download()
1072 {
1073         _INNER_FUNC_ENTER;
1074
1075         gboolean is_test_successful = TRUE;
1076         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1077
1078         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
1079
1080         result = sync_agent_dm_fota_download_noti(response_type);
1081         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1082                 _DEBUG_VERBOSE("sync_agent_push_download() failed !!");
1083                 is_test_successful = FALSE;
1084         } else {
1085                 _DEBUG_VERBOSE("sync_agent_push_download() success !!");
1086                 is_test_successful = TRUE;
1087         }
1088
1089         _INNER_FUNC_EXIT;
1090
1091         return is_test_successful;
1092 }
1093
1094 static gboolean __test_noti_install()
1095 {
1096         _INNER_FUNC_ENTER;
1097
1098         gboolean is_test_successful = TRUE;
1099         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1100
1101         int response_type = UI_RESPONSE_TYPE_OK;        /* FIXME */
1102
1103         result = sync_agent_dm_fota_install_noti(response_type);
1104         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1105                 _DEBUG_VERBOSE("sync_agent_push_install() failed !!");
1106                 is_test_successful = FALSE;
1107         } else {
1108                 _DEBUG_VERBOSE("sync_agent_push_install() success !!");
1109                 is_test_successful = TRUE;
1110         }
1111
1112         _INNER_FUNC_EXIT;
1113
1114         return is_test_successful;
1115 }
1116
1117 static gboolean __test_noti_set_interval()
1118 {
1119         _INNER_FUNC_ENTER;
1120
1121         gboolean is_test_successful = TRUE;
1122         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1123
1124         int interval_type = UI_RESPONSE_TYPE_REMINDER_INTERVAL_1_HOUR;  /* FIXME */
1125
1126         result = sync_agent_dm_fota_set_interval_noti(interval_type);
1127         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1128                 _DEBUG_VERBOSE("sync_agent_push_set_interval() failed !!");
1129                 is_test_successful = FALSE;
1130         } else {
1131                 _DEBUG_VERBOSE("sync_agent_push_set_interval() success !!");
1132                 is_test_successful = TRUE;
1133         }
1134
1135         _INNER_FUNC_EXIT;
1136
1137         return is_test_successful;
1138 }
1139
1140 /* Registration wrapping test api */
1141 static gboolean __test_reg_account_registration()
1142 {
1143         _INNER_FUNC_ENTER;
1144
1145         gboolean is_test_successful = TRUE;
1146         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1147
1148         result = sync_agent_dm_reg_account_registration();
1149         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1150                 _DEBUG_VERBOSE("sync_agent_reg_account_registration() failed !!");
1151                 is_test_successful = FALSE;
1152         } else {
1153                 _DEBUG_VERBOSE("sync_agent_reg_account_registration() success !!");
1154                 is_test_successful = TRUE;
1155         }
1156
1157         _INNER_FUNC_EXIT;
1158
1159         return is_test_successful;
1160 }
1161
1162 static gboolean __test_add_dmacc()
1163 {
1164         _INNER_FUNC_ENTER;
1165
1166         gboolean is_test_successful = TRUE;
1167         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1168         sync_agent_dm_service_server_type_e dmacc_type = UI_SAMSUNG_FUMO_TYPE;
1169
1170         result = sync_agent_dm_add_dmacc(dmacc_type);
1171         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1172                 _DEBUG_VERBOSE("sync_agent_dm_remove_dmacc() failed !!");
1173                 is_test_successful = FALSE;
1174         } else {
1175                 _DEBUG_VERBOSE("sync_agent_dm_remove_dmacc() success !!");
1176                 is_test_successful = TRUE;
1177         }
1178
1179         _INNER_FUNC_EXIT;
1180
1181         return is_test_successful;
1182 }
1183
1184 static gboolean __test_remove_dmacc()
1185 {
1186         _INNER_FUNC_ENTER;
1187
1188         gboolean is_test_successful = TRUE;
1189         sync_agent_dm_error_e result = UI_SYNC_AGENT_DM_FAIL;
1190         sync_agent_dm_service_server_type_e dmacc_type = UI_SAMSUNG_FUMO_TYPE;
1191
1192         result = sync_agent_dm_remove_dmacc(dmacc_type);
1193         if (result != UI_SYNC_AGENT_DM_SUCCESS) {
1194                 _DEBUG_VERBOSE("sync_agent_dm_remove_dmacc() failed !!");
1195                 is_test_successful = FALSE;
1196         } else {
1197                 _DEBUG_VERBOSE("sync_agent_dm_remove_dmacc() success !!");
1198                 is_test_successful = TRUE;
1199         }
1200
1201         _INNER_FUNC_EXIT;
1202
1203         return is_test_successful;
1204 }
1205
1206 int main(int argc, char *argv[])
1207 {
1208         _EXTERN_FUNC_ENTER;
1209
1210         GIOChannel *stdin_channel = NULL;
1211         guint result;
1212
1213 //      signal(SIGPIPE, _pipe_handler);
1214
1215         sync_agent_dm_error_e dm_err = UI_SYNC_AGENT_DM_SUCCESS;
1216
1217         // select ui
1218         _select_ui_input();
1219         switch (selected_ui_num) {
1220         case 1:
1221                 dm_err = sync_agent_dm_admin_init();
1222                 break;
1223         case 2:
1224                 dm_err = sync_agent_dm_alert_init();
1225                 break;
1226         case 3:
1227                 dm_err = sync_agent_dm_cp_init();
1228                 break;
1229         case 4:
1230                 dm_err = sync_agent_dm_fota_init();
1231                 break;
1232         case 5:
1233                 dm_err = sync_agent_dm_push_init();
1234                 break;
1235         case 6:
1236                 dm_err = sync_agent_dm_reg_init();
1237                 break;
1238         case 7:
1239                 dm_err = sync_agent_dm_dmacc_init();
1240                 break;
1241         default:
1242                 break;
1243         }
1244
1245         if (dm_err != UI_SYNC_AGENT_DM_SUCCESS) {
1246                 _DEBUG_ERROR("dm ui init failed !!");
1247                 return -1;
1248         }
1249
1250         /* Creates a new GIOChannel from std input */
1251         stdin_channel = g_io_channel_unix_new(0);
1252         retvm_if(stdin_channel == NULL, -1, "Error creating new GIOChannel!");
1253
1254         /* Adds the GIOChannel into the default main loop context with the default priority. */
1255         result = g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc) _process_cmd_input, NULL);
1256         retvm_if(result == 0, -1, "Error creating watch!");
1257
1258         // display menu
1259         switch (selected_ui_num) {
1260         case 1:
1261                 _print_admin_ui_test();
1262                 break;
1263         case 2:
1264                 _print_alert_ui_test();
1265                 break;
1266         case 3:
1267                 _print_cp_ui_test();
1268                 break;
1269         case 4:
1270                 _print_fota_ui_test();
1271                 break;
1272         case 5:
1273                 _print_noti_ui_test();
1274                 break;
1275         case 6:
1276                 _print_reg_ui_test();
1277                 break;
1278         case 7:
1279                 _printf_dmacc_control_ui_test();
1280                 break;
1281         default:
1282                 break;
1283         }
1284
1285         // wait for policy receiver callback rest
1286         g_mainloop = g_main_loop_new(NULL, FALSE);
1287         g_main_loop_run(g_mainloop);
1288
1289         // reaches here when g_main_loop_quit is called
1290         switch (selected_ui_num) {
1291         case 1:
1292                 dm_err = sync_agent_dm_admin_deinit();
1293                 break;
1294         case 2:
1295                 dm_err = sync_agent_dm_alert_deinit();
1296                 break;
1297         case 3:
1298                 dm_err = sync_agent_dm_cp_deinit();
1299                 break;
1300         case 4:
1301                 dm_err = sync_agent_dm_fota_deinit();
1302                 break;
1303         case 5:
1304                 dm_err = sync_agent_dm_push_deinit();
1305                 break;
1306         case 6:
1307                 dm_err = sync_agent_dm_reg_deinit();
1308                 break;
1309         case 7:
1310                 dm_err = sync_agent_dm_dmacc_deinit();
1311                 break;
1312         default:
1313                 break;
1314         }
1315         if (dm_err != UI_SYNC_AGENT_DM_SUCCESS) {
1316                 _DEBUG_ERROR("dm ui deinit failed !!");
1317                 return -1;
1318         }
1319
1320         _EXTERN_FUNC_EXIT;
1321
1322         return 0;
1323 }