diff --git a/Kconfig b/Kconfig index d59876c..266cef2 100644 --- a/Kconfig +++ b/Kconfig @@ -40,6 +40,11 @@ config TELEPHONY_TOOL bool "Telephony tool" default n +config TELEPHONY_TEST + bool "enbale telephony test" + default n + depends on TELEPHONY && TESTING_CMOCKA + if TELEPHONY_TOOL config TELEPHONY_TOOL_STACKSIZE @@ -50,5 +55,21 @@ config TELEPHONY_TOOL_PRIORITY int "Telephony tool priority" default 100 +endif + +if TELEPHONY_TEST + +config TELEPHONY_TEST_PRIORITY + int "cmocka_telephony_test priority" + default 99 + +config TELEPHONY_TEST_STACKSIZE + int "cmocka_telephony_test stack size" + default 16384 + +config TEST_PHONE_NUMBER + string "test phone number" + default "10086" + endif endif diff --git a/Makefile b/Makefile index 2705df7..17d907e 100644 --- a/Makefile +++ b/Makefile @@ -34,14 +34,21 @@ ifneq ($(CONFIG_TELEPHONY_TOOL),) STACKSIZE += $(CONFIG_TELEPHONY_TOOL_STACKSIZE) endif -ASRCS := $(wildcard $(ASRCS)) -CSRCS := $(wildcard $(CSRCS)) -CXXSRCS := $(wildcard $(CXXSRCS)) -MAINSRC := $(wildcard $(MAINSRC)) -NOEXPORTSRCS = $(ASRCS)$(CSRCS)$(CXXSRCS)$(MAINSRC) - -ifneq ($(NOEXPORTSRCS),) -BIN := $(APPDIR)/staging/libframework.a +ifneq ($(CONFIG_TELEPHONY_TEST),) + CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/testing/cmocka/cmocka/include + CSRCS += $(filter-out test/*_telephony_test.c, $(wildcard test/*.c)) + + ifneq ($(CONFIG_GOLDFISH_RIL),) + MAINSRC += $(CURDIR)/test/cmocka_telephony_test.c + else + MAINSRC += $(CURDIR)/test/product_telephony_test.c + endif + PROGNAME += cmocka_telephony_test + PRIORITY += $(CONFIG_TELEPHONY_TEST_PRIORITY) + STACKSIZE += $(CONFIG_TELEPHONY_TEST_STACKSIZE) + +depend:: + $(Q) touch $(CSRCS) endif EXPORT_FILES := include diff --git a/src/tapi_data.c b/src/tapi_data.c index bb59dc6..0dd73c5 100644 --- a/src/tapi_data.c +++ b/src/tapi_data.c @@ -245,7 +245,7 @@ static int data_property_changed(DBusConnection* connection, ar->arg2 = tapi_utils_get_slot_id(slot); isvalid = true; } else if ((ar->msg_id == MSG_DATA_NETWORK_TYPE_CHANGE_IND) - && (strcmp(property, "Bearer") == 0)) { + && (strcmp(property, "Technology") == 0)) { ar->status = OK; dbus_message_iter_get_basic(&var, &value_int); diff --git a/test/cmocka_telephony_test.c b/test/cmocka_telephony_test.c new file mode 100644 index 0000000..0f8c56d --- /dev/null +++ b/test/cmocka_telephony_test.c @@ -0,0 +1,2379 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "telephony_call_test.h" +#include "telephony_common_test.h" +#include "telephony_data_test.h" +#include "telephony_ims_test.h" +#include "telephony_network_test.h" +#include "telephony_sim_test.h" +#include "telephony_sms_test.h" +#include "telephony_ss_test.h" +#include "telephony_test.h" + +#define REPEAT_TEST_MORE_FOR for (int _i = 0; _i < 10; _i++) +#define REPEAT_TEST_LESS_FOR for (int _i = 0; _i < 3; _i++) + +char* phone_num = NULL; +static uv_async_t g_uv_exit; +static int ready_done; +tapi_context context = NULL; +static int count = 0; +typedef enum { + CASE_NORMAL_MODE = 0, + CASE_AIRPLANE_MODE = 1, + CASE_CALL_DIALING = 2, + CASE_MODEM_POWEROFF = 3, +} case_type; + +struct judge_type judge_data; + +char* short_english_text = "test"; +char* long_english_text = "testtesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttest"; +char* short_chinese_text = "测试"; +char* long_chinese_text = "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试"; + +static void exit_async_cleanup(uv_async_t* handle) +{ + tapi_close(context); + context = NULL; +} + +tapi_context get_tapi_ctx(void) +{ + return context; +} + +int judge(void) +{ + int timeout = TIMEOUT; + + while (timeout-- > 0) { + + if (judge_data.flag == judge_data.expect) { + if (judge_data.result != 0) + syslog(LOG_ERR, "result error\n"); + else + syslog(LOG_INFO, "result correct\n"); + + return 0; + } + + sleep(1); + syslog(LOG_INFO, "There is %d second(s) remain.\n", timeout); + } + + syslog(LOG_ERR, "judge timeout\n"); + assert(0); + return -ETIME; +} + +void judge_data_init(void) +{ + judge_data.flag = INVALID_VALUE; + judge_data.expect = INVALID_VALUE; + judge_data.result = INVALID_VALUE; +} + +static void TestNuttxHasIccCard(void** state) +{ + (void)state; + int ret = tapi_sim_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxHasIccCardNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_multi_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimOperator(void** state) +{ + (void)state; + int ret = tapi_sim_get_sim_operator_test(0, "310260"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimOperatorName(void** state) +{ + (void)state; + int ret = tapi_sim_get_sim_operator_name_test(0, "T-Mobile"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimOperatorNameNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_get_sim_operator_name_numerous(0, "T-Mobile"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimOperatorNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_multi_get_sim_operator(0, "310260"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimSubscriberId(void** state) +{ + (void)state; + int ret = tapi_sim_get_sim_subscriber_id_test(0, "310260000000000"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimSubscriberIdNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_multi_get_sim_subscriber_id_test(0, "310260000000000"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetIccId(void** state) +{ + (void)state; + int ret = tapi_sim_get_sim_iccid_test(0, "89860318640220133897"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetIccIdNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_multi_get_sim_iccid_test(0, "89860318640220133897"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetMSISDN(void** state) +{ + (void)state; + int ret = tapi_sim_get_ef_msisdn_test(0, "+15551234567"); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetMSISDNNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_multi_get_ef_msisdn_test(0, "+15551234567"); + assert_int_equal(ret, OK); +} + +static void TestNuttxTransmitAPDUInBasicChannel(void** state) +{ + (void)state; + int ret = tapi_transmit_apdu_basic_channel_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetSimState(void** state) +{ + (void)state; + int ret = tapi_sim_get_state_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxOpenLogicalChannel(void** state) +{ + (void)state; + int ret = tapi_open_logical_channel_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxCloseLogicalChannel(void** state) +{ + (void)state; + int ret = tapi_close_logical_channel_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxLogicalChannelOpenCloseNumerous(void** state) +{ + (void)state; + int ret = sim_open_close_logical_channel_numerous(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxTransmitAPDUInLogicalChannel(void** state) +{ + int ret = sim_transmit_apdu_by_logical_channel(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxSetUiccEnablement(void** state) +{ + (void)state; + int ret = tapi_sim_set_uicc_enablement_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetUiccEnablement(void** state) +{ + (void)state; + int ret = tapi_sim_get_uicc_enablement_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxTransmitAPDUBasicChannel(void** state) +{ + (void)state; + int ret = tapi_transmit_apdu_basic_channel_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxEnterPin(void** state) +{ + (void)state; + int ret = tapi_sim_enter_pin_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxChangePin(void** state) +{ + (void)state; + int ret = sim_change_pin_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxLockPin(void** state) +{ + (void)state; + int ret = tapi_sim_lock_pin_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxUnlockPin(void** state) +{ + (void)state; + int ret = tapi_sim_unlock_pin_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxLoadAdnEntries(void** state) +{ + (void)state; + int ret = tapi_phonebook_load_adn_entries_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxLoadFdnEntries(void** state) +{ + (void)state; + int ret = tapi_phonebook_load_fdn_entries_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxInsertFdnEntry(void** state) +{ + (void)state; + int ret = tapi_phonebook_insert_fdn_entry_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxUpdateFdnEntry(void** state) +{ + (void)state; + int ret = tapi_phonebook_update_fdn_entry_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDeleteFdnEntry(void** state) +{ + (void)state; + int ret = tapi_phonebook_delete_fdn_entry_test(0); + assert_int_equal(ret, OK); +} + +// static void cmocka_tapi_sim_listen_sim_state_change(void **state) +// { +// int ret = tapi_sim_listen_sim_test(0, 23); +// assert_int_equal(ret, OK); +// } + +// static void cmocka_tapi_sim_listen_sim_uicc_app_enabled_change(void **state) +// { +// int ret = tapi_sim_listen_sim_test(0, 24); +// assert_int_equal(ret, OK); +// } + +// static void TestNuttxLoadEccList(void** state) +// { +// (void)state; +// int ret = tapi_call_load_ecc_list_test(0); +// assert_int_equal(ret, 0); +// } + +static void TestNuttxSetVoicecallSlot(void** state) +{ + (void)state; + int ret = tapi_call_set_default_voicecall_slot_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetVoicecallSlot(void** state) +{ + (void)state; + int ret = tapi_call_get_default_voicecall_slot_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxClearVoicecallSlotSet(void** state) +{ + (void)state; + int ret = call_clear_voicecall_slot_set(); + assert_int_equal(ret, 0); +} + +static void TestNuttxListenCall(void** state) +{ + (void)state; + int ret = tapi_call_listen_call_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxUnlistenCall(void** state) +{ + (void)state; + int ret = tapi_call_unlisten_call_test(); + assert_int_equal(ret, 0); +} + +static void TestNuttxStartDtmf(void** state) +{ + (void)state; + int ret = tapi_start_dtmf_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxStopDtmf(void** state) +{ + (void)state; + int ret = tapi_stop_dtmf_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxHangupBetweenDialingAndAnswering(void** state) +{ + (void)state; + sleep(2); + int ret = call_hangup_between_dialing_and_answering(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxIncomingCallAnswerAndHangup(void** state) +{ + int ret = incoming_call_answer_and_hangup(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxIncomingCallAnswerAndRemoteHangup(void** state) +{ + int ret = incoming_call_answer_and_remote_hangup(0); + assert_int_equal(ret, 0); +} + +// static void TestNuttxDialAgainAfterRemoteHangup(void **state) { +// int ret = call_dial_after_caller_reject(0); +// assert_int_equal(ret, 0); +// } + +// static void TestNuttxHangupCallAfterRemoteAnswer(void **state) { +// int ret = call_hangup_after_caller_answer(0); +// assert_int_equal(ret, 0); +// } + +static void TestNuttxOutgoingCallRemoteAnswerAndHangup(void** state) +{ + int ret = outgoing_call_remote_answer_and_hangup(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxCallConnectAndLocalHangup(void** state) +{ + int ret = call_connect_and_local_hangup(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxDialAndRemoteHangup(void** state) +{ + int ret = dial_and_remote_hangup(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxIncomingCallandLocalHangup(void** state) +{ + int ret = incoming_call_and_local_hangup(0); + assert_int_equal(ret, 0); +} + +// static void TestNuttxRemoteHangupThenIncomingNewCall(void **state) { +// int ret = call_dial_caller_reject_and_incoming(0); +// assert_int_equal(ret, 0); +// } + +// static void TestNuttxRemoteHangupThenDialAnother(void **state) { +// int ret = call_dial_caller_reject_and_dial_another(0); +// assert_int_equal(ret, 0); +// } + +static void TestNuttxHangupCurrentCall(void** state) +{ + (void)state; + int ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxHangupAllCall(void** state) +{ + (void)state; + int ret = tapi_call_hangup_all_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetCallCount(void** state) +{ + (void)state; + int ret = tapi_get_call_count(0); + assert_true(ret >= 0); +} + +static void TestNuttxDialNumber(void** state) +{ + (void)state; + int ret = tapi_dial_number(0); + assert_int_equal(ret, OK); + sleep(2); +} + +static void TestNuttxDialEccNumber(void** state) +{ + (void)state; + int ret = tapi_dial_ecc_number(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialLongPhoneNumber(void** state) +{ + (void)state; + int ret = tapi_dial_with_long_phone_number(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialShotPhoneNumber(void** state) +{ + (void)state; + int ret = tapi_dial_with_short_phone_number(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialWithEnableHideCallId(void** state) +{ + (void)state; + int ret = tapi_dial_with_enable_hide_callerid(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialWithDisabledHideCallId(void** state) +{ + (void)state; + int ret = tapi_dial_with_disabled_hide_callerid(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialWithDefaultHideCallId(void** state) +{ + (void)state; + int ret = tapi_dial_with_default_hide_callerid(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +// static void TestNuttxIncomingNewCallThenRemoteHangup(void **state) { +// int ret = call_incoming_and_hangup_by_dialer_before_answer(0); +// assert_int_equal(ret, 0); +// } + +static void TestNuttxDialWithAreaCode(void** state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_area_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialWithPauseCode(void** state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_pause_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialWithWaitCode(void** state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_wait_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDialWithNumerousCode(void** state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_numerous_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttCheckAleringStatusAfterDial(void** state) +{ + (void)state; + int ret = call_check_alerting_status_after_dial(0); + assert_int_equal(ret, OK); +} + +// static void TestNuttxCheckStatusInDialing(void **state) +// { +// int ret = call_check_status_in_dialing(0); +// assert_int_equal(ret, 0); +// } + +// data testcases +static void TestNuttxDataLoadApnContexts(void** state) +{ + (void)state; + int ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSaveApnContextSupl(void** state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "3", "supl", "supl", "2", "2"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSaveApnContextEmergency(void** state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "7", "emergency", + "emergency", "2", "2"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSaveLongApnContex(void** state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "1", + "longname-----------------------------------------" + "-----------------------------------------longname", + "cmnet4", "2", "2"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSaveApnContext(void** state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", "2"); + assert_int_equal(ret, 0); +} + +static void TestNuttxDataRemoveApnContext(void** state) +{ + (void)state; + int ret = tapi_data_remove_apn_context_test("0", "/ril_0/context3"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataResetApnContexts(void** state) +{ + (void)state; + int ret = tapi_data_reset_apn_contexts_test("0"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataResetApnContextsRepeatedly(void** state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + int ret = tapi_data_reset_apn_contexts_test("0"); + assert_int_equal(ret, OK); + } +} + +static void TestNuttxDataEditApnName(void** state) +{ + (void)state; + int ret; + ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "1", "cmname", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnType(void** state) +{ + (void)state; + int ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "3", "cmname", "cmname", "2", "2"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnProto(void** state) +{ + (void)state; + int ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "3", "cmname", "cmname", "0", "2"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnAuth(void** state) +{ + (void)state; + int ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "3", "cmname", "cmname", "0", "0"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnAll(void** state) +{ + (void)state; + int ret; + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "2", "cmnameall", "cmnameall", "1", "1"); + assert_int_equal(ret, OK); + ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnAndRemove(void** state) +{ + (void)state; + int ret; + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "2", "cmnameall", "cmnameall", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_remove_apn_context_test("0", "/ril_0/context3"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnAndReset(void** state) +{ + (void)state; + int ret; + ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "1", "cmname", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_reset_apn_contexts_test("0"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEditApnRepeatedlyAndLoad(void** state) +{ + (void)state; + int ret; + ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context1", "1", "cmname11", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context1", "1", "cmname22", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context1", "1", "cmname33", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEnable(void** state) +{ + (void)state; + int ret = data_enabled_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataDisable(void** state) +{ + (void)state; + int ret = data_disabled_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataEnableRepeatedly(void** state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + TestNuttxDataEnable(state); + TestNuttxDataDisable(state); + } +} + +static void TestNuttxDataIsEnable(void** state) +{ + (void)state; + bool enable = false; + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 1); +} + +static void TestNuttxDataIsDisable(void** state) +{ + (void)state; + bool enable = true; + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 0); +} + +static void TestNuttxDataRegister(void** state) +{ + (void)state; + int ret = tapi_data_listen_data_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataUnregister(void** state) +{ + (void)state; + int ret = tapi_data_unlisten_data_test(); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataRequestNetworkInternet(void** state) +{ + (void)state; + int ret = data_request_network_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataReleaseNetworkInternet(void** state) +{ + (void)state; + int ret = data_release_network_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataReleaseNetworkInternetRepeatedly(void** state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + TestNuttxDataReleaseNetworkInternet(state); + TestNuttxDataRequestNetworkInternet(state); + } +} + +static void TestNuttxDataRequestNetworkIms(void** state) +{ + (void)state; + int ret = data_request_ims(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataReleaseNetworkIms(void** state) +{ + (void)state; + int ret = data_release_ims(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataReleaseNetworkImsRepeatedly(void** state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + TestNuttxDataRequestNetworkIms(state); + TestNuttxDataReleaseNetworkIms(state); + } +} + +static void TestNuttxDataSetPreferredApn(void** state) +{ + (void)state; + int ret = tapi_data_set_preferred_apn_test(0, "/ril_0/context1"); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataGetPreferredApn(void** state) +{ + (void)state; + int ret = tapi_data_get_preferred_apn_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSendScreenState(void** state) +{ + (void)state; + int ret = tapi_data_send_screen_stat_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataIsPsAttached(void** state) +{ + (void)state; + int ret = tapi_data_is_ps_attached_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataGetNetworkType(void** state) +{ + (void)state; + int ret = tapi_data_get_network_type_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSetDefaultDataSlot(void** state) +{ + (void)state; + int ret = tapi_data_set_default_data_slot_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataGetDefaultDataSlot(void** state) +{ + (void)state; + sleep(2); + int ret = tapi_data_get_default_data_slot_test(); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataSetDataAllow(void** state) +{ + (void)state; + int ret = tapi_data_set_data_allow_test(0); + assert_true(ret == OK); +} + +static void TestNuttxDataGetCallList(void** state) +{ + (void)state; + int ret = data_get_call_list(0); + assert_true(ret == OK); +} + +static void TestNuttxEnableDataRoaming(void** state) +{ + (void)state; + int ret = data_enable_roaming_test(); + assert_true(ret == OK); +} + +static void TestNuttxDisableDataRoaming(void** state) +{ + (void)state; + int ret = data_disable_roaming_test(); + assert_true(ret == OK); +} + +static void TestNuttxSmsSetServiceCenterNum(void** state) +{ + (void)state; + int ret = sms_set_service_center_number_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsGetServiceCenterNum(void** state) +{ + (void)state; + sleep(5); + int ret = sms_check_service_center_number_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortMessageInEnglish(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortMessageInChinese(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortDataMessageInEnglish(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortDataMessageInChinese(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongMessageInEnglish(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongMessageInChinese(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongDataMessageInEnglish(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongDataMessageInChinese(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortEnglishMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_message_in_dialing(0, phone_num, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortChineseMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_message_in_dialing(0, phone_num, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongEnglishMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_message_in_dialing(0, phone_num, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongChineseMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_message_in_dialing(0, phone_num, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortEnglishDataMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, short_english_text, 0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendShortChineseDataMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, short_chinese_text, 0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongEnglishDataMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, long_english_text, 0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsSendLongChineseDataMessageInDialing(void** state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, long_chinese_text, 0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendEnglishMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendChineseMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongEnglishMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongChineseMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendEnglishDataMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendChineseDataMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongEnglishDataMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongChineseDataMessageInVoiceImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendEnglishMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendChineseMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongEnglishMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongChineseMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendEnglishDataMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendChineseDataMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongEnglishDataMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongChineseDataMessageInSmsImsCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendEnglishMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendChineseMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongEnglishMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongChineseMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendEnglishDataMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendChineseDataMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongEnglishDataMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSendLongChineseDataMessageInSmsVoiceCap(void** state) +{ + (void)state; + int ret = sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void TestNuttxSetSmsDefaultSlot(void** state) +{ + (void)state; + int ret = tapi_sms_set_default_slot(get_tapi_ctx(), 0); + sleep(5); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetSmsDefaultSlot(void** state) +{ + (void)state; + int result = -1; + int ret = tapi_sms_get_default_slot(context, &result); + syslog(LOG_INFO, "%s, ret: %d, result: %d", __func__, ret, result); + assert_int_equal(ret, 0); + assert_int_equal(result, 0); +} + +static void TestNuttxSmsSetCellBroadcastPower(void** state) +{ + (void)state; + int ret = tapi_sms_set_cell_broadcast_power_on(get_tapi_ctx(), 0, 1); + sleep(5); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsGetCellBroadcastPower(void** state) +{ + (void)state; + bool result = false; + int ret = tapi_sms_get_cell_broadcast_power_on(get_tapi_ctx(), 0, &result); + syslog(LOG_INFO, "%s, ret: %d, result: %d", __func__, 0, (int)result); + assert_int_equal(ret, 0); + assert_int_equal(result, 1); +} + +static void TestNuttxSmsSetCellBroadcastTopics(void** state) +{ + (void)state; + int ret = tapi_sms_set_cell_broadcast_topics(get_tapi_ctx(), 0, "1"); + sleep(5); + assert_int_equal(ret, 0); +} + +static void TestNuttxSmsGetCellBroadcastTopics(void** state) +{ + (void)state; + char* result = NULL; + int ret = tapi_sms_get_cell_broadcast_topics(get_tapi_ctx(), 0, &result); + assert_int_equal(ret, 0); + assert_int_equal(strcmp(result, "1"), 0); +} + +static void TestNuttxNetSelectAuto(void** state) +{ + (void)state; + int ret = tapi_net_select_auto_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetSelectManual(void** state) +{ + (void)state; + sleep(4); + int ret = tapi_net_select_manual_test(0, "310", "260", "lte"); + sleep(4); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetScan(void** state) +{ + (void)state; + int ret = tapi_net_scan_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetGetServingCellinfos(void** state) +{ + (void)state; + int ret = tapi_net_get_serving_cellinfos_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetGetNeighbouringCellInfos(void** state) +{ + (void)state; + int ret = tapi_net_get_neighbouring_cellInfos_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetRegistrationInfo(void** state) +{ + (void)state; + int ret = tapi_net_registration_info_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetGetOperatorName(void** state) +{ + (void)state; + int ret = tapi_net_get_operator_name_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetQuerySignalstrength(void** state) +{ + (void)state; + int ret = tapi_net_query_signalstrength_test(0); + assert_int_equal(ret, OK); +} + +// static void TestNuttxNetSetCellInfoListRate(void **state) +// { +// int ret = tapi_net_set_cell_info_list_rate_test(0, 10); +// assert_int_equal(ret, OK); +// } + +static void TestNuttxNetGetVoiceRegistered(void** state) +{ + (void)state; + int ret = tapi_net_get_voice_registered_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetVoiceNwType(void** state) +{ + (void)state; + tapi_network_type type = NETWORK_TYPE_UNKNOWN; + int ret = tapi_network_get_voice_network_type(get_tapi_ctx(), 0, &type); + syslog(LOG_INFO, "%s, ret: %d, type: %d", __func__, ret, (int)type); + assert_int_equal(ret, OK); + assert_int_equal((int)type, 13); +} + +static void TestNuttxGetVoiceRoaming(void** state) +{ + (void)state; + bool value = true; + int ret = tapi_network_is_voice_roaming(get_tapi_ctx(), 0, &value); + syslog(LOG_INFO, "%s, ret: %d, value: %d", __func__, ret, (int)value); + assert_int_equal(ret, OK); + assert_int_equal((int)value, 0); +} + +// modem +static void TestNuttxModemGetImei(void** state) +{ + (void)state; + int ret = tapi_get_imei_test(0); + assert_int_equal(ret, OK); +} + +// static void TestNuttxModemSetUmtsPrefNetMode(void** state) +// { +// // defalut rat mode is NETWORK_PREF_NET_TYPE_LTE_GSM_WCDMA (9) +// tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_UMTS; +// int ret = tapi_set_pref_net_mode_test(0, set_value); +// assert_int_equal(ret, OK); +// } + +// static void TestNuttxModemSetGsmOnlyPrefNetMode(void** state) +// { +// tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_GSM_ONLY; +// int ret = tapi_set_pref_net_mode_test(0, set_value); +// assert_int_equal(ret, OK); +// } + +// static void TestNuttxModemSetWcdmaOnlyPrefNetMode(void** state) +// { +// tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_WCDMA_ONLY; +// int ret = tapi_set_pref_net_mode_test(0, set_value); +// assert_int_equal(ret, OK); +// } + +// static void TestNuttxModemSetLteOnlyPrefNetMode(void** state) +// { +// tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_LTE_ONLY; +// int ret = tapi_set_pref_net_mode_test(0, set_value); +// assert_int_equal(ret, OK); +// } + +// static void TestNuttxModemSetLteWcdmaPrefNetMode(void** state) +// { +// tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_LTE_WCDMA; +// int ret = tapi_set_pref_net_mode_test(0, set_value); +// assert_int_equal(ret, OK); +// } + +// static void TestNuttxModemSetLteGsmWcdmaPrefNetMode(void** state) +// { +// tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_LTE_GSM_WCDMA; +// int ret = tapi_set_pref_net_mode_test(0, set_value); +// assert_int_equal(ret, OK); +// } + +static void TestNuttxModemGetPrefNetMode(void** state) +{ + sleep(5); + tapi_pref_net_mode get_value = NETWORK_PREF_NET_TYPE_ANY; + int ret = tapi_get_pref_net_mode_test(0, &get_value); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemSetRadioPowerOn(void** state) +{ + (void)state; + int ret = tapi_set_radio_power_test(0, 1); + assert_int_equal(ret, OK); + sleep(10); +} + +static void TestNuttxModemSetRadioPowerOff(void** state) +{ + (void)state; + int ret = tapi_set_radio_power_test(0, 0); + assert_int_equal(ret, OK); + sleep(10); +} + +static void TestNuttxModemSetRadioPowerOnOffRepeatedly(void** state) +{ + (void)state; + REPEAT_TEST_LESS_FOR + { + TestNuttxModemSetRadioPowerOn(state); + TestNuttxModemSetRadioPowerOff(state); + } +} + +static void TestNuttxGetModemEnableStatus(void** state) +{ + (void)state; + int get_state = 1; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetModemDsiableStatus(void** state) +{ + (void)state; + int get_state = 0; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemEnable(void** state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 1); + assert_int_equal(ret, OK); + sleep(10); +} + +static void TestNuttxModemDisable(void** state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 0); + assert_int_equal(ret, OK); + sleep(10); +} + +static void TestNuttxModemEnableDisableRepeatedly(void** state) +{ + (void)state; + REPEAT_TEST_LESS_FOR + { + TestNuttxModemEnable(state); + TestNuttxGetModemEnableStatus(state); + TestNuttxModemDisable(state); + TestNuttxGetModemDsiableStatus(state); + } +} + +static void TestNuttxModemRegister(void** state) +{ + (void)state; + int ret = tapi_modem_register_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemUnregister(void** state) +{ + (void)state; + int ret = tapi_modem_unregister_test(); + assert_true(ret == OK); +} + +static void TestNuttxGetModemRevision(void** state) +{ + int ret; + ret = tapi_get_modem_revision_test(0); + assert_int_equal(ret, OK); +} + +// static void TestNuttxImsServiceStatus(void** state) +// { +// case_type* mode = *state; +// // device default info.reg_info is 1, info.ext_info is 5 +// REPEAT_TEST_LESS_FOR +// { +// tapi_ims_registration_info info; +// int ret = tapi_ims_set_service_status_test(0, 1); +// if (*mode == CASE_NORMAL_MODE || *mode == CASE_AIRPLANE_MODE +// || *mode == CASE_CALL_DIALING) { +// assert_int_equal(ret, OK); +// ret = tapi_ims_get_registration_test(0, &info); +// assert_int_equal(ret, OK); +// assert_int_equal(info.reg_info, 1); +// assert_int_equal(info.ext_info, 1); +// } else { +// assert_int_equal(ret, -5); +// } +// sleep(1); + +// ret = tapi_ims_set_service_status_test(0, 5); +// if (*mode == CASE_NORMAL_MODE || *mode == CASE_AIRPLANE_MODE +// || *mode == CASE_CALL_DIALING) { +// assert_int_equal(ret, OK); +// ret = tapi_ims_get_registration_test(0, &info); +// assert_int_equal(ret, OK); +// assert_int_equal(info.reg_info, 1); +// assert_int_equal(info.ext_info, 5); +// sleep(1); +// } else { +// assert_int_equal(ret, -5); +// } +// } +// } + +// static void TestNuttxModemDialCall(void** state) +// { +// int slot_id = 0; +// int ret1 = tapi_call_listen_call_test(slot_id); +// int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); +// int ret = ret1 || ret2; +// assert_int_equal(ret, OK); +// sleep(2); +// } + +// static void TestNuttxModemHangupCall(void** state) +// { +// int slot_id = 0; +// int ret1 = tapi_call_hanup_current_call_test(slot_id); +// int ret2 = tapi_call_unlisten_call_test(); +// int ret = ret1 || ret2; +// assert_int_equal(ret, OK); +// } + +static void TestNuttxModemInvokeOemShotRilRequestRaw(void** state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "01A0B023", 4); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemInvokeOemLongRilRequestRaw(void** state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "01A0B02301A0B02301A0B02301A0B02301A0B02301", 21); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemInvokeOemSeperateRilRequestRaw(void** state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "10|22", 2); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemInvokeOemNormalRilRequestRaw(void** state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "01A0B023", 2); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemInvokeOemRilRequestATCmdStrings(void** state) +{ + char* req_data = "AT+CPIN?"; + int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 1); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemInvokeOemRilRequestNotATCmdStrings(void** state) +{ + // not AT cmd + char* req_data = "10|22"; + int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 2); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemInvokeOemRilRequestHexStrings(void** state) +{ + char* req_data = "0x10|0x01"; + int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 2); + assert_int_equal(ret, OK); +} + +// static void TestNuttxModemInvokeOemRilRequestLongStrings(void **state) +// { +// char req_data[MAX_INPUT_ARGS_LEN]; + +// // test error +// // FIXME: tapi_invoke_oem_ril_request_strings_test interface buffer overflow +// // when req_data len is 21, current max len is 20 +// strcpy(req_data, +// "10|22|10|22|10|22|10|22|10|22|10|22|10|22|10|22|10|22|10|22"); +// int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 20); +// assert_int_equal(ret, -1); + +// // strcpy(req_data, "10|22"); +// // // FIXME: _dbus_check_is_valid_utf8 is called by dbus_message_iter_append_basic +// // // cannot handle \0 in char * string; +// // ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 20); +// // assert_int_equal(ret, -1); +// } + +// static void cmocka_set_radio_power_on_off_test(void **state) +// { +// for(int i = 0; i < 3; i++) +// { +// tapi_set_radio_power_test(0, 0); +// sleep(1); +// tapi_set_radio_power_test(0, 1); +// sleep(1); +// } +// int ret = tapi_get_radio_power_test(0); +// assert_int_equal(ret, 1); +// } + +static void TestNuttxImsListen(void** state) +{ + (void)state; + int ret = tapi_ims_listen_ims_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsTurnOn(void** state) +{ + (void)state; + int ret = tapi_ims_turn_on_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsGetRegistration(void** state) +{ + (void)state; + int ret = tapi_ims_get_registration_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsGetEnabled(void** state) +{ + (void)state; + int ret = tapi_ims_get_enabled_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsSetServiceStatus(void** state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 5); + assert_int_equal(ret, 0); + sleep(5); +} + +static void TestNuttxImsSetSmsCap(void** state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 4); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsSetSmsVoiceCap(void** state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 5); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsResetImsCap(void** state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 1); + assert_int_equal(ret, 0); + sleep(10); +} + +static void TestNuttxImsTurnOff(void** state) +{ + (void)state; + int ret = tapi_ims_turn_off_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxImsTurnOnOff(void** state) +{ + (void)state; + REPEAT_TEST_LESS_FOR + { + TestNuttxImsTurnOn(state); + TestNuttxImsGetEnabled(state); + TestNuttxImsGetRegistration(state); + TestNuttxImsTurnOff(state); + } +} + +static void TestNuttxSSRegister(void** state) +{ + (void)state; + int ret = tapi_listen_ss_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSSUnRegister(void** state) +{ + (void)state; + int ret = tapi_unlisten_ss_test(); + assert_int_equal(ret, 0); +} + +static void TestNuttxRequestCallBarring(void** state) +{ + (void)state; + int ret = tapi_ss_request_call_barring_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxSetCallBarring(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_barring_option_test(0, "AI", "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetCallBarring(void** state) +{ + (void)state; + sleep(5); + int ret = tapi_ss_get_call_barring_option_test(0, "VoiceIncoming", "always"); + assert_int_equal(ret, 0); +} + +static void TestNuttxChangeCallBarringPassword(void** state) +{ + (void)state; + int ret = tapi_ss_change_call_barring_password_test(0, "1234", "2345"); + assert_int_equal(ret, 0); +} + +static void TestNuttxResetCallBarringPassword(void** state) +{ + (void)state; + int ret = tapi_ss_change_call_barring_password_test(0, "2345", "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxDisableAllIncoming(void** state) +{ + (void)state; + int ret = tapi_ss_disable_all_incoming_test(0, "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxDisableAllOutgoing(void** state) +{ + (void)state; + int ret = tapi_ss_disable_all_outgoing_test(0, "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxDisableAllCallBarrings(void** state) +{ + (void)state; + int ret = tapi_ss_disable_all_call_barrings_test(0, "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxSetCallForwardingUnConditional(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 0, "10086"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetCallForwardingUnConditional(void** state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 0); + assert_int_equal(ret, 0); +} + +static void TestNuttxClearCallForwardingUnconditional(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 0, "\0"); + assert_int_equal(ret, 0); +} + +static void TestNuttxSetCallForwardingBusy(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 1, "10086"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetCallForwardingBusy(void** state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 1); + assert_int_equal(ret, 0); +} + +static void TestNuttxClearCallForwardingBusy(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 1, "\0"); + assert_int_equal(ret, 0); +} + +static void TestNuttxSetCallForwardingNoReply(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 2, "10086"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetCallForwardingNoReply(void** state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 2); + assert_int_equal(ret, 0); +} + +static void TestNuttxClearCallForwardingNoReply(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 2, "\0"); + assert_int_equal(ret, 0); +} + +static void TestNuttxSetCallForwardingNotReachable(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 3, "10086"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetCallForwardingNotReachable(void** state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 3); + assert_int_equal(ret, 0); +} + +static void TestNuttxClearCallForwardingNotReachable(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 3, "\0"); + assert_int_equal(ret, 0); +} + +static void TestNuttxEnableCallWaiting(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_waiting_test(0, true); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetEnableCallWaiting(void** state) +{ + (void)state; + int ret = tapi_ss_get_call_waiting_test(0, true); + assert_int_equal(ret, 0); +} + +static void TestNuttxDisableCallWaiting(void** state) +{ + (void)state; + int ret = tapi_ss_set_call_waiting_test(0, false); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetDisableCallWaiting(void** state) +{ + (void)state; + int ret = tapi_ss_get_call_waiting_test(0, false); + assert_int_equal(ret, 0); +} + +static void TestNuttxEnableFdn(void** state) +{ + (void)state; + int ret = tapi_ss_enable_fdn_test(0, true, "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetFdnEnabled(void** state) +{ + (void)state; + int ret = tapi_ss_query_fdn_test(0, true); + assert_int_equal(ret, 0); +} + +static void TestNuttxDisableFdn(void** state) +{ + (void)state; + int ret = tapi_ss_enable_fdn_test(0, false, "1234"); + assert_int_equal(ret, 0); +} + +static void TestNuttxGetFdnDisabled(void** state) +{ + (void)state; + int ret = tapi_ss_query_fdn_test(0, false); + assert_int_equal(ret, 0); +} + +static void tapi_cb(tapi_async_result* result) +{ + if (result->msg_id == EVENT_MODEM_ENABLE_DONE && result->status == OK) { + ready_done = 1; + } else if (result->msg_id == MSG_VOICE_REGISTRATION_STATE_CHANGE_IND) { + ready_done = 1; + } else { + ready_done = -1; + } +} + +static int wait_for_async_result(const char* str) +{ + while (ready_done != 1) { + if (ready_done == -1 || count >= 10) { + syslog(LOG_ERR, "%s\n", str); + return -1; + } else { + sleep(1); + count++; + } + } + + return 0; +} + +static void on_tapi_client_ready(const char* client_name, void* user_data) +{ + if (client_name != NULL) + syslog(LOG_DEBUG, "tapi is ready for %s\n", client_name); + + ready_done = 1; + + /** + * both args are NULL, that's tapi received disconnect message + * so we here need to stop the default loop + */ + if (client_name == NULL && user_data == NULL) { + if (context != NULL) { + syslog(LOG_ERR, "recieve dbus disconnected msg, free tapi context"); + tapi_close(context); + context = NULL; + } + syslog(LOG_INFO, "tapi already closed, stop default loop"); + uv_stop(uv_default_loop()); + } +} + +static void* run_test_loop(void* args) +{ + context = tapi_open("vela.telephony.test", on_tapi_client_ready, NULL); + if (context == NULL) { + return NULL; + } + + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + uv_loop_close(uv_default_loop()); + + return NULL; +} + +int main(int argc, char* argv[]) +{ +#ifndef CONFIG_TEST_PHONE_NUMBER + printf("Please config phone number in Kconfig!\n"); + return 0; +#endif + int ret; + + ready_done = 0; + phone_num = CONFIG_TEST_PHONE_NUMBER; + + /* initialize async handler before the thread creation + * in case we have some race issues + */ + uv_async_init(uv_default_loop(), &g_uv_exit, exit_async_cleanup); + + pthread_t thread; + pthread_attr_t attr; + struct sched_param param; + pthread_attr_init(&attr); + /* tapi main thread priority should equal to ofono thread priority */ + param.sched_priority = 100; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, 262144); + ret = pthread_create(&thread, &attr, run_test_loop, NULL); + if (ret != 0) { + syslog(LOG_ERR, "pthread_create failed with %d\n", ret); + return -1; + } + + while (!ready_done) + sleep(1); + + ready_done = 0; + count = 0; + tapi_enable_modem(get_tapi_ctx(), 0, EVENT_MODEM_ENABLE_DONE, 1, tapi_cb); + ret = wait_for_async_result("modem failed to start and cannot be tested"); + if (ret == -1) + goto do_exit; + + ready_done = 0; + count = 0; + tapi_network_register(get_tapi_ctx(), 0, MSG_VOICE_REGISTRATION_STATE_CHANGE_IND, NULL, tapi_cb); + ret = wait_for_async_result("Network connection failure, unable to perform the test."); + if (ret == -1) + goto do_exit; + + const struct CMUnitTest SimTestSuites[] = { + cmocka_unit_test(TestNuttxHasIccCard), + cmocka_unit_test(TestNuttxHasIccCardNumerousTimes), + cmocka_unit_test(TestNuttxGetSimOperatorName), + cmocka_unit_test(TestNuttxGetSimOperatorNameNumerousTimes), + cmocka_unit_test(TestNuttxGetSimOperator), + cmocka_unit_test(TestNuttxGetSimOperatorNumerousTimes), + cmocka_unit_test(TestNuttxGetSimSubscriberId), + cmocka_unit_test(TestNuttxGetSimSubscriberIdNumerousTimes), + cmocka_unit_test(TestNuttxGetIccId), + cmocka_unit_test(TestNuttxGetIccIdNumerousTimes), + cmocka_unit_test(TestNuttxGetMSISDN), + cmocka_unit_test(TestNuttxGetMSISDNNumerousTimes), + cmocka_unit_test(TestNuttxTransmitAPDUInBasicChannel), + cmocka_unit_test(TestNuttxOpenLogicalChannel), + cmocka_unit_test(TestNuttxCloseLogicalChannel), + cmocka_unit_test(TestNuttxLogicalChannelOpenCloseNumerous), + cmocka_unit_test(TestNuttxTransmitAPDUInLogicalChannel), + cmocka_unit_test(TestNuttxSetUiccEnablement), + cmocka_unit_test(TestNuttxGetUiccEnablement), + cmocka_unit_test(TestNuttxTransmitAPDUBasicChannel), + cmocka_unit_test(TestNuttxGetSimState), + cmocka_unit_test(TestNuttxEnterPin), + cmocka_unit_test(TestNuttxChangePin), + cmocka_unit_test(TestNuttxLockPin), + cmocka_unit_test(TestNuttxUnlockPin), + cmocka_unit_test(TestNuttxLoadAdnEntries), + cmocka_unit_test(TestNuttxLoadFdnEntries), + cmocka_unit_test(TestNuttxInsertFdnEntry), + cmocka_unit_test(TestNuttxUpdateFdnEntry), + cmocka_unit_test(TestNuttxDeleteFdnEntry), + }; + + const struct CMUnitTest CallTestSuites[] = { + cmocka_unit_test(TestNuttxListenCall), + cmocka_unit_test(TestNuttxDialNumber), + cmocka_unit_test(TestNuttxHangupCurrentCall), + cmocka_unit_test(TestNuttxDialEccNumber), + cmocka_unit_test(TestNuttxDialLongPhoneNumber), + cmocka_unit_test(TestNuttxDialShotPhoneNumber), + cmocka_unit_test(TestNuttxDialWithEnableHideCallId), + cmocka_unit_test(TestNuttxDialWithDisabledHideCallId), + cmocka_unit_test(TestNuttxDialWithDefaultHideCallId), + cmocka_unit_test(TestNuttxDialWithAreaCode), + cmocka_unit_test(TestNuttxDialWithPauseCode), + cmocka_unit_test(TestNuttxDialWithWaitCode), + cmocka_unit_test(TestNuttxDialWithNumerousCode), + cmocka_unit_test(TestNuttCheckAleringStatusAfterDial), + cmocka_unit_test(TestNuttxStartDtmf), + cmocka_unit_test(TestNuttxStopDtmf), + cmocka_unit_test(TestNuttxGetCallCount), + cmocka_unit_test(TestNuttxHangupAllCall), + // cmocka_unit_test(TestNuttxLoadEccList), + cmocka_unit_test(TestNuttxSetVoicecallSlot), + cmocka_unit_test(TestNuttxGetVoicecallSlot), + cmocka_unit_test(TestNuttxClearVoicecallSlotSet), + // hangup between dialing and answering + cmocka_unit_test(TestNuttxHangupBetweenDialingAndAnswering), + cmocka_unit_test(TestNuttxIncomingCallAnswerAndHangup), + cmocka_unit_test(TestNuttxIncomingCallAnswerAndRemoteHangup), + cmocka_unit_test(TestNuttxOutgoingCallRemoteAnswerAndHangup), + cmocka_unit_test(TestNuttxCallConnectAndLocalHangup), + cmocka_unit_test(TestNuttxDialAndRemoteHangup), + cmocka_unit_test(TestNuttxIncomingCallandLocalHangup), + cmocka_unit_test(TestNuttxUnlistenCall), +#if 0 + + // answer the incoming call then hangup it + cmocka_unit_test(TestNuttxAnswerAndHangupTheIncomingCall), + + // dial again after remote hangup + // cmocka_unit_test(TestNuttxDialAgainAfterRemoteHangup), + + // hangup after remote answer + cmocka_unit_test(TestNuttxHangupCallAfterRemoteAnswer), + + // dial then remote answer and hangup + // cmocka_unit_test(TestNuttxDialThenRemoteAnswerAndHangup), + + // remote hangup then incoming new call + // cmocka_unit_test(TestNuttxRemoteHangupThenIncomingNewCall), + + // remote hangup then dial another + // cmocka_unit_test(TestNuttxRemoteHangupThenDialAnother), + + // dial with numerous hide call id + cmocka_unit_test(TestNuttxDialWithNumerousHideCallId), + + // incoming new call then remote hangup + // cmocka_unit_test(TestNuttxIncomingNewCallThenRemoteHangup), + + // dial using a phone number with area code + cmocka_unit_test(TestNuttxDialWithAreaCode), +#endif + }; + + const struct CMUnitTest DataTestSuites[] = { + cmocka_unit_test(TestNuttxDataRegister), + cmocka_unit_test(TestNuttxDataUnregister), + cmocka_unit_test(TestNuttxDataRegister), + cmocka_unit_test(TestNuttxDataLoadApnContexts), + cmocka_unit_test(TestNuttxDataSaveApnContext), + cmocka_unit_test(TestNuttxDataRemoveApnContext), + cmocka_unit_test(TestNuttxDataResetApnContexts), + cmocka_unit_test(TestNuttxDataResetApnContextsRepeatedly), + cmocka_unit_test(TestNuttxDataEditApnName), + cmocka_unit_test(TestNuttxDataEditApnType), + cmocka_unit_test(TestNuttxDataEditApnProto), + cmocka_unit_test(TestNuttxDataEditApnAuth), + cmocka_unit_test(TestNuttxDataEditApnAll), + cmocka_unit_test(TestNuttxDataEditApnAndRemove), + cmocka_unit_test(TestNuttxDataEditApnAndReset), + cmocka_unit_test(TestNuttxDataEditApnRepeatedlyAndLoad), + cmocka_unit_test(TestNuttxDataResetApnContexts), + cmocka_unit_test(TestNuttxDataEnable), + cmocka_unit_test(TestNuttxDataIsEnable), + cmocka_unit_test(TestNuttxDataDisable), + cmocka_unit_test(TestNuttxDataIsDisable), + cmocka_unit_test(TestNuttxDataEnableRepeatedly), + cmocka_unit_test(TestNuttxDataEnable), + cmocka_unit_test(TestNuttxDataReleaseNetworkInternet), + cmocka_unit_test(TestNuttxDataRequestNetworkInternet), + cmocka_unit_test(TestNuttxDataReleaseNetworkInternetRepeatedly), + cmocka_unit_test(TestNuttxDataDisable), + cmocka_unit_test(TestNuttxDataRequestNetworkIms), + cmocka_unit_test(TestNuttxDataReleaseNetworkIms), + cmocka_unit_test(TestNuttxDataReleaseNetworkImsRepeatedly), + cmocka_unit_test(TestNuttxDataSaveApnContextSupl), + cmocka_unit_test(TestNuttxDataSaveApnContextEmergency), + cmocka_unit_test(TestNuttxDataResetApnContexts), + cmocka_unit_test(TestNuttxDataSetPreferredApn), + cmocka_unit_test(TestNuttxDataGetPreferredApn), + cmocka_unit_test(TestNuttxDataSendScreenState), + cmocka_unit_test(TestNuttxDataGetNetworkType), + cmocka_unit_test(TestNuttxDataIsPsAttached), + cmocka_unit_test(TestNuttxDataSetDefaultDataSlot), + cmocka_unit_test(TestNuttxDataGetDefaultDataSlot), + cmocka_unit_test(TestNuttxDataSetDataAllow), + cmocka_unit_test(TestNuttxDataGetCallList), + cmocka_unit_test(TestNuttxDataSaveLongApnContex), + cmocka_unit_test(TestNuttxDataResetApnContexts), + cmocka_unit_test(TestNuttxEnableDataRoaming), + cmocka_unit_test(TestNuttxDisableDataRoaming), + cmocka_unit_test(TestNuttxDataUnregister), + }; + + const struct CMUnitTest SmsTestSuites[] = { + cmocka_unit_test(TestNuttxListenCall), + cmocka_unit_test(TestNuttxImsListen), + cmocka_unit_test(TestNuttxImsTurnOn), + cmocka_unit_test(TestNuttxSmsSetServiceCenterNum), + cmocka_unit_test(TestNuttxSmsGetServiceCenterNum), + cmocka_unit_test(TestNuttxSmsSendShortMessageInEnglish), + cmocka_unit_test(TestNuttxSmsSendShortMessageInChinese), + cmocka_unit_test(TestNuttxSmsSendShortDataMessageInEnglish), + cmocka_unit_test(TestNuttxSmsSendShortDataMessageInChinese), + cmocka_unit_test(TestNuttxSmsSendLongMessageInEnglish), + cmocka_unit_test(TestNuttxSmsSendLongMessageInChinese), + cmocka_unit_test(TestNuttxSmsSendLongDataMessageInEnglish), + cmocka_unit_test(TestNuttxSmsSendLongDataMessageInChinese), + cmocka_unit_test(TestNuttxSmsSendShortEnglishMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendShortChineseMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendLongEnglishMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendLongChineseMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendShortEnglishDataMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendShortChineseDataMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendLongEnglishDataMessageInDialing), + cmocka_unit_test(TestNuttxSmsSendLongChineseDataMessageInDialing), + cmocka_unit_test(TestNuttxSendEnglishMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendChineseMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendLongEnglishMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendLongChineseMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendEnglishDataMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendChineseDataMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendLongEnglishDataMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxSendLongChineseDataMessageInVoiceImsCap), + cmocka_unit_test(TestNuttxImsSetSmsCap), + cmocka_unit_test(TestNuttxSendEnglishMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendChineseMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendLongEnglishMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendLongChineseMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendEnglishDataMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendChineseDataMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendLongEnglishDataMessageInSmsImsCap), + cmocka_unit_test(TestNuttxSendLongChineseDataMessageInSmsImsCap), + cmocka_unit_test(TestNuttxImsSetSmsVoiceCap), + cmocka_unit_test(TestNuttxSendEnglishMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendChineseMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendLongEnglishMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendLongChineseMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendEnglishDataMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendChineseDataMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendLongEnglishDataMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSendLongChineseDataMessageInSmsVoiceCap), + cmocka_unit_test(TestNuttxSetSmsDefaultSlot), + cmocka_unit_test(TestNuttxGetSmsDefaultSlot), + cmocka_unit_test(TestNuttxSmsSetCellBroadcastPower), + cmocka_unit_test(TestNuttxSmsGetCellBroadcastPower), + cmocka_unit_test(TestNuttxSmsSetCellBroadcastTopics), + cmocka_unit_test(TestNuttxSmsGetCellBroadcastTopics), + cmocka_unit_test(TestNuttxImsResetImsCap), + cmocka_unit_test(TestNuttxImsTurnOff), + cmocka_unit_test(TestNuttxUnlistenCall), + }; + + const struct CMUnitTest NetTestSuites[] = { + cmocka_unit_test(TestNuttxNetSelectManual), + cmocka_unit_test(TestNuttxNetSelectAuto), + cmocka_unit_test(TestNuttxNetScan), + cmocka_unit_test(TestNuttxNetGetServingCellinfos), + cmocka_unit_test(TestNuttxNetGetNeighbouringCellInfos), + cmocka_unit_test(TestNuttxNetRegistrationInfo), + cmocka_unit_test(TestNuttxNetGetOperatorName), + cmocka_unit_test(TestNuttxNetQuerySignalstrength), + // cmocka_unit_test(TestNuttxNetSetCellInfoListRate), + cmocka_unit_test(TestNuttxNetGetVoiceRegistered), + cmocka_unit_test(TestNuttxGetVoiceNwType), + cmocka_unit_test(TestNuttxGetVoiceRoaming), + }; + + const struct CMUnitTest ImsTestSuits[] = { + cmocka_unit_test(TestNuttxImsTurnOn), + cmocka_unit_test(TestNuttxImsGetRegistration), + cmocka_unit_test(TestNuttxImsGetEnabled), + cmocka_unit_test(TestNuttxImsSetServiceStatus), + cmocka_unit_test(TestNuttxImsResetImsCap), + cmocka_unit_test(TestNuttxImsTurnOff), + cmocka_unit_test(TestNuttxImsTurnOnOff), + }; + + const struct CMUnitTest SSTestSuits[] = { + cmocka_unit_test(TestNuttxSSRegister), + cmocka_unit_test(TestNuttxSSUnRegister), + cmocka_unit_test(TestNuttxRequestCallBarring), + cmocka_unit_test(TestNuttxSetCallBarring), + cmocka_unit_test(TestNuttxGetCallBarring), + cmocka_unit_test(TestNuttxChangeCallBarringPassword), + cmocka_unit_test(TestNuttxResetCallBarringPassword), + cmocka_unit_test(TestNuttxDisableAllIncoming), + cmocka_unit_test(TestNuttxDisableAllOutgoing), + cmocka_unit_test(TestNuttxDisableAllCallBarrings), + cmocka_unit_test(TestNuttxSetCallForwardingUnConditional), + cmocka_unit_test(TestNuttxGetCallForwardingUnConditional), + cmocka_unit_test(TestNuttxClearCallForwardingUnconditional), + cmocka_unit_test(TestNuttxSetCallForwardingBusy), + cmocka_unit_test(TestNuttxGetCallForwardingBusy), + cmocka_unit_test(TestNuttxClearCallForwardingBusy), + cmocka_unit_test(TestNuttxSetCallForwardingNoReply), + cmocka_unit_test(TestNuttxGetCallForwardingNoReply), + cmocka_unit_test(TestNuttxClearCallForwardingNoReply), + cmocka_unit_test(TestNuttxSetCallForwardingNotReachable), + cmocka_unit_test(TestNuttxGetCallForwardingNotReachable), + cmocka_unit_test(TestNuttxClearCallForwardingNotReachable), + cmocka_unit_test(TestNuttxEnableCallWaiting), + cmocka_unit_test(TestNuttxGetEnableCallWaiting), + cmocka_unit_test(TestNuttxDisableCallWaiting), + cmocka_unit_test(TestNuttxGetDisableCallWaiting), + cmocka_unit_test(TestNuttxEnableFdn), + cmocka_unit_test(TestNuttxGetFdnEnabled), + cmocka_unit_test(TestNuttxDisableFdn), + cmocka_unit_test(TestNuttxGetFdnDisabled), + }; + + const struct CMUnitTest CommonTestSuites[] = { + cmocka_unit_test(TestNuttxModemGetImei), + // cmocka_unit_test(TestNuttxModemSetUmtsPrefNetMode), + // cmocka_unit_test(TestNuttxModemSetGsmOnlyPrefNetMode), + // cmocka_unit_test(TestNuttxModemSetWcdmaOnlyPrefNetMode), + // cmocka_unit_test(TestNuttxModemSetLteOnlyPrefNetMode), + // cmocka_unit_test(TestNuttxModemSetLteWcdmaPrefNetMode), + // cmocka_unit_test(TestNuttxModemSetLteGsmWcdmaPrefNetMode), + cmocka_unit_test(TestNuttxModemGetPrefNetMode), + cmocka_unit_test(TestNuttxModemRegister), + cmocka_unit_test(TestNuttxModemUnregister), + cmocka_unit_test(TestNuttxModemInvokeOemShotRilRequestRaw), + cmocka_unit_test(TestNuttxModemInvokeOemLongRilRequestRaw), + cmocka_unit_test(TestNuttxModemInvokeOemNormalRilRequestRaw), + cmocka_unit_test(TestNuttxModemInvokeOemSeperateRilRequestRaw), + cmocka_unit_test(TestNuttxModemInvokeOemRilRequestATCmdStrings), + cmocka_unit_test(TestNuttxModemInvokeOemRilRequestNotATCmdStrings), + cmocka_unit_test(TestNuttxModemInvokeOemRilRequestHexStrings), + cmocka_unit_test(TestNuttxImsListen), + cmocka_unit_test(TestNuttxGetModemRevision), + cmocka_unit_test(TestNuttxModemDisable), + cmocka_unit_test(TestNuttxGetModemDsiableStatus), + cmocka_unit_test(TestNuttxModemEnableDisableRepeatedly), + cmocka_unit_test(TestNuttxModemEnable), + cmocka_unit_test(TestNuttxGetModemEnableStatus), + cmocka_unit_test(TestNuttxModemSetRadioPowerOff), + cmocka_unit_test(TestNuttxModemSetRadioPowerOnOffRepeatedly), + cmocka_unit_test(TestNuttxModemSetRadioPowerOn), + cmocka_unit_test(TestNuttxModemDisable), + + // cmocka_unit_test_setup_teardown(TestNuttxModemSetRadioPowerOnOffRepeatedly, + // setup_normal_mode, free_mode), + // // Airplane mode + // cmocka_unit_test(TestNuttxModemSetRadioPowerOff), + // // cmocka_unit_test_setup_teardown(TestNuttxImsServiceStatus, + // // setup_airplane_mode, free_mode), + // cmocka_unit_test(TestNuttxModemSetRadioPowerOn), + + // // Call dialing + // cmocka_unit_test(TestNuttxModemDialCall), + // // TODO: enable disable modem + // cmocka_unit_test(TestNuttxModemSetRadioPowerOn), + // // cmocka_unit_test_setup_teardown(TestNuttxImsServiceStatus, + // // setup_call_dialing, free_mode), + // cmocka_unit_test(TestNuttxModemHangupCall), + + // // Modem poweroff + // + // // cmocka_unit_test_setup_teardown(TestNuttxImsServiceStatus, + // // setup_modem_poweroff, free_mode), + // cmocka_unit_test_setup_teardown(TestNuttxModemSetRadioPowerOnOffRepeatedly, + // setup_modem_poweroff, free_mode), + // // FIXME: Cannot enable because of RADIO_NOT_AVAILABLE + // // cmocka_unit_test(TestNuttxModemEnable), + }; + + sleep(3); + cmocka_run_group_tests(SimTestSuites, NULL, NULL); + + cmocka_run_group_tests(CallTestSuites, NULL, NULL); + + cmocka_run_group_tests(DataTestSuites, NULL, NULL); + + cmocka_run_group_tests(SmsTestSuites, NULL, NULL); + + cmocka_run_group_tests(NetTestSuites, NULL, NULL); + + cmocka_run_group_tests(ImsTestSuits, NULL, NULL); + + cmocka_run_group_tests(SSTestSuits, NULL, NULL); + + cmocka_run_group_tests(CommonTestSuites, NULL, NULL); + +do_exit: + uv_async_send(&g_uv_exit); + + pthread_join(thread, NULL); + uv_close((uv_handle_t*)&g_uv_exit, NULL); + + return 0; +} diff --git a/test/product_telephony_test.c b/test/product_telephony_test.c new file mode 100644 index 0000000..e4b950d --- /dev/null +++ b/test/product_telephony_test.c @@ -0,0 +1,403 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "telephony_call_test.h" +#include "telephony_common_test.h" +#include "telephony_data_test.h" +#include "telephony_ims_test.h" +#include "telephony_network_test.h" +#include "telephony_sim_test.h" +#include "telephony_sms_test.h" +#include "telephony_test.h" + +#define REPEAT_TEST_MORE_FOR for (int _i = 0; _i < 10; _i++) +#define REPEAT_TEST_LESS_FOR for (int _i = 0; _i < 3; _i++) + +char* phone_num = NULL; +static uv_async_t g_uv_exit; +static int ready_done; +tapi_context context = NULL; +typedef enum { + CASE_NORMAL_MODE = 0, + CASE_AIRPLANE_MODE = 1, + CASE_CALL_DIALING = 2, + CASE_MODEM_POWEROFF = 3, +} case_type; + +int modem_status = -1; + +struct judge_type judge_data; + +static void exit_async_cleanup(uv_async_t* handle) +{ + tapi_close(context); + context = NULL; +} + +tapi_context get_tapi_ctx(void) +{ + return context; +} + +int judge(void) +{ + int timeout = TIMEOUT; + + while (timeout-- > 0) { + + if (judge_data.flag == judge_data.expect) { + if (judge_data.result != 0) + syslog(LOG_ERR, "result error\n"); + else + syslog(LOG_INFO, "result correct\n"); + + return 0; + } + + sleep(1); + syslog(LOG_INFO, "There is %d second(s) remain.\n", timeout); + } + + syslog(LOG_ERR, "judge timeout\n"); + assert(0); + return -ETIME; +} + +void judge_data_init(void) +{ + judge_data.flag = INVALID_VALUE; + judge_data.expect = INVALID_VALUE; + judge_data.result = INVALID_VALUE; +} + +static void TestNuttxDataEnable(void** state) +{ + (void)state; + int ret = data_enabled_test(0); + assert_int_equal(ret, OK); + sleep(20); +} + +static void TestNuttxDataDisable(void** state) +{ + (void)state; + int ret = data_disabled_test(0); + assert_int_equal(ret, OK); + sleep(20); +} + +static void TestNuttxDataIsEnable(void** state) +{ + (void)state; + bool enable = false; + sleep(5); + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 1); +} + +static void TestNuttxDataIsDisable(void** state) +{ + (void)state; + bool enable = true; + sleep(5); + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 0); +} + +static void TestNuttxDataRegister(void** state) +{ + (void)state; + int ret = tapi_data_listen_data_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataUnregister(void** state) +{ + (void)state; + int ret = tapi_data_unlisten_data_test(); + assert_int_equal(ret, OK); +} + +// modem +static void TestNuttxModemGetImei(void** state) +{ + (void)state; + int ret = tapi_get_imei_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetModemEnableStatus(void** state) +{ + (void)state; + int get_state = 1; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void TestNuttxGetModemDsiableStatus(void** state) +{ + (void)state; + int get_state = 0; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemEnable(void** state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 1); + assert_int_equal(ret, OK); + sleep(60); +} + +static void TestNuttxModemDisable(void** state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 0); + assert_int_equal(ret, OK); + sleep(10); +} + +static void TestNuttxModemEnableDisableRepeatedly(void** state) +{ + REPEAT_TEST_LESS_FOR + { + TestNuttxModemEnable(state); + sleep(60); + TestNuttxGetModemEnableStatus(state); + TestNuttxModemDisable(state); + sleep(60); + TestNuttxGetModemDsiableStatus(state); + } +} + +static void TestNuttxModemRegister(void** state) +{ + (void)state; + int ret = tapi_modem_register_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxModemUnregister(void** state) +{ + (void)state; + int ret = tapi_modem_unregister_test(); + assert_true(ret == OK); +} + +static void TestNuttxGetModemRevision(void** state) +{ + int ret; + ret = tapi_get_modem_revision_test(0); + assert_int_equal(ret, OK); +} + +static void modem_status_cb(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + assert(0); + return; + } + + if (result->msg_id == EVENT_MODEM_STATUS_QUERY_DONE) { + modem_status = result->arg2; + } +} + +static void on_tapi_client_ready(const char* client_name, void* user_data) +{ + if (client_name != NULL) + syslog(LOG_DEBUG, "tapi is ready for %s\n", client_name); + + ready_done = 1; + + /** + * both args is NULL, that's tapi received disconnect message + * so we here stop the default loop + */ + if (client_name == NULL && user_data == NULL) { + if (context != NULL) { + syslog(LOG_ERR, "recieve dbus disconnected msg, free tapi context"); + tapi_close(context); + context = NULL; + } + syslog(LOG_INFO, "tapi already closed, stop default loop"); + uv_stop(uv_default_loop()); + } +} + +static void TestNuttxHasIccCard(void** state) +{ + (void)state; + int ret = tapi_sim_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxHasIccCardNumerousTimes(void** state) +{ + (void)state; + int ret = tapi_sim_multi_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxNetGetOperatorName(void** state) +{ + (void)state; + int ret = tapi_net_get_operator_name_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxDataIsPsAttached(void** state) +{ + (void)state; + int ret = tapi_data_is_ps_attached_test(0); + assert_int_equal(ret, OK); +} + +static void TestNuttxListenCall(void** state) +{ + (void)state; + int ret = tapi_call_listen_call_test(0); + assert_int_equal(ret, 0); +} + +static void TestNuttxUnlistenCall(void** state) +{ + (void)state; + int ret = tapi_call_unlisten_call_test(); + assert_int_equal(ret, 0); +} + +static void TestNuttxDialCall(void** state) +{ + sleep(30); + (void)state; + int ret = tapi_call_dial_test(0, "10086", 0); + assert_int_equal(ret, 0); + sleep(30); +} + +static void TestNuttxHangupCall(void** state) +{ + (void)state; + int ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, 0); + sleep(30); +} + +static void* run_test_loop(void* args) +{ + context = tapi_open("vela.telephony.test", on_tapi_client_ready, NULL); + if (context == NULL) { + return 0; + } + + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + uv_loop_close(uv_default_loop()); + + return NULL; +} + +int main(int argc, char* argv[]) +{ +#ifndef CONFIG_TEST_PHONE_NUMBER + printf("Please config phone number in Kconfig!\n"); + return 0; +#endif + int ret; + + ready_done = 0; + phone_num = CONFIG_TEST_PHONE_NUMBER; + + /* initialize async handler before the thread creation + * in case we have some race issues + */ + uv_async_init(uv_default_loop(), &g_uv_exit, exit_async_cleanup); + + pthread_t thread; + pthread_attr_t attr; + struct sched_param param; + pthread_attr_init(&attr); + /* tapi main thread priority should equal to ofono thread priority */ + param.sched_priority = 100; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, 262144); + ret = pthread_create(&thread, &attr, run_test_loop, NULL); + if (ret != 0) { + syslog(LOG_ERR, "pthread_create failed with %d\n", ret); + return -1; + } + + while (!ready_done) + sleep(1); + + const struct CMUnitTest StabilityTestSuites[] = { + cmocka_unit_test(TestNuttxListenCall), + cmocka_unit_test(TestNuttxModemRegister), + cmocka_unit_test(TestNuttxModemUnregister), + cmocka_unit_test(TestNuttxDataRegister), + cmocka_unit_test(TestNuttxDataUnregister), + cmocka_unit_test(TestNuttxDataRegister), + cmocka_unit_test(TestNuttxModemEnable), + cmocka_unit_test(TestNuttxGetModemEnableStatus), + cmocka_unit_test(TestNuttxHasIccCard), + cmocka_unit_test(TestNuttxHasIccCardNumerousTimes), + cmocka_unit_test(TestNuttxDataIsPsAttached), + cmocka_unit_test(TestNuttxNetGetOperatorName), + cmocka_unit_test(TestNuttxModemGetImei), + cmocka_unit_test(TestNuttxGetModemRevision), + cmocka_unit_test(TestNuttxDialCall), + cmocka_unit_test(TestNuttxHangupCall), + cmocka_unit_test(TestNuttxDataEnable), + cmocka_unit_test(TestNuttxDataIsEnable), + cmocka_unit_test(TestNuttxDataDisable), + cmocka_unit_test(TestNuttxDataIsDisable), + cmocka_unit_test(TestNuttxDataUnregister), + cmocka_unit_test(TestNuttxModemDisable), + cmocka_unit_test(TestNuttxGetModemDsiableStatus), + cmocka_unit_test(TestNuttxModemEnableDisableRepeatedly), + cmocka_unit_test(TestNuttxUnlistenCall), + }; + + sleep(120); + tapi_get_modem_status(get_tapi_ctx(), 0, + EVENT_MODEM_STATUS_QUERY_DONE, modem_status_cb); + sleep(30); + if (modem_status == -1) { + assert(0); + } else if (modem_status == 1) { + tapi_data_enable_data(get_tapi_ctx(), false); + sleep(30); + tapi_enable_modem(get_tapi_ctx(), 0, + EVENT_MODEM_ENABLE_DONE, false, NULL); + sleep(60); + } + + cmocka_run_group_tests(StabilityTestSuites, NULL, NULL); + + uv_async_send(&g_uv_exit); + + pthread_join(thread, NULL); + uv_close((uv_handle_t*)&g_uv_exit, NULL); + + return 0; +} diff --git a/test/remote_operation.c b/test/remote_operation.c new file mode 100644 index 0000000..ec8023f --- /dev/null +++ b/test/remote_operation.c @@ -0,0 +1,17 @@ +#include +#include + +#include "remote_operation.h" +#include "telephony_common_test.h" + +char remote_command_buf[512]; + +void remote_call_operation(int slot_id, const char* phone_number, enum REMOTE_CALL_COMMAND_TYPE op) +{ + char* oem_req[1]; + oem_req[0] = remote_command_buf; + memset(remote_command_buf, 0, sizeof(remote_command_buf)); + sprintf(remote_command_buf, "AT+REMOTECALL=%d,0,0,%s,129", (int)op, phone_number); + tapi_invoke_oem_ril_request_strings(get_tapi_ctx(), slot_id, + EVENT_OEM_RIL_REQUEST_STRINGS_DONE, oem_req, 1, NULL); +} \ No newline at end of file diff --git a/test/remote_operation.h b/test/remote_operation.h new file mode 100644 index 0000000..282e510 --- /dev/null +++ b/test/remote_operation.h @@ -0,0 +1,8 @@ +enum REMOTE_CALL_COMMAND_TYPE { + ACTIVE_CALL = 0, + HOLD_CALL = 1, + INCOMING_CALL = 4, + REJECT_CALL = 6, +}; + +void remote_call_operation(int slot_id, const char* phone_number, enum REMOTE_CALL_COMMAND_TYPE op); \ No newline at end of file diff --git a/test/telephony_call_test.c b/test/telephony_call_test.c new file mode 100644 index 0000000..534045a --- /dev/null +++ b/test/telephony_call_test.c @@ -0,0 +1,3161 @@ +#include + +#include "remote_operation.h" +#include "telephony_call_test.h" + +extern char* phone_num; + +extern struct judge_type judge_data; + +static struct +{ + int call_state_watch_id; + int call_emergencylist_change_watch_id; + int call_ring_back_tone_change_watch_id; + int call_slot_change_watch_id; + int ss_call_barring_watch_id; + int ss_ussd_property_change_watch_id; + int ss_ussd_notification_received_watch_id; + int ss_ussd_request_received_watch_id; + int default_voicecall_slot; +} global_data; + +static struct +{ + char call_id[101]; + char network_name[101]; + unsigned int call_count; + int two_call_state_sum; + char hold_call_id[101]; + int current_call_state; +} test_case_data; + +static void test_case_data_init(void) +{ + memset(&test_case_data, 0, sizeof(test_case_data)); + test_case_data.current_call_state = -1; +} + +static int incoming_call(char* incoming_number) +{ + return 0; +} + +static int hangup_remote_call(int call_id) +{ + return 0; +} + +static void call_state_change_cb(tapi_async_result* result) +{ + tapi_call_info* call_info; + + syslog(LOG_DEBUG, "%s : %d\n", __func__, result->status); + call_info = (tapi_call_info*)result->data; + + syslog(LOG_DEBUG, "call changed call_id : %s\n", call_info->call_id); + syslog(LOG_DEBUG, "call state: %d \n", call_info->state); + syslog(LOG_DEBUG, "call LineIdentification: %s \n", call_info->lineIdentification); + syslog(LOG_DEBUG, "call IncomingLine: %s \n", call_info->incoming_line); + syslog(LOG_DEBUG, "call Name: %s \n", call_info->name); + syslog(LOG_DEBUG, "call StartTime: %s \n", call_info->start_time); + syslog(LOG_DEBUG, "call Multiparty: %d \n", call_info->multiparty); + syslog(LOG_DEBUG, "call RemoteHeld: %d \n", call_info->remote_held); + syslog(LOG_DEBUG, "call RemoteMultiparty: %d \n", call_info->remote_multiparty); + syslog(LOG_DEBUG, "call Information: %s \n", call_info->info); + syslog(LOG_DEBUG, "call Icon: %d \n", call_info->icon); + syslog(LOG_DEBUG, "call Emergency: %d \n", call_info->is_emergency_number); + syslog(LOG_DEBUG, "call disconnect_reason: %d \n\n", call_info->disconnect_reason); + + if (judge_data.expect == CALL_LOCAL_HANGUP) { + if (call_info->disconnect_reason == CALL_DISCONNECT_REASON_LOCAL_HANGUP) { + judge_data.result = 0; + } + + judge_data.flag = CALL_LOCAL_HANGUP; + } else if (judge_data.expect == CALL_STATE_CHANGE_TO_ACTIVE) { + if (call_info->state == 0) { + judge_data.result = 0; + } + + judge_data.flag = CALL_STATE_CHANGE_TO_ACTIVE; + } else if (judge_data.expect == CALL_REMOTE_HANGUP) { + if (call_info->disconnect_reason == CALL_DISCONNECT_REASON_REMOTE_HANGUP) { + judge_data.result = 0; + } + + judge_data.flag = CALL_REMOTE_HANGUP; + } else if (judge_data.expect == NEW_CALL_INCOMING + || judge_data.expect == NEW_CALL_WAITING + || judge_data.expect == INCOMING_CALL_WITH_NETWORK_NAME) { + char* call_id = call_info->call_id; + strncpy(test_case_data.call_id, call_id, strlen(call_id)); + test_case_data.call_id[strlen(call_id)] = '\0'; + + if (judge_data.expect == INCOMING_CALL_WITH_NETWORK_NAME) { + char* network_name = call_info->name; + strncpy(test_case_data.network_name, network_name, strlen(network_name)); + test_case_data.network_name[strlen(network_name)] = '\0'; + judge_data.result = 0; + judge_data.flag = INCOMING_CALL_WITH_NETWORK_NAME; + } else { + if (judge_data.expect == NEW_CALL_INCOMING && call_info->state == 4) { + judge_data.result = 0; + judge_data.flag = NEW_CALL_INCOMING; + } else if (judge_data.expect == NEW_CALL_WAITING && call_info->state == 5) { + judge_data.result = 0; + judge_data.flag = NEW_CALL_WAITING; + } + } + } else if (judge_data.expect == HANGUP_DUE_TO_NETWORK_EXCEPTION) { + if (call_info->disconnect_reason == CALL_DISCONNECT_REASON_NETWORK_HANGUP) { + judge_data.result = 0; + } + + judge_data.flag = judge_data.expect; + } else if (judge_data.expect == CALL_STATE_CHANGE_TO_HOLD) { + if (call_info->state == 1) { + judge_data.result = 0; + } + + judge_data.flag = judge_data.expect; + } else if (judge_data.expect == NEW_CALL_ALERTING) { + if (call_info->state == 3) { + judge_data.result = 0; + } + + judge_data.flag = judge_data.expect; + } +} + +static void tele_call_ecc_list_async_fun(tapi_async_result* result) +{ + int status = result->status; + int list_length = result->arg2; + ecc_info* ret = result->data; + + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "status : %d\n", status); + syslog(LOG_DEBUG, "list length: %d\n", list_length); + + if (result->status == 0) { + for (int i = 0; i < list_length; i++) { + syslog(LOG_DEBUG, "ecc number : %s,%u,%u \n", ret[i].ecc_num, ret[i].category, ret[i].condition); + } + } +} + +static void tele_call_manager_call_async_fun(tapi_async_result* result) +{ + tapi_call_info* call_info; + + syslog(LOG_DEBUG, "%s : %d\n", __func__, result->status); + if (result->status != OK) { + syslog(LOG_ERR, "async result error in %s", __func__); + return; + } + + if (result->msg_id == MSG_CALL_ADD_MESSAGE_IND) { + call_info = (tapi_call_info*)result->data; + + syslog(LOG_DEBUG, "call added call_id : %s\n", call_info->call_id); + syslog(LOG_DEBUG, "call state: %d \n", call_info->state); + syslog(LOG_DEBUG, "call LineIdentification: %s \n", call_info->lineIdentification); + syslog(LOG_DEBUG, "call IncomingLine: %s \n", call_info->incoming_line); + syslog(LOG_DEBUG, "call Name: %s \n", call_info->name); + syslog(LOG_DEBUG, "call StartTime: %s \n", call_info->start_time); + syslog(LOG_DEBUG, "call Multiparty: %d \n", call_info->multiparty); + syslog(LOG_DEBUG, "call RemoteHeld: %d \n", call_info->remote_held); + syslog(LOG_DEBUG, "call RemoteMultiparty: %d \n", call_info->remote_multiparty); + syslog(LOG_DEBUG, "call Information: %s \n", call_info->info); + syslog(LOG_DEBUG, "call Icon: %d \n", call_info->icon); + syslog(LOG_DEBUG, "call Emergency: %d \n\n", call_info->is_emergency_number); + + } else if (result->msg_id == MSG_CALL_REMOVE_MESSAGE_IND) { + syslog(LOG_DEBUG, "call removed call_id : %s\n", (char*)result->data); + } else if (result->msg_id == MSG_CALL_RING_BACK_TONE_IND) { + syslog(LOG_DEBUG, "ring back tone status : %d\n", result->arg2); + } else if (result->msg_id == MSG_CALL_FORWARDED_MESSAGE_IND) { + syslog(LOG_DEBUG, "call Forwarded: %s\n", (char*)result->data); + } else if (result->msg_id == MSG_CALL_BARRING_ACTIVE_MESSAGE_IND) { + syslog(LOG_DEBUG, "call BarringActive: %s\n", (char*)result->data); + } else if (result->msg_id == MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND) { + if (judge_data.expect == MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND) { + syslog(LOG_DEBUG, "default voicecall slot: %d\n", result->arg2); + judge_data.result = OK; + global_data.default_voicecall_slot = result->arg2; + judge_data.flag = MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND; + } + } +} + +int tapi_call_listen_call_test(int slot_id) +{ + global_data.call_state_watch_id = -1; + global_data.call_state_watch_id = tapi_call_register_call_state_change( + get_tapi_ctx(), slot_id, NULL, call_state_change_cb); + + if (global_data.call_state_watch_id < 0) { + syslog(LOG_ERR, "%s, call state change registered fail, ret: %d", + __func__, global_data.call_state_watch_id); + return -1; + } + + global_data.call_emergencylist_change_watch_id = -1; + global_data.call_emergencylist_change_watch_id = tapi_call_register_emergency_list_change( + get_tapi_ctx(), slot_id, NULL, tele_call_ecc_list_async_fun); + + if (global_data.call_emergencylist_change_watch_id < 0) { + syslog(LOG_ERR, "%s, emergency list change registered fail, ret: %d", + __func__, global_data.call_emergencylist_change_watch_id); + return -1; + } + + global_data.call_ring_back_tone_change_watch_id = -1; + global_data.call_ring_back_tone_change_watch_id = tapi_call_register_ringback_tone_change( + get_tapi_ctx(), slot_id, NULL, tele_call_manager_call_async_fun); + + if (global_data.call_ring_back_tone_change_watch_id < 0) { + syslog(LOG_ERR, "%s, ring back change registered fail, ret: %d", + __func__, global_data.call_ring_back_tone_change_watch_id); + return -1; + } + + global_data.call_slot_change_watch_id = -1; + global_data.call_slot_change_watch_id = tapi_call_register_default_voicecall_slot_change( + get_tapi_ctx(), NULL, tele_call_manager_call_async_fun); + if (global_data.call_slot_change_watch_id < 0) { + syslog(LOG_ERR, "%s, voicecall slot change registered fail, ret: %d", + __func__, global_data.call_slot_change_watch_id); + return -1; + } + + return 0; +} + +static void tele_call_async_fun(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + int event = result->msg_id; + int status = result->status; + + switch (event) { + case EVENT_REQUEST_DIAL_DONE: + syslog(LOG_DEBUG, "%s: EVENT_REQUEST_DIAL_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_REQUEST_DIAL_DONE) { + judge_data.result = status; + char* call_id = (char*)result->data; + strncpy(test_case_data.call_id, call_id, strlen(call_id)); + test_case_data.call_id[strlen(call_id)] = '\0'; + judge_data.flag = EVENT_REQUEST_DIAL_DONE; + } + break; + case EVENT_REQUEST_START_DTMF_DONE: + syslog(LOG_DEBUG, "%s: EVENT_REQUEST_START_DTMF_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_REQUEST_START_DTMF_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_REQUEST_START_DTMF_DONE; + } + break; + case EVENT_REQUEST_STOP_DTMF_DONE: + syslog(LOG_DEBUG, "%s: EVENT_REQUEST_STOP_DTMF_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_REQUEST_STOP_DTMF_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_REQUEST_STOP_DTMF_DONE; + } + break; + default: + break; + } +} + +static void ss_signal_change(tapi_async_result* result) +{ + tapi_call_barring_info* cb_value; + int signal = result->msg_id; + int slot_id = result->arg1; + + switch (signal) { + case MSG_CALL_BARRING_PROPERTY_CHANGE_IND: + cb_value = result->data; + syslog(LOG_DEBUG, "call barring service %s changed to %s in slot[%d] \n", + cb_value->service_type, cb_value->value, slot_id); + break; + case MSG_USSD_PROPERTY_CHANGE_IND: + syslog(LOG_DEBUG, "ussd state changed to %s in slot[%d] \n", (char*)result->data, slot_id); + break; + case MSG_USSD_NOTIFICATION_RECEIVED_IND: + syslog(LOG_DEBUG, "ussd notification message %s received in slot[%d] \n", + (char*)result->data, slot_id); + break; + case MSG_USSD_REQUEST_RECEIVED_IND: + syslog(LOG_DEBUG, "ussd request message %s received in slot[%d] \n", + (char*)result->data, slot_id); + break; + default: + break; + } +} + +int tapi_ss_listen_test(int slot_id) +{ + global_data.ss_call_barring_watch_id = -1; + global_data.ss_call_barring_watch_id = tapi_ss_register(get_tapi_ctx(), + slot_id, 47, NULL, ss_signal_change); + + if (global_data.ss_call_barring_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", + __func__, slot_id); + return -1; + } + + global_data.ss_ussd_property_change_watch_id = -1; + global_data.ss_ussd_property_change_watch_id = tapi_ss_register(get_tapi_ctx(), + slot_id, 50, NULL, ss_signal_change); + + if (global_data.ss_ussd_property_change_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", + __func__, slot_id); + return -1; + } + + global_data.ss_ussd_notification_received_watch_id = -1; + global_data.ss_ussd_notification_received_watch_id = tapi_ss_register(get_tapi_ctx(), + slot_id, 48, NULL, ss_signal_change); + + if (global_data.ss_ussd_notification_received_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", + __func__, slot_id); + return -1; + } + + global_data.ss_ussd_request_received_watch_id = -1; + global_data.ss_ussd_request_received_watch_id = tapi_ss_register(get_tapi_ctx(), + slot_id, 49, NULL, ss_signal_change); + + if (global_data.ss_ussd_request_received_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", + __func__, slot_id); + return -1; + } + + return 0; +} + +int tapi_ss_unlisten_test(void) +{ + if (global_data.ss_call_barring_watch_id < 0 || global_data.ss_ussd_notification_received_watch_id < 0 || global_data.ss_ussd_property_change_watch_id < 0 || global_data.ss_ussd_request_received_watch_id < 0) + return -1; + + int ret = -1, res = 0; + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ss_call_barring_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister ss call barring change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ss_ussd_notification_received_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister ss ussd notification received change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ss_ussd_property_change_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister ss ussd property change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ss_ussd_request_received_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister ss ussd request received change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_listen_error_code_test(int slot_id) +{ + int ret1 = tapi_ss_register(get_tapi_ctx(), + slot_id, 46, NULL, ss_signal_change); + + int ret2 = tapi_ss_register(get_tapi_ctx(), + slot_id, 52, NULL, ss_signal_change); + + return ret1 >= 0 || ret2 >= 0; +} + +int tapi_call_dial_test(int slot_id, char* phone_number, int hide_caller_id) +{ + int res = 0; + test_case_data_init(); + judge_data_init(); + judge_data.expect = EVENT_REQUEST_DIAL_DONE; + int ret = tapi_call_dial(get_tapi_ctx(), slot_id, + phone_number, hide_caller_id, EVENT_REQUEST_DIAL_DONE, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_call_dial_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_hanup_current_call_test(int slot_id) +{ + syslog(LOG_DEBUG, "%s called, current call id: %s\n", + __func__, test_case_data.call_id); + + if (test_case_data.call_id[0] == 0) { + syslog(LOG_DEBUG, "no call to hanup\n"); + return -1; + } + + int res = 0; + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret = tapi_call_hangup_by_id(get_tapi_ctx(), slot_id, test_case_data.call_id); + + if (ret) { + syslog(LOG_ERR, "tapi_call_hanup_current_call_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_call_hanup_current_call_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_unlisten_call_test(void) +{ + int ret = -1, res = 0; + ret = tapi_unregister(get_tapi_ctx(), global_data.call_state_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister call state change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), global_data.call_emergencylist_change_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister emergency list change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), global_data.call_ring_back_tone_change_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister ring back tone change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void call_list_query_complete(tapi_async_result* result) +{ + tapi_call_info* call_info; + + syslog(LOG_DEBUG, "%s : \n", __func__); + if (result->status != OK) + return; + + syslog(LOG_DEBUG, "call count: %d \n\n", result->arg2); + if (judge_data.expect == GET_ALL_CALLS) { + judge_data.result = 0; + test_case_data.call_count = result->arg2; + judge_data.flag = judge_data.expect; + } else if (judge_data.expect == GET_TWO_CALL_STATES) { + judge_data.result = 0; + test_case_data.two_call_state_sum = 0; + judge_data.flag = judge_data.expect; + } + + call_info = result->data; + + for (int i = 0; i < result->arg2; i++) { + + test_case_data.two_call_state_sum += call_info[i].state; + + if (judge_data.expect == GET_HOLD_CALL_ID) { + if (call_info[i].state == 1) { + char* hold_call_id = call_info[i].call_id; + strncpy(test_case_data.hold_call_id, hold_call_id, strlen(hold_call_id)); + test_case_data.hold_call_id[strlen(hold_call_id)] = '\0'; + judge_data.result = 0; + judge_data.flag = judge_data.expect; + } + } + + if (judge_data.expect == GET_CURRENT_CALL_STATE) { + test_case_data.current_call_state = call_info[i].state; + judge_data.result = 0; + judge_data.flag = judge_data.expect; + } + + syslog(LOG_DEBUG, "call id: %s \n", call_info[i].call_id); + syslog(LOG_DEBUG, "call state: %d \n", call_info[i].state); + syslog(LOG_DEBUG, "call LineIdentification: %s \n", call_info[i].lineIdentification); + syslog(LOG_DEBUG, "call IncomingLine: %s \n", call_info[i].incoming_line); + syslog(LOG_DEBUG, "call Name: %s \n", call_info[i].name); + syslog(LOG_DEBUG, "call StartTime: %s \n", call_info[i].start_time); + syslog(LOG_DEBUG, "call Multiparty: %d \n", call_info[i].multiparty); + syslog(LOG_DEBUG, "call RemoteHeld: %d \n", call_info[i].remote_held); + syslog(LOG_DEBUG, "call RemoteMultiparty: %d \n", call_info[i].remote_multiparty); + syslog(LOG_DEBUG, "call Information: %s \n", call_info[i].info); + syslog(LOG_DEBUG, "call Icon: %d \n", call_info[i].icon); + syslog(LOG_DEBUG, "call Emergency: %d \n\n", call_info[i].is_emergency_number); + } +} + +int tapi_get_call_count(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = GET_ALL_CALLS; + test_case_data.call_count = 0; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, call_list_query_complete); + + if (ret) { + syslog(LOG_ERR, "tapi_get_call_count execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_get_call_count is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + return test_case_data.call_count; + +on_exit: + return res; +} + +static int tapi_get_two_call_state(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = GET_TWO_CALL_STATES; + test_case_data.two_call_state_sum = -22; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, call_list_query_complete); + + if (ret) { + syslog(LOG_ERR, "tapi_get_two_call_state execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_get_two_call_state is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + return test_case_data.two_call_state_sum; + +on_exit: + return res; +} + +static char* get_hold_call_id(int slot_id) +{ + judge_data_init(); + judge_data.expect = GET_HOLD_CALL_ID; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, call_list_query_complete); + + if (ret) { + syslog(LOG_ERR, "get_hold_call_id execute fail in %s, ret: %d", + __func__, ret); + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "get_hold_call_id is not executed in %s", __func__); + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + goto on_exit; + } + + return test_case_data.hold_call_id; + +on_exit: + return NULL; +} + +static int get_current_call_state_test(int slot_id) +{ + int res = 0; + test_case_data.current_call_state = -2; + judge_data_init(); + judge_data.expect = GET_CURRENT_CALL_STATE; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, call_list_query_complete); + + if (ret) { + syslog(LOG_ERR, "get_current_call_state_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "get_current_call_state_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + return test_case_data.current_call_state; + +on_exit: + return res; +} + +int tapi_call_hangup_all_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret = tapi_call_hangup_all_calls(get_tapi_ctx(), slot_id); + + if (ret) { + syslog(LOG_ERR, "tapi_call_hangup_all_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_call_hangup_all_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_dial_using_phone_number_with_area_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "02510086", 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_call_dial_using_phone_number_with_pause_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "10086,001", 0); + return ret; +} + +int tapi_call_dial_using_phone_number_with_wait_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "10086;001", 0); + return ret; +} + +int tapi_call_dial_using_phone_number_with_numerous_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "10086,001;001", 0); + return ret; +} + +int tapi_call_load_ecc_list_test(int slot_id) +{ + ecc_info out[MAX_ECC_LIST_SIZE]; + int size = tapi_call_get_ecc_list(get_tapi_ctx(), slot_id, out); + + if (size <= 0) + return -1; + + int ret = 0; + syslog(LOG_INFO, "ecc list: \n"); + + for (int i = 0; i < size; i++) { + syslog(LOG_DEBUG, "ecc number : %s,%u,%u \n", out[i].ecc_num, out[i].category, out[i].condition); + } + + char* correct_ecc_list_with_sim_card[] = { "110", "119", "120", "118", "999", "000", "08", "911", "112" }; + char* correct_ecc_list_without_sim_card[] = { "119", "118", "999", "110", "08", "000" }; + char* error_ecc_list[] = { "0", "07", "234" }; + + bool has_sim_card = false; + tapi_sim_has_icc_card(get_tapi_ctx(), 0, &has_sim_card); + + if (has_sim_card) { + for (int i = 0; i < sizeof(correct_ecc_list_with_sim_card) / sizeof(char*); i++) { + if (tapi_call_is_emergency_number(get_tapi_ctx(), correct_ecc_list_with_sim_card[i]) == -1) { + syslog(LOG_ERR, "%s is not in ecc list\n", correct_ecc_list_with_sim_card[i]); + ret |= -1; + } + } + } else { + for (int i = 0; i < sizeof(correct_ecc_list_without_sim_card) / sizeof(char*); i++) { + if (tapi_call_is_emergency_number( + get_tapi_ctx(), correct_ecc_list_without_sim_card[i]) + == -1) { + syslog(LOG_ERR, "%s is not in ecc list\n", correct_ecc_list_without_sim_card[i]); + ret |= -1; + } + } + } + + for (int i = 0; i < sizeof(error_ecc_list) / sizeof(char*); i++) { + if (tapi_call_is_emergency_number(get_tapi_ctx(), error_ecc_list[i]) != -1) { + syslog(LOG_ERR, "%s is not emergency number\n", error_ecc_list[i]); + ret |= -1; + } + } + + return ret; +} + +int tapi_call_set_default_voicecall_slot_test(int slot_id) +{ + int res = 0; + judge_data_init(); + global_data.default_voicecall_slot = -100; + judge_data.expect = MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND; + + int ret = tapi_call_set_default_slot(get_tapi_ctx(), slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_call_set_default_slot execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_call_manager_call_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.default_voicecall_slot != slot_id) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_get_default_voicecall_slot_test(int expect_res) +{ + int result = -1; + int ret = tapi_call_get_default_slot(get_tapi_ctx(), &result); + syslog(LOG_DEBUG, "%s, ret: %d, voicecall_slot: %d", __func__, ret, result); + + return ret || expect_res != result; +} + +int tapi_call_answer_call_test(int slot_id, char* call_id) +{ + + if (test_case_data.call_id[0] == 0) { + syslog(LOG_ERR, "current call id is NULL\n"); + return -1; + } + + int res = 0; + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret = tapi_call_answer_by_id(get_tapi_ctx(), slot_id, call_id); + + if (ret) { + syslog(LOG_ERR, "tapi_call_answer_call_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_call_answer_call_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int call_check_alerting_status(void) +{ + int res = 0; + judge_data_init(); + judge_data.expect = NEW_CALL_ALERTING; + + if (judge()) { + syslog(LOG_DEBUG, "call_check_status is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int call_check_alerting_status_after_dial(int slot_id) +{ + int ret1 = tapi_call_dial_test(slot_id, phone_num, 0); + + int ret2 = call_check_alerting_status(); + syslog(LOG_INFO, "%s, ret1 : %d ret2 : %d \n", __func__, ret1, ret2); + + if (ret1 != 0 || ret2 != 0) { + return -1; + } + + return 0; +} + +int call_dial_after_caller_reject(int slot_id) +{ + int ret1, ret2, ret3, ret4, ret5; + ret1 = ret2 = ret3 = ret4 = ret5 = -1; + + for (int i = 0; i < 5; ++i) { + ret1 = tapi_call_listen_call_test(slot_id); + ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if (judge() || judge_data.result || ret1 || ret2) + goto error; + + ret3 = tapi_call_dial_test(slot_id, phone_num, 0); + ret4 = tapi_call_hanup_current_call_test(slot_id); + ret5 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4 || ret5) != 0) { + goto error; + } + } + + return 0; + +error: + if (tapi_get_call_count(slot_id)) { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_hangup_after_caller_answer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + int ret4 = tapi_call_hanup_current_call_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + if ((ret4 || ret5) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int outgoing_call_remote_answer_and_hangup(int slot_id) +{ + int res = 0; + if (tapi_call_dial_test(slot_id, phone_num, 0) < 0) { + syslog(LOG_ERR, "dail fail in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + remote_call_operation(slot_id, phone_num, ACTIVE_CALL); + if (judge()) { + syslog(LOG_ERR, "No active call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + remote_call_operation(slot_id, phone_num, REJECT_CALL); + if (judge()) { + syslog(LOG_ERR, "No hangup call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int call_dial_caller_reject_and_incoming(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + incoming_call("10010"); + + if (judge() || judge_data.result) + goto error; + + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_dial_caller_reject_and_dial_another(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + int ret3 = tapi_call_dial_test(slot_id, "10001", 0); + int ret4 = tapi_call_hanup_current_call_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4 || ret5) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_hangup_between_dialing_and_answering(int slot_id) +{ + int res = 0; + int ret = tapi_call_dial_test(slot_id, phone_num, 0); + if (ret) { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_call_hanup_current_call_test(slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_call_hanup_current_call_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int call_clear_voicecall_slot_set(void) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND; + global_data.default_voicecall_slot = -100; + int ret = tapi_call_set_default_voicecall_slot_test(-1); + + if (ret) { + syslog(LOG_ERR, "tapi_call_set_default_voicecall_slot_test execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_call_manager_call_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.default_voicecall_slot != -1) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +// todo +int call_dial_to_phone_in_call(int slot_id) +{ + // todo: caller in process + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +// todo +int call_dial_to_phone_out_of_service(int slot_id) +{ + // todo: caller out of service + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +// todo +int call_dial_without_sim_card(int slot_id) +{ + // todo: pull out the sim card + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +// todo +int call_dial_ecc_number_without_sim_card(int slot_id) +{ + // todo: pull out the sim card + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, "911", 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +// todo +int call_dial_to_empty_number(int slot_id) +{ + char* empty_phone_number = "123456"; + + // todo: 123456 is empty phone number + + int ret1 = tapi_call_listen_call_test(slot_id); + + if (ret1 != 0) + return -1; + + int ret2 = tapi_call_dial_test(slot_id, empty_phone_number, 0); + + if (ret2 == 0) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +int tapi_dial_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_dial_ecc_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "911", 0); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + return ret; +} + +int tapi_dial_with_long_phone_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "167101398140", 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_dial_with_short_phone_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "11", 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_dial_with_enable_hide_callerid(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 1); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_dial_with_disabled_hide_callerid(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 2); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_dial_with_default_hide_callerid(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, ret); + return ret; +} + +int tapi_start_dtmf_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_START_DTMF_DONE; + int ret = tapi_call_start_dtmf(get_tapi_ctx(), slot_id, '0', EVENT_REQUEST_START_DTMF_DONE, + tele_call_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_start_dtmf_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_start_dtmf_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_stop_dtmf_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_STOP_DTMF_DONE; + int ret = tapi_call_stop_dtmf(get_tapi_ctx(), slot_id, EVENT_REQUEST_STOP_DTMF_DONE, + tele_call_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_stop_dtmf_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_stop_dtmf_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +// todo: unsolicited message error, need gaojiawei fix +int call_incoming_and_hangup_by_dialer_before_answer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + incoming_call("10010"); + + if ((judge() || ret1 || judge_data.result) != 0) + goto error; + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if (judge() != 0) + goto error; + + int ret2 = tapi_call_unlisten_call_test(); + + if ((ret2 || judge_data.result) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_incoming_and_hangup_by_dialer_before_answer_numerous(int slot_id) +{ + for (int i = 0; i < 5; i++) { + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call from different phone number + + if (judge() != 0) + return -1; + + if ((ret1 || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + // todo: dialer hangup + + if (judge() != 0) + return -1; + + int ret2 = tapi_call_unlisten_call_test(); + + if ((ret2 || judge_data.result) != 0) + return -1; + } + + return 0; +} + +int incoming_call_answer_and_hangup(int slot_id) +{ + int res = 0; + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + remote_call_operation(slot_id, phone_num, INCOMING_CALL); + if (judge()) { + syslog(LOG_ERR, "No incoming call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) < 0) { + syslog(LOG_ERR, "Answer call fail in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + if (tapi_call_hanup_current_call_test(slot_id) < 0) { + syslog(LOG_ERR, "Hangup call fail in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int incoming_call_answer_and_remote_hangup(int slot_id) +{ + int res = 0; + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + remote_call_operation(slot_id, phone_num, INCOMING_CALL); + if (judge()) { + syslog(LOG_ERR, "No incoming call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) < 0) { + syslog(LOG_ERR, "Answer call fail in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + remote_call_operation(slot_id, phone_num, REJECT_CALL); + if (judge()) { + syslog(LOG_ERR, "No incoming call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +// todo +int call_display_the_network_of_incoming_call(int slot_id, char* network_name) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = INCOMING_CALL_WITH_NETWORK_NAME; + + // todo: incoming call with network name + + if (judge() != 0) + return -1; + + int ret2 = strncmp(network_name, + test_case_data.network_name, + strlen(test_case_data.network_name) + 1); + + if ((ret1 || ret2 || judge_data.result) != 0) + return -1; + + if (test_case_data.call_id[0] != '\0') { + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4) != 0) + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +// todo +int call_display_the_network_of_incoming_call_in_call_process(int slot_id, + char* network_name) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = INCOMING_CALL_WITH_NETWORK_NAME; + + // todo: incoming call with network name + + if ((judge() || ret2 || judge_data.result) != 0) + return -1; + + int ret3 = strncmp(network_name, + test_case_data.network_name, + strlen(test_case_data.network_name) + 1); + + if (ret3 != 0) + return -1; + + if (tapi_get_call_count(slot_id) != 0) { + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + if ((ret4 || ret5) != 0) + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +// todo +int call_dial_active_hangup_due_to_dialer_network_exception(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: caller answer + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = HANGUP_DUE_TO_NETWORK_EXCEPTION; + + // todo: hangup due to dialer network exception + + if ((judge() || judge_data.result) != 0) { + if (tapi_get_call_count(slot_id) != 0) + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +// todo +int call_dial_active_hangup_due_to_caller_network_exception(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: caller answer + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = HANGUP_DUE_TO_NETWORK_EXCEPTION; + + // todo: hangup due to caller network exception + + if ((judge() || judge_data.result) != 0) { + if (tapi_get_call_count(slot_id) != 0) + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +// todo 30 +int call_check_status_in_dialing(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + + int call_state = get_current_call_state_test(slot_id); + + if ((ret1 || ret2) != 0 + || call_state != CALL_STATUS_DIALING) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo 31 +int call_dial_and_check_status_in_call_process(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: caller answer + + if ((ret1 || ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + int call_state = get_current_call_state_test(slot_id); + + if (call_state != CALL_STATUS_ACTIVE) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo 32 +int call_incoming_answer_and_check_status_in_call_process(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if (ret2 || call_state != CALL_STATUS_ACTIVE) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo 33 +int call_check_status_in_incoming(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if (call_state != CALL_STATUS_INCOMING) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo 34 +int call_incoming_answer_caller_hold_and_check_status(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + int ret3 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if ((ret2 || ret3) != 0 || call_state != CALL_STATUS_HELD) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 35 +int call_incoming_answer_dialer_hold_and_check_status(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + + // todo: dialer hold + + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if (ret2 != 0 || call_state != CALL_STATUS_HELD) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo: 36 +int call_check_call_status_in_multi_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: another incoming call + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_hold_and_answer(get_tapi_ctx(), slot_id); + + if ((judge() || ret3 || judge_data.result) != 0) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 37 +int call_check_call_status_in_call_waiting_with_multi_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: another incoming call + + if ((ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 + || tapi_get_two_call_state(slot_id) != 5) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo: 38 +int call_check_call_status_in_dialing_with_multi_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + int ret3 = tapi_call_dial_test(slot_id, phone_num, 0); + + if ((ret2 || ret3 || judge()) != 0) + return -1; + + sleep(5); + + if (tapi_get_call_count(slot_id) != 2 + || tapi_get_two_call_state(slot_id) != 3) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 39 +int call_hold_old_call_incoming_new_call_and_check_status(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret3 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || ret3 || judge() || judge_data.result) != 0) + return -1; + + judge_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: another incoming call + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 2 + || tapi_get_two_call_state(slot_id) != 5) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 42 +int call_incoming_hangup_first_answer_second(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + char old_call_id[101]; + strncpy(old_call_id, test_case_data.call_id, strlen(test_case_data.call_id) + 1); + + sleep(5); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if ((judge() || judge_data.result) != 0) + return -1; + + char new_call_id[101]; + strncpy(new_call_id, test_case_data.call_id, strlen(test_case_data.call_id) + 1); + + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret2 = tapi_call_hangup_by_id(get_tapi_ctx(), slot_id, old_call_id); + + if ((judge() || ret2 || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, new_call_id) != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo: 43 +int call_release_and_answer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret2 = tapi_call_release_and_answer(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo: 44 +int call_incoming_hold_and_recover_by_dialer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + sleep(5); + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + + // todo: dialer hold + + if ((ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: dialer active + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo: 45 +int call_dialer_hold_recover_and_hold_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: caller answer + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret3 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret3 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret4 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret4 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + + // todo: caller hold + + if ((judge() || judge_data.result) != 0) + return -1; + + int ret5 = tapi_call_hangup_all_test(slot_id); + int ret6 = tapi_call_unlisten_call_test(); + + return ret5 || ret6; +} + +// todo: 47 +int call_incoming_hold_and_recover_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + sleep(5); + + for (int i = 0; i < 3; i++) { + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret3 || judge() || judge_data.result) != 0) + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 48 +int call_hold_and_hangup(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +// todo: 49 +int call_swap_dial_reject_swap(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + // todo: caller reject + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 50 +int call_hold_incoming_answer_hangup_second_recover_first(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 51 +int call_incoming_second_call_swap_answer_hangup_swap(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 52 +int call_hold_current_call_and_reject_new_incoming(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 53 +int call_incoming_and_hangup_new_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming new call + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(10); + + if (tapi_get_call_count(slot_id) != 1) + return -1; + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo: 54 +int call_hold_first_call_and_answer_second_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming new call + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret2 = tapi_call_hold_and_answer(get_tapi_ctx(), slot_id); + int ret3 = tapi_get_two_call_state(slot_id); + + if ((judge() || judge_data.result || ret2 || ret3) != 0) + return -1; + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 55 +int call_dial_second_call_active_and_hangup_by_dialer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: caller answer + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 1 + || get_current_call_state_test(slot_id) != CALL_STATUS_ACTIVE) + return -1; + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo: 56 +int call_dial_second_call_and_hangup_by_caller_before_answering(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + // todo caller reject + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(5); + + if (tapi_get_call_count(slot_id) != 1 + || get_current_call_state_test(slot_id) != CALL_STATUS_ACTIVE) + return -1; + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo: 57 +int call_dial_second_call_active_and_hangup_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(10); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo: caller answer + + if (judge() || judge_data.result) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + // todo: caller hangup + + if (judge() || judge_data.result) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 1) + return -1; + + sleep(5); + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo: 58 +int call_hangup_hold_call_in_two_calls(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + // todo caller answer + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_get_call_count(slot_id) != 2) + return -1; + char* hold_call_id = get_hold_call_id(slot_id); + + if (hold_call_id == NULL) + return -1; + + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret3 = tapi_call_hangup_by_id(get_tapi_ctx(), slot_id, hold_call_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 1) + return -1; + + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 59 +int call_swap_in_two_calling(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || judge() || judge_data.result) != 0) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + char old_call_id[101]; + char* call_id = get_hold_call_id(slot_id); + + if (call_id == NULL) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + strncpy(old_call_id, call_id, strlen(call_id) + 1); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret3 || judge() || judge_data.result) != 0) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + call_id = get_hold_call_id(slot_id); + + if (call_id == NULL) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (strncmp(old_call_id, call_id, strlen(call_id) + 1) == 0) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 60 +int call_hangup_current_call_and_recover_hold_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hanup_current_call_test(slot_id); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || ret3 || judge() || judge_data.result) != 0) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +// todo: 61 +int call_hangup_all_call_in_two_calling(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + if ((judge() || judge_data.result) != 0) + return -1; + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo: 62 +int incoming_new_call_in_calling_and_hangup_all_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + + if ((judge() || judge_data.result) != 0) + return -1; + sleep(10); + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 5) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +// todo: 63 +int call_dial_third_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + // todo: incoming call + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + // todo: incoming another call + if ((judge() || judge_data.result) != 0) + return -1; + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || tapi_get_two_call_state(slot_id) != 1) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + if (!ret2) { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +int call_connect_and_local_hangup(int slot_id) +{ + int res = 0; + if (tapi_call_dial_test(slot_id, phone_num, 0) < 0) { + syslog(LOG_ERR, "dail fail in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + remote_call_operation(slot_id, phone_num, ACTIVE_CALL); + if (judge()) { + syslog(LOG_ERR, "No active call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + + if (tapi_call_hanup_current_call_test(slot_id) < 0) { + syslog(LOG_ERR, "local hangup fail in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int dial_and_remote_hangup(int slot_id) +{ + int res = 0; + if (tapi_call_dial_test(slot_id, phone_num, 0) < 0) { + syslog(LOG_ERR, "dail fail in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + remote_call_operation(slot_id, phone_num, REJECT_CALL); + if (judge()) { + syslog(LOG_ERR, "No hangup call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int incoming_call_and_local_hangup(int slot_id) +{ + int res = 0; + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + remote_call_operation(slot_id, phone_num, INCOMING_CALL); + if (judge()) { + syslog(LOG_ERR, "No incoming call message received in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "Unsolicited message error in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + if (tapi_call_hanup_current_call_test(slot_id) < 0) { + syslog(LOG_ERR, "Hangup call fail in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +// 67 +int call_listen_and_unlisten_ss(int slot_id) +{ + int ret1 = tapi_ss_listen_test(slot_id); + int ret2 = tapi_ss_unlisten_test(); + + return ret1 || ret2; +} + +// 68 +int call_listen_error_ss_code(int slot_id) +{ + return tapi_ss_listen_error_code_test(slot_id); +} + +void set_callback_data(int expect) +{ + judge_data_init(); + judge_data.expect = expect; +} + +int judge_callback_result(void) +{ + if ((judge() || judge_data.result) != 0) + return -1; + + return 0; +} + +void incoming_first_call(void) +{ + test_case_data_init(); + set_callback_data(NEW_CALL_INCOMING); +} + +void incoming_another_call(void) +{ + test_case_data_init(); + set_callback_data(NEW_CALL_WAITING); +} \ No newline at end of file diff --git a/test/telephony_call_test.h b/test/telephony_call_test.h new file mode 100644 index 0000000..8dee88c --- /dev/null +++ b/test/telephony_call_test.h @@ -0,0 +1,117 @@ +#ifndef TELEPHONY_CALL_TEST_H_ +#define TELEPHONY_CALL_TEST_H_ + +#include "telephony_test.h" +#include + +#define CALL_LOCAL_HANGUP 0x01 +#define CALL_STATE_CHANGE_TO_ACTIVE 0x02 +#define CALL_REMOTE_HANGUP 0x03 +#define NEW_CALL_INCOMING 0x04 +#define INCOMING_CALL_WITH_NETWORK_NAME 0x05 +#define HANGUP_DUE_TO_NETWORK_EXCEPTION 0x06 +#define CALL_STATE_CHANGE_TO_HOLD 0x07 +#define GET_ALL_CALLS 0x08 +#define GET_TWO_CALL_STATES 0x09 +#define GET_HOLD_CALL_ID 0x10 +#define GET_CURRENT_CALL_STATE 0x11 +#define NEW_CALL_WAITING 0x12 +#define NEW_CALL_DIALING 0x13 +#define NEW_CALL_ALERTING 0x14 +#define EVENT_REQUEST_START_DTMF_DONE 0x15 +#define EVENT_REQUEST_STOP_DTMF_DONE 0x16 + +int tapi_call_listen_call_test(int slot_id); +int tapi_call_dial_test(int slot_id, char* phone_number, int hide_caller_id); +int tapi_call_hanup_current_call_test(int slot_id); +int tapi_call_hangup_all_test(int slot_id); +int tapi_call_unlisten_call_test(void); +int tapi_call_dial_using_phone_number_with_area_code_test(int slot_id); +int tapi_call_dial_using_phone_number_with_pause_code_test(int slot_id); +int tapi_call_dial_using_phone_number_with_wait_code_test(int slot_id); +int tapi_call_dial_using_phone_number_with_numerous_code_test(int slot_id); +int tapi_dial_number(int slot_id); +int tapi_dial_ecc_number(int slot_id); +int tapi_dial_with_enable_hide_callerid(int slot_id); +int tapi_dial_with_disabled_hide_callerid(int slot_id); +int tapi_dial_with_default_hide_callerid(int slot_id); +int tapi_dial_with_long_phone_number(int slot_id); +int tapi_dial_with_short_phone_number(int slot_id); +int tapi_start_dtmf_test(int slot_id); +int tapi_stop_dtmf_test(int slot_id); +int tapi_call_load_ecc_list_test(int slot_id); +int tapi_call_get_call_test(int slot_id); +int tapi_call_answer_call_test(int slot_id, char* call_id); +int tapi_ss_listen_test(int slot_id); +int tapi_ss_unlisten_test(void); +int tapi_ss_listen_error_code_test(int slot_id); +void set_callback_data(int expect); +int judge_callback_result(void); +void incoming_first_call(void); +void incoming_another_call(void); +int call_check_alerting_status_after_dial(int slot_id); +int call_hangup_between_dialing_and_answering(int slot_id); +int call_dial_with_area_code(int slot_id); +int call_dial_after_caller_reject(int slot_id); +int call_hangup_after_caller_answer(int slot_id); +int outgoing_call_remote_answer_and_hangup(int slot_id); +int call_dial_caller_reject_and_incoming(int slot_id); +int call_dial_caller_reject_and_dial_another(int slot_id); +int incoming_call_answer_and_remote_hangup(int slot_id); +int call_dial_to_phone_in_call(int slot_id); +int call_dial_to_phone_out_of_service(int slot_id); +int call_dial_without_sim_card(int slot_id); +int call_dial_ecc_number_without_sim_card(int slot_id); +int call_incoming_and_hangup_by_dialer_before_answer(int slot_id); +int call_incoming_and_hangup_by_dialer_before_answer_numerous(int slot_id); +int call_display_the_network_of_incoming_call(int slot_id, char* network_name); +int call_dial_active_hangup_due_to_dialer_network_exception(int slot_id); +int call_dial_active_hangup_due_to_caller_network_exception(int slot_id); +int call_incoming_hangup_first_answer_second(int slot_id); +int call_incoming_hold_and_recover_by_dialer(int slot_id); +int call_dialer_hold_recover_and_hold_by_caller(int slot_id); +int call_incoming_hold_and_recover_by_caller(int slot_id); +int call_swap_dial_reject_swap(int slot_id); +int call_release_and_answer(int slot_id); +int call_hold_and_hangup(int slot_id); +int call_hold_incoming_hangup_second_recover_first(int slot_id); +int call_hold_incoming_answer_hangup_second_recover_first(int slot_id); +int call_incoming_second_call_swap_answer_hangup_swap(int slot_id); +int call_hold_current_call_and_reject_new_incoming(int slot_id); +int call_incoming_and_hangup_new_call(int slot_id); +int call_hold_first_call_and_answer_second_call(int slot_id); +int call_dial_second_call_active_and_hangup_by_dialer(int slot_id); +int call_dial_second_call_and_hangup_by_caller_before_answering(int slot_id); +int call_dial_second_call_active_and_hangup_by_caller(int slot_id); +int call_hangup_hold_call_in_two_calls(int slot_id); +int call_dial_to_empty_number(int slot_id); +int incoming_call_answer_and_hangup(int slot_id); +int call_display_the_network_of_incoming_call_in_call_process(int slot_id, + char* network_name); +int call_check_status_in_dialing(int slot_id); +int call_dial_and_check_status_in_call_process(int slot_id); +int call_check_status_in_incoming(int slot_id); +int call_incoming_answer_and_check_status_in_call_process(int slot_id); +int call_incoming_answer_caller_hold_and_check_status(int slot_id); +int call_incoming_answer_dialer_hold_and_check_status(int slot_id); +int call_check_call_status_in_multi_call(int slot_id); +int call_check_call_status_in_call_waiting_with_multi_call(int slot_id); +int call_check_call_status_in_dialing_with_multi_call(int slot); +int call_hold_old_call_incoming_new_call_and_check_status(int slot_id); +int call_swap_in_two_calling(int slot_id); +int call_hangup_current_call_and_recover_hold_call(int slot_id); +int call_hangup_all_call_in_two_calling(int slot_id); +int incoming_new_call_in_calling_and_hangup_all_call(int slot_id); +int call_dial_third_call(int slot_id); +int call_incoming_third_call(int slot_id); +int call_listen_and_unlisten_ss(int slot_id); +int call_listen_error_ss_code(int slot_id); +int tapi_call_hangup_all_test(int slot_id); +int tapi_get_call_count(int slot_id); +int tapi_call_set_default_voicecall_slot_test(int slot_id); +int tapi_call_get_default_voicecall_slot_test(int expect_res); +int call_clear_voicecall_slot_set(void); +int call_connect_and_local_hangup(int slot_id); +int dial_and_remote_hangup(int slot_id); +int incoming_call_and_local_hangup(int slot_id); +#endif \ No newline at end of file diff --git a/test/telephony_common_test.c b/test/telephony_common_test.c new file mode 100644 index 0000000..104e89c --- /dev/null +++ b/test/telephony_common_test.c @@ -0,0 +1,544 @@ +#include "telephony_common_test.h" +#include +#include +#include + +#define DATA_INIT_VALUE -100 +// seconds +#define HANDLE_REPEAT_TIME 1 +#define HANDLE_REPEAT_COUNT 10 + +#define MAX_MODEM_WATCH_COUNT 4 +#define MSG_DATA_IND_START MSG_DATA_ENABLED_CHANGE_IND +#define MSG_NETWORK_IND_START MSG_NETWORK_STATE_CHANGE_IND +#define MSG_MODEM_IND_START MSG_RADIO_STATE_CHANGE_IND + +static struct +{ + int radio_state_watch_id; + int phone_state_watch_id; + int modem_restart_ind_watch_id; + int oem_hook_raw_watch_id; + int modem_state; +} modem_data; + +extern struct judge_type judge_data; + +static void radio_signal_change(tapi_async_result* result); + +static void tele_call_async_fun(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + int event = result->msg_id; + int status = result->status; + + switch (event) { + case EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE: + syslog(LOG_DEBUG, "%s: EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE; + } + break; + case EVENT_MODEM_ENABLE_DONE: + syslog(LOG_DEBUG, "%s: EVENT_MODEM_ENABLE_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_MODEM_ENABLE_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_MODEM_ENABLE_DONE; + } + break; + case EVENT_RADIO_STATE_SET_DONE: + syslog(LOG_DEBUG, "%s: EVENT_RADIO_STATE_SET_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_RADIO_STATE_SET_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_RADIO_STATE_SET_DONE; + } + break; + case EVENT_OEM_RIL_REQUEST_RAW_DONE: + syslog(LOG_DEBUG, "%s: EVENT_OEM_RIL_REQUEST_RAW_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_OEM_RIL_REQUEST_RAW_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_OEM_RIL_REQUEST_RAW_DONE; + } + break; + case EVENT_OEM_RIL_REQUEST_STRINGS_DONE: + syslog(LOG_DEBUG, "%s: EVENT_OEM_RIL_REQUEST_STRINGS_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_OEM_RIL_REQUEST_STRINGS_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_OEM_RIL_REQUEST_STRINGS_DONE; + } + break; + case EVENT_MODEM_STATUS_QUERY_DONE: + syslog(LOG_DEBUG, "%s: EVENT_MODEM_STATUS_QUERY_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_MODEM_STATUS_QUERY_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_MODEM_STATUS_QUERY_DONE; + modem_data.modem_state = result->arg2; + } + break; + case EVENT_RAT_MODE_SET_DONE: + syslog(LOG_DEBUG, "%s: EVENT_RAT_MODE_SET_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_RAT_MODE_SET_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_RAT_MODE_SET_DONE; + } + break; + default: + break; + } +} + +int tapi_get_imei_test(int slot_id) +{ + char* imei = NULL; + + int ret = tapi_get_imei(get_tapi_ctx(), slot_id, &imei); + syslog(LOG_DEBUG, "%s, slotId : %d imei : %s \n", __func__, slot_id, imei); + + return ret; +} + +int tapi_get_modem_revision_test(int slot_id) +{ + char* version = NULL; + + int ret = tapi_get_modem_revision(get_tapi_ctx(), slot_id, &version); + syslog(LOG_DEBUG, "%s, slotId : %d version : %s \n", __func__, slot_id, version); + + return ret || (!version); +} + +int tapi_get_pref_net_mode_test(int slot_id, tapi_pref_net_mode* value) +{ + int ret = tapi_get_pref_net_mode(get_tapi_ctx(), slot_id, value); + syslog(LOG_DEBUG, "%s, slotId : %d value :%d \n", __func__, slot_id, *value); + return ret; +} + +int tapi_set_radio_power_test(int slot_id, bool target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_RADIO_STATE_SET_DONE; + + int ret = tapi_set_radio_power(get_tapi_ctx(), slot_id, + EVENT_RADIO_STATE_SET_DONE, target_state, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_set_radio_power_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_set_radio_power_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_get_radio_power_test(int slot_id, bool* value) +{ + int ret = tapi_get_radio_power(get_tapi_ctx(), slot_id, value); + syslog(LOG_DEBUG, "%s, slotId : %d value : %d \n", __func__, slot_id, *value); + return ret; +} + +int tapi_modem_register_test(int slot_id) +{ + modem_data.radio_state_watch_id = -1; + modem_data.radio_state_watch_id = tapi_register(get_tapi_ctx(), + slot_id, MSG_RADIO_STATE_CHANGE_IND, NULL, radio_signal_change); + if (modem_data.radio_state_watch_id < 0) { + syslog(LOG_ERR, "%s, radio state change registered fail, ret: %d", __func__, + modem_data.radio_state_watch_id); + return -1; + } + + modem_data.phone_state_watch_id = -1; + modem_data.phone_state_watch_id = tapi_register(get_tapi_ctx(), + slot_id, MSG_PHONE_STATE_CHANGE_IND, NULL, radio_signal_change); + if (modem_data.phone_state_watch_id < 0) { + syslog(LOG_ERR, "%s, phone state change registered fail, ret: %d", __func__, + modem_data.phone_state_watch_id); + return -1; + } + + modem_data.modem_restart_ind_watch_id = -1; + modem_data.modem_restart_ind_watch_id = tapi_register(get_tapi_ctx(), + slot_id, MSG_MODEM_RESTART_IND, NULL, radio_signal_change); + if (modem_data.modem_restart_ind_watch_id < 0) { + syslog(LOG_ERR, "%s, modem restart ind registered fail, ret: %d", __func__, + modem_data.modem_restart_ind_watch_id); + return -1; + } + + modem_data.oem_hook_raw_watch_id = -1; + modem_data.oem_hook_raw_watch_id = tapi_register(get_tapi_ctx(), + slot_id, MSG_OEM_HOOK_RAW_IND, NULL, radio_signal_change); + if (modem_data.oem_hook_raw_watch_id < 0) { + syslog(LOG_ERR, "%s, oem hook raw registered fail, ret: %d", __func__, + modem_data.oem_hook_raw_watch_id); + return -1; + } + + return 0; +} + +int tapi_modem_unregister_test(void) +{ + int ret = -1, res = 0; + ret = tapi_unregister(get_tapi_ctx(), modem_data.radio_state_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister radio state change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), modem_data.phone_state_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister phone state change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), modem_data.modem_restart_ind_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister modem restart change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), modem_data.oem_hook_raw_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister oem hook raw fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static int hex_string_to_byte_array(char* hex_str, unsigned char* byte_arr, int arr_len) +{ + char* str; + int len; + int i, j; + + if (hex_str == NULL) + return -EINVAL; + + len = strlen(hex_str); + if (!len || (len % 2) != 0 || len > arr_len * 2) + return -EINVAL; + + str = strdup(hex_str); + + for (i = 0, j = 0; i < len; i += 2, j++) { + // uppercase char 'a'~'f' + if (str[i] >= 'a' && str[i] <= 'f') + str[i] = str[i] & ~0x20; + + if (str[i + 1] >= 'a' && str[i + 1] <= 'f') + str[i + 1] = str[i + 1] & ~0x20; + + // convert the first character to decimal. + if (str[i] >= 'A' && str[i] <= 'F') + byte_arr[j] = (str[i] - 'A' + 10) << 4; + else if (str[i] >= '0' && str[i] <= '9') + byte_arr[j] = (str[i] & ~0x30) << 4; + else + return -EINVAL; + + // convert the second character to decimal + // and combine with the previous decimal. + if (str[i + 1] >= 'A' && str[i + 1] <= 'F') + byte_arr[j] |= (str[i + 1] - 'A' + 10); + else if (str[i + 1] >= '0' && str[i + 1] <= '9') + byte_arr[j] |= (str[i + 1] & ~0x30); + else + return -EINVAL; + } + + free(str); + return 0; +} + +int tapi_invoke_oem_ril_request_raw_test(int slot_id, char* oem_req, int length) +{ + int res = 0; + unsigned char req_data[MAX_INPUT_ARGS_LEN]; + hex_string_to_byte_array(oem_req, req_data, MAX_INPUT_ARGS_LEN); + judge_data_init(); + judge_data.expect = EVENT_OEM_RIL_REQUEST_RAW_DONE; + + int ret = tapi_invoke_oem_ril_request_raw(get_tapi_ctx(), slot_id, + EVENT_OEM_RIL_REQUEST_RAW_DONE, req_data, length, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_invoke_oem_ril_request_raw_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_invoke_oem_ril_request_raw_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_invoke_oem_ril_request_strings_test(int slot_id, char* req_data, int length) +{ + char* result; + char* ptr = NULL; + // FIXME: oem_req should be inited + char* oem_req[MAX_OEM_RIL_RESP_STRINGS_LENTH] = { 0 }; + int count = 0; + int res = 0; + result = strtok_r(req_data, "|", &ptr); + while (result != NULL) { + if (count < length) + oem_req[count] = result; + + count++; + result = strtok_r(NULL, "|", &ptr); + } + + judge_data_init(); + judge_data.expect = EVENT_OEM_RIL_REQUEST_STRINGS_DONE; + + int ret = tapi_invoke_oem_ril_request_strings(get_tapi_ctx(), slot_id, + EVENT_OEM_RIL_REQUEST_STRINGS_DONE, oem_req, length, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_invoke_oem_ril_request_strings_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_invoke_oem_ril_request_strings_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_get_modem_activity_info_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE; + + int ret = tapi_get_modem_activity_info(get_tapi_ctx(), slot_id, + EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_get_modem_activity_info_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_get_modem_activity_info_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_enable_modem_test(int slot_id, int target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_MODEM_ENABLE_DONE; + + int ret = tapi_enable_modem(get_tapi_ctx(), slot_id, + EVENT_MODEM_ENABLE_DONE, target_state, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_enable_modem_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_enable_modem_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_get_modem_status_test(int slot_id, int* state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_MODEM_STATUS_QUERY_DONE; + modem_data.modem_state = -1; + + int ret = tapi_get_modem_status(get_tapi_ctx(), slot_id, + EVENT_MODEM_STATUS_QUERY_DONE, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_get_modem_enable_status_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_get_modem_enable_status_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (modem_data.modem_state != *state) { + syslog(LOG_ERR, "modem_data.modem_state is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_set_pref_net_mode_test(int slot_id, tapi_pref_net_mode target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_RAT_MODE_SET_DONE; + + int ret = tapi_set_pref_net_mode(get_tapi_ctx(), slot_id, + EVENT_RAT_MODE_SET_DONE, target_state, tele_call_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_set_pref_net_mode_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tapi_set_pref_net_mode_test is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void radio_signal_change(tapi_async_result* result) +{ + int signal = result->msg_id; + int slot_id = result->arg1; + int param = result->arg2; + + switch (signal) { + case MSG_RADIO_STATE_CHANGE_IND: + syslog(LOG_DEBUG, "radio state changed to %d in slot[%d] \n", param, slot_id); + if (judge_data.expect == MSG_RADIO_STATE_CHANGE_IND) { + judge_data.result = OK; + } + break; + case MSG_PHONE_STATE_CHANGE_IND: + syslog(LOG_DEBUG, "phone state changed to %d in slot[%d] \n", param, slot_id); + if (judge_data.expect == MSG_PHONE_STATE_CHANGE_IND) { + judge_data.result = OK; + } + break; + case MSG_MODEM_RESTART_IND: + syslog(LOG_DEBUG, "modem restart in slot[%d] \n", slot_id); + if (judge_data.expect == MSG_MODEM_RESTART_IND) { + judge_data.result = OK; + } + break; + case MSG_OEM_HOOK_RAW_IND: + syslog(LOG_DEBUG, "oem hook raw in slot[%d] \n", slot_id); + if (judge_data.expect == MSG_OEM_HOOK_RAW_IND) { + judge_data.result = OK; + } + break; + default: + break; + } +} \ No newline at end of file diff --git a/test/telephony_common_test.h b/test/telephony_common_test.h new file mode 100644 index 0000000..cfe78e9 --- /dev/null +++ b/test/telephony_common_test.h @@ -0,0 +1,21 @@ +#ifndef TELEPHONY_COMMON_TEST_H_ +#define TELEPHONY_COMMON_TEST_H_ +#define MAX_INPUT_ARGS_LEN 128 + +#include "telephony_test.h" + +int tapi_get_imei_test(int slot_id); +int tapi_get_modem_revision_test(int slot_id); +int tapi_get_modem_activity_info_test(int slot_id); +int tapi_get_pref_net_mode_test(int slot_id, tapi_pref_net_mode* value); +int tapi_set_radio_power_test(int slot_id, bool target_state); +int tapi_get_radio_power_test(int slot_id, bool* value); +int tapi_modem_register_test(int slot_id); +int tapi_modem_unregister_test(void); +int tapi_invoke_oem_ril_request_raw_test(int slot_id, char* oem_req, int length); +int tapi_invoke_oem_ril_request_strings_test(int slot_id, char* req_data, int length); +int tapi_enable_modem_test(int slot_id, int target_state); +int tapi_get_modem_status_test(int slot_id, int* state); +int tapi_set_pref_net_mode_test(int slot_id, tapi_pref_net_mode target_state); + +#endif \ No newline at end of file diff --git a/test/telephony_data_test.c b/test/telephony_data_test.c new file mode 100644 index 0000000..955ac87 --- /dev/null +++ b/test/telephony_data_test.c @@ -0,0 +1,786 @@ +#include "telephony_data_test.h" + +extern struct judge_type judge_data; +static struct +{ + int data_enabled_watch_id; + int data_connection_state_change_watch_id; + int data_on; + int connection_state; +} global_data; + +static void data_event_response(tapi_async_result* result); +static void data_signal_change(tapi_async_result* result); + +int tapi_data_listen_data_test(int slot_id) +{ + global_data.data_enabled_watch_id = -1; + global_data.data_enabled_watch_id = tapi_data_register( + get_tapi_ctx(), slot_id, MSG_DATA_ENABLED_CHANGE_IND, NULL, data_signal_change); + + if (global_data.data_enabled_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, target_state: %d, watch_id: %d", + __func__, slot_id, MSG_DATA_ENABLED_CHANGE_IND, + global_data.data_enabled_watch_id); + return -1; + } + + global_data.data_connection_state_change_watch_id = -1; + global_data.data_connection_state_change_watch_id = tapi_data_register( + get_tapi_ctx(), slot_id, MSG_DATA_CONNECTION_STATE_CHANGE_IND, NULL, data_signal_change); + if (global_data.data_connection_state_change_watch_id < 0) { + syslog(LOG_DEBUG, "%s, slot_id: %d, target_state: %d, watch_id: %d", + __func__, slot_id, MSG_DATA_CONNECTION_STATE_CHANGE_IND, + global_data.data_connection_state_change_watch_id); + return -1; + } + + return 0; +} + +int tapi_data_unlisten_data_test(void) +{ + int ret = -1, res = 0; + syslog(LOG_INFO, "data enabled watch id: %d, data connection state change watch id: %d", + global_data.data_enabled_watch_id, + global_data.data_connection_state_change_watch_id); + ret = tapi_data_unregister(get_tapi_ctx(), global_data.data_enabled_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister data enable change fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_data_unregister(get_tapi_ctx(), global_data.data_connection_state_change_watch_id); + if (ret) { + syslog(LOG_ERR, "unregister data connection state change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_load_apn_contexts_test(int slot_id) +{ + int ret = -1; + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_APN_LOADED_DONE; + ret = tapi_data_load_apn_contexts(get_tapi_ctx(), slot_id, EVENT_APN_LOADED_DONE, data_event_response); + + if (ret) { + syslog(LOG_ERR, "tapi_data_load_apn_contexts_test execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "data_event_response called by %s is not execute", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_save_apn_context_test(char* slot_id, char* type, char* name, char* apn, char* proto, char* auth) +{ + int ret = -1; + int res = 0; + tapi_data_context* apn_context; + judge_data_init(); + judge_data.expect = EVENT_APN_ADD_DONE; + apn_context = malloc(sizeof(tapi_data_context)); + if (apn_context == NULL) { + syslog(LOG_DEBUG, "apn_contex is null in %s", __func__); + return -EINVAL; + } + + apn_context->type = atoi(type); + apn_context->protocol = atoi(proto); + apn_context->auth_method = atoi(auth); + + if (strlen(name) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->name, name); + + if (strlen(apn) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->accesspointname, apn); + + strcpy(apn_context->username, ""); + strcpy(apn_context->password, ""); + + ret = tapi_data_add_apn_context(get_tapi_ctx(), atoi(slot_id), EVENT_APN_ADD_DONE, apn_context, data_event_response); + free(apn_context); + if (ret) { + syslog(LOG_ERR, "tapi_data_add_apn_context execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "data_event_response is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_edit_apn_context_test(char* slot_id, char* id, char* type, char* name, char* apn, char* proto, char* auth) +{ + int ret = -1; + tapi_data_context* apn_context; + judge_data_init(); + judge_data.expect = EVENT_APN_EDIT_DONE; + apn_context = malloc(sizeof(tapi_data_context)); + if (apn_context == NULL) { + syslog(LOG_ERR, "apn_context is null in %s", __func__); + return -EINVAL; + } + + apn_context->id = id; + apn_context->type = atoi(type); + apn_context->protocol = atoi(proto); + apn_context->auth_method = atoi(auth); + + if (strlen(name) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->name, name); + + if (strlen(apn) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->accesspointname, apn); + + strcpy(apn_context->username, ""); + strcpy(apn_context->password, ""); + + ret = tapi_data_edit_apn_context(get_tapi_ctx(), atoi(slot_id), EVENT_APN_EDIT_DONE, apn_context, data_event_response); + free(apn_context); + judge(); + + return ret + || judge_data.result + || (judge_data.expect != judge_data.flag); +} + +int tapi_data_remove_apn_context_test(char* slot_id, char* id) +{ + int ret = -1; + int res = 0; + tapi_data_context* apn; + judge_data_init(); + judge_data.expect = EVENT_APN_REMOVAL_DONE; + + apn = malloc(sizeof(tapi_data_context)); + if (apn == NULL) { + syslog(LOG_ERR, "apn is null in %s", __func__); + return ret; + } + + apn->id = id; + ret = tapi_data_remove_apn_context(get_tapi_ctx(), atoi(slot_id), EVENT_APN_REMOVAL_DONE, apn, data_event_response); + free(apn); + if (ret) { + syslog(LOG_ERR, "tapi_data_remove_apn_context execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "data_event_response is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_DEBUG, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_reset_apn_contexts_test(char* slot_id) +{ + int ret = -1; + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_APN_RESTORE_DONE; + + ret = tapi_data_reset_apn_contexts(get_tapi_ctx(), atoi(slot_id), EVENT_APN_RESTORE_DONE, data_event_response); + if (ret) { + syslog(LOG_ERR, "tapi_data_reset_apn_contexts execute fail in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "data_event_response is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_request_network_test(int slot_id, char* target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DATA_CONNECTION_STATE_CHANGE_IND; + global_data.connection_state = -100; + + int ret = tapi_data_request_network(get_tapi_ctx(), slot_id, target_state); + if (ret) { + syslog(LOG_ERR, "tapi_data_request_network execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "the callback function of request_network is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.connection_state != 1) { + syslog(LOG_ERR, "connection state is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_release_network_test(int slot_id, char* target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DATA_CONNECTION_STATE_CHANGE_IND; + global_data.connection_state = -100; + int ret = tapi_data_release_network(get_tapi_ctx(), slot_id, target_state); + if (ret) { + syslog(LOG_ERR, "tapi_data_release_network execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "the callback function of release_network is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.connection_state != 0) { + syslog(LOG_ERR, "connection state is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_enable_test(int state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DATA_ENABLED_CHANGE_IND; + global_data.data_on = -1; + int ret = tapi_data_enable_data(get_tapi_ctx(), state); + if (ret) { + syslog(LOG_ERR, "tapi_data_enable_data execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "the callback function of data_enable is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result in %s is invalid", __func__); + res = -1; + goto on_exit; + } + + if (global_data.data_on != state) { + syslog(LOG_ERR, "data status is error"); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +// is-data-on +int tapi_data_get_enabled_test(bool* result) +{ + int ret = tapi_data_get_enabled(get_tapi_ctx(), result); + bool flag = *result; + syslog(LOG_DEBUG, "ret: %d, result: %d", ret, (int)flag); + + return ret; +} + +int tapi_data_is_ps_attached_test(int slot_id) +{ + bool result = false; + int ret = tapi_data_is_registered(get_tapi_ctx(), slot_id, &result); + return ret || !result; +} + +int tapi_data_get_network_type_test(int slot_id) +{ + tapi_network_type result = NETWORK_TYPE_UNKNOWN; + int ret = tapi_data_get_network_type(get_tapi_ctx(), slot_id, &result); + return ret || result != NETWORK_TYPE_LTE; +} + +int tapi_data_enable_roaming_test(int state) +{ + int ret = tapi_data_enable_roaming(get_tapi_ctx(), state); + return ret; +} + +bool tapi_data_get_roaming_enabled_test(bool* result) +{ + int ret = tapi_data_get_roaming_enabled(get_tapi_ctx(), result); + return ret; +} + +int tapi_data_set_preferred_apn_test(int slot_id, char* apn_id) +{ + tapi_data_context* apn = malloc(sizeof(tapi_data_context)); + if (apn == NULL) { + syslog(LOG_ERR, "apn is null in %s", __func__); + return -1; + } + + apn->id = apn_id; + int ret = tapi_data_set_preferred_apn(get_tapi_ctx(), slot_id, apn); + free(apn); + return ret; +} + +int tapi_data_get_preferred_apn_test(int slot_id) +{ + sleep(2); + char* apn = NULL; + int ret = tapi_data_get_preferred_apn(get_tapi_ctx(), slot_id, &apn); + syslog(LOG_DEBUG, "%s: %s", __func__, apn); + + return ret || strcmp(apn, "/ril_0/context1") != 0; +} + +int tapi_data_set_default_data_slot_test(int slot_id) +{ + int ret = tapi_data_set_default_slot(get_tapi_ctx(), slot_id); + return ret; +} + +int tapi_data_get_default_data_slot_test(void) +{ + int result = -1; + int ret = tapi_data_get_default_slot(get_tapi_ctx(), &result); + return ret || result != 0; +} + +int tapi_data_set_data_allow_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DATA_ALLOWED_DONE; + int ret = tapi_data_set_data_allow(get_tapi_ctx(), slot_id, EVENT_DATA_ALLOWED_DONE, 1, data_event_response); + if (ret) { + syslog(LOG_ERR, "tapi_data_set_data_allow execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "data_event_response is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_send_screen_stat_test(int slot_id) +{ + int ret = tapi_set_fast_dormancy(get_tapi_ctx(), slot_id, + EVENT_REQUEST_SCREEN_STATE_DONE, 1, data_event_response); + sleep(4); + + return ret; +} + +int tapi_data_get_data_call_list_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DATA_CALL_LIST_QUERY_DONE; + + int ret = tapi_data_get_data_connection_list(get_tapi_ctx(), slot_id, + EVENT_DATA_CALL_LIST_QUERY_DONE, data_event_response); + if (ret) { + syslog(LOG_DEBUG, "tapi_data_get_data_connection_list execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "data_event_response in %s is not executed", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_DEBUG, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void data_event_response(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + int event = result->msg_id; + int status = result->status; + + switch (event) { + case EVENT_APN_LOADED_DONE: + if (judge_data.expect == EVENT_APN_LOADED_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_APN_LOADED_DONE; + } + break; + case EVENT_APN_ADD_DONE: + if (judge_data.expect == EVENT_APN_ADD_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_APN_ADD_DONE; + } + break; + case EVENT_APN_EDIT_DONE: + if (judge_data.expect == EVENT_APN_EDIT_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_APN_EDIT_DONE; + } + break; + case EVENT_APN_REMOVAL_DONE: + if (judge_data.expect == EVENT_APN_REMOVAL_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_APN_REMOVAL_DONE; + } + break; + case EVENT_APN_RESTORE_DONE: + if (judge_data.expect == EVENT_APN_RESTORE_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_APN_RESTORE_DONE; + } + break; + case EVENT_DATA_ALLOWED_DONE: + if (judge_data.expect == EVENT_DATA_ALLOWED_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_DATA_ALLOWED_DONE; + } + case EVENT_REQUEST_SCREEN_STATE_DONE: + if (judge_data.expect == EVENT_REQUEST_SCREEN_STATE_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_REQUEST_SCREEN_STATE_DONE; + } + break; + case EVENT_DATA_CALL_LIST_QUERY_DONE: + if (judge_data.expect == EVENT_DATA_CALL_LIST_QUERY_DONE) { + judge_data.result = status; + judge_data.flag = EVENT_DATA_CALL_LIST_QUERY_DONE; + } + default: + break; + } +} + +static void data_signal_change(tapi_async_result* result) +{ + tapi_data_context* dc; + tapi_ipv4_settings* ipv4; + tapi_ipv6_settings* ipv6; + int signal = result->msg_id; + int slot_id = result->arg1; + int param = result->arg2; + + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + switch (signal) { + case MSG_DATA_REGISTRATION_STATE_CHANGE_IND: + syslog(LOG_DEBUG, "data registration state changed to %d in slot[%d] \n", param, slot_id); + if (judge_data.expect == MSG_DATA_REGISTRATION_STATE_CHANGE_IND) { + judge_data.result = OK; + judge_data.flag = MSG_DATA_REGISTRATION_STATE_CHANGE_IND; + } + break; + case MSG_DATA_NETWORK_TYPE_CHANGE_IND: + syslog(LOG_DEBUG, "data network type changed to %d in slot[%d] \n", param, slot_id); + if (judge_data.expect == MSG_DATA_NETWORK_TYPE_CHANGE_IND) { + judge_data.result = OK; + judge_data.flag = MSG_DATA_NETWORK_TYPE_CHANGE_IND; + } + break; + case MSG_DEFAULT_DATA_SLOT_CHANGE_IND: + syslog(LOG_DEBUG, "data slot changed to slot[%d] \n", param); + if (judge_data.expect == MSG_DEFAULT_DATA_SLOT_CHANGE_IND) { + judge_data.result = OK; + judge_data.flag = MSG_DEFAULT_DATA_SLOT_CHANGE_IND; + } + break; + case MSG_DATA_ENABLED_CHANGE_IND: + if (judge_data.expect == MSG_DATA_ENABLED_CHANGE_IND) { + syslog(LOG_DEBUG, "data switch changed to %d in slot[%d] \n", param, slot_id); + judge_data.result = 0; + global_data.data_on = param; + judge_data.flag = MSG_DATA_ENABLED_CHANGE_IND; + } + break; + case MSG_DATA_CONNECTION_STATE_CHANGE_IND: + if (judge_data.expect == MSG_DATA_CONNECTION_STATE_CHANGE_IND) { + dc = result->data; + if (dc != NULL) { + syslog(LOG_DEBUG, "id (apn_path) = %s \n", dc->id); + syslog(LOG_DEBUG, "type = %s \n", tapi_utils_apn_type_to_string(dc->type)); + syslog(LOG_DEBUG, "active = %d \n", dc->active); + global_data.connection_state = dc->active; + if (dc->ip_settings != NULL) { + ipv4 = dc->ip_settings->ipv4; + if (ipv4 != NULL) { + syslog(LOG_DEBUG, "ipv4-interface = %s; ip = %s; gateway = %s; dns[0] = %s; \n", + ipv4->interface, ipv4->ip, ipv4->gateway, ipv4->dns[0]); + } + ipv6 = dc->ip_settings->ipv6; + if (ipv6 != NULL) { + syslog(LOG_DEBUG, "ipv6-interface = %s; ip = %s; gateway = %s; dns[0] = %s; \n", + ipv6->interface, ipv6->ip, ipv6->gateway, ipv6->dns[0]); + } + } + } + judge_data.result = 0; + judge_data.flag = MSG_DATA_CONNECTION_STATE_CHANGE_IND; + } + break; + default: + break; + } +} + +int data_enabled_test(int slot_id) +{ + int ret = tapi_data_enable_test(1); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + + return ret; +} + +int data_disabled_test(int slot_id) +{ + int ret = tapi_data_enable_test(0); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + + return ret; +} + +int data_release_network_test(int slot_id) +{ + int ret = tapi_data_release_network_test(slot_id, "internet"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_request_network_test(int slot_id) +{ + int ret = tapi_data_request_network_test(slot_id, "internet"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_request_ims(int slot_id) +{ + int ret = tapi_data_request_network_test(slot_id, "ims"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_release_ims(int slot_id) +{ + int ret = tapi_data_release_network_test(slot_id, "ims"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_get_call_list(int slot_id) +{ + int ret = -1; + int res = 0; + + ret = tapi_data_enable_test(1); + if (ret) { + syslog(LOG_ERR, "enable data failed in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_data_get_data_call_list_test(slot_id); + if (ret) { + syslog(LOG_ERR, "get data call list failed in %s", __func__); + res = -1; + goto on_exit; + } + + ret = tapi_data_enable_test(0); + if (ret) { + syslog(LOG_ERR, "disable data failed in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int data_enable_roaming_test(void) +{ + bool result = false; + int ret = -1; + int res = 0; + ret = tapi_data_enable_roaming_test(true); + if (ret) { + syslog(LOG_ERR, "enable data roaming failed"); + res = -1; + goto on_exit; + } + + sleep(3); + ret = tapi_data_get_roaming_enabled_test(&result); + if (ret) { + syslog(LOG_ERR, "get data roaming failed in %s", __func__); + res = -1; + goto on_exit; + } + + if (!result) { + syslog(LOG_ERR, "data roaming state is error in %s, state: %d", __func__, (int)result); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int data_disable_roaming_test(void) +{ + bool result = true; + int ret = -1; + int res = 0; + ret = tapi_data_enable_roaming_test(false); + if (ret) { + syslog(LOG_ERR, "disable data roaming failed in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + ret = tapi_data_get_roaming_enabled_test(&result); + if (ret) { + syslog(LOG_ERR, "get data roaming failed in %s", __func__); + res = -1; + goto on_exit; + } + + if (result) { + syslog(LOG_ERR, "data roaming state is error in %s, state: %d", __func__, (int)result); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} \ No newline at end of file diff --git a/test/telephony_data_test.h b/test/telephony_data_test.h new file mode 100644 index 0000000..0688002 --- /dev/null +++ b/test/telephony_data_test.h @@ -0,0 +1,38 @@ +#ifndef TELEPHONY_DATA_TEST_H_ +#define TELEPHONY_DATA_TEST_H_ + +#include "telephony_test.h" + +int tapi_data_listen_data_test(int slot_id); +int tapi_data_unlisten_data_test(void); +int tapi_data_enable_test(int state); +int tapi_data_load_apn_contexts_test(int slot_id); +int tapi_data_save_apn_context_test(char* slot_id, char* type, char* name, char* apn, char* proto, char* auth); +int tapi_data_edit_apn_context_test(char* slot_id, char* id, char* type, char* name, char* apn, char* proto, char* auth); +int tapi_data_remove_apn_context_test(char* slot_id, char* id); +int tapi_data_reset_apn_contexts_test(char* slot_id); +int tapi_data_request_network_test(int slot_id, char* target_state); +int tapi_data_release_network_test(int slot_id, char* target_state); +int tapi_data_enable_roaming_test(int); +bool tapi_data_get_roaming_enabled_test(bool* result); +int tapi_data_get_enabled_test(bool* result); +int tapi_data_is_ps_attached_test(int slot_id); +int tapi_data_get_network_type_test(int slot_id); +int tapi_data_set_preferred_apn_test(int slot_id, char* apn_id); +int tapi_data_get_preferred_apn_test(int slot_id); +int tapi_data_set_default_data_slot_test(int slot_id); +int tapi_data_get_default_data_slot_test(void); +int tapi_data_set_data_allow_test(int slot_id); +int tapi_data_send_screen_stat_test(int slot_id); +int tapi_data_get_data_call_list_test(int slot_id); +int data_enabled_test(int slot_id); +int data_disabled_test(int slot_id); +int data_release_network_test(int slot_id); +int data_request_network_test(int slot_id); +int data_request_ims(int slot_id); +int data_release_ims(int slot_id); +int data_get_call_list(int slot_id); +int data_enable_roaming_test(void); +int data_disable_roaming_test(void); + +#endif /* TELEPHONY_DATA_TEST_H_ */ diff --git a/test/telephony_ims_test.c b/test/telephony_ims_test.c new file mode 100644 index 0000000..2dbeec3 --- /dev/null +++ b/test/telephony_ims_test.c @@ -0,0 +1,153 @@ +#include "telephony_ims_test.h" + +static void tele_ims_async_fun(tapi_async_result* result); +extern struct judge_type judge_data; + +static struct +{ + int ims_enabled; + int ims_reg_watch_id; +} global_data; + +int tapi_ims_listen_ims_test(int slot_id) +{ + global_data.ims_reg_watch_id = -1; + global_data.ims_reg_watch_id = tapi_ims_register_registration_change(get_tapi_ctx(), + slot_id, NULL, tele_ims_async_fun); + + if (global_data.ims_reg_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", + __func__, slot_id); + return -1; + } + + return 0; +} + +int tapi_ims_turn_on_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = IMS_REG; + global_data.ims_enabled = -1; + int ret = tapi_ims_turn_on(get_tapi_ctx(), slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_ims_turn_on execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "the callback function is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.ims_enabled != 1) { + syslog(LOG_ERR, "ims enabled is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ims_turn_off_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = IMS_REG; + global_data.ims_enabled = -1; + int ret = tapi_ims_turn_off(get_tapi_ctx(), slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_ims_turn_off execute fail in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "the callback function is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.ims_enabled != 0) { + syslog(LOG_ERR, "ims enabled is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ims_get_registration_test(int slot_id) +{ + tapi_ims_registration_info info; + memset(&info, 0, sizeof(info)); + int ret = tapi_ims_get_registration(get_tapi_ctx(), slot_id, &info); + syslog(LOG_ERR, "%s, slot_id: %d, reg_info: %d", __func__, slot_id, info.reg_info); + + return ret || !info.reg_info; +} + +int tapi_ims_set_service_status_test(int slot_id, int status) +{ + int res = 0; + int ret = tapi_ims_set_service_status(get_tapi_ctx(), slot_id, status); + if (ret) { + syslog(LOG_ERR, "tapi_ims_set_service_status execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void tele_ims_async_fun(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + switch (result->arg1) { + case IMS_REG: + if (judge_data.expect == IMS_REG) { + syslog(LOG_DEBUG, "IMS_REG change : %d", result->arg2); + judge_data.result = 0; + global_data.ims_enabled = result->arg2; + judge_data.flag = IMS_REG; + } + break; + break; + default: + break; + } +} + +int tapi_ims_get_enabled_test(int slot_id) +{ + bool result = false; + int ret = tapi_ims_get_enabled(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, slot_id: %d, ims_enable: %d", __func__, slot_id, result); + + return ret || !result; +} \ No newline at end of file diff --git a/test/telephony_ims_test.h b/test/telephony_ims_test.h new file mode 100644 index 0000000..5204309 --- /dev/null +++ b/test/telephony_ims_test.h @@ -0,0 +1,13 @@ +#ifndef TELEPHONY_IMS_TEST_H_ +#define TELEPHONY_IMS_TEST_H_ + +#include "telephony_test.h" + +int tapi_ims_listen_ims_test(int slot_id); +int tapi_ims_turn_on_test(int slot_id); +int tapi_ims_turn_off_test(int slot_id); +int tapi_ims_get_registration_test(int slot_id); +int tapi_ims_get_enabled_test(int slot_id); +int tapi_ims_set_service_status_test(int slot_id, int status); + +#endif \ No newline at end of file diff --git a/test/telephony_network_test.c b/test/telephony_network_test.c new file mode 100644 index 0000000..2547bb5 --- /dev/null +++ b/test/telephony_network_test.c @@ -0,0 +1,361 @@ +#include "telephony_network_test.h" +#include + +extern struct judge_type judge_data; + +static struct +{ + int network_count; + int reg_state; + int serving_cell_reg; +} global_data; + +static void network_event_callback(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + tapi_operator_info** operator_list; + tapi_operator_info* operator_info; + tapi_registration_info* info; + tapi_cell_identity** cell_list; + tapi_cell_identity* cell; + int msg, index; + + msg = result->msg_id; + + switch (msg) { + case EVENT_NETWORK_SCAN_DONE: + if (judge_data.expect == EVENT_NETWORK_SCAN_DONE) { + index = result->arg2; + operator_list = result->data; + + while (--index >= 0) { + operator_info = *operator_list++; + syslog(LOG_DEBUG, "id : %s, name : %s, status : %d, mcc : %s, mnc : %s \n", + operator_info->id, operator_info->name, operator_info->status, + operator_info->mcc, operator_info->mnc); + } + + judge_data.result = 0; + global_data.network_count = result->arg2; + judge_data.flag = EVENT_NETWORK_SCAN_DONE; + } + break; + case EVENT_REGISTER_AUTO_DONE: + if (judge_data.expect == EVENT_REGISTER_AUTO_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_REGISTER_AUTO_DONE; + } + break; + case EVENT_REGISTER_MANUAL_DONE: + if (judge_data.expect == EVENT_REGISTER_MANUAL_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_REGISTER_MANUAL_DONE; + } + break; + case EVENT_QUERY_REGISTRATION_INFO_DONE: + if (judge_data.expect == EVENT_QUERY_REGISTRATION_INFO_DONE) { + info = result->data; + syslog(LOG_DEBUG, "%s : \n", __func__); + if (info == NULL) { + judge_data.result = -1; + judge_data.flag = EVENT_QUERY_REGISTRATION_INFO_DONE; + return; + } + + syslog(LOG_DEBUG, "reg_state = %d operator_name = %s mcc = %s mnc = %s \n", + info->reg_state, info->operator_name, info->mcc, info->mnc); + + judge_data.result = 0; + global_data.reg_state = info->reg_state; + judge_data.flag = EVENT_QUERY_REGISTRATION_INFO_DONE; + } + + break; + case EVENT_QUERY_SERVING_CELL_DONE: + if (judge_data.expect == EVENT_QUERY_SERVING_CELL_DONE) { + index = result->arg2; + cell_list = result->data; + + while (--index >= 0) { + cell = *cell_list++; + syslog(LOG_DEBUG, "ci : %d, mcc : %s, mnc : %s, registered : %d, type : %d, \n", + cell->ci, cell->mcc_str, cell->mnc_str, cell->registered, cell->type); + if (cell->registered == 1) { + global_data.serving_cell_reg = 1; + } + } + + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_SERVING_CELL_DONE; + } + break; + case EVENT_QUERY_NEIGHBOURING_CELL_DONE: + if (judge_data.expect == EVENT_QUERY_NEIGHBOURING_CELL_DONE) { + index = result->arg2; + cell_list = result->data; + + while (--index >= 0) { + cell = *cell_list++; + syslog(LOG_DEBUG, "ci : %d, mcc : %s, mnc : %s, registered : %d, type : %d, \n", + cell->ci, cell->mcc_str, cell->mnc_str, cell->registered, cell->type); + } + + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_NEIGHBOURING_CELL_DONE; + } + break; + default: + break; + } +} + +int tapi_net_select_auto_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REGISTER_AUTO_DONE; + int ret = tapi_network_select_auto(get_tapi_ctx(), slot_id, EVENT_REGISTER_AUTO_DONE, + network_event_callback); + if (ret) { + syslog(LOG_ERR, "tapi_network_select_auto execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "network_event_callback is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_select_manual_test(int slot_id, char* mcc, char* mnc, char* tech) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REGISTER_MANUAL_DONE; + tapi_operator_info* network_info = malloc(sizeof(tapi_operator_info)); + if (network_info == NULL) { + syslog(LOG_ERR, "tapi_operator_info is null in %s", __func__); + return -ENOMEM; + } + + snprintf(network_info->mcc, sizeof(network_info->mcc), "%s", mcc); + snprintf(network_info->mnc, sizeof(network_info->mnc), "%s", mnc); + snprintf(network_info->technology, sizeof(network_info->technology), "%s", tech); + + int ret = tapi_network_select_manual(get_tapi_ctx(), slot_id, EVENT_REGISTER_MANUAL_DONE, + network_info, network_event_callback); + free(network_info); + if (ret) { + syslog(LOG_ERR, "tapi_network_select_manual execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "network_event_callback is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_scan_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_NETWORK_SCAN_DONE; + global_data.network_count = -1; + + int ret = tapi_network_scan(get_tapi_ctx(), slot_id, EVENT_NETWORK_SCAN_DONE, + network_event_callback); + if (ret) { + syslog(LOG_ERR, "tapi_network_scan execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "network_event_callback is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.network_count <= 0) { + syslog(LOG_ERR, "network scan error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_registration_info_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_REGISTRATION_INFO_DONE; + global_data.reg_state = -1; + int ret = tapi_network_get_registration_info(get_tapi_ctx(), slot_id, + EVENT_QUERY_REGISTRATION_INFO_DONE, network_event_callback); + if (ret) { + syslog(LOG_ERR, "tapi_network_get_registration_info execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "network_event_callback is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.reg_state != 1) { + syslog(LOG_ERR, "reg state is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_get_serving_cellinfos_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_SERVING_CELL_DONE; + global_data.serving_cell_reg = -1; + int ret = tapi_network_get_serving_cellinfos(get_tapi_ctx(), slot_id, + EVENT_QUERY_SERVING_CELL_DONE, network_event_callback); + if (ret) { + syslog(LOG_ERR, "tapi_network_get_serving_cellinfos execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "network_event_callback is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.serving_cell_reg != 1) { + syslog(LOG_ERR, "serving cell reg is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_get_neighbouring_cellInfos_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_NEIGHBOURING_CELL_DONE; + int ret = tapi_network_get_neighbouring_cellinfos(get_tapi_ctx(), slot_id, + EVENT_QUERY_NEIGHBOURING_CELL_DONE, network_event_callback); + if (ret) { + syslog(LOG_ERR, "tapi_network_get_neighbouring_cellinfos execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "network_event_callback is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_get_operator_name_test(int slot_id) +{ + char* operator_name = NULL; + int ret = tapi_network_get_display_name(get_tapi_ctx(), slot_id, &operator_name); + syslog(LOG_DEBUG, "%s, slotId : %d value :%s \n", __func__, slot_id, operator_name); + + return ret || operator_name == NULL; +} + +int tapi_net_query_signalstrength_test(int slot_id) +{ + tapi_signal_strength ss; + memset(&ss, 0, sizeof(ss)); + int ret = tapi_network_get_signalstrength(get_tapi_ctx(), slot_id, &ss); + syslog(LOG_DEBUG, "%s, slotId : %d RSRP value :%d \n", __func__, slot_id, ss.rsrp); + + return ret || !ss.rsrp; +} + +int tapi_net_get_voice_registered_test(int slot_id) +{ + bool result = false; + int ret = tapi_network_is_voice_registered(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, slot_id: %d, voice_reg: %d", __func__, slot_id, (int)result); + + return ret || !result; +} \ No newline at end of file diff --git a/test/telephony_network_test.h b/test/telephony_network_test.h new file mode 100644 index 0000000..c02645e --- /dev/null +++ b/test/telephony_network_test.h @@ -0,0 +1,17 @@ +#ifndef TELEPHONY_NETWORK_TEST_H_ +#define TELEPHONY_NETWORK_TEST_H_ + +#include "telephony_test.h" + +int tapi_net_select_auto_test(int slot_id); +int tapi_net_select_manual_test(int slot_id, char* mcc, char* mnc, char* tech); +int tapi_net_scan_test(int slot_id); +int tapi_net_registration_info_test(int slot_id); +int tapi_net_get_serving_cellinfos_test(int slot_id); +int tapi_net_get_neighbouring_cellInfos_test(int slot_id); +int tapi_net_get_voice_networktype_test(int slot_id, tapi_network_type* type); +int tapi_net_get_operator_name_test(int slot_id); +int tapi_net_query_signalstrength_test(int slot_id); +int tapi_net_get_voice_registered_test(int slot_id); + +#endif /* TELEPHONY_NETWORK_TEST_H_ */ diff --git a/test/telephony_sim_test.c b/test/telephony_sim_test.c new file mode 100644 index 0000000..d88d7db --- /dev/null +++ b/test/telephony_sim_test.c @@ -0,0 +1,947 @@ +#include "telephony_sim_test.h" + +extern struct judge_type judge_data; + +static struct +{ + int sim_state_change_watch_id; + int sim_uicc_app_enabled_change_watch_id; + int current_channel_session_id; +} global_data; + +static void global_data_init(void) +{ + global_data.sim_state_change_watch_id = -1; + global_data.sim_uicc_app_enabled_change_watch_id = -1; +} + +int tapi_sim_has_icc_card_test(int slot_id) +{ + bool result = false; + int ret = tapi_sim_has_icc_card(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, result: %d\n", __func__, ret, slot_id, result); + + return ret || (!result); +} + +int tapi_sim_multi_has_icc_card_test(int slot_id) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) { + if ((ret = tapi_sim_has_icc_card_test(slot_id)) != 0) { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_sim_operator_test(int slot_id, const char* expect_res) +{ + char operator[MAX_MCC_LENGTH + MAX_MNC_LENGTH + 1]; + memset(operator, 0, sizeof(operator)); + int ret = tapi_sim_get_sim_operator(get_tapi_ctx(), + 0, (MAX_MCC_LENGTH + MAX_MNC_LENGTH + 1), operator); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, operator: %s\n", __func__, ret, slot_id, operator); + + return ret || (operator[0] == 0) || strcmp(expect_res, operator); +} + +int tapi_sim_multi_get_sim_operator(int slot_id, const char* expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) { + if ((ret = tapi_sim_get_sim_operator_test(slot_id, expect_res)) != 0) { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_sim_operator_name_test(int slot_id, const char* expect_res) +{ + char* spn = NULL; + int ret = tapi_sim_get_sim_operator_name(get_tapi_ctx(), slot_id, &spn); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, spn: %s\n", __func__, ret, slot_id, spn); + + return ret || (spn == NULL) || strcmp(expect_res, spn); +} + +int tapi_sim_get_sim_operator_name_numerous(int slot_id, const char* expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) { + if ((ret = tapi_sim_get_sim_operator_name_test(slot_id, expect_res)) != 0) { + goto on_exit; + } + } + +on_exit: + return ret; +} + +int tapi_sim_get_sim_subscriber_id_test(int slot_id, const char* expect_res) +{ + char* result = NULL; + int ret = tapi_sim_get_subscriber_id(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, subscriber_id: %s\n", + __func__, ret, slot_id, result); + + return ret || (!result) || strcmp(result, expect_res); +} + +int tapi_sim_multi_get_sim_subscriber_id_test(int slot_id, const char* expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) { + if ((ret = tapi_sim_get_sim_subscriber_id_test(slot_id, expect_res)) != 0) { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_sim_iccid_test(int slot_id, const char* expect_res) +{ + char* iccid = NULL; + int ret = tapi_sim_get_sim_iccid(get_tapi_ctx(), slot_id, &iccid); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, iccid: %s\n", __func__, ret, slot_id, iccid); + + return ret || iccid == NULL || strcmp(expect_res, iccid); +} + +int tapi_sim_multi_get_sim_iccid_test(int slot_id, const char* expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) { + if ((ret = tapi_sim_get_sim_iccid_test(slot_id, expect_res)) != 0) { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_ef_msisdn_test(int slot_id, const char* expect_res) +{ + char* number = NULL; + int ret = tapi_get_msisdn_number(get_tapi_ctx(), slot_id, &number); + syslog(LOG_DEBUG, "%s, ret: %d, slotId : %d number : %s \n", __func__, ret, slot_id, number); + + return ret || number == NULL || strcmp(expect_res, number); +} + +int tapi_sim_multi_get_ef_msisdn_test(int slot_id, const char* expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) { + if ((ret = tapi_sim_get_ef_msisdn_test(slot_id, expect_res)) != 0) { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_state_test(int slot_id) +{ + int state = 0; + int ret = tapi_sim_get_sim_state(get_tapi_ctx(), slot_id, &state); + syslog(LOG_DEBUG, "%s, ret: %d, slotId : %d sim_state : %s \n", __func__, ret, slot_id, + tapi_sim_state_to_string((tapi_sim_state)state)); + + return ret || state != 3; +} + +static void tele_sim_async_fun(tapi_async_result* result) +{ + sim_lock_state* sim_lock = NULL; + sim_state_result* ss; + unsigned char* apdu_data; + int i; + + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + if (result->msg_id == EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE + || result->msg_id == EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE) { + apdu_data = (unsigned char*)result->data; + for (i = 0; i < result->arg2; i++) + syslog(LOG_DEBUG, "apdu data %d : %d ", i, apdu_data[i]); + + if (judge_data.expect == EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE; + } else if (judge_data.expect == EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE; + } + + } else if (result->msg_id == EVENT_OPEN_LOGICAL_CHANNEL_DONE) { + syslog(LOG_DEBUG, "open logical channel respond session id : %d\n", result->arg2); + global_data.current_channel_session_id = result->arg2; + + if (judge_data.expect == EVENT_OPEN_LOGICAL_CHANNEL_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_OPEN_LOGICAL_CHANNEL_DONE; + } + + } else if (result->msg_id == MSG_SIM_STATE_CHANGE_IND) { + ss = result->data; + if (ss != NULL) { + syslog(LOG_DEBUG, "response strings name : %s\n", ss->name); + if (strcmp(ss->name, "Present") == 0) { + syslog(LOG_DEBUG, "response is sim present : %d\n", ss->value); + } else if (strcmp(ss->name, "PinRequired") == 0) { + syslog(LOG_DEBUG, "response pin required type : %s\n", (char*)ss->data); + } else if (strcmp(ss->name, "LockedPins") == 0) { + sim_lock = ss->data; + if (sim_lock != NULL) { + for (i = 0; i < result->arg2; ++i) { + syslog(LOG_DEBUG, "response locked pins type : %s\n", + sim_lock->sim_pwd_type[i]); + } + } + } else if (strcmp(ss->name, "Retries") == 0) { + sim_lock = ss->data; + if (sim_lock != NULL) { + for (i = 0; i < result->arg2; ++i) { + syslog(LOG_DEBUG, "response locked pins type : %s\n", + sim_lock->sim_pwd_type[i]); + syslog(LOG_DEBUG, "response locked pins retries : %d\n", + sim_lock->retry_count[i]); + } + } + } + } + } else if (result->msg_id == EVENT_CLOSE_LOGICAL_CHANNEL_DONE) { + if (judge_data.expect == EVENT_CLOSE_LOGICAL_CHANNEL_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_CLOSE_LOGICAL_CHANNEL_DONE; + } + } else if (result->msg_id == EVENT_UICC_ENABLEMENT_SET_DONE) { + if (judge_data.expect == EVENT_UICC_ENABLEMENT_SET_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_UICC_ENABLEMENT_SET_DONE; + } + } else if (result->msg_id == EVENT_ENTER_SIM_PIN_DONE) { + if (judge_data.expect == EVENT_ENTER_SIM_PIN_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_ENTER_SIM_PIN_DONE; + } + } else if (result->msg_id == EVENT_CHANGE_SIM_PIN_DONE) { + if (judge_data.expect == EVENT_CHANGE_SIM_PIN_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_CHANGE_SIM_PIN_DONE; + } + } else if (result->msg_id == EVENT_LOCK_SIM_PIN_DONE) { + if (judge_data.expect == EVENT_LOCK_SIM_PIN_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_LOCK_SIM_PIN_DONE; + } + } else if (result->msg_id == EVENT_UNLOCK_SIM_PIN_DONE) { + if (judge_data.expect == EVENT_UNLOCK_SIM_PIN_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_UNLOCK_SIM_PIN_DONE; + } + } +} + +int tapi_sim_listen_sim_test(int slot_id, int event_id) +{ + global_data_init(); + + if (event_id != MSG_SIM_STATE_CHANGE_IND && event_id != MSG_SIM_UICC_APP_ENABLED_CHANGE_IND) { + syslog(LOG_ERR, "event id error\n"); + return -1; + } + + if (event_id == MSG_SIM_STATE_CHANGE_IND) { + global_data.sim_state_change_watch_id + = tapi_sim_register(get_tapi_ctx(), slot_id, event_id, NULL, tele_sim_async_fun); + + if (global_data.sim_state_change_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, MSG_SIM_STATE_CHANGE_IND, watch id < 0\n", + __func__, slot_id); + return -1; + } + } else { + global_data.sim_uicc_app_enabled_change_watch_id = tapi_sim_register(get_tapi_ctx(), slot_id, event_id, NULL, tele_sim_async_fun); + + if (global_data.sim_uicc_app_enabled_change_watch_id < 0) { + syslog(LOG_ERR, "%s, slot_id: %d, MSG_SIM_UICC_APP_ENABLED_CHANGE_IND, watch id < 0\n", + __func__, slot_id); + return -1; + } + } + + return 0; +} + +int tapi_sim_unlisten_sim_test(int slot_id, int watch_id) +{ + if (watch_id == -1 + || (watch_id != global_data.sim_state_change_watch_id + && watch_id != global_data.sim_uicc_app_enabled_change_watch_id)) { + syslog(LOG_ERR, "watch id error\n"); + return -1; + } + + int ret = tapi_sim_unregister(get_tapi_ctx(), watch_id); + + if (ret == 0) { + if (watch_id == global_data.sim_state_change_watch_id) { + global_data.sim_state_change_watch_id = -1; + } else { + global_data.sim_uicc_app_enabled_change_watch_id = -1; + } + } + + return ret; +} + +int tapi_open_logical_channel_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_OPEN_LOGICAL_CHANNEL_DONE; + unsigned char aid[] = "A0000000871002FF86FFFF89FFFFFFFF"; + int res = 0; + global_data.current_channel_session_id = -1; + + int ret = tapi_sim_open_logical_channel(get_tapi_ctx(), slot_id, + EVENT_OPEN_LOGICAL_CHANNEL_DONE, aid, 16, tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_open_logical_channel execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.current_channel_session_id == -1) { + syslog(LOG_ERR, "session id is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_close_logical_channel_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_CLOSE_LOGICAL_CHANNEL_DONE; + + if (global_data.current_channel_session_id == -1) { + syslog(LOG_ERR, "session id is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + int ret = tapi_sim_close_logical_channel(get_tapi_ctx(), slot_id, + EVENT_CLOSE_LOGICAL_CHANNEL_DONE, global_data.current_channel_session_id, + tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_close_logical_channel execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + global_data.current_channel_session_id = -1; + return res; +} + +static int hex_string_to_byte_array(char* hex_str, unsigned char* byte_arr, int arr_len) +{ + char* str; + int len; + int i, j; + int ret = -EINVAL; + + if (hex_str == NULL) + return ret; + + len = strlen(hex_str); + if (!len || (len % 2) != 0 || len > arr_len * 2) + return ret; + + str = strdup(hex_str); + if (str == NULL) + return ret; + + for (i = 0, j = 0; i < len; i += 2, j++) { + // uppercase char 'a'~'f' + if (str[i] >= 'a' && str[i] <= 'f') + str[i] = str[i] & ~0x20; + + if (str[i + 1] >= 'a' && str[i + 1] <= 'f') + str[i + 1] = str[i + 1] & ~0x20; + + // convert the first character to decimal. + if (str[i] >= 'A' && str[i] <= 'F') + byte_arr[j] = (str[i] - 'A' + 10) << 4; + else if (str[i] >= '0' && str[i] <= '9') + byte_arr[j] = (str[i] & ~0x30) << 4; + else + goto out; + + // convert the second character to decimal + // and combine with the previous decimal. + if (str[i + 1] >= 'A' && str[i + 1] <= 'F') + byte_arr[j] |= (str[i + 1] - 'A' + 10); + else if (str[i + 1] >= '0' && str[i + 1] <= '9') + byte_arr[j] |= (str[i + 1] & ~0x30); + else + goto out; + } + + ret = 0; +out: + free(str); + + return ret; +} + +int tapi_transmit_apdu_basic_channel_test(int slot_id) +{ + char data[] = "A0B000010473656E669000"; + int res = 0; + unsigned char pdu[128]; + judge_data_init(); + judge_data.expect = EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE; + int len = strlen(data) / 2; + + if (hex_string_to_byte_array(data, pdu, 128) != 0) { + syslog(LOG_ERR, "hex_string_to_byte_array execute fail"); + res = -1; + goto on_exit; + } + + int ret = tapi_sim_transmit_apdu_basic_channel(get_tapi_ctx(), slot_id, + EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, pdu, len, tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_transmit_apdu_basic_channel execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_transmit_apdu_logical_channel_test(int slot_id) +{ + int res = 0; + + if (global_data.current_channel_session_id == -1) { + syslog(LOG_ERR, "session is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + unsigned char pdu[128]; + char data[] = "FFF2000000"; + int len = strlen(data) / 2; + + if (hex_string_to_byte_array(data, pdu, 128) != 0) { + syslog(LOG_ERR, "hex_string_to_byte_array execute fail in %s", __func__); + res = -1; + goto on_exit; + } + + judge_data_init(); + judge_data.expect = EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE; + + int ret = tapi_sim_transmit_apdu_logical_channel(get_tapi_ctx(), slot_id, + EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, global_data.current_channel_session_id, + pdu, len, tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_transmit_apdu_logical_channel execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sim_open_close_logical_channel_numerous(int slot_id) +{ + for (int i = 0; i < 10; i++) { + if (tapi_open_logical_channel_test(slot_id)) + return -1; + + if (tapi_close_logical_channel_test(slot_id)) + return -1; + } + + return 0; +} + +int sim_transmit_apdu_by_logical_channel(int slot_id) +{ + int ret = -1; + int res = 0; + ret = tapi_open_logical_channel_test(slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_open_logical_channel_test execute fail in %s", __func__); + res = -1; + goto on_exit; + } + + ret = tapi_transmit_apdu_logical_channel_test(slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_transmit_apdu_logical_channel_test execute fail in %s", __func__); + res = -1; + goto on_exit; + } + + ret = tapi_close_logical_channel_test(slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_close_logical_channel_test execute fail in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_set_uicc_enablement_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_UICC_ENABLEMENT_SET_DONE; + + int ret = tapi_sim_set_uicc_enablement(get_tapi_ctx(), slot_id, + EVENT_UICC_ENABLEMENT_SET_DONE, 1, tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_set_uicc_enablement execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_get_uicc_enablement_test(int slot_id) +{ + tapi_sim_uicc_app_state state = SIM_UICC_APP_UNKNOWN; + int ret = tapi_sim_get_uicc_enablement(get_tapi_ctx(), slot_id, &state); + syslog(LOG_DEBUG, "%s, ret: %d, state: %d", __func__, ret, (int)state); + + return ret || state != SIM_UICC_APP_ACTIVE; +} + +int tapi_sim_enter_pin_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_ENTER_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_enter_pin(get_tapi_ctx(), slot_id, + EVENT_ENTER_SIM_PIN_DONE, "pin2", "1234", tele_sim_async_fun); + + if (ret) { + syslog(LOG_DEBUG, "tapi_sim_enter_pin execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_change_pin_test(int slot_id, char* old_pin, char* new_pin) +{ + syslog(LOG_DEBUG, "%s, old_pin: %s, new_pin: %s", __func__, old_pin, new_pin); + judge_data_init(); + judge_data.expect = EVENT_CHANGE_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_change_pin(get_tapi_ctx(), slot_id, + EVENT_CHANGE_SIM_PIN_DONE, "pin2", old_pin, new_pin, tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_change_pin execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sim_change_pin_test(int slot_id) +{ + int ret = -1; + int res = 0; + ret = tapi_sim_change_pin_test(slot_id, "1234", "2345"); + if (ret) { + syslog(LOG_DEBUG, "change pin from \"1234\" to \"2345\" fail"); + res = -1; + goto on_exit; + } + + ret = tapi_sim_change_pin_test(slot_id, "2345", "1234"); + if (ret) { + syslog(LOG_DEBUG, "change pin from \"2345\" to \"1234\" fail"); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_lock_pin_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_LOCK_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_lock_pin(get_tapi_ctx(), slot_id, + EVENT_LOCK_SIM_PIN_DONE, "pin", "1234", tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_lock_pin execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_unlock_pin_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_UNLOCK_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_unlock_pin(get_tapi_ctx(), slot_id, + EVENT_UNLOCK_SIM_PIN_DONE, "pin", "1234", tele_sim_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_sim_unlock_pin execute fail in %s, ret: %d", __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void tele_phonebook_async_fun(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->msg_id == EVENT_LOAD_ADN_ENTRIES_DONE) { + syslog(LOG_DEBUG, "adn entries : %s\n", (char*)result->data); + if (judge_data.expect == EVENT_LOAD_ADN_ENTRIES_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_LOAD_ADN_ENTRIES_DONE; + } + } else if (result->msg_id == EVENT_LOAD_FDN_ENTRIES_DONE) { + if (judge_data.expect == EVENT_LOAD_FDN_ENTRIES_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_LOAD_FDN_ENTRIES_DONE; + } + } else if (result->msg_id == EVENT_INSERT_FDN_ENTRIES_DONE) { + if (judge_data.expect == EVENT_INSERT_FDN_ENTRIES_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_INSERT_FDN_ENTRIES_DONE; + } + } else if (result->msg_id == EVENT_UPDATE_FDN_ENTRIES_DONE) { + if (judge_data.expect == EVENT_UPDATE_FDN_ENTRIES_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_UPDATE_FDN_ENTRIES_DONE; + } + } else if (result->msg_id == EVENT_DELETE_FDN_ENTRIES_DONE) { + if (judge_data.expect == EVENT_DELETE_FDN_ENTRIES_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_DELETE_FDN_ENTRIES_DONE; + } + } +} + +int tapi_phonebook_load_adn_entries_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_LOAD_ADN_ENTRIES_DONE; + int ret = tapi_phonebook_load_adn_entries(get_tapi_ctx(), slot_id, + EVENT_LOAD_ADN_ENTRIES_DONE, tele_phonebook_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_phonebook_load_adn_entries execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_load_fdn_entries_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_LOAD_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_load_fdn_entries(get_tapi_ctx(), slot_id, + EVENT_LOAD_FDN_ENTRIES_DONE, tele_phonebook_async_fun); + if (ret) { + syslog(LOG_DEBUG, "tapi_phonebook_load_fdn_entries execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_insert_fdn_entry_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_INSERT_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_insert_fdn_entry(get_tapi_ctx(), slot_id, + EVENT_INSERT_FDN_ENTRIES_DONE, "cmcc", "10086", "1234", + tele_phonebook_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_phonebook_insert_fdn_entry execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_DEBUG, "tele_phonebook_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_update_fdn_entry_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_UPDATE_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_update_fdn_entry(get_tapi_ctx(), 0, + EVENT_UPDATE_FDN_ENTRIES_DONE, 1, "cmcc", "1008601", "1234", + tele_phonebook_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_phonebook_update_fdn_entry execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_delete_fdn_entry_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DELETE_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_delete_fdn_entry(get_tapi_ctx(), 0, + EVENT_DELETE_FDN_ENTRIES_DONE, 1, "1234", tele_phonebook_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_phonebook_delete_fdn_entry execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} \ No newline at end of file diff --git a/test/telephony_sim_test.h b/test/telephony_sim_test.h new file mode 100644 index 0000000..c1de2d4 --- /dev/null +++ b/test/telephony_sim_test.h @@ -0,0 +1,41 @@ +#ifndef TELEPHONY_SIM_TEST_H_ +#define TELEPHONY_SIM_TEST_H_ + +#include "telephony_test.h" +#define TEST_COUNT 10 + +int tapi_sim_has_icc_card_test(int slot_id); +int tapi_sim_multi_has_icc_card_test(int slot_id); +int tapi_sim_get_sim_operator_test(int slot_id, const char* expect_res); +int tapi_sim_multi_get_sim_operator(int slot_id, const char* expect_res); +int tapi_sim_get_sim_operator_name_test(int slot_id, const char* expect_res); +int tapi_sim_get_sim_operator_name_numerous(int slot_id, const char* expect_res); +int tapi_sim_get_sim_subscriber_id_test(int slot_id, const char* expect_res); +int tapi_sim_multi_get_sim_subscriber_id_test(int slot_id, const char* expect_res); +int tapi_sim_get_sim_iccid_test(int slot_id, const char* expect_res); +int tapi_sim_multi_get_sim_iccid_test(int slot_id, const char* expect_res); +int tapi_sim_get_ef_msisdn_test(int slot_id, const char* expect_res); +int tapi_sim_multi_get_ef_msisdn_test(int slot_id, const char* expect_res); +int tapi_sim_listen_sim_test(int slot_id, int event_id); +int tapi_sim_unlisten_sim_test(int slot_id, int watch_id); +int tapi_open_logical_channel_test(int slot_id); +int tapi_close_logical_channel_test(int slot_id); +int tapi_transmit_apdu_basic_channel_test(int slot_id); +int tapi_sim_get_state_test(int slot_id); +int tapi_sim_set_uicc_enablement_test(int slot_id); +int tapi_sim_get_uicc_enablement_test(int slot_id); +int tapi_sim_enter_pin_test(int slot_id); +int tapi_sim_change_pin_test(int slot_id, char* old_pin, char* new_pin); +int tapi_sim_lock_pin_test(int slot_id); +int tapi_sim_unlock_pin_test(int slot_id); +int tapi_phonebook_load_adn_entries_test(int slot_id); +int tapi_phonebook_load_fdn_entries_test(int slot_id); +int tapi_phonebook_insert_fdn_entry_test(int slot_id); +int tapi_phonebook_update_fdn_entry_test(int slot_id); +int tapi_phonebook_delete_fdn_entry_test(int slot_id); +int sim_open_close_logical_channel_numerous(int slot_id); +int tapi_transmit_apdu_logical_channel_test(int slot_id); +int sim_transmit_apdu_by_logical_channel(int slot_id); +int sim_change_pin_test(int slot_id); + +#endif \ No newline at end of file diff --git a/test/telephony_sms_test.c b/test/telephony_sms_test.c new file mode 100644 index 0000000..dff6b8d --- /dev/null +++ b/test/telephony_sms_test.c @@ -0,0 +1,190 @@ +#include "telephony_sms_test.h" +#include "telephony_call_test.h" +#include "telephony_common_test.h" +#include "telephony_ims_test.h" +#include + +extern struct judge_type judge_data; + +static void tele_sms_event_response(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id: %d result err, return.\n", __func__, result->msg_id); + return; + } + + judge_data.result = 0; + + if (result->msg_id == EVENT_SEND_MESSAGE_DONE) { + syslog(LOG_DEBUG, "send message successed, uuid : %s\n", (char*)result->data); + judge_data.flag = EVENT_SEND_MESSAGE_DONE; + } else if (result->msg_id == EVENT_SEND_DATA_MESSAGE_DONE) { + syslog(LOG_DEBUG, "send data message successed"); + judge_data.flag = EVENT_SEND_DATA_MESSAGE_DONE; + } +} + +int sms_send_message_test(tapi_context context, int slot_id, char* number, char* text) +{ + if (context == NULL || number == NULL || text == NULL) { + syslog(LOG_ERR, "%s, number: %s, text: %s", __func__, number, text); + return -EINVAL; + } + + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_SEND_MESSAGE_DONE; + + int ret = tapi_sms_send_message(context, slot_id, 0, number, text, + EVENT_SEND_MESSAGE_DONE, tele_sms_event_response); + if (ret) { + syslog(LOG_ERR, "tapi_sms_send_message execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sms_event_response is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sms_set_service_center_number_test(int slot_id) +{ + int ret = tapi_sms_set_service_center_address(get_tapi_ctx(), slot_id, "10086"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int sms_check_service_center_number_test(int slot_id) +{ + char* smsc_addr_rtn = NULL; + int ret = tapi_sms_get_service_center_address(get_tapi_ctx(), slot_id, &smsc_addr_rtn); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d, smsc_addr_rtn: %s", __func__, slot_id, ret, smsc_addr_rtn); + + return ret || strcmp(smsc_addr_rtn, "10086") != 0; +} + +int sms_send_data_message_test(int slot_id, char* to, int port, char* text) +{ + if (to == NULL) { + syslog(LOG_ERR, "to is null in %s", __func__); + return -EINVAL; + } + + if (text == NULL) { + syslog(LOG_ERR, "text is null in %s", __func__); + return -EINVAL; + } + + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_SEND_DATA_MESSAGE_DONE; + int ret = tapi_sms_send_data_message(get_tapi_ctx(), slot_id, 0, to, port, text, + EVENT_SEND_DATA_MESSAGE_DONE, tele_sms_event_response); + if (ret) { + syslog(LOG_ERR, "tapi_sms_send_data_message execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_sms_event_response is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sms_send_message_in_dialing(int slot_id, char* to, char* text) +{ + int ret = -1; + int res = 0; + + ret = tapi_call_dial_test(slot_id, to, 0); + if (ret) { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = sms_send_message_test(get_tapi_ctx(), slot_id, to, text); + if (ret) { + syslog(LOG_ERR, "sms_send_message_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_call_hanup_current_call_test(slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_call_hanup_current_call_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sms_send_data_message_in_dialing(int slot_id, char* to, char* text, int port) +{ + int ret = -1; + int res = 0; + + ret = tapi_call_dial_test(slot_id, to, 0); + if (ret) { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = sms_send_data_message_test(slot_id, to, port, text); + if (ret) { + syslog(LOG_ERR, "sms_send_data_message_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_call_hanup_current_call_test(slot_id); + if (ret) { + syslog(LOG_ERR, "tapi_call_hanup_current_call_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} \ No newline at end of file diff --git a/test/telephony_sms_test.h b/test/telephony_sms_test.h new file mode 100644 index 0000000..4cc3dd2 --- /dev/null +++ b/test/telephony_sms_test.h @@ -0,0 +1,14 @@ +#ifndef TELEPHONY_SMS_TEST_H_ +#define TELEPHONY_SMS_TEST_H_ + +#include "telephony_test.h" + +int sms_send_message_test(tapi_context context, int slot_id, char* number, char* text); + +int sms_set_service_center_number_test(int slot_id); +int sms_check_service_center_number_test(int slot_id); +int sms_send_data_message_test(int slot_id, char* to, int port, char* text); +int sms_send_message_in_dialing(int slot_id, char* to, char* text); +int sms_send_data_message_in_dialing(int slot_id, char* to, char* text, int port); + +#endif /* TELEPHONY_SMS_TEST_H_ */ diff --git a/test/telephony_ss_test.c b/test/telephony_ss_test.c new file mode 100644 index 0000000..81d2a0f --- /dev/null +++ b/test/telephony_ss_test.c @@ -0,0 +1,589 @@ +#include "telephony_ss_test.h" + +extern struct judge_type judge_data; + +static struct { + int call_barring_property_change_watch_id; + int ussd_property_change_watch_id; + int ussd_notification_received_watch_id; + int ussd_request_received_watch_id; + char cf_number[64]; + int fdn_enable; + int cf_type; + int cw; +} global_data; + +static void ss_signal_change(tapi_async_result* result) +{ + tapi_call_barring_info* cb_value; + int signal = result->msg_id; + int slot_id = result->arg1; + + switch (signal) { + case MSG_CALL_BARRING_PROPERTY_CHANGE_IND: + cb_value = result->data; + syslog(LOG_DEBUG, "call barring service %s changed to %s in slot[%d] \n", + cb_value->service_type, cb_value->value, slot_id); + break; + case MSG_USSD_PROPERTY_CHANGE_IND: + syslog(LOG_DEBUG, "ussd state changed to %s in slot[%d] \n", (char*)result->data, slot_id); + break; + case MSG_USSD_NOTIFICATION_RECEIVED_IND: + syslog(LOG_DEBUG, "ussd notification message %s received in slot[%d] \n", + (char*)result->data, slot_id); + break; + case MSG_USSD_REQUEST_RECEIVED_IND: + syslog(LOG_DEBUG, "ussd request message %s received in slot[%d] \n", + (char*)result->data, slot_id); + break; + default: + break; + } +} + +int tapi_listen_ss_test(int slot_id) +{ + global_data.call_barring_property_change_watch_id = -1; + global_data.call_barring_property_change_watch_id = tapi_ss_register(get_tapi_ctx(), slot_id, MSG_CALL_BARRING_PROPERTY_CHANGE_IND, + NULL, ss_signal_change); + if (global_data.call_barring_property_change_watch_id < 0) { + syslog(LOG_ERR, "call barring property change register fail, ret: %d", + global_data.call_barring_property_change_watch_id); + return -1; + } + + global_data.ussd_property_change_watch_id = -1; + global_data.ussd_property_change_watch_id = tapi_ss_register(get_tapi_ctx(), slot_id, MSG_USSD_PROPERTY_CHANGE_IND, + NULL, ss_signal_change); + if (global_data.ussd_property_change_watch_id < 0) { + syslog(LOG_ERR, "ussd property change register fail, ret: %d", + global_data.ussd_property_change_watch_id); + return -1; + } + + global_data.ussd_notification_received_watch_id = -1; + global_data.ussd_notification_received_watch_id = tapi_ss_register(get_tapi_ctx(), slot_id, MSG_USSD_NOTIFICATION_RECEIVED_IND, + NULL, ss_signal_change); + if (global_data.ussd_notification_received_watch_id < 0) { + syslog(LOG_DEBUG, "ussd notification received register fail, ret: %d", + global_data.ussd_notification_received_watch_id); + return -1; + } + + global_data.ussd_request_received_watch_id = -1; + global_data.ussd_request_received_watch_id = tapi_ss_register(get_tapi_ctx(), slot_id, MSG_USSD_REQUEST_RECEIVED_IND, + NULL, ss_signal_change); + if (global_data.ussd_request_received_watch_id < 0) { + syslog(LOG_ERR, "ussd request received register fail, ret: %d", + global_data.ussd_request_received_watch_id); + return -1; + } + + return 0; +} + +int tapi_unlisten_ss_test(void) +{ + int ret; + if (global_data.call_barring_property_change_watch_id < 0 + || global_data.ussd_property_change_watch_id < 0 + || global_data.ussd_notification_received_watch_id < 0 + || global_data.ussd_request_received_watch_id < 0) { + return -1; + } + + ret = -1; + ret = tapi_ss_unregister(get_tapi_ctx(), global_data.call_barring_property_change_watch_id); + if (ret < 0) { + syslog(LOG_DEBUG, "call barring property change unregister fail, ret: %d", ret); + return -1; + } + + ret = -1; + ret = tapi_ss_unregister(get_tapi_ctx(), global_data.ussd_property_change_watch_id); + if (ret < 0) { + syslog(LOG_ERR, "ussd property change unregister fail, ret: %d", ret); + return -1; + } + + ret = -1; + ret = tapi_ss_unregister(get_tapi_ctx(), global_data.ussd_notification_received_watch_id); + if (ret < 0) { + syslog(LOG_DEBUG, "ussd notification received unregister fail, ret: %d", ret); + return -1; + } + + ret = -1; + ret = tapi_ss_unregister(get_tapi_ctx(), global_data.ussd_request_received_watch_id); + if (ret < 0) { + syslog(LOG_ERR, "ussd request received unregister fail, ret: %d", ret); + return -1; + } + + return 0; +} + +static void tele_ss_async_fun(tapi_async_result* result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, result->msg_id); + return; + } + + if (result->msg_id == EVENT_QUERY_ALL_CALL_BARRING_DONE) { + if (judge_data.expect == EVENT_QUERY_ALL_CALL_BARRING_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_ALL_CALL_BARRING_DONE; + } + } else if (result->msg_id == EVENT_REQUEST_CALL_BARRING_DONE) { + if (judge_data.expect == EVENT_REQUEST_CALL_BARRING_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_REQUEST_CALL_BARRING_DONE; + } + } else if (result->msg_id == EVENT_CALL_BARRING_PASSWD_CHANGE_DONE) { + if (judge_data.expect == EVENT_CALL_BARRING_PASSWD_CHANGE_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_CALL_BARRING_PASSWD_CHANGE_DONE; + } + } else if (result->msg_id == EVENT_DISABLE_ALL_INCOMING_DONE) { + if (judge_data.expect == EVENT_DISABLE_ALL_INCOMING_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_DISABLE_ALL_INCOMING_DONE; + } + } else if (result->msg_id == EVENT_DISABLE_ALL_OUTGOING_DONE) { + if (judge_data.expect == EVENT_DISABLE_ALL_OUTGOING_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_DISABLE_ALL_OUTGOING_DONE; + } + } else if (result->msg_id == EVENT_DISABLE_ALL_CALL_BARRINGS_DONE) { + if (judge_data.expect == EVENT_DISABLE_ALL_CALL_BARRINGS_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_DISABLE_ALL_CALL_BARRINGS_DONE; + } + } else if (result->msg_id == EVENT_REQUEST_CALL_FORWARDING_DONE) { + if (judge_data.expect == EVENT_REQUEST_CALL_FORWARDING_DONE) { + if (result->arg1 == global_data.cf_type && result->arg2 == 1) { + judge_data.result = 0; + judge_data.flag = EVENT_REQUEST_CALL_FORWARDING_DONE; + } + } + } else if (result->msg_id == EVENT_QUERY_CALL_FORWARDING_DONE) { + tapi_call_forward_info* cf_info = result->data; + if (judge_data.expect == EVENT_QUERY_CALL_FORWARDING_DONE) { + if (result->arg1 == global_data.cf_type && cf_info != NULL + && !strcmp(global_data.cf_number, cf_info->phone_number.number)) { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_CALL_FORWARDING_DONE; + } + } + } else if (result->msg_id == EVENT_REQUEST_CALL_WAITING_DONE) { + if (judge_data.expect == EVENT_REQUEST_CALL_WAITING_DONE) { + if (result->arg2 == global_data.cw) { + judge_data.result = 0; + judge_data.flag = EVENT_REQUEST_CALL_WAITING_DONE; + } + } + } else if (result->msg_id == EVENT_QUERY_CALL_WAITING_DONE) { + if (judge_data.expect == EVENT_QUERY_CALL_WAITING_DONE) { + if (result->arg2 == global_data.cw) { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_CALL_WAITING_DONE; + } + } + } else if (result->msg_id == EVENT_ENABLE_FDN_DONE) { + if (judge_data.expect == EVENT_ENABLE_FDN_DONE) { + judge_data.result = 0; + judge_data.flag = EVENT_ENABLE_FDN_DONE; + } + } else if (result->msg_id == EVENT_QUERY_FDN_DONE) { + if (judge_data.expect == EVENT_QUERY_FDN_DONE) { + if (result->arg2 == global_data.fdn_enable) { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_FDN_DONE; + } + } + } +} + +int tapi_ss_request_call_barring_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_ALL_CALL_BARRING_DONE; + int ret = tapi_ss_request_call_barring(get_tapi_ctx(), slot_id, + EVENT_QUERY_ALL_CALL_BARRING_DONE, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_request_call_barring execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_set_call_barring_option_test(int slot_id, char* facility, char* pin2) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_CALL_BARRING_DONE; + int ret = tapi_ss_set_call_barring_option(get_tapi_ctx(), slot_id, + EVENT_REQUEST_CALL_BARRING_DONE, "AI", "1234", tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_set_call_barring_option execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_get_call_barring_option_test(int slot_id, char* key, char* expect) +{ + char* result = NULL; + int ret = tapi_ss_get_call_barring_option(get_tapi_ctx(), slot_id, key, &result); + syslog(LOG_INFO, "%s, ret: %d, result: %s", __func__, ret, result); + return ret || result == NULL || strcmp(expect, result); +} + +int tapi_ss_change_call_barring_password_test(int slot_id, char* old_passwd, char* new_passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_CALL_BARRING_PASSWD_CHANGE_DONE; + int ret = tapi_ss_change_call_barring_password(get_tapi_ctx(), slot_id, + EVENT_CALL_BARRING_PASSWD_CHANGE_DONE, old_passwd, new_passwd, + tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_change_call_barring_password execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_disable_all_incoming_test(int slot_id, char* passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DISABLE_ALL_INCOMING_DONE; + int ret = tapi_ss_disable_all_incoming(get_tapi_ctx(), slot_id, + EVENT_DISABLE_ALL_INCOMING_DONE, passwd, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_disable_all_incoming execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_disable_all_outgoing_test(int slot_id, char* passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DISABLE_ALL_OUTGOING_DONE; + int ret = tapi_ss_disable_all_outgoing(get_tapi_ctx(), slot_id, + EVENT_DISABLE_ALL_OUTGOING_DONE, passwd, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_disable_all_outgoing execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_disable_all_call_barrings_test(int slot_id, char* passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DISABLE_ALL_CALL_BARRINGS_DONE; + int ret = tapi_ss_disable_all_call_barrings(get_tapi_ctx(), slot_id, + EVENT_DISABLE_ALL_CALL_BARRINGS_DONE, passwd, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_disable_all_call_barrings execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_set_call_forwarding_option_test(int slot_id, int cf_type, char* number) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_CALL_FORWARDING_DONE; + memset(global_data.cf_number, 0, sizeof(global_data.cf_number)); + strcpy(global_data.cf_number, number); + global_data.cf_type = cf_type; + int ret = tapi_ss_set_call_forwarding_option(get_tapi_ctx(), slot_id, + EVENT_REQUEST_CALL_FORWARDING_DONE, cf_type, BEARER_CLASS_VOICE, number, + tele_ss_async_fun); + + if (ret) { + syslog(LOG_ERR, "tapi_ss_set_call_forwarding_option execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_get_call_forwarding_option_test(int slot_id, int cf_type) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_CALL_FORWARDING_DONE; + global_data.cf_type = cf_type; + int ret = tapi_ss_query_call_forwarding_option(get_tapi_ctx(), slot_id, + EVENT_QUERY_CALL_FORWARDING_DONE, cf_type, BEARER_CLASS_VOICE, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_query_call_forwarding_option execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_set_call_waiting_test(int slot_id, bool enable) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_CALL_WAITING_DONE; + global_data.cw = (int)enable; + int ret = tapi_ss_set_call_waiting(get_tapi_ctx(), slot_id, + EVENT_REQUEST_CALL_WAITING_DONE, enable, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_set_call_waiting execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_get_call_waiting_test(int slot_id, bool expect) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_CALL_WAITING_DONE; + global_data.cw = (int)expect; + int ret = tapi_ss_get_call_waiting(get_tapi_ctx(), slot_id, + EVENT_QUERY_CALL_WAITING_DONE, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_get_call_waiting execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_enable_fdn_test(int slot_id, bool enable, char* passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_ENABLE_FDN_DONE; + int ret = tapi_ss_enable_fdn(get_tapi_ctx(), slot_id, EVENT_ENABLE_FDN_DONE, enable, + passwd, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_enable_fdn execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_query_fdn_test(int slot_id, bool expect) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_FDN_DONE; + global_data.fdn_enable = (int)expect; + int ret = tapi_ss_query_fdn(get_tapi_ctx(), slot_id, EVENT_QUERY_FDN_DONE, tele_ss_async_fun); + if (ret) { + syslog(LOG_ERR, "tapi_ss_query_fdn execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} \ No newline at end of file diff --git a/test/telephony_ss_test.h b/test/telephony_ss_test.h new file mode 100644 index 0000000..20f44a8 --- /dev/null +++ b/test/telephony_ss_test.h @@ -0,0 +1,22 @@ +#ifndef TELEPHONY_SS_TEST_H_ +#define TELEPHONY_SS_TEST_H_ + +#include "telephony_test.h" + +int tapi_listen_ss_test(int slot_id); +int tapi_unlisten_ss_test(void); +int tapi_ss_request_call_barring_test(int slot_id); +int tapi_ss_set_call_barring_option_test(int slot_id, char* facility, char* pin2); +int tapi_ss_get_call_barring_option_test(int slot_id, char* key, char* expect); +int tapi_ss_change_call_barring_password_test(int slot_id, char* old_passwd, char* new_passwd); +int tapi_ss_disable_all_incoming_test(int slot_id, char* passwd); +int tapi_ss_disable_all_outgoing_test(int slot_id, char* passwd); +int tapi_ss_disable_all_call_barrings_test(int slot_id, char* passwd); +int tapi_ss_set_call_forwarding_option_test(int slot_id, int cf_type, char* number); +int tapi_ss_get_call_forwarding_option_test(int slot_id, int cf_type); +int tapi_ss_set_call_waiting_test(int slot_id, bool enable); +int tapi_ss_get_call_waiting_test(int slot_id, bool expect); +int tapi_ss_enable_fdn_test(int slot_id, bool enable, char* passwd); +int tapi_ss_query_fdn_test(int slot_id, bool expect); + +#endif /* TELEPHONY_SS_TEST_H_ */ diff --git a/test/telephony_test.h b/test/telephony_test.h new file mode 100644 index 0000000..fcdfe94 --- /dev/null +++ b/test/telephony_test.h @@ -0,0 +1,105 @@ +#ifndef TELEPHONY_TEST_H_ +#define TELEPHONY_TEST_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define context tapi_test_context + +// Generic Callback Event +#define EVENT_MODEM_LIST_QUERY_DONE 0x1001 +#define EVENT_RADIO_STATE_SET_DONE 0x1002 +#define EVENT_RAT_MODE_SET_DONE 0x1003 +#define EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE 0x1004 +#define EVENT_MODEM_ENABLE_DONE 0x1005 +#define EVENT_MODEM_STATUS_QUERY_DONE 0x1006 +#define EVENT_OEM_RIL_REQUEST_RAW_DONE 0x1007 +#define EVENT_OEM_RIL_REQUEST_STRINGS_DONE 0x1008 + +// Data Callback Event +#define EVENT_APN_LOADED_DONE 0x1009 +#define EVENT_APN_ADD_DONE 0x1010 +#define EVENT_APN_EDIT_DONE 0x101A +#define EVENT_APN_REMOVAL_DONE 0x101B +#define EVENT_APN_RESTORE_DONE 0x101C +#define EVENT_DATA_ALLOWED_DONE 0x101D +#define EVENT_DATA_CALL_LIST_QUERY_DONE 0x101E +#define EVENT_REQUEST_SCREEN_STATE_DONE 0x101F + +// SIM Callback Event +#define EVENT_CHANGE_SIM_PIN_DONE 0x21 +#define EVENT_ENTER_SIM_PIN_DONE 0x22 +#define EVENT_RESET_SIM_PIN_DONE 0x23 +#define EVENT_LOCK_SIM_PIN_DONE 0x24 +#define EVENT_UNLOCK_SIM_PIN_DONE 0x25 +#define EVENT_OPEN_LOGICAL_CHANNEL_DONE 0x26 +#define EVENT_CLOSE_LOGICAL_CHANNEL_DONE 0x27 +#define EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE 0x28 +#define EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE 0x29 +#define EVENT_UICC_ENABLEMENT_SET_DONE 0x2A + +// Network Callback Event +#define EVENT_NETWORK_SCAN_DONE 0x31 +#define EVENT_REGISTER_AUTO_DONE 0x32 +#define EVENT_REGISTER_MANUAL_DONE 0x33 +#define EVENT_QUERY_REGISTRATION_INFO_DONE 0x34 +#define EVENT_QUERY_SERVING_CELL_DONE 0x35 +#define EVENT_QUERY_NEIGHBOURING_CELL_DONE 0x36 +#define EVENT_NETWORK_SET_CELL_INFO_LIST_RATE_DONE 0x37 + +// SS Callback Event +#define EVENT_REQUEST_CALL_BARRING_DONE 0x41 +#define EVENT_CALL_BARRING_PASSWD_CHANGE_DONE 0x42 +#define EVENT_DISABLE_ALL_CALL_BARRINGS_DONE 0x43 +#define EVENT_DISABLE_ALL_INCOMING_DONE 0x44 +#define EVENT_DISABLE_ALL_OUTGOING_DONE 0x45 +#define EVENT_REQUEST_CALL_FORWARDING_DONE 0x46 +#define EVENT_DISABLE_CALL_FORWARDING_DONE 0x47 +#define EVENT_CANCEL_USSD_DONE 0x48 +#define EVENT_REQUEST_CALL_WAITING_DONE 0x49 +#define EVENT_SEND_USSD_DONE 0x4A +#define EVENT_INITIATE_SERVICE_DONE 0x4B +#define EVENT_ENABLE_FDN_DONE 0x4C +#define EVENT_QUERY_FDN_DONE 0x4D +#define EVENT_REQUEST_CLIR_DONE 0x4E +#define EVENT_QUERY_ALL_CALL_BARRING_DONE 0x4F +#define EVENT_QUERY_ALL_CALL_FORWARDING_DONE 0x50 +#define EVENT_QUERY_ALL_CALL_SETTING_DONE 0x51 +#define EVENT_QUERY_CALL_FORWARDING_DONE 0x52 +#define EVENT_QUERY_CALL_WAITING_DONE 0x53 + +// PhoneBook Callback Event +#define EVENT_LOAD_ADN_ENTRIES_DONE 0x61 +#define EVENT_LOAD_FDN_ENTRIES_DONE 0x62 +#define EVENT_INSERT_FDN_ENTRIES_DONE 0x63 +#define EVENT_UPDATE_FDN_ENTRIES_DONE 0x64 +#define EVENT_DELETE_FDN_ENTRIES_DONE 0x65 + +// Call CallBack Event +#define EVENT_REQUEST_DIAL_DONE 0x71 + +// Sms CallBack Event +#define EVENT_SEND_MESSAGE_DONE 0x81 +#define EVENT_SEND_DATA_MESSAGE_DONE 0x82 + +#define TIMEOUT 15 +#define INVALID_VALUE -1 + +tapi_context get_tapi_ctx(void); +int judge(void); +void judge_data_init(void); + +struct judge_type { + int flag; + int expect; + int result; +}; + +#endif /* TELEPHONY_TEST_H_ */