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