From: hj kim Date: Thu, 9 Aug 2018 00:20:31 +0000 (+0900) Subject: Fix test code crash X-Git-Tag: accepted/tizen/unified/20180810.062842^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9057c961cbacc7b49fb146a6b781bc8fbe09012e;p=platform%2Fcore%2Fapi%2Fmedia-controller.git Fix test code crash Change-Id: I23361c014f3042216d03a877d5a857a9e7eab071 --- diff --git a/test/client_test/media_controller_client_test.c b/test/client_test/media_controller_client_test.c index 94ae6ef..cc5e994 100755 --- a/test/client_test/media_controller_client_test.c +++ b/test/client_test/media_controller_client_test.c @@ -186,7 +186,7 @@ void _mc_cmd_reply_received_cb(const char *server_name, const char *request_id, unsigned int i = 0; unsigned int found = 0; for (i = 0; i < TEST_REQ_MAX; i++) { - if (strcmp(request_id, g_request_id[i]) == 0) { + if ((g_request_id[i] != NULL) && (strcmp(request_id, g_request_id[i]) == 0)) { found = 1; break; } @@ -348,25 +348,23 @@ bool server_playlist_item_cb(const char *index, mc_metadata_h meta, void *user_d bool server_playlist_list_cb(mc_playlist_h playlist, void *user_data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; - char *playlist_name = NULL; if (playlist == NULL) { mc_error("Invalid playlist handle"); return false; } - ret = mc_playlist_get_name(playlist, &playlist_name); + MC_SAFE_FREE(g_playlist_name); + ret = mc_playlist_get_name(playlist, &g_playlist_name); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_error("Fail to mc_playlist_get_name [%d]", ret); - mc_debug("playlist_name [%s]", playlist_name); + mc_debug("playlist_name [%s]", g_playlist_name); ret = mc_playlist_foreach_item(playlist, server_playlist_item_cb, NULL); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_error("Fail to mc_playlist_foreach_item [%d]", ret); - MC_SAFE_FREE(playlist_name); - return true; } @@ -510,10 +508,12 @@ static gboolean _send() return FALSE; } - ret = mc_client_send_playlist_cmd(g_mc_client, g_server_name, g_playlist_name, "1", MC_PLAYBACK_ACTION_PLAY, 300, &g_request_id[TEST_REQ_PLAYLIST_CMD]); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - g_print("Fail to send play playlist item [%d]", ret); - return FALSE; + if (g_playlist_name != NULL) { + ret = mc_client_send_playlist_cmd(g_mc_client, g_server_name, g_playlist_name, "1", MC_PLAYBACK_ACTION_PLAY, 300, &g_request_id[TEST_REQ_PLAYLIST_CMD]); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to send play playlist item [%d]", ret); + return FALSE; + } } struct timespec reqtime; diff --git a/test/server_test/media_controller_server_test.c b/test/server_test/media_controller_server_test.c index 1ff5af2..bcbb55d 100755 --- a/test/server_test/media_controller_server_test.c +++ b/test/server_test/media_controller_server_test.c @@ -88,47 +88,62 @@ void __playback_state_command_received_cb(const char *client_name, mc_playback_s void __playback_action_received_cb(const char *client_name, const char *request_id, mc_playback_action_e action, void *user_data) { - int ret = 0; - g_print("[%s][%s] recieved playback action:[%d] from [%s]\n", client_name, request_id, action, client_name); + int ret = MEDIA_CONTROLLER_ERROR_NONE; + g_print("[%s] recieved playback action:[%d] from [%s]\n", request_id, action, client_name); - ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) - g_print("Fail to mc_server_send_command_reply\n"); + if (request_id != NULL) { + ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to mc_server_send_command_reply\n"); + } } void __playback_position_cmd_received_cb(const char *client_name, const char *request_id, unsigned long long position, void *user_data) { - int ret = 0; - g_print("[%s][%s] recieved playback position:[%llu] from [%s]\n", client_name, request_id, position, client_name); + int ret = MEDIA_CONTROLLER_ERROR_NONE; + g_print("[%s] recieved playback position:[%llu] from [%s]\n", request_id, position, client_name); - ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) - g_print("Fail to mc_server_send_command_reply\n"); + if (request_id != NULL) { + ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to mc_server_send_command_reply\n"); + } } void __shuffle_mode_cmd_received_cb(const char *client_name, const char *request_id, mc_shuffle_mode_e shuffle_mode, void *user_data) { - int ret = 0; - g_print("[%s][%s] recieved shuffle mode:[%d] from [%s]\n", client_name, request_id, shuffle_mode, client_name); + int ret = MEDIA_CONTROLLER_ERROR_NONE; + g_print("[%s] recieved shuffle mode:[%d] from [%s]\n", request_id, shuffle_mode, client_name); - ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) - g_print("Fail to mc_server_send_command_reply\n"); + if (request_id != NULL) { + ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to mc_server_send_command_reply\n"); + } } void __playlist_play_received_cb(const char* client_name, const char *request_id, const char *playlist_name, const char *index, mc_playback_action_e action, unsigned long long position, void *user_data) { - mc_debug("[%s]recieved playlist play : playlist_name[%s] index[%s] action[%d] position[%llu] from [%s]", request_id, playlist_name, index, action, position, client_name); + int ret = MEDIA_CONTROLLER_ERROR_NONE; + g_print("[%s] recieved playlist play : playlist_name[%s] index[%s] action[%d] position[%llu] from [%s]\n", request_id, playlist_name, index, action, position, client_name); + + if (request_id != NULL) { + ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to mc_server_send_command_reply\n"); + } } void __repeat_mode_cmd_received_cb(const char *client_name, const char *request_id, mc_repeat_mode_e repeat_mode, void *user_data) { - int ret = 0; + int ret = MEDIA_CONTROLLER_ERROR_NONE; + g_print("[%s] recieved repeat mode:[%d] from [%s]\n", request_id, repeat_mode, client_name); - g_print("[%s][%s] recieved repeat mode:[%d] from [%s]\n", client_name, request_id, repeat_mode, client_name); - ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) - g_print("Fail to mc_server_send_command_reply\n"); + if (request_id != NULL) { + ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to mc_server_send_command_reply\n"); + } } void __custom_command_received_cb(const char *client_name, const char *command, bundle *data, void *user_data) @@ -150,8 +165,8 @@ void __custom_command_received_cb(const char *client_name, const char *command, bundle_data = g_strdup_printf("%s, %s, %s, %s", get_value1, get_value2, get_value3, get_value4); } - g_print("[%s] recieved command:[%s] from [%s]\n", client_name, command, client_name); - g_print("[%s] recieved bundle:[%s] from [%s]\n", client_name, bundle_data, client_name); + g_print("recieved command:[%s] from [%s]\n", command, client_name); + g_print("recieved bundle:[%s] from [%s]\n", bundle_data, client_name); bundle *bundle_reply = bundle_create(); bundle_add_str(bundle_reply, "key1", "result1"); @@ -335,8 +350,8 @@ void __custom_cmd_received_cb(const char *client_name, const char *request_id, c bundle_data = g_strdup_printf("%s, %s, %s, %s", get_value1, get_value2, get_value3, get_value4); } - g_print("[%s] recieved request_id:[%s] command:[%s] from [%s]\n", client_name, request_id, command, client_name); - g_print("[%s] recieved bundle:[%s] from [%s]\n", client_name, bundle_data, client_name); + g_print("recieved request_id:[%s] command:[%s] from [%s]\n", request_id, command, client_name); + g_print("recieved bundle:[%s] from [%s]\n", bundle_data, client_name); bundle *bundle_reply = bundle_create(); bundle_add_str(bundle_reply, "key1", "result1_2"); @@ -344,9 +359,11 @@ void __custom_cmd_received_cb(const char *client_name, const char *request_id, c bundle_add_str(bundle_reply, "key3", "result3_2"); bundle_add_str(bundle_reply, "key4", "result4_2"); - ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, bundle_reply); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) - g_print("Fail to mc_server_send_command_reply\n"); + if (request_id != NULL) { + ret = mc_server_send_cmd_reply(g_mc_server, client_name, request_id, 0, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to mc_server_send_command_reply\n"); + } bundle_free(bundle_reply); if (bundle_data != NULL)