From 7f7d40007f5afe5a3290ffade8aa69b31d5c4bb3 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Tue, 6 Sep 2022 16:56:57 +0900 Subject: [PATCH] add remove of callback lists When is calling, added result_cb_list also needs to destroy. So, add code of removing result_cb_list. Also, for checking this, add test too. Change-Id: Ic0428fc0db0f040138f71f221cc7bb362e909a81 --- src/mmi-client.c | 21 +++++++++++++++++++++ tests/mmi-main-test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/mmi-client.c b/src/mmi-client.c index bdd0f87..1d460ee 100644 --- a/src/mmi-client.c +++ b/src/mmi-client.c @@ -61,6 +61,27 @@ int mmi_client_destroy(void) } mmi_ipc_shutdown(); + + GList *iter = NULL; + result_cb_s *data = NULL; + + if (g_list_length(mmi_h->result_cb_list) > 0) { + iter = g_list_first(mmi_h->result_cb_list); + while (iter != NULL) { + data = iter->data; + if (data != NULL) { + data->input_event_type = 0; + data->result_callback = NULL; + free(data); + data = NULL; + + GList *temp = iter; + iter = g_list_next(iter); + mmi_h->result_cb_list = g_list_remove_link(mmi_h->result_cb_list, temp); + } + } + } + free(mmi_h); mmi_h = NULL; diff --git a/tests/mmi-main-test.cpp b/tests/mmi-main-test.cpp index 0f08648..917ca14 100644 --- a/tests/mmi-main-test.cpp +++ b/tests/mmi-main-test.cpp @@ -65,6 +65,10 @@ void voice_touch_callback(void *user_data, int input_event_type, const char *res { } +void voice_recognition_callback(void *user_data, int input_event_type, const char *result_out) +{ +} + TEST_F(MMIMainTest, MMIClientSetResultCbSuccess) { int res = mmi_init(); @@ -76,6 +80,7 @@ TEST_F(MMIMainTest, MMIClientSetResultCbSuccess) EXPECT_EQ(res, MMI_ERROR_NONE); mmi_handle mmi_client = mmi_client_get(); + GList* iter = NULL; result_cb_s *data = NULL; @@ -112,6 +117,7 @@ TEST_F(MMIMainTest, MMISetResultCbSuccess) mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH; EXPECT_EQ(res, MMI_ERROR_NONE); + res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL); EXPECT_EQ(res, MMI_ERROR_NONE); @@ -130,3 +136,19 @@ TEST_F(MMIMainTest, MMISetResultCbFail) mmi_shutdown(); } + +TEST_F(MMIMainTest, MMIClientDestroyRemoveGList) +{ + int res = mmi_init(); + mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH; + + EXPECT_EQ(res, MMI_ERROR_NONE); + + res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL); + EXPECT_EQ(res, MMI_ERROR_NONE); + + res = mmi_set_result_cb(MMI_VOICE_RECOGNITION, voice_recognition_callback, NULL); + EXPECT_EQ(res, MMI_ERROR_NONE); + + mmi_client_destroy(); +} -- 2.7.4