2 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
38 #define PATH_FMT_RO_APP_ROOT tzplatform_getenv(TZ_SYS_RO_APP)
39 #define TIZEN_PATH_MAX 1024
41 /*-----------------------------------------------------------------------------------------*/
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;
49 /*-----------------------------------------------------------------------------------------*/
50 /* function prototypes */
51 static void testapp_system_signal_handler(int signal_number);
52 void testapp_show_prompt(testapp_menu_type_e menu);
54 /*-----------------------------------------------------------------------------------------*/
56 void testapp_print(char *fmt, ...)
60 vfprintf(stdout, fmt, args);
65 static gboolean testapp_initialize_testing()
67 struct timeval tv_1, tv_2;
70 /* register signal handler */
71 if (signal(SIGINT, testapp_system_signal_handler) == SIG_ERR) {
72 testapp_print("register signal handler fail\n");
76 if (signal(SIGQUIT, testapp_system_signal_handler) == SIG_ERR) {
77 testapp_print("register signal handler fail\n");
81 if (signal(SIGTSTP, testapp_system_signal_handler) == SIG_ERR) {
82 testapp_print("register signal handler fail\n");
86 if (signal(SIGTERM, testapp_system_signal_handler) == SIG_ERR) {
87 testapp_print("register signal handler fail\n");
92 gettimeofday(&tv_1, NULL);
94 /* TODO : initializing notification */
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);
104 static gboolean testapp_finalize_testing()
106 /* TODO : finalizing notification */
111 static void testapp_system_signal_handler(int signal_number)
113 testapp_print("signal:%d\n", signal_number);
114 switch (signal_number) {
119 testapp_finalize_testing();
123 testapp_print("unhandled signal:%d\n", signal_number);
132 void testapp_show_menu(testapp_menu_type_e 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");
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");
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");
173 /* Common { ------------------------------------------------------------------*/
175 static int testapp_add_a_notification()
177 notification_h noti_handle = NULL;
178 int noti_err = NOTIFICATION_ERROR_NONE;
180 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
182 if (noti_handle == NULL) {
183 testapp_print("notification_create failed");
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);
197 noti_err = notification_set_ongoing_flag(noti_handle, true);
198 noti_err = notification_set_auto_remove(noti_handle, false);
200 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
202 noti_err = notification_post(noti_handle);
204 if (noti_err != NOTIFICATION_ERROR_NONE) {
205 testapp_print("notification_post failed[%d]", noti_err);
211 notification_free(noti_handle);
216 /* Common } ------------------------------------------------------------------ */
218 /* Basic Test { -------------------------------------------------------------- */
219 static int testapp_test_post_notification()
221 int err = NOTIFICATION_ERROR_NONE;
223 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
224 testapp_print("testapp_add_a_notification failed[%d]", err);
234 static int testapp_test_post_notifications()
236 int err = NOTIFICATION_ERROR_NONE;
237 int repeat_count = 0;
240 testapp_print("Input count : ");
242 if (0 >= scanf("%d", &repeat_count)) {
243 testapp_print("Invalid input");
247 if (repeat_count > 30) {
248 testapp_print("Too many count");
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);
263 static int testapp_test_post_notification_on_indicator()
265 notification_h noti_handle = NULL;
266 int noti_err = NOTIFICATION_ERROR_NONE;
267 char image_path[TIZEN_PATH_MAX] = {0, };
269 noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
271 if (noti_handle == NULL) {
272 testapp_print("notification_create failed");
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);
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);
282 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR);
284 if (noti_err != NOTIFICATION_ERROR_NONE) {
285 testapp_print("notification_set_display_applist failed[%d]", noti_err);
289 noti_err = notification_post(noti_handle);
291 if (noti_err != NOTIFICATION_ERROR_NONE) {
292 testapp_print("notification_post failed[%d]", noti_err);
298 notification_free(noti_handle);
303 static int testapp_test_post_status_message()
305 int noti_err = NOTIFICATION_ERROR_NONE;
308 noti_err = notification_status_message_post("This is only a test");
310 if (noti_err != NOTIFICATION_ERROR_NONE)
311 testapp_print("notification_status_message_post failed[%d]", noti_err);
316 static int testapp_test_delete_all_notifications()
318 int noti_err = NOTIFICATION_ERROR_NONE;
320 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
322 testapp_print("notification_delete_all returns[%d]", noti_err);
327 static int testapp_test_post_heads_up_notification_with_button()
329 notification_h noti_handle = NULL;
330 int noti_err = NOTIFICATION_ERROR_NONE;
331 int app_control_err = APP_CONTROL_ERROR_NONE;
335 app_control_h app_control = NULL;
336 time_t result = time(NULL);
337 char tag[100] = { 0, };
339 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
341 if (noti_handle == NULL) {
342 testapp_print("notification_create failed");
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);
349 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ACTIVE | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
351 snprintf(tag, 100, "%d", (int)result);
353 noti_err = notification_set_tag(noti_handle, tag);
355 if (noti_err != NOTIFICATION_ERROR_NONE) {
356 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
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);
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);
372 noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
374 if (noti_err != NOTIFICATION_ERROR_NONE) {
375 testapp_print("notification_set_event_handler failed[%d]", noti_err);
379 app_control_destroy(app_control);
382 noti_err = notification_post(noti_handle);
384 if (noti_err != NOTIFICATION_ERROR_NONE) {
385 testapp_print("notification_post failed[%d]", noti_err);
389 noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
391 if (noti_err != NOTIFICATION_ERROR_NONE) {
392 testapp_print("notification_get_id failed[%d]", noti_err);
397 notification_free(noti_handle);
400 noti_handle = notification_load(NULL, priv_id);
402 if (noti_handle == NULL) {
403 testapp_print("notification_load failed");
407 noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
409 if (noti_err != NOTIFICATION_ERROR_NONE || app_control == NULL) {
410 testapp_print("notification_get_event_handler failed[%d]", noti_err);
414 app_control_get_app_id(app_control, &app_id);
417 testapp_print("result app_id [%s]\n", app_id);
424 app_control_destroy(app_control);
427 notification_free(noti_handle);
432 static int testapp_test_post_notification_with_domain_text()
434 notification_h noti_handle = NULL;
435 int noti_err = NOTIFICATION_ERROR_NONE;
436 time_t result = time(NULL);
437 char tag[100] = { 0, };
439 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
441 if (noti_handle == NULL) {
442 testapp_print("notification_create failed");
446 noti_err = notification_set_text_domain(noti_handle, "message", "/usr/apps/org.tizen.message/res/locale");
448 if (noti_err != NOTIFICATION_ERROR_NONE) {
449 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
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);
459 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
461 if (noti_err != NOTIFICATION_ERROR_NONE) {
462 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
466 snprintf(tag, 100, "%d", (int)result);
468 noti_err = notification_set_tag(noti_handle, tag);
470 if (noti_err != NOTIFICATION_ERROR_NONE) {
471 testapp_print("notification_set_tag failed[%d]\n", noti_err);
475 noti_err = notification_post(noti_handle);
477 if (noti_err != NOTIFICATION_ERROR_NONE) {
478 testapp_print("notification_post failed[%d]", noti_err);
486 notification_free(noti_handle);
491 static int testapp_test_load_by_tag()
493 notification_h noti_handle = NULL;
494 int noti_err = NOTIFICATION_ERROR_NONE;
496 noti_handle = notification_load_by_tag("hfe4fif#$sd$ew");
498 if (noti_handle == NULL) {
499 testapp_print("notification_load_by_tag failed");
505 notification_free(noti_handle);
510 static int testapp_test_get_list()
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;
522 noti_err = notification_get_detail_list("./notification-test-app", NOTIFICATION_PRIV_ID_NONE, NOTIFICATION_GROUP_ID_NONE, 10, ¬i_list_handle);
524 if (noti_err != NOTIFICATION_ERROR_NONE) {
525 testapp_print("notification_get_detail_list failed[%d]\n", noti_err);
529 noti_list_cursor_handle = notification_list_get_head(noti_list_handle);
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);
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);
544 if (noti_list_handle)
545 notification_free_list(noti_list_handle);
550 static gboolean testapp_interpret_command_basic_test(int selected_number)
552 gboolean go_to_loop = TRUE;
554 switch (selected_number) {
556 testapp_test_post_notification();
560 testapp_test_post_notifications();
564 testapp_test_post_notification_on_indicator();
568 testapp_test_post_status_message();
572 testapp_test_delete_all_notifications();
576 testapp_test_post_heads_up_notification_with_button();
580 testapp_test_post_notification_with_domain_text();
584 testapp_test_load_by_tag();
588 testapp_test_get_list();
603 void testapp_notification_main()
605 gboolean go_to_loop = TRUE;
609 testapp_show_menu(TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
610 testapp_show_prompt(TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
612 if (0 >= scanf("%d", &menu_number))
613 testapp_print("Invalid input");
615 go_to_loop = testapp_interpret_command_basic_test(menu_number);
618 /* Basic Test } ---------------------------------------------------------------*/
620 /* Setting Test } ---------------------------------------------------------------*/
622 static int testapp_test_get_setting_list()
624 int err = NOTIFICATION_ERROR_NONE;
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;
633 notification_setting_get_setting_array(&setting_array, &count);
635 testapp_print("count [%d]\n", count);
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);
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);
648 notification_setting_free_notification(setting_array);
653 static int testapp_test_update_setting()
655 int err = NOTIFICATION_ERROR_NONE;
656 notification_setting_h setting = NULL;
658 err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
660 if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
661 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
663 notification_setting_set_allow_to_notify(setting, 0);
664 notification_setting_update_setting(setting);
668 notification_setting_free_notification(setting);
673 static int testapp_test_update_system_setting()
675 int err = NOTIFICATION_ERROR_NONE;
677 int visibility_class;
678 notification_system_setting_h system_setting = NULL;
680 err = notification_system_setting_load_system_setting(&system_setting);
682 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
683 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
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);
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);
697 err = notification_system_setting_update_system_setting(system_setting);
699 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
700 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
706 notification_system_setting_free_system_setting(system_setting);
711 static int testapp_test_refresh_setting_table()
713 int err = NOTIFICATION_ERROR_NONE;
714 err = notification_setting_refresh_setting_table();
716 if (err != NOTIFICATION_ERROR_NONE) {
717 testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
726 static gboolean testapp_interpret_command_setting_test(int selected_number)
728 gboolean go_to_loop = TRUE;
730 switch (selected_number) {
732 testapp_test_get_setting_list();
736 testapp_test_update_setting();
740 testapp_test_update_system_setting();
744 testapp_test_refresh_setting_table();
759 void testapp_setting_main()
761 gboolean go_to_loop = TRUE;
765 testapp_show_menu(TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
766 testapp_show_prompt(TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
768 if (0 >= scanf("%d", &menu_number))
769 testapp_print("Invalid input");
771 go_to_loop = testapp_interpret_command_setting_test(menu_number);
774 /* Setting Test } ---------------------------------------------------------------*/
776 /* Main { ---------------------------------------------------------------------*/
777 static gboolean testapp_interpret_command(int menu_number)
779 gboolean go_to_loop = TRUE;
781 switch (menu_number) {
783 testapp_notification_main();
787 testapp_setting_main();
801 void testapp_show_prompt(testapp_menu_type_e menu)
804 case TESTAPP_MENU_TYPE_MAIN_MENU:
805 testapp_print("[MAIN]# ");
808 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
809 testapp_print("[BASIC_TEST]# ");
812 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
813 testapp_print("[SETTING_TEST]# ");
818 int main(int argc, char *argv[])
820 gboolean go_to_loop = TRUE;
823 if (testapp_initialize_testing() == FALSE) {
824 testapp_print("Initializing failed.\n");
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);
836 testapp_finalize_testing();
840 /* Main } ---------------------------------------------------------------------*/