Refactoring: Integrate redundant test code 98/276698/18
authorjiyong.min <jiyong.min@samsung.com>
Thu, 23 Jun 2022 05:13:35 +0000 (14:13 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 4 Jul 2022 00:00:42 +0000 (09:00 +0900)
Change-Id: I4a503bc12a691fe08fde0384155a77daf33a4df5

anim/test/mm_util_anim_testsuite.c
common/include/mm_util_private.h
common/include/mm_util_test_internal.h [new file with mode: 0644]
gif/test/mm_util_gif_testsuite.c
heif/test/mm_util_heif_testsuite.c
imgp/test/mm_util_imgp_testsuite.c
jpeg/test/mm_util_jpeg_testsuite.c
jxl/test/mm_util_jxl_testsuite.c
magick/test/mm_util_magick_testsuite.c
packaging/libmm-utility.spec
webp/test/mm_util_webp_testsuite.c

index 370b3fd..06890f1 100644 (file)
@@ -26,7 +26,6 @@
 #include <mm_util_private.h>
 #include <tzplatform_config.h>
 
-#define TEST_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
 
 #define WEBP_ENCODE_FILE_PATH  tzplatform_mkpath(TZ_USER_CONTENT, "anim_test_enc_file.webp")
 #define WEBP_ENCODE_MEM_PATH   tzplatform_mkpath(TZ_USER_CONTENT, "anim_test_enc_mem.webp")
@@ -53,7 +52,7 @@ static void __decode_func(gpointer data, gpointer user_data)
        char *path = (char *)data;
        mm_util_image_h image = NULL;
 
-       if (!TEST_STRING_VALID(path)) {
+       if (!MMUTIL_STRING_VALID(path)) {
                g_print("\t[ANIM_testsuite] invalid path %s\n", path);
                return;
        }
@@ -161,7 +160,7 @@ static gboolean __get_arguments(int argc, char *argv[])
 {
        g_path = g_strdup(argv[1]);
 
-       if (!TEST_STRING_VALID(g_path)) {
+       if (!MMUTIL_STRING_VALID(g_path)) {
                fprintf(stderr, "\t[ANIM_testsuite] invalid path %s\n", argv[1]);
                return FALSE;
        }
@@ -189,38 +188,60 @@ static void __add_image(gpointer data, gpointer user_data)
                fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_add_image failed : %d\n", ret);
 }
 
-static gboolean __test_encode_to_file(mm_util_img_codec_type type, const char *path)
+static int __anim_encode_setup(mm_util_img_codec_type type, mm_util_anim_enc_h *anim_encode)
 {
-       int ret = 0;
+       int ret = MM_UTIL_ERROR_NONE;
        mm_util_anim_enc_h anim_enc = NULL;
 
-       fprintf(stderr, "[ANIM_testsuite] The test begins: %d, %s\n", type, path);
+       mm_util_retvm_if(!anim_encode, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid anim_encode");
 
        ret = mm_util_anim_enc_create(type, &anim_enc);
        if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
-               return FALSE;
+               fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_create failed : %d\n", ret);
+               return ret;
        }
 
        ret = mm_util_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
        if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
+               fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_bgcolor failed : %d\n", ret);
                if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
-                       goto END;
+                       goto ERROR;
        }
 
        ret = mm_util_anim_enc_set_loop_count(anim_enc, TEST_LOOP_COUNT);
        if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
+               fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_loop_count failed : %d\n", ret);
                if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
-                       goto END;
+                       goto ERROR;
        }
 
        ret = mm_util_anim_enc_set_lossless(anim_enc, TRUE);
        if (ret != MM_UTIL_ERROR_NONE) {
                fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_lossless failed : %d\n", ret);
                if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
-                       goto END;
+                       goto ERROR;
+       }
+
+       *anim_encode = anim_enc;
+       fprintf(stderr, "[ANIM_testsuite] The handle setup\n");
+       return MM_UTIL_ERROR_NONE;
+ERROR:
+       mm_util_anim_enc_destroy(anim_enc);
+
+       return ret;
+}
+
+static gboolean __test_encode_to_file(mm_util_img_codec_type type, const char *path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_anim_enc_h anim_enc = NULL;
+
+       fprintf(stderr, "[ANIM_testsuite] The test begins: %d, %s\n", type, path);
+
+       ret = __anim_encode_setup(type, &anim_enc);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               fprintf(stderr, "\t[ANIM_testsuite] __anim_enc_setup failed : %d\n", ret);
+               return ret;
        }
 
        g_queue_foreach(g_queue_images, __add_image, anim_enc);
@@ -229,20 +250,16 @@ static gboolean __test_encode_to_file(mm_util_img_codec_type type, const char *p
        if (ret != MM_UTIL_ERROR_NONE)
                fprintf(stderr, "\t[ANIM_testsuite] mm_util_encode_webp_to_file failed : %d\n", ret);
 
-END:
        mm_util_anim_enc_destroy(anim_enc);
 
-       fprintf(stderr, "[ANIM_testsuite] The test ended\n");
+       fprintf(stderr, "[ANIM_testsuite] The test finished.\n");
 
-       if (ret != MM_UTIL_ERROR_NONE)
-               return FALSE;
-
-       return TRUE;
+       return (ret == MM_UTIL_ERROR_NONE);
 }
 
 static gboolean __test_encode_to_buffer(mm_util_img_codec_type type, const char *path)
 {
-       int ret = 0;
+       int ret = MM_UTIL_ERROR_NONE;
        mm_util_anim_enc_h anim_enc = NULL;
        /* for encoding webp to memory */
        unsigned char *encoded_data = NULL;
@@ -250,55 +267,28 @@ static gboolean __test_encode_to_buffer(mm_util_img_codec_type type, const char
 
        fprintf(stderr, "[ANIM_testsuite] The test begins: %d, %s\n", type, path);
 
-       ret = mm_util_anim_enc_create(type, &anim_enc);
+       ret = __anim_encode_setup(type, &anim_enc);
        if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
-               return FALSE;
-       }
-
-       ret = mm_util_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
-               if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
-                       goto END;
+               fprintf(stderr, "\t[ANIM_testsuite] __anim_enc_setup failed : %d\n", ret);
+               return ret;
        }
-
-       ret = mm_util_anim_enc_set_loop_count(anim_enc, TEST_LOOP_COUNT);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
-               if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
-                       goto END;
-       }
-
-       ret = mm_util_anim_enc_set_lossless(anim_enc, true);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_lossless failed : %d\n", ret);
-               if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
-                       goto END;
-       }
-
        g_queue_foreach(g_queue_images, __add_image, anim_enc);
 
        ret = mm_util_anim_enc_save_to_buffer(anim_enc, &encoded_data, &encoded_size);
-       if (ret != MM_UTIL_ERROR_NONE) {
+       if (ret == MM_UTIL_ERROR_NONE) {
+               ret = mm_util_file_write(path, encoded_data, encoded_size);
+               if (ret != MM_UTIL_ERROR_NONE)
+                       printf("Fail mm_util_file_write [%d]\n", ret);
+       } else {
                fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_save_to_buffer failed : %d\n", ret);
-               goto END;
        }
 
-       ret = mm_util_file_write(path, encoded_data, encoded_size);
-       if (ret != MM_UTIL_ERROR_NONE)
-               printf("Fail mm_util_file_write [%d]\n", ret);
-
-END:
        mm_util_anim_enc_destroy(anim_enc);
-       g_free(encoded_data);
-
-       fprintf(stderr, "[ANIM_testsuite] The test ended\n");
+       MMUTIL_SAFE_FREE(encoded_data);
 
-       if (ret != MM_UTIL_ERROR_NONE)
-               return FALSE;
+       fprintf(stderr, "[ANIM_testsuite] The test finished.\n");
 
-       return TRUE;
+       return (ret == MM_UTIL_ERROR_NONE);
 }
 
 int main(int argc, char *argv[])
@@ -308,37 +298,37 @@ int main(int argc, char *argv[])
                return 0;
        }
 
-       if (FALSE == __get_arguments(argc, argv)) {
+       if (!__get_arguments(argc, argv)) {
                fprintf(stderr, "\t[ANIM_testsuite] _get_arguments failed\n");
                goto out;
        }
 
        /* test encoding webp animation to file */
-       if (FALSE == __test_encode_to_file(ANIM_CODEC_WEBP, WEBP_ENCODE_FILE_PATH)) {
-               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file failed\n");
+       if (!__test_encode_to_file(ANIM_CODEC_WEBP, WEBP_ENCODE_FILE_PATH)) {
+               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file(webp) failed\n");
                goto out;
        }
 
        /* test encoding webp animation to buffer */
-       if (FALSE == __test_encode_to_buffer(ANIM_CODEC_WEBP, WEBP_ENCODE_MEM_PATH)) {
-               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer failed\n");
+       if (!__test_encode_to_buffer(ANIM_CODEC_WEBP, WEBP_ENCODE_MEM_PATH)) {
+               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer(webp) failed\n");
                goto out;
        }
 
        /* test encoding agif animation to file */
-       if (FALSE == __test_encode_to_file(ANIM_CODEC_GIF, GIF_ENCODE_FILE_PATH)) {
-               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file failed\n");
+       if (!__test_encode_to_file(ANIM_CODEC_GIF, GIF_ENCODE_FILE_PATH)) {
+               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file(gif) failed\n");
                goto out;
        }
 
        /* test encoding agif animation to buffer */
-       if (FALSE == __test_encode_to_buffer(ANIM_CODEC_GIF, GIF_ENCODE_MEM_PATH)) {
-               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer failed\n");
+       if (!__test_encode_to_buffer(ANIM_CODEC_GIF, GIF_ENCODE_MEM_PATH)) {
+               fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer(gif) failed\n");
                goto out;
        }
 
 out:
-       g_free(g_path);
+       MMUTIL_SAFE_FREE(g_path);
        g_queue_free_full(g_queue_images, mm_image_destroy_image);
        g_queue_free_full(g_queue_files, g_free);
 
index 55f49a1..db33d13 100644 (file)
 extern "C" {
 #endif
 
+
 /* for memory management */
-#define MMUTIL_SAFE_FREE(x)                            { if (x) { free(x); x = NULL; } }
-#define MMUTIL_SAFE_STRCPY(dst, src, n)        g_strlcpy(dst, src, n)
-#define MMUTIL_STRING_VALID(str)       ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
+#define MMUTIL_SAFE_FREE(x) do { \
+               g_free(x); \
+               x = NULL; \
+       } while(0)
+#define MMUTIL_SAFE_IMAGE_FREE(x) do { \
+               mm_image_destroy_image(x); \
+               x = NULL; \
+       } while(0)
+#define MMUTIL_SAFE_STRCPY(dst, src, n)  g_strlcpy(dst, src, n)
+#define MMUTIL_STRING_VALID(str)         (str != NULL && strlen(str) > 0)
 
 #define SAFE_STRLCPY(dst, src, n)      g_strlcpy(dst, src, n);
 
diff --git a/common/include/mm_util_test_internal.h b/common/include/mm_util_test_internal.h
new file mode 100644 (file)
index 0000000..086ffd7
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __MM_UTIL_TEST_INTERNAL_H__
+#define __MM_UTIL_TEST_INTERNAL_H__
+
+#include <glib.h>
+#include <mm_util_image.h>
+
+typedef enum {
+       TEST_AUTO,
+       TEST_DECODE_FILE,
+       TEST_DECODE_BUFFER,
+       TEST_ENCODE_FILE,
+       TEST_ENCODE_BUFFER,
+       TEST_NUM,
+} mm_util_test_mode_e;
+
+#endif   /*__MM_UTIL_TEST_INTERNAL_H__*/
index 02da2d6..62dbe13 100644 (file)
 #include <mm_util_gif.h>
 #include <mm_util_image.h>
 #include <mm_util_private.h>
+#include <mm_util_test_internal.h>
 #include <tzplatform_config.h>
 
-#define SAFE_FREE(x)           { if (x != NULL) { free(x); x = NULL; } }
-#define SAFE_G_FREE(x)         { if (x != NULL) { g_free(x); x = NULL; } }
-#define SAFE_IMAGE_FREE(x)             { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
 #define DECODE_FILE_PATH       tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_dec_file.raw")
 #define DECODE_MEM_PATH                tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_dec_mem.raw")
 #define ENCODE_FILE_PATH       tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_enc_file.gif")
 #define ENCODE_MEM_PATH                tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_enc_mem.gif")
 
-typedef enum {
-       TEST_AUTO,
-       TEST_DECODE_FILE,
-       TEST_DECODE_MEMORY,
-       TEST_ENCODE_FILE,
-       TEST_ENCODE_MEMORY,
-       TEST_NUM,
-} test_mode_e;
-
 static char *MODE_TO_STR[] = {
        "AUTO",
        "DECODE_FILE",
@@ -88,9 +76,9 @@ gboolean _get_arguments(int argc, char *argv[])
 
        g_path = g_strdup(argv[2]);
 
-       if ((g_test_mode == TEST_AUTO) || (g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
+       if ((g_test_mode == TEST_AUTO) || (g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
                /* do nothing */
-       } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_MEMORY) {
+       } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_BUFFER) {
                if (argc < 4) {
                        fprintf(stderr, "\t[GIF_testsuite] not enough args\n");
                        _print_help(argv[0]);
@@ -113,7 +101,7 @@ gboolean _get_arguments(int argc, char *argv[])
        return TRUE;
 }
 
-gboolean _test_decode(const test_mode_e mode)
+gboolean _test_decode(const mm_util_test_mode_e mode)
 {
        int ret = 0;
        unsigned char *data = NULL;
@@ -134,11 +122,11 @@ gboolean _test_decode(const test_mode_e mode)
                ret = mm_util_file_write(DECODE_FILE_PATH, data, size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[GIF_testsuite] mm_util_file_write failed %d\n", ret);
-                       SAFE_FREE(data);
+                       MMUTIL_SAFE_FREE(data);
                        return FALSE;
                }
-               SAFE_FREE(data);
-       } else if (mode == TEST_DECODE_MEMORY) {
+               MMUTIL_SAFE_FREE(data);
+       } else if (mode == TEST_DECODE_BUFFER) {
                ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[GIF_testsuite] mm_util_file_read failed %d\n", ret);
@@ -158,23 +146,23 @@ gboolean _test_decode(const test_mode_e mode)
                ret = mm_util_file_write(DECODE_MEM_PATH, data, size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[GIF_testsuite] mm_util_file_write failed %d\n", ret);
-                       SAFE_FREE(data);
+                       MMUTIL_SAFE_FREE(data);
                        return FALSE;
                }
-               SAFE_FREE(data);
+               MMUTIL_SAFE_FREE(data);
        }
 
        return TRUE;
 }
 
-gboolean _test_encode(const test_mode_e mode)
+gboolean _test_encode(const mm_util_test_mode_e mode)
 {
        int ret = 0;
        /* for encoding gif to memory */
        void *encoded_data = NULL;
        size_t encoded_size = 0;
 
-       if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_MEMORY))
+       if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_BUFFER))
                return TRUE;
 
        ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
@@ -196,29 +184,29 @@ gboolean _test_encode(const test_mode_e mode)
                        fprintf(stderr, "\t[GIF_testsuite] mm_util_encode_gif_to_file failed : %d\n", ret);
                        return FALSE;
                }
-       } else if (mode == TEST_ENCODE_MEMORY) {
+       } else if (mode == TEST_ENCODE_BUFFER) {
                ret = mm_util_encode_to_gif_memory(&g_decoded_data, 1, &encoded_data, &encoded_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[GIF_testsuite] mm_util_encode_gif_to_memory failed : %d\n", ret);
-                       SAFE_FREE(encoded_data);
+                       MMUTIL_SAFE_FREE(encoded_data);
                        return FALSE;
                }
 
                ret = mm_util_file_write(ENCODE_MEM_PATH, encoded_data, encoded_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[GIF_testsuite] mm_util_file_write failed %d\n", ret);
-                       SAFE_FREE(encoded_data);
+                       MMUTIL_SAFE_FREE(encoded_data);
                        return FALSE;
                }
        }
 
-       SAFE_FREE(encoded_data);
+       MMUTIL_SAFE_FREE(encoded_data);
        return TRUE;
 }
 
 gboolean _test_auto()
 {
-       test_mode_e test_mode = TEST_DECODE_FILE;
+       mm_util_test_mode_e test_mode = TEST_DECODE_FILE;
 
        while (test_mode < TEST_NUM) {
                fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
@@ -227,7 +215,7 @@ gboolean _test_auto()
                        g_path = g_strdup(DECODE_FILE_PATH);
                }
                /* test decoding gif */
-               if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) {
+               if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_BUFFER)) {
                        if (FALSE == _test_decode(test_mode)) {
                                fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
                                return FALSE;
@@ -235,7 +223,7 @@ gboolean _test_auto()
                }
 
                /* test encoding gif */
-               if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) {
+               if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_BUFFER)) {
                        if (FALSE == _test_encode(test_mode)) {
                                fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
                                return FALSE;
@@ -244,9 +232,8 @@ gboolean _test_auto()
 
                fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]);
 
-               g_free(g_read_data);
-               g_read_data = NULL;
-               SAFE_IMAGE_FREE(g_decoded_data);
+               MMUTIL_SAFE_FREE(g_read_data);
+               MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
                test_mode++;
        }
 
@@ -273,7 +260,7 @@ int main(int argc, char *argv[])
        }
 
        /* test decoding gif */
-       if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
+       if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
                if (FALSE == _test_decode(g_test_mode)) {
                        fprintf(stderr, "\t[GIF_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]);
                        goto out;
@@ -281,7 +268,7 @@ int main(int argc, char *argv[])
        }
 
        /* test encoding gif */
-       if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) {
+       if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_BUFFER)) {
                if (FALSE == _test_encode(g_test_mode)) {
                        fprintf(stderr, "\t[GIF_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);
                        goto out;
@@ -289,9 +276,9 @@ int main(int argc, char *argv[])
        }
 
 out:
-       g_free(g_path);
-       g_free(g_read_data);
-       SAFE_IMAGE_FREE(g_decoded_data);
+       MMUTIL_SAFE_FREE(g_path);
+       MMUTIL_SAFE_FREE(g_read_data);
+       MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
 
        return 0;
 }
index 2f783e1..dc67657 100644 (file)
 #include <mm_util_image.h>
 #include <mm_util_jpeg.h>
 #include <mm_util_private.h>
-
-#define SAFE_FREE(x)           { g_free(x); x = NULL; }
-#define SAFE_IMAGE_FREE(x)     { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
-typedef enum {
-       TEST_AUTO,
-       TEST_DECODE_FILE,
-       TEST_DECODE_BUFFER,
-       TEST_NUM,
-} heif_test_mode_e;
+#include <mm_util_test_internal.h>
 
 static char *MODE_TO_STR[] = {
        "AUTO",
@@ -132,7 +123,7 @@ static gboolean __get_arguments(int argc, char *argv[])
        return TRUE;
 }
 
-static gboolean __test_decode(const heif_test_mode_e mode, mm_util_color_format_e color, const char *path)
+static gboolean __test_decode(const mm_util_test_mode_e mode, mm_util_color_format_e color, const char *path)
 {
        int ret = 0;
 
@@ -173,18 +164,18 @@ static gboolean __test_decode(const heif_test_mode_e mode, mm_util_color_format_
 
 static gboolean __test_auto()
 {
-       heif_test_mode_e test_mode = TEST_DECODE_FILE;
+       mm_util_test_mode_e test_mode = TEST_DECODE_FILE;
        mm_util_color_format_e color = MM_UTIL_COLOR_YUV420;
        gboolean result = FALSE;
 
-       while (test_mode < TEST_NUM) {
+       while (test_mode <= TEST_DECODE_BUFFER) {
                g_print("\t[HEIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
                /* test decoding heif */
                if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_BUFFER)) {
                        for (color = MM_UTIL_COLOR_YUV420; color < MM_UTIL_COLOR_NUM; color++) {
                                result |= __test_decode(test_mode, color, g_test_filename[test_mode][color]);
-                               SAFE_FREE(g_read_data);
-                               SAFE_IMAGE_FREE(g_decoded_data);
+                               MMUTIL_SAFE_FREE(g_read_data);
+                               MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
                        }
                }
 
@@ -223,8 +214,8 @@ int main(int argc, char *argv[])
 
 out:
        g_free(g_path);
-       SAFE_FREE(g_read_data);
-       SAFE_IMAGE_FREE(g_decoded_data);
+       MMUTIL_SAFE_FREE(g_read_data);
+       MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
 
        return 0;
 }
index dbd265a..4627fba 100644 (file)
 #include <mm_util_imgp.h>
 #include <mm_util_image.h>
 #include <mm_util_private.h>
+#include <mm_util_test_internal.h>
 #include <limits.h>
 #include <tzplatform_config.h>
 
-#define IMGP_FREE(src)         { if (src != NULL) {g_free(src); src = NULL; } }
-#define SAFE_IMAGE_FREE(x)     { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
 typedef struct {
        /* for source image */
        char *path;
@@ -246,12 +244,12 @@ int main(int argc, char *argv[])
        }
 
 TEST_FAIL:
-       SAFE_IMAGE_FREE(_src);
-       SAFE_IMAGE_FREE(_dst);
-       IMGP_FREE(g_transformed.data);
-       IMGP_FREE(g_args.data);
-       g_free(g_args.cmd);
-       g_free(g_args.path);
+       MMUTIL_SAFE_IMAGE_FREE(_src);
+       MMUTIL_SAFE_IMAGE_FREE(_dst);
+       MMUTIL_SAFE_FREE(g_transformed.data);
+       MMUTIL_SAFE_FREE(g_args.data);
+       MMUTIL_SAFE_FREE(g_args.cmd);
+       MMUTIL_SAFE_FREE(g_args.path);
 
        return 0;
 }
index 40b5389..28bb836 100644 (file)
 #include <mm_util_jpeg.h>
 #include <mm_util_image.h>
 #include <mm_util_private.h>
+#include <mm_util_test_internal.h>
 #include <tzplatform_config.h>
 
-#define SAFE_FREE(x)           { if (x != NULL) { free(x); x = NULL; } }
-#define SAFE_IMAGE_FREE(x)     { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
 #define DECODE_FILE_PATH       tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_dec_file.raw")
 #define DECODE_MEM_PATH                tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_dec_mem.raw")
 #define ENCODE_FILE_PATH       tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_enc_file.jpg")
 #define ENCODE_MEM_PATH                tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_enc_mem.jpg")
 
-typedef enum {
-       TEST_AUTO,
-       TEST_DECODE_FILE,
-       TEST_DECODE_MEMORY,
-       TEST_ENCODE_FILE,
-       TEST_ENCODE_MEMORY,
-       TEST_NUM,
-} jpeg_test_mode_e;
-
 static char *MODE_TO_STR[] = {
        "AUTO",
        "DECODE_FILE",
@@ -101,10 +90,10 @@ gboolean _get_arguments(int argc, char *argv[])
        } else if (g_test_mode == TEST_DECODE_FILE) {
                if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
-       } else if (g_test_mode == TEST_DECODE_MEMORY) {
+       } else if (g_test_mode == TEST_DECODE_BUFFER) {
                if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
-       } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_MEMORY) {
+       } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_BUFFER) {
                if (argc < 5) {
                        fprintf(stderr, "\t[JPEG_testsuite] not enough args\n");
                        _print_help(argv[0]);
@@ -136,7 +125,7 @@ gboolean _get_arguments(int argc, char *argv[])
        return TRUE;
 }
 
-gboolean _test_decode(const jpeg_test_mode_e mode)
+gboolean _test_decode(const mm_util_test_mode_e mode)
 {
        int ret = 0;
        unsigned char *data = NULL;
@@ -157,11 +146,11 @@ gboolean _test_decode(const jpeg_test_mode_e mode)
                ret = mm_util_file_write(DECODE_FILE_PATH, data, size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_write failed %d\n", ret);
-                       SAFE_FREE(data);
+                       MMUTIL_SAFE_FREE(data);
                        return FALSE;
                }
-               SAFE_FREE(data);
-       } else if (mode == TEST_DECODE_MEMORY) {
+               MMUTIL_SAFE_FREE(data);
+       } else if (mode == TEST_DECODE_BUFFER) {
                ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_read failed %d\n", ret);
@@ -181,23 +170,23 @@ gboolean _test_decode(const jpeg_test_mode_e mode)
                ret = mm_util_file_write(DECODE_MEM_PATH, data, size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_write failed %d\n", ret);
-                       SAFE_FREE(data);
+                       MMUTIL_SAFE_FREE(data);
                        return FALSE;
                }
-               SAFE_FREE(data);
+               MMUTIL_SAFE_FREE(data);
        }
 
        return TRUE;
 }
 
-gboolean _test_encode(const jpeg_test_mode_e mode)
+gboolean _test_encode(const mm_util_test_mode_e mode)
 {
        int ret = 0;
        /* for encoding jpeg to memory */
        void *encoded_data = NULL;
        size_t encoded_size = 0;
 
-       if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_MEMORY))
+       if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_BUFFER))
                return TRUE;
 
        ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
@@ -219,28 +208,28 @@ gboolean _test_encode(const jpeg_test_mode_e mode)
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
                        return FALSE;
                }
-       } else if (mode == TEST_ENCODE_MEMORY) {
+       } else if (mode == TEST_ENCODE_BUFFER) {
                ret = mm_util_encode_to_jpeg_memory(g_decoded_data, (int)g_quality, &encoded_data, &encoded_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
-                       SAFE_FREE(encoded_data);
+                       MMUTIL_SAFE_FREE(encoded_data);
                        return FALSE;
                }
                ret = mm_util_file_write(ENCODE_MEM_PATH, encoded_data, encoded_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_write failed %d\n", ret);
-                       SAFE_FREE(encoded_data);
+                       MMUTIL_SAFE_FREE(encoded_data);
                        return FALSE;
                }
        }
 
-       SAFE_FREE(encoded_data);
+       MMUTIL_SAFE_FREE(encoded_data);
        return TRUE;
 }
 
 gboolean _test_auto()
 {
-       jpeg_test_mode_e test_mode = TEST_DECODE_FILE;
+       mm_util_test_mode_e test_mode = TEST_DECODE_FILE;
 
        while (test_mode < TEST_NUM) {
                fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
@@ -249,7 +238,7 @@ gboolean _test_auto()
                        g_path = g_strdup(DECODE_FILE_PATH);
                }
                /* test decoding jpeg */
-               if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) {
+               if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_BUFFER)) {
                        if (FALSE == _test_decode(test_mode)) {
                                fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
                                return FALSE;
@@ -257,7 +246,7 @@ gboolean _test_auto()
                }
 
                /* test encoding jpeg */
-               if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) {
+               if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_BUFFER)) {
                        if (FALSE == _test_encode(test_mode)) {
                                fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
                                return FALSE;
@@ -266,8 +255,8 @@ gboolean _test_auto()
 
                fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]);
 
-               SAFE_FREE(g_read_data);
-               SAFE_IMAGE_FREE(g_decoded_data);
+               MMUTIL_SAFE_FREE(g_read_data);
+               MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
                test_mode++;
        }
 
@@ -294,7 +283,7 @@ int main(int argc, char *argv[])
        }
 
        /* test decoding jpeg */
-       if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
+       if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
                if (FALSE == _test_decode(g_test_mode)) {
                        fprintf(stderr, "\t[JPEG_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]);
                        goto out;
@@ -302,7 +291,7 @@ int main(int argc, char *argv[])
        }
 
        /* test encoding jpeg */
-       if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) {
+       if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_BUFFER)) {
                if (FALSE == _test_encode(g_test_mode)) {
                        fprintf(stderr, "\t[JPEG_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);
                        goto out;
@@ -311,8 +300,8 @@ int main(int argc, char *argv[])
 
 out:
        g_free(g_path);
-       SAFE_FREE(g_read_data);
-       SAFE_IMAGE_FREE(g_decoded_data);
+       MMUTIL_SAFE_FREE(g_read_data);
+       MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
 
        return 0;
 }
index def4d60..b753d6b 100644 (file)
 #include <mm_util_jxl.h>
 #include <mm_util_jpeg.h>
 #include <mm_util_private.h>
+#include <mm_util_test_internal.h>
 
-#define SAFE_FREE(x)           { g_free(x); x = NULL; }
-#define SAFE_IMAGE_FREE(x)     { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
 #define MAX_QUALITY                    4
 
-typedef enum {
-       TEST_AUTO,
-       TEST_DECODE_FILE,
-       TEST_DECODE_BUFFER,
-       TEST_ENCODE_FILE,
-       TEST_ENCODE_BUFFER,
-       TEST_NUM,
-} jxl_test_mode_e;
-
 static char *MODE_TO_STR[] = {
        "AUTO",
        "DECODE_FILE",
@@ -192,12 +182,12 @@ static void __set_enc_opt(bool lossless)
        g_print("\t[JXL_testsuite] __set_enc_opt lossless: %s\n", (lossless) ? "lossless" : "lossy");
 }
 
-static gboolean __test_decode(const jxl_test_mode_e mode, mm_util_color_format_e color)
+static gboolean __test_decode(const mm_util_test_mode_e mode, mm_util_color_format_e color)
 {
        int ret = 0;
 
-       SAFE_FREE(g_read_data);
-       SAFE_IMAGE_FREE(g_decoded_data);
+       MMUTIL_SAFE_FREE(g_read_data);
+       MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
 
        if ((mode != TEST_DECODE_FILE) && (mode != TEST_DECODE_BUFFER))
                return TRUE;
@@ -232,7 +222,7 @@ static gboolean __test_decode(const jxl_test_mode_e mode, mm_util_color_format_e
        return TRUE;
 }
 
-static gboolean __test_encode(const jxl_test_mode_e mode, mm_util_color_format_e color)
+static gboolean __test_encode(const mm_util_test_mode_e mode, mm_util_color_format_e color)
 {
        int ret = 0;
        void *encoded_data = NULL;
@@ -252,14 +242,14 @@ static gboolean __test_encode(const jxl_test_mode_e mode, mm_util_color_format_e
                ret = mm_util_encode_jxl_to_buffer(g_decoded_data, g_enc_opt, &encoded_data, &encoded_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        g_print("\t[JXL_testsuite] mm_util_encode_jxl_to_buffer failed : %d\n", ret);
-                       SAFE_FREE(encoded_data);
+                       MMUTIL_SAFE_FREE(encoded_data);
                        return FALSE;
                }
                ret = mm_util_file_write(g_test_filename[mode][color], encoded_data, encoded_size);
                if (ret != MM_UTIL_ERROR_NONE)
                        g_print("\t[JXL_testsuite] mm_util_file_write failed : %d\n", ret);
 
-               SAFE_FREE(encoded_data);
+               MMUTIL_SAFE_FREE(encoded_data);
        }
 
        return TRUE;
@@ -337,9 +327,9 @@ int main(int argc, char *argv[])
        }
 
 out:
-       g_free(g_path);
-       SAFE_FREE(g_read_data);
-       SAFE_IMAGE_FREE(g_decoded_data);
+       MMUTIL_SAFE_FREE(g_path);
+       MMUTIL_SAFE_FREE(g_read_data);
+       MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
        mm_util_enc_opt_destroy(g_enc_opt);
 
        return 0;
index dd9ca86..40251a3 100644 (file)
 #include <string.h>
 #include <mm_util_magick.h>
 #include <mm_util_private.h>
+#include <mm_util_test_internal.h>
 
 typedef enum {
        MM_UTIL_RESIZE,
        MM_UTIL_ROTATE,
 } mm_util_func_e;
 
-#define MM_UTIL_SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
-
 static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation);
 static int __magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
 static int __magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
@@ -110,7 +109,7 @@ static void __save_to_file(mm_util_image_h handle, const char *out_path)
        if (ret != MM_UTIL_ERROR_NONE)
                printf("Fail mm_util_file_write [%d]\n", ret);
 
-       MM_UTIL_SAFE_FREE(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        return;
 }
@@ -120,7 +119,7 @@ static int __get_buffer_for_test(mm_util_color_format_e req_format, unsigned cha
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h dst_handle = NULL;
-       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       const char * src_path = "/opt/usr/home/owner/origin.jpg";
 
        ret = mm_util_resize_P_B(src_path, 4000, 3000, req_format, &dst_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -132,7 +131,7 @@ static int __get_buffer_for_test(mm_util_color_format_e req_format, unsigned cha
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_image_get_image [%d]\n", ret);
                mm_image_destroy_image(dst_handle);
-               MM_UTIL_SAFE_FREE(*buffer);
+               MMUTIL_SAFE_FREE(*buffer);
                return ret;
        }
 
@@ -146,7 +145,7 @@ static int __get_buffer_for_test(mm_util_color_format_e req_format, unsigned cha
 static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       const char * src_path = "/opt/usr/home/owner/origin.jpg";
 
        printf("* Rotate P P Test * rotation = [%d]* \n", rotation);
 
@@ -160,7 +159,7 @@ static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation)
 static int __magick_resize_P_P_test(unsigned int req_width, unsigned int req_height)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       const char * src_path = "/opt/usr/home/owner/origin.jpg";
        char dst_path[1024] = {0, };
        memset(dst_path, 0x00, sizeof(dst_path));
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pp_%u_%u.jpg", req_width, req_height);
@@ -179,7 +178,7 @@ static int __magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_colo
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h dst_handle = NULL;
-       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       const char * src_path = "/opt/usr/home/owner/origin.jpg";
 
        printf("* Rotate P B Test * rotation = [%d] format = [%d] \n", rotation, req_format);
 
@@ -200,7 +199,7 @@ static int __magick_resize_P_B_test(unsigned int req_width, unsigned int req_hei
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h dst_handle = NULL;
-       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       const char * src_path = "/opt/usr/home/owner/origin.jpg";
        char dst_path[1024] = {0, };
        memset(dst_path, 0x00, sizeof(dst_path));
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pb_%u_%u.raw", req_width, req_height);
@@ -241,7 +240,7 @@ static int __magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_colo
        ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_image_create_image [%d]\n", ret);
-               MM_UTIL_SAFE_FREE(buffer);
+               MMUTIL_SAFE_FREE(buffer);
                return ret;
        }
 
@@ -251,7 +250,7 @@ static int __magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_colo
 
        mm_image_destroy_image(src_handle);
 
-       MM_UTIL_SAFE_FREE(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        return ret;
 }
@@ -280,7 +279,7 @@ static int __magick_resize_B_P_test(unsigned int req_width, unsigned int req_hei
        ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_image_create_image [%d]\n", ret);
-               MM_UTIL_SAFE_FREE(buffer);
+               MMUTIL_SAFE_FREE(buffer);
                return ret;
        }
 
@@ -290,7 +289,7 @@ static int __magick_resize_B_P_test(unsigned int req_width, unsigned int req_hei
 
        mm_image_destroy_image(src_handle);
 
-       MM_UTIL_SAFE_FREE(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        return ret;
 }
@@ -317,7 +316,7 @@ static int __magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_colo
        ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_image_create_image [%d]\n", ret);
-               MM_UTIL_SAFE_FREE(buffer);
+               MMUTIL_SAFE_FREE(buffer);
                return ret;
        }
 
@@ -325,7 +324,7 @@ static int __magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_colo
        if (ret != MM_UTIL_ERROR_NONE)
                printf("Fail mm_util_rotate_B_B [%d]\n", ret);
 
-       MM_UTIL_SAFE_FREE(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        __save_to_file(dst_handle, __get_dst_raw_path(rotation));
 
@@ -360,7 +359,7 @@ static int __magick_resize_B_B_test(unsigned int req_width, unsigned int req_hei
        ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_image_create_image [%d]\n", ret);
-               MM_UTIL_SAFE_FREE(buffer);
+               MMUTIL_SAFE_FREE(buffer);
                return ret;
        }
 
@@ -368,7 +367,7 @@ static int __magick_resize_B_B_test(unsigned int req_width, unsigned int req_hei
        if (ret != MM_UTIL_ERROR_NONE)
                printf("Fail mm_util_resize_B_B [%d]\n", ret);
 
-       MM_UTIL_SAFE_FREE(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        __save_to_file(dst_handle, dst_path);
 
@@ -403,7 +402,7 @@ static int __magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_c
        ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_image_create_image [%d]\n", ret);
-               MM_UTIL_SAFE_FREE(buffer);
+               MMUTIL_SAFE_FREE(buffer);
                return ret;
        }
 
@@ -411,7 +410,7 @@ static int __magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_c
        if (ret != MM_UTIL_ERROR_NONE)
                printf("Fail mm_util_convert_B_B [%d]\n", ret);
 
-       MM_UTIL_SAFE_FREE(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        __save_to_file(dst_handle, dst_path);
 
@@ -424,7 +423,7 @@ static int __magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_c
 static int __magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       const char * src_path = "/opt/usr/home/owner/origin.jpg";
        char dst_path[1024] = {0, };
        memset(dst_path, 0x00, sizeof(dst_path));
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/resize_rotate_pp_%u_%u.jpg", req_width, req_height);
@@ -438,234 +437,232 @@ static int __magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned
        return ret;
 }
 
-static int __magick_decenc_file_png_test(mm_util_color_format_e format, unsigned int comp_level)
+static int __magick_decode_file_test(const char *path, mm_util_color_format_e format, mm_util_image_h* decoded_image)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.png";
-       char dst_path[1024] = {0, };
-       mm_util_image_h decoded_image = NULL;
-       mm_util_enc_opt_h enc_option = NULL;
 
-       memset(dst_path, 0x00, sizeof(dst_path));
-       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_png_test_%d_%u.png", format, comp_level);
+       ret = mm_util_decode_image_from_file(path, format, decoded_image);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
 
-       printf("* PNG test [%s] \n", dst_path);
+       return ret;
+}
+
+static int __magick_decode_buffer_test(const char *path, mm_util_color_format_e format, mm_util_image_h* decoded_image)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       void *src_buffer = NULL;
+       size_t src_buffer_size = 0;
 
-       ret = mm_util_decode_image_from_file(src_path, format, &decoded_image);
+       ret = mm_util_file_read(path, &src_buffer, &src_buffer_size);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
+               printf("Fail mm_util_file_read [%s: %d]\n", path, ret);
                return ret;
        }
 
+       ret = mm_util_decode_image_from_buffer(src_buffer, src_buffer_size, format, decoded_image);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
+
+       MMUTIL_SAFE_FREE(src_buffer);
+       return ret;
+}
+
+static int __magick_encode_setup(mm_util_img_codec_type codec, unsigned int compression, bool lossless, mm_util_enc_opt_h *enc_opt)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_enc_opt_h enc_option = NULL;
+
+       mm_util_retvm_if(!enc_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid enc_opt");
+
        ret = mm_util_enc_opt_create(&enc_option);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
-               goto END;
+               return ret;
        }
 
-       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_PNG);
+       ret = mm_util_enc_opt_set_codec(enc_option, codec);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
-               goto END;
-       }
+               goto ERROR;
+       }
+
+       if (codec == IMG_CODEC_PNG) {
+               ret = mm_util_enc_opt_set_png_compression(enc_option, compression);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
+                       goto ERROR;
+               }
+       } else if (codec == IMG_CODEC_WEBP) {
+               ret = mm_util_enc_opt_set_lossless(enc_option, lossless);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       printf("Fail mm_util_enc_opt_set_lossless [0x%x]\n", ret);
+                       goto ERROR;
+               }
+       }
+
+       *enc_opt = enc_option;
+       return MM_UTIL_ERROR_NONE;
+ERROR:
+       mm_util_enc_opt_destroy(enc_option);
+
+       return ret;
+}
+
+static int __magick_encode_file_test(mm_util_image_h decoded_image, mm_util_img_codec_type codec, unsigned int compression, bool lossless, const char *path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_enc_opt_h enc_option = NULL;
 
-       ret = mm_util_enc_opt_set_png_compression(enc_option, comp_level);
+       ret = __magick_encode_setup(codec, compression, lossless, &enc_option);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
-               goto END;
+               printf("Fail __magick_encode_setup [0x%x]\n", ret);
+               return ret;
        }
 
-       ret = mm_util_encode_image_to_file(decoded_image, enc_option, dst_path);
+       ret = mm_util_encode_image_to_file(decoded_image, enc_option, path);
        if (ret != MM_UTIL_ERROR_NONE)
                printf("Fail mm_util_encode_image_to_file [0x%x]\n", ret);
 
-END:
        mm_util_enc_opt_destroy(enc_option);
-       mm_image_destroy_image(decoded_image);
 
        return ret;
 }
 
-static int __magick_decenc_buffer_png_test(mm_util_color_format_e format, unsigned int comp_level)
+static int __magick_encode_buffer_test(mm_util_image_h decoded_image, mm_util_img_codec_type codec, unsigned int compression, bool lossless, const char *path)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.png";
-       char dst_path[1024] = {0, };
-       mm_util_image_h decoded_image = NULL;
        mm_util_enc_opt_h enc_option = NULL;
-       void *src_buffer = NULL;
-       size_t src_buffer_size = 0;
        void *buffer = NULL;
        size_t buffer_size = 0;
 
-       memset(dst_path, 0x00, sizeof(dst_path));
-       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_png_test_%d_%u.png", format, comp_level);
-
-       printf("* PNG test [%s] \n", dst_path);
-
-       ret = mm_util_file_read(src_path, &src_buffer, &src_buffer_size);
+       ret = __magick_encode_setup(codec, compression, lossless, &enc_option);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_file_read [%s: %d]\n", src_path, ret);
-               return ret;
-       }
-
-       ret = mm_util_decode_image_from_buffer(src_buffer, src_buffer_size, format, &decoded_image);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
-               g_free(src_buffer);
+               printf("Fail __magick_encode_setup [0x%x]\n", ret);
                return ret;
        }
 
-       g_free(src_buffer);
-
-       ret = mm_util_enc_opt_create(&enc_option);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
-               goto END;
-       }
-
-       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_PNG);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
-               goto END;
-       }
-
-       ret = mm_util_enc_opt_set_png_compression(enc_option, comp_level);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
-               goto END;
-       }
-
        ret = mm_util_encode_image_to_buffer(decoded_image, enc_option, &buffer, &buffer_size);
        if (ret != MM_UTIL_ERROR_NONE) {
                printf("Fail mm_util_encode_image_to_buffer [0x%x]\n", ret);
                goto END;
        }
 
-       ret = mm_util_file_write(dst_path, buffer, buffer_size);
+       ret = mm_util_file_write(path, buffer, buffer_size);
        if (ret != MM_UTIL_ERROR_NONE)
                printf("Fail mm_util_file_write [0x%x]\n", ret);
 
 END:
        mm_util_enc_opt_destroy(enc_option);
-       mm_image_destroy_image(decoded_image);
-       g_free(buffer);
+       MMUTIL_SAFE_FREE(buffer);
 
        return ret;
 }
 
-static int __magick_decenc_file_webp_test(mm_util_color_format_e format, bool lossless)
+static int __magick_decenc_file_png_test(mm_util_color_format_e format, unsigned int comp_level)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.webp";
+       const char * src_path = "/opt/usr/home/owner/origin.png";
        char dst_path[1024] = {0, };
        mm_util_image_h decoded_image = NULL;
-       mm_util_enc_opt_h enc_option = NULL;
 
        memset(dst_path, 0x00, sizeof(dst_path));
-       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_png_test_%d_%u.png", format, comp_level);
 
-       printf("* WEBP test [%s] \n", dst_path);
+       printf("* PNG test [%s] \n", dst_path);
 
-       ret = mm_util_decode_image_from_file(src_path, format, &decoded_image);
+       ret = __magick_decode_file_test(src_path, format, &decoded_image);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
+               printf("Fail __magick_decode_file_test [0x%x]\n", ret);
                return ret;
        }
 
-       ret = mm_util_enc_opt_create(&enc_option);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
-               goto END;
-       }
+       ret = __magick_encode_file_test(decoded_image, IMG_CODEC_PNG, comp_level, false, dst_path);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail __magick_encode_file_test [0x%x]\n", ret);
 
-       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_WEBP);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
-               goto END;
-       }
+       mm_image_destroy_image(decoded_image);
+
+       return ret;
+}
+
+static int __magick_decenc_buffer_png_test(mm_util_color_format_e format, unsigned int comp_level)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       const char * src_path = "/opt/usr/home/owner/origin.png";
+       char dst_path[1024] = {0, };
+       mm_util_image_h decoded_image = NULL;
+
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_png_test_%d_%u.png", format, comp_level);
+
+       printf("* PNG test [%s] \n", dst_path);
 
-       ret = mm_util_enc_opt_set_lossless(enc_option, lossless);
+       ret = __magick_decode_buffer_test(src_path, format, &decoded_image);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_lossless [0x%x]\n", ret);
-               goto END;
+               printf("Fail __magick_decode_buffer_test [0x%x]\n", ret);
+               return ret;
        }
 
-       ret = mm_util_encode_image_to_file(decoded_image, enc_option, dst_path);
+       ret = __magick_encode_buffer_test(decoded_image, IMG_CODEC_PNG, comp_level, false, dst_path);
        if (ret != MM_UTIL_ERROR_NONE)
-               printf("Fail mm_util_encode_image_to_file [0x%x]\n", ret);
+               printf("Fail __magick_encode_buffer_test [0x%x]\n", ret);
 
-END:
-       mm_util_enc_opt_destroy(enc_option);
        mm_image_destroy_image(decoded_image);
 
        return ret;
 }
 
-static int __magick_decenc_buffer_webp_test(mm_util_color_format_e format, bool lossless)
+static int __magick_decenc_file_webp_test(mm_util_color_format_e format, bool lossless)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       char * src_path = "/opt/usr/home/owner/origin.webp";
+       const char * src_path = "/opt/usr/home/owner/origin.webp";
        char dst_path[1024] = {0, };
        mm_util_image_h decoded_image = NULL;
-       mm_util_enc_opt_h enc_option = NULL;
-       void *src_buffer = NULL;
-       size_t src_buffer_size = 0;
-       void *buffer = NULL;
-       size_t buffer_size = 0;
 
        memset(dst_path, 0x00, sizeof(dst_path));
-       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
 
        printf("* WEBP test [%s] \n", dst_path);
 
-       ret = mm_util_file_read(src_path, &src_buffer, &src_buffer_size);
+       ret = __magick_decode_file_test(src_path, format, &decoded_image);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_file_read [%s: %d]\n", src_path, ret);
+               printf("Fail __magick_decode_file_test [0x%x]\n", ret);
                return ret;
        }
 
-       ret = mm_util_decode_image_from_buffer(src_buffer, src_buffer_size, format, &decoded_image);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
-               g_free(src_buffer);
-               return ret;
-       }
+       ret = __magick_encode_file_test(decoded_image, IMG_CODEC_WEBP, 0, lossless, dst_path);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail __magick_encode_file_test [0x%x]\n", ret);
 
-       g_free(src_buffer);
+       mm_image_destroy_image(decoded_image);
 
-       ret = mm_util_enc_opt_create(&enc_option);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
-               goto END;
-       }
+       return ret;
+}
 
-       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_WEBP);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
-               goto END;
-       }
+static int __magick_decenc_buffer_webp_test(mm_util_color_format_e format, bool lossless)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       const char * src_path = "/opt/usr/home/owner/origin.webp";
+       char dst_path[1024] = {0, };
+       mm_util_image_h decoded_image = NULL;
 
-       ret = mm_util_enc_opt_set_lossless(enc_option, lossless);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_enc_opt_set_lossless [0x%x]\n", ret);
-               goto END;
-       }
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
 
-       ret = mm_util_encode_image_to_buffer(decoded_image, enc_option, &buffer, &buffer_size);
+       printf("* WEBP test [%s] \n", dst_path);
+
+       ret = __magick_decode_buffer_test(src_path, format, &decoded_image);
        if (ret != MM_UTIL_ERROR_NONE) {
-               printf("Fail mm_util_encode_image_to_buffer [0x%x]\n", ret);
-               goto END;
+               printf("Fail __magick_decode_buffer_test [0x%x]\n", ret);
+               return ret;
        }
 
-       ret = mm_util_file_write(dst_path, buffer, buffer_size);
+       ret = __magick_encode_buffer_test(decoded_image, IMG_CODEC_WEBP, 0, lossless, dst_path);
        if (ret != MM_UTIL_ERROR_NONE)
-               printf("Fail mm_util_file_write [0x%x]\n", ret);
+               printf("Fail __magick_encode_buffer_test [0x%x]\n", ret);
 
-END:
-       mm_util_enc_opt_destroy(enc_option);
        mm_image_destroy_image(decoded_image);
-       g_free(buffer);
 
        return ret;
 }
index f235689..470a6bf 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.4.4
+Version:    0.4.5
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 06cb84f..5f28a77 100644 (file)
@@ -26,7 +26,6 @@
 #include <mm_util_private.h>
 #include <tzplatform_config.h>
 
-#define TEST_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
 
 #define ENCODE_FILE_PATH       tzplatform_mkpath(TZ_USER_CONTENT, "webp_test_enc_file.webp")
 #define ENCODE_MEM_PATH                tzplatform_mkpath(TZ_USER_CONTENT, "webp_test_enc_mem.webp")
@@ -48,7 +47,7 @@ static void __decode_func(gpointer data, gpointer user_data)
        char *path = (char *)data;
        mm_util_image_h image = NULL;
 
-       if (!TEST_STRING_VALID(path)) {
+       if (!MMUTIL_STRING_VALID(path)) {
                g_print("invalid path %s\n", path);
                return;
        }
@@ -149,7 +148,7 @@ static gboolean __get_arguments(int argc, char *argv[])
 {
        g_path = g_strdup(argv[1]);
 
-       if (!TEST_STRING_VALID(g_path)) {
+       if (!MMUTIL_STRING_VALID(g_path)) {
                fprintf(stderr, "\t[WEBP_testsuite] invalid path %s\n", argv[1]);
                return FALSE;
        }
@@ -171,29 +170,50 @@ static void __add_image(gpointer data, gpointer user_data)
                fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_add_image failed : %d\n", ret);
 }
 
-static gboolean __test_encode_to_file()
+static int __webp_encode_setup(mm_util_webp_anim_enc_h *webp_encode)
 {
        int ret = 0;
-       mm_util_webp_anim_enc_h anim_enc = NULL;
+       mm_util_webp_anim_enc_h webp_enc = NULL;
+
+       mm_util_retvm_if(!webp_encode, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid webp_encode");
 
-       ret = mm_util_webp_anim_enc_create(&anim_enc);
+       ret = mm_util_webp_anim_enc_create(&webp_enc);
        if (ret != MM_UTIL_ERROR_NONE) {
                fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
-               return FALSE;
+               return ret;
        }
 
-       ret = mm_util_webp_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
+       ret = mm_util_webp_anim_enc_set_bgcolor(webp_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
        if (ret != MM_UTIL_ERROR_NONE) {
                fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
                goto END;
        }
 
-       ret = mm_util_webp_anim_enc_set_loop_count(anim_enc, g_loop_count);
+       ret = mm_util_webp_anim_enc_set_loop_count(webp_enc, g_loop_count);
        if (ret != MM_UTIL_ERROR_NONE) {
                fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
                goto END;
        }
 
+       *webp_encode = webp_enc;
+END:
+       if (ret != MM_UTIL_ERROR_NONE)
+               mm_util_webp_anim_enc_destroy(webp_enc);
+
+       return ret;
+}
+
+static gboolean __test_encode_to_file()
+{
+       int ret = 0;
+       mm_util_webp_anim_enc_h anim_enc = NULL;
+
+       ret = __webp_encode_setup(&anim_enc);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               fprintf(stderr, "\t[WEBP_testsuite] __webp_encode_setup failed : %d\n", ret);
+               return FALSE;
+       }
+
        g_queue_foreach(g_queue_images, __add_image, anim_enc);
 
        ret = mm_util_webp_anim_enc_save_to_file(anim_enc, ENCODE_FILE_PATH);
@@ -205,10 +225,7 @@ static gboolean __test_encode_to_file()
 END:
        mm_util_webp_anim_enc_destroy(anim_enc);
 
-       if (ret != MM_UTIL_ERROR_NONE)
-               return FALSE;
-
-       return TRUE;
+       return (ret == MM_UTIL_ERROR_NONE);
 }
 
 static gboolean __test_encode_to_buffer()
@@ -219,24 +236,12 @@ static gboolean __test_encode_to_buffer()
        void *encoded_data = NULL;
        size_t encoded_size = 0;
 
-       ret = mm_util_webp_anim_enc_create(&anim_enc);
+       ret = __webp_encode_setup(&anim_enc);
        if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
+               fprintf(stderr, "\t[WEBP_testsuite] __webp_encode_setup failed : %d\n", ret);
                return FALSE;
        }
 
-       ret = mm_util_webp_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
-               goto END;
-       }
-
-       ret = mm_util_webp_anim_enc_set_loop_count(anim_enc, g_loop_count);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
-               goto END;
-       }
-
        g_queue_foreach(g_queue_images, __add_image, anim_enc);
 
        ret = mm_util_webp_anim_enc_save_to_buffer(anim_enc, &encoded_data, &encoded_size);
@@ -254,10 +259,7 @@ END:
 
        g_free(encoded_data);
 
-       if (ret != MM_UTIL_ERROR_NONE)
-               return FALSE;
-
-       return TRUE;
+       return (ret == MM_UTIL_ERROR_NONE);
 }
 
 int main(int argc, char *argv[])
@@ -267,19 +269,19 @@ int main(int argc, char *argv[])
                return 0;
        }
 
-       if (FALSE == __get_arguments(argc, argv)) {
+       if (!__get_arguments(argc, argv)) {
                fprintf(stderr, "\t[WEBP_testsuite] _get_arguments failed\n");
                goto out;
        }
 
        /* test encoding animation webp to file */
-       if (FALSE == __test_encode_to_file()) {
+       if (!__test_encode_to_file()) {
                fprintf(stderr, "\t[WEBP_testsuite] __test_encode_to_file failed\n");
                goto out;
        }
 
        /* test encoding animation webp to buffer */
-       if (FALSE == __test_encode_to_buffer()) {
+       if (!__test_encode_to_buffer()) {
                fprintf(stderr, "\t[WEBP_testsuite] __test_encode_to_buffer failed\n");
                goto out;
        }