2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
24 #include <system_info.h>
26 #include <tapi_common.h>
27 #include <TapiUtility.h>
28 #include <ITapiModem.h>
29 #include <ITapiNetwork.h>
33 #include "tapi_hal_tc.h"
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;
44 #define FEATURE_TELEPHONY "tizen.org/feature/network.telephony"
45 #define FEATRE_NOT_SUPPORT "Telephony feature is not supported"
47 #define ASYNC_RESULT_SUCCESS 0x0
48 #define ASYNC_RESULT_UNKNOWN 0x0FFFFFFF
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;
56 static TelSimCardStatus_t sim_card_status = TAPI_SIM_STATUS_CARD_ERROR;
58 static bool __check_telephony_feature_supported()
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;
67 static gboolean __timeout_callback(gpointer data)
69 EXPECT_TRUE(0) << " - tapi callback timeout!";
75 static void _get_flight_mode_callback(TapiHandle *handle, int result, void *data, void *user_data)
77 int *mode = (int *)data;
79 std::cout << "tel_get_flight_mode() response receive" << std::endl;
80 std::cout << " - result = " << result << " (0=Success)" << std::endl;
81 async_result = result;
84 std::cout << " - mode = " << *mode << " (0=flight mode OFF, 1=flight mode ON)" <<std::endl;
86 std::cout << " - mode is invalid" << std::endl;
92 static void _get_sim_iccid_callback(TapiHandle *handle, int result, void *data, void *user_data)
94 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
95 TelSimIccIdInfo_t *iccid = (TelSimIccIdInfo_t *)data;
97 std::cout << "tel_get_sim_iccid() response received" << std::endl;
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;
109 static void _get_sim_msisdn_callback(TapiHandle *handle, int result, void *data, void *user_data)
111 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
112 TelSimMsisdnList_t *list = (TelSimMsisdnList_t *)data;
114 std::cout << "tel_get_sim_msisdn() response received" << std::endl;
116 if ( access_rt == TAPI_SIM_ACCESS_SUCCESS) {
117 async_result = ASYNC_RESULT_SUCCESS;
118 std::cout << " - list->count = " << list->count << std::endl;
120 std::cout << " - msisdn[0] : name = " << list->list[0].name << ", num = " << list->list[0].num << std::endl;
126 TEST(TAPI_INIT, tel_get_cp_name_list)
128 g_bFeatureTelephony = __check_telephony_feature_supported();
129 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
131 cp_list = tel_get_cp_name_list();
132 ASSERT_TRUE(cp_list != NULL) << "cp_list is null" << std::endl;
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;
144 TEST(TAPI_INIT, tel_init_P)
146 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
147 ASSERT_TRUE(cp_list != NULL && cp_count > 0);
149 tapi_h = tel_init(cp_list[0]);
150 ASSERT_TRUE(tapi_h != NULL) << "tel_init() is failed" << std::endl;
154 TEST(TAPI_INIT, tel_get_ready_state_P)
156 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
157 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
164 std::cout << " - telephony_state : TELEPHONY_STATE_READY" << std::endl;
167 TEST(TAPI_MODEM, telephony_modem_get_power_status_P)
169 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
170 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
176 std::cout << " - modem_power_status = " << modem_status << " (0=on,1=off,2=rst,3=low)" << std::endl;
179 TEST(TAPI_MODEM, tel_get_misc_me_version_sync_P)
181 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
182 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
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;
199 TEST(TAPI_MODEM, tel_get_misc_me_sn_sync_P)
201 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
202 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
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;
217 TEST(TAPI_MODEM, tel_get_misc_me_imei_sync_P)
219 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
220 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
226 std::cout << " - imei number = " << imei << std::endl;
231 TEST(TAPI_MODEM, tel_get_flight_mode_P)
233 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
234 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
239 RUN_GMAIN_LOOP(__timeout_callback);
241 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_flight_mode() is failed failed";
242 async_result = ASYNC_RESULT_UNKNOWN;
245 TEST(TAPI_SIM, tel_get_sim_init_info_P)
247 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
248 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
251 int sim_card_changed = 0;
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;
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;
262 std::cout << "- SIM status = SIM card Error" << std::endl;
267 TEST(TAPI_SIM, tel_get_sim_imsi_P)
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;
274 TelSimImsiInfo_t imsi;
275 memset(&imsi, 0, sizeof(TelSimImsiInfo_t));
277 ret = tel_get_sim_imsi(tapi_h, &imsi);
278 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_imsi() is failed" << std::endl;
280 std::cout << " - mcc = "<< imsi.szMcc << std::endl;
281 std::cout << " - mnc = " << imsi.szMnc << std::endl;
282 std::cout << " - msin = " << imsi.szMsin << std::endl;
285 TEST(TAPI_SIM, tel_get_sim_iccid_P)
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;
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;
294 RUN_GMAIN_LOOP(__timeout_callback);
296 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_sim_iccid() is failed failed";
297 async_result = ASYNC_RESULT_UNKNOWN;
300 TEST(TAPI_SIM, tel_get_sim_msisdn_P)
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;
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;
309 RUN_GMAIN_LOOP(__timeout_callback);
311 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_sim_msisdn() is failed failed";
312 async_result = ASYNC_RESULT_UNKNOWN;
315 TEST(TAPI_NETWORK, tel_get_network_properties_P)
317 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
318 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
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;
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);
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;
354 TEST(TAPI_DEINIT, tel_deinit_P)
356 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
357 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
359 int ret = tel_deinit(tapi_h);
360 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_deinit() is failed" << std::endl;
364 int main(int argc, char **argv) {
365 InitGoogleTest(&argc, argv);
367 return RUN_ALL_TESTS();