4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7 * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
29 #include <sys/types.h>
32 #include <glib-object.h>
33 #include <dlog/dlog.h>
43 #define LOG_TAG "TEST_LOG"
45 #define TEST_APP_LOG_PRINT(FMT, ARG...) SLOGD(FMT, ##ARG);
47 #define AUTO_TEST 0 /*Flag to Enable or Disable auto testing */
51 #define ITER_COUNT 200 /*Stress testing iteration count */
58 } create_subtype; /*alarm type */
62 /*Used to hold multiple alarm id created */
63 alarm_id_t alarm_id_arr[ITER_COUNT] = { 0, };
67 #define USER_INPUT_YES 1
68 #define USER_INPUT_NO 2
70 #define USER_INPUT_DEFAULT 1
71 #define USER_INPUT_VOLATILE 2
73 GMainLoop *mainloop = NULL; /*gmain loop */
75 alarm_id_t alarm_id; /*Alarm identificaiton no */
77 guint pgm_exit_time = 2000000; /*gmainloop life in milli second for few scenarios */
79 bool cleanup_req = false; /*tells whether test program cleanup required
80 or not before program exit */
82 bool multiple_alarm = false;
85 static int __alarm_callback(alarm_id_t alarm_id, void *user_param);
87 static int __alarm_callback1(alarm_id_t alarm_id, void *user_param);
89 static void __create_interval_alarm(void);
91 static void __create_app_svc_interval_alarm(void);
93 static void __create_calendar_alarm(void);
95 static void __create_app_svc_calendar_alarm(void);
97 static gboolean __timout_handler(gpointer user_data);
99 static void __test_pgm_clean_up(void);
101 static int __get_integer_input_data(void);
103 static void __test_alarm_manager_delete_alarm(void);
105 static void __test_alarm_manager_create_alarm(void);
107 static void __test_alarm_manager_get_information(void);
109 static void __test_alarm_manager_get_appsvc_information(void);
111 static void __test_alarm_manager_get_alarm_ids(void);
113 static void __print_api_return_result(int err_no, const char *api_name);
115 static void __test_alarm_manager_callback(void);
117 static int __get_alarm_persistance_type(void);
119 static char *__get_alarm_destination(void);
121 static int __get_alarm_repeat_mode(void);
123 static void __print_appsvc_bundle_data(const char *key, const char *val, void *data);
126 /*This function will be executed upon alarm expiry*/
127 static int __alarm_callback(alarm_id_t alarm_id_rec, void *user_param)
129 time_t current_time = { 0, };
132 TEST_APP_LOG_PRINT("Alarm[%d] has expired at %s\n", alarm_id_rec,
133 ctime(¤t_time));
134 printf("Alarm[%d] has expired at %s\n", alarm_id_rec,
135 ctime(¤t_time));
141 /*This function will be executed upon alarm expiry*/
142 static int __alarm_callback1(alarm_id_t alarm_id_rec, void *user_param)
144 time_t current_time = { 0, };
146 printf("Callback function 2 executed\n");
148 TEST_APP_LOG_PRINT("Alarm[%d] has expired at %s\n", alarm_id_rec,
149 ctime(¤t_time));
150 printf("Alarm[%d] has expired at %s\n", alarm_id_rec,
151 ctime(¤t_time));
157 /*This function prints the result of Alarm manager API call*/
158 static void __print_api_return_result(int err_no, const char *api_name)
161 printf("Alarm Manager API \"%s\" retuned with result: ", api_name);
164 case ERR_ALARM_INVALID_PARAM:{
166 ("Alarm Manager error: \"ERR_ALARM_INVALID_PARAM\"\n");
169 case ERR_ALARM_INVALID_ID:{
171 ("Alarm Manager error: \"ERR_ALARM_INVALID_ID\"\n");
174 case ERR_ALARM_INVALID_REPEAT:{
176 ("Alarm Manager error: \"ERR_ALARM_INVALID_REPEAT\"\n");
179 case ERR_ALARM_INVALID_TIME:{
181 ("Alarm Manager error: \"ERR_ALARM_INVALID_TIME\"\n");
184 case ERR_ALARM_INVALID_DATE:{
186 ("Alarm Manager error: \"ERR_ALARM_INVALID_DATE\"\n");
189 case ERR_ALARM_NO_SERVICE_NAME:{
191 ("Alarm Manager error: \"ERR_ALARM_NO_SERVICE_NAME\"\n");
194 case ERR_ALARM_NO_PERMISSION:{
196 ("Alarm Manager error: \"ERR_ALARM_NO_PERMISSION\"\n");
199 case ERR_ALARM_INVALID_TYPE:{
201 ("Alarm Manager error: \"ERR_ALARM_INVALID_TYPE\"\n");
204 case ERR_ALARM_SYSTEM_FAIL:{
206 ("Alarm Manager error: \"ERR_ALARM_SYSTEM_FAIL\"\n");
209 case ALARMMGR_RESULT_SUCCESS:{
211 ("Alarm API Success: \"ALARMMGR_RESULT_SUCCESS\"\n");
215 printf("Alarm Manager error: Unknow Error \n");
219 /*Depending upon the test scenario,
220 these errno are added to assert()! */
221 assert(err_no == ALARMMGR_RESULT_SUCCESS
222 || err_no == ERR_ALARM_INVALID_ID
223 || err_no == ERR_ALARM_INVALID_PARAM);
225 assert(err_no == ALARMMGR_RESULT_SUCCESS);
232 static void __print_appsvc_bundle_data(const char *key, const char *val, void *data){
233 printf("Key-->[%s], Val-->[%s]\n",key,val);
237 /*This function is to take command line integer input from the user*/
238 static int __get_integer_input_data(void)
240 char input_str[32] = { 0, };
244 if (fgets(input_str, 1024, stdin) == NULL) {
245 printf("Input buffer overflow....\n");
249 if (sscanf(input_str, "%d", &data) != 1) {
250 printf("Input only integer option....\n");
257 /*Function to get alarm persistance type*/
258 static int __get_alarm_persistance_type(void)
260 int type = ALARM_TYPE_VOLATILE;
262 printf("Enter Type\n");
263 printf("1. ALARM_TYPE_DEFAULT \n");
264 printf("2. ALARM_TYPE_VOLATILE\n");
265 printf("Enter Choice between [1-2]....\n");
266 alarm_type = __get_integer_input_data();
268 switch (alarm_type) {
269 case USER_INPUT_DEFAULT:
271 type = ALARM_TYPE_DEFAULT;
274 case USER_INPUT_VOLATILE:
276 type = ALARM_TYPE_VOLATILE;
281 printf("Invalid option....Try Again\n");
289 static char *__get_alarm_destination(void)
292 char *destination = NULL;
293 printf("[Optional]: Do you want to provide Destination?\n");
296 printf("Enter Choice between [1-2]....\n");
297 alarm_type = __get_integer_input_data();
298 switch (alarm_type) {
303 destination = (char *)malloc(1024);
304 if (NULL == destination) {
308 ("Enter destination: [Ex:org.tizen.alarm-test "
309 "or org.tizen.gallery...]\n");
310 if (fgets(destination, 1024, stdin) == NULL) {
311 printf("Input buffer overflow....,try again\n");
315 destination[strlen(destination) - 1] = '\0';
325 printf("Invalid option....Try Again\n");
333 static int __get_alarm_repeat_mode(void)
336 printf("Enter Repeat Mode:\n");
337 printf("0. ALARM_REPEAT_MODE_ONCE\n");
338 printf("1. ALARM_REPEAT_MODE_REPEAT\n");
339 printf("2. ALARM_REPEAT_MODE_WEEKLY\n");
340 printf("3. ALARM_REPEAT_MODE_MONTHLY\n");
341 printf("4. ALARM_REPEAT_MODE_ANNUALLY\n");
342 printf("5. ALARM_REPEAT_MODE_MAX\n");
343 printf("Enter Choice between [0-5]....\n");
344 repeat_mode = __get_integer_input_data();
345 if (repeat_mode > 5 || repeat_mode < 0) {
346 printf("Invalid option....Try Again\n");
352 /*Function to create alarm in the calender input format*/
353 static void __create_calendar_alarm(void)
355 char *destination = NULL;
357 struct tm current_tm;
358 alarm_entry_t *alarm_info = NULL;
360 alarm_date_t test_time;
362 int year, month, day, hour, min, sec;
365 year = month = day = hour = min = sec = 0;
368 printf("current time: %s\n", ctime(¤t_time));
370 localtime_r(¤t_time, ¤t_tm);
371 alarm_info = alarmmgr_create_alarm();
372 assert(alarm_info != NULL);
375 test_time.year = current_tm.tm_year;
376 test_time.month = current_tm.tm_mon;
377 test_time.day = current_tm.tm_mday;
379 test_time.hour = current_tm.tm_hour;
380 test_time.min = current_tm.tm_min + 1;
384 printf("Enter Year of Alarm Expiry: ");
385 year = __get_integer_input_data();
387 printf("Enter month of Alarm Expiry: ");
388 month = __get_integer_input_data();
390 printf("Enter day of Alarm Expiry: ");
391 day = __get_integer_input_data();
393 printf("Enter hour of Alarm Expiry: ");
394 hour = __get_integer_input_data();
396 printf("Enter minute of Alarm Expiry: ");
397 min = __get_integer_input_data();
399 printf("Enter second Alarm Expiry: ");
400 sec = __get_integer_input_data();
402 test_time.year = year;
403 test_time.month = month;
405 test_time.hour = hour;
409 ("Note: Test Program will exit After [Year:%d Month:%d Day:%d "
410 "at Hour:%d Min:%d Sec:%d]. Please wait....\n\n",
411 year, month, day, hour, min, sec);
414 result = alarmmgr_set_time(alarm_info, test_time);
415 __print_api_return_result(result, "alarmmgr_set_time");
418 repeat_mode = ALARM_REPEAT_MODE_WEEKLY;
420 repeat_mode = __get_alarm_repeat_mode();
422 result = alarmmgr_set_repeat_mode(alarm_info, repeat_mode,
423 ALARM_WDAY_SUNDAY | ALARM_WDAY_MONDAY
424 | ALARM_WDAY_TUESDAY |
425 ALARM_WDAY_WEDNESDAY |
426 ALARM_WDAY_THURSDAY |
428 ALARM_WDAY_SATURDAY);
429 __print_api_return_result(result, "alarmmgr_set_repeat_mode");
432 type = (random() % 2) + 1;
434 type = __get_alarm_persistance_type();
436 result = alarmmgr_set_type(alarm_info, type);
437 __print_api_return_result(result, "alarmmgr_set_type");
441 alarmmgr_add_alarm_with_localtime(alarm_info, destination,
444 destination = __get_alarm_destination();
446 alarmmgr_add_alarm_with_localtime(alarm_info, destination,
448 __print_api_return_result(result, "alarmmgr_add_alarm_with_localtime");
449 printf("Created Alarm with Alarm ID %d\n", alarm_id);
454 pgm_exit_time = 70000;
456 ("Note: Test Program will exit After %f seconds..."
457 "Please wait....\n\n", (float)pgm_exit_time / 1000);
462 /*Function to create alarm with a delay for first expiry and
463 alarm expiry inteval for subsequent alarm*/
464 static void __create_interval_alarm(void)
466 time_t current_time = { 0, };
472 char *destination = NULL;
479 printf("current time: %s\n", ctime(¤t_time));
480 printf("Enter First Delay (in seconds) for alarm: \n");
481 delay = __get_integer_input_data();
487 printf("Enter Alarm repeat Interval in seconds (if 0, no repeat): \n");
488 interval = __get_integer_input_data();
492 type = (random() % 2) + 1;
494 type = __get_alarm_persistance_type();
498 multiple_alarm = true;
499 for (i = 0; i < ITER_COUNT; i++) {
503 alarmmgr_add_alarm(type, delay, interval,
504 destination, &alarm_id_arr[i]);
505 __print_api_return_result(result, "alarmmgr_add_alarm");
508 destination = __get_alarm_destination();
510 alarmmgr_add_alarm(type, delay, interval, destination, &alarm_id);
511 __print_api_return_result(result, "alarmmgr_add_alarm");
512 printf("Created Alarm with Alarm ID %d\n", alarm_id);
518 pgm_exit_time = ((delay + interval) * 1000) + 100;
520 ("Note: Test Program will exit After %f seconds..."
521 "Please wait....\n\n", (float)pgm_exit_time / 1000);
526 /*Function to create alarm (with app-svc information)
527 in the calender input format */
528 static void __create_app_svc_calendar_alarm(void)
531 struct tm current_tm;
532 alarm_entry_t *alarm_info = NULL;
534 alarm_date_t test_time;
540 char pkgname[1024] = { 0, };
542 memset(pkgname, '\0', 1024);
544 int year, month, day, hour, min, sec;
545 year = month = day = hour = min = sec = 0;
548 printf("current time: %s\n", ctime(¤t_time));
550 localtime_r(¤t_time, ¤t_tm);
551 alarm_info = alarmmgr_create_alarm();
552 assert(alarm_info != NULL);
555 test_time.year = current_tm.tm_year;
556 test_time.month = current_tm.tm_mon;
557 test_time.day = current_tm.tm_mday;
559 test_time.hour = current_tm.tm_hour;
560 test_time.min = current_tm.tm_min + 1;
563 printf("Enter Year of Alarm Expiry: ");
564 year = __get_integer_input_data();
566 printf("Enter month of Alarm Expiry: ");
567 month = __get_integer_input_data();
569 printf("Enter day of Alarm Expiry: ");
570 day = __get_integer_input_data();
572 printf("Enter hour of Alarm Expiry: ");
573 hour = __get_integer_input_data();
575 printf("Enter minute of Alarm Expiry: ");
576 min = __get_integer_input_data();
578 printf("Enter second Alarm Expiry: ");
579 sec = __get_integer_input_data();
581 test_time.year = year;
582 test_time.month = month;
584 test_time.hour = hour;
589 ("Note: Test Program will exit After "
590 "[Year:%d Month:%d Day:%d at Hour:%d Min:%d Sec:%d]."
591 " Please wait....\n\n", year, month, day, hour, min, sec);
593 result = alarmmgr_set_time(alarm_info, test_time);
594 __print_api_return_result(result, "alarmmgr_set_time");
597 repeat_mode = ALARM_REPEAT_MODE_WEEKLY;
599 repeat_mode = __get_alarm_repeat_mode();
601 result = alarmmgr_set_repeat_mode(alarm_info, repeat_mode,
602 ALARM_WDAY_SUNDAY | ALARM_WDAY_MONDAY
603 | ALARM_WDAY_TUESDAY |
604 ALARM_WDAY_WEDNESDAY |
605 ALARM_WDAY_THURSDAY |
607 ALARM_WDAY_SATURDAY);
608 __print_api_return_result(result, "alarmmgr_set_repeat_mode");
611 type = (random() % 2) + 1;
613 type = __get_alarm_persistance_type();
615 result = alarmmgr_set_type(alarm_info, type);
616 __print_api_return_result(result, "alarmmgr_set_type");
625 printf("Enter APPSVC Operation\n");
626 printf("1. APPSVC_OPERATION_DEFAULT \n");
627 printf("2. APPSVC_OPERATION_SEARCH\n");
628 printf("3. No operation\n");
629 op_type = __get_integer_input_data();
633 appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
637 appsvc_set_operation(b, APPSVC_OPERATION_SEARCH);
642 printf("NO APPSVC OPERATION!!!\n");
646 printf("Invalid option....Try Again\n");
653 sprintf(pkgname, "org.tizen.gallery");
658 ("Enter Pkgname: [Ex:org.tizen.alarm-test "
659 "or org.tizen.gallery...]\n");
660 if (fgets(pkgname, 1024, stdin) == NULL) {
661 printf("Input buffer overflow....,try again\n");
665 pkgname[strlen(pkgname) - 1] = '\0';
667 appsvc_set_pkgname(b, pkgname);
670 alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, (void *)b,
672 __print_api_return_result(result,
673 "alarmmgr_add_alarm_appsvc_with_localtime");
675 printf("Alarm created with alarm id %d\n", alarm_id);
679 pgm_exit_time = 70000;
682 ("Note: Test Program will exit After %f "
683 "seconds...Please wait....\n\n", (float)pgm_exit_time / 1000);
685 ("Upon Alarm Expiry, %s application will be "
686 "launched (purpose:testing)\n", pkgname);
690 /*Function to create alarm with a delay for first expiry and
691 alarm expiry inteval for subsequent alarm (with app-svc information)*/
692 static void __create_app_svc_interval_alarm(void)
694 time_t current_time = { 0, };
702 char pkgname[1024] = { 0, };
704 memset(pkgname, '\0', 1024);
709 delay = (random() % 9) + 1;
710 interval = (random() % 9);
712 printf("current time: %s\n", ctime(¤t_time));
713 printf("Enter First Delay (in seconds) for alarm: \n");
714 delay = __get_integer_input_data();
715 printf("Enter Alarm repeat Interval in seconds (if 0, no repeat): \n");
716 interval = __get_integer_input_data();
721 pgm_exit_time = ((delay + interval) * 1000) + 100;
723 ("Note: Test Program will exit After %f "
724 "seconds...Please wait....\n\n", (float)pgm_exit_time / 1000);
727 type = (random() % 2) + 1;
729 type = __get_alarm_persistance_type();
739 printf("Enter APPSVC Operation\n");
740 printf("1. APPSVC_OPERATION_DEFAULT \n");
741 printf("2. APPSVC_OPERATION_SEARCH\n");
742 printf("3. No operation\n");
743 op_type = __get_integer_input_data();
748 appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
752 appsvc_set_operation(b, APPSVC_OPERATION_SEARCH);
757 printf("NO APPSVC OPERATION!!!\n");
761 printf("Invalid option....Try Again\n");
770 sprintf(pkgname, "org.tizen.gallery");
773 ("Enter Pkgname: [Ex:org.tizen.alarm-test "
774 "or org.tizen.gallery...]\n");
775 if (fgets(pkgname, 1024, stdin) == NULL) {
776 printf("Input buffer overflow...Try Again.\n");
779 pkgname[strlen(pkgname) - 1] = '\0';
781 appsvc_set_pkgname(b, pkgname);
784 multiple_alarm = true;
785 for (i = 0; i < ITER_COUNT; i++) {
789 alarmmgr_add_alarm_appsvc(type, delay, interval, (void *)b,
791 __print_api_return_result(result, "alarmmgr_add_alarm");
795 alarmmgr_add_alarm_appsvc(type, delay, interval, (void *)b,
797 __print_api_return_result(result, "alarmmgr_add_alarm_appsvc");
798 printf("Created Alarm with Alarm ID %d\n", alarm_id);
804 pgm_exit_time = ((delay + interval) * 1000) + 100;
806 ("Note: Test Program will exit After %f seconds..."
807 "Please wait....\n\n", (float)pgm_exit_time / 1000);
812 /*This function will be executed before program exit (if required)*/
813 static void __test_pgm_clean_up(void)
816 printf("Cleaning up test program\n");
819 if (multiple_alarm == true) {
820 for (i = 0; i < ITER_COUNT; i++) {
821 result = alarmmgr_remove_alarm(alarm_id_arr[i]);
822 __print_api_return_result(result,
823 "alarmmgr_remove_alarm");
825 multiple_alarm = false;
827 result = alarmmgr_remove_alarm(alarm_id);
828 __print_api_return_result(result, "alarmmgr_remove_alarm");
831 result = alarmmgr_remove_alarm(alarm_id);
832 __print_api_return_result(result, "alarmmgr_remove_alarm");
837 /*Function to exit gmainloop*/
838 static gboolean __timout_handler(gpointer user_data)
841 g_main_loop_quit(mainloop);
846 /*Main alarm create function which provides options
847 for different types of alarm creation*/
848 static void __test_alarm_manager_callback(void)
850 printf("Inside Alarm Callback test\n");
853 mainloop = g_main_loop_new(NULL, FALSE);
854 assert(mainloop != NULL);
856 result = alarmmgr_init("org.tizen.alarm-test");
857 __print_api_return_result(result, "alarmmgr_init");
859 result = alarmmgr_set_cb(__alarm_callback, NULL);
860 __print_api_return_result(result, "alarmmgr_set_cb");
861 result = alarmmgr_set_cb(__alarm_callback1, NULL);
862 __print_api_return_result(result, "alarmmgr_set_cb");
864 __create_interval_alarm();
866 g_timeout_add(pgm_exit_time, __timout_handler, NULL);
868 g_main_loop_run(mainloop);
871 __test_pgm_clean_up();
877 /*Main alarm create function which provides options
878 for different types of alarm creation*/
879 static void __test_alarm_manager_create_alarm(void)
885 alarm_type = sub_type;
887 char destination[1024] = { 0, };
889 printf("Enter Alarm Type\n");
890 printf("1. Interval with initial delay\n");
891 printf("2. App-svc Interval alarm with initial delay\n");
892 printf("3. Calendar Alarm\n");
893 printf("4. App-svc Calendar Alarm\n");
894 printf("Enter Choice between [1-4]....\n");
895 alarm_type = __get_integer_input_data();
897 mainloop = g_main_loop_new(NULL, FALSE);
898 assert(mainloop != NULL);
900 switch (alarm_type) {
904 result = alarmmgr_init("org.tizen.1000");
908 ("Enter pkgname (used to generate service name)"
909 "[Ex:org.tizen.alarm-test or "
910 "org.tizen.1000 etc]\n");
911 if (fgets(destination, 1024, stdin) == NULL) {
912 printf("Input buffer overflow....,try again\n");
916 destination[strlen(destination) - 1] = '\0';
918 result = alarmmgr_init(destination);
920 __print_api_return_result(result, "alarmmgr_init");
922 result = alarmmgr_set_cb(__alarm_callback, NULL);
923 __print_api_return_result(result, "alarmmgr_set_cb");
925 __create_interval_alarm();
931 printf("Inside APPSVC Interval Alarm test\n");
932 __create_app_svc_interval_alarm();
937 printf("Inside Calendar Alarm test\n");
939 result = alarmmgr_init("org.tizen.1000");
943 ("Enter pkgname (used to generate service name)"
944 "[Ex:org.tizen.alarm-test or "
945 "org.tizen.1000 etc]\n");
946 if (fgets(destination, 1024, stdin) == NULL) {
947 printf("Input buffer overflow....,try again\n");
951 destination[strlen(destination) - 1] = '\0';
953 result = alarmmgr_init(destination);
955 __print_api_return_result(result, "alarmmgr_init");
957 result = alarmmgr_set_cb(__alarm_callback, NULL);
958 __print_api_return_result(result, "alarmmgr_set_cb");
960 __create_calendar_alarm();
965 printf("Inside APPSVC Calendar Alarm test\n");
966 __create_app_svc_calendar_alarm();
971 printf("Invalid option....Try Again\n");
976 g_timeout_add(pgm_exit_time, __timout_handler, NULL);
978 g_main_loop_run(mainloop);
981 __test_pgm_clean_up();
987 /*Main alarm get information function which provides
988 different options of getting alarm information*/
989 static void __test_alarm_manager_get_information(void)
992 printf("Inside Get Info Interval Alarm test\n");
995 alarm_entry_t *alarm_info;
998 alarm_date_t time = { 0, };
1003 printf("1. Get Existing Alarm's Information\n");
1004 printf("2. Create Alarm & Get Information\n");
1005 option = __get_integer_input_data();
1007 alarm_info = alarmmgr_create_alarm();
1008 assert(alarm_info != NULL);
1013 printf("Enter Alarm Id: \n");
1014 alarm_id = __get_integer_input_data();
1015 result = alarmmgr_get_info(alarm_id, alarm_info);
1016 __print_api_return_result(result, "alarmmgr_get_info");
1017 result = alarmmgr_get_time(alarm_info, &time);
1018 __print_api_return_result(result, "alarmmgr_get_time");
1019 printf("day is %d\n", time.day);
1020 printf("Alarm Get Info Success\n");
1025 result = alarmmgr_init("org.tizen.10000");
1026 __print_api_return_result(result, "alarmmgr_init");
1029 type = (random() % 2) + 1;
1031 type = __get_alarm_persistance_type();
1035 alarmmgr_add_alarm(type, 2, 0, NULL, &alarm_id);
1036 __print_api_return_result(result, "alarmmgr_add_alarm");
1037 printf("Created Alarm with Alarm ID %d\n", alarm_id);
1039 pgm_exit_time = 3000;
1040 g_timeout_add(pgm_exit_time, __timout_handler, NULL);
1042 result = alarmmgr_get_info(alarm_id, alarm_info);
1043 __print_api_return_result(result, "alarmmgr_get_info");
1045 alarm_date_t time = { 0, };
1046 result = alarmmgr_get_time(alarm_info, &time);
1047 __print_api_return_result(result, "alarmmgr_get_time");
1049 printf("day is %d\n", time.day);
1050 printf("Alarm Get Info Success\n");
1052 __test_pgm_clean_up();
1058 printf("Invalid option\n");
1065 static void __test_alarm_manager_get_appsvc_information(void)
1069 printf("Inside Get Info Interval Alarm test\n");
1072 alarm_entry_t *alarm_info;
1078 printf("1. Get Existing Alarm's Information\n");
1079 printf("2. Create Alarm & Get Information\n");
1080 option = __get_integer_input_data();
1082 alarm_info = alarmmgr_create_alarm();
1083 assert(alarm_info != NULL);
1088 printf("Enter Alarm ID:\n");
1089 alarm_id = __get_integer_input_data();
1091 b = alarmmgr_get_alarm_appsvc_info(alarm_id, &result);
1094 bundle_iterate(b, __print_appsvc_bundle_data, NULL);
1096 __print_api_return_result(result, "alarmmgr_get_alarm_appsvc_info");
1102 mainloop = g_main_loop_new(NULL, FALSE);
1103 assert(mainloop != NULL);
1105 __create_app_svc_interval_alarm();
1107 b = alarmmgr_get_alarm_appsvc_info(alarm_id, &result);
1108 __print_api_return_result(result, "alarmmgr_get_alarm_appsvc_info");
1110 bundle_iterate(b, __print_appsvc_bundle_data, NULL);
1112 g_timeout_add(2000, __timout_handler, NULL);
1114 g_main_loop_run(mainloop);
1117 __test_pgm_clean_up();
1123 printf("Invalid option\n");
1132 static int __alarm_id_retrive_callback(alarm_id_t id, void *user_param)
1135 n = (int *)user_param;
1137 printf("Invalid Parameter in test program");
1140 printf("[%d]Alarm ID is %d\n", *n, id);
1146 static void __test_alarm_manager_get_alarm_ids(void)
1148 printf("Inside Get Ids Alarm test\n");
1156 printf("1. Get Existing Alarm's ID\n");
1157 printf("2. Create Alarm & Get ID\n");
1159 option = __get_integer_input_data();
1164 result = alarmmgr_init("org.tizen.1000");
1165 __print_api_return_result(result, "alarmmgr_init");
1167 alarmmgr_enum_alarm_ids(__alarm_id_retrive_callback,
1169 __print_api_return_result(result,
1170 "alarmmgr_enum_alarm_ids");
1175 result = alarmmgr_init("org.tizen.test");
1176 __print_api_return_result(result, "alarmmgr_init");
1179 type = (random() % 2) + 1;
1181 type = __get_alarm_persistance_type();
1183 result = alarmmgr_add_alarm(type, 2, 0,
1185 printf("Created Alarm with Alarm ID %d\n", alarm_id);
1187 __print_api_return_result(result, "alarmmgr_add_alarm");
1189 result = alarmmgr_add_alarm(type, 3, 0,
1191 __print_api_return_result(result, "alarmmgr_add_alarm");
1192 printf("Created Alarm with Alarm ID %d\n", alarm_id);
1194 pgm_exit_time = 5100;
1195 g_timeout_add(pgm_exit_time, __timout_handler, NULL);
1198 alarmmgr_enum_alarm_ids(__alarm_id_retrive_callback,
1200 __print_api_return_result(result,
1201 "alarmmgr_enum_alarm_ids");
1207 printf("Invalid option\n");
1214 /*Main alarm delete test function which provides options
1215 for different types of alarm deletion*/
1216 static void __test_alarm_manager_delete_alarm(void)
1221 printf("Inside Delete Alarm test\n");
1226 printf("1. Delete Existing Alarm\n");
1227 printf("2. Create Alarm & Delete\n");
1229 option = __get_integer_input_data();
1234 printf("Enter Alarm Id: \n");
1235 option = __get_integer_input_data();
1237 result = alarmmgr_remove_alarm(option);
1238 __print_api_return_result(result,
1239 "alarmmgr_remove_alarm");
1244 result = alarmmgr_init("org.tizen.test");
1245 __print_api_return_result(result, "alarmmgr_init");
1248 type = (random() % 2) + 1;
1250 type = __get_alarm_persistance_type();
1252 result = alarmmgr_add_alarm(type, 2, 0,
1254 __print_api_return_result(result, "alarmmgr_add_alamr");
1255 printf("Created Alarm with Alarm ID %d\n", alarm_id);
1257 result = alarmmgr_remove_alarm(alarm_id);
1258 __print_api_return_result(result,
1259 "alarmmgr_remove_alarm");
1265 printf("Invalid Option\n");
1272 /*Entry point of the test program*/
1273 int main(int argc, char **argv)
1282 /*test result will be written into below file */
1283 fd = open("/var/alarm_test.log", O_CREAT | O_RDWR | O_APPEND, 0666);
1285 printf("Unable to create log file\n");
1289 printf("Insufficient arguments\n");
1291 ("Example: ./test_alarmmgr.exe {all|create_interval|"
1292 "create_svc_interval|create_calendar|create_svc_calendar|"
1293 "delete|get_id|callback} <iteration>");
1302 char *test_job = NULL;
1305 iteration = atoi(argv[2]);
1307 printf("##################Alarm Test for %s Starts##################\n",
1311 for (i = 0; i < iteration; i++) {
1312 printf("########ITERATION %d #############\n", i);
1313 if (strncmp(test_job, "create_interval", 15) == 0) {
1314 sub_type = INTERVAL;
1315 __test_alarm_manager_create_alarm();
1316 } else if (strncmp(test_job, "create_svc_interval", 19) == 0) {
1317 sub_type = INTERVAL_APPSVC;
1318 __test_alarm_manager_create_alarm();
1319 } else if (strncmp(test_job, "create_calendar", 15) == 0) {
1320 sub_type = CALENDAR;
1321 __test_alarm_manager_create_alarm();
1322 } else if (strncmp(test_job, "create_svc_calendar", 19) == 0) {
1323 sub_type = CALENDAR_APPSVC;
1324 __test_alarm_manager_create_alarm();
1325 } else if (strncmp(test_job, "delete", 6) == 0) {
1326 __test_alarm_manager_delete_alarm();
1327 } else if (strncmp(test_job, "get_info", 8) == 0) {
1328 __test_alarm_manager_get_information();
1329 } else if (strncmp(test_job, "get_id", 6) == 0) {
1330 __test_alarm_manager_get_alarm_ids();
1331 } else if (strncmp(test_job, "callback", 8) == 0) {
1332 __test_alarm_manager_callback();
1333 } else if (strncmp(test_job, "all", 3) == 0) {
1334 for (k = INTERVAL; k <= CALENDAR_APPSVC; k++) {
1336 __test_alarm_manager_create_alarm();
1338 __test_alarm_manager_delete_alarm();
1339 __test_alarm_manager_get_information();
1340 __test_alarm_manager_get_alarm_ids();
1341 __test_alarm_manager_get_alarm_ids();
1342 __test_alarm_manager_callback();
1345 printf("Invalid Option\n");
1349 printf("##################Alarm Test for %s Ends##################\n\n",
1354 /*Compile with disabling AUTO_TEST flag for individual testing */
1359 printf("*********ALARM MANAGER TESTING************\n");
1360 printf("1. Test Alarm-Manager: Create Alarm\n");
1361 printf("2. Test Alarm-Manager: Delete Alarm\n");
1362 printf("3. Test Alarm-Manager: Get Alarm Information\n");
1363 printf("4. Test Alarm-Manager: Get Alarm ID\n");
1364 printf("5. Test Alarm-Manager: Callback\n");
1365 printf("6. Test Alarm-Manager: Get Alarm app-svc(bundle) Information");
1366 printf("Enter Choice between [1-5]....\n");
1368 option = __get_integer_input_data();
1372 __test_alarm_manager_create_alarm();
1377 __test_alarm_manager_delete_alarm();
1382 __test_alarm_manager_get_information();
1387 __test_alarm_manager_get_alarm_ids();
1392 __test_alarm_manager_callback();
1397 __test_alarm_manager_get_appsvc_information();
1402 printf("Invalid Input!!! Retry again\n");
1406 printf("****************************************\n");