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>
38 /*-----------------------------------------------------------------------------------------*/
40 typedef enum testapp_menu_type {
41 TESTAPP_MENU_TYPE_MAIN_MENU = 1,
42 TESTAPP_MENU_TYPE_BASIC_TEST_MENU = 2,
43 } testapp_menu_type_e;
45 /*-----------------------------------------------------------------------------------------*/
46 /* function prototypes */
47 static void testapp_system_signal_handler (int signal_number);
48 void testapp_show_prompt (testapp_menu_type_e menu);
50 /*-----------------------------------------------------------------------------------------*/
52 void testapp_print (char *fmt, ...)
56 vfprintf (stdout, fmt, args);
61 static gboolean testapp_initialize_testing ()
63 struct timeval tv_1, tv_2;
66 /* register signal handler */
67 if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
68 testapp_print ("register signal handler fail\n");
72 if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
73 testapp_print ("register signal handler fail\n");
77 if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
78 testapp_print ("register signal handler fail\n");
82 if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
83 testapp_print ("register signal handler fail\n");
88 gettimeofday(&tv_1, NULL);
90 /* TODO : initializing notification */
92 gettimeofday(&tv_2, NULL);
93 interval = tv_2.tv_usec - tv_1.tv_usec;
94 testapp_print("\t Initializing Proceed time %d us\n",interval);
100 static gboolean testapp_finalize_testing ()
102 /* TODO : finalizing notification */
107 static void testapp_system_signal_handler (int signal_number)
109 testapp_print ("signal:%d\n", signal_number);
110 switch (signal_number) {
115 testapp_finalize_testing();
119 testapp_print ("unhandled signal:%d\n", signal_number);
128 void testapp_show_menu (testapp_menu_type_e menu)
131 case TESTAPP_MENU_TYPE_MAIN_MENU:
132 testapp_print ("==========================================\n");
133 testapp_print (" Notification test application \n");
134 testapp_print ("==========================================\n");
135 testapp_print ("1. Basic Test\n");
136 testapp_print ("0. Exit \n");
137 testapp_print ("------------------------------------------\n");
139 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
140 testapp_print ("==========================================\n");
141 testapp_print (" Basic test menu \n");
142 testapp_print ("==========================================\n");
143 testapp_print (" 1. Post a simple notification\n");
144 testapp_print (" 2. Post simple notifications repeatedly\n");
145 testapp_print (" 3. Post a notification on indicator\n");
146 testapp_print (" 4. Post status status message\n");
147 testapp_print (" 5. Delete all notification\n");
148 testapp_print ("------------------------------------------\n");
154 /* Common { ------------------------------------------------------------------*/
156 static int testapp_add_a_notification()
158 notification_h noti_handle = NULL;
159 int noti_err = NOTIFICATION_ERROR_NONE;
161 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
163 if (noti_handle == NULL) {
164 testapp_print("notification_create failed");
168 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
169 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
170 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
171 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
172 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);
173 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
174 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);
175 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
176 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);
178 noti_err = notification_post(noti_handle);
180 if (noti_err != NOTIFICATION_ERROR_NONE) {
181 testapp_print("notification_post failed[%d]", noti_err);
187 notification_free(noti_handle);
192 /* Common } ------------------------------------------------------------------*/
194 /* Basic Test { --------------------------------------------------------------*/
195 static int testapp_test_post_notification()
197 int err = NOTIFICATION_ERROR_NONE;
199 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
200 testapp_print("testapp_add_a_notification failed[%d]", err);
210 static int testapp_test_post_notifications()
212 int err = NOTIFICATION_ERROR_NONE;
213 int repeat_count = 0;
216 testapp_print("Input count : ");
218 if (0 >= scanf("%d", &repeat_count))
219 testapp_print("Invalid input");
221 for (i = 0; i < repeat_count; i++) {
222 if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
223 testapp_print("testapp_add_a_notification failed[%d]", err);
233 static int testapp_test_post_notification_on_indicator()
235 notification_h noti_handle = NULL;
236 int noti_err = NOTIFICATION_ERROR_NONE;
238 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
240 if (noti_handle == NULL) {
241 testapp_print("notification_create failed");
245 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
246 noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
248 noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR);
250 if(noti_err != NOTIFICATION_ERROR_NONE) {
251 testapp_print("notification_set_display_applist failed[%d]", noti_err);
255 noti_err = notification_post(noti_handle);
257 if (noti_err != NOTIFICATION_ERROR_NONE) {
258 testapp_print("notification_post failed[%d]", noti_err);
264 notification_free(noti_handle);
269 static int testapp_test_post_status_message()
271 int noti_err = NOTIFICATION_ERROR_NONE;
274 noti_err = notification_status_message_post("This is only a test");
276 if(noti_err != NOTIFICATION_ERROR_NONE) {
277 testapp_print("notification_status_message_post failed[%d]", noti_err);
283 static int testapp_test_delete_all_notifications()
285 int noti_err = NOTIFICATION_ERROR_NONE;
287 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
289 testapp_print("notification_delete_all returns[%d]", noti_err);
294 static gboolean testapp_interpret_command_basic_test (int selected_number)
296 gboolean go_to_loop = TRUE;
298 switch (selected_number) {
300 testapp_test_post_notification();
304 testapp_test_post_notifications();
308 testapp_test_post_notification_on_indicator();
312 testapp_test_post_status_message();
316 testapp_test_delete_all_notifications();
331 void testapp_notification_main ()
333 gboolean go_to_loop = TRUE;
337 testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
338 testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
340 if (0 >= scanf("%d", &menu_number))
341 testapp_print("Invalid input");
343 go_to_loop = testapp_interpret_command_basic_test(menu_number);
346 /* Basic Test } ---------------------------------------------------------------*/
349 /* Main { ---------------------------------------------------------------------*/
350 static gboolean testapp_interpret_command (int menu_number)
352 gboolean go_to_loop = TRUE;
354 switch (menu_number) {
356 testapp_notification_main();
370 void testapp_show_prompt (testapp_menu_type_e menu)
373 case TESTAPP_MENU_TYPE_MAIN_MENU:
374 testapp_print ("[MAIN]# ");
377 case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
378 testapp_print ("[BASIC_TEST]# ");
383 int main (int argc, char *argv[])
385 gboolean go_to_loop = TRUE;
388 if ( testapp_initialize_testing() == FALSE ) {
389 testapp_print ("Initializing failed.\n");
394 testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
395 testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
396 if (0 >= scanf ("%d", &menu_number))
397 testapp_print("Invalid input");
398 go_to_loop = testapp_interpret_command (menu_number);
401 testapp_finalize_testing();
405 /* Main } ---------------------------------------------------------------------*/