This function saves a result callback by each input_event_type in client module.
Also, create input_event_type as enum for readabiltiy.
And, add test code for mmi_client_set_result_cb.
Change-Id: I2a4f27ebe7d1c235a99fc125153d2ed4ef1fed7e
mmi_h->rpc_h = mmi_ipc_get_rpc_h();
mmi_h->stub_appid = mmi_ipc_get_stub_appid();
mmi_h->state = mmi_ipc_get_state();
+ mmi_h->result_cb_list = NULL;
return MMI_ERROR_NONE;
}
int mmi_client_set_result_cb(int input_event_type, result_cb callback, void* user_data)
{
+ LOGI("Set result cb about input event type(%d) to client", input_event_type);
+
+ if (callback == NULL) {
+ LOGE("Callback is invalid");
+ return MMI_ERROR_INVALID_PARAMETER;
+ }
+
+ result_cb_s* input_result_callback = (result_cb_s*)calloc(1, sizeof(result_cb_s));
+ if (input_result_callback == NULL) {
+ LOGE("[ERROR] Fail to allocate memory");
+ return MMI_ERROR_OUT_OF_MEMORY;
+ }
+
+ input_result_callback->input_event_type = input_event_type;
+ input_result_callback->result_callback = callback;
+ mmi_h->result_cb_list = g_list_append(mmi_h->result_cb_list, input_result_callback);
+
return MMI_ERROR_NONE;
}
+
+mmi_handle mmi_client_get(void)
+{
+ return mmi_h;
+}
#define __MMI_CLIENT_H__
#include "mmi-common.h"
+#include <glib.h>
typedef void* mmi_rpc_h;
mmi_rpc_h rpc_h;
const char *stub_appid;
int state;
+ GList* result_cb_list;
} mmi_struct_s;
typedef mmi_struct_s* mmi_handle;
+typedef struct {
+ int input_event_type;
+ int input_event_state;
+ result_cb result_callback;
+} result_cb_s;
+
#ifdef __cplusplus
extern "C" {
#endif
int mmi_client_create(void);
int mmi_client_destroy(void);
int mmi_client_set_result_cb(int input_event_type, result_cb callback, void* user_data);
+mmi_handle mmi_client_get(void);
#ifdef __cplusplus
}
typedef void (*result_cb)(void *user_data, int input_event_type, const char *result_out);
+typedef enum {
+ MMI_VOICE_TOUCH,
+ MMI_VOICE_RECOGNITION,
+} mmi_input_event_type_e;
+
#endif //__MMI_COMMON_H__
mmi_client_destroy();
}
-TEST_F(MMIMainTest, MMIClientSetResultCb)
+void voice_touch_callback(void *user_data, int input_event_type, const char *result_out)
+{
+}
+
+TEST_F(MMIMainTest, MMIClientSetResultCbSuccess)
{
int res = mmi_init();
- int input_event_type = 0;
+ mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
EXPECT_EQ(res, MMI_ERROR_NONE);
- res = mmi_client_set_result_cb(input_event_type, NULL, NULL);
+ res = mmi_client_set_result_cb(input_event_type, voice_touch_callback, NULL);
+ EXPECT_EQ(res, MMI_ERROR_NONE);
+
+ mmi_handle mmi_client = mmi_client_get();
+ GList* iter = NULL;
+ result_cb_s *data = NULL;
+
+ iter = g_list_first(mmi_client->result_cb_list);
+ if(NULL != iter) {
+ data = (result_cb_s*)iter->data;
+ EXPECT_NE(data->result_callback, nullptr);
+ EXPECT_EQ(data->result_callback, voice_touch_callback);
+ EXPECT_EQ(data->input_event_type, MMI_VOICE_TOUCH);
+ }
+ else {
+ EXPECT_TRUE(false);
+ }
+
+ mmi_shutdown();
+}
+
+TEST_F(MMIMainTest, MMIClientSetResultCbFail)
+{
+ int res = mmi_init();
+ mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
EXPECT_EQ(res, MMI_ERROR_NONE);
+ res = mmi_client_set_result_cb(input_event_type, NULL, NULL);
+ EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
mmi_shutdown();
}