#include <Ecore.h>
#include <system_info.h>
#include <tzplatform_config.h>
+#include <vconf.h>
+#include <app_manager_extension.h>
#include <voice_control_manager.h>
#include <voice_control_manager_internal.h>
+#include <voice_control_setting.h>
#include "system_info_mock.h"
#include "cynara_mock.h"
static const char *TEST_COMMAND_JSON_PATH = tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_APP"), "/org.tizen.vc-unittests/res/test_command.json");
static const char *TEST_DEMANDABLE_LIST_XML_PATH = tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_APP"), "/org.tizen.vc-unittests/res/test_demandable_list.xml");
static const char *TEST_EMPTY_FILE_PATH = tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_APP"), "/org.tizen.vc-unittests/res/empty_file");
+static const char *TEST_PCM_DATA_PATH = tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_APP"), "/org.tizen.vc-unittests/res/test_pcm.dat");
static const char *TEST_DOMAIN = "domain";
static const char *DEFAULT_ENGINE_APP_ID = "org.tizen.vc-engine-default";
+
static vc_state_e g_vc_mgr_state = VC_STATE_NONE;
static vc_service_state_e g_vc_mgr_service_state = VC_SERVICE_STATE_NONE;
+static bool g_all_result_cb_invoked = false;
+static bool g_result_cb_invoked = false;
+static bool g_speech_detected_cb_invoked = false;
+static bool g_error_cb_invoked = false;
+static int g_set_selected_result_return = VC_ERROR_NONE;
+static int g_get_error_message_return = VC_ERROR_NONE;
+
+static unsigned char* g_pcm_data = nullptr;
+static long g_pcm_size = 0;
+static vc_cmd_list_h g_test_commands = nullptr;
static bool __is_mgr_state_changed(vc_state_e state, int wait_delay)
{
static bool __vc_mgr_all_result_cb(vc_result_event_e event, vc_cmd_list_h vc_cmd_list, const char *result, const char *msg, void *user_data)
{
- return true;
+ g_all_result_cb_invoked = true;
+ g_set_selected_result_return = vc_mgr_set_selected_results(g_test_commands);
+ return false;
}
static void __vc_mgr_pre_result_cb(vc_pre_result_event_e event, const char *result, void *user_data)
static void __vc_mgr_result_cb(vc_result_event_e event, vc_cmd_list_h vc_cmd_list, const char* result, void* user_data)
{
+ g_result_cb_invoked = true;
}
static void __vc_mgr_begin_speech_detected_cb(void *user_data)
{
+ g_speech_detected_cb_invoked = true;
}
static void __vc_mgr_dialog_request_cb(int pid, const char *disp_text, const char *utt_text, bool continuous, void *user_data)
static void __vc_mgr_error_cb(vc_error_e reason, void* user_data)
{
+ g_error_cb_invoked = true;
+
+ char *error = nullptr;
+ g_get_error_message_return = vc_mgr_get_error_message(&error);
+ free(error);
}
static void __vc_mgr_vc_tts_streaming_cb(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len, void *user_data)
return commands;
}
-static void __initialize_ecore()
-{
- ecore_init();
- ecore_main_loop_glib_integrate();
-}
-
-static void __shutdown_ecore()
-{
- ecore_shutdown();
-}
-
static bool __is_vc_mgr_supported()
{
bool is_vc_supported = false;
return false;
}
+static bool __is_all_result_cb_invoked(int wait_delay)
+{
+ int max_count = wait_delay * 10;
+ int count = 0;
+ while (max_count > count && false == g_all_result_cb_invoked) {
+ ecore_main_loop_iterate();
+ usleep(100000);
+ count++;
+ }
+
+ return g_all_result_cb_invoked;
+}
+
+static bool __is_result_cb_invoked(int wait_delay)
+{
+ int max_count = wait_delay * 10;
+ int count = 0;
+ while (max_count > count && false == g_result_cb_invoked) {
+ ecore_main_loop_iterate();
+ usleep(100000);
+ count++;
+ }
+
+ return g_result_cb_invoked;
+}
+
+static bool __is_speech_detected_cb_invoked(int wait_delay)
+{
+ int max_count = wait_delay * 10;
+ int count = 0;
+ while (max_count > count && false == g_speech_detected_cb_invoked) {
+ ecore_main_loop_iterate();
+ usleep(100000);
+ count++;
+ }
+
+ return g_speech_detected_cb_invoked;
+}
+
+static bool __is_error_cb_invoked(int wait_delay)
+{
+ int max_count = wait_delay * 10;
+ int count = 0;
+ while (max_count > count && false == g_error_cb_invoked) {
+ ecore_main_loop_iterate();
+ usleep(100000);
+ count++;
+ }
+
+ return g_error_cb_invoked;
+}
+
+static void __get_test_PCM_data()
+{
+ const char* pcm_path = TEST_PCM_DATA_PATH;
+ FILE* fp_in = fopen(pcm_path, "rb");
+ if (fp_in == nullptr) {
+ return;
+ }
+
+ fseek(fp_in, 0, SEEK_END);
+ long size = ftell(fp_in);
+ fseek(fp_in, 0, SEEK_SET);
+ if (size <= 0) {
+ fclose(fp_in);
+ return;
+ }
+
+ unsigned char* data = (unsigned char*)calloc(sizeof(unsigned char), size);
+ if (NULL == data) {
+ fclose(fp_in);
+ return;
+ }
+ size_t read_size = fread(data, sizeof(unsigned char), size, fp_in);
+ fclose(fp_in);
+
+ if (read_size <= 0) {
+ free(data);
+ return;
+ }
+
+ g_pcm_size = size;
+ g_pcm_data = data;
+
+ return;
+}
+
+static void __initialize_test_environment()
+{
+ ecore_init();
+ ecore_main_loop_glib_integrate();
+
+ g_vc_mgr_state = VC_STATE_NONE;
+ g_vc_mgr_service_state = VC_SERVICE_STATE_NONE;
+
+ g_all_result_cb_invoked = false;
+ g_result_cb_invoked = false;
+ g_speech_detected_cb_invoked = false;
+ g_error_cb_invoked = false;
+ g_set_selected_result_return = VC_ERROR_OPERATION_FAILED;
+ g_get_error_message_return = VC_ERROR_OPERATION_FAILED;
+
+ g_test_commands = __create_test_command_list();
+
+ vc_setting_initialize();
+ vc_setting_set_language("en_US");
+}
+
+static void __shutdown_test_environment()
+{
+ vc_cmd_list_destroy(g_test_commands, true);
+ g_test_commands = nullptr;
+
+ vc_setting_set_auto_language(true);
+ vc_setting_deinitialize();
+
+ ecore_shutdown();
+}
+
+static void __test_voice_recording()
+{
+ EXPECT_EQ(vc_mgr_set_recognition_mode(VC_RECOGNITION_MODE_MANUAL), VC_ERROR_NONE);
+ EXPECT_EQ(vc_mgr_set_audio_streaming_mode(VC_AUDIO_STREAMING_MODE_OUTSIDE), VC_ERROR_NONE);
+
+ ASSERT_EQ(vc_mgr_set_command_list(g_test_commands), VC_ERROR_NONE);
+
+ ASSERT_EQ(vc_mgr_start(false), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_RECORDING, 5), true);
+
+ __get_test_PCM_data();
+ ASSERT_NE(g_pcm_data, nullptr);
+ ASSERT_GT(g_pcm_size, 0);
+
+ const size_t shift_size = 12000;
+ int data_num = g_pcm_size / shift_size;
+ for (int i = 0; i <= data_num; i++ ) {
+ if (0 == i) {
+ EXPECT_EQ(vc_mgr_send_audio_streaming(VC_AUDIO_STREAMING_EVENT_START, &g_pcm_data[i*shift_size], shift_size), VC_ERROR_NONE);
+ } else if (data_num == i) {
+ EXPECT_EQ(vc_mgr_send_audio_streaming(VC_AUDIO_STREAMING_EVENT_FINISH, &g_pcm_data[i*shift_size], g_pcm_size % shift_size), VC_ERROR_NONE);
+ } else {
+ EXPECT_EQ(vc_mgr_send_audio_streaming(VC_AUDIO_STREAMING_EVENT_CONTINUE, &g_pcm_data[i*shift_size], shift_size), VC_ERROR_NONE);
+ }
+ }
+
+ ASSERT_EQ(vc_mgr_stop(), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_PROCESSING, 5), true);
+}
+
namespace {
class VcMgrTestInNoneState : public testing::Test {
public:
virtual void SetUp()
{
- __initialize_ecore();
- g_vc_mgr_state = VC_STATE_NONE;
- g_vc_mgr_service_state = VC_SERVICE_STATE_NONE;
+ __initialize_test_environment();
__is_feature_supported = __is_vc_mgr_supported();
}
virtual void TearDown()
{
vc_mgr_deinitialize();
- __shutdown_ecore();
+ __shutdown_test_environment();
}
public:
public:
virtual void SetUp()
{
- __initialize_ecore();
- g_vc_mgr_state = VC_STATE_NONE;
- g_vc_mgr_service_state = VC_SERVICE_STATE_NONE;
+ __initialize_test_environment();
__is_feature_supported = __is_vc_mgr_supported();
EXPECT_EQ(vc_mgr_initialize(), VC_ERROR_NONE);
EXPECT_EQ(vc_mgr_unset_service_state_changed_cb(), VC_ERROR_NONE);
EXPECT_EQ(vc_mgr_deinitialize(), VC_ERROR_NONE);
- __shutdown_ecore();
+ __shutdown_test_environment();
}
public:
public:
virtual void SetUp()
{
- __initialize_ecore();
- g_vc_mgr_state = VC_STATE_NONE;
- g_vc_mgr_service_state = VC_SERVICE_STATE_NONE;
+ __initialize_test_environment();
__is_feature_supported = __is_vc_mgr_supported();
EXPECT_EQ(vc_mgr_initialize(), VC_ERROR_NONE);
EXPECT_EQ(vc_mgr_set_state_changed_cb(__vc_mgr_state_changed_cb, nullptr), VC_ERROR_NONE);
EXPECT_EQ(vc_mgr_set_service_state_changed_cb(__vc_mgr_service_state_changed_cb, nullptr), VC_ERROR_NONE);
+ EXPECT_EQ(vc_mgr_set_all_result_cb(__vc_mgr_all_result_cb, nullptr), VC_ERROR_NONE);
EXPECT_EQ(vc_mgr_prepare(), VC_ERROR_NONE);
ASSERT_EQ(true, __is_mgr_state_changed(VC_STATE_READY, 5));
ASSERT_EQ(true, __is_mgr_service_state_changed(VC_SERVICE_STATE_READY, 5));
EXPECT_EQ(vc_mgr_unset_service_state_changed_cb(), VC_ERROR_NONE);
EXPECT_EQ(vc_mgr_deinitialize(), VC_ERROR_NONE);
- __shutdown_ecore();
+ __shutdown_test_environment();
}
public:
* @since_tizen 5.0
* @description Positive UTC for set audio type
*/
-TEST_F(VcMgrTestInReadyState, vc_set_result_cb_p)
+TEST_F(VcMgrTestInReadyState, utc_vc_mgr_set_audio_type_p)
{
const char *audioType = "audio_id";
if (false == __is_feature_supported) {
}
/**
+ * @testcase utc_vc_mgr_set_all_result_cb_p2
+ * @since_tizen 5.0
+ * @description Positive UTC for set all result callback
+ */
+TEST_F(VcMgrTestInInitializedState, utc_vc_mgr_set_all_result_cb_p2)
+{
+ if (false == __is_feature_supported) {
+ EXPECT_EQ(vc_mgr_set_all_result_cb(__vc_mgr_all_result_cb, nullptr), VC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ EXPECT_EQ(vc_mgr_set_all_result_cb(__vc_mgr_all_result_cb, nullptr), VC_ERROR_NONE);
+
+ ASSERT_EQ(vc_mgr_prepare(), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_state_changed(VC_STATE_READY, 5), true);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_READY, 5), true);
+
+ __test_voice_recording();
+
+ EXPECT_EQ(__is_all_result_cb_invoked(5), true);
+}
+
+/**
* @testcase utc_vc_mgr_set_all_result_cb_n1
* @since_tizen 5.0
* @description Negative UTC for set all result callback
}
/**
+ * @testcase utc_vc_mgr_set_result_cb_p2
+ * @since_tizen 5.0
+ * @description Positive UTC for set result callback
+ */
+TEST_F(VcMgrTestInInitializedState, utc_vc_mgr_set_result_cb_p2)
+{
+ if (false == __is_feature_supported) {
+ EXPECT_EQ(vc_mgr_set_result_cb(__vc_mgr_result_cb, nullptr), VC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ // TODO: Is it necessary to set all result callback?
+ EXPECT_EQ(vc_mgr_set_all_result_cb(__vc_mgr_all_result_cb, nullptr), VC_ERROR_NONE);
+ EXPECT_EQ(vc_mgr_set_result_cb(__vc_mgr_result_cb, nullptr), VC_ERROR_NONE);
+
+ ASSERT_EQ(vc_mgr_prepare(), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_state_changed(VC_STATE_READY, 5), true);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_READY, 5), true);
+
+ __test_voice_recording();
+
+ EXPECT_EQ(__is_result_cb_invoked(5), true);
+}
+
+/**
* @testcase utc_vc_mgr_set_result_cb_n1
* @since_tizen 5.0
* @description Negative UTC for set result callback
}
/**
+ * @testcase utc_vc_mgr_set_speech_detected_cb_p2
+ * @since_tizen 5.0
+ * @description Positive UTC for set speech detected callback
+ */
+TEST_F(VcMgrTestInInitializedState, utc_vc_mgr_set_speech_detected_cb_p2)
+{
+ if (false == __is_feature_supported) {
+ EXPECT_EQ(vc_mgr_set_speech_detected_cb(__vc_mgr_begin_speech_detected_cb, nullptr), VC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ EXPECT_EQ(vc_mgr_set_speech_detected_cb(__vc_mgr_begin_speech_detected_cb, nullptr), VC_ERROR_NONE);
+
+ ASSERT_EQ(vc_mgr_prepare(), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_state_changed(VC_STATE_READY, 5), true);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_READY, 5), true);
+
+ __test_voice_recording();
+
+ EXPECT_EQ(__is_speech_detected_cb_invoked(5), true);
+}
+
+/**
* @testcase utc_vc_mgr_set_speech_detected_cb_n1
* @since_tizen 5.0
* @description Negative UTC for set speech detected callback
}
/**
+ * @testcase utc_vc_mgr_get_error_message_p
+ * @since_tizen 5.0
+ * @description Positive UTC for get error message
+ */
+TEST_F(VcMgrTestInInitializedState, utc_vc_mgr_get_error_message_p)
+{
+ if (false == __is_feature_supported) {
+ EXPECT_EQ(vc_mgr_set_error_cb(__vc_mgr_error_cb, nullptr), VC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ char* engine_id = vconf_get_str(VCONFKEY_VC_ENGINE_DEFAULT);
+
+ app_context_h context = nullptr;
+ EXPECT_EQ(app_manager_get_app_context(engine_id, &context), APP_MANAGER_ERROR_NONE);
+ EXPECT_NE(context, nullptr);
+ free(engine_id);
+
+ EXPECT_EQ(vc_mgr_set_error_cb(__vc_mgr_error_cb, nullptr), VC_ERROR_NONE);
+
+ EXPECT_EQ(vc_mgr_prepare(), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_state_changed(VC_STATE_READY, 5), true);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_READY, 5), true);
+
+ EXPECT_EQ(app_manager_terminate_app(context), APP_MANAGER_ERROR_NONE);
+ app_context_destroy(context);
+
+ EXPECT_EQ(__is_error_cb_invoked(5), true);
+ EXPECT_EQ(g_get_error_message_return, VC_ERROR_NONE);
+}
+
+/**
* @testcase utc_vc_mgr_get_error_message_n1
* @since_tizen 5.0
* @description Negative UTC for get error message
}
/**
+ * @testcase utc_vc_mgr_set_error_cb_p2
+ * @since_tizen 5.0
+ * @description Positive UTC for set error callback
+ */
+TEST_F(VcMgrTestInInitializedState, utc_vc_mgr_set_error_cb_p2)
+{
+ if (false == __is_feature_supported) {
+ EXPECT_EQ(vc_mgr_set_error_cb(__vc_mgr_error_cb, nullptr), VC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ char* engine_id = vconf_get_str(VCONFKEY_VC_ENGINE_DEFAULT);
+
+ app_context_h context = nullptr;
+ EXPECT_EQ(app_manager_get_app_context(engine_id, &context), APP_MANAGER_ERROR_NONE);
+ EXPECT_NE(context, nullptr);
+ free(engine_id);
+
+ EXPECT_EQ(vc_mgr_set_error_cb(__vc_mgr_error_cb, nullptr), VC_ERROR_NONE);
+
+ EXPECT_EQ(vc_mgr_prepare(), VC_ERROR_NONE);
+ ASSERT_EQ(__is_mgr_state_changed(VC_STATE_READY, 5), true);
+ ASSERT_EQ(__is_mgr_service_state_changed(VC_SERVICE_STATE_READY, 5), true);
+
+ EXPECT_EQ(app_manager_terminate_app(context), APP_MANAGER_ERROR_NONE);
+ app_context_destroy(context);
+
+ EXPECT_EQ(__is_error_cb_invoked(5), true);
+}
+
+/**
* @testcase utc_vc_mgr_set_error_cb_n1
* @since_tizen 5.0
* @description Negative UTC for set error callback
}
/**
+ * @testcase utc_vc_mgr_set_selected_results_p
+ * @since_tizen 5.0
+ * @description Positive UTC for set selected results
+ */
+TEST_F(VcMgrTestInReadyState, utc_vc_mgr_set_selected_results_p)
+{
+ if (false == __is_feature_supported) {
+ EXPECT_EQ(vc_mgr_set_selected_results(g_test_commands), VC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ __test_voice_recording();
+
+ EXPECT_EQ(__is_all_result_cb_invoked(5), true);
+ EXPECT_EQ(g_set_selected_result_return, VC_ERROR_NONE);
+}
+
+/**
* @testcase utc_vc_mgr_set_selected_results_n1
* @since_tizen 5.0
* @description Negative UTC for set selected results