Add HAL TC for modem, SIM and network
[platform/core/telephony/libtapi.git] / haltest / tapi_hal_tc.cpp
1 /*
2  * Copyright (c) 2014 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 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <unistd.h>
20 #include <iostream>
21 #include <stdio.h>
22 #include <glib.h>
23 #include <sys/time.h>
24 #include <system_info.h>
25
26 #include <tapi_common.h>
27 #include <TapiUtility.h>
28 #include <ITapiModem.h>
29 #include <ITapiNetwork.h>
30 #include <ITapiSim.h>
31
32
33 #include "tapi_hal_tc.h"
34
35 using ::testing::EmptyTestEventListener;
36 using ::testing::InitGoogleTest;
37 using ::testing::Test;
38 using ::testing::TestCase;
39 using ::testing::TestEventListeners;
40 using ::testing::TestInfo;
41 using ::testing::TestPartResult;
42 using ::testing::UnitTest;
43
44 #define FEATURE_TELEPHONY       "tizen.org/feature/network.telephony"
45 #define FEATRE_NOT_SUPPORT      "Telephony feature is not supported"
46
47 #define ASYNC_RESULT_SUCCESS 0x0
48 #define ASYNC_RESULT_UNKNOWN 0x0FFFFFFF
49
50 static TapiHandle *tapi_h = NULL;
51 static char **cp_list = NULL;
52 static int cp_count = 0;
53 static bool g_bFeatureTelephony = false;
54 static int async_result = ASYNC_RESULT_UNKNOWN;
55
56 static TelSimCardStatus_t sim_card_status = TAPI_SIM_STATUS_CARD_ERROR;
57
58 static bool __check_telephony_feature_supported()
59 {
60         bool value = false;
61         int ret = system_info_get_platform_bool(FEATURE_TELEPHONY, &value);
62         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed" << std::endl;
63         EXPECT_EQ(true, value) << FEATRE_NOT_SUPPORT << std::endl;
64         return value;
65 }
66
67 static gboolean __timeout_callback(gpointer data)
68 {
69         EXPECT_TRUE(0) << " - tapi callback timeout!";
70         QUIT_GMAIN_LOOP;
71
72         return false;
73 }
74
75 static void _get_flight_mode_callback(TapiHandle *handle, int result, void *data, void *user_data)
76 {
77         int *mode = (int *)data;
78
79         std::cout << "tel_get_flight_mode() response receive" << std::endl;
80         std::cout << " - result = " << result << " (0=Success)" << std::endl;
81         async_result = result;
82
83         if (mode)
84                 std::cout << " - mode = " << *mode << " (0=flight mode OFF, 1=flight mode ON)" <<std::endl;
85         else
86                 std::cout << " - mode is invalid" << std::endl;
87
88         QUIT_GMAIN_LOOP;
89
90 }
91
92 static void _get_sim_iccid_callback(TapiHandle *handle, int result, void *data, void *user_data)
93 {
94         TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
95         TelSimIccIdInfo_t *iccid = (TelSimIccIdInfo_t *)data;
96
97         std::cout << "tel_get_sim_iccid() response received" << std::endl;
98
99         if ( access_rt == TAPI_SIM_ACCESS_SUCCESS) {
100                 async_result = ASYNC_RESULT_SUCCESS;
101                 std::cout << " - iccid length = " << iccid->icc_length << std::endl;
102                 std::cout << " - iccid = " << iccid->icc_num << std::endl;
103         }
104
105         QUIT_GMAIN_LOOP;
106
107 }
108
109 static void _get_sim_msisdn_callback(TapiHandle *handle, int result, void *data, void *user_data)
110 {
111         TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
112         TelSimMsisdnList_t *list = (TelSimMsisdnList_t *)data;
113
114         std::cout << "tel_get_sim_msisdn() response received" << std::endl;
115
116         if ( access_rt == TAPI_SIM_ACCESS_SUCCESS) {
117                 async_result = ASYNC_RESULT_SUCCESS;
118                 std::cout << " - list->count = " << list->count << std::endl;
119                 if (list->count > 0)
120                         std::cout << " - msisdn[0] : name = " << list->list[0].name << ", num = " << list->list[0].num << std::endl;
121         }
122
123         QUIT_GMAIN_LOOP;
124 }
125
126 TEST(TAPI_INIT, tel_get_cp_name_list)
127 {
128         g_bFeatureTelephony = __check_telephony_feature_supported();
129         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
130
131         cp_list = tel_get_cp_name_list();
132         ASSERT_TRUE(cp_list != NULL) << "cp_list is null" << std::endl;
133
134         unsigned int i = 0;
135         while (cp_list[i]) {
136                 cp_count++;
137                 i++;
138         }
139         ASSERT_TRUE(cp_count > 0) << "cp_count is 0" << std::endl;
140         std::cout << " - cp_count:" << cp_count << std::endl;
141         std::cout << " - cp_list[0] = " << cp_list[0] << std::endl;
142 }
143
144 TEST(TAPI_INIT, tel_init_P)
145 {
146         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
147         ASSERT_TRUE(cp_list != NULL && cp_count > 0);
148
149         tapi_h = tel_init(cp_list[0]);
150         ASSERT_TRUE(tapi_h != NULL) << "tel_init() is failed" << std::endl;
151 }
152
153
154 TEST(TAPI_INIT, tel_get_ready_state_P)
155 {
156         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
157         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
158
159         int state = 0;
160         int ret = tel_get_ready_state(&state);
161         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_ready_state() is failed" << std::endl;
162         ASSERT_TRUE(state == 1) << "TELEPHONY_STATE_NOT_READY" << std::endl;
163
164         std::cout << " - telephony_state : TELEPHONY_STATE_READY" << std::endl;
165 }
166
167 TEST(TAPI_MODEM, telephony_modem_get_power_status_P)
168 {
169         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
170         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
171
172         int modem_status = -1;
173         int ret = tel_check_modem_power_status(tapi_h, &modem_status);
174         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_check_modem_power_status() is failed" << std::endl;
175
176         std::cout << " - modem_power_status = " << modem_status << " (0=on,1=off,2=rst,3=low)" << std::endl;
177 }
178
179 TEST(TAPI_MODEM, tel_get_misc_me_version_sync_P)
180 {
181         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
182         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
183
184         TelMiscVersionInformation *info = NULL;
185         info = tel_get_misc_me_version_sync(tapi_h);
186         EXPECT_TRUE(NULL != info) << "tel_get_misc_me_version_sync() is failed" << std::endl;
187
188         std::cout << " - sw version = " << info->szSwVersion << std::endl;
189         std::cout << " - hw version = " << info->szHwVersion << std::endl;
190         std::cout << " - RfCal Date = " << info->szRfCalDate << std::endl;
191         std::cout << " - Product Code = " << info->szProductCode << std::endl;
192         std::cout << " - Model ID = " << info->szModelId << std::endl;
193         std::cout << " - Prl Version = " << info->szPrlVersion << std::endl;
194         std::cout << " - ERI Version = " << info->szEriVersion << std::endl;
195
196         free(info);
197 }
198
199 TEST(TAPI_MODEM, tel_get_misc_me_sn_sync_P)
200 {
201         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
202         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
203
204         TelMiscSNInformation *sn;
205         sn = tel_get_misc_me_sn_sync(tapi_h);
206         EXPECT_TRUE(NULL != sn) << "tel_get_misc_me_sn_sync() is failed" << std::endl;
207
208
209         std::cout << " - esn number = " << sn->szEsn << std::endl;
210         std::cout << " - meid number = " << sn->szMeid << std::endl;
211         std::cout << " - imei number = " << sn->szImei << std::endl;
212         std::cout << " - imeisv number = " << sn->szImeiSv << std::endl;
213
214         free(sn);
215 }
216
217 TEST(TAPI_MODEM, tel_get_misc_me_imei_sync_P)
218 {
219         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
220         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
221
222         char *imei;
223         imei = tel_get_misc_me_imei_sync(tapi_h);
224         EXPECT_TRUE(NULL != imei) << "tel_get_misc_me_imei_sync() is failed" << std::endl;
225
226         std::cout << " - imei number = " << imei << std::endl;
227
228         free(imei);
229 }
230
231 TEST(TAPI_MODEM, tel_get_flight_mode_P)
232 {
233         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
234         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
235
236         int ret = tel_get_flight_mode(tapi_h, _get_flight_mode_callback, NULL);
237         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_flight_mode() is failed" << std::endl;
238
239         RUN_GMAIN_LOOP(__timeout_callback);
240
241         EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_flight_mode() is failed failed";
242         async_result = ASYNC_RESULT_UNKNOWN;
243 }
244
245 TEST(TAPI_SIM, tel_get_sim_init_info_P)
246 {
247         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
248         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
249
250         int ret = 0;
251         int sim_card_changed = 0;
252
253         ret = tel_get_sim_init_info(tapi_h, &sim_card_status, &sim_card_changed);
254         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_init_info() is failed" << std::endl;
255
256         if (sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
257                 std::cout << " - SIM status = SIM_INIT_COMPLETED" << std::endl;
258                 std::cout << " - SIM changed = " << sim_card_changed<< std::endl;
259         } else if (sim_card_status == TAPI_SIM_STATUS_CARD_NOT_PRESENT) {
260                 std::cout << "- SIM status = No SIM" << std::endl;
261         } else {
262                 std::cout << "- SIM status = SIM card Error" << std::endl;
263         }
264
265 }
266
267 TEST(TAPI_SIM, tel_get_sim_imsi_P)
268 {
269         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
270         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
271         ASSERT_TRUE(sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) << "SIM status is invalid" << std::endl;
272
273         int ret = 0;
274         TelSimImsiInfo_t imsi;
275         memset(&imsi, 0, sizeof(TelSimImsiInfo_t));
276
277         ret = tel_get_sim_imsi(tapi_h, &imsi);
278         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_imsi() is failed" << std::endl;
279
280         std::cout << " - mcc = "<< imsi.szMcc << std::endl;
281         std::cout << " - mnc = " << imsi.szMnc << std::endl;
282         std::cout << " - msin = " << imsi.szMsin << std::endl;
283 }
284
285 TEST(TAPI_SIM, tel_get_sim_iccid_P)
286 {
287         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
288         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
289         ASSERT_TRUE(sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) << "SIM status is invalid" << std::endl;
290
291         int ret = tel_get_sim_iccid(tapi_h, _get_sim_iccid_callback, NULL);
292         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_iccid() is failed" << std::endl;
293
294         RUN_GMAIN_LOOP(__timeout_callback);
295
296         EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_sim_iccid() is failed failed";
297         async_result = ASYNC_RESULT_UNKNOWN;
298 }
299
300 TEST(TAPI_SIM, tel_get_sim_msisdn_P)
301 {
302         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
303         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
304         ASSERT_TRUE(sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) << "SIM status is invalid" << std::endl;
305
306         int ret = tel_get_sim_msisdn(tapi_h, _get_sim_msisdn_callback, NULL);
307         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_msisdn() is failed" << std::endl;
308
309         RUN_GMAIN_LOOP(__timeout_callback);
310
311         EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_sim_msisdn() is failed failed";
312         async_result = ASYNC_RESULT_UNKNOWN;
313 }
314
315 TEST(TAPI_NETWORK, tel_get_network_properties_P)
316 {
317         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
318         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
319
320         int svc_type = -1, act = -1, ps_type = -1, cs = -1, ps = -1;
321         int roam = -1, sig_level = -1;
322         char *plmn = NULL, *n_name = NULL, *s_name = NULL;
323
324         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
325         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_ACT, &act);
326         tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_PLMN, &plmn);
327         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_PS_TYPE, &ps_type);
328         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_CIRCUIT_STATUS, &cs);
329         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_PACKET_STATUS, &ps);
330         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &sig_level);
331         tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_ROAMING_STATUS, &roam);
332         tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_NETWORK_NAME, &n_name);
333         tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_SPN_NAME, &s_name);
334
335         std::cout << "<network properties>" << std::endl;
336         std::cout <<"  [service_type]: " << svc_type << std::endl;
337         std::cout <<"  [act]: " << act << std::endl;
338         std::cout <<"  [plmn]: " << plmn << std::endl;
339         std::cout <<"  [ps_type]: " <<ps_type << std::endl;
340         std::cout <<"  [cs_status]: " << cs << std::endl;
341         std::cout <<"  [ps_status]: " << ps << std::endl;
342         std::cout <<"  [sig_level]: " << sig_level << std::endl;
343         std::cout <<"  [roaming_status]: " << roam << std::endl;
344         std::cout <<"  [network_name]: " << n_name << std::endl;
345         std::cout <<"  [spn_name]: " << s_name << std::endl;
346
347         g_free(plmn);
348         g_free(n_name);
349         g_free(s_name);
350
351 }
352
353
354 TEST(TAPI_DEINIT, tel_deinit_P)
355 {
356         ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
357         ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
358
359         int ret = tel_deinit(tapi_h);
360         EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_deinit() is failed" << std::endl;
361         tapi_h = NULL;
362 }
363
364 int main(int argc, char **argv) {
365   InitGoogleTest(&argc, argv);
366
367   return RUN_ALL_TESTS();
368 }