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 _noti_modem_power(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
77 int *status = (int *)data;
79 std::cout << std::endl;
80 std::cout << "<<notification received - Modem:Power>>" << std::endl;
83 std::cout << " [status]: " << *status << "(0:ON,1:OFF,2:RST,3:LOW)" << std::endl << std::endl;
86 static void _noti_registration_status(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
88 TelNetworkRegistrationStatus_t *noti = (TelNetworkRegistrationStatus_t *)data;
91 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
93 std::cout << std::endl;
94 std::cout << "<<notification received - Network:RegistrationStatus>>" << std::endl;
96 std::cout << " [service_type]: " << svc_type << "(1=No Service, 2=Emergency, 4=2G, 7=3G, 9=LTE)" << std::endl;
97 std::cout << " [cs status]: " << noti->cs << "(0=No Service, 1=Emergency, 2=Avaliable, 3=Searching)" << std::endl;
98 std::cout << " [ps status]: " << noti->ps << "(0=No Service, 1=Emergency, 2=Avaliable, 3=Searching)" << std::endl;
99 std::cout << " [is roaming]: " << noti->is_roaming << std::endl << std::endl;
102 static void _get_flight_mode_callback(TapiHandle *handle, int result, void *data, void *user_data)
104 int *mode = (int *)data;
106 std::cout << "tel_get_flight_mode() response receive" << std::endl;
107 std::cout << " [result]: " << result << " (0=Success)" << std::endl;
108 async_result = result;
111 std::cout << " [mode]: " << *mode << " (0=flight mode OFF, 1=flight mode ON)" <<std::endl;
113 std::cout << " [mode is invalid]" << std::endl;
119 static void _set_flight_mode_callback(TapiHandle *handle, int result, void *data, void *user_data)
121 std::cout << "tel_set_flight_mode() response receive" << std::endl;
122 std::cout << " [result]: " << result << " (1=FLIGHT_MODE_ON, 2=FLIGHT_MODE_OFF)" << std::endl;
123 async_result = ASYNC_RESULT_SUCCESS;
129 static void _get_sim_iccid_callback(TapiHandle *handle, int result, void *data, void *user_data)
131 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
132 TelSimIccIdInfo_t *iccid = (TelSimIccIdInfo_t *)data;
134 std::cout << "tel_get_sim_iccid() response received" << std::endl;
136 if (sim_card_status == TAPI_SIM_STATUS_CARD_ERROR
137 || sim_card_status == TAPI_SIM_STATUS_CARD_BLOCKED
138 || sim_card_status == TAPI_SIM_STATUS_CARD_NOT_PRESENT
139 || sim_card_status == TAPI_SIM_STATUS_CARD_REMOVED
140 || sim_card_status == TAPI_SIM_STATUS_UNKNOWN) {
141 std::cout << " [MSISDN is unavaliable due to abnormal SIM card status" << std::endl;
142 async_result = ASYNC_RESULT_SUCCESS;
148 if ( access_rt == TAPI_SIM_ACCESS_SUCCESS) {
149 async_result = ASYNC_RESULT_SUCCESS;
150 std::cout << " [iccid length]: " << iccid->icc_length << std::endl;
151 std::cout << " [iccid]: " << iccid->icc_num << std::endl;
158 static void _get_sim_msisdn_callback(TapiHandle *handle, int result, void *data, void *user_data)
160 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
161 TelSimMsisdnList_t *list = (TelSimMsisdnList_t *)data;
163 std::cout << "tel_get_sim_msisdn() response received" << std::endl;
165 if (sim_card_status == TAPI_SIM_STATUS_CARD_ERROR
166 || sim_card_status == TAPI_SIM_STATUS_CARD_BLOCKED
167 || sim_card_status == TAPI_SIM_STATUS_CARD_NOT_PRESENT
168 || sim_card_status == TAPI_SIM_STATUS_CARD_REMOVED
169 || sim_card_status == TAPI_SIM_STATUS_UNKNOWN) {
170 std::cout << " [MSISDN is unavaliable due to abnormal SIM card status" << std::endl;
171 async_result = ASYNC_RESULT_SUCCESS;
177 if ( access_rt == TAPI_SIM_ACCESS_SUCCESS && list) {
178 async_result = ASYNC_RESULT_SUCCESS;
179 std::cout << " [list->count]: " << list->count << std::endl;
181 std::cout << " [msisdn[0]]: name = " << list->list[0].name << ", num = " << list->list[0].num << std::endl;
187 TEST(TAPI_INIT, tel_get_cp_name_list)
189 g_bFeatureTelephony = __check_telephony_feature_supported();
190 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
192 cp_list = tel_get_cp_name_list();
193 ASSERT_TRUE(cp_list != NULL) << "cp_list is null" << std::endl;
200 ASSERT_TRUE(cp_count > 0) << "cp_count is 0" << std::endl;
201 std::cout << " [cp_count]: " << cp_count << std::endl;
202 std::cout << " [cp_list[0]]: " << cp_list[0] << std::endl;
205 TEST(TAPI_INIT, tel_init_P)
207 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
208 ASSERT_TRUE(cp_list != NULL && cp_count > 0);
210 tapi_h = tel_init(cp_list[0]);
211 ASSERT_TRUE(tapi_h != NULL) << "tel_init() is failed" << std::endl;
215 TEST(TAPI_INIT, tel_get_ready_state_P)
217 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
218 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
221 int ret = tel_get_ready_state(&state);
222 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_ready_state() is failed" << std::endl;
223 ASSERT_TRUE(state == 1) << "TELEPHONY_STATE_NOT_READY" << std::endl;
225 std::cout << " - telephony_state : TELEPHONY_STATE_READY" << std::endl;
228 TEST(TAPI_INIT, tel_register_noti_event_P)
230 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
231 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
234 ret = tel_register_noti_event(tapi_h, TAPI_NOTI_MODEM_POWER, _noti_modem_power, NULL);
235 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_register_noti_event() : TAPI_NOTI_MODEM_POWER is failed" << std::endl;
237 ret = tel_register_noti_event(tapi_h, TAPI_NOTI_NETWORK_REGISTRATION_STATUS, _noti_registration_status, NULL);
238 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_register_noti_event() : TAPI_NOTI_NETWORK_REGISTRATION_STATUS is failed" << std::endl;
242 TEST(TAPI_NETWORK, tel_get_property_int_P)
244 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
245 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
247 int svc_type = -1, act = -1, cs = -1, ps = -1;
248 int roam = -1, sig_level = -1;
250 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
251 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_ACT, &act);
252 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_CIRCUIT_STATUS, &cs);
253 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_PACKET_STATUS, &ps);
254 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &sig_level);
255 tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_ROAMING_STATUS, &roam);
257 std::cout << "<network properties>" << std::endl;
258 std::cout << " [service_type]: " << svc_type << "(1=No Service, 2=Emergency, 4=2G, 7=3G, 9=LTE)" << std::endl;
259 std::cout << " [access technology]: " << act << "(0=No Service, 1=GSM, 5=UMTS, 7=HSDPA, 19=LTE)" << std::endl;
260 std::cout << " [cs_status]: " << cs << "(0=No Service, 1=Emergency, 2=Avaliable, 3=Searching)"<< std::endl;
261 std::cout << " [ps_status]: " << ps << "(0=No Service, 1=Emergency, 2=Avaliable, 3=Searching)"<< std::endl;
262 std::cout << " [sig_level]: " << sig_level << std::endl;
263 std::cout << " [roaming_status]: " << roam << std::endl;
266 TEST(TAPI_NETWORK, tel_get_property_string_P)
268 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
269 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
271 char *plmn = NULL, *n_name = NULL, *s_name = NULL;
273 tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_PLMN, &plmn);
274 tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_NETWORK_NAME, &n_name);
275 tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_SPN_NAME, &s_name);
277 std::cout << "<network properties>" << std::endl;
278 std::cout << " [plmn]: " << plmn << std::endl;
279 std::cout << " [network_name]: " << n_name << std::endl;
280 std::cout << " [spn_name]: " << s_name << std::endl;
289 TEST(TAPI_MODEM, telephony_modem_get_power_status_P)
291 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
292 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
294 int modem_status = -1;
295 int ret = tel_check_modem_power_status(tapi_h, &modem_status);
296 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_check_modem_power_status() is failed" << std::endl;
298 std::cout << " - modem_power_status = " << modem_status << " (0=on,1=off,2=rst,3=low)" << std::endl;
301 TEST(TAPI_MODEM, tel_get_misc_me_version_sync_P)
303 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
304 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
306 TelMiscVersionInformation *info = NULL;
307 info = tel_get_misc_me_version_sync(tapi_h);
308 ASSERT_TRUE(NULL != info) << "tel_get_misc_me_version_sync() is failed" << std::endl;
310 std::cout << " [sw version]: " << info->szSwVersion << std::endl;
311 std::cout << " [hw version]: " << info->szHwVersion << std::endl;
312 std::cout << " [RfCal Date]: " << info->szRfCalDate << std::endl;
313 std::cout << " [Product Code]: " << info->szProductCode << std::endl;
314 std::cout << " [Model ID]: " << info->szModelId << std::endl;
315 std::cout << " [Prl Version]: " << info->szPrlVersion << std::endl;
316 std::cout << " [ERI Version]: " << info->szEriVersion << std::endl;
321 TEST(TAPI_MODEM, tel_get_misc_me_sn_sync_P)
323 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
324 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
326 TelMiscSNInformation *sn;
327 sn = tel_get_misc_me_sn_sync(tapi_h);
328 ASSERT_TRUE(NULL != sn) << "tel_get_misc_me_sn_sync() is failed" << std::endl;
331 std::cout << " [esn number]: " << sn->szEsn << std::endl;
332 std::cout << " [meid number]: " << sn->szMeid << std::endl;
333 std::cout << " [imei number]: " << sn->szImei << std::endl;
334 std::cout << " [imeisv number]: " << sn->szImeiSv << std::endl;
339 TEST(TAPI_MODEM, tel_get_misc_me_imei_sync_P)
341 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
342 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
345 imei = tel_get_misc_me_imei_sync(tapi_h);
346 ASSERT_TRUE(NULL != imei) << "tel_get_misc_me_imei_sync() is failed" << std::endl;
348 std::cout << " [imei number]: " << imei << std::endl;
353 TEST(TAPI_MODEM, tel_get_flight_mode_P1)
355 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
356 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
358 int ret = tel_get_flight_mode(tapi_h, _get_flight_mode_callback, NULL);
359 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_flight_mode() is failed" << std::endl;
361 RUN_GMAIN_LOOP(__timeout_callback);
363 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_flight_mode() is failed failed";
364 async_result = ASYNC_RESULT_UNKNOWN;
367 TEST(TAPI_MODEM, tel_set_flight_mode_on)
369 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
370 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
372 int ret = tel_set_flight_mode(tapi_h, TAPI_POWER_FLIGHT_MODE_ENTER, _set_flight_mode_callback, NULL);
373 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_set_flight_mode() is failed" << std::endl;
375 RUN_GMAIN_LOOP(__timeout_callback);
377 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_set_flight_mode()[ON] is failed failed";
378 async_result = ASYNC_RESULT_UNKNOWN;
381 TEST(TAPI_MODEM, tel_get_flight_mode_P2)
383 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
384 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
386 int ret = tel_get_flight_mode(tapi_h, _get_flight_mode_callback, NULL);
387 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_flight_mode() is failed" << std::endl;
389 RUN_GMAIN_LOOP(__timeout_callback);
391 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_flight_mode() is failed failed";
392 async_result = ASYNC_RESULT_UNKNOWN;
395 TEST(TAPI_MODEM, tel_set_flight_mode_off)
397 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
398 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
400 int ret = tel_set_flight_mode(tapi_h, TAPI_POWER_FLIGHT_MODE_LEAVE, _set_flight_mode_callback, NULL);
401 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_set_flight_mode() is failed" << std::endl;
403 RUN_GMAIN_LOOP(__timeout_callback);
405 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_set_flight_mode()[OFF] is failed failed";
406 async_result = ASYNC_RESULT_UNKNOWN;
409 TEST(TAPI_SIM, tel_get_sim_init_info_P)
411 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
412 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
415 int sim_card_changed = 0;
417 ret = tel_get_sim_init_info(tapi_h, &sim_card_status, &sim_card_changed);
418 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_init_info() is failed" << std::endl;
420 if (sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
421 std::cout << " [SIM status]: SIM_INIT_COMPLETED" << std::endl;
422 std::cout << " [SIM changed]: " << sim_card_changed<< std::endl;
423 } else if (sim_card_status == TAPI_SIM_STATUS_CARD_NOT_PRESENT) {
424 std::cout << " [SIM status]: No SIM" << std::endl;
426 std::cout << " [SIM status]: SIM card Error" << std::endl;
430 TEST(TAPI_SIM, tel_get_sim_imsi_P)
432 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
433 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
436 TelSimImsiInfo_t imsi;
437 memset(&imsi, 0, sizeof(TelSimImsiInfo_t));
439 if (sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
440 ret = tel_get_sim_imsi(tapi_h, &imsi);
441 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_imsi() is failed" << std::endl;
443 std::cout << " [mcc]: "<< imsi.szMcc << std::endl;
444 std::cout << " [mnc]: " << imsi.szMnc << std::endl;
445 std::cout << " [msin]: " << imsi.szMsin << std::endl;
449 TEST(TAPI_SIM, tel_get_sim_iccid_P)
451 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
452 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
454 int ret = tel_get_sim_iccid(tapi_h, _get_sim_iccid_callback, NULL);
455 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_iccid() is failed" << std::endl;
457 if (sim_card_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
458 RUN_GMAIN_LOOP(__timeout_callback);
460 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_sim_iccid() is failed failed";
461 async_result = ASYNC_RESULT_UNKNOWN;
465 TEST(TAPI_SIM, tel_get_sim_msisdn_P)
467 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
468 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
470 int ret = tel_get_sim_msisdn(tapi_h, _get_sim_msisdn_callback, NULL);
471 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_get_sim_msisdn() is failed" << std::endl;
473 RUN_GMAIN_LOOP(__timeout_callback);
475 EXPECT_EQ(ASYNC_RESULT_SUCCESS, async_result) << "tel_get_sim_msisdn() is failed failed";
476 async_result = ASYNC_RESULT_UNKNOWN;
479 TEST(TAPI_DEINIT, tel_deregister_noti_event_P)
481 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
482 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
485 ret = tel_deregister_noti_event(tapi_h, TAPI_NOTI_MODEM_POWER);
486 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_deregister_noti_event() : TAPI_NOTI_MODEM_POWER is failed" << std::endl;
488 ret = tel_deregister_noti_event(tapi_h, TAPI_NOTI_NETWORK_REGISTRATION_STATUS);
489 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_deregister_noti_event() : TAPI_NOTI_NETWORK_REGISTRATION_STATUS is failed" << std::endl;
492 TEST(TAPI_DEINIT, tel_deinit_P)
494 ASSERT_EQ(true, g_bFeatureTelephony) << FEATRE_NOT_SUPPORT << std::endl;
495 ASSERT_TRUE(tapi_h != NULL) << "tapi_h is NULL" << std::endl;
497 int ret = tel_deinit(tapi_h);
498 EXPECT_EQ(TAPI_API_SUCCESS, ret) << "tel_deinit() is failed" << std::endl;
502 int main(int argc, char **argv)
507 testing::InitGoogleTest(&argc, argv);
509 std::cout << "Exception occurred." << std::endl;
512 ret = RUN_ALL_TESTS();
513 } catch (const ::testing::internal::GoogleTestFailureException& e) {
515 std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;