Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / wearable / TC / testcase / utc_common.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include <tet_api.h>
22 #include <stdlib.h>
23
24 #include <tapi_common.h>
25 #include <TapiUtility.h>
26
27 #include "util_common.h"
28
29 TapiHandle *handle;
30 enum async_state async_flag;
31
32
33 /**
34  * tel_get_cp_name_list
35  *
36  */
37 static void utc_tel_get_cp_name_list (void)
38 {
39         char **result;
40
41         result = tel_get_cp_name_list ();
42         if (result == NULL) {
43                 dts_fail("tel_get_cp_name_list");
44                 return;
45         }
46
47         dts_pass("tel_get_cp_name_list");
48 }
49
50 /**
51  * tel_init / tel_deinit
52  *
53  */
54 static void utc_tel_init_deinit (void)
55 {
56         TapiHandle *h;
57         int ret;
58
59         h = tel_init (NULL);
60         if (h == NULL) {
61                 dts_fail("tel_init", "Fail to initialization");
62                 return;
63         }
64
65         ret = tel_deinit (h);
66         if (ret != TAPI_API_SUCCESS) {
67                 dts_fail("tel_deinit", "Fail to deinitialization");
68                 return;
69         }
70
71         h = tel_init ("invalid_name");
72         if (h == NULL) {
73                 dts_fail("tel_init", "Fail to initialization (invalid name should success)");
74                 return;
75         }
76
77         ret = tel_deinit (h);
78         if (ret != TAPI_API_SUCCESS) {
79                 dts_fail("tel_deinit", "Fail to deinitialization");
80                 return;
81         }
82
83         dts_pass("tel_init");
84 }
85
86
87 static void utc_fail_tel_init_deinit (void)
88 {
89         int ret;
90
91         ret = tel_deinit (NULL);
92         if (ret == TAPI_API_SUCCESS) {
93                 dts_fail("tel_deinit", "Fail to parameter check");
94                 return;
95         }
96
97         dts_pass("tel_deinit");
98 }
99
100 /**
101  * tel_register_noti_event / tel_deregister_noti_event
102  *
103  */
104 static void on_noti (TapiHandle *h, const char *noti_id, void *data, void *user_data)
105 {
106 }
107
108 static void utc_tel_register_noti_event (void)
109 {
110         int ret;
111
112         ret = tel_register_noti_event (handle, TAPI_NOTI_NETWORK_REGISTRATION_STATUS, on_noti, NULL);
113         if (ret != TAPI_API_SUCCESS) {
114                 dts_fail("tel_register_noti_event");
115                 return;
116         }
117
118         ret = tel_deregister_noti_event (handle, TAPI_NOTI_NETWORK_REGISTRATION_STATUS);
119         if (ret != TAPI_API_SUCCESS) {
120                 dts_fail("tel_deregister_noti_event");
121                 return;
122         }
123
124         dts_pass("tel_register_noti_event");
125 }
126
127 static void utc_fail_tel_register_noti_event (void)
128 {
129         int ret;
130
131         ret = tel_register_noti_event (handle, TAPI_NOTI_NETWORK_REGISTRATION_STATUS, NULL, NULL);
132         if (ret == TAPI_API_SUCCESS) {
133                 dts_fail("tel_register_noti_event");
134                 return;
135         }
136
137         ret = tel_register_noti_event (handle, NULL, NULL, NULL);
138         if (ret == TAPI_API_SUCCESS) {
139                 dts_fail("tel_register_noti_event");
140                 return;
141         }
142
143         ret = tel_register_noti_event (NULL, TAPI_NOTI_NETWORK_REGISTRATION_STATUS, on_noti, NULL);
144         if (ret == TAPI_API_SUCCESS) {
145                 dts_fail("tel_register_noti_event");
146                 return;
147         }
148
149         /* deregister the unregistered event */
150         ret = tel_deregister_noti_event (handle, TAPI_NOTI_NETWORK_CHANGE);
151         if (ret == TAPI_API_SUCCESS) {
152                 dts_fail("tel_deregister_noti_event");
153                 return;
154         }
155
156         dts_pass("tel_register_noti_event");
157 }
158
159
160 /**
161  * tel_get_property_int
162  *
163  */
164 static void utc_tel_get_property_int (void)
165 {
166         int ret;
167         int act = 0;
168
169         ret = tel_get_property_int (handle, TAPI_PROP_NETWORK_ACT, &act);
170         if (ret != TAPI_API_SUCCESS) {
171                 dts_fail("tel_get_property_int");
172                 return;
173         }
174
175         dts_pass("tel_get_property_int");
176 }
177
178 static void utc_fail_tel_get_property_int (void)
179 {
180         int ret;
181         int act = 0;
182
183         ret = tel_get_property_int (handle, TAPI_PROP_NETWORK_ACT, NULL);
184         if (ret == TAPI_API_SUCCESS) {
185                 dts_fail("tel_get_property_int");
186                 return;
187         }
188
189         ret = tel_get_property_int (handle, NULL, &act);
190         if (ret == TAPI_API_SUCCESS) {
191                 dts_fail("tel_get_property_int");
192                 return;
193         }
194
195
196         ret = tel_get_property_int (NULL, TAPI_PROP_NETWORK_ACT, &act);
197         if (ret == TAPI_API_SUCCESS) {
198                 dts_fail("tel_get_property_int");
199                 return;
200         }
201
202         dts_pass("tel_get_property_int");
203 }
204
205
206 /**
207  * tel_get_property_string
208  *
209  */
210 static void utc_tel_get_property_string (void)
211 {
212         int ret;
213         char *plmn = NULL;
214
215         ret = tel_get_property_string (handle, TAPI_PROP_NETWORK_PLMN, &plmn);
216         if (ret != TAPI_API_SUCCESS) {
217                 dts_fail("tel_get_property_string");
218                 return;
219         }
220
221         if (plmn)
222                 free (plmn);
223
224         dts_pass("tel_get_property_string");
225 }
226
227 static void utc_fail_tel_get_property_string (void)
228 {
229         int ret;
230         char *plmn = NULL;
231
232         ret = tel_get_property_string (handle, TAPI_PROP_NETWORK_PLMN, NULL);
233         if (ret == TAPI_API_SUCCESS) {
234                 dts_fail("tel_get_property_string");
235                 return;
236         }
237
238         ret = tel_get_property_string (handle, NULL, &plmn);
239         if (ret == TAPI_API_SUCCESS) {
240                 dts_fail("tel_get_property_string");
241                 return;
242         }
243
244         ret = tel_get_property_string (NULL, TAPI_PROP_NETWORK_PLMN, &plmn);
245         if (ret == TAPI_API_SUCCESS) {
246                 dts_fail("tel_get_property_string");
247                 return;
248         }
249
250         dts_pass("tel_get_property_string");
251 }
252
253
254 struct tet_testlist tet_testlist[] = {
255         { utc_tel_get_cp_name_list, 1 },
256         { utc_tel_init_deinit, 1 },
257         { utc_fail_tel_init_deinit, 2 },
258         { utc_tel_register_noti_event, 1 },
259         { utc_fail_tel_register_noti_event, 2 },
260         { utc_tel_get_property_int, 1 },
261         { utc_fail_tel_get_property_int, 2 },
262         { utc_tel_get_property_string, 1 },
263         { utc_fail_tel_get_property_string, 2 },
264         { NULL, 0 },
265 };
266
267 static void startup (void)
268 {
269         /* start of TC */
270         tet_printf ("\n TC start");
271
272         handle = tel_init (NULL);
273 }
274
275 static void cleanup (void)
276 {
277         tel_deinit (handle);
278
279         /* end of TC */
280         tet_printf ("\n TC end");
281 }
282
283 void (*tet_startup) (void) = startup;
284 void (*tet_cleanup) (void) = cleanup;