Changed internal source code in multi callback APIs. 04/163804/5 accepted/tizen/unified/20171220.064708 submit/tizen/20171215.064142
authorjinwang.an <jinwang.an@samsung.com>
Wed, 13 Dec 2017 11:27:32 +0000 (20:27 +0900)
committerjinwang.an <jinwang.an@samsung.com>
Fri, 15 Dec 2017 05:14:24 +0000 (14:14 +0900)
 - Add Regression Test code for multi callback

Change-Id: I8a036ae118279f0ac37643988fbda24558cda0b6
Signed-off-by: jinwang.an <jinwang.an@samsung.com>
include/system_settings_private.h
src/system_settings.c
src/system_settings_multi_callback.c
src/system_settings_vconf.c

index eb4ca68..12b3e17 100644 (file)
@@ -335,11 +335,12 @@ int system_setting_vconf_set_changed_multi_cb(const char *vconf_key, system_sett
  * @brief Unset the system settings notification callback
  * @since_tizen 4.0
  * @param[in] vconf_key vconf key name used in the code
+ * @param[in] key system_settings_key_e value.
  * @return     0 on success, otherwise a negative error value
  * @retval     #SYSTEM_SETTINGS_ERROR_NONE Successful
  * @retval     #SYSTEM_SETTINGS_ERROR_IO_ERROR Internal I/O error
  */
-int system_setting_vconf_unset_changed_multi_cb(const char *vconf_key);
+int system_setting_vconf_unset_changed_multi_cb(const char *vconf_key, system_settings_key_e key);
 
 /**
  * @internal
index 3ac3efb..1ce015a 100644 (file)
@@ -1007,6 +1007,7 @@ int system_settings_add_changed_cb(system_settings_key_e key, system_settings_ch
        }
 
        system_settings_vconf_get_key_string(key, &vconf_string);
+       LOGE("[%s] key = %d %s", __FUNCTION__, key, vconf_string ? vconf_string : "NULL");
 
        /* Store the callback function from application side */
        ret = add_multi_callback(&system_setting_item->changed_cb_list, callback, user_data);
@@ -1053,7 +1054,7 @@ int system_settings_remove_changed_cb(system_settings_key_e key, system_settings
                system_settings_vconf_get_key_string(key, &vconf_string);
                if (vconf_string == NULL)
                        return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
-               ret = system_setting_vconf_unset_changed_multi_cb(vconf_string);
+               ret = system_setting_vconf_unset_changed_multi_cb(vconf_string, key);
                if (ret == SYSTEM_SETTINGS_ERROR_NONE)
                        system_setting_item->changed_cb_list.is_registered = 0;
                LOGE("Leave [%s]", __FUNCTION__);
@@ -3354,6 +3355,69 @@ static void utc_system_settings_add_changed_cb_p1(void)
 }
 
 
+static void utc_system_settings_changed_callback_1(system_settings_key_e key, void *user_data)
+{
+       _callback_called = true;
+}
+
+static void utc_system_settings_changed_callback_2(system_settings_key_e key, void *user_data)
+{
+       _callback_called = true;
+}
+
+static void utc_system_settings_add_remove_changed_cb_p1(void)
+{
+       int retcode = 0;
+       int key_idx = 0;
+
+       for (key_idx = SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE; key_idx < SYSTEM_SETTINGS_KEY_MAX ; key_idx++) {
+
+               if (key_idx == SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED + 1)
+                       continue; /* skip removed system-setting key */
+
+               if (key_idx == SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE)
+                       continue; /* skip removed system-setting key */
+
+               retcode = system_settings_add_changed_cb(key_idx,
+                                                                                                       utc_system_settings_changed_callback_1, NULL);
+
+               if (retcode == SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED) {
+                       g_assert_cmpint(retcode, ==, SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED);
+               } else {
+                       if (retcode != SYSTEM_SETTINGS_ERROR_NONE)
+                               printf("ERROR !! key =%d , ret = %d\n", key_idx, retcode);
+               }
+
+               retcode = system_settings_remove_changed_cb(key_idx,
+                                                                                                       utc_system_settings_changed_callback_1);
+
+               if (retcode == SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED) {
+                       g_assert_cmpint(retcode, ==, SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED);
+               } else {
+                       if (retcode != SYSTEM_SETTINGS_ERROR_NONE)
+                               printf("ERROR !! key =%d , ret = %d\n", key_idx, retcode);
+               }
+
+               retcode = system_settings_add_changed_cb(key_idx,
+                                                                                                        utc_system_settings_changed_callback_1, NULL);
+               my_assert_ret(retcode);
+
+               retcode = system_settings_add_changed_cb(key_idx,
+                                                                                                        utc_system_settings_changed_callback_2, NULL);
+               my_assert_ret(retcode);
+
+               retcode = system_settings_remove_changed_cb(key_idx,
+                                                                                                       utc_system_settings_changed_callback_1);
+               my_assert_ret(retcode);
+
+               retcode = system_settings_remove_changed_cb(key_idx,
+                                                                                                       utc_system_settings_changed_callback_2);
+               my_assert_ret(retcode);
+       }
+
+       return;
+}
+
 static void simple_test_case(void)
 {
        /* a suitable test */
@@ -3368,6 +3432,7 @@ void unittest_api()
        /* hook up your test functions */
        g_test_add_func("/API Test Case", simple_test_case);
        g_test_add_func("/utc_system_settings_add_changed_cb_p1", utc_system_settings_add_changed_cb_p1);
+       g_test_add_func("/utc_system_settings_add_remove_changed_cb_p1", utc_system_settings_add_remove_changed_cb_p1);
        g_test_add_func("/utc_system_settings_get_value_string_p1", utc_system_settings_get_value_string_p1);
        g_test_add_func("/utc_system_settings_get_value_string_p2", utc_system_settings_get_value_string_p2);
        g_test_add_func("/utc_system_settings_get_value_string_p3", utc_system_settings_get_value_string_p3);
index 13dcf09..29c5651 100644 (file)
@@ -60,7 +60,7 @@ int delete_multi_callback(callback_list *handle, system_settings_changed_cb ptr)
 
        GList* itr = find_callback_node(handle, ptr);
        if (itr) {
-               g_list_remove_link(handle->list, itr);
+               handle->list = g_list_remove_link(handle->list, itr);
                free_multi_callback_node((callback_node*)itr->data);
                g_list_free(itr);
        }
index f736ab1..85074a2 100644 (file)
@@ -344,11 +344,62 @@ static void system_setting_vconf_event_multi_cb(keynode_t *node, void *event_dat
        LOGE("Leave [%s]", __FUNCTION__);
 }
 
+static void system_setting_vconf_event_multi_cb_slot_0(keynode_t *node, void *event_data)
+{
+       system_setting_vconf_event_multi_cb(node, event_data);
+}
+
+static void system_setting_vconf_event_multi_cb_slot_1(keynode_t *node, void *event_data)
+{
+       system_setting_vconf_event_multi_cb(node, event_data);
+}
+
+static void system_setting_vconf_event_multi_cb_slot_2(keynode_t *node, void *event_data)
+{
+       system_setting_vconf_event_multi_cb(node, event_data);
+}
+
+static void system_setting_vconf_event_multi_cb_slot_3(keynode_t *node, void *event_data)
+{
+       system_setting_vconf_event_multi_cb(node, event_data);
+}
+
+static system_setting_vconf_event_cb system_setting_vconf_get_event_multi_cb_slot(system_settings_key_e key)
+{
+       int cal = (int) key;
+       int slot = cal % 4;
+
+       switch (slot) {
+       case 0:
+               return system_setting_vconf_event_multi_cb_slot_0;
+
+       case 1:
+               return system_setting_vconf_event_multi_cb_slot_1;
+
+       case 2:
+               return system_setting_vconf_event_multi_cb_slot_2;
+
+       case 3:
+               return system_setting_vconf_event_multi_cb_slot_3;
+
+       default:
+               return NULL;
+       }
+}
+
 int system_setting_vconf_set_changed_multi_cb(const char *vconf_key, system_settings_key_e key)
 {
        LOGE("Enter [%s]", __FUNCTION__);
-       if (vconf_notify_key_changed(vconf_key, system_setting_vconf_event_multi_cb, (void *)key)) {
-               LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_notify_key_changed error");
+       system_setting_vconf_event_cb vconf_event_cb;
+
+       vconf_event_cb = system_setting_vconf_get_event_multi_cb_slot(key);
+
+       if (vconf_event_cb == NULL)
+               return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
+
+       int ret = vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)key);
+       if (ret != NULL) {
+               LOGE("[%s] INVALID_error , ret = %d, %s", __FUNCTION__, ret, "vconf_notify_key_changed error");
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
 
@@ -356,11 +407,19 @@ int system_setting_vconf_set_changed_multi_cb(const char *vconf_key, system_sett
        return SYSTEM_SETTINGS_ERROR_NONE;
 }
 
-int system_setting_vconf_unset_changed_multi_cb(const char *vconf_key)
+int system_setting_vconf_unset_changed_multi_cb(const char *vconf_key, system_settings_key_e key)
 {
        LOGE("Enter [%s]", __FUNCTION__);
-       if (vconf_ignore_key_changed(vconf_key, system_setting_vconf_event_multi_cb)) {
-               LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_ignore_key_changed error");
+       system_setting_vconf_event_cb vconf_event_cb;
+
+       vconf_event_cb = system_setting_vconf_get_event_multi_cb_slot(key);
+
+       if (vconf_event_cb == NULL)
+               return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
+
+       int ret = vconf_ignore_key_changed(vconf_key, vconf_event_cb);
+       if (ret != NULL) {
+               LOGE("[%s] INVALID_error , ret = %d, %s", __FUNCTION__, ret, "vconf_ignore_key_changed error");
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }