Refactored Test-Suite logging; 16/139816/7 accepted/tizen/unified/20170921.071949 submit/tizen/20170920.101730
authorIevgen Vagin <i.vagin@samsung.com>
Thu, 20 Jul 2017 12:37:19 +0000 (15:37 +0300)
committeraravind.gara <aravind.gara@samsung.com>
Wed, 20 Sep 2017 01:40:06 +0000 (10:40 +0900)
[Version] 0.0.6
[Issue Type] keep DRY code

Change-Id: Ia05870d43766a80474f115a0d44258b1f15ebac5
Signed-off-by: Ievgen Vagin <i.vagin@samsung.com>
test/logger/logger.h
test/proxy/src/proxy.c

index 572459b..4269056 100644 (file)
 #    define LOG_MODE_DLOG   (LOG_MODE_FILE << 2)
 #endif
 
+#define PRINT_INFO_OR_ERROR_INFO(expr, fmt, arg...)           \
+       do {                                                    \
+               if (expr)                                           \
+                       _logger_log_info(""fmt"", ##arg);               \
+               else                                                \
+                       _logger_log_err(""fmt"", ##arg);                \
+       } while (0)
+
 /* Enumeration for terminal colors. Used in internal _printf() function */
 typedef enum {
        CMD_COLOR_RED,
index f1a2a25..1719b75 100644 (file)
@@ -269,12 +269,10 @@ static int __proxy_sound_pool_create()
                                        "restrictions. Destroying the pool...");
 
                        ret = sound_pool_destroy(pool);
-                       if (ret == SOUND_POOL_ERROR_NONE)
-                               _logger_log_info("sound_pool_destroy(pool) returned %s value",
-                                               __stringify_sound_pool_error(ret));
-                       else
-                               _logger_log_err("sound_pool_destroy(pool) returned %s value",
-                                               __stringify_sound_pool_error(ret));
+
+                       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                                       "sound_pool_destroy(pool) returned %s value",
+                                       __stringify_sound_pool_error(ret));
 
                        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
                }
@@ -316,12 +314,9 @@ static int __proxy_sound_pool_destroy(const char *pars)
 
        ret = sound_pool_destroy(pools[idx]);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_destroy(pool) returned %s value",
-                               __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_destroy(pool) returned %s value",
-                               __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_destroy(pool) returned %s value",
+                       __stringify_sound_pool_error(ret));
 
        pools[idx] = NULL;
 
@@ -354,14 +349,9 @@ static int __proxy_sound_pool_activate(const char *pars)
 
        ret = sound_pool_activate(pools[idx]);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_set_state(pool, "
-                               "SOUND_POOL_STATE_ACTIVE) returned %s value",
-                               __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_set_state(pool, "
-                               "SOUND_POOL_STATE_ACTIVE) returned %s value",
-                               __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_set_state(pool, SOUND_POOL_STATE_ACTIVE) returned "
+                       "%s value", __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -391,14 +381,9 @@ static int __proxy_sound_pool_deactivate(const char *pars)
 
        int ret = sound_pool_deactivate(pools[idx]);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_set_state(pool, "
-                               "SOUND_POOL_STATE_INACTIVE) returned %s value",
-                               __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_set_state(pool, "
-                               "SOUND_POOL_STATE_INACTIVE) returned %s value",
-                               __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_set_state(pool, SOUND_POOL_STATE_INACTIVE) returned "
+                       "%s value", __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -432,12 +417,9 @@ static int __proxy_sound_pool_get_state(const char *pars)
        const char *str_state = (state == SOUND_POOL_STATE_ACTIVE ?
                        "SOUND_POOL_STATE_ACTIVE" : "SOUND_POOL_STATE_INACTIVE");
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_get_state(pool, state) returned %s value,"
-                               " state is %s", __stringify_sound_pool_error(ret), str_state);
-       else
-               _logger_log_err("sound_pool_get_state(pool, state) returned %s value,"
-                               " state is %s", __stringify_sound_pool_error(ret), str_state);
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_get_state(pool, state) returned %s value,"
+                       " state is %s", __stringify_sound_pool_error(ret), str_state);
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -472,12 +454,9 @@ static int __proxy_sound_pool_set_volume(const char *pars)
 
        int ret = sound_pool_set_volume(pools[idx], volume);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_set_global_volume(pool, %f) "
-                               "returned %s value", volume, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_set_global_volume(pool, %f) "
-                               "returned %s value", volume, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_set_global_volume(pool, %f) returned %s value",
+                       volume, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -509,14 +488,9 @@ static int __proxy_sound_pool_get_volume(const char *pars)
        float volume = .0f;
        int ret = sound_pool_get_volume(pools[idx], &volume);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_get_global_volume(pool, volume) returned "
-                               "%s value, volume is %f", __stringify_sound_pool_error(ret),
-                               volume);
-       else
-               _logger_log_err("sound_pool_get_global_volume(pool, volume) returned "
-                               "%s value, volume is %f", __stringify_sound_pool_error(ret),
-                               volume);
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_get_global_volume(pool, volume) returned %s value, "
+                       "volume is %f", __stringify_sound_pool_error(ret), volume);
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -556,12 +530,9 @@ static int __proxy_sound_pool_set_state_changed_cb_message(const char *pars)
        int ret = sound_pool_set_state_changed_cb(pools[idx], __sp_cb_msg,
                        messages[idx]);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_set_state_changed_cb(pool, cb, "
-                               "\"%s\") returned %s value", msg, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_set_state_changed_cb(pool, cb, "
-                               "\"%s\") returned %s value", msg, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_set_state_change_callback(pool, cb, \"%s\") "
+                       "returned %s value", msg, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -601,12 +572,9 @@ static int __proxy_sound_pool_set_state_changed_cb_script(const char *pars)
        int ret = sound_pool_set_state_changed_cb(pools[idx], __sp_cb_scr,
                        scripts[idx]);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_set_state_changed_cb(pool, cb, "
-                               "\"%s\") returned %s value", scr, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_set_state_changed_cb(pool, cb, "
-                               "\"%s\") returned %s value", scr, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_set_state_change_callback(pool, cb, \"%s\") "
+                       "returned %s value", scr, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -644,12 +612,9 @@ static int __proxy_sound_pool_unset_state_changed_cb(const char *pars)
                free(scripts[idx]);
        scripts[idx] = NULL;
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_unset_state_changed_cb(pool) "
-                               "returned %s value", __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_unset_state_changed_cb(pool) "
-                               "returned %s value", __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_unset_state_change_callback(pool) "
+                       "returned %s value", __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -723,14 +688,9 @@ static int __proxy_sound_pool_load_source_from_file(const char *pars)
 
        int ret = sound_pool_load_source_from_file(pools[idx], fname, tag);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_load_source_from_file(pool, \"%s\", "
-                               "\"%s\") returned %s value", fname, tag,
-                               __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_load_source_from_file(pool, \"%s\", "
-                               "\"%s\") returned %s value", fname, tag,
-                               __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_load_source_from_file(pool, \"%s\", \"%s\") returned "
+                       "%s value", fname, tag, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -764,12 +724,9 @@ static int __proxy_sound_pool_unload_source(const char *pars)
 
        int ret = sound_pool_unload_source(pools[idx], tag);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_unload_source(pool, \"%s\") returned "
-                               "%s value", tag, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_unload_source(pool, \"%s\") returned "
-                               "%s value", tag, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_unload_source(pool, \"%s\") returned "
+                       "%s value", tag, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -781,7 +738,7 @@ static int __proxy_sound_pool_play_stream(const char *pars)
        int loop = 0;
        float volume = 1.0f;
        unsigned rank = DEFAULT_STREAM_PRIORITY_RANK;
-    sound_pool_stream_priority_policy_e priority_policy = SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE;
+       sound_pool_stream_priority_policy_e priority_policy = SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE;
 
        char tag[MAX_PATH_LEN] = {'\0'};
 
@@ -852,12 +809,9 @@ static int __proxy_sound_pool_pause_stream(const char *pars)
 
        int ret = sound_pool_stream_pause(pools[idx], stream_idx);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_pause_stream(pool, %i) returned %s "
-                               "value", stream_idx, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_pause_stream(pool, %i) returned %s "
-                               "value", stream_idx, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_pause_stream(pool, %i) returned %s value",
+                       stream_idx, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -888,12 +842,9 @@ static int __proxy_sound_pool_resume_stream(const char *pars)
 
        int ret = sound_pool_stream_resume(pools[idx], stream_idx);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_resume_stream(pool, %i) returned %s "
-                               "value", stream_idx, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_resume_stream(pool, %i) returned %s "
-                               "value", stream_idx, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_resume_stream(pool, %i) returned %s value",
+                       stream_idx, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -924,12 +875,9 @@ static int __proxy_sound_pool_stop_stream(const char *pars)
 
        int ret = sound_pool_stream_stop(pools[idx], stream_idx);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_stop_stream(pool, %i) returned %s "
-                               "value", stream_idx, __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_stop_stream(pool, %i) returned %s "
-                               "value", stream_idx, __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_stop_stream(pool, %i) returned %s value",
+                       stream_idx, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -965,14 +913,9 @@ static int __proxy_sound_pool_stream_set_volume(const char *pars)
 
        int ret = sound_pool_stream_set_volume(pools[idx], stream_idx, volume_val);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_stream_set_volume(pool, %i, %f) "
-                               "returned %s value", stream_idx, volume_val,
-                               __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_stream_set_volume(pool, %i, %f) "
-                               "returned %s value", stream_idx, volume_val,
-                               __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_stream_set_volume(pool, %i, %f) returned %s value",
+                       stream_idx, volume_val, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -1005,14 +948,9 @@ static int __proxy_sound_pool_stream_get_volume(const char *pars)
        float volume = .0f;
        int ret = sound_pool_stream_get_volume(pools[idx], stream_idx, &volume);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_stream_get_volume(pool, %zu, volume) "
-                               "returned %s value, volume is %f", stream_idx,
-                               __stringify_sound_pool_error(ret), volume);
-       else
-               _logger_log_err("sound_pool_stream_get_volume(pool, %zu, volume) "
-                               "returned %s value, volume is %f", stream_idx,
-                               __stringify_sound_pool_error(ret), volume);
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_stream_get_volume(pool, %zu, volume) returned %s value, "
+                       "volume is %f", stream_idx, __stringify_sound_pool_error(ret), volume);
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -1045,14 +983,9 @@ static int __proxy_sound_pool_stream_set_priority(const char *pars)
 
        int ret = sound_pool_stream_set_priority(pools[idx], stream_idx, rank);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_stream_set_priority(pool, %zu, %u) "
-                               "returned %s value", stream_idx, rank,
-                               __stringify_sound_pool_error(ret));
-       else
-               _logger_log_err("sound_pool_stream_set_priority(pool, %zu, %u) "
-                               "returned %s value", stream_idx, rank,
-                               __stringify_sound_pool_error(ret));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_stream_set_priority(pool, %zu, %u) returned %s value",
+                       stream_idx, rank, __stringify_sound_pool_error(ret));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -1085,14 +1018,9 @@ static int __proxy_sound_pool_stream_get_priority(const char *pars)
        unsigned rank = 0;
        int ret = sound_pool_stream_get_priority(pools[idx], stream_idx, &rank);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_stream_get_priority(pool, %u, rank) "
-                               "returned %s value, rank value is %u", stream_idx,
-                               __stringify_sound_pool_error(ret), rank);
-       else
-               _logger_log_err("sound_pool_stream_get_priority(pool, %u, rank) "
-                               "returned %s value, rank value is %u", stream_idx,
-                               __stringify_sound_pool_error(ret), rank);
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_stream_get_priority(pool, %u, rank) returned %s value, "
+                       "rank value is %u", stream_idx, __stringify_sound_pool_error(ret), rank);
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }
@@ -1125,16 +1053,10 @@ static int __proxy_sound_pool_get_stream_state(const char *pars)
        sound_pool_stream_state_e state = SOUND_POOL_STREAM_STATE_NONE;
        int ret = sound_pool_stream_get_state(pools[idx], stream_idx,  &state);
 
-       if (ret == SOUND_POOL_ERROR_NONE)
-               _logger_log_info("sound_pool_get_stream_state(pool, %zu, state) "
-                               "returned %s value, state is %s", stream_idx,
-                               __stringify_sound_pool_error(ret),
-                               __stringify_stream_state(state));
-       else
-               _logger_log_err("sound_pool_get_stream_state(pool, %zu, state) "
-                               "returned %s value, state is %s", stream_idx,
-                               __stringify_sound_pool_error(ret),
-                               __stringify_stream_state(state));
+       PRINT_INFO_OR_ERROR_INFO(ret == SOUND_POOL_ERROR_NONE,
+                       "sound_pool_get_stream_state(pool, %zu, state) returned %s value, "
+                       "state is %s", stream_idx, __stringify_sound_pool_error(ret),
+                       __stringify_stream_state(state));
 
        return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
 }