[UTC][stt][Non-ACR][Add exception for engine server network failure]
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 7 Aug 2017 12:28:17 +0000 (21:28 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Mon, 7 Aug 2017 13:45:53 +0000 (22:45 +0900)
Change-Id: Icc17d440271c8d2b6aba3f0117fc63fc744cd240
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
src/utc/stt/utc-stt.c

index 3876b7e..9e79a66 100755 (executable)
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <Elementary.h>
+#include <dlog.h>
 
 #include "assert.h"
 
@@ -30,9 +31,10 @@ static char *g_language = NULL;
 static stt_state_e g_current_state;
 static stt_state_e g_temp_current_state;
 static bool g_stt_supported = false;
-
+static stt_error_e g_error;
 
 static void __stt_state_changed_cb(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data);
+static void __stt_error_cb(stt_h stt, stt_error_e reason, void *user_data);
 
 void utc_stt_startup(void)
 {
@@ -42,11 +44,13 @@ void utc_stt_startup(void)
        system_info_get_platform_bool("http://tizen.org/feature/speech.recognition", &g_stt_supported);
        elm_init(0,NULL);
        g_current_state = 0;
+       g_error = TIZEN_ERROR_NONE;
 
        if (g_stt_supported) {
                g_stt = NULL;
                ret = stt_create(&g_stt);
                stt_set_state_changed_cb(g_stt, __stt_state_changed_cb, NULL);
+               stt_set_error_cb(g_stt, __stt_error_cb, NULL);
        }
 }
 
@@ -55,6 +59,7 @@ void utc_stt_cleanup(void)
        /* end of TC */
        if (true == g_stt_supported) {
                stt_unset_state_changed_cb(g_stt);
+               stt_unset_error_cb(g_stt);
                stt_destroy(g_stt);
        }
        g_stt = NULL;
@@ -84,6 +89,10 @@ static void __stt_temp_state_changed_cb(stt_h stt, stt_state_e previous, stt_sta
 
 static void __stt_error_cb(stt_h stt, stt_error_e reason, void *user_data)
 {
+       g_error = reason;
+       dlog_print(DLOG_ERROR, "NativeTCT", "ERROR(%d)", g_error);
+
+       return;
 }
 
 static void __stt_recognition_result_cb(stt_h stt, stt_result_event_e event, const char** data, int data_count, const char* msg, void *user_data)
@@ -1145,6 +1154,7 @@ int utc_stt_start_p(void)
                assert_eq(ret, STT_ERROR_NOT_SUPPORTED);
        } else {
                assert_neq(g_stt, NULL);
+
                ret = stt_prepare(g_stt);
                assert_eq(ret, STT_ERROR_NONE);
 
@@ -1163,12 +1173,14 @@ int utc_stt_start_p(void)
                        g_language = NULL;
                }
 
-                while (STT_STATE_RECORDING != g_current_state){
-                        ecore_main_loop_iterate();
-                }
+               while (STT_STATE_RECORDING != g_current_state && STT_ERROR_OUT_OF_NETWORK != g_error){
+                       ecore_main_loop_iterate();
+               }
+
+               dlog_print(DLOG_INFO, "NativeTCT", "State(%d)", g_current_state);
 
                int count = 0;
-               while (STT_STATE_PROCESSING != g_current_state){
+               while (STT_STATE_PROCESSING != g_current_state && STT_ERROR_OUT_OF_NETWORK != g_error){
                        ecore_main_loop_iterate();
                        usleep(100000);
                        count++;
@@ -1248,6 +1260,7 @@ int utc_stt_stop_p(void)
                assert_eq(ret, STT_ERROR_NOT_SUPPORTED);
        } else {
                assert_neq(g_stt, NULL);
+
                ret = stt_prepare(g_stt);
                assert_eq(ret, STT_ERROR_NONE);
 
@@ -1258,12 +1271,13 @@ int utc_stt_stop_p(void)
                ret = stt_start(g_stt, NULL, STT_RECOGNITION_TYPE_FREE);
                assert_eq(ret, STT_ERROR_NONE);
 
-               while (STT_STATE_RECORDING != g_current_state){
+               int count = 0;
+               while (STT_STATE_RECORDING != g_current_state && STT_ERROR_OUT_OF_NETWORK != g_error){
                        ecore_main_loop_iterate();
                }
 
-               int count = 0;
-               while (STT_STATE_PROCESSING != g_current_state){
+               count = 0;
+               while (STT_STATE_PROCESSING != g_current_state && STT_ERROR_OUT_OF_NETWORK != g_error){
                        ecore_main_loop_iterate();
                        usleep(100000);
                        count++;
@@ -1338,12 +1352,12 @@ int utc_stt_cancel_p(void)
                ret = stt_start(g_stt, NULL, STT_RECOGNITION_TYPE_FREE);
                assert_eq(ret, STT_ERROR_NONE);
 
-               while (STT_STATE_RECORDING != g_current_state){
+               while (STT_STATE_RECORDING != g_current_state && STT_ERROR_OUT_OF_NETWORK != g_error){
                        ecore_main_loop_iterate();
                }
 
                int i = 0;
-               for (i = 0; i < 10; i++) {
+               for (i = 0; i < 10 && STT_ERROR_OUT_OF_NETWORK != g_error; i++) {
                        ecore_main_loop_iterate();
                }
 
@@ -1420,6 +1434,7 @@ int utc_stt_get_recording_volume_p(void)
                assert_eq(ret, STT_ERROR_NOT_SUPPORTED);
        } else {
                assert_neq(g_stt, NULL);
+
                ret = stt_prepare(g_stt);
                assert_eq(ret, STT_ERROR_NONE);
 
@@ -1430,22 +1445,24 @@ int utc_stt_get_recording_volume_p(void)
                ret = stt_start(g_stt, NULL, STT_RECOGNITION_TYPE_FREE);
                assert_eq(ret, STT_ERROR_NONE);
 
-               while (STT_STATE_RECORDING != g_current_state){
+               while (STT_STATE_RECORDING != g_current_state && STT_ERROR_OUT_OF_NETWORK != g_error){
                        ecore_main_loop_iterate();
                }
 
                int i = 0;
-               for (i = 0; i < 10; i++) {
+               for (i = 0; i < 10 && STT_ERROR_OUT_OF_NETWORK != g_error; i++) {
                        ecore_main_loop_iterate();
                }
 
-               ret = stt_get_recording_volume(g_stt, &vol);
-               assert_eq(ret, STT_ERROR_NONE);
+               if (STT_ERROR_OUT_OF_NETWORK != g_error) {
+                       ret = stt_get_recording_volume(g_stt, &vol);
+                       assert_eq(ret, STT_ERROR_NONE);
 
-               ecore_main_loop_iterate();
+                       ecore_main_loop_iterate();
 
-               ret = stt_cancel(g_stt);
-               assert_eq(ret, STT_ERROR_NONE);
+                       ret = stt_cancel(g_stt);
+                       assert_eq(ret, STT_ERROR_NONE);
+               }
 
                while (STT_STATE_READY != g_current_state){
                        ecore_main_loop_iterate();