Fixed build errors caused by 2.4 merge.
[platform/core/api/notification.git] / test-app / main.c
1 /*
2  *  Test application for notification API
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Kyuho Jo <kyuho.jo@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23
24 /* common header */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <signal.h>
28 #include <sys/time.h>
29 #include <unistd.h>
30
31 /* open header */
32 #include <glib.h>
33
34 /* notification header */
35 #include <notification.h>
36 #include <notification_internal.h>
37 #include <notification_status.h>
38 #include <notification_setting.h>
39 #include <notification_setting_internal.h>
40 #include <notification_text_domain.h>
41
42 /*-----------------------------------------------------------------------------------------*/
43 /* types */
44 typedef enum testapp_menu_type {
45         TESTAPP_MENU_TYPE_MAIN_MENU = 1,
46         TESTAPP_MENU_TYPE_BASIC_TEST_MENU = 2,
47         TESTAPP_MENU_TYPE_SETTING_TEST_MENU = 3
48 } testapp_menu_type_e;
49
50 /*-----------------------------------------------------------------------------------------*/
51 /* function prototypes */
52 static void testapp_system_signal_handler (int signal_number);
53 void testapp_show_prompt (testapp_menu_type_e menu);
54
55 /*-----------------------------------------------------------------------------------------*/
56 /* implementation */
57 void testapp_print (char *fmt, ...)
58 {
59         va_list args = {0};
60         va_start(args, fmt);
61         vfprintf (stdout, fmt, args);
62         va_end (args);
63         fflush (stdout);
64 }
65
66 static gboolean testapp_initialize_testing ()
67 {
68         struct timeval tv_1, tv_2;
69         int interval;
70
71         /* register signal handler */
72         if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
73                 testapp_print ("register signal handler fail\n");
74                 return FALSE;
75         }
76
77         if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
78                 testapp_print ("register signal handler fail\n");
79                 return FALSE;
80         }
81
82         if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
83                 testapp_print ("register signal handler fail\n");
84                 return FALSE;
85         }
86
87         if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
88                 testapp_print ("register signal handler fail\n");
89                 return FALSE;
90         }
91
92
93         gettimeofday(&tv_1, NULL);
94
95         /* TODO : initializing notification */
96
97         gettimeofday(&tv_2, NULL);
98         interval = tv_2.tv_usec - tv_1.tv_usec;
99         testapp_print("\t Initializing Proceed time %d us\n",interval);
100
101
102         return TRUE;
103 }
104
105 static gboolean testapp_finalize_testing ()
106 {
107         /* TODO : finalizing notification */
108
109         return TRUE;
110 }
111
112 static void testapp_system_signal_handler (int signal_number)
113 {
114         testapp_print ("signal:%d\n", signal_number);
115         switch (signal_number) {
116         case SIGQUIT:
117         case SIGINT:
118         case SIGTSTP:
119         case SIGTERM:
120                 testapp_finalize_testing();
121                 break;
122
123         default:
124                 testapp_print ("unhandled signal:%d\n", signal_number);
125                 break;
126         }
127         exit(0);
128 }
129
130
131
132
133 void testapp_show_menu (testapp_menu_type_e menu)
134 {
135         switch (menu) {
136         case TESTAPP_MENU_TYPE_MAIN_MENU:
137                 testapp_print ("==========================================\n");
138                 testapp_print ("    Notification test application \n");
139                 testapp_print ("==========================================\n");
140                 testapp_print ("1. Basic Test\n");
141                 testapp_print ("2. Setting Test\n");
142                 testapp_print ("0. Exit \n");
143                 testapp_print ("------------------------------------------\n");
144                 break;
145         case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
146                 testapp_print ("==========================================\n");
147                 testapp_print ("    Basic test menu \n");
148                 testapp_print ("==========================================\n");
149                 testapp_print (" 1.  Post a simple notification\n");
150                 testapp_print (" 2.  Post simple notifications repeatedly\n");
151                 testapp_print (" 3.  Post a notification on indicator\n");
152                 testapp_print (" 4.  Post status status message\n");
153                 testapp_print (" 5.  Delete all notification\n");
154                 testapp_print (" 6.  Post a heads notification with a button\n");
155                 testapp_print (" 7.  Post a notification with domain text\n");
156                 testapp_print (" 8.  Load by tag\n");
157                 testapp_print ("------------------------------------------\n");
158                 break;
159         case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
160                 testapp_print ("==========================================\n");
161                 testapp_print ("    Setting test menu \n");
162                 testapp_print ("==========================================\n");
163                 testapp_print (" 1.  Get setting list\n");
164                 testapp_print (" 2.  Update setting\n");
165                 testapp_print (" 3.  Update system setting\n");
166                 testapp_print (" 4.  Refresh setting table\n");
167                 testapp_print ("------------------------------------------\n");
168                 break;
169         default:
170                 break;
171         }
172 }
173 /* Common { ------------------------------------------------------------------*/
174
175 static int testapp_add_a_notification()
176 {
177         notification_h noti_handle = NULL;
178         int noti_err = NOTIFICATION_ERROR_NONE;
179
180         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
181
182         if (noti_handle == NULL) {
183                 testapp_print("notification_create failed");
184                 goto FINISH_OFF;
185         }
186
187         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
188         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
189         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
190         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
191         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, "I'm Info Sub 1", "INFO_SUB_1", NOTIFICATION_VARIABLE_TYPE_NONE);
192         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
193         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, "I'm Info Sub 2", "INFO_SUB_2", NOTIFICATION_VARIABLE_TYPE_NONE);
194         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
195         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_3, "I'm Info Sub 3", "INFO_SUB_3", NOTIFICATION_VARIABLE_TYPE_NONE);
196
197         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
198
199         noti_err  = notification_post(noti_handle);
200
201         if (noti_err != NOTIFICATION_ERROR_NONE) {
202                 testapp_print("notification_post failed[%d]", noti_err);
203                 goto FINISH_OFF;
204         }
205
206         FINISH_OFF:
207         if (noti_handle)
208                 notification_free(noti_handle);
209
210         return noti_err;
211 }
212
213 /* Common } ------------------------------------------------------------------*/
214
215 /* Basic Test { --------------------------------------------------------------*/
216 static int testapp_test_post_notification()
217 {
218         int err = NOTIFICATION_ERROR_NONE;
219
220         if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
221                 testapp_print("testapp_add_a_notification failed[%d]", err);
222                 goto FINISH_OFF;
223         }
224
225
226         FINISH_OFF:
227
228         return err;
229 }
230
231 static int testapp_test_post_notifications()
232 {
233         int err = NOTIFICATION_ERROR_NONE;
234         int repeat_count = 0;
235         int i = 0;
236
237         testapp_print("Input count : ");
238
239         if (0 >= scanf("%d", &repeat_count)) {
240                 testapp_print("Invalid input");
241                 goto FINISH_OFF;
242         }
243
244         if (repeat_count > 30) {
245                 testapp_print("Too many count");
246                 goto FINISH_OFF;
247         }
248
249         for (i = 0; i < repeat_count; i++) {
250                 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
251                         testapp_print("testapp_add_a_notification failed[%d]", err);
252                         goto FINISH_OFF;
253                 }
254         }
255
256 FINISH_OFF:
257         return err;
258 }
259
260 static int testapp_test_post_notification_on_indicator()
261 {
262         notification_h noti_handle = NULL;
263         int noti_err = NOTIFICATION_ERROR_NONE;
264
265         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
266
267         if (noti_handle == NULL) {
268                 testapp_print("notification_create failed");
269                 goto FINISH_OFF;
270         }
271
272         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
273         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "This is very loooooooooooooooooooooooooooooooooooooooooong message", NOTIFICATION_VARIABLE_TYPE_NONE);
274
275         noti_err  = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR);
276
277         if(noti_err != NOTIFICATION_ERROR_NONE) {
278                 testapp_print("notification_set_display_applist failed[%d]", noti_err);
279                 goto FINISH_OFF;
280         }
281
282         noti_err  = notification_post(noti_handle);
283
284         if (noti_err != NOTIFICATION_ERROR_NONE) {
285                 testapp_print("notification_post failed[%d]", noti_err);
286                 goto FINISH_OFF;
287         }
288
289         FINISH_OFF:
290         if (noti_handle)
291                 notification_free(noti_handle);
292
293         return noti_err;
294 }
295
296 static int testapp_test_post_status_message()
297 {
298         int noti_err = NOTIFICATION_ERROR_NONE;
299
300
301         noti_err = notification_status_message_post("This is only a test");
302
303         if(noti_err != NOTIFICATION_ERROR_NONE) {
304                 testapp_print("notification_status_message_post failed[%d]", noti_err);
305         }
306
307         return noti_err;
308 }
309
310 static int testapp_test_delete_all_notifications()
311 {
312         int noti_err = NOTIFICATION_ERROR_NONE;
313
314         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
315
316         testapp_print("notification_delete_all returns[%d]", noti_err);
317
318         return noti_err;
319 }
320
321 static int testapp_test_post_heads_up_notification_with_button()
322 {
323         notification_h noti_handle = NULL;
324         int noti_err = NOTIFICATION_ERROR_NONE;
325         int app_control_err = APP_CONTROL_ERROR_NONE;
326         int priv_id = 0;
327         int group_id = 0;
328         char *app_id = NULL;
329         app_control_h app_control = NULL;
330         time_t result = time(NULL);
331         char tag[100] = { 0, };
332
333         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
334
335         if (noti_handle == NULL) {
336                 testapp_print("notification_create failed");
337                 goto FINISH_OFF;
338         }
339
340         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
341         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
342
343         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ACTIVE | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
344
345         snprintf(tag, 100, "%d", (int)result);
346
347         noti_err = notification_set_tag(noti_handle, tag);
348
349         if (noti_err != NOTIFICATION_ERROR_NONE) {
350                 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
351                 goto FINISH_OFF;
352         }
353
354         app_control_err = app_control_create(&app_control);
355         if (app_control_err != APP_CONTROL_ERROR_NONE ) {
356                 testapp_print("app_control_create failed[%d]\n", app_control_err);
357                 goto FINISH_OFF;
358         }
359
360         app_control_err = app_control_set_app_id(app_control, "org.tizen.quickpanel");
361         if (app_control_err != APP_CONTROL_ERROR_NONE ) {
362                 testapp_print("app_control_set_app_id failed[%d]\n", app_control_err);
363                 goto FINISH_OFF;
364         }
365
366         noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
367
368         if (noti_err != NOTIFICATION_ERROR_NONE) {
369                 testapp_print("notification_set_event_handler failed[%d]", noti_err);
370                 goto FINISH_OFF;
371         }
372
373         app_control_destroy(app_control);
374         app_control = NULL;
375
376         noti_err = notification_post(noti_handle);
377
378         if (noti_err != NOTIFICATION_ERROR_NONE) {
379                 testapp_print("notification_post failed[%d]", noti_err);
380                 goto FINISH_OFF;
381         }
382
383         noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
384
385         if (noti_err != NOTIFICATION_ERROR_NONE) {
386                 testapp_print("notification_get_id failed[%d]", noti_err);
387                 goto FINISH_OFF;
388         }
389
390         if (noti_handle)
391                 notification_free(noti_handle);
392         noti_handle = NULL;
393
394         noti_handle = notification_load(NULL, priv_id);
395
396         if (noti_handle == NULL) {
397                 testapp_print("notification_load failed");
398                 goto FINISH_OFF;
399         }
400
401         noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
402
403         if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) {
404                 testapp_print("notification_get_event_handler failed[%d]", noti_err);
405                 goto FINISH_OFF;
406         }
407
408         app_control_get_app_id(app_control, &app_id);
409
410         if (app_id) {
411                 testapp_print("result app_id [%s]\n", app_id);
412                 free(app_id);
413         }
414
415 FINISH_OFF:
416
417         if (app_control)
418                 app_control_destroy(app_control);
419
420         if (noti_handle)
421                 notification_free(noti_handle);
422
423         return noti_err;
424 }
425
426 static int testapp_test_post_notification_with_domain_text()
427 {
428         notification_h noti_handle = NULL;
429         int noti_err = NOTIFICATION_ERROR_NONE;
430         time_t result = time(NULL);
431         char tag[100] = { 0, };
432
433         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
434
435         if (noti_handle == NULL) {
436                 testapp_print("notification_create failed");
437                 goto FINISH_OFF;
438         }
439
440         noti_err = notification_set_text_domain(noti_handle, "message", "/usr/apps/org.tizen.message/res/locale");
441
442         if (noti_err != NOTIFICATION_ERROR_NONE) {
443                 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
444                 goto FINISH_OFF;
445         }
446
447         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
448         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "[%s] *** [%s]",
449                         NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_BODY_NO_SUBJECT",
450                         NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_POP_NEW_MESSAGE",
451                         NOTIFICATION_VARIABLE_TYPE_NONE);
452
453         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
454
455         if (noti_err != NOTIFICATION_ERROR_NONE) {
456                 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
457                 goto FINISH_OFF;
458         }
459
460         snprintf(tag, 100, "%d", (int)result);
461
462         noti_err = notification_set_tag(noti_handle, tag);
463
464         if (noti_err != NOTIFICATION_ERROR_NONE) {
465                 testapp_print("notification_set_tag failed[%d]\n", noti_err);
466                 goto FINISH_OFF;
467         }
468
469         noti_err = notification_post(noti_handle);
470
471         if (noti_err != NOTIFICATION_ERROR_NONE) {
472                 testapp_print("notification_post failed[%d]", noti_err);
473                 goto FINISH_OFF;
474         }
475
476 FINISH_OFF:
477
478
479         if (noti_handle)
480                 notification_free(noti_handle);
481
482         return noti_err;
483 }
484
485 static int testapp_test_load_by_tag()
486 {
487         notification_h noti_handle = NULL;
488         int noti_err = NOTIFICATION_ERROR_NONE;
489
490         noti_handle = notification_load_by_tag("hfe4fif#$sd$ew");
491
492         if (noti_handle == NULL) {
493                 testapp_print("notification_load_by_tag failed");
494                 goto FINISH_OFF;
495         }
496
497 FINISH_OFF:
498         if (noti_handle)
499                 notification_free(noti_handle);
500
501         return noti_err;
502 }
503
504 static gboolean testapp_interpret_command_basic_test (int selected_number)
505 {
506         gboolean go_to_loop = TRUE;
507
508         switch (selected_number) {
509         case 1:
510                 testapp_test_post_notification();
511                 break;
512
513         case 2:
514                 testapp_test_post_notifications();
515                 break;
516
517         case 3:
518                 testapp_test_post_notification_on_indicator();
519                 break;
520
521         case 4:
522                 testapp_test_post_status_message();
523                 break;
524
525         case 5:
526                 testapp_test_delete_all_notifications();
527                 break;
528
529         case 6:
530                 testapp_test_post_heads_up_notification_with_button();
531                 break;
532
533         case 7:
534                 testapp_test_post_notification_with_domain_text();
535                 break;
536
537         case 8:
538                 testapp_test_load_by_tag();
539                 break;
540
541         case 0:
542                 go_to_loop = FALSE;
543                 break;
544
545         default:
546                 break;
547         }
548
549         return go_to_loop;
550
551 }
552
553 void testapp_notification_main ()
554 {
555         gboolean go_to_loop = TRUE;
556         int menu_number = 0;
557
558         while (go_to_loop) {
559                 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
560                 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
561
562                 if (0 >= scanf("%d", &menu_number))
563                         testapp_print("Invalid input");
564
565                 go_to_loop = testapp_interpret_command_basic_test(menu_number);
566         }
567 }
568 /* Basic Test } ---------------------------------------------------------------*/
569
570 /* Setting Test } ---------------------------------------------------------------*/
571
572 static int testapp_test_get_setting_list()
573 {
574         int err = NOTIFICATION_ERROR_NONE;
575         int i = 0;
576         int count = 0;
577         char *package_name = NULL;
578         bool allow_to_notify = false;
579         bool do_not_disturb_except = false;
580         int visibility_class = false;
581         notification_setting_h setting_array = NULL;
582
583         notification_setting_get_setting_array(&setting_array, &count);
584
585         testapp_print("count [%d]\n", count);
586
587         for (i = 0; i < count; i++) {
588                 notification_setting_get_package_name(setting_array + i, &package_name);
589                 notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify);
590                 notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except);
591                 notification_setting_get_visibility_class(setting_array + i, &visibility_class);
592
593                 testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n"
594                                 ,i, package_name, allow_to_notify, do_not_disturb_except, visibility_class);
595                 free(package_name);
596         }
597
598         notification_setting_free_notification(setting_array);
599
600         return err;
601 }
602
603 static int testapp_test_update_setting()
604 {
605         int err = NOTIFICATION_ERROR_NONE;
606         notification_setting_h setting = NULL;
607
608         err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
609
610         if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
611                 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
612         }
613         else {
614                 notification_setting_set_allow_to_notify(setting, 0);
615                 notification_setting_update_setting(setting);
616         }
617
618         return err;
619 }
620
621 static int testapp_test_update_system_setting()
622 {
623         int err = NOTIFICATION_ERROR_NONE;
624         bool do_not_disturb;
625         int visibility_class;
626         notification_system_setting_h system_setting = NULL;
627
628         err = notification_system_setting_load_system_setting(&system_setting);
629
630         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
631                 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
632                 goto out;
633         }
634
635         notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
636         testapp_print("do_not_disturb [%d]\n", do_not_disturb);
637         do_not_disturb = !do_not_disturb;
638         notification_system_setting_set_do_not_disturb(system_setting, do_not_disturb);
639
640         notification_system_setting_get_visibility_class(system_setting, &visibility_class);
641         testapp_print("visibility_class [%d]\n", visibility_class);
642         visibility_class = !visibility_class;
643         notification_system_setting_set_visibility_class(system_setting, visibility_class);
644
645         err = notification_system_setting_update_system_setting(system_setting);
646
647         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
648                 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
649                 goto out;
650         }
651
652 out:
653         if (system_setting)
654                 notification_system_setting_free_system_setting(system_setting);
655
656         return err;
657 }
658
659 static int testapp_test_refresh_setting_table()
660 {
661         int err = NOTIFICATION_ERROR_NONE;
662         err = notification_setting_refresh_setting_table();
663
664         if (err != NOTIFICATION_ERROR_NONE) {
665                 testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
666                 goto out;
667         }
668
669 out:
670
671         return err;
672 }
673
674 static gboolean testapp_interpret_command_setting_test (int selected_number)
675 {
676         gboolean go_to_loop = TRUE;
677
678         switch (selected_number) {
679         case 1:
680                 testapp_test_get_setting_list();
681                 break;
682
683         case 2:
684                 testapp_test_update_setting();
685                 break;
686
687         case 3:
688                 testapp_test_update_system_setting();
689                 break;
690
691         case 4:
692                 testapp_test_refresh_setting_table();
693                 break;
694
695         case 0:
696                 go_to_loop = FALSE;
697                 break;
698
699         default:
700                 break;
701         }
702
703         return go_to_loop;
704
705 }
706
707 void testapp_setting_main()
708 {
709         gboolean go_to_loop = TRUE;
710         int menu_number = 0;
711
712         while (go_to_loop) {
713                 testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
714                 testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
715
716                 if (0 >= scanf("%d", &menu_number))
717                         testapp_print("Invalid input");
718
719                 go_to_loop = testapp_interpret_command_setting_test(menu_number);
720         }
721 }
722 /* Setting Test } ---------------------------------------------------------------*/
723
724 /* Main { ---------------------------------------------------------------------*/
725 static gboolean testapp_interpret_command (int menu_number)
726 {
727         gboolean go_to_loop = TRUE;
728
729         switch (menu_number) {
730         case 1:
731                 testapp_notification_main();
732                 break;
733
734         case 2:
735                 testapp_setting_main();
736                 break;
737
738         case 0:
739                 go_to_loop = FALSE;
740                 break;
741
742         default:
743                 break;
744         }
745
746         return go_to_loop;
747 }
748
749 void testapp_show_prompt (testapp_menu_type_e menu)
750 {
751         switch (menu) {
752         case TESTAPP_MENU_TYPE_MAIN_MENU:
753                 testapp_print ("[MAIN]# ");
754                 break;
755
756         case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
757                 testapp_print ("[BASIC_TEST]# ");
758                 break;
759
760         case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
761                 testapp_print ("[SETTING_TEST]# ");
762                 break;
763         }
764 }
765
766 int main (int argc, char *argv[])
767 {
768         gboolean go_to_loop = TRUE;
769         int menu_number = 0;
770
771         if ( testapp_initialize_testing() == FALSE ) {
772                 testapp_print ("Initializing failed.\n");
773                 return 1;
774         }
775
776         while (go_to_loop) {
777                 testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
778                 testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
779                 if (0 >= scanf ("%d", &menu_number))
780                         testapp_print("Invalid input");
781                 go_to_loop = testapp_interpret_command (menu_number);
782         }
783
784         testapp_finalize_testing();
785
786         return 0;
787 }
788 /* Main } ---------------------------------------------------------------------*/
789