Initialize Tizen 2.3
[framework/appfw/alarm-manager.git] / TC / unit / utc_ApplicationFW_alarmmgr_get_info_func.c
1 /*
2  *  alarm-manager
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include <tet_api.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28
29 #include "alarm.h"
30
31 static void startup(void);
32 static void cleanup(void);
33
34 void (*tet_startup)(void) = startup;
35 void (*tet_cleanup)(void) = cleanup;
36
37 static void utc_ApplicationFW_alarmmgr_get_info_func_01(void);
38 static void utc_ApplicationFW_alarmmgr_get_info_func_02(void);
39
40 enum {
41         POSITIVE_TC_IDX = 0x01,
42         NEGATIVE_TC_IDX,
43 };
44
45 struct tet_testlist tet_testlist[] = {
46         { utc_ApplicationFW_alarmmgr_get_info_func_01, POSITIVE_TC_IDX },
47         { utc_ApplicationFW_alarmmgr_get_info_func_02, NEGATIVE_TC_IDX },
48         { NULL , 0 }
49 };
50
51 static int pid;
52
53 static void startup(void)
54 {
55 }
56
57 static void cleanup(void)
58 {
59 }
60
61 /**
62  * @brief Positive test case of alarmmgr_get_info()
63  */
64 static void utc_ApplicationFW_alarmmgr_get_info_func_01(void)
65 {
66         int ret_val = ALARMMGR_RESULT_SUCCESS;
67         int alarm_type = ALARM_TYPE_VOLATILE;
68         time_t trigger_at_time = 10; 
69         time_t interval = 10; 
70         const char* destination = NULL;
71         alarm_id_t alarm_id;
72
73         alarm_entry_t *alarm;
74
75         const char* pkg_name = "com.samsung.test_get_info1";
76
77         
78         g_type_init();
79
80         ret_val =alarmmgr_init(pkg_name) ;
81         if(ret_val != ALARMMGR_RESULT_SUCCESS)
82         {
83                  tet_infoline("\nAlarm Manager : call to alarmmgr_init () failed \n");
84                  tet_result(TET_FAIL);
85                  return;
86         }
87         
88         ret_val = alarmmgr_add_alarm( alarm_type,  trigger_at_time, interval  , destination, &alarm_id);
89
90         if(ret_val != ALARMMGR_RESULT_SUCCESS)
91         {
92                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_info () failed \n");
93                  tet_result(TET_FAIL);
94                  return;
95         }
96
97         alarm = alarmmgr_create_alarm();
98         
99         ret_val = alarmmgr_get_info(alarm_id, alarm);
100         if(ret_val == ALARMMGR_RESULT_SUCCESS)
101         {
102                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_info() is successful \n");
103                  tet_result(TET_PASS);
104         }
105         else
106         {
107                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_info() failed \n");
108                  tet_result(TET_FAIL);
109         }
110         alarmmgr_remove_alarm( alarm_id) ;
111 }
112
113 /**
114  * @brief Negative test case of ug_init alarmmgr_get_info()
115  */
116 static void utc_ApplicationFW_alarmmgr_get_info_func_02(void)
117 {
118         int ret_val = ALARMMGR_RESULT_SUCCESS;
119         alarm_id_t alarm_id = -1;
120         alarm_entry_t* alarm = NULL;
121
122         const char* pkg_name = "com.samsung.test_get_info2";
123
124         g_type_init();
125
126         ret_val =alarmmgr_init(pkg_name) ;
127         if(ret_val != ALARMMGR_RESULT_SUCCESS)
128         {
129                  tet_infoline("\nAlarm Manager : call to alarmmgr_init () failed \n");
130                  tet_result(TET_FAIL);
131                  return;
132         }
133
134         ret_val =alarmmgr_get_info( alarm_id, alarm) ;
135         if(ret_val == ERR_ALARM_INVALID_PARAM)
136         {
137                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_info() with invalid parameter  is successful \n");
138                  tet_result(TET_PASS);
139         }
140         else
141         {
142                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_info() failed \n");
143                  tet_result(TET_FAIL);
144         }
145 }