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_status.h>
37 #include <notification_setting.h>
38 #include <notification_setting_internal.h>
40 /*-----------------------------------------------------------------------------------------*/
42 typedef enum testapp_menu_type {
43 TESTAPP_MENU_TYPE_MAIN_MENU = 1,
44 TESTAPP_MENU_TYPE_BASIC_TEST_MENU = 2,
45 TESTAPP_MENU_TYPE_SETTING_TEST_MENU = 3
46 } testapp_menu_type_e;
48 /*-----------------------------------------------------------------------------------------*/
49 /* function prototypes */
50 static void testapp_system_signal_handler (int signal_number);
51 void testapp_show_prompt (testapp_menu_type_e menu);
53 /*-----------------------------------------------------------------------------------------*/
55 void testapp_print (char *fmt, ...)
59 vfprintf (stdout, fmt, args);
64 static gboolean testapp_initialize_testing ()
66 struct timeval tv_1, tv_2;
69 /* register signal handler */
70 if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
71 testapp_print ("register signal handler fail\n");
75 if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
76 testapp_print ("register signal handler fail\n");
80 if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
81 testapp_print ("register signal handler fail\n");
85 if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
86 testapp_print ("register signal handler fail\n");
91 gettimeofday(&tv_1, NULL);
93 /* TODO : initializing notification */
95 gettimeofday(&tv_2, NULL);
96 interval = tv_2.tv_usec - tv_1.tv_usec;
97 testapp_print("\t Initializing Proceed time %d us\n",interval);
103 static gboolean testapp_finalize_testing ()
105 /* TODO : finalizing notification */
110 static void testapp_system_signal_handler (int signal_number)
112 testapp_print ("signal:%d\n", signal_number);
113 switch (signal_number) {
118 testapp_finalize_testing();
122 testapp_print ("unhandled signal:%d\n", signal_number);
131 void testapp_show_menu (testapp_menu_type_e menu)
134 case TESTAPP_MENU_TYPE_MAIN_MENU:
135 testapp_print ("==========================================\n");
136 testapp_print (" Notification test application \n");
137 testapp_print ("==========================================\n");
138 testapp_print ("1. Basic Test\n");
139 testapp_print ("2. Setting Test\n");
140 testapp_print ("0. Exit \n");
141 testapp_print ("------------------------------------------\n");
143 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
144 testapp_print ("==========================================\n");
145 testapp_print (" Basic test menu \n");
146 testapp_print ("==========================================\n");
147 testapp_print (" 1. Post a simple notification\n");
148 testapp_print (" 2. Post simple notifications repeatedly\n");
149 testapp_print (" 3. Post a notification on indicator\n");
150 testapp_print (" 4. Post status status message\n");
151 testapp_print (" 5. Delete all notification\n");
152 testapp_print (" 6. Post a heads notification with a button\n");
153 testapp_print (" 7. Post a notification with domain text\n");
154 testapp_print ("------------------------------------------\n");
156 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
157 testapp_print ("==========================================\n");
158 testapp_print (" Setting test menu \n");
159 testapp_print ("==========================================\n");
160 testapp_print (" 1. Get setting list\n");
161 testapp_print (" 2. Update setting\n");
162 testapp_print (" 3. Update system setting\n");
163 testapp_print (" 4. Refresh setting table\n");
164 testapp_print ("------------------------------------------\n");
170 /* Common { ------------------------------------------------------------------*/
172 static int testapp_add_a_notification()
174 notification_h noti_handle = NULL;
175 int noti_err = NOTIFICATION_ERROR_NONE;
177 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
179 if (noti_handle == NULL) {
180 testapp_print("notification_create failed");
184 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
185 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
186 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
187 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
188 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);
189 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
190 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);
191 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
192 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);
194 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
196 noti_err = notification_post(noti_handle);
198 if (noti_err != NOTIFICATION_ERROR_NONE) {
199 testapp_print("notification_post failed[%d]", noti_err);
205 notification_free(noti_handle);
210 /* Common } ------------------------------------------------------------------*/
212 /* Basic Test { --------------------------------------------------------------*/
213 static int testapp_test_post_notification()
215 int err = NOTIFICATION_ERROR_NONE;
217 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
218 testapp_print("testapp_add_a_notification failed[%d]", err);
228 static int testapp_test_post_notifications()
230 int err = NOTIFICATION_ERROR_NONE;
231 int repeat_count = 0;
234 testapp_print("Input count : ");
236 if (0 >= scanf("%d", &repeat_count))
237 testapp_print("Invalid input");
239 for (i = 0; i < repeat_count; i++) {
240 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
241 testapp_print("testapp_add_a_notification failed[%d]", err);
250 static int testapp_test_post_notification_on_indicator()
252 notification_h noti_handle = NULL;
253 int noti_err = NOTIFICATION_ERROR_NONE;
255 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
257 if (noti_handle == NULL) {
258 testapp_print("notification_create failed");
262 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
263 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "This is very loooooooooooooooooooooooooooooooooooooooooong message", NOTIFICATION_VARIABLE_TYPE_NONE);
265 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR);
267 if(noti_err != NOTIFICATION_ERROR_NONE) {
268 testapp_print("notification_set_display_applist failed[%d]", noti_err);
272 noti_err = notification_post(noti_handle);
274 if (noti_err != NOTIFICATION_ERROR_NONE) {
275 testapp_print("notification_post failed[%d]", noti_err);
281 notification_free(noti_handle);
286 static int testapp_test_post_status_message()
288 int noti_err = NOTIFICATION_ERROR_NONE;
291 noti_err = notification_status_message_post("This is only a test");
293 if(noti_err != NOTIFICATION_ERROR_NONE) {
294 testapp_print("notification_status_message_post failed[%d]", noti_err);
300 static int testapp_test_delete_all_notifications()
302 int noti_err = NOTIFICATION_ERROR_NONE;
304 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
306 testapp_print("notification_delete_all returns[%d]", noti_err);
311 static int testapp_test_post_heads_up_notification_with_button()
313 notification_h noti_handle = NULL;
314 int noti_err = NOTIFICATION_ERROR_NONE;
315 int app_control_err = APP_CONTROL_ERROR_NONE;
319 app_control_h app_control = NULL;
320 time_t result = time(NULL);
321 char tag[100] = { 0, };
323 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
325 if (noti_handle == NULL) {
326 testapp_print("notification_create failed");
330 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
331 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
333 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_HEADS_UP | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
335 snprintf(tag, 100, "%d", result);
337 noti_err = notification_set_tag(noti_handle, tag);
339 if (noti_err != NOTIFICATION_ERROR_NONE) {
340 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
344 app_control_err = app_control_create(&app_control);
345 if (app_control_err != APP_CONTROL_ERROR_NONE ) {
346 testapp_print("app_control_create failed[%d]\n", app_control_err);
350 app_control_err = app_control_set_app_id(app_control, "org.tizen.quickpanel");
351 if (app_control_err != APP_CONTROL_ERROR_NONE ) {
352 testapp_print("app_control_set_app_id failed[%d]\n", app_control_err);
356 noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
358 if (noti_err != NOTIFICATION_ERROR_NONE) {
359 testapp_print("notification_set_event_handler failed[%d]", noti_err);
363 app_control_destroy(app_control);
366 noti_err = notification_post(noti_handle);
368 if (noti_err != NOTIFICATION_ERROR_NONE) {
369 testapp_print("notification_post failed[%d]", noti_err);
373 noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
375 if (noti_err != NOTIFICATION_ERROR_NONE) {
376 testapp_print("notification_get_id failed[%d]", noti_err);
381 notification_free(noti_handle);
384 noti_handle = notification_load(NULL, priv_id);
386 if (noti_handle == NULL) {
387 testapp_print("notification_load failed");
391 noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
393 if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) {
394 testapp_print("notification_get_event_handler failed[%d]", noti_err);
398 app_control_get_app_id(app_control, &app_id);
401 testapp_print("result app_id [%s]\n", app_id);
408 app_control_destroy(app_control);
411 notification_free(noti_handle);
416 static int testapp_test_post_notification_with_domain_text()
418 notification_h noti_handle = NULL;
419 int noti_err = NOTIFICATION_ERROR_NONE;
420 int app_control_err = APP_CONTROL_ERROR_NONE;
424 time_t result = time(NULL);
425 char tag[100] = { 0, };
427 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
429 if (noti_handle == NULL) {
430 testapp_print("notification_create failed");
434 noti_err = notification_set_text_domain(noti_handle, "message", "/usr/apps/org.tizen.message/res/locale");
436 if (noti_err != NOTIFICATION_ERROR_NONE) {
437 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
441 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
442 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "[%s] *** [%s]",
443 NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_BODY_NO_SUBJECT",
444 NOTIFICATION_VARIABLE_TYPE_STRING, "IDS_MSGF_POP_NEW_MESSAGE",
445 NOTIFICATION_VARIABLE_TYPE_NONE);
447 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
449 if (noti_err != NOTIFICATION_ERROR_NONE) {
450 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
454 snprintf(tag, 100, "%d", result);
456 noti_err = notification_set_tag(noti_handle, tag);
458 if (noti_err != NOTIFICATION_ERROR_NONE) {
459 testapp_print("notification_set_tag failed[%d]\n", noti_err);
463 noti_err = notification_post(noti_handle);
465 if (noti_err != NOTIFICATION_ERROR_NONE) {
466 testapp_print("notification_post failed[%d]", noti_err);
474 notification_free(noti_handle);
479 static gboolean testapp_interpret_command_basic_test (int selected_number)
481 gboolean go_to_loop = TRUE;
483 switch (selected_number) {
485 testapp_test_post_notification();
489 testapp_test_post_notifications();
493 testapp_test_post_notification_on_indicator();
497 testapp_test_post_status_message();
501 testapp_test_delete_all_notifications();
505 testapp_test_post_heads_up_notification_with_button();
509 testapp_test_post_notification_with_domain_text();
524 void testapp_notification_main ()
526 gboolean go_to_loop = TRUE;
530 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
531 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
533 if (0 >= scanf("%d", &menu_number))
534 testapp_print("Invalid input");
536 go_to_loop = testapp_interpret_command_basic_test(menu_number);
539 /* Basic Test } ---------------------------------------------------------------*/
541 /* Setting Test } ---------------------------------------------------------------*/
543 static int testapp_test_get_setting_list()
545 int err = NOTIFICATION_ERROR_NONE;
548 char *package_name = NULL;
549 bool allow_to_notify = false;
550 bool do_not_disturb_except = false;
551 bool visibility_class = false;
552 notification_setting_h setting_array = NULL;
554 notification_setting_get_setting_array(&setting_array, &count);
556 testapp_print("count [%d]\n", count);
558 for (i = 0; i < count; i++) {
559 notification_setting_get_package_name(setting_array + i, &package_name);
560 notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify);
561 notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except);
562 notification_setting_get_visibility_class(setting_array + i, &visibility_class);
564 testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n"
565 ,i, package_name, allow_to_notify, do_not_disturb_except, visibility_class);
569 notification_setting_free_notification(setting_array);
574 static int testapp_test_update_setting()
576 int err = NOTIFICATION_ERROR_NONE;
577 notification_setting_h setting = NULL;
579 err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
581 if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
582 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
585 notification_setting_set_allow_to_notify(setting, 0);
586 notification_setting_update_setting(setting);
592 static int testapp_test_update_system_setting()
594 int err = NOTIFICATION_ERROR_NONE;
596 int visibility_class;
597 notification_system_setting_h system_setting = NULL;
599 err = notification_system_setting_load_system_setting(&system_setting);
601 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
602 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
606 notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
607 testapp_print("do_not_disturb [%d]\n", do_not_disturb);
608 do_not_disturb = !do_not_disturb;
609 notification_system_setting_set_do_not_disturb(system_setting, do_not_disturb);
611 notification_system_setting_get_visibility_class(system_setting, &visibility_class);
612 testapp_print("visibility_class [%d]\n", visibility_class);
613 visibility_class = !visibility_class;
614 notification_system_setting_set_visibility_class(system_setting, visibility_class);
616 err = notification_system_setting_update_system_setting(system_setting);
618 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
619 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
625 notification_system_setting_free_system_setting(system_setting);
630 static int testapp_test_refresh_setting_table()
632 int err = NOTIFICATION_ERROR_NONE;
633 err = notification_setting_refresh_setting_table();
635 if (err != NOTIFICATION_ERROR_NONE) {
636 testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
645 static gboolean testapp_interpret_command_setting_test (int selected_number)
647 gboolean go_to_loop = TRUE;
649 switch (selected_number) {
651 testapp_test_get_setting_list();
655 testapp_test_update_setting();
659 testapp_test_update_system_setting();
663 testapp_test_refresh_setting_table();
678 void testapp_setting_main()
680 gboolean go_to_loop = TRUE;
684 testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
685 testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
687 if (0 >= scanf("%d", &menu_number))
688 testapp_print("Invalid input");
690 go_to_loop = testapp_interpret_command_setting_test(menu_number);
693 /* Setting Test } ---------------------------------------------------------------*/
695 /* Main { ---------------------------------------------------------------------*/
696 static gboolean testapp_interpret_command (int menu_number)
698 gboolean go_to_loop = TRUE;
700 switch (menu_number) {
702 testapp_notification_main();
706 testapp_setting_main();
720 void testapp_show_prompt (testapp_menu_type_e menu)
723 case TESTAPP_MENU_TYPE_MAIN_MENU:
724 testapp_print ("[MAIN]# ");
727 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
728 testapp_print ("[BASIC_TEST]# ");
731 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
732 testapp_print ("[SETTING_TEST]# ");
737 int main (int argc, char *argv[])
739 gboolean go_to_loop = TRUE;
742 if ( testapp_initialize_testing() == FALSE ) {
743 testapp_print ("Initializing failed.\n");
748 testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
749 testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
750 if (0 >= scanf ("%d", &menu_number))
751 testapp_print("Invalid input");
752 go_to_loop = testapp_interpret_command (menu_number);
755 testapp_finalize_testing();
759 /* Main } ---------------------------------------------------------------------*/