bool bCallbackResult = false;
bool g_CallBackHit = false;
+
+static const char *TEST_LANGUAGE = "en_US";
+static const char *TEST_RECOG_TYPE = STT_RECOGNITION_TYPE_FREE_PARTIAL;
+static char g_szTestPcmPath[1024];
+static char* g_szPcmData = NULL;
+static size_t g_nPcmSize = 0;
+
/**
* @function ITs_stt_startup
* @description Called before each test
*/
void stt_state_changed_callback(stt_h stt, stt_state_e previous, stt_state_e current, void *user_data)
{
-#if DEBUG
FPRINTF("[Line : %d][%s] Reached stt_state_changed_callback\\n", __LINE__, API_NAMESPACE);
-#endif
-
g_bStateCallbackOccurred = true;
if(stt == NULL)
}
+int SttGetTestPcmFileData()
+{
+ FILE* fp_in = fopen(g_szTestPcmPath, "rb");
+ if (fp_in == NULL) {
+ FPRINTF("[Line : %d][%s] Unable to open file: test_pcm.dat\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+
+ fseek(fp_in, 0, SEEK_END);
+ long size = ftell(fp_in);
+ fseek(fp_in, 0, SEEK_SET);
+ if (size <= 0) {
+ fclose(fp_in);
+ return 1;
+ }
+ FPRINTF("[Line : %d][%s] File Size is: [%ld]\\n", __LINE__, API_NAMESPACE, size);
+
+ char* data = (char *)calloc(sizeof(char), size);
+ if (NULL == data) {
+ fclose(fp_in);
+ return 1;
+ }
+
+ size_t read_size = fread(data, sizeof(char), size, fp_in);
+ fclose(fp_in);
+
+ if (read_size <= 0) {
+ free(data);
+ return 1;
+ }
+ FPRINTF("[Line : %d][%s] File Read Size is: [%d]\\n", __LINE__, API_NAMESPACE, read_size);
+ g_nPcmSize = size;
+ g_szPcmData = data;
+ return 0;
+}
+
+static bool SttPrepareState(void)
+{
+ stt_state_e state = STT_STATE_CREATED;
+ stt_get_state(g_hStt, &state);
+ if (STT_STATE_CREATED != state) {
+ FPRINTF("[Line : %d][%s] Current state is not STT_STATE_CREATED\\n", __LINE__, API_NAMESPACE);
+ return false;
+ }
+
+ int nRet = stt_set_state_changed_cb(g_hStt, stt_state_changed_callback, NULL);
+ if ( nRet != STT_ERROR_NONE )
+ {
+ FPRINTF("[Line : %d][%s] stt_set_state_changed_cb failed, error returned = %s\\n", __LINE__, API_NAMESPACE, SttGetError(nRet));
+ return false;
+ }
+ nRet = stt_prepare(g_hStt);
+ if ( nRet != STT_ERROR_NONE )
+ {
+ FPRINTF("[Line : %d][%s] stt_prepare failed, error returned = %s\\n", __LINE__, API_NAMESPACE, SttGetError(nRet));
+ return false;
+ }
+ WAIT_FOR_CALLBACK(STT_STATE_READY);
+
+ stt_get_state(g_hStt, &state);
+ if (STT_STATE_READY != state) {
+ FPRINTF("[Line : %d][%s] After stt_prepare, current state is not STT_STATE_READY\\n", __LINE__, API_NAMESPACE);
+ return false;
+ }
+ return true;
+}
+static bool SttUnprepareState(void)
+{
+ stt_state_e state = STT_STATE_CREATED;
+ stt_get_state(g_hStt, &state);
+ if (STT_STATE_READY != state) {
+ return false;
+ }
+
+ int nRet = stt_unprepare(g_hStt);
+ if ( nRet != STT_ERROR_NONE )
+ {
+ FPRINTF("[Line : %d][%s] stt_unprepare failed, error returned = %s\\n", __LINE__, API_NAMESPACE, SttGetError(nRet));
+ return false;
+ }
+ WAIT_FOR_CALLBACK(STT_STATE_CREATED);
+
+ nRet = stt_unset_state_changed_cb(g_hStt);
+ if ( nRet != STT_ERROR_NONE )
+ {
+ FPRINTF("[Line : %d][%s] Support API stt_unset_state_changed_cb failed on postcondition, error returned = %s\\n", __LINE__, API_NAMESPACE, SttGetError(nRet));
+ return false;
+ }
+ return true;
+}
+
+static bool SttSetPrivateDataMode(void)
+{
+ stt_state_e state = STT_STATE_CREATED;
+ stt_get_state(g_hStt, &state);
+ if (STT_STATE_READY != state) {
+ return false;
+ }
+
+ int nRet = stt_set_private_data(g_hStt, "stt_verification", "true");
+ if (STT_ERROR_NONE != nRet) {
+ FPRINTF("[Line : %d][%s] stt_set_private_data failed for true flag, error returned = %s\\n", __LINE__, API_NAMESPACE, SttGetError(nRet));
+ return false;
+ }
+ return true;
+}
+
+static bool SttUnsetPrivateDataMode(void)
+{
+ stt_state_e state = STT_STATE_CREATED;
+ stt_get_state(g_hStt, &state);
+ if (STT_STATE_READY != state) {
+ return false;
+ }
+
+ int nRet = stt_set_private_data(g_hStt, "stt_verification", "false");
+ if (STT_ERROR_NONE != nRet) {
+ FPRINTF("[Line : %d][%s] stt_set_private_data failed for false flag, error returned = %s\\n", __LINE__, API_NAMESPACE, SttGetError(nRet));
+ return false;
+ }
+ return true;
+}
+
/** @addtogroup itc-stt-testcases
* @brief Integration testcases for module stt
* @ingroup itc-stt
return 0;
}
+
+//& purpose Start and Stop audio streaming
+//& type: auto
+/**
+* @testcase ITc_stt_start_stop_audio_streaming_p
+* @since_tizen 8.0
+* @author SRID(shobhit.v)
+* @reviewer SRID(tarun1.kumar)
+* @type auto
+* @description Check Start and Stop audio streaming APIs
+* @scenario Start and Stop audio streaming
+* @apicovered stt_start_audio_streaming and stt_stop_audio_streaming
+* @passcase If stt_start_audio_streaming and stt_stop_audio_streaming pass
+* @failcase If any precondition API, stt_start_audio_streaming Or stt_stop_audio_streaming fails
+* @precondition NA
+* @postcondition NA
+*/
+int ITc_stt_start_stop_audio_streaming_p(void)
+{
+ START_TEST;
+
+ int nRet = -1;
+ stt_state_e nState;
+
+ if (g_bFeatureSupported == false)
+ {
+ nRet = stt_start_audio_streaming(g_hStt, TEST_LANGUAGE, TEST_RECOG_TYPE);
+ PRINT_RESULT(STT_ERROR_NOT_SUPPORTED, nRet, "stt_start_audio_streaming", SttGetError(nRet));
+
+ nRet = stt_stop_audio_streaming(g_hStt);
+ PRINT_RESULT(STT_ERROR_NOT_SUPPORTED, nRet, "stt_stop_audio_streaming", SttGetError(nRet));
+ return 0;
+ }
+
+ if( SttPrepareState() == false)
+ {
+ FPRINTF("[Line : %d][%s] SttPrepareState failed\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ if( SttSetPrivateDataMode() == false)
+ {
+ FPRINTF("[Line : %d][%s] SttSetPrivateDataMode failed\\n", __LINE__, API_NAMESPACE);
+ SttUnprepareState();
+ return 1;
+ }
+
+ nRet = stt_start_audio_streaming(g_hStt, TEST_LANGUAGE, TEST_RECOG_TYPE);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_start_audio_streaming", SttGetError(nRet), SttUnsetPrivateDataMode(); SttUnprepareState());
+ FPRINTF("[Line : %d][%s] stt_start_audio_streaming Pass\\n", __LINE__, API_NAMESPACE);
+
+ WAIT_FOR_CALLBACK(STT_STATE_RECORDING);
+ nRet = stt_get_state(g_hStt, &nState);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_get_state", SttGetError(nRet), SttUnsetPrivateDataMode(); SttUnprepareState());
+ if ( nState != STT_STATE_RECORDING )
+ {
+ FPRINTF("[Line : %d][%s] stt_start_audio_streaming failed as expected current state is not STT_STATE_RECORDING\\n", __LINE__, API_NAMESPACE);
+ SttUnsetPrivateDataMode();
+ SttUnprepareState();
+ return 1;
+ }
+
+ nRet = stt_stop_audio_streaming(g_hStt);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_stop_audio_streaming", SttGetError(nRet), SttUnsetPrivateDataMode(); SttUnprepareState());
+ FPRINTF("[Line : %d][%s] stt_stop_audio_streaming Pass\\n", __LINE__, API_NAMESPACE);
+
+ WAIT_FOR_CALLBACK(STT_STATE_PROCESSING);
+ WAIT_FOR_CALLBACK(STT_STATE_READY);
+
+ nRet = stt_get_state(g_hStt, &nState);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_get_state", SttGetError(nRet),SttUnsetPrivateDataMode();SttUnprepareState());
+ if ( nState != STT_STATE_READY )
+ {
+ FPRINTF("[Line : %d][%s] stt_stop_audio_streaming failed as expected current state is not STT_STATE_READY\\n", __LINE__, API_NAMESPACE);
+ SttUnsetPrivateDataMode();
+ SttUnprepareState();
+ return 1;
+ }
+
+ SttUnsetPrivateDataMode();
+ SttUnprepareState();
+
+ return 0;
+}
+
+
+//& purpose To get recognizable audio format information
+//& type: auto
+/**
+* @testcase ITc_stt_get_audio_format_p
+* @since_tizen 8.0
+* @author SRID(shobhit.v)
+* @reviewer SRID(tarun1.kumar)
+* @type auto
+* @description Get recognizable audio format information
+* @scenario Prepare state and get audio format information
+* @apicovered stt_get_audio_format
+* @passcase If stt_get_audio_format pass
+* @failcase If stt_get_audio_format fail
+* @precondition NA
+* @postcondition NA
+*/
+int ITc_stt_get_audio_format_p(void)
+{
+ START_TEST;
+
+ int nRet = -1;
+ stt_audio_type_e type = STT_AUDIO_TYPE_RAW_S16;
+ int nRate = -1;
+ int nChannels = -1;
+
+ if (g_bFeatureSupported == false)
+ {
+ nRet = stt_get_audio_format(g_hStt, &type, &nRate, &nChannels);
+ PRINT_RESULT(STT_ERROR_NOT_SUPPORTED, nRet, "stt_get_audio_format", SttGetError(nRet));
+ return 0;
+ }
+
+ if( SttPrepareState() == false)
+ {
+ FPRINTF("[Line : %d][%s] SttPrepareState failed\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ nRet = stt_get_audio_format(g_hStt, &type, &nRate, &nChannels);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_get_audio_format", SttGetError(nRet), SttUnprepareState());
+ if (nRate == -1 || nChannels == -1)
+ {
+ FPRINTF("[Line : %d][%s] stt_get_audio_format failed. Output parameter values are incorrect.\\n", __LINE__, API_NAMESPACE);
+ SttUnprepareState();
+ return 1;
+ }
+
+ SttUnprepareState();
+ return 0;
+}
+
+
+//& purpose To send audio streaming data to service engine
+//& type: auto
+/**
+* @testcase ITc_stt_send_audio_streaming_p
+* @since_tizen 8.0
+* @author SRID(shobhit.v)
+* @reviewer SRID(tarun1.kumar)
+* @type auto
+* @description To send audio streaming data to service engine
+* @scenario Start audio streaming and Send audio streaming data
+* @apicovered stt_start_audio_streaming and stt_send_audio_streaming
+* @passcase If stt_start_audio_streaming and stt_send_audio_streaming pass
+* @failcase If stt_start_audio_streaming or stt_send_audio_streaming fail
+* @precondition NA
+* @postcondition NA
+*/
+int ITc_stt_send_audio_streaming_p(void)
+{
+ START_TEST;
+
+ int nRet = -1;
+ stt_state_e nState;
+ stt_audio_type_e type = STT_AUDIO_TYPE_RAW_S16;
+ int nRate = -1;
+ int nChannels = -1;
+
+ if (g_bFeatureSupported == false)
+ {
+ nRet = stt_send_audio_streaming(g_hStt, g_szPcmData, g_nPcmSize);
+ PRINT_RESULT(STT_ERROR_NOT_SUPPORTED, nRet, "stt_send_audio_streaming", SttGetError(nRet));
+ return 0;
+ }
+
+ if ( false == SttAppendToAppDataPath(PCM_FILE, g_szTestPcmPath) )
+ {
+ FPRINTF("[Line : %d][%s] unable to get the app data path\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ else
+ FPRINTF("[Line : %d][%s] PCM file path is: [%s]\\n", __LINE__, API_NAMESPACE, g_szTestPcmPath);
+
+ nRet = SttGetTestPcmFileData();
+ if (nRet == 1)
+ {
+ FPRINTF("[Line : %d][%s] Error in get pcm data.\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+
+ if( SttPrepareState() == false)
+ {
+ FPRINTF("[Line : %d][%s] SttPrepareState failed\\n", __LINE__, API_NAMESPACE);
+ return 1;
+ }
+ if( SttSetPrivateDataMode() == false)
+ {
+ FPRINTF("[Line : %d][%s] SttSetPrivateDataMode failed\\n", __LINE__, API_NAMESPACE);
+ SttUnprepareState();
+ return 1;
+ }
+
+ nRet = stt_start_audio_streaming(g_hStt, TEST_LANGUAGE, TEST_RECOG_TYPE);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_start_audio_streaming", SttGetError(nRet),SttUnsetPrivateDataMode(); SttUnprepareState());
+ FPRINTF("[Line : %d][%s] stt_start_audio_streaming Pass\\n", __LINE__, API_NAMESPACE);
+
+ WAIT_FOR_CALLBACK(STT_STATE_RECORDING);
+
+ nRet = stt_get_state(g_hStt, &nState);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_get_state", SttGetError(nRet),SttUnsetPrivateDataMode(); SttUnprepareState());
+ if ( nState != STT_STATE_RECORDING )
+ {
+ FPRINTF("[Line : %d][%s] stt_start_audio_streaming failed as expected current state is not STT_STATE_RECORDING\\n", __LINE__, API_NAMESPACE);
+ stt_stop_audio_streaming(g_hStt);
+ SttUnsetPrivateDataMode();
+ SttUnprepareState();
+ return 1;
+ }
+
+ nRet = stt_send_audio_streaming(g_hStt, g_szPcmData, g_nPcmSize);
+ PRINT_RESULT_CLEANUP(STT_ERROR_NONE, nRet, "stt_send_audio_streaming", SttGetError(nRet),SttUnsetPrivateDataMode(); SttUnprepareState());
+ FPRINTF("[Line : %d][%s] stt_send_audio_streaming Pass\\n", __LINE__, API_NAMESPACE);
+
+ SttUnsetPrivateDataMode();
+ SttUnprepareState();
+
+ return 0;
+}
+
/** @} */
/** @} */