add remove of callback lists 98/281598/1
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 6 Sep 2022 07:56:57 +0000 (16:56 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 20 Sep 2022 04:52:31 +0000 (13:52 +0900)
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
tests/mmi-main-test.cpp

index bdd0f87..1d460ee 100644 (file)
@@ -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;
 
index 0f08648..917ca14 100644 (file)
@@ -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();
+}