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_status.h>
38 #include <notification_setting.h>
39 #include <notification_setting_internal.h>
40 #include <notification_text_domain.h>
42 /*-----------------------------------------------------------------------------------------*/
44 typedef enum testapp_menu_type {
45 TESTAPP_MENU_TYPE_MAIN_MENU = 1,
46 TESTAPP_MENU_TYPE_BASIC_TEST_MENU = 2,
47 TESTAPP_MENU_TYPE_SETTING_TEST_MENU = 3
48 } testapp_menu_type_e;
50 /*-----------------------------------------------------------------------------------------*/
51 /* function prototypes */
52 static void testapp_system_signal_handler (int signal_number);
53 void testapp_show_prompt (testapp_menu_type_e menu);
55 /*-----------------------------------------------------------------------------------------*/
57 void testapp_print (char *fmt, ...)
61 vfprintf (stdout, fmt, args);
66 static gboolean testapp_initialize_testing ()
68 struct timeval tv_1, tv_2;
71 /* register signal handler */
72 if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
73 testapp_print ("register signal handler fail\n");
77 if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
78 testapp_print ("register signal handler fail\n");
82 if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
83 testapp_print ("register signal handler fail\n");
87 if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
88 testapp_print ("register signal handler fail\n");
93 gettimeofday(&tv_1, NULL);
95 /* TODO : initializing notification */
97 gettimeofday(&tv_2, NULL);
98 interval = tv_2.tv_usec - tv_1.tv_usec;
99 testapp_print("\t Initializing Proceed time %d us\n",interval);
105 static gboolean testapp_finalize_testing ()
107 /* TODO : finalizing notification */
112 static void testapp_system_signal_handler (int signal_number)
114 testapp_print ("signal:%d\n", signal_number);
115 switch (signal_number) {
120 testapp_finalize_testing();
124 testapp_print ("unhandled signal:%d\n", signal_number);
133 void testapp_show_menu (testapp_menu_type_e menu)
136 case TESTAPP_MENU_TYPE_MAIN_MENU:
137 testapp_print ("==========================================\n");
138 testapp_print (" Notification test application \n");
139 testapp_print ("==========================================\n");
140 testapp_print ("1. Basic Test\n");
141 testapp_print ("2. Setting Test\n");
142 testapp_print ("0. Exit \n");
143 testapp_print ("------------------------------------------\n");
145 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
146 testapp_print ("==========================================\n");
147 testapp_print (" Basic test menu \n");
148 testapp_print ("==========================================\n");
149 testapp_print (" 1. Post a simple notification\n");
150 testapp_print (" 2. Post simple notifications repeatedly\n");
151 testapp_print (" 3. Post a notification on indicator\n");
152 testapp_print (" 4. Post status status message\n");
153 testapp_print (" 5. Delete all notification\n");
154 testapp_print (" 6. Post a heads notification with a button\n");
155 testapp_print (" 7. Post a notification with domain text\n");
156 testapp_print (" 8. Load by tag\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_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
199 noti_err = notification_post(noti_handle);
201 if (noti_err != NOTIFICATION_ERROR_NONE) {
202 testapp_print("notification_post failed[%d]", noti_err);
208 notification_free(noti_handle);
213 /* Common } ------------------------------------------------------------------*/
215 /* Basic Test { --------------------------------------------------------------*/
216 static int testapp_test_post_notification()
218 int err = NOTIFICATION_ERROR_NONE;
220 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
221 testapp_print("testapp_add_a_notification failed[%d]", err);
231 static int testapp_test_post_notifications()
233 int err = NOTIFICATION_ERROR_NONE;
234 int repeat_count = 0;
237 testapp_print("Input count : ");
239 if (0 >= scanf("%d", &repeat_count)) {
240 testapp_print("Invalid input");
244 if (repeat_count > 30) {
245 testapp_print("Too many count");
249 for (i = 0; i < repeat_count; i++) {
250 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
251 testapp_print("testapp_add_a_notification failed[%d]", err);
260 static int testapp_test_post_notification_on_indicator()
262 notification_h noti_handle = NULL;
263 int noti_err = NOTIFICATION_ERROR_NONE;
265 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
267 if (noti_handle == NULL) {
268 testapp_print("notification_create failed");
272 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
273 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "This is very loooooooooooooooooooooooooooooooooooooooooong message", NOTIFICATION_VARIABLE_TYPE_NONE);
275 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR);
277 if(noti_err != NOTIFICATION_ERROR_NONE) {
278 testapp_print("notification_set_display_applist failed[%d]", noti_err);
282 noti_err = notification_post(noti_handle);
284 if (noti_err != NOTIFICATION_ERROR_NONE) {
285 testapp_print("notification_post failed[%d]", noti_err);
291 notification_free(noti_handle);
296 static int testapp_test_post_status_message()
298 int noti_err = NOTIFICATION_ERROR_NONE;
301 noti_err = notification_status_message_post("This is only a test");
303 if(noti_err != NOTIFICATION_ERROR_NONE) {
304 testapp_print("notification_status_message_post failed[%d]", noti_err);
310 static int testapp_test_delete_all_notifications()
312 int noti_err = NOTIFICATION_ERROR_NONE;
314 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
316 testapp_print("notification_delete_all returns[%d]", noti_err);
321 static int testapp_test_post_heads_up_notification_with_button()
323 notification_h noti_handle = NULL;
324 int noti_err = NOTIFICATION_ERROR_NONE;
325 int app_control_err = APP_CONTROL_ERROR_NONE;
329 app_control_h app_control = NULL;
330 time_t result = time(NULL);
331 char tag[100] = { 0, };
333 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
335 if (noti_handle == NULL) {
336 testapp_print("notification_create failed");
340 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
341 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
343 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ACTIVE | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
345 snprintf(tag, 100, "%d", (int)result);
347 noti_err = notification_set_tag(noti_handle, tag);
349 if (noti_err != NOTIFICATION_ERROR_NONE) {
350 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
354 app_control_err = app_control_create(&app_control);
355 if (app_control_err != APP_CONTROL_ERROR_NONE ) {
356 testapp_print("app_control_create failed[%d]\n", app_control_err);
360 app_control_err = app_control_set_app_id(app_control, "org.tizen.quickpanel");
361 if (app_control_err != APP_CONTROL_ERROR_NONE ) {
362 testapp_print("app_control_set_app_id failed[%d]\n", app_control_err);
366 noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
368 if (noti_err != NOTIFICATION_ERROR_NONE) {
369 testapp_print("notification_set_event_handler failed[%d]", noti_err);
373 app_control_destroy(app_control);
376 noti_err = notification_post(noti_handle);
378 if (noti_err != NOTIFICATION_ERROR_NONE) {
379 testapp_print("notification_post failed[%d]", noti_err);
383 noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
385 if (noti_err != NOTIFICATION_ERROR_NONE) {
386 testapp_print("notification_get_id failed[%d]", noti_err);
391 notification_free(noti_handle);
394 noti_handle = notification_load(NULL, priv_id);
396 if (noti_handle == NULL) {
397 testapp_print("notification_load failed");
401 noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
403 if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) {
404 testapp_print("notification_get_event_handler failed[%d]", noti_err);
408 app_control_get_app_id(app_control, &app_id);
411 testapp_print("result app_id [%s]\n", app_id);
418 app_control_destroy(app_control);
421 notification_free(noti_handle);
426 static int testapp_test_post_notification_with_domain_text()
428 notification_h noti_handle = NULL;
429 int noti_err = NOTIFICATION_ERROR_NONE;
430 time_t result = time(NULL);
431 char tag[100] = { 0, };
433 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
435 if (noti_handle == NULL) {
436 testapp_print("notification_create failed");
440 noti_err = notification_set_text_domain(noti_handle, "message", "/usr/apps/org.tizen.message/res/locale");
442 if (noti_err != NOTIFICATION_ERROR_NONE) {
443 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
447 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
448 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "[%s] *** [%s]",
449 NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_BODY_NO_SUBJECT",
450 NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_POP_NEW_MESSAGE",
451 NOTIFICATION_VARIABLE_TYPE_NONE);
453 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
455 if (noti_err != NOTIFICATION_ERROR_NONE) {
456 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
460 snprintf(tag, 100, "%d", (int)result);
462 noti_err = notification_set_tag(noti_handle, tag);
464 if (noti_err != NOTIFICATION_ERROR_NONE) {
465 testapp_print("notification_set_tag failed[%d]\n", noti_err);
469 noti_err = notification_post(noti_handle);
471 if (noti_err != NOTIFICATION_ERROR_NONE) {
472 testapp_print("notification_post failed[%d]", noti_err);
480 notification_free(noti_handle);
485 static int testapp_test_load_by_tag()
487 notification_h noti_handle = NULL;
488 int noti_err = NOTIFICATION_ERROR_NONE;
490 noti_handle = notification_load_by_tag("hfe4fif#$sd$ew");
492 if (noti_handle == NULL) {
493 testapp_print("notification_load_by_tag failed");
499 notification_free(noti_handle);
504 static gboolean testapp_interpret_command_basic_test (int selected_number)
506 gboolean go_to_loop = TRUE;
508 switch (selected_number) {
510 testapp_test_post_notification();
514 testapp_test_post_notifications();
518 testapp_test_post_notification_on_indicator();
522 testapp_test_post_status_message();
526 testapp_test_delete_all_notifications();
530 testapp_test_post_heads_up_notification_with_button();
534 testapp_test_post_notification_with_domain_text();
538 testapp_test_load_by_tag();
553 void testapp_notification_main ()
555 gboolean go_to_loop = TRUE;
559 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
560 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
562 if (0 >= scanf("%d", &menu_number))
563 testapp_print("Invalid input");
565 go_to_loop = testapp_interpret_command_basic_test(menu_number);
568 /* Basic Test } ---------------------------------------------------------------*/
570 /* Setting Test } ---------------------------------------------------------------*/
572 static int testapp_test_get_setting_list()
574 int err = NOTIFICATION_ERROR_NONE;
577 char *package_name = NULL;
578 bool allow_to_notify = false;
579 bool do_not_disturb_except = false;
580 int visibility_class = false;
581 notification_setting_h setting_array = NULL;
583 notification_setting_get_setting_array(&setting_array, &count);
585 testapp_print("count [%d]\n", count);
587 for (i = 0; i < count; i++) {
588 notification_setting_get_package_name(setting_array + i, &package_name);
589 notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify);
590 notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except);
591 notification_setting_get_visibility_class(setting_array + i, &visibility_class);
593 testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n"
594 ,i, package_name, allow_to_notify, do_not_disturb_except, visibility_class);
598 notification_setting_free_notification(setting_array);
603 static int testapp_test_update_setting()
605 int err = NOTIFICATION_ERROR_NONE;
606 notification_setting_h setting = NULL;
608 err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
610 if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
611 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
614 notification_setting_set_allow_to_notify(setting, 0);
615 notification_setting_update_setting(setting);
621 static int testapp_test_update_system_setting()
623 int err = NOTIFICATION_ERROR_NONE;
625 int visibility_class;
626 notification_system_setting_h system_setting = NULL;
628 err = notification_system_setting_load_system_setting(&system_setting);
630 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
631 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
635 notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
636 testapp_print("do_not_disturb [%d]\n", do_not_disturb);
637 do_not_disturb = !do_not_disturb;
638 notification_system_setting_set_do_not_disturb(system_setting, do_not_disturb);
640 notification_system_setting_get_visibility_class(system_setting, &visibility_class);
641 testapp_print("visibility_class [%d]\n", visibility_class);
642 visibility_class = !visibility_class;
643 notification_system_setting_set_visibility_class(system_setting, visibility_class);
645 err = notification_system_setting_update_system_setting(system_setting);
647 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
648 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
654 notification_system_setting_free_system_setting(system_setting);
659 static int testapp_test_refresh_setting_table()
661 int err = NOTIFICATION_ERROR_NONE;
662 err = notification_setting_refresh_setting_table();
664 if (err != NOTIFICATION_ERROR_NONE) {
665 testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
674 static gboolean testapp_interpret_command_setting_test (int selected_number)
676 gboolean go_to_loop = TRUE;
678 switch (selected_number) {
680 testapp_test_get_setting_list();
684 testapp_test_update_setting();
688 testapp_test_update_system_setting();
692 testapp_test_refresh_setting_table();
707 void testapp_setting_main()
709 gboolean go_to_loop = TRUE;
713 testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
714 testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
716 if (0 >= scanf("%d", &menu_number))
717 testapp_print("Invalid input");
719 go_to_loop = testapp_interpret_command_setting_test(menu_number);
722 /* Setting Test } ---------------------------------------------------------------*/
724 /* Main { ---------------------------------------------------------------------*/
725 static gboolean testapp_interpret_command (int menu_number)
727 gboolean go_to_loop = TRUE;
729 switch (menu_number) {
731 testapp_notification_main();
735 testapp_setting_main();
749 void testapp_show_prompt (testapp_menu_type_e menu)
752 case TESTAPP_MENU_TYPE_MAIN_MENU:
753 testapp_print ("[MAIN]# ");
756 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
757 testapp_print ("[BASIC_TEST]# ");
760 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
761 testapp_print ("[SETTING_TEST]# ");
766 int main (int argc, char *argv[])
768 gboolean go_to_loop = TRUE;
771 if ( testapp_initialize_testing() == FALSE ) {
772 testapp_print ("Initializing failed.\n");
777 testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
778 testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
779 if (0 >= scanf ("%d", &menu_number))
780 testapp_print("Invalid input");
781 go_to_loop = testapp_interpret_command (menu_number);
784 testapp_finalize_testing();
788 /* Main } ---------------------------------------------------------------------*/