2 * Test application for notification API
4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
44 /*-----------------------------------------------------------------------------------------*/
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;
52 /*-----------------------------------------------------------------------------------------*/
53 /* function prototypes */
54 static void testapp_system_signal_handler (int signal_number);
55 void testapp_show_prompt (testapp_menu_type_e menu);
57 /*-----------------------------------------------------------------------------------------*/
59 void testapp_print (char *fmt, ...)
63 vfprintf (stdout, fmt, args);
68 static gboolean testapp_initialize_testing ()
70 struct timeval tv_1, tv_2;
73 /* register signal handler */
74 if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
75 testapp_print ("register signal handler fail\n");
79 if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
80 testapp_print ("register signal handler fail\n");
84 if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
85 testapp_print ("register signal handler fail\n");
89 if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
90 testapp_print ("register signal handler fail\n");
95 gettimeofday(&tv_1, NULL);
97 /* TODO : initializing notification */
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);
107 static gboolean testapp_finalize_testing ()
109 /* TODO : finalizing notification */
114 static void testapp_system_signal_handler (int signal_number)
116 testapp_print ("signal:%d\n", signal_number);
117 switch (signal_number) {
122 testapp_finalize_testing();
126 testapp_print ("unhandled signal:%d\n", signal_number);
135 void testapp_show_menu (testapp_menu_type_e 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");
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");
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");
176 /* Common { ------------------------------------------------------------------*/
178 static int testapp_add_a_notification()
180 notification_h noti_handle = NULL;
181 int noti_err = NOTIFICATION_ERROR_NONE;
183 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
185 if (noti_handle == NULL) {
186 testapp_print("notification_create failed");
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);
200 noti_err = notification_set_ongoing_flag(noti_handle, true);
201 noti_err = notification_set_auto_remove(noti_handle, false);
203 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
205 noti_err = notification_post(noti_handle);
207 if (noti_err != NOTIFICATION_ERROR_NONE) {
208 testapp_print("notification_post failed[%d]", noti_err);
214 notification_free(noti_handle);
219 /* Common } ------------------------------------------------------------------*/
221 /* Basic Test { --------------------------------------------------------------*/
222 static int testapp_test_post_notification()
224 int err = NOTIFICATION_ERROR_NONE;
226 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
227 testapp_print("testapp_add_a_notification failed[%d]", err);
237 static int testapp_test_post_notifications()
239 int err = NOTIFICATION_ERROR_NONE;
240 int repeat_count = 0;
243 testapp_print("Input count : ");
245 if (0 >= scanf("%d", &repeat_count)) {
246 testapp_print("Invalid input");
250 if (repeat_count > 30) {
251 testapp_print("Too many count");
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);
266 static int testapp_test_post_notification_on_indicator()
268 notification_h noti_handle = NULL;
269 int noti_err = NOTIFICATION_ERROR_NONE;
271 noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
273 if (noti_handle == NULL) {
274 testapp_print("notification_create failed");
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);
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);
317 static int testapp_test_delete_all_notifications()
319 int noti_err = NOTIFICATION_ERROR_NONE;
321 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
323 testapp_print("notification_delete_all returns[%d]", noti_err);
328 static int testapp_test_post_heads_up_notification_with_button()
330 notification_h noti_handle = NULL;
331 int noti_err = NOTIFICATION_ERROR_NONE;
332 int app_control_err = APP_CONTROL_ERROR_NONE;
336 app_control_h app_control = NULL;
337 time_t result = time(NULL);
338 char tag[100] = { 0, };
340 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
342 if (noti_handle == NULL) {
343 testapp_print("notification_create failed");
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);
350 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ACTIVE | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
352 snprintf(tag, 100, "%d", (int)result);
354 noti_err = notification_set_tag(noti_handle, tag);
356 if (noti_err != NOTIFICATION_ERROR_NONE) {
357 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
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);
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);
373 noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
375 if (noti_err != NOTIFICATION_ERROR_NONE) {
376 testapp_print("notification_set_event_handler failed[%d]", noti_err);
380 app_control_destroy(app_control);
383 noti_err = notification_post(noti_handle);
385 if (noti_err != NOTIFICATION_ERROR_NONE) {
386 testapp_print("notification_post failed[%d]", noti_err);
390 noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
392 if (noti_err != NOTIFICATION_ERROR_NONE) {
393 testapp_print("notification_get_id failed[%d]", noti_err);
398 notification_free(noti_handle);
401 noti_handle = notification_load(NULL, priv_id);
403 if (noti_handle == NULL) {
404 testapp_print("notification_load failed");
408 noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
410 if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) {
411 testapp_print("notification_get_event_handler failed[%d]", noti_err);
415 app_control_get_app_id(app_control, &app_id);
418 testapp_print("result app_id [%s]\n", app_id);
425 app_control_destroy(app_control);
428 notification_free(noti_handle);
433 static int testapp_test_post_notification_with_domain_text()
435 notification_h noti_handle = NULL;
436 int noti_err = NOTIFICATION_ERROR_NONE;
437 time_t result = time(NULL);
438 char tag[100] = { 0, };
440 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
442 if (noti_handle == NULL) {
443 testapp_print("notification_create failed");
447 noti_err = notification_set_text_domain(noti_handle, "message", "/usr/apps/org.tizen.message/res/locale");
449 if (noti_err != NOTIFICATION_ERROR_NONE) {
450 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
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);
460 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
462 if (noti_err != NOTIFICATION_ERROR_NONE) {
463 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
467 snprintf(tag, 100, "%d", (int)result);
469 noti_err = notification_set_tag(noti_handle, tag);
471 if (noti_err != NOTIFICATION_ERROR_NONE) {
472 testapp_print("notification_set_tag failed[%d]\n", noti_err);
476 noti_err = notification_post(noti_handle);
478 if (noti_err != NOTIFICATION_ERROR_NONE) {
479 testapp_print("notification_post failed[%d]", noti_err);
487 notification_free(noti_handle);
492 static int testapp_test_load_by_tag()
494 notification_h noti_handle = NULL;
495 int noti_err = NOTIFICATION_ERROR_NONE;
497 noti_handle = notification_load_by_tag("hfe4fif#$sd$ew");
499 if (noti_handle == NULL) {
500 testapp_print("notification_load_by_tag failed");
506 notification_free(noti_handle);
511 static int testapp_test_get_list()
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;
523 noti_err = notification_get_detail_list("./notification-test-app", NOTIFICATION_PRIV_ID_NONE, NOTIFICATION_GROUP_ID_NONE, 10, ¬i_list_handle);
525 if (noti_err != NOTIFICATION_ERROR_NONE) {
526 testapp_print("notification_get_detail_list failed[%d]\n", noti_err);
530 noti_list_cursor_handle = notification_list_get_head(noti_list_handle);
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);
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);
545 if (noti_list_handle)
546 notification_free_list(noti_list_handle);
551 static gboolean testapp_interpret_command_basic_test (int selected_number)
553 gboolean go_to_loop = TRUE;
555 switch (selected_number) {
557 testapp_test_post_notification();
561 testapp_test_post_notifications();
565 testapp_test_post_notification_on_indicator();
569 testapp_test_post_status_message();
573 testapp_test_delete_all_notifications();
577 testapp_test_post_heads_up_notification_with_button();
581 testapp_test_post_notification_with_domain_text();
585 testapp_test_load_by_tag();
589 testapp_test_get_list();
604 void testapp_notification_main ()
606 gboolean go_to_loop = TRUE;
610 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
611 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
613 if (0 >= scanf("%d", &menu_number))
614 testapp_print("Invalid input");
616 go_to_loop = testapp_interpret_command_basic_test(menu_number);
619 /* Basic Test } ---------------------------------------------------------------*/
621 /* Setting Test } ---------------------------------------------------------------*/
623 static int testapp_test_get_setting_list()
625 int err = NOTIFICATION_ERROR_NONE;
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;
634 notification_setting_get_setting_array(&setting_array, &count);
636 testapp_print("count [%d]\n", count);
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);
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);
649 notification_setting_free_notification(setting_array);
654 static int testapp_test_update_setting()
656 int err = NOTIFICATION_ERROR_NONE;
657 notification_setting_h setting = NULL;
659 err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
661 if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
662 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
665 notification_setting_set_allow_to_notify(setting, 0);
666 notification_setting_update_setting(setting);
670 notification_setting_free_notification(setting);
676 static int testapp_test_update_system_setting()
678 int err = NOTIFICATION_ERROR_NONE;
680 int visibility_class;
681 notification_system_setting_h system_setting = NULL;
683 err = notification_system_setting_load_system_setting(&system_setting);
685 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
686 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
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);
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);
700 err = notification_system_setting_update_system_setting(system_setting);
702 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
703 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
709 notification_system_setting_free_system_setting(system_setting);
714 static int testapp_test_refresh_setting_table()
716 int err = NOTIFICATION_ERROR_NONE;
717 err = notification_setting_refresh_setting_table();
719 if (err != NOTIFICATION_ERROR_NONE) {
720 testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
729 static gboolean testapp_interpret_command_setting_test (int selected_number)
731 gboolean go_to_loop = TRUE;
733 switch (selected_number) {
735 testapp_test_get_setting_list();
739 testapp_test_update_setting();
743 testapp_test_update_system_setting();
747 testapp_test_refresh_setting_table();
762 void testapp_setting_main()
764 gboolean go_to_loop = TRUE;
768 testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
769 testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
771 if (0 >= scanf("%d", &menu_number))
772 testapp_print("Invalid input");
774 go_to_loop = testapp_interpret_command_setting_test(menu_number);
777 /* Setting Test } ---------------------------------------------------------------*/
779 /* Main { ---------------------------------------------------------------------*/
780 static gboolean testapp_interpret_command (int menu_number)
782 gboolean go_to_loop = TRUE;
784 switch (menu_number) {
786 testapp_notification_main();
790 testapp_setting_main();
804 void testapp_show_prompt (testapp_menu_type_e menu)
807 case TESTAPP_MENU_TYPE_MAIN_MENU:
808 testapp_print ("[MAIN]# ");
811 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
812 testapp_print ("[BASIC_TEST]# ");
815 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
816 testapp_print ("[SETTING_TEST]# ");
821 int main (int argc, char *argv[])
823 gboolean go_to_loop = TRUE;
826 if ( testapp_initialize_testing() == FALSE ) {
827 testapp_print ("Initializing failed.\n");
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);
839 testapp_finalize_testing();
843 /* Main } ---------------------------------------------------------------------*/