summaryrefslogtreecommitdiff
path: root/TC/testcase
diff options
context:
space:
mode:
Diffstat (limited to 'TC/testcase')
-rwxr-xr-xTC/testcase/Makefile25
-rwxr-xr-xTC/testcase/sample.jpgbin0 -> 38184 bytes
-rwxr-xr-xTC/testcase/tslist3
-rwxr-xr-xTC/testcase/utc_image_util_jpeg.c469
-rwxr-xr-xTC/testcase/utc_media_image_util_basic.c543
5 files changed, 1040 insertions, 0 deletions
diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile
new file mode 100755
index 0000000..fbb2cbe
--- /dev/null
+++ b/TC/testcase/Makefile
@@ -0,0 +1,25 @@
+CC ?= gcc
+
+C_FILES = $(shell ls *.c)
+
+PKGS = capi-media-image-util dlog glib-2.0
+
+LDFLAGS = `pkg-config --libs $(PKGS)`
+LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o
+LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s
+LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s
+
+CFLAGS = -I. `pkg-config --cflags $(PKGS)`
+CFLAGS += -I$(TET_ROOT)/inc/tet3
+CFLAGS += -Wall
+
+#TARGETS = $(C_FILES:%.c=tc-%)
+TCS := $(shell ls -1 *.c | cut -d. -f1)
+
+all: $(TCS)
+
+%: %.c
+ $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
+
+clean:
+ rm -f $(TCS)
diff --git a/TC/testcase/sample.jpg b/TC/testcase/sample.jpg
new file mode 100755
index 0000000..7222371
--- /dev/null
+++ b/TC/testcase/sample.jpg
Binary files differ
diff --git a/TC/testcase/tslist b/TC/testcase/tslist
new file mode 100755
index 0000000..becb7ea
--- /dev/null
+++ b/TC/testcase/tslist
@@ -0,0 +1,3 @@
+/testcase/utc_image_util_jpeg
+/testcase/utc_media_image_util_basic
+
diff --git a/TC/testcase/utc_image_util_jpeg.c b/TC/testcase/utc_image_util_jpeg.c
new file mode 100755
index 0000000..9b692c5
--- /dev/null
+++ b/TC/testcase/utc_image_util_jpeg.c
@@ -0,0 +1,469 @@
+/*
+* Copyright (c) 2011 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.
+*/
+
+
+#include <stdio.h>
+#include <tet_api.h>
+#include <image_util.h>
+
+static void startup(void);
+static void cleanup(void);
+
+void (*tet_startup)(void) = startup;
+void (*tet_cleanup)(void) = cleanup;
+
+#define SAMPLE_JPEG "sample.jpg"
+#define WRONG_PATH ""
+#define OUTPUT_JPEG "test_output.jpg"
+
+image_util_colorspace_e SUPPORTED_COLORSPACE;
+image_util_colorspace_e NOT_SUPPORTED_COLORSPACE;
+image_util_colorspace_e FIRST_COLORSPACE;
+image_util_colorspace_e LAST_COLORSPACE;
+
+/**
+ * @brief Global struct for raw image data
+ */
+struct{
+ unsigned char *buffer;
+ int size;
+ int w;
+ int h;
+}raw_image = {NULL, 0, 0, 0};
+
+
+/**
+ * @brief Global struct for jpeg image
+ */
+struct{
+ unsigned char *buffer;
+ int size;
+}jpeg_image = {NULL, 0};
+
+
+#define API_NAME_IMAGE_UTIL_DECODE_JPEG "image_util_decode_jpeg"
+#define API_NAME_IMAGE_UTIL_ENCODE_JPEG "image_util_encode_jpeg"
+#define API_NAME_IMAGE_UTIL_DECODE_JPEG_FROM_MEMORY "image_util_decode_jpeg_from_memory"
+#define API_NAME_IMAGE_UTIL_ENCODE_JPEG_TO_MEMORY "image_util_encode_jpeg_to_memory"
+
+static void utc_image_util_decode_jpeg_n_1(void);
+static void utc_image_util_decode_jpeg_n_2(void);
+static void utc_image_util_decode_jpeg_n_3(void);
+static void utc_image_util_decode_jpeg_n_4(void);
+static void utc_image_util_decode_jpeg_n_5(void);
+static void utc_image_util_decode_jpeg_p(void);
+static void utc_image_util_decode_jpeg_from_memory_n_1(void);
+static void utc_image_util_decode_jpeg_from_memory_n_2(void);
+static void utc_image_util_decode_jpeg_from_memory_n_3(void);
+static void utc_image_util_decode_jpeg_from_memory_n_4(void);
+static void utc_image_util_decode_jpeg_from_memory_p(void);
+static void utc_image_util_encode_jpeg_n_1(void);
+static void utc_image_util_encode_jpeg_n_2(void);
+static void utc_image_util_encode_jpeg_n_3(void);
+static void utc_image_util_encode_jpeg_n_4(void);
+static void utc_image_util_encode_jpeg_n_5(void);
+static void utc_image_util_encode_jpeg_p(void);
+static void utc_image_util_encode_jpeg_to_memory_n_1(void);
+static void utc_image_util_encode_jpeg_to_memory_n_2(void);
+static void utc_image_util_encode_jpeg_to_memory_n_3(void);
+static void utc_image_util_encode_jpeg_to_memory_n_4(void);
+static void utc_image_util_encode_jpeg_to_memory_p(void);
+
+enum
+{
+ POSITIVE_TC_IDX = 0x01,
+ NEGATIVE_TC_IDX,
+};
+
+struct tet_testlist tet_testlist[] = {
+/**
+ * image_util_decode_jpeg
+ */
+ { utc_image_util_decode_jpeg_n_1, 1 },
+ { utc_image_util_decode_jpeg_n_2, 2 },
+ { utc_image_util_decode_jpeg_n_3, 3 },
+ { utc_image_util_decode_jpeg_n_4, 4 },
+ { utc_image_util_decode_jpeg_n_5, 5 },
+ { utc_image_util_decode_jpeg_p, 6},
+
+/**
+ * image_util_encode_jpeg
+ */
+ { utc_image_util_encode_jpeg_n_1, 7 },
+ { utc_image_util_encode_jpeg_n_2, 8 },
+ { utc_image_util_encode_jpeg_n_3, 9 },
+ { utc_image_util_encode_jpeg_n_4, 10 },
+ { utc_image_util_encode_jpeg_n_5, 11 },
+ { utc_image_util_encode_jpeg_p, 12},
+
+/**
+ * image_util_encode_jpeg_to_memory
+ */
+ { utc_image_util_encode_jpeg_to_memory_n_1, 13 },
+ { utc_image_util_encode_jpeg_to_memory_n_2, 14 },
+ { utc_image_util_encode_jpeg_to_memory_n_3, 15 },
+ { utc_image_util_encode_jpeg_to_memory_n_4, 16 },
+ { utc_image_util_encode_jpeg_to_memory_p, 17 },
+
+/**
+ * image_util_decode_jpeg_from_memory
+ */
+ { utc_image_util_decode_jpeg_from_memory_n_1, 18 },
+ { utc_image_util_decode_jpeg_from_memory_n_2, 19 },
+ { utc_image_util_decode_jpeg_from_memory_n_3, 20 },// SIGSEGV from api
+ { utc_image_util_decode_jpeg_from_memory_n_4, 21 },
+ { utc_image_util_decode_jpeg_from_memory_p, 22 }, // SIGSEGV from api
+ { NULL, 0 },
+};
+
+/**
+ * @brief Callback to find first supported colorspace
+ */
+static bool find_first_supported_colorspace_cb( image_util_colorspace_e colorspace, void * user_data)
+{
+ *(int*)user_data = colorspace;
+ return false;
+}
+
+static void startup(void)
+{
+ /* start of TC */
+ tet_printf("\n TC start");
+ // set first not supportes colorspace
+ image_util_foreach_supported_jpeg_colorspace( find_first_supported_colorspace_cb , (void*)(&SUPPORTED_COLORSPACE) );
+
+ // set oher colorspaces
+ NOT_SUPPORTED_COLORSPACE = IMAGE_UTIL_COLORSPACE_YUV422; //TODO: FIND NOT SUPPORTED FORMAT
+ FIRST_COLORSPACE = IMAGE_UTIL_COLORSPACE_YV12;
+ LAST_COLORSPACE = IMAGE_UTIL_COLORSPACE_BGRX8888;
+
+ // prepare buffers for raw and jpeg images
+ if(image_util_decode_jpeg(SAMPLE_JPEG, SUPPORTED_COLORSPACE, &raw_image.buffer, &raw_image.w, &raw_image.h, &raw_image.size) == IMAGE_UTIL_ERROR_NONE){
+ tet_printf("\n raw_image initialization OK");
+ if(image_util_encode_jpeg_to_memory(raw_image.buffer, raw_image.w , raw_image.h , SUPPORTED_COLORSPACE, 100, &jpeg_image.buffer, &jpeg_image.size) == IMAGE_UTIL_ERROR_NONE)
+ tet_printf("\n jpeg_image initialization OK");
+ else
+ tet_printf("\n jpeg_image initialization FAILED");
+ }
+ else
+ tet_printf("\n raw_image initialization FAILED");
+}
+
+static void cleanup(void)
+{
+ /* end of TC */
+ free(raw_image.buffer);
+ free(jpeg_image.buffer);
+ tet_printf("\n TC end");
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg(). Invalid path or image_buffer parameters;
+ */
+static void utc_image_util_decode_jpeg_n_1(void)
+{
+ int r;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg(NULL, SUPPORTED_COLORSPACE, NULL, &w, &h, &size);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg(). Parameter colorspace over the range.
+ */
+static void utc_image_util_decode_jpeg_n_2(void)
+{
+ int r;
+ int w, h;
+ int size;
+ unsigned char *buffer = NULL;
+
+ r = image_util_decode_jpeg(SAMPLE_JPEG, LAST_COLORSPACE + 1, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg(). Parameter colorspace below the range.
+ */
+static void utc_image_util_decode_jpeg_n_3(void)
+{
+ int r;
+ int w, h;
+ int size;
+ unsigned char *buffer = NULL;
+
+ r = image_util_decode_jpeg(SAMPLE_JPEG, FIRST_COLORSPACE - 1, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg(). Not supported format.
+ */
+static void utc_image_util_decode_jpeg_n_4(void)
+{
+ int r;
+ int w, h;
+ int size;
+ unsigned char *buffer = NULL;
+
+ r = image_util_decode_jpeg(SAMPLE_JPEG, NOT_SUPPORTED_COLORSPACE, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG, r, IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg(). Wrong image file path. (Incomplete documentation!)
+ */
+static void utc_image_util_decode_jpeg_n_5(void)
+{
+ int r;
+ int w, h;
+ int size;
+ unsigned char *buffer = NULL;
+
+ r = image_util_decode_jpeg(WRONG_PATH, SUPPORTED_COLORSPACE, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG, r, IMAGE_UTIL_ERROR_NO_SUCH_FILE);
+}
+
+
+/**
+ * @brief Positive test case of image_util_decode_jpeg(). Al parameters OK, Success expected.
+ */
+static void utc_image_util_decode_jpeg_p(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg(SAMPLE_JPEG, SUPPORTED_COLORSPACE, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG, r, IMAGE_UTIL_ERROR_NONE);
+}
+
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg_from_memory(). Invalid jpeg_buffer or image_buffer parameters;
+ */
+static void utc_image_util_decode_jpeg_from_memory_n_1(void)
+{
+ int r;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg_from_memory(NULL, jpeg_image.size, SUPPORTED_COLORSPACE, NULL, &w, &h, &size);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG_FROM_MEMORY, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg_from_memory(). Parameter colorspace below the range.
+ */
+static void utc_image_util_decode_jpeg_from_memory_n_2(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg_from_memory(jpeg_image.buffer, jpeg_image.size, FIRST_COLORSPACE -1, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG_FROM_MEMORY, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg_from_memory(). Parameter colorspace over the range.
+ */
+static void utc_image_util_decode_jpeg_from_memory_n_3(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg_from_memory(jpeg_image.buffer, jpeg_image.size, LAST_COLORSPACE + 1, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG_FROM_MEMORY, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_decode_jpeg_from_memory(). Not supported format.
+ */
+static void utc_image_util_decode_jpeg_from_memory_n_4(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg_from_memory(jpeg_image.buffer, jpeg_image.size, NOT_SUPPORTED_COLORSPACE, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG_FROM_MEMORY, r, IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
+}
+
+
+/**
+ * @brief Positive test image_util_decode_jpeg_from_memory(). Al parameters OK, Success expected.
+ */
+static void utc_image_util_decode_jpeg_from_memory_p(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int w, h;
+ int size;
+
+ r = image_util_decode_jpeg_from_memory(jpeg_image.buffer, jpeg_image.size, SUPPORTED_COLORSPACE, &buffer, &w, &h, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_DECODE_JPEG_FROM_MEMORY, r, IMAGE_UTIL_ERROR_NONE);
+}
+/**
+ * @brief Negative test case of image_util_encode_jpeg(). Invalid path or buffer parameters;
+ */
+static void utc_image_util_encode_jpeg_n_1(void)
+{
+ int r;
+
+ r = image_util_encode_jpeg(NULL, raw_image.w , raw_image.h , SUPPORTED_COLORSPACE, 100, NULL);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg(). Parameter colorspace over the range.
+ */
+static void utc_image_util_encode_jpeg_n_2(void)
+{
+ int r;
+
+ r = image_util_encode_jpeg(raw_image.buffer, raw_image.w , raw_image.h , LAST_COLORSPACE + 1, 100, OUTPUT_JPEG);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+/**
+ * @brief Negative test case of image_util_encode_jpeg(). Parameter colorspace below the range.
+ */
+static void utc_image_util_encode_jpeg_n_3(void)
+{
+ int r;
+
+ r = image_util_encode_jpeg(raw_image.buffer, raw_image.w , raw_image.h , FIRST_COLORSPACE -1, 100, OUTPUT_JPEG);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg(). Not supported format.
+ */
+static void utc_image_util_encode_jpeg_n_4(void)
+{
+ int r;
+
+ r = image_util_encode_jpeg(raw_image.buffer, raw_image.w , raw_image.h , NOT_SUPPORTED_COLORSPACE, 100, OUTPUT_JPEG);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG, r, IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
+}
+
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg(). Wrong image file path.
+ */
+static void utc_image_util_encode_jpeg_n_5(void)
+{
+ int r;
+
+ r = image_util_encode_jpeg(raw_image.buffer, raw_image.w , raw_image.h , SUPPORTED_COLORSPACE, 100, WRONG_PATH);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG, r, IMAGE_UTIL_ERROR_NO_SUCH_FILE);
+}
+
+
+/**
+ * @brief Positive test case of image_util_encode_jpeg(). Al parameters OK, Success expected.
+ */
+static void utc_image_util_encode_jpeg_p(void)
+{
+ int r;
+
+ r = image_util_encode_jpeg(raw_image.buffer, raw_image.w , raw_image.h , SUPPORTED_COLORSPACE, 100, OUTPUT_JPEG);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG, r, IMAGE_UTIL_ERROR_NONE);
+}
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg_to_memory(). Invalid path or image_buffer or jpeg_buffer parameters;
+ */
+static void utc_image_util_encode_jpeg_to_memory_n_1(void)
+{
+ int r;
+ int size;
+
+ r = image_util_encode_jpeg_to_memory(NULL, 5 , 5 , SUPPORTED_COLORSPACE, 100, NULL, &size);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG_TO_MEMORY, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg_to_memory(). Parameter colorspace over the range.
+ */
+static void utc_image_util_encode_jpeg_to_memory_n_2(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int size;
+
+ r = image_util_encode_jpeg_to_memory(raw_image.buffer, raw_image.w , raw_image.h , FIRST_COLORSPACE - 1, 100, &buffer, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG_TO_MEMORY, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg_to_memory(). Parameter colorspace below the range.
+ */
+static void utc_image_util_encode_jpeg_to_memory_n_3(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int size;
+
+ r = image_util_encode_jpeg_to_memory(raw_image.buffer, raw_image.w , raw_image.h , LAST_COLORSPACE + 1, 100, &buffer, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG_TO_MEMORY, r, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Negative test case of image_util_encode_jpeg_to_memory(). Not supported format.
+ */
+static void utc_image_util_encode_jpeg_to_memory_n_4(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int size;
+
+ r = image_util_encode_jpeg_to_memory(raw_image.buffer, raw_image.w , raw_image.h , NOT_SUPPORTED_COLORSPACE, 100, &buffer, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG_TO_MEMORY, r, IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
+}
+
+/**
+ * @brief Positive test case of image_util_encode_jpeg_to_memory(). Al parameters OK, Success expected.
+ */
+static void utc_image_util_encode_jpeg_to_memory_p(void)
+{
+ int r;
+ unsigned char *buffer = NULL;
+ int size;
+
+ r = image_util_encode_jpeg_to_memory(raw_image.buffer, raw_image.w , raw_image.h , SUPPORTED_COLORSPACE, 100, &buffer, &size);
+ free(buffer);
+ dts_check_eq(API_NAME_IMAGE_UTIL_ENCODE_JPEG_TO_MEMORY, r, IMAGE_UTIL_ERROR_NONE);
+}
diff --git a/TC/testcase/utc_media_image_util_basic.c b/TC/testcase/utc_media_image_util_basic.c
new file mode 100755
index 0000000..cfaf7aa
--- /dev/null
+++ b/TC/testcase/utc_media_image_util_basic.c
@@ -0,0 +1,543 @@
+/*
+* Copyright (c) 2011 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.
+*/
+
+#include <stdio.h>
+#include <tet_api.h>
+#include <image_util.h>
+
+
+
+#define API_NAME_IMAGEUTIL_COLORSPACE "image_util_colorspace"
+#define API_NAME_IMAGEUTIL_COLOR_CONVERT "image_util_color_convert"
+#define API_NAME_IMAGEUTIL_BUFFER_SIZE "image_util_buffer_size"
+#define API_NAME_IMAGEUTIL_TRANSFORM "image_util_color_transform"
+
+#define SAMPLE_FILENAME "./sample.jpg"
+
+#define LAST_COLORSPACE IMAGE_UTIL_COLORSPACE_BGRX8888
+
+static void startup(void);
+static void cleanup(void);
+
+void (*tet_startup)(void) = startup;
+void (*tet_cleanup)(void) = cleanup;
+
+//Retrieves all supported JPEG encoding/decoding colorspace by invoking a callback function once for each one.
+static void utc_image_util_supported_jpeg_colorspace_p(void); // how many colorspaces are available
+static void utc_image_util_supported_jpeg_colorspace_2_p(void); // does ,,foreach'' return pass?
+static void utc_image_util_supported_jpeg_colorspace_3_p(void); // does ,,foreach'' return pass for all cases?
+
+//Convert the image's colorspace.
+static void utc_image_util_convert_colorspace_p(void);
+static void utc_image_util_convert_colorspace_1_n(void);
+static void utc_image_util_convert_colorspace_2_n(void);
+
+//Calculates the size of image buffer for the specified resolution and colorspace.
+static void utc_image_util_calculate_bufsize_result_p(void);
+static void utc_image_util_calculate_bufsize_result_1_n(void);
+static void utc_image_util_calculate_bufsize_result_2_n(void);
+static void utc_image_util_calculate_bufsize_result_3_n(void);
+static void utc_image_util_calculate_bufsize_result_4_p(void);
+static void utc_image_util_calculate_bufsize_result_5_p(void);
+
+
+//Transforms the image to with the specified destination width and height and angle in degrees.
+static void utc_image_util_file_rotate_p(void);
+static void utc_image_util_file_rotate_2_p(void);
+static void utc_image_util_file_rotate_3_p(void);
+
+
+
+
+static bool jpeg_colorspace_cb( image_util_colorspace_e colorspace, void * user_data);
+static bool jpeg_colorspace_quit_cb( image_util_colorspace_e colorspace, void * user_data);
+static bool jpeg_colorspace_size_cb( image_util_colorspace_e colorspace, void * user_data);
+
+
+//available transforms
+#define AT_COUTN 4
+const int avail_trans[AT_COUTN] =
+{
+ IMAGE_UTIL_COLORSPACE_YV12,
+ IMAGE_UTIL_COLORSPACE_I420,
+ IMAGE_UTIL_COLORSPACE_NV12,
+ IMAGE_UTIL_COLORSPACE_RGB888,
+};
+
+
+
+enum
+{
+ POSITIVE_TC_IDX = 0x01,
+ NEGATIVE_TC_IDX,
+};
+
+
+
+
+struct tet_testlist tet_testlist[] = {
+ { utc_image_util_supported_jpeg_colorspace_p, 1},
+ { utc_image_util_supported_jpeg_colorspace_2_p, 2},
+ { utc_image_util_supported_jpeg_colorspace_3_p, 3},
+ { utc_image_util_calculate_bufsize_result_p, 4},
+ { utc_image_util_calculate_bufsize_result_1_n, 5},
+ { utc_image_util_calculate_bufsize_result_2_n, 6},
+ { utc_image_util_calculate_bufsize_result_3_n, 7},
+ { utc_image_util_calculate_bufsize_result_4_p, 8},
+ { utc_image_util_calculate_bufsize_result_5_p, 9},
+ { utc_image_util_convert_colorspace_p, 10},
+ { utc_image_util_convert_colorspace_1_n, 11},
+ { utc_image_util_convert_colorspace_2_n, 12},
+ { utc_image_util_file_rotate_p, 13},
+ { utc_image_util_file_rotate_2_p, 14},
+ { utc_image_util_file_rotate_3_p, 15},
+ { NULL, 0},
+};
+
+
+static void startup(void)
+{
+ // TC start
+}
+
+static void cleanup(void)
+{
+ // TC end
+}
+
+
+
+static bool jpeg_colorspace_cb( image_util_colorspace_e colorspace, void * user_data)
+{
+ return true;
+}
+
+
+static bool jpeg_colorspace_quit_cb( image_util_colorspace_e colorspace, void * user_data)
+{
+ int last = *((int*)user_data);
+ return (int)colorspace == last ? false : true;
+}
+
+
+
+static bool jpeg_colorspace_size_cb( image_util_colorspace_e colorspace, void * user_data)
+{
+ int * result = (int*)user_data;
+
+ const int W = 480, H = 320; // these values are taken from test file - sample.jpg
+ int width = 0, height = 0;
+ int size_decode = 0;
+ unsigned int size_calc = 0;
+ unsigned char * img_buf = 0;
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, colorspace, &img_buf, &width, &height, &size_decode );
+
+ // prepare buffers
+ image_util_calculate_buffer_size( W, H, colorspace, &size_calc );
+
+ free( img_buf );
+
+ *result = (size_decode == size_calc);
+
+ // if false then callbacks stop
+ return *result;
+}
+
+
+
+
+
+/**
+ * @brief how many colorspaces are available
+ */
+static void utc_image_util_supported_jpeg_colorspace_p(void)
+{
+ int pointer = 0;
+ int ret = image_util_foreach_supported_jpeg_colorspace( NULL , (void*)(&pointer) );
+ dts_check_eq( API_NAME_IMAGEUTIL_COLORSPACE, ret, IMAGE_UTIL_ERROR_INVALID_PARAMETER );
+}
+
+
+
+
+
+
+
+/**
+ * @brief does ,,foreach'' return pass?
+ */
+static void utc_image_util_supported_jpeg_colorspace_2_p(void)
+{
+ int err = image_util_foreach_supported_jpeg_colorspace( jpeg_colorspace_cb , (void*)NULL );
+ dts_check_eq( API_NAME_IMAGEUTIL_COLORSPACE, err, IMAGE_UTIL_ERROR_NONE );
+}
+
+
+
+
+
+
+
+/**
+ * @brief does ,,foreach'' return pass for all cases?
+ */
+static void utc_image_util_supported_jpeg_colorspace_3_p(void)
+{
+ int err;
+ char buf[100] = { '\0' };
+ snprintf( buf, 100, "%s", API_NAME_IMAGEUTIL_COLORSPACE );
+
+ // parameter i decides when loop of callbacks should break
+ int i;
+ for( i = 0; i < LAST_COLORSPACE; ++i )
+ {
+ err = image_util_foreach_supported_jpeg_colorspace( jpeg_colorspace_quit_cb , (void*)(&i) );
+ if( err != 0 )
+ {
+ sprintf( buf, " [error: colorspace_2_p on position %d]", i );
+ break;
+ }
+ }
+
+ dts_check_eq( buf, err, 0 );
+}
+
+
+
+
+
+
+/**
+ * @brief check the buffer size calculation with correct parameters
+ */
+static void utc_image_util_calculate_bufsize_result_p(void)
+{
+ int width = 100, height = 20;
+ unsigned int size = 0;
+
+ int err = image_util_calculate_buffer_size( width, height, IMAGE_UTIL_COLORSPACE_RGB888, &size );
+ dts_check_eq( API_NAME_IMAGEUTIL_BUFFER_SIZE, err, 0 );
+}
+
+
+
+
+
+/**
+ * @brief check the buffer size calculation with uncorrect parameters
+ */
+static void utc_image_util_calculate_bufsize_result_1_n(void)
+{
+ int width = 100, height = 20;
+ unsigned int size = 0;
+ const int colorspace = IMAGE_UTIL_COLORSPACE_BGRX8888 + 1; // after last one
+
+ int err = image_util_calculate_buffer_size( width, height, colorspace, &size );
+ dts_check_ne( API_NAME_IMAGEUTIL_BUFFER_SIZE, err, 0 );
+}
+
+
+
+
+
+
+/**
+ * @brief check the buffer size calculation with uncorrect parameters
+ */
+static void utc_image_util_calculate_bufsize_result_2_n(void)
+{
+ int width = -100, height = 20; // wrong parameter
+ unsigned int size = 0;
+ const int colorspace = IMAGE_UTIL_COLORSPACE_BGRX8888;
+
+ int err = image_util_calculate_buffer_size( width, height, colorspace, &size );
+ dts_check_ne( API_NAME_IMAGEUTIL_BUFFER_SIZE, err, 0 );
+}
+
+
+
+
+
+
+/**
+ * @brief check the buffer size calculation with uncorrect parameters
+ */
+static void utc_image_util_calculate_bufsize_result_3_n(void)
+{
+ int width = 0, height = 0; // wrong parameter
+ unsigned int size = 0;
+ const int colorspace = IMAGE_UTIL_COLORSPACE_BGRX8888;
+
+ int err = image_util_calculate_buffer_size( width, height, colorspace, &size );
+ dts_check_ne( API_NAME_IMAGEUTIL_BUFFER_SIZE, err, 0 );
+}
+
+
+
+
+
+/**
+ * @brief do the buffer size calculation and check if
+ * this is the same like with decode_jpeg function
+ */
+static void utc_image_util_calculate_bufsize_result_4_p(void)
+{
+ const int W = 480, H = 320; // these values are taken from original file sample.jpg
+ int width = 0, height = 0;
+ int size_decode = 0;
+ unsigned int size_calc = 0;
+ unsigned char * img_buf = 0;
+ const image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, colorspace, &img_buf, &width, &height, &size_decode );
+
+ // prepare buffers
+ image_util_calculate_buffer_size( W, H, colorspace, &size_calc );
+
+ free( img_buf );
+
+ dts_check_eq( API_NAME_IMAGEUTIL_BUFFER_SIZE, (int)size_calc, size_decode );
+}
+
+
+
+
+/**
+ * @brief do the buffer size calculation for all colorspaces
+ * this is similar like ..._calculate_bufsize_result_4_p
+ */
+static void utc_image_util_calculate_bufsize_result_5_p(void)
+{
+ int result = -1;
+
+ // do the loop for all colorspaces and check bufsize there inside
+ image_util_foreach_supported_jpeg_colorspace( jpeg_colorspace_size_cb, (void*)(&result) );
+
+ // result is taken from inside the colorspace callbacks loop,
+ // there is compared buffor size
+ // result takes true or false
+ dts_check_eq( API_NAME_IMAGEUTIL_BUFFER_SIZE, result, 1 );
+}
+
+
+/**
+ * @brief check if color conversion returns positive
+ */
+static void utc_image_util_convert_colorspace_p(void)
+{
+ int width = 0, height = 0;
+ unsigned int size_decode = 0;
+ unsigned char * img_target = 0;
+ unsigned char * img_source = 0;
+ const image_util_colorspace_e cs_target = IMAGE_UTIL_COLORSPACE_RGB888;
+ const image_util_colorspace_e cs_source = IMAGE_UTIL_COLORSPACE_YV12;
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, cs_source, &img_source, &width, &height, &size_decode );
+ image_util_calculate_buffer_size(width, height, cs_target , &size_decode);
+ img_target = malloc( size_decode );
+
+ // do conversion
+ int ret = image_util_convert_colorspace( img_target, cs_target,
+ img_source, width, height, cs_source );
+ free( img_target );
+ free( img_source );
+
+ dts_check_eq( API_NAME_IMAGEUTIL_COLOR_CONVERT, ret, IMAGE_UTIL_ERROR_NONE );
+}
+
+
+
+
+
+
+/**
+ * @brief check if color conversion function has the verification of input parameters
+ */
+static void utc_image_util_convert_colorspace_1_n(void)
+{
+ int width = 0, height = 0;
+ unsigned char * img_target = 0; // NULL pointer!
+ unsigned char * img_source = 0; // NULL pointer!
+ const image_util_colorspace_e cs_target = IMAGE_UTIL_COLORSPACE_RGB888;
+ const image_util_colorspace_e cs_source = IMAGE_UTIL_COLORSPACE_YV12;
+
+ // do conversion
+ int ret = image_util_convert_colorspace( img_target, cs_target,
+ img_source, width, height, cs_source );
+
+ dts_check_ne( API_NAME_IMAGEUTIL_COLOR_CONVERT, ret, IMAGE_UTIL_ERROR_NONE );
+}
+
+
+
+/**
+ * @brief check if color conversion has verification of input parameters
+ */
+static void utc_image_util_convert_colorspace_2_n(void)
+{
+ int width = 0, height = 0;
+ int size_decode = 0;
+ unsigned char * img_target = 0;
+ unsigned char * img_source = 0;
+ const image_util_colorspace_e cs_target = IMAGE_UTIL_COLORSPACE_BGRX8888 + 1; // out of the scope!
+ const image_util_colorspace_e cs_source = IMAGE_UTIL_COLORSPACE_YV12;
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, cs_source, &img_source, &width, &height, &size_decode );
+
+ // do conversion
+ int ret = image_util_convert_colorspace( img_target, cs_target,
+ img_source, width, height, cs_source );
+ free( img_target );
+ free( img_source );
+
+ dts_check_ne( API_NAME_IMAGEUTIL_COLOR_CONVERT, ret, IMAGE_UTIL_ERROR_NONE );
+}
+
+
+
+
+/**
+ * @brief Simple use of transformation
+ */
+static void utc_image_util_file_rotate_p(void)
+{
+ int width = 0, height = 0;
+ int size_decode = 0;
+ unsigned char * img_target = 0;
+ unsigned char * img_source = 0;
+
+ image_util_rotation_e dest_rotation = IMAGE_UTIL_ROTATION_90;
+
+ const image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, colorspace, &img_source, &width, &height, &size_decode );
+
+ image_util_calculate_buffer_size(width, height, colorspace , &size_decode);
+
+ img_target = malloc( size_decode );
+
+ // do rotation
+ int ret = image_util_rotate( img_target, &width, &height, dest_rotation,
+ img_source, width, height, colorspace );
+
+ free( img_target );
+ free( img_source );
+
+ dts_check_eq( API_NAME_IMAGEUTIL_TRANSFORM, ret, IMAGE_UTIL_ERROR_NONE );
+}
+
+
+
+
+
+/**
+ * @brief Image transformation for all rotation types
+ */
+static void utc_image_util_file_rotate_2_p(void)
+{
+ int ret = -1;
+
+ int width = 0, height = 0;
+ int target_width , target_height = 0;
+ int size_decode = 0;
+ unsigned char * img_target = 0;
+ unsigned char * img_source = 0;
+
+ const image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, colorspace, &img_source, &width, &height, &size_decode );
+ image_util_calculate_buffer_size(width, height, colorspace , &size_decode);
+
+ img_target = malloc( size_decode );
+
+ image_util_rotation_e rot;
+ for( rot = IMAGE_UTIL_ROTATION_NONE;
+ rot <= IMAGE_UTIL_ROTATION_FLIP_VERT; ++rot )
+ {
+ // do rotation
+ ret = image_util_rotate( img_target, &target_width, &target_height, rot,
+ img_source, width, height, colorspace );
+
+ if( ret != 0 )
+ break;
+ }
+
+ free( img_target );
+ free( img_source );
+
+ dts_check_eq( API_NAME_IMAGEUTIL_TRANSFORM, ret, IMAGE_UTIL_ERROR_NONE );
+}
+
+
+
+
+
+/**
+ * @brief Image transformation for all available colorspaces
+ */
+static void utc_image_util_file_rotate_3_p(void)
+{
+ int ret = -1;
+
+ // loop uses all colorspaces for one transformation
+ int i;
+ for( i = 0; i < AT_COUTN; ++i )
+ {
+ int width = 0, height = 0;
+ int size_decode = 0;
+ unsigned char * img_target = 0;
+ unsigned char * img_source_converted = 0;
+ unsigned char * img_source = 0;
+
+
+ // load jpeg sample file
+ image_util_decode_jpeg( SAMPLE_FILENAME, IMAGE_UTIL_COLORSPACE_RGB888 , &img_source, &width, &height, &size_decode );
+ // convert target format
+ if( IMAGE_UTIL_COLORSPACE_RGB888 != avail_trans[i] ){
+ image_util_calculate_buffer_size(width, height, avail_trans[i], &size_decode);
+ img_source_converted = malloc(size_decode);
+ image_util_convert_colorspace(img_source_converted , avail_trans[i] , img_source , width, height, IMAGE_UTIL_COLORSPACE_RGB888);
+ free(img_source);
+ img_source = img_source_converted;
+ }
+
+
+
+ image_util_calculate_buffer_size(width, height, avail_trans[i] , &size_decode);
+ img_target = malloc( size_decode );
+
+ // do rotation
+ ret = image_util_rotate( img_target, &width, &height, IMAGE_UTIL_ROTATION_180,
+ img_source, width, height, avail_trans[i] );
+
+ free( img_target );
+ free( img_source );
+
+ if( ret != 0 )
+ break;
+ }
+
+
+
+ dts_check_eq( API_NAME_IMAGEUTIL_TRANSFORM, ret, IMAGE_UTIL_ERROR_NONE );
+}