From d6f24023802e6ef23db9b9120848080630462004 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 28 Jul 2022 13:48:33 +0900 Subject: [PATCH] Reorder precondition checker - Issue: Some unit tests are failed. - Solution: The reason why the tests are failed is because the order for checking precondition is changed from previous code. All APIs first check parameters and then check state. However, some function check state first and the parameters after next patch. https://review.tizen.org/gerrit/c/platform/core/uifw/stt/+/277656 This patch revert the order of precondition check, so every APIs check precondition with same way. Change-Id: I91d1ef4e3fd0910070e182bad39156d45b1c69fc Signed-off-by: Suyeon Hwang --- client/stt.c | 64 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/client/stt.c b/client/stt.c index cf182a9..ebf0037 100644 --- a/client/stt.c +++ b/client/stt.c @@ -544,10 +544,11 @@ static bool __stt_config_supported_engine_cb(const char* engine_id, const char* int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine"); @@ -573,11 +574,13 @@ int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, v int stt_get_engine(stt_h stt, char** engine_id) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == engine_id, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "===== Get current engine"); int ret = 0; @@ -716,12 +719,8 @@ int stt_set_credential(stt_h stt, const char* credential) SLOG(LOG_INFO, TAG_STTC, "===== Set credential"); RETVM_IF(NULL == credential, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); - - /* check state */ - if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, + "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); if (NULL != client->credential) { free(client->credential); @@ -754,11 +753,13 @@ static bool __stt_is_necessary_to_retry_dbus_request(int count, int return_value int stt_set_private_data(stt_h stt, const char* key, const char* data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == key || NULL == data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "===== Set private data"); if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) { @@ -790,11 +791,13 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data) int stt_get_private_data(stt_h stt, const char* key, char** data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == key || NULL == data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "===== Get private data"); int ret = -1; @@ -1220,11 +1223,12 @@ int stt_get_error_message(stt_h stt, char** err_msg) int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == type || NULL == support, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -1274,12 +1278,13 @@ int stt_set_start_sound(stt_h stt, const char* filename) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == filename, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); RETVM_IF(0 != access(filename, F_OK), STT_ERROR_INVALID_PARAMETER, "[ERROR] File does not exist"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND"); @@ -1338,12 +1343,14 @@ int stt_set_stop_sound(stt_h stt, const char* filename) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == filename, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); RETVM_IF(0 != access(filename, F_OK), STT_ERROR_INVALID_PARAMETER, "[ERROR] File does not exist"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND"); int ret = -1; @@ -1556,11 +1563,12 @@ int __stt_cb_set_volume(unsigned int uid, float volume) int stt_get_recording_volume(stt_h stt, float* volume) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == volume, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); *volume = g_volume_db; @@ -1862,11 +1870,13 @@ int __stt_cb_speech_status(unsigned int uid, int status) int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set recognition result cb"); client->recognition_result_cb = callback; @@ -1893,11 +1903,13 @@ int stt_unset_recognition_result_cb(stt_h stt) int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set state changed cb"); client->state_changed_cb = callback; @@ -1924,11 +1936,13 @@ int stt_unset_state_changed_cb(stt_h stt) int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set error cb"); client->error_cb = callback; @@ -1955,11 +1969,13 @@ int stt_unset_error_cb(stt_h stt) int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set default language changed cb"); client->default_lang_changed_cb = callback; @@ -1986,11 +2002,13 @@ int stt_unset_default_language_changed_cb(stt_h stt) int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set engine changed cb"); client->engine_changed_cb = callback; @@ -2018,11 +2036,13 @@ int stt_unset_engine_changed_cb(stt_h stt) int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED); + int temp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != temp) return temp; RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set speech status cb"); client->speech_status_cb = callback; @@ -2049,11 +2069,13 @@ int stt_unset_speech_status_cb(stt_h stt) int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate) { stt_client_s* client = NULL; - int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY); + int tmp = __stt_check_precondition(stt, &client); if (STT_ERROR_NONE != tmp) return tmp; RETVM_IF(NULL == filepath, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE"); if (STT_INTERNAL_STATE_NONE != client->internal_state) { -- 2.7.4