From: Jiyong Min Date: Tue, 6 Mar 2018 01:17:48 +0000 (+0900) Subject: Fix typo and TAINTED_INT svace issue X-Git-Tag: accepted/tizen/unified/20180315.061339~10^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79217e403e96bd294fe165535f0c316e54f4327a;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Fix typo and TAINTED_INT svace issue Change-Id: I71664d4f8cdf26e85371231873c8170add4474ea Signed-off-by: Jiyong Min --- diff --git a/bmp/test/mm_util_bmp_testsuite.c b/bmp/test/mm_util_bmp_testsuite.c index 9f2a3bb..a99e5c8 100755 --- a/bmp/test/mm_util_bmp_testsuite.c +++ b/bmp/test/mm_util_bmp_testsuite.c @@ -217,7 +217,7 @@ gboolean _test_decode(const bmp_test_mode_e mode) { int ret = 0; - /* test decoding jpeg */ + /* test decoding bmp */ if (mode == TEST_DECODE_FILE) { ret = mm_util_decode_from_bmp_file(&g_decoded_data, g_path); if (ret != MM_UTIL_ERROR_NONE) { @@ -251,7 +251,7 @@ gboolean _test_decode(const bmp_test_mode_e mode) gboolean _test_encode(const bmp_test_mode_e mode) { int ret = 0; - /* for encoding jpeg to memory */ + /* for encoding bmp to memory */ void *encoded_data = NULL; unsigned int encoded_size = 0; @@ -264,17 +264,17 @@ gboolean _test_encode(const bmp_test_mode_e mode) } g_decoded_data.size = (unsigned int)g_readed_size; - /* test encoding jpeg */ + /* test encoding bmp */ if (mode == TEST_ENCODE_FILE) { ret = mm_util_encode_bmp_to_file(&g_decoded_data, ENCODE_FILE_PATH); if (ret != MM_UTIL_ERROR_NONE) { - fprintf(stderr, "\t[BMP_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret); + fprintf(stderr, "\t[BMP_testsuite] mm_util_encode_bmp_to_file failed : %d\n", ret); return FALSE; } } else if (mode == TEST_ENCODE_MEMORY) { ret = mm_util_encode_bmp_to_memory(&g_decoded_data, &encoded_data, &encoded_size); if (ret != MM_UTIL_ERROR_NONE) { - fprintf(stderr, "\t[BMP_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret); + fprintf(stderr, "\t[BMP_testsuite] mm_util_encode_bmp_to_memory failed : %d\n", ret); SAFE_FREE(encoded_data); return FALSE; } @@ -303,7 +303,7 @@ gboolean _test_auto() return FALSE; } } - /* test decoding jpeg */ + /* test decoding bmp */ if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) { if (FALSE == _test_decode(test_mode)) { fprintf(stderr, "\t[BMP_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]); @@ -311,7 +311,7 @@ gboolean _test_auto() } } - /* test encoding jpeg */ + /* test encoding bmp */ if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) { if (FALSE == _test_encode(test_mode)) { fprintf(stderr, "\t[BMP_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]); @@ -341,14 +341,14 @@ int main(int argc, char *argv[]) goto out; } - /* test full functions automatically */ + /* test all functions automatically */ if (g_test_mode == TEST_AUTO) { if (FALSE == _test_auto()) fprintf(stderr, "\t[BMP_testsuite] _test_auto failed\n"); goto out; } - /* test decoding jpeg */ + /* test decoding bmp */ if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) { if (FALSE == _test_decode(g_test_mode)) { fprintf(stderr, "\t[BMP_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]); @@ -356,7 +356,7 @@ int main(int argc, char *argv[]) } } - /* test encoding jpeg */ + /* test encoding bmp */ if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) { if (FALSE == _test_encode(g_test_mode)) { fprintf(stderr, "\t[BMP_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]); diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c index e96a172..f19da85 100755 --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -27,17 +27,104 @@ #include #include #include +#include +#include + +#define TRANSFORM_TEST_PATH tzplatform_mkpath(TZ_USER_CONTENT, "imgp_result") #define MAX_STRING_LEN 128 #define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4 #define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } } mm_util_imgp_h imgp_handle = NULL; -bool completed = false; GCond g_thread_cond; GMutex g_thread_mutex; +static gboolean _read_file(char *path, void **data, size_t *length) +{ + FILE *fp = NULL; + long len = 0; + + if (!path || !data || length == 0) { + fprintf(stderr, "\t[JPEG_testsuite] invalid data %s %p %p\n", path, data, length); + return FALSE; + } + + fprintf(stderr, "\t[JPEG_testsuite] %s read\n", path); + + fp = fopen(path, "r"); + if (fp == NULL) { + fprintf(stderr, "\t[JPEG_testsuite] fopen failed (%d) \n", errno); + return FALSE; + } + + fseek(fp, 0, SEEK_END); + len = ftell(fp); + if (len < 0) { + fprintf(stderr, "\t[JPEG_testsuite] ftell failed \n"); + fclose(fp); + return FALSE; + } + + rewind(fp); + *data = (void *)calloc(1, len); + if (*data == NULL) { + fprintf(stderr, "\tmemory allocation failed \n"); + fclose(fp); + return FALSE; + } + + *length = fread(*data, 1, (size_t)len, fp); + if (*length != len) { + fprintf(stderr, "\t[JPEG_testsuite] fread failed \n"); + } + + fclose(fp); + + if (*data == NULL) { + *length = 0; + return FALSE; + } + + *length = (size_t)len; + + fprintf(stderr, "\t[JPEG_testsuite] %s %zu read DONE\n", path, *length); + + return TRUE; +} + +static gboolean _write_file(const char *path, void *data, size_t length) +{ + FILE *fp = NULL; + size_t len = 0; + + if (!path || !data || length == 0) { + fprintf(stderr, "\t[JPEG_testsuite] invalid data %s %p %zu\n", path, data, length); + return FALSE; + } + + fprintf(stderr, "\t[JPEG_testsuite] %s %p %zu write\n", path, data, length); + + fp = fopen(path, "w"); + if (fp == NULL) { + fprintf(stderr, "\t[JPEG_testsuite] fopen failed (%d) \n", errno); + return FALSE; + } + + len = fwrite(data, 1, length, fp); + if (len != length) { + fprintf(stderr, "\t[JPEG_testsuite] fwrite failed \n"); + } + + fclose(fp); + fp = NULL; + + fprintf(stderr, "\t[JPEG_testsuite] %s write DONE\n", path); + + return TRUE; +} + void _wait() { g_mutex_lock(&g_thread_mutex); @@ -66,36 +153,45 @@ bool _transform_completed_cb(mm_util_color_image_h image, int error, void *user_ if (error == MM_UTIL_ERROR_NONE) { fprintf(stderr, "completed\n"); - FILE *fp = fopen(output_file, "w"); - if (fp) { - void *dst = NULL; - err = mm_util_get_color_image(image, NULL, NULL, NULL, &dst, &size); - if (err != MM_UTIL_ERROR_NONE) { - IMGP_FREE(dst); - fclose(fp); - fprintf(stderr, "Error mm_util_get_color_image (%d)\n", err); - _signal(); - return FALSE; - } - fprintf(stderr, "dst: %p [%zu]\n", dst, size); - fwrite(dst, 1, size, fp); - fprintf(stderr, "FREE\n"); - fclose(fp); + void *dst = NULL; + err = mm_util_get_color_image(image, NULL, NULL, NULL, &dst, &size); + if (err != MM_UTIL_ERROR_NONE) { + fprintf(stderr, "Error mm_util_get_color_image (%d)\n", err); + goto out; } - fprintf(stderr, "write result\n"); + if (FALSE == _write_file(output_file, dst, size)) { + fprintf(stderr, "\t[IMGP_testsuite] writing file(%s) error\n", output_file); + goto out; + } + fprintf(stderr, "write success\n"); } else { fprintf(stderr, "[Error] complete cb (%d)\n", error); } - completed = true; +out: fprintf(stderr, "Destory - destroy image\n"); + mm_util_destroy_color_image(image); _signal(); return TRUE; } +gboolean _get_input_data(const char *argv, const long min, const long max, unsigned int *data) +{ + if (argv == NULL || strlen(argv) == 0) + return FALSE; + + long temp = g_ascii_strtoll(argv, NULL, 10); + if (temp < min || temp > max) + return FALSE; + + *data = (unsigned int)temp; + + return TRUE; +} + int main(int argc, char *argv[]) { int ret = 0; @@ -113,15 +209,15 @@ int main(int argc, char *argv[]) bool sync_mode = (strcmp(argv[1], "sync") == 0) ? TRUE : FALSE; char *filename = strdup(argv[2]); char *command = strdup(argv[3]); - unsigned int src_width = (unsigned int)atoi(argv[4]); - unsigned int src_height = (unsigned int)atoi(argv[5]); - mm_util_color_format_e src_format = atoi(argv[6]); - unsigned int dst_width = (unsigned int)atoi(argv[7]); - unsigned int dst_height = (unsigned int)atoi(argv[8]); - mm_util_color_format_e dst_format = atoi(argv[9]); - mm_util_img_rotate_type rotation = atoi(argv[10]); - unsigned int start_x = (unsigned int)atoi(argv[11]); - unsigned int start_y = (unsigned int)atoi(argv[12]); + unsigned int src_width = 0; + unsigned int src_height = 0; + mm_util_color_format_e src_format = 0; + unsigned int dst_width = 0; + unsigned int dst_height = 0; + mm_util_color_format_e dst_format = 0; + mm_util_img_rotate_type rotation = 0; + unsigned int start_x = 0; + unsigned int start_y = 0; char output_file[40] = {}; unsigned int res_w = 0; unsigned int res_h = 0; @@ -130,51 +226,55 @@ int main(int argc, char *argv[]) /* async mode */ mm_util_color_image_h orig_image = NULL; - fprintf(stderr, "command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d\n", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation); - - { /* read input file */ - FILE *fp = fopen(filename, "r"); - if (fp == NULL) { - fprintf(stderr, "\tfile open failed %d\n", errno); - goto TEST_FAIL; - } - - fseek(fp, 0, SEEK_END); - src_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - - src = calloc(1, src_size); - if (src == NULL) { - fprintf(stderr, "\tmemory allocation failed\n"); - goto TEST_FAIL; - } - - if (fread(src, 1, src_size, fp) == src_size) - fprintf(stderr, "#Success# fread\n"); - else - fprintf(stderr, "#Error# fread\n"); - - if (src == NULL || src_size <= 0) { - fprintf(stderr, "#Error# fread\n"); - goto TEST_FAIL; - } - + /* get arguments */ + if (FALSE == _get_input_data(argv[4], 0, (long)UINT_MAX, &src_width)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong src_width %s\n", argv[4]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[5], 0, (long)UINT_MAX, &src_height)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong src_height %s\n", argv[5]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[6], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &src_format)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong src_format %s\n", argv[6]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[7], 0, (long)UINT_MAX, &dst_width)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[7]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[8], 0, (long)UINT_MAX, &dst_height)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[8]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[9], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &dst_format)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_format %s\n", argv[9]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[10], MM_UTIL_ROTATE_0, MM_UTIL_ROTATE_NUM - 1, &rotation)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong rotation %s\n", argv[10]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[11], 0, (long)UINT_MAX, &start_x)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong start_x %s\n", argv[11]); + goto TEST_FAIL; + } + if (FALSE == _get_input_data(argv[12], 0, (long)UINT_MAX, &start_y)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong start_y %s\n", argv[12]); + goto TEST_FAIL; } - { /* ready output file */ - char *output_fmt = (char *) calloc(1, sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE); - memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE); - if (dst_format == MM_UTIL_COLOR_YUV420 || - dst_format == MM_UTIL_COLOR_YUV422 || - dst_format == MM_UTIL_COLOR_I420) { - strncpy(output_fmt, "yuv", strlen("yuv")); - } else { - //strncpy(output_fmt, "rgb", strlen("rgb")); - strncpy(output_fmt, "rgb", strlen("raw")); - } - snprintf(output_file, 40, "result_%s_%dx%d.%s", command, dst_width, dst_height, output_fmt); + /* read input file */ + if (FALSE == _read_file(filename, &src, &src_size)) { + fprintf(stderr, "\t[IMGP_testsuite] reading file(%s) error\n", filename); + goto TEST_FAIL; } + fprintf(stderr, "command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d\n", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation); + + /* ready output file */ + snprintf(output_file, 40, "%s_%s_%dx%d.raw", TRANSFORM_TEST_PATH, command, dst_width, dst_height); + if (sync_mode) { fprintf(stderr, "SYNC\n"); if (strcmp(command, "convert") == 0) @@ -193,14 +293,10 @@ int main(int argc, char *argv[]) goto TEST_FAIL; } - { /* write output file */ - FILE *fpout = fopen(output_file, "w"); - if (fpout) { - fprintf(stderr, "dst: %p [%zu]\n", dst, res_buffer_size); - fwrite(dst, 1, res_buffer_size, fpout); - fprintf(stderr, "FREE\n"); - fclose(fpout); - } + /* write output file */ + if (FALSE == _write_file(output_file, dst, res_buffer_size)) { + fprintf(stderr, "\t[IMGP_testsuite] writing file(%s) error\n", output_file); + goto TEST_FAIL; } } else { /* Async mode */ fprintf(stderr, "ASYNC\n"); diff --git a/jpeg/test/mm_util_jpeg_testsuite.c b/jpeg/test/mm_util_jpeg_testsuite.c index 03dff99..b2897db 100755 --- a/jpeg/test/mm_util_jpeg_testsuite.c +++ b/jpeg/test/mm_util_jpeg_testsuite.c @@ -361,7 +361,7 @@ int main(int argc, char *argv[]) goto out; } - /* test full functions automatically */ + /* test all functions automatically */ if (g_test_mode == TEST_AUTO) { if (FALSE == _test_auto()) fprintf(stderr, "\t[JPEG_testsuite] _test_auto failed\n"); diff --git a/png/test/mm_util_png_testsuite.c b/png/test/mm_util_png_testsuite.c index b12c8f9..0655ebb 100755 --- a/png/test/mm_util_png_testsuite.c +++ b/png/test/mm_util_png_testsuite.c @@ -222,11 +222,11 @@ gboolean _test_decode(const png_test_mode_e mode) { int ret = 0; - /* test decoding jpeg */ + /* test decoding png */ if (mode == TEST_DECODE_FILE) { ret = mm_util_decode_from_png_file(&g_decoded_data, g_path); if (ret != MM_UTIL_ERROR_NONE) { - fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_jpeg_file_with_downscale failed %d\n", ret); + fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_png_file failed %d\n", ret); return FALSE; } if (FALSE == _write_file(DECODE_FILE_PATH, g_decoded_data.data, (size_t)g_decoded_data.size)) { @@ -241,7 +241,7 @@ gboolean _test_decode(const png_test_mode_e mode) ret = mm_util_decode_from_png_memory(&g_decoded_data, g_readed_data, (unsigned long long)g_readed_size); if (ret != MM_UTIL_ERROR_NONE) { - fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_jpeg_memory_with_downscale failed %d\n", ret); + fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_png_memory failed %d\n", ret); return FALSE; } if (FALSE == _write_file(DECODE_MEM_PATH, g_decoded_data.data, (size_t)g_decoded_data.size)) { @@ -256,7 +256,7 @@ gboolean _test_decode(const png_test_mode_e mode) gboolean _test_encode(const png_test_mode_e mode) { int ret = 0; - /* for encoding jpeg to memory */ + /* for encoding png to memory */ void *encoded_data = NULL; size_t encoded_size = 0; @@ -268,17 +268,17 @@ gboolean _test_encode(const png_test_mode_e mode) return FALSE; } - /* test encoding jpeg */ + /* test encoding png */ if (mode == TEST_ENCODE_FILE) { ret = mm_util_encode_to_png_file(&g_decoded_data, g_compression, ENCODE_FILE_PATH); if (ret != MM_UTIL_ERROR_NONE) { - fprintf(stderr, "\t[PNG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret); + fprintf(stderr, "\t[PNG_testsuite] mm_util_encode_to_png_file failed : %d\n", ret); return FALSE; } } else if (mode == TEST_ENCODE_MEMORY) { ret = mm_util_encode_to_png_memory(&g_decoded_data, g_compression, &encoded_data, &encoded_size); if (ret != MM_UTIL_ERROR_NONE) { - fprintf(stderr, "\t[PNG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret); + fprintf(stderr, "\t[PNG_testsuite] mm_util_encode_to_png_memory failed : %d\n", ret); SAFE_FREE(encoded_data); return FALSE; } @@ -307,7 +307,7 @@ gboolean _test_auto() return FALSE; } } - /* test decoding jpeg */ + /* test decoding png */ if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) { if (FALSE == _test_decode(test_mode)) { fprintf(stderr, "\t[PNG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]); @@ -315,7 +315,7 @@ gboolean _test_auto() } } - /* test encoding jpeg */ + /* test encoding png */ if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) { if (FALSE == _test_encode(test_mode)) { fprintf(stderr, "\t[PNG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]); @@ -345,14 +345,14 @@ int main(int argc, char *argv[]) goto out; } - /* test full functions automatically */ + /* test all functions automatically */ if (g_test_mode == TEST_AUTO) { if (FALSE == _test_auto()) fprintf(stderr, "\t[PNG_testsuite] _test_auto failed\n"); goto out; } - /* test decoding jpeg */ + /* test decoding png */ if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) { if (FALSE == _test_decode(g_test_mode)) { fprintf(stderr, "\t[PNG_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]); @@ -360,7 +360,7 @@ int main(int argc, char *argv[]) } } - /* test encoding jpeg */ + /* test encoding png */ if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) { if (FALSE == _test_encode(g_test_mode)) { fprintf(stderr, "\t[PNG_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);