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 ("------------------------------------------\n");
155 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
156 testapp_print ("==========================================\n");
157 testapp_print (" Setting test menu \n");
158 testapp_print ("==========================================\n");
159 testapp_print (" 1. Get setting list\n");
160 testapp_print (" 2. Update setting\n");
161 testapp_print (" 3. Update system setting\n");
162 testapp_print ("------------------------------------------\n");
168 /* Common { ------------------------------------------------------------------*/
170 static int testapp_add_a_notification()
172 notification_h noti_handle = NULL;
173 int noti_err = NOTIFICATION_ERROR_NONE;
175 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
177 if (noti_handle == NULL) {
178 testapp_print("notification_create failed");
182 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
183 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
184 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
185 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
186 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);
187 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
188 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);
189 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
190 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);
192 noti_err = notification_post(noti_handle);
194 if (noti_err != NOTIFICATION_ERROR_NONE) {
195 testapp_print("notification_post failed[%d]", noti_err);
201 notification_free(noti_handle);
206 /* Common } ------------------------------------------------------------------*/
208 /* Basic Test { --------------------------------------------------------------*/
209 static int testapp_test_post_notification()
211 int err = NOTIFICATION_ERROR_NONE;
213 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
214 testapp_print("testapp_add_a_notification failed[%d]", err);
224 static int testapp_test_post_notifications()
226 int err = NOTIFICATION_ERROR_NONE;
227 int repeat_count = 0;
230 testapp_print("Input count : ");
232 if (0 >= scanf("%d", &repeat_count))
233 testapp_print("Invalid input");
235 for (i = 0; i < repeat_count; i++) {
236 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
237 testapp_print("testapp_add_a_notification failed[%d]", err);
246 static int testapp_test_post_notification_on_indicator()
248 notification_h noti_handle = NULL;
249 int noti_err = NOTIFICATION_ERROR_NONE;
251 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
253 if (noti_handle == NULL) {
254 testapp_print("notification_create failed");
258 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
259 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
261 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR);
263 if(noti_err != NOTIFICATION_ERROR_NONE) {
264 testapp_print("notification_set_display_applist failed[%d]", noti_err);
268 noti_err = notification_post(noti_handle);
270 if (noti_err != NOTIFICATION_ERROR_NONE) {
271 testapp_print("notification_post failed[%d]", noti_err);
277 notification_free(noti_handle);
282 static int testapp_test_post_status_message()
284 int noti_err = NOTIFICATION_ERROR_NONE;
287 noti_err = notification_status_message_post("This is only a test");
289 if(noti_err != NOTIFICATION_ERROR_NONE) {
290 testapp_print("notification_status_message_post failed[%d]", noti_err);
296 static int testapp_test_delete_all_notifications()
298 int noti_err = NOTIFICATION_ERROR_NONE;
300 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
302 testapp_print("notification_delete_all returns[%d]", noti_err);
307 static int testapp_test_post_heads_up_notification_with_button()
309 notification_h noti_handle = NULL;
310 int noti_err = NOTIFICATION_ERROR_NONE;
311 int app_control_err = APP_CONTROL_ERROR_NONE;
315 app_control_h app_control = NULL;
316 time_t result = time(NULL);
317 char tag[100] = { 0, };
319 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
321 if (noti_handle == NULL) {
322 testapp_print("notification_create failed");
326 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
327 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
329 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_HEADS_UP | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
331 snprintf(tag, 100, "%d", result);
333 noti_err = notification_set_tag(noti_handle, tag);
335 if (noti_err != NOTIFICATION_ERROR_NONE) {
336 testapp_print("notification_set_display_applist failed[%d]\n", noti_err);
340 app_control_err = app_control_create(&app_control);
341 if (app_control_err != APP_CONTROL_ERROR_NONE ) {
342 testapp_print("app_control_create failed[%d]\n", app_control_err);
346 app_control_err = app_control_set_app_id(app_control, "org.tizen.quickpanel");
347 if (app_control_err != APP_CONTROL_ERROR_NONE ) {
348 testapp_print("app_control_set_app_id failed[%d]\n", app_control_err);
352 noti_err = notification_set_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
354 if (noti_err != NOTIFICATION_ERROR_NONE) {
355 testapp_print("notification_set_event_handler failed[%d]", noti_err);
359 noti_err = notification_post(noti_handle);
361 app_control_destroy(app_control);
364 if (noti_err != NOTIFICATION_ERROR_NONE) {
365 testapp_print("notification_post failed[%d]", noti_err);
369 noti_err = notification_get_id(noti_handle, &group_id, &priv_id);
371 if (noti_err != NOTIFICATION_ERROR_NONE) {
372 testapp_print("notification_get_id failed[%d]", noti_err);
378 notification_free(noti_handle);
382 noti_handle = notification_load(NULL, priv_id);
384 if (noti_handle == NULL) {
385 testapp_print("notification_load failed");
389 noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
391 if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) {
392 testapp_print("notification_get_event_handler failed[%d]", noti_err);
396 app_control_get_app_id(app_control, &app_id);
399 testapp_print("result app_id [%s]", app_id);
406 app_control_destroy(app_control);
409 notification_free(noti_handle);
414 static gboolean testapp_interpret_command_basic_test (int selected_number)
416 gboolean go_to_loop = TRUE;
418 switch (selected_number) {
420 testapp_test_post_notification();
424 testapp_test_post_notifications();
428 testapp_test_post_notification_on_indicator();
432 testapp_test_post_status_message();
436 testapp_test_delete_all_notifications();
440 testapp_test_post_heads_up_notification_with_button();
455 void testapp_notification_main ()
457 gboolean go_to_loop = TRUE;
461 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
462 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
464 if (0 >= scanf("%d", &menu_number))
465 testapp_print("Invalid input");
467 go_to_loop = testapp_interpret_command_basic_test(menu_number);
470 /* Basic Test } ---------------------------------------------------------------*/
472 /* Setting Test } ---------------------------------------------------------------*/
474 static int testapp_test_get_setting_list()
476 int err = NOTIFICATION_ERROR_NONE;
479 char *package_name = NULL;
480 bool allow_to_notify = false;
481 bool do_not_disturb_except = false;
482 bool visibility_class = false;
483 notification_setting_h setting_array = NULL;
485 notification_setting_get_setting_array(&setting_array, &count);
487 testapp_print("count [%d]\n", count);
489 for (i = 0; i < count; i++) {
490 notification_setting_get_package_name(setting_array + i, &package_name);
491 notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify);
492 notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except);
493 notification_setting_get_visibility_class(setting_array + i, &visibility_class);
495 testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n"
496 ,i, package_name, allow_to_notify, do_not_disturb_except, visibility_class);
498 notification_setting_free_notification(setting_array );
507 static int testapp_test_update_setting()
509 int err = NOTIFICATION_ERROR_NONE;
510 notification_setting_h setting = NULL;
512 err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
514 if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
515 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
518 notification_setting_set_allow_to_notify(setting, 0);
519 notification_setting_update_setting(setting);
525 static int testapp_test_update_system_setting()
527 int err = NOTIFICATION_ERROR_NONE;
529 int visibility_class;
530 notification_system_setting_h system_setting = NULL;
533 err = notification_system_setting_load_system_setting(&system_setting);
535 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
536 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
540 notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
541 testapp_print("do_not_disturb [%d]\n", do_not_disturb);
542 do_not_disturb = !do_not_disturb;
543 notification_system_setting_set_do_not_disturb(system_setting, do_not_disturb);
545 notification_system_setting_get_visibility_class(system_setting, &visibility_class);
546 testapp_print("visibility_class [%d]\n", visibility_class);
547 visibility_class = !visibility_class;
548 notification_system_setting_set_visibility_class(system_setting, visibility_class);
550 err = notification_system_setting_update_system_setting(system_setting);
552 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
553 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
559 notification_system_setting_free_system_setting(system_setting);
564 static gboolean testapp_interpret_command_setting_test (int selected_number)
566 gboolean go_to_loop = TRUE;
568 switch (selected_number) {
570 testapp_test_get_setting_list();
574 testapp_test_update_setting();
578 testapp_test_update_system_setting();
593 void testapp_setting_main()
595 gboolean go_to_loop = TRUE;
599 testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
600 testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
602 if (0 >= scanf("%d", &menu_number))
603 testapp_print("Invalid input");
605 go_to_loop = testapp_interpret_command_setting_test(menu_number);
608 /* Setting Test } ---------------------------------------------------------------*/
610 /* Main { ---------------------------------------------------------------------*/
611 static gboolean testapp_interpret_command (int menu_number)
613 gboolean go_to_loop = TRUE;
615 switch (menu_number) {
617 testapp_notification_main();
621 testapp_setting_main();
635 void testapp_show_prompt (testapp_menu_type_e menu)
638 case TESTAPP_MENU_TYPE_MAIN_MENU:
639 testapp_print ("[MAIN]# ");
642 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
643 testapp_print ("[BASIC_TEST]# ");
646 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
647 testapp_print ("[SETTING_TEST]# ");
652 int main (int argc, char *argv[])
654 gboolean go_to_loop = TRUE;
657 if ( testapp_initialize_testing() == FALSE ) {
658 testapp_print ("Initializing failed.\n");
663 testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
664 testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
665 if (0 >= scanf ("%d", &menu_number))
666 testapp_print("Invalid input");
667 go_to_loop = testapp_interpret_command (menu_number);
670 testapp_finalize_testing();
674 /* Main } ---------------------------------------------------------------------*/