From 4de3b6b0364bd7681121d63d953836257c236f0a Mon Sep 17 00:00:00 2001 From: Asit Srivastava Date: Mon, 4 Jul 2016 15:29:31 +0530 Subject: [PATCH] [ITC][stt][ACR-670][new TCs added] Change-Id: If2f8e5a829e3ae73bd0774ea6558120853766211 Signed-off-by: Asit Srivastava --- src/itc/stt/ITs-stt-common.c | 48 +++++-- src/itc/stt/ITs-stt-common.h | 11 ++ src/itc/stt/ITs-stt.c | 255 +++++++++++++++++++++++++++++++++- src/itc/stt/tct-stt-native_mobile.h | 8 ++ src/itc/stt/tct-stt-native_tv.h | 8 ++ src/itc/stt/tct-stt-native_wearable.h | 8 ++ 6 files changed, 322 insertions(+), 16 deletions(-) diff --git a/src/itc/stt/ITs-stt-common.c b/src/itc/stt/ITs-stt-common.c index 2359cab..80bb49e 100755 --- a/src/itc/stt/ITs-stt-common.c +++ b/src/itc/stt/ITs-stt-common.c @@ -21,6 +21,18 @@ //Add helper function definitions here /** +* @function TimeoutFunction +* @description Called if some callback is not invoked for a particular timeout +* @parameter gpointer data +* @return gboolean +*/ +gboolean TimeoutFunction(gpointer data) +{ + g_main_loop_quit((GMainLoop *)data); + return false; +} + +/** * @function SttGetError * @description Maps stt_error_e enums to string values * @parameter nError : error code returned @@ -31,22 +43,28 @@ char* SttGetError(stt_error_e nError) char *szErrorVal = NULL; switch ( nError ) { - case STT_ERROR_NONE: szErrorVal = "STT_ERROR_NONE"; break; - case STT_ERROR_OUT_OF_MEMORY: szErrorVal = "STT_ERROR_OUT_OF_MEMORY"; break; - case STT_ERROR_INVALID_PARAMETER: szErrorVal = "STT_ERROR_INVALID_PARAMETER"; break; - case STT_ERROR_IO_ERROR: szErrorVal = "STT_ERROR_IO_ERROR"; break; - case STT_ERROR_TIMED_OUT: szErrorVal = "STT_ERROR_TIMED_OUT"; break; - case STT_ERROR_OPERATION_FAILED: szErrorVal = "STT_ERROR_OPERATION_FAILED"; break; - case STT_ERROR_RECORDER_BUSY: szErrorVal = "STT_ERROR_RECORDER_BUSY"; break; - case STT_ERROR_OUT_OF_NETWORK: szErrorVal = "STT_ERROR_OUT_OF_NETWORK"; break; - case STT_ERROR_INVALID_STATE: szErrorVal = "STT_ERROR_INVALID_STATE"; break; - case STT_ERROR_INVALID_LANGUAGE: szErrorVal = "STT_ERROR_INVALID_LANGUAGE"; break; - case STT_ERROR_ENGINE_NOT_FOUND: szErrorVal = "STT_ERROR_ENGINE_NOT_FOUND"; break; - case STT_ERROR_NOT_SUPPORTED: szErrorVal = "STT_ERROR_NOT_SUPPORTED"; break; - case STT_ERROR_NOT_SUPPORTED_FEATURE: szErrorVal = "STT_ERROR_NOT_SUPPORTED_FEATURE"; break; - default: szErrorVal = "Undefined Error"; break; + case STT_ERROR_NONE: szErrorVal = "STT_ERROR_NONE"; break; + case STT_ERROR_OUT_OF_MEMORY: szErrorVal = "STT_ERROR_OUT_OF_MEMORY"; break; + case STT_ERROR_INVALID_PARAMETER: szErrorVal = "STT_ERROR_INVALID_PARAMETER"; break; + case STT_ERROR_IO_ERROR: szErrorVal = "STT_ERROR_IO_ERROR"; break; + case STT_ERROR_TIMED_OUT: szErrorVal = "STT_ERROR_TIMED_OUT"; break; + case STT_ERROR_OPERATION_FAILED: szErrorVal = "STT_ERROR_OPERATION_FAILED"; break; + case STT_ERROR_RECORDER_BUSY: szErrorVal = "STT_ERROR_RECORDER_BUSY"; break; + case STT_ERROR_OUT_OF_NETWORK: szErrorVal = "STT_ERROR_OUT_OF_NETWORK"; break; + case STT_ERROR_INVALID_STATE: szErrorVal = "STT_ERROR_INVALID_STATE"; break; + case STT_ERROR_INVALID_LANGUAGE: szErrorVal = "STT_ERROR_INVALID_LANGUAGE"; break; + case STT_ERROR_ENGINE_NOT_FOUND: szErrorVal = "STT_ERROR_ENGINE_NOT_FOUND"; break; + case STT_ERROR_NOT_SUPPORTED: szErrorVal = "STT_ERROR_NOT_SUPPORTED"; break; + case STT_ERROR_NOT_SUPPORTED_FEATURE: szErrorVal = "STT_ERROR_NOT_SUPPORTED_FEATURE"; break; + case STT_ERROR_PERMISSION_DENIED: szErrorVal = "STT_ERROR_PERMISSION_DENIED"; break; + case STT_ERROR_RECORDING_TIMED_OUT: szErrorVal = "STT_ERROR_RECORDING_TIMED_OUT"; break; + case STT_ERROR_NO_SPEECH: szErrorVal = "STT_ERROR_NO_SPEECH"; break; + case STT_ERROR_IN_PROGRESS_TO_READY: szErrorVal = "STT_ERROR_IN_PROGRESS_TO_READY"; break; + case STT_ERROR_IN_PROGRESS_TO_RECORDING: szErrorVal = "STT_ERROR_IN_PROGRESS_TO_RECORDING"; break; + case STT_ERROR_IN_PROGRESS_TO_PROCESSING: szErrorVal = "STT_ERROR_IN_PROGRESS_TO_PROCESSING"; break; + case STT_ERROR_SERVICE_RESET: szErrorVal = "STT_ERROR_SERVICE_RESET"; break; + default: szErrorVal = "Undefined Error"; break; } - return szErrorVal; } diff --git a/src/itc/stt/ITs-stt-common.h b/src/itc/stt/ITs-stt-common.h index 4fa2ac3..32eb7d9 100755 --- a/src/itc/stt/ITs-stt-common.h +++ b/src/itc/stt/ITs-stt-common.h @@ -31,6 +31,7 @@ * @ingroup itc * @{ */ +#define TIMEOUT_CB 5000 #define API_NAMESPACE "STT_ITC" #define PATH_LEN 1024 #define START_SOUND "start_sound.wav" @@ -68,6 +69,8 @@ stt_state_e g_nCurrentState; bool g_bSupportedEngineCallbackOccured; bool g_bSupportedLanguageCallbackOccured; +GMainLoop *g_pMainLoop; +gboolean TimeoutFunction(gpointer data); #define START_TEST {\ FPRINTF("[Line : %d][%s] Starting test : %s\\n", __LINE__, API_NAMESPACE, __FUNCTION__);\ @@ -100,6 +103,14 @@ bool g_bSupportedLanguageCallbackOccured; }\ }\ +#define RUN_POLLING_LOOP {\ + g_pMainLoop = g_main_loop_new(NULL, false);\ + nIotconTimeoutId = g_timeout_add(TIMEOUT_CB, TimeoutFunction, g_pMainLoop);\ + g_main_loop_run(g_pMainLoop);\ + g_source_remove(nIotconTimeoutId);\ + g_pMainLoop = NULL;\ +} + /******************************************************* HELPER FUNCTIONS**************************************************/ // Maps stt_error_e enums to string values diff --git a/src/itc/stt/ITs-stt.c b/src/itc/stt/ITs-stt.c index 3b854cc..a9a17bb 100755 --- a/src/itc/stt/ITs-stt.c +++ b/src/itc/stt/ITs-stt.c @@ -35,7 +35,7 @@ stt_result_time_event_e g_resultEvents[100]; int g_nResultEventCount = 0; bool bCallbackResult = false; - +bool g_CallBackHit = false; /** * @function ITs_stt_startup * @description Called before each test @@ -704,6 +704,74 @@ void deinitialize_setup_with_result_callback() } } +/** +* @function sttEngineChangedcb +* @description callback function register by stt_set_engine_changed_cb +* @parameter +* @param[in] stt The STT handle +* @param[in] engine_id Engine id +* @param[in] language The default language +* @param[in] support_silence Whether the silence detection is supported or not +* @param[in] need_credential The necessity of credential +* @param[in] user_data The user data passed from the callback registration function +* @precondition NA +* @postcondition NA +* @return bool +*/ +bool sttEngineChangedcb(stt_h stt, const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data) +{ +#if DEBUG + FPRINTF("[Line : %d][%s] Reached sttEngineChangedcb\\n", __LINE__, API_NAMESPACE); +#endif + + g_CallBackHit = true; + + if(stt == NULL) + { + FPRINTF("[Line : %d][%s] Handle is NULL in callback function\\n", __LINE__, API_NAMESPACE); + } + + if ( g_pMainLoop ) + { + g_main_loop_quit(g_pMainLoop); + g_main_loop_unref(g_pMainLoop); + g_pMainLoop = NULL; + } + return true; +} + +/** +* @function sttErrorCallback +* @description Called when an error occurs +* @parameter [in] stt The STT handle +* [in] reason The error type (e.g. STT_ERROR_OUT_OF_NETWORK, STT_ERROR_IO_ERROR) +* [in] user_data The user data passed from the callback registration function +* @precondition An application registers this callback using stt_set_error_cb() to detect error +* @return None +*/ +void sttErrorCallback(stt_h stt, stt_error_e reason, void *user_data) +{ +#if DEBUG + FPRINTF("[Line : %d][%s] Reached sttErrorCallback\\n", __LINE__, API_NAMESPACE); +#endif + + g_CallBackHit = true; + + if(stt == NULL) + { + FPRINTF("[Line : %d][%s] Handle is NULL in callback function\\n", __LINE__, API_NAMESPACE); + } + + if ( g_pMainLoop ) + { + g_main_loop_quit(g_pMainLoop); + g_main_loop_unref(g_pMainLoop); + g_pMainLoop = NULL; + } + +} + + /** @addtogroup itc-stt-testcases * @brief Integration testcases for module stt * @ingroup itc-stt @@ -2685,5 +2753,190 @@ int ITc_stt_foreach_supported_languages_p(void) return 0; } +//& type: auto +//& purpose: To get the list of supported voices. +/** +* @testcase ITc_stt_set_credential_p +* @since_tizen 3.0 +* @author SRID(asit.s) +* @reviewer SRID(a.pandia1) +* @type auto +* @scenario create a stt handler\n +* call set credentials\n +* @apicovered stt_set_credential, +* @passcase if API is successful +* @failcase if API is not successful +* @precondition NA +* @postcondition NA +*/ +int ITc_stt_set_credential_p(void) +{ + START_TEST; + + stt_state_e state; + const char* credential = "TizenApp"; + + int nRet = stt_get_state(g_hStt, &state); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_get_state", SttGetError(nRet)); + if ( state != STT_STATE_CREATED ) + { + FPRINTF("[Line : %d][%s] get state is not matched state is :: %d \\n", __LINE__, API_NAMESPACE,state); + return 1; + } + + //Target API + nRet = stt_set_credential(g_hStt,credential); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_set_credential", SttGetError(nRet)); + + return 0; +} + +//& type: auto +//& purpose: To get the list of supported voices. +/** +* @testcase ITc_stt_set_get_private_data_p +* @since_tizen 3.0 +* @author SRID(asit.s) +* @reviewer SRID(a.pandia1) +* @type auto +* @scenario create a stt handler\n +* call stt_set_private_data\n +* call stt_get_private_data\n +* @apicovered stt_set_private_data,stt_get_private_data +* @passcase if API is successful +* @failcase if API is not successful +* @precondition NA +* @postcondition NA +*/ +int ITc_stt_set_get_private_data_p(void) +{ + START_TEST; + char* Getdata = NULL; + + int nRet = stt_prepare(g_hStt); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_prepare", SttGetError(nRet)); + + WAIT_FOR_CALLBACK(STT_STATE_READY); + + nRet = stt_set_private_data(g_hStt,"test","data"); + PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_set_private_data", SttGetError(nRet), stt_unprepare(g_hStt)); + + nRet = stt_get_private_data(g_hStt,"test",&Getdata); + PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_get_private_data", SttGetError(nRet), stt_unprepare(g_hStt);FREE_MEMORY(Getdata)); + + if( 0 != strcmp("test",Getdata) ) + { + FPRINTF("[Line : %d][%s] get data is not matched \\n", __LINE__, API_NAMESPACE); + FREE_MEMORY(Getdata); + stt_unprepare(g_hStt); + return 1; + } + + FREE_MEMORY(Getdata); + nRet = stt_unprepare(g_hStt); + PRINT_RESULT_NORETURN(STT_ERROR_NONE, nRet, "stt_unprepare", SttGetError(nRet)); + return 0; +} + +//& type: auto +//& purpose: To get the list of supported voices. +/** +* @testcase ITc_stt_get_error_message_p +* @since_tizen 3.0 +* @author SRID(asit.s) +* @reviewer SRID(a.pandia1) +* @type auto +* @scenario create a stt handler\n +* call stt_set_error_cb to register callback function\n +* call stt_set_credential with NULL parameters to generate error\n +* call stt_get_error_message to get error. +* @apicovered stt_set_credential,stt_set_error_cb,stt_get_error_message. +* @passcase if API is successful +* @failcase if API is not successful +* @precondition NA +* @postcondition NA +*/ +int ITc_stt_get_error_message_p(void) +{ + START_TEST; + + char* err_msg = NULL; + stt_state_e state; + int nIotconTimeoutId = 0; + + int nRet = stt_get_state(g_hStt, &state); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_get_state", SttGetError(nRet)); + + if(state != STT_STATE_CREATED) + { + FPRINTF("[Line : %d][%s] get state is not matched \\n", __LINE__, API_NAMESPACE); + return 1; + } + + nRet = stt_set_error_cb(g_hStt, sttErrorCallback, NULL); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_set_error_cb", SttGetError(nRet)); + + //This API called for generating error + nRet = stt_set_credential(NULL,NULL); + PRINT_RESULT_NORETURN(STT_ERROR_NONE,nRet,"stt_set_credential",SttGetError(nRet)); + + RUN_POLLING_LOOP; + if(g_CallBackHit != true) + { + FPRINTF("[Line : %d][%s] callback hit failed \\n", __LINE__, API_NAMESPACE); + stt_unset_error_cb(g_hStt); + return 1; + } + + nRet = stt_get_error_message(g_hStt, &err_msg); + PRINT_RESULT_CLEANUP(STT_ERROR_NONE,nRet,"stt_get_error_message",SttGetError(nRet),stt_unset_error_cb(g_hStt);FREE_MEMORY(err_msg)); + CHECK_HANDLE(err_msg, "stt_get_error_message"); + FREE_MEMORY(err_msg); + + nRet = stt_unset_error_cb(g_hStt); + PRINT_RESULT_NORETURN(STT_ERROR_NONE, nRet, "stt_unset_error_cb", SttGetError(nRet)); + + return 0; +} + + +//& type: auto +//& purpose: To get the list of supported voices. +/** +* @testcase ITc_stt_set_unset_engine_changed_cb_p +* @since_tizen 3.0 +* @author SRID(asit.s) +* @reviewer SRID(a.pandia1) +* @type auto +* @scenario create a stt handler\n +* call stt_set_engine_changed_cb and register callback function\n +* call stt_unset_engine_changed_cb to deregister. +* @apicovered stt_set_engine_changed_cb,stt_unset_engine_changed_cb +* @passcase if API is successful +* @failcase if API is not successful +* @precondition NA +* @postcondition NA +*/ +int ITc_stt_set_unset_engine_changed_cb_p(void) +{ + START_TEST; + int nIotconTimeoutId = 0; + g_CallBackHit = false; + + int nRet = stt_set_engine_changed_cb(g_hStt,sttEngineChangedcb,NULL); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_set_engine_changed_cb", SttGetError(nRet)); + + RUN_POLLING_LOOP; + if(g_CallBackHit != true) + { + FPRINTF("[Line : %d][%s] callback hit failed \\n", __LINE__, API_NAMESPACE); + return 1; + } + + nRet = stt_unset_engine_changed_cb(g_hStt); + PRINT_RESULT(STT_ERROR_NONE, nRet, "stt_unset_engine_changed_cb", SttGetError(nRet)); + + return 0; +} /** @} */ /** @} */ diff --git a/src/itc/stt/tct-stt-native_mobile.h b/src/itc/stt/tct-stt-native_mobile.h index 91d8042..f06e225 100755 --- a/src/itc/stt/tct-stt-native_mobile.h +++ b/src/itc/stt/tct-stt-native_mobile.h @@ -42,6 +42,10 @@ extern int ITc_stt_set_unset_error_cb_p(void); extern int ITc_stt_foreach_detailed_result_p(void); extern int ITc_stt_foreach_supported_engines_p(void); extern int ITc_stt_foreach_supported_languages_p(void); +extern int ITc_stt_set_credential_p(void); +extern int ITc_stt_set_get_private_data_p(void); +extern int ITc_stt_get_error_message_p(void); +extern int ITc_stt_set_unset_engine_changed_cb_p(void); testcase tc_array[] = { {"ITc_stt_create_destroy_p", ITc_stt_create_destroy_p, ITs_stt_startup, ITs_stt_cleanup}, @@ -64,6 +68,10 @@ testcase tc_array[] = { {"ITc_stt_foreach_detailed_result_p", ITc_stt_foreach_detailed_result_p, ITs_stt_startup, ITs_stt_cleanup}, {"ITc_stt_foreach_supported_engines_p", ITc_stt_foreach_supported_engines_p, ITs_stt_startup, ITs_stt_cleanup}, {"ITc_stt_foreach_supported_languages_p", ITc_stt_foreach_supported_languages_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_credential_p", ITc_stt_set_credential_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_get_private_data_p", ITc_stt_set_get_private_data_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_get_error_message_p", ITc_stt_get_error_message_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_unset_engine_changed_cb_p", ITc_stt_set_unset_engine_changed_cb_p, ITs_stt_startup, ITs_stt_cleanup}, {NULL, NULL} }; diff --git a/src/itc/stt/tct-stt-native_tv.h b/src/itc/stt/tct-stt-native_tv.h index 79f2dae..0c25ccc 100755 --- a/src/itc/stt/tct-stt-native_tv.h +++ b/src/itc/stt/tct-stt-native_tv.h @@ -41,6 +41,10 @@ extern int ITc_stt_set_unset_error_cb_p(void); extern int ITc_stt_foreach_detailed_result_p(void); extern int ITc_stt_foreach_supported_engines_p(void); extern int ITc_stt_foreach_supported_languages_p(void); +extern int ITc_stt_set_credential_p(void); +extern int ITc_stt_set_get_private_data_p(void); +extern int ITc_stt_get_error_message_p(void); +extern int ITc_stt_set_unset_engine_changed_cb_p(void); testcase tc_array[] = { {"ITc_stt_create_destroy_p", ITc_stt_create_destroy_p, ITs_stt_startup, ITs_stt_cleanup}, @@ -63,6 +67,10 @@ testcase tc_array[] = { {"ITc_stt_foreach_detailed_result_p", ITc_stt_foreach_detailed_result_p, ITs_stt_startup, ITs_stt_cleanup}, {"ITc_stt_foreach_supported_engines_p", ITc_stt_foreach_supported_engines_p, ITs_stt_startup, ITs_stt_cleanup}, {"ITc_stt_foreach_supported_languages_p", ITc_stt_foreach_supported_languages_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_credential_p", ITc_stt_set_credential_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_get_private_data_p", ITc_stt_set_get_private_data_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_get_error_message_p", ITc_stt_get_error_message_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_unset_engine_changed_cb_p", ITc_stt_set_unset_engine_changed_cb_p, ITs_stt_startup, ITs_stt_cleanup}, {NULL, NULL} }; diff --git a/src/itc/stt/tct-stt-native_wearable.h b/src/itc/stt/tct-stt-native_wearable.h index 91d8042..f06e225 100755 --- a/src/itc/stt/tct-stt-native_wearable.h +++ b/src/itc/stt/tct-stt-native_wearable.h @@ -42,6 +42,10 @@ extern int ITc_stt_set_unset_error_cb_p(void); extern int ITc_stt_foreach_detailed_result_p(void); extern int ITc_stt_foreach_supported_engines_p(void); extern int ITc_stt_foreach_supported_languages_p(void); +extern int ITc_stt_set_credential_p(void); +extern int ITc_stt_set_get_private_data_p(void); +extern int ITc_stt_get_error_message_p(void); +extern int ITc_stt_set_unset_engine_changed_cb_p(void); testcase tc_array[] = { {"ITc_stt_create_destroy_p", ITc_stt_create_destroy_p, ITs_stt_startup, ITs_stt_cleanup}, @@ -64,6 +68,10 @@ testcase tc_array[] = { {"ITc_stt_foreach_detailed_result_p", ITc_stt_foreach_detailed_result_p, ITs_stt_startup, ITs_stt_cleanup}, {"ITc_stt_foreach_supported_engines_p", ITc_stt_foreach_supported_engines_p, ITs_stt_startup, ITs_stt_cleanup}, {"ITc_stt_foreach_supported_languages_p", ITc_stt_foreach_supported_languages_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_credential_p", ITc_stt_set_credential_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_get_private_data_p", ITc_stt_set_get_private_data_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_get_error_message_p", ITc_stt_get_error_message_p, ITs_stt_startup, ITs_stt_cleanup}, + {"ITc_stt_set_unset_engine_changed_cb_p", ITc_stt_set_unset_engine_changed_cb_p, ITs_stt_startup, ITs_stt_cleanup}, {NULL, NULL} }; -- 2.7.4