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 app_control_destroy(app_control);
362 noti_err = notification_post(noti_handle);
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);
377 notification_free(noti_handle);
380 noti_handle = notification_load(NULL, priv_id);
382 if (noti_handle == NULL) {
383 testapp_print("notification_load failed");
387 noti_err = notification_get_event_handler(noti_handle, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control);
389 if (noti_err != NOTIFICATION_ERROR_NONE ||app_control == NULL) {
390 testapp_print("notification_get_event_handler failed[%d]", noti_err);
394 app_control_get_app_id(app_control, &app_id);
397 testapp_print("result app_id [%s]\n", app_id);
404 app_control_destroy(app_control);
407 notification_free(noti_handle);
412 static gboolean testapp_interpret_command_basic_test (int selected_number)
414 gboolean go_to_loop = TRUE;
416 switch (selected_number) {
418 testapp_test_post_notification();
422 testapp_test_post_notifications();
426 testapp_test_post_notification_on_indicator();
430 testapp_test_post_status_message();
434 testapp_test_delete_all_notifications();
438 testapp_test_post_heads_up_notification_with_button();
453 void testapp_notification_main ()
455 gboolean go_to_loop = TRUE;
459 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
460 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
462 if (0 >= scanf("%d", &menu_number))
463 testapp_print("Invalid input");
465 go_to_loop = testapp_interpret_command_basic_test(menu_number);
468 /* Basic Test } ---------------------------------------------------------------*/
470 /* Setting Test } ---------------------------------------------------------------*/
472 static int testapp_test_get_setting_list()
474 int err = NOTIFICATION_ERROR_NONE;
477 char *package_name = NULL;
478 bool allow_to_notify = false;
479 bool do_not_disturb_except = false;
480 bool visibility_class = false;
481 notification_setting_h setting_array = NULL;
483 notification_setting_get_setting_array(&setting_array, &count);
485 testapp_print("count [%d]\n", count);
487 for (i = 0; i < count; i++) {
488 notification_setting_get_package_name(setting_array + i, &package_name);
489 notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify);
490 notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except);
491 notification_setting_get_visibility_class(setting_array + i, &visibility_class);
493 testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n"
494 ,i, package_name, allow_to_notify, do_not_disturb_except, visibility_class);
496 notification_setting_free_notification(setting_array );
505 static int testapp_test_update_setting()
507 int err = NOTIFICATION_ERROR_NONE;
508 notification_setting_h setting = NULL;
510 err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
512 if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
513 testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);
516 notification_setting_set_allow_to_notify(setting, 0);
517 notification_setting_update_setting(setting);
523 static int testapp_test_update_system_setting()
525 int err = NOTIFICATION_ERROR_NONE;
527 int visibility_class;
528 notification_system_setting_h system_setting = NULL;
531 err = notification_system_setting_load_system_setting(&system_setting);
533 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
534 testapp_print("notification_system_setting_load_system_setting failed [%d]\n", err);
538 notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
539 testapp_print("do_not_disturb [%d]\n", do_not_disturb);
540 do_not_disturb = !do_not_disturb;
541 notification_system_setting_set_do_not_disturb(system_setting, do_not_disturb);
543 notification_system_setting_get_visibility_class(system_setting, &visibility_class);
544 testapp_print("visibility_class [%d]\n", visibility_class);
545 visibility_class = !visibility_class;
546 notification_system_setting_set_visibility_class(system_setting, visibility_class);
548 err = notification_system_setting_update_system_setting(system_setting);
550 if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
551 testapp_print("notification_system_setting_update_system_setting failed [%d]\n", err);
557 notification_system_setting_free_system_setting(system_setting);
562 static gboolean testapp_interpret_command_setting_test (int selected_number)
564 gboolean go_to_loop = TRUE;
566 switch (selected_number) {
568 testapp_test_get_setting_list();
572 testapp_test_update_setting();
576 testapp_test_update_system_setting();
591 void testapp_setting_main()
593 gboolean go_to_loop = TRUE;
597 testapp_show_menu (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
598 testapp_show_prompt (TESTAPP_MENU_TYPE_SETTING_TEST_MENU);
600 if (0 >= scanf("%d", &menu_number))
601 testapp_print("Invalid input");
603 go_to_loop = testapp_interpret_command_setting_test(menu_number);
606 /* Setting Test } ---------------------------------------------------------------*/
608 /* Main { ---------------------------------------------------------------------*/
609 static gboolean testapp_interpret_command (int menu_number)
611 gboolean go_to_loop = TRUE;
613 switch (menu_number) {
615 testapp_notification_main();
619 testapp_setting_main();
633 void testapp_show_prompt (testapp_menu_type_e menu)
636 case TESTAPP_MENU_TYPE_MAIN_MENU:
637 testapp_print ("[MAIN]# ");
640 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
641 testapp_print ("[BASIC_TEST]# ");
644 case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
645 testapp_print ("[SETTING_TEST]# ");
650 int main (int argc, char *argv[])
652 gboolean go_to_loop = TRUE;
655 if ( testapp_initialize_testing() == FALSE ) {
656 testapp_print ("Initializing failed.\n");
661 testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
662 testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
663 if (0 >= scanf ("%d", &menu_number))
664 testapp_print("Invalid input");
665 go_to_loop = testapp_interpret_command (menu_number);
668 testapp_finalize_testing();
672 /* Main } ---------------------------------------------------------------------*/