Add multi-user feature
[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(" 10. Post noti to 5002 \n");
158                 testapp_print("------------------------------------------\n");
159                 break;
160         case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
161                 testapp_print("==========================================\n");
162                 testapp_print("    Setting test menu \n");
163                 testapp_print("==========================================\n");
164                 testapp_print(" 1.  Get setting list\n");
165                 testapp_print(" 2.  Update setting\n");
166                 testapp_print(" 3.  Update system setting\n");
167                 testapp_print(" 4.  Refresh setting table\n");
168                 testapp_print("------------------------------------------\n");
169                 break;
170         default:
171                 break;
172         }
173 }
174 /* Common { ------------------------------------------------------------------*/
175
176
177 static int testapp_add_a_notification_to_bob()
178 {
179         notification_h noti_handle = NULL;
180         int noti_err = NOTIFICATION_ERROR_NONE;
181
182         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
183
184         if (noti_handle == NULL) {
185                 testapp_print("notification_create failed");
186                 goto FINISH_OFF;
187         }
188
189         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
190         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
191         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
192         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
193         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);
194         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
195         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);
196         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
197         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);
198
199         noti_err  = notification_set_ongoing_flag(noti_handle, true);
200         noti_err  = notification_set_auto_remove(noti_handle, false);
201
202         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
203
204         noti_err  = notification_post_for_uid(noti_handle, 5002);
205
206         if (noti_err != NOTIFICATION_ERROR_NONE) {
207                 testapp_print("notification_post failed[%d]", noti_err);
208                 goto FINISH_OFF;
209         }
210
211 FINISH_OFF:
212         if (noti_handle)
213                 notification_free(noti_handle);
214
215         return noti_err;
216 }
217
218
219 static int testapp_add_a_notification()
220 {
221         notification_h noti_handle = NULL;
222         int noti_err = NOTIFICATION_ERROR_NONE;
223
224         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
225
226         if (noti_handle == NULL) {
227                 testapp_print("notification_create failed");
228                 goto FINISH_OFF;
229         }
230
231         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
232         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
233         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
234         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
235         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);
236         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
237         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);
238         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
239         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);
240
241         noti_err  = notification_set_ongoing_flag(noti_handle, true);
242         noti_err  = notification_set_auto_remove(noti_handle, false);
243
244         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
245
246         noti_err  = notification_post(noti_handle);
247
248         if (noti_err != NOTIFICATION_ERROR_NONE) {
249                 testapp_print("notification_post failed[%d]", noti_err);
250                 goto FINISH_OFF;
251         }
252
253 FINISH_OFF:
254         if (noti_handle)
255                 notification_free(noti_handle);
256
257         return noti_err;
258 }
259
260 /* Common } ------------------------------------------------------------------ */
261
262 /* Basic Test { -------------------------------------------------------------- */
263 static int testapp_test_post_notification()
264 {
265         int err = NOTIFICATION_ERROR_NONE;
266
267         if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
268                 testapp_print("testapp_add_a_notification failed[%d]", err);
269                 goto FINISH_OFF;
270         }
271
272
273 FINISH_OFF:
274
275         return err;
276 }
277
278 static int testapp_test_post_notifications()
279 {
280         int err = NOTIFICATION_ERROR_NONE;
281         int repeat_count = 0;
282         int i = 0;
283
284         testapp_print("Input count : ");
285
286         if (0 >= scanf("%d", &repeat_count)) {
287                 testapp_print("Invalid input");
288                 goto FINISH_OFF;
289         }
290
291         if (repeat_count > 30) {
292                 testapp_print("Too many count");
293                 goto FINISH_OFF;
294         }
295
296         for (i = 0; i < repeat_count; i++) {
297                 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
298                         testapp_print("testapp_add_a_notification failed[%d]", err);
299                         goto FINISH_OFF;
300                 }
301         }
302
303 FINISH_OFF:
304         return err;
305 }
306
307 static int testapp_test_post_notification_on_indicator()
308 {
309         notification_h noti_handle = NULL;
310         int noti_err = NOTIFICATION_ERROR_NONE;
311         char image_path[TIZEN_PATH_MAX] = {0, };
312
313         noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
314
315         if (noti_handle == NULL) {
316                 testapp_print("notification_create failed");
317                 goto FINISH_OFF;
318         }
319
320         snprintf(image_path, TIZEN_PATH_MAX, "%s/org.tizen.indicator/res/icons/Shealth/B03_shealth.png", PATH_FMT_RO_APP_ROOT);
321         noti_err  = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, image_path);
322         /*
323         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
324         noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "This is very long message", NOTIFICATION_VARIABLE_TYPE_NONE);
325         */
326         noti_err  = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR);
327
328         if (noti_err != NOTIFICATION_ERROR_NONE) {
329                 testapp_print("notification_set_display_applist failed[%d]", noti_err);
330                 goto FINISH_OFF;
331         }
332
333         noti_err  = notification_post(noti_handle);
334
335         if (noti_err != NOTIFICATION_ERROR_NONE) {
336                 testapp_print("notification_post failed[%d]", noti_err);
337                 goto FINISH_OFF;
338         }
339
340 FINISH_OFF:
341         if (noti_handle)
342                 notification_free(noti_handle);
343
344         return noti_err;
345 }
346
347 static int testapp_test_post_status_message()
348 {
349         int noti_err = NOTIFICATION_ERROR_NONE;
350
351
352         noti_err = notification_status_message_post("This is only a test");
353
354         if (noti_err != NOTIFICATION_ERROR_NONE)
355                 testapp_print("notification_status_message_post failed[%d]", noti_err);
356
357         return noti_err;
358 }
359
360 static int testapp_test_delete_all_notifications()
361 {
362         int noti_err = NOTIFICATION_ERROR_NONE;
363
364         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
365
366         testapp_print("notification_delete_all returns[%d]", noti_err);
367
368         return noti_err;
369 }
370
371 static int testapp_test_post_heads_up_notification_with_button()
372 {
373         notification_h noti_handle = NULL;
374         int noti_err = NOTIFICATION_ERROR_NONE;
375         int app_control_err = APP_CONTROL_ERROR_NONE;
376         int priv_id = 0;
377         int group_id = 0;
378         char *app_id = NULL;
379         app_control_h app_control = NULL;
380         time_t result = time(NULL);
381         char tag[100] = { 0, };
382
383         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
384
385         if (noti_handle == NULL) {
386                 testapp_print("notification_create failed");
387                 goto FINISH_OFF;
388         }
389
390         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
391         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
392
393         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ACTIVE | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
394
395         snprintf(tag, 100, "%d", (int)result);
396
397         noti_err = notification_set_tag(noti_handle, tag);
398
399         if (noti_err != NOTIFICATION_ERROR_NONE) {
400                 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
401                 goto FINISH_OFF;
402         }
403
404         app_control_err = app_control_create(&app_control);
405         if (app_control_err != APP_CONTROL_ERROR_NONE) {
406                 testapp_print("app_control_create failed[%d]\n", app_control_err);
407                 goto FINISH_OFF;
408         }
409
410         app_control_err = app_control_set_app_id(app_control, "org.tizen.quickpanel");
411         if (app_control_err != APP_CONTROL_ERROR_NONE) {
412                 testapp_print("app_control_set_app_id failed[%d]\n", app_control_err);
413                 goto FINISH_OFF;
414         }
415
416         noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
417
418         if (noti_err != NOTIFICATION_ERROR_NONE) {
419                 testapp_print("notification_set_event_handler failed[%d]", noti_err);
420                 goto FINISH_OFF;
421         }
422
423         app_control_destroy(app_control);
424         app_control = NULL;
425
426         noti_err = notification_post(noti_handle);
427
428         if (noti_err != NOTIFICATION_ERROR_NONE) {
429                 testapp_print("notification_post failed[%d]", noti_err);
430                 goto FINISH_OFF;
431         }
432
433         noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
434
435         if (noti_err != NOTIFICATION_ERROR_NONE) {
436                 testapp_print("notification_get_id failed[%d]", noti_err);
437                 goto FINISH_OFF;
438         }
439
440         if (noti_handle)
441                 notification_free(noti_handle);
442         noti_handle = NULL;
443
444         noti_handle = notification_load(NULL, priv_id);
445
446         if (noti_handle == NULL) {
447                 testapp_print("notification_load failed");
448                 goto FINISH_OFF;
449         }
450
451         noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
452
453         if (noti_err != NOTIFICATION_ERROR_NONE || app_control == NULL) {
454                 testapp_print("notification_get_event_handler failed[%d]", noti_err);
455                 goto FINISH_OFF;
456         }
457
458         app_control_get_app_id(app_control, &app_id);
459
460         if (app_id) {
461                 testapp_print("result app_id [%s]\n", app_id);
462                 free(app_id);
463         }
464
465 FINISH_OFF:
466
467         if (app_control)
468                 app_control_destroy(app_control);
469
470         if (noti_handle)
471                 notification_free(noti_handle);
472
473         return noti_err;
474 }
475
476 static int testapp_test_post_notification_with_domain_text()
477 {
478         notification_h noti_handle = NULL;
479         int noti_err = NOTIFICATION_ERROR_NONE;
480         time_t result = time(NULL);
481         char tag[100] = { 0, };
482
483         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
484
485         if (noti_handle == NULL) {
486                 testapp_print("notification_create failed");
487                 goto FINISH_OFF;
488         }
489
490         noti_err = notification_set_text_domain(noti_handle, "message", "/usr/apps/org.tizen.message/res/locale");
491
492         if (noti_err != NOTIFICATION_ERROR_NONE) {
493                 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
494                 goto FINISH_OFF;
495         }
496
497         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
498         noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "[%s] *** [%s]",
499                         NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_BODY_NO_SUBJECT",
500                         NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_POP_NEW_MESSAGE",
501                         NOTIFICATION_VARIABLE_TYPE_NONE);
502
503         noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
504
505         if (noti_err != NOTIFICATION_ERROR_NONE) {
506                 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
507                 goto FINISH_OFF;
508         }
509
510         snprintf(tag, 100, "%d", (int)result);
511
512         noti_err = notification_set_tag(noti_handle, tag);
513
514         if (noti_err != NOTIFICATION_ERROR_NONE) {
515                 testapp_print("notification_set_tag failed[%d]\n", noti_err);
516                 goto FINISH_OFF;
517         }
518
519         noti_err = notification_post(noti_handle);
520
521         if (noti_err != NOTIFICATION_ERROR_NONE) {
522                 testapp_print("notification_post failed[%d]", noti_err);
523                 goto FINISH_OFF;
524         }
525
526 FINISH_OFF:
527
528
529         if (noti_handle)
530                 notification_free(noti_handle);
531
532         return noti_err;
533 }
534
535 static int testapp_test_load_by_tag()
536 {
537         notification_h noti_handle = NULL;
538         int noti_err = NOTIFICATION_ERROR_NONE;
539
540         noti_handle = notification_load_by_tag("hfe4fif#$sd$ew");
541
542         if (noti_handle == NULL) {
543                 testapp_print("notification_load_by_tag failed");
544                 goto FINISH_OFF;
545         }
546
547 FINISH_OFF:
548         if (noti_handle)
549                 notification_free(noti_handle);
550
551         return noti_err;
552 }
553
554 static int testapp_test_get_list()
555 {
556         notification_h noti_handle = NULL;
557         notification_list_h noti_list_handle = NULL;
558         notification_list_h noti_list_cursor_handle = NULL;
559         int noti_err = NOTIFICATION_ERROR_NONE;
560         int priv_id;
561         int group_id;
562         int type;
563         bool ongoing_flag;
564         bool auto_remove;
565
566         noti_err = notification_get_detail_list("./notification-test-app", NOTIFICATION_PRIV_ID_NONE, NOTIFICATION_GROUP_ID_NONE, 10, &noti_list_handle);
567
568         if (noti_err != NOTIFICATION_ERROR_NONE) {
569                 testapp_print("notification_get_detail_list failed[%d]\n", noti_err);
570                 goto FINISH_OFF;
571         }
572
573         noti_list_cursor_handle = notification_list_get_head(noti_list_handle);
574
575         while (noti_list_cursor_handle) {
576                 noti_handle = notification_list_get_data(noti_list_cursor_handle);
577                 notification_get_id(noti_handle, &group_id, &priv_id);
578                 notification_get_type(noti_handle, &type);
579                 notification_get_ongoing_flag(noti_handle, &ongoing_flag);
580                 notification_get_auto_remove(noti_handle, &auto_remove);
581
582                 testapp_print("priv_id[%d] type[%d] ongoing_flag[%d] auto_remove[%d]\n", priv_id, type, ongoing_flag, auto_remove);
583                 noti_list_cursor_handle = notification_list_get_next(noti_list_cursor_handle);
584         }
585
586
587 FINISH_OFF:
588         if (noti_list_handle)
589                 notification_free_list(noti_list_handle);
590
591         return noti_err;
592 }
593
594 static gboolean testapp_interpret_command_basic_test(int selected_number)
595 {
596         gboolean go_to_loop = TRUE;
597
598         switch (selected_number) {
599         case 1:
600                 testapp_test_post_notification();
601                 break;
602
603         case 2:
604                 testapp_test_post_notifications();
605                 break;
606
607         case 3:
608                 testapp_test_post_notification_on_indicator();
609                 break;
610
611         case 4:
612                 testapp_test_post_status_message();
613                 break;
614
615         case 5:
616                 testapp_test_delete_all_notifications();
617                 break;
618
619         case 6:
620                 testapp_test_post_heads_up_notification_with_button();
621                 break;
622
623         case 7:
624                 testapp_test_post_notification_with_domain_text();
625                 break;
626
627         case 8:
628                 testapp_test_load_by_tag();
629                 break;
630
631         case 9:
632                 testapp_test_get_list();
633                 break;
634         case 10:
635                 testapp_add_a_notification_to_bob();
636                 break;
637
638         case 0:
639                 go_to_loop = FALSE;
640                 break;
641
642         default:
643                 break;
644         }
645
646         return go_to_loop;
647
648 }
649
650 void testapp_notification_main()
651 {
652         gboolean go_to_loop = TRUE;
653         int menu_number = 0;
654
655         while (go_to_loop) {
656                 testapp_show_menu(TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
657                 testapp_show_prompt(TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
658
659                 if (0 >= scanf("%d", &menu_number))
660                         testapp_print("Invalid input");
661
662                 go_to_loop = testapp_interpret_command_basic_test(menu_number);
663         }
664 }
665 /* Basic Test } ---------------------------------------------------------------*/
666
667 /* Setting Test } ---------------------------------------------------------------*/
668
669 static int testapp_test_get_setting_list()
670 {
671         int err = NOTIFICATION_ERROR_NONE;
672         int i = 0;
673         int count = 0;
674         char *package_name = NULL;
675         bool allow_to_notify = false;
676         bool do_not_disturb_except = false;
677         int visibility_class = false;
678         notification_setting_h setting_array = NULL;
679
680         notification_setting_get_setting_array(&setting_array, &count);
681
682         testapp_print("count [%d]\n", count);
683
684         for (i = 0; i < count; i++) {
685                 notification_setting_get_package_name(setting_array + i, &package_name);
686                 notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify);
687                 notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except);
688                 notification_setting_get_visibility_class(setting_array + i, &visibility_class);
689
690                 testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n"
691                                 , i, package_name, allow_to_notify, do_not_disturb_except, visibility_class);
692                 free(package_name);
693         }
694
695         notification_setting_free_notification(setting_array);
696
697         return err;
698 }
699
700 static int testapp_test_update_setting()
701 {
702         int err = NOTIFICATION_ERROR_NONE;
703         notification_setting_h setting = NULL;
704
705         err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
706
707         if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
708                 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
709         } else {
710                 notification_setting_set_allow_to_notify(setting, 0);
711                 notification_setting_update_setting(setting);
712         }
713
714         if (setting)
715                 notification_setting_free_notification(setting);
716
717         return err;
718 }
719
720 static int testapp_test_update_system_setting()
721 {
722         int err = NOTIFICATION_ERROR_NONE;
723         bool do_not_disturb;
724         int visibility_class;
725         notification_system_setting_h system_setting = NULL;
726
727         err = notification_system_setting_load_system_setting(&system_setting);
728
729         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
730                 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
731                 goto out;
732         }
733
734         notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
735         testapp_print("do_not_disturb [%d]\n", do_not_disturb);
736         do_not_disturb = !do_not_disturb;
737         notification_system_setting_set_do_not_disturb(system_setting, do_not_disturb);
738
739         notification_system_setting_get_visibility_class(system_setting, &visibility_class);
740         testapp_print("visibility_class [%d]\n", visibility_class);
741         visibility_class = !visibility_class;
742         notification_system_setting_set_visibility_class(system_setting, visibility_class);
743
744         err = notification_system_setting_update_system_setting(system_setting);
745
746         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
747                 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
748                 goto out;
749         }
750
751 out:
752         if (system_setting)
753                 notification_system_setting_free_system_setting(system_setting);
754
755         return err;
756 }
757
758 static int testapp_test_refresh_setting_table()
759 {
760         int err = NOTIFICATION_ERROR_NONE;
761         err = notification_setting_refresh_setting_table(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
762
763         if (err != NOTIFICATION_ERROR_NONE) {
764                 testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
765                 goto out;
766         }
767
768 out:
769
770         return err;
771 }
772
773 static gboolean testapp_interpret_command_setting_test(int selected_number)
774 {
775         gboolean go_to_loop = TRUE;
776
777         switch (selected_number) {
778         case 1:
779                 testapp_test_get_setting_list();
780                 break;
781
782         case 2:
783                 testapp_test_update_setting();
784                 break;
785
786         case 3:
787                 testapp_test_update_system_setting();
788                 break;
789
790         case 4:
791                 testapp_test_refresh_setting_table();
792                 break;
793
794         case 0:
795                 go_to_loop = FALSE;
796                 break;
797
798         default:
799                 break;
800         }
801
802         return go_to_loop;
803
804 }
805
806 void testapp_setting_main()
807 {
808         gboolean go_to_loop = TRUE;
809         int menu_number = 0;
810
811         while (go_to_loop) {
812                 testapp_show_menu(TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
813                 testapp_show_prompt(TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
814
815                 if (0 >= scanf("%d", &menu_number))
816                         testapp_print("Invalid input");
817
818                 go_to_loop = testapp_interpret_command_setting_test(menu_number);
819         }
820 }
821 /* Setting Test } ---------------------------------------------------------------*/
822
823 /* Main { ---------------------------------------------------------------------*/
824 static gboolean testapp_interpret_command(int menu_number)
825 {
826         gboolean go_to_loop = TRUE;
827
828         switch (menu_number) {
829         case 1:
830                 testapp_notification_main();
831                 break;
832
833         case 2:
834                 testapp_setting_main();
835                 break;
836
837         case 0:
838                 go_to_loop = FALSE;
839                 break;
840
841         default:
842                 break;
843         }
844
845         return go_to_loop;
846 }
847
848 void testapp_show_prompt(testapp_menu_type_e menu)
849 {
850         switch (menu) {
851         case TESTAPP_MENU_TYPE_MAIN_MENU:
852                 testapp_print("[MAIN]# ");
853                 break;
854
855         case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
856                 testapp_print("[BASIC_TEST]# ");
857                 break;
858
859         case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
860                 testapp_print("[SETTING_TEST]# ");
861                 break;
862         }
863 }
864
865 int main(int argc, char *argv[])
866 {
867         gboolean go_to_loop = TRUE;
868         int menu_number = 0;
869
870         if (testapp_initialize_testing() == FALSE) {
871                 testapp_print("Initializing failed.\n");
872                 return 1;
873         }
874
875         while (go_to_loop) {
876                 testapp_show_menu(TESTAPP_MENU_TYPE_MAIN_MENU);
877                 testapp_show_prompt(TESTAPP_MENU_TYPE_MAIN_MENU);
878                 if (0 >= scanf("%d", &menu_number))
879                         testapp_print("Invalid input");
880                 go_to_loop = testapp_interpret_command(menu_number);
881         }
882
883         testapp_finalize_testing();
884
885         return 0;
886 }
887 /* Main } ---------------------------------------------------------------------*/
888