Git init
[framework/appfw/alarm-manager.git] / TC / unit / utc_ApplicationFW_alarmmgr_get_time_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_time_func_01(void);
38 static void utc_ApplicationFW_alarmmgr_get_time_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_time_func_01, POSITIVE_TC_IDX },
47         { utc_ApplicationFW_alarmmgr_get_time_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_time()
63  */
64 static void utc_ApplicationFW_alarmmgr_get_time_func_01(void)
65 {
66         int ret_val = ALARMMGR_RESULT_SUCCESS;
67         alarm_entry_t* alarm;
68
69         time_t current_time;
70        struct tm current_tm;
71         alarm_date_t test_time;
72         alarm_date_t new_time;
73
74
75        time(&current_time);
76        localtime_r(&current_time, &current_tm);
77        
78        alarm = alarmmgr_create_alarm();
79         if(alarm == NULL)
80         {
81                  tet_infoline("\nAlarm Manager : call to alarmmgr_create_alarm() is failed \n");
82                  tet_result(TET_FAIL);
83         }
84         else
85                 {
86        
87                     test_time.year = current_tm.tm_year+1900;                 
88                         test_time.month = current_tm.tm_mon+1;                
89                         test_time.day = current_tm.tm_mday;                  
90                                                     
91                         test_time.hour = current_tm.tm_hour;
92                         test_time.min = current_tm.tm_min+1;
93                         test_time.sec = 0;
94                         
95                        ret_val = alarmmgr_set_time(alarm,test_time);
96                         if(ret_val == ALARMMGR_RESULT_SUCCESS)
97                         {
98                                  tet_infoline("\nAlarm Manager : call to alarmmgr_set_time() is successful \n");
99                                  tet_result(TET_PASS);
100                         }
101                         else
102                         {
103                                  tet_infoline("\nAlarm Manager : call to alarmmgr_set_time() failed \n");
104                                  tet_result(TET_FAIL);
105                         }
106
107                         
108         
109                         ret_val = alarmmgr_get_time(alarm, &new_time);
110                         if(ret_val == ALARMMGR_RESULT_SUCCESS)
111                         {
112                                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_time() is successful \n");
113                                  tet_result(TET_PASS);
114                         }
115                         else
116                         {
117                                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_time() failed \n");
118                                  tet_result(TET_FAIL);
119                         }
120                         alarmmgr_free_alarm( alarm) ;
121                 }
122 }
123
124 /**
125  * @brief Negative test case of ug_init alarmmgr_get_time()
126  */
127 static void utc_ApplicationFW_alarmmgr_get_time_func_02(void)
128 {
129         int ret_val = ALARMMGR_RESULT_SUCCESS;
130         const alarm_entry_t* alarm = NULL;
131         alarm_date_t* time = NULL;
132
133         ret_val =alarmmgr_get_time( alarm,  time) ;
134         if(ret_val == ERR_ALARM_INVALID_PARAM)
135         {
136                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_time()  with invalid parameter is successful \n");
137                  tet_result(TET_PASS);
138         }
139         else
140         {
141                  tet_infoline("\nAlarm Manager : call to alarmmgr_get_time() failed \n");
142                  tet_result(TET_FAIL);
143         }
144 }