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