release tizen_2.0
[framework/api/sim.git] / TC / testcase / utc_telephony_sim.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <tet_api.h>
19 #include <sim.h>
20 #include <stdlib.h>
21
22 enum {
23         POSITIVE_TC_IDX = 0x01,
24         NEGATIVE_TC_IDX,
25 };
26
27 static void startup(void);
28 static void cleanup(void);
29
30 void (*tet_startup)(void) = startup;
31 void (*tet_cleanup)(void) = cleanup;
32
33 static void utc_telephony_sim_get_icc_id_n(void);
34 static void utc_telephony_sim_get_icc_id_p(void);
35 static void utc_telephony_sim_get_mcc_n(void);
36 static void utc_telephony_sim_get_mcc_p(void);
37 static void utc_telephony_sim_get_mnc_n(void);
38 static void utc_telephony_sim_get_mnc_p(void);
39 static void utc_telephony_sim_get_msin_n(void);
40 static void utc_telephony_sim_get_msin_p(void);
41 static void utc_telephony_sim_get_spn_n(void);
42 static void utc_telephony_sim_get_spn_p(void);
43 static void utc_telephony_sim_get_cphs_operator_name_n(void);
44 static void utc_telephony_sim_get_cphs_operator_name_p(void);
45 static void utc_telephony_sim_get_state_n(void);
46 static void utc_telephony_sim_get_state_p(void);
47 static void utc_telephony_sim_get_subscriber_number_n(void);
48 static void utc_telephony_sim_get_subscriber_number_p(void);
49 static void utc_telephony_sim_set_state_changed_cb_p(void);
50 static void utc_telephony_sim_set_state_changed_cb_n(void);
51 static void utc_telephony_sim_unset_state_changed_cb_p(void);
52
53
54
55 struct tet_testlist tet_testlist[] = {
56         { utc_telephony_sim_get_icc_id_n, NEGATIVE_TC_IDX },                        
57         { utc_telephony_sim_get_icc_id_p, POSITIVE_TC_IDX },
58         { utc_telephony_sim_get_mcc_n, NEGATIVE_TC_IDX },
59         { utc_telephony_sim_get_mcc_p, POSITIVE_TC_IDX },       
60         { utc_telephony_sim_get_mnc_n, NEGATIVE_TC_IDX },       
61         { utc_telephony_sim_get_mnc_p, POSITIVE_TC_IDX },
62         { utc_telephony_sim_get_msin_n, NEGATIVE_TC_IDX },
63         { utc_telephony_sim_get_msin_p, POSITIVE_TC_IDX },
64         { utc_telephony_sim_get_spn_n, NEGATIVE_TC_IDX },       
65         { utc_telephony_sim_get_spn_p, POSITIVE_TC_IDX },
66         { utc_telephony_sim_get_cphs_operator_name_n, NEGATIVE_TC_IDX },
67         { utc_telephony_sim_get_cphs_operator_name_p, POSITIVE_TC_IDX },
68         { utc_telephony_sim_get_state_n, NEGATIVE_TC_IDX },
69         { utc_telephony_sim_get_state_p, POSITIVE_TC_IDX },
70         { utc_telephony_sim_get_subscriber_number_n, NEGATIVE_TC_IDX }, 
71         { utc_telephony_sim_get_subscriber_number_p, POSITIVE_TC_IDX },
72         { utc_telephony_sim_set_state_changed_cb_p, POSITIVE_TC_IDX },
73         { utc_telephony_sim_set_state_changed_cb_n, NEGATIVE_TC_IDX },
74         { utc_telephony_sim_unset_state_changed_cb_p, POSITIVE_TC_IDX },
75         { NULL, 0 },
76 };
77
78
79 static void startup(void)
80 {
81         /* start of TC */
82         tet_printf("\n TC start");
83 }
84
85
86 static void cleanup(void)
87 {
88         /* end of TC */
89         tet_printf("\n TC end");
90 }
91
92 /**
93  * @brief Callback function
94  */
95 void sim_state_changed(sim_state_e state, void* user_data)
96 {
97
98 }
99
100 /**
101  * @brief Negative test case of sim_get_icc_id()
102  */
103 static void utc_telephony_sim_get_icc_id_n(void)
104 {
105         int ret = SIM_ERROR_NONE;
106
107         //  Invalid parameter test
108         ret = sim_get_icc_id(NULL);
109         dts_check_eq("sim_get_icc_id", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); 
110 }
111
112
113 /**
114  * @brief Positive test case of sim_get_icc_id()
115  */
116 static void utc_telephony_sim_get_icc_id_p(void)
117 {
118         char* icc_id = NULL;
119         int ret = SIM_ERROR_NONE;
120
121         //  Normal operation test
122         ret = sim_get_icc_id(&icc_id);
123         if( icc_id != NULL )
124                 free(icc_id);
125         dts_check_eq("sim_get_icc_id", ret, SIM_ERROR_NONE, "Failed to get ICC ID");
126 }
127
128
129 /**
130  * @brief Negative test case of sim_get_mcc()
131  */
132 static void utc_telephony_sim_get_mcc_n(void)
133 {
134         int ret = SIM_ERROR_NONE;
135
136         //  Invalid parameter test
137         ret = sim_get_mcc(NULL);
138         dts_check_eq("sim_get_mcc", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); 
139 }
140
141
142 /**
143  * @brief Positive test case of sim_get_mcc()
144  */
145 static void utc_telephony_sim_get_mcc_p(void)
146 {
147         char* mcc = NULL; 
148         int ret = SIM_ERROR_NONE;
149
150         //  Normal operation test
151         ret = sim_get_mcc(&mcc);
152         if( ret == SIM_ERROR_NONE )
153                 free(mcc);
154         dts_check_eq("sim_get_mcc", ret, SIM_ERROR_NONE, "Failed to get MCC"); 
155 }
156
157
158 /**
159  * @brief Negative test case of sim_get_mnc()
160  */
161 static void utc_telephony_sim_get_mnc_n(void)
162 {
163         int ret = SIM_ERROR_NONE;
164
165         //  Invalid parameter test 
166         ret = sim_get_mnc(NULL);
167         dts_check_eq("sim_get_mnc", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); 
168 }
169
170
171 /**
172  * @brief Positive test case of sim_get_mnc()
173  */
174 static void utc_telephony_sim_get_mnc_p(void)
175 {
176         char* mnc = NULL; 
177         int ret = SIM_ERROR_NONE;
178
179         //  Normal operation test
180         ret = sim_get_mnc(&mnc);
181         if( ret == SIM_ERROR_NONE )
182                 free(mnc);
183         dts_check_eq("sim_get_mnc", ret, SIM_ERROR_NONE, "Failed to get MNC"); 
184 }
185
186
187 /**
188  * @brief Negative test case of sim_get_msin()
189  */
190 static void utc_telephony_sim_get_msin_n(void)
191 {
192         int ret = SIM_ERROR_NONE;
193
194         //  Invalid parameter test
195         ret = sim_get_msin(NULL);
196         dts_check_eq("sim_get_msin", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter");
197 }
198
199
200 /**
201  * @brief Positive test case of sim_get_msin()
202  */
203 static void utc_telephony_sim_get_msin_p(void)
204 {
205         char* msin = NULL;
206         int ret = SIM_ERROR_NONE;
207
208         //  Normal operation test
209         ret = sim_get_msin(&msin);
210         if( ret == SIM_ERROR_NONE )
211                 free(msin);
212         dts_check_eq("sim_get_msin", ret, SIM_ERROR_NONE, "Failed to get MSIN");
213 }
214
215
216 /**
217  * @brief Negative test case of sim_get_spn()
218  */
219 static void utc_telephony_sim_get_spn_n(void)
220 {
221         int ret = SIM_ERROR_NONE;
222
223         //  Invalid parameter test    
224         ret = sim_get_spn(NULL);
225         dts_check_eq("sim_get_spn", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); 
226 }
227
228
229 /**
230  * @brief Positive test case of sim_get_spn()
231  */
232 static void utc_telephony_sim_get_spn_p(void)
233 {
234         char* spn = NULL; 
235         int ret = SIM_ERROR_NONE;
236
237         //  Normal operation test
238         ret = sim_get_spn(&spn);
239         if( ret == SIM_ERROR_NONE )
240                 free(spn);
241         dts_check_eq("sim_get_spn", ret, SIM_ERROR_NONE, "Failed to get SPN");
242 }
243
244
245 /**
246  * @brief Negative test case of sim_get_cphs_operator_name()
247  */
248 static void utc_telephony_sim_get_cphs_operator_name_n(void)
249 {
250         int ret = SIM_ERROR_NONE;
251
252         //  Invalid parameter test
253         ret = sim_get_cphs_operator_name(NULL, NULL);
254         dts_check_eq("sim_get_cphs_operator_name", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter");
255 }
256
257
258 /**
259  * @brief Positive test case of sim_get_cphs_operator_name()
260  */
261 static void utc_telephony_sim_get_cphs_operator_name_p(void)
262 {
263         char* full_name = NULL;
264         char* short_name = NULL;
265         int ret = SIM_ERROR_NONE;
266
267         //  Normal operation test
268         ret = sim_get_cphs_operator_name(&full_name, &short_name);
269         if( ret == SIM_ERROR_NONE ) {
270                 free(full_name);
271                 free(short_name);
272         }
273         dts_check_eq("sim_get_cphs_operator_name", ret, SIM_ERROR_NONE, "Failed to get CPHS full/short operator name");
274 }
275
276
277 /**
278  * @brief Negative test case of sim_get_state()
279  */
280 static void utc_telephony_sim_get_state_n(void)
281 {
282         int ret = SIM_ERROR_NONE;
283
284         //  Invalid parameter test    
285         ret = sim_get_state(NULL);
286         dts_check_eq("sim_get_state", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); 
287 }
288
289
290 /**
291  * @brief Positive test case of sim_get_state()
292  */
293 static void utc_telephony_sim_get_state_p(void)
294 {
295         sim_state_e sim_status; 
296         int ret = SIM_ERROR_NONE;
297
298         //  Normal operation test
299         ret = sim_get_state(&sim_status);
300         dts_check_eq("sim_get_state", ret, SIM_ERROR_NONE, "Failed to get the current status of SIM");
301 }
302
303
304 /**
305  * @brief Negative test case of sim_get_subscriber_number()
306  */
307 static void utc_telephony_sim_get_subscriber_number_n(void)
308 {
309         int ret = SIM_ERROR_NONE;
310
311         // Invalid parameter test
312         ret = sim_get_subscriber_number(NULL);
313         dts_check_eq("sim_get_subscriber_number", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); 
314 }
315
316
317 /**
318  * @brief Positive test case of sim_get_subscriber_number()
319  */
320 static void utc_telephony_sim_get_subscriber_number_p(void)
321 {
322         char* subscriber_number = NULL;
323         int ret = SIM_ERROR_NONE;
324
325         //  Normal operation test
326         ret = sim_get_subscriber_number(&subscriber_number);
327         if( ret == SIM_ERROR_NONE )
328         {
329                         free(subscriber_number);
330                         dts_pass("sim_get_subscriber_number", "Succeeded to get subscriber number.");
331         }
332                 else
333                 {
334                         dts_fail("sim_get_subscriber_number", "Failed to get subscriber number.");
335                 }
336 }
337
338
339 static void utc_telephony_sim_set_state_changed_cb_p(void)
340 {
341     sim_error_e ret = sim_set_state_changed_cb(sim_state_changed, NULL);
342     dts_check_eq("sim_set_state_changed_cb", ret, SIM_ERROR_NONE, 
343                 "sim_set_state_changed_cb failed.");
344 }
345
346 static void utc_telephony_sim_set_state_changed_cb_n(void)
347 {
348     sim_error_e ret = sim_set_state_changed_cb(NULL, NULL);
349     dts_check_eq("sim_set_state_changed_cb", ret, SIM_ERROR_INVALID_PARAMETER,  
350                 "SIM_ERROR_INVALID_PARAMETER must be returned when parameter is NULL.");
351 }
352
353 static void utc_telephony_sim_unset_state_changed_cb_p(void)
354 {
355     sim_error_e ret = sim_unset_state_changed_cb();
356     dts_check_eq("sim_unset_state_changed_cb", ret, SIM_ERROR_NONE, 
357                 "sim_unset_state_changed_cb failed.");
358 }
359
360