INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-bmp C CXX)
+
+SET(GTEST_TEST "gtest-libmm-bmp")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_common"
+ "mmutil_bmp"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-bmp-unittest.bmp"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 "FileInterface.h"
+
+FileInterface::FileInterface(const char *path)
+{
+ fp = NULL;
+ fileSize = 0;
+
+ FileInterface::Open(path);
+}
+
+FileInterface::~FileInterface(void)
+{
+ if (fp)
+ fclose(fp);
+ fp = NULL;
+
+ if (readData)
+ free(readData);
+ readData = NULL;
+}
+
+void FileInterface::Open(const char *path)
+{
+ fp = fopen(path, "r");
+ if (!fp)
+ return ;
+
+ long size = 0;
+
+ fseek(fp, 0, SEEK_END);
+ size = (size_t)ftell(fp);
+ rewind(fp);
+
+ if (size < 0)
+ return ;
+ fileSize = (size_t)size;
+}
+
+gboolean FileInterface::ReadData()
+{
+ if (!fp || fileSize == 0)
+ return FALSE;
+
+ readData = (unsigned char *)calloc(1, fileSize);
+ if (fread(readData, 1, fileSize, fp) != fileSize) {
+ return FALSE;
+ }
+ readDataSize = fileSize;
+ return TRUE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __FILE_INTERFACE_H__
+#define __FILE_INTERFACE_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+class FileInterface {
+ private:
+ FILE *fp;
+ size_t fileSize;
+
+ void Open(const char *path);
+ public:
+ unsigned char *readData;
+ size_t readDataSize;
+
+ FileInterface(const char *path);
+ ~FileInterface(void);
+ gboolean ReadData();
+};
+
+#endif /*__FILE_INTERFACE_H__*/
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_bmp_unittest.h"
+#include "FileInterface.h"
+#include "mm_util_bmp.h"
+
+#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-bmp-unittest.bmp")
+#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-bmp-result.bmp")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_bmp_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_bmp_Test, mm_util_decode_from_bmp_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_bmp_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_bmp_Test, mm_util_decode_from_bmp_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_bmp_file(NULL, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_bmp_file(DECODE_FILE_PATH, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_bmp_Test, mm_util_decode_from_bmp_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image;
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_bmp_memory(IFile.readData, IFile.readDataSize, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_bmp_Test, mm_util_decode_from_bmp_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image;
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_bmp_memory(NULL, IFile.readDataSize, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_bmp_memory(IFile.readData, IFile.readDataSize, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_bmp_Test, mm_util_encode_bmp_to_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_bmp_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_bmp_to_file(&decode_image, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_bmp_Test, mm_util_encode_bmp_to_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_encode_bmp_to_file(NULL, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_bmp_to_file(&decode_image, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_bmp_Test, mm_util_encode_bmp_to_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_decode_from_bmp_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_bmp_to_memory(&decode_image, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(buffer != NULL);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+
+ if (buffer != NULL)
+ free(buffer);
+}
+
+TEST(libmm_bmp_Test, mm_util_encode_bmp_to_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_encode_bmp_to_memory(NULL, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_bmp_to_memory(&decode_image, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_bmp_to_memory(&decode_image, &buffer, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_BMP_UNITTEST_H__
+#define __LIB_MM_BMP_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_BMP"
+
+#endif /*__LIB_MM_BMP_UNITTEST_H__*/
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
#ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
int mm_util_decode_from_gif_file(const char *fpath, mm_image_info_s *decoded)
{
+ mm_util_retvm_if(!MMUTIL_STRING_VALID(fpath), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fpath");
+ mm_util_retvm_if((decoded == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid color image");
+
mm_util_fenter();
return __read_gif(decoded, fpath, NULL, 0);
int mm_util_decode_from_gif_memory(void *memory, const size_t src_size, mm_image_info_s *decoded)
{
+ mm_util_retvm_if(memory == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid memory");
+ mm_util_retvm_if((decoded == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid color image");
+
mm_util_fenter();
return __read_gif(decoded, NULL, memory, src_size);
mm_util_fenter();
mm_util_retvm_if(images == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- mm_util_retvm_if(image_count == 0, MM_UTIL_ERROR_INVALID_OPERATION, "Invalid parameter");
- mm_util_retvm_if(path == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "Invalid parameter");
+ mm_util_retvm_if(image_count == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+ mm_util_retvm_if(path == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
ret = mm_util_gif_encode_create(&gif_file_h);
mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_create failed %d", ret);
mm_util_fenter();
mm_util_retvm_if(images == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- mm_util_retvm_if(image_count == 0, MM_UTIL_ERROR_INVALID_OPERATION, "Invalid parameter");
- mm_util_retvm_if(buffer == NULL || size == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "Invalid parameter");
+ mm_util_retvm_if(image_count == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+ mm_util_retvm_if(buffer == NULL || size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
ret = mm_util_gif_encode_create(&gif_file_h);
mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_create failed %d", ret);
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-gif C CXX)
+
+SET(GTEST_TEST "gtest-libmm-gif")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_common"
+ "mmutil_gif"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-gif-unittest.gif"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 "FileInterface.h"
+
+FileInterface::FileInterface(const char *path)
+{
+ fp = NULL;
+ fileSize = 0;
+
+ FileInterface::Open(path);
+}
+
+FileInterface::~FileInterface(void)
+{
+ if (fp)
+ fclose(fp);
+ fp = NULL;
+
+ if (readData)
+ free(readData);
+ readData = NULL;
+}
+
+void FileInterface::Open(const char *path)
+{
+ fp = fopen(path, "r");
+ if (!fp)
+ return ;
+
+ long size = 0;
+
+ fseek(fp, 0, SEEK_END);
+ size = (size_t)ftell(fp);
+ rewind(fp);
+
+ if (size < 0)
+ return ;
+ fileSize = (size_t)size;
+}
+
+gboolean FileInterface::ReadData()
+{
+ if (!fp || fileSize == 0)
+ return FALSE;
+
+ readData = (unsigned char *)calloc(1, fileSize);
+ if (fread(readData, 1, fileSize, fp) != fileSize) {
+ return FALSE;
+ }
+ readDataSize = fileSize;
+ return TRUE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __FILE_INTERFACE_H__
+#define __FILE_INTERFACE_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+class FileInterface {
+ private:
+ FILE *fp;
+ size_t fileSize;
+
+ void Open(const char *path);
+ public:
+ unsigned char *readData;
+ size_t readDataSize;
+
+ FileInterface(const char *path);
+ ~FileInterface(void);
+ gboolean ReadData();
+};
+
+#endif /*__FILE_INTERFACE_H__*/
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_gif_unittest.h"
+#include "FileInterface.h"
+#include "mm_util_gif.h"
+
+#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-gif-unittest.gif")
+#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-gif-result.gif")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_gif_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_gif_Test, mm_util_decode_from_gif_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_gif_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_gif_Test, mm_util_decode_from_gif_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_gif_file(NULL, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_gif_file(DECODE_FILE_PATH, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_gif_Test, mm_util_decode_from_gif_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image;
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_gif_memory(IFile.readData, IFile.readDataSize, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_gif_Test, mm_util_decode_from_gif_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image;
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_gif_memory(NULL, IFile.readDataSize, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_gif_memory(IFile.readData, IFile.readDataSize, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_gif_Test, mm_util_encode_to_gif_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ mm_image_info_s *ptr_decode_image = &decode_image;
+
+ ret = mm_util_decode_from_gif_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_to_gif_file(&ptr_decode_image, 1, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_gif_Test, mm_util_encode_to_gif_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ mm_image_info_s *ptr_decode_image = &decode_image;
+
+ ret = mm_util_encode_to_gif_file(NULL, 1, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_gif_file(&ptr_decode_image, 1, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_gif_Test, mm_util_encode_to_gif_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ mm_image_info_s *ptr_decode_image = &decode_image;
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_decode_from_gif_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_to_gif_memory(&ptr_decode_image, 1, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(buffer != NULL);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+
+ if (buffer != NULL)
+ free(buffer);
+}
+
+TEST(libmm_gif_Test, mm_util_encode_to_gif_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ mm_image_info_s *ptr_decode_image = &decode_image;
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_encode_to_gif_memory(NULL, 1, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_gif_memory(&ptr_decode_image, 1, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_gif_memory(&ptr_decode_image, 1, &buffer, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_GIF_UNITTEST_H__
+#define __LIB_MM_GIF_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_GIF"
+
+#endif /*__LIB_MM_GIF_UNITTEST_H__*/
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-imgcv C CXX)
+
+SET(GTEST_TEST "gtest-libmm-imgcv")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_imgcv"
+ "mmutil_jpeg"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-imgcv-unittest.jpg"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_imgcv_unittest.h"
+#include "mm_util_jpeg.h"
+#include "mm_util_imgcv.h"
+
+#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-imgcv-unittest.jpg")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_imgcv_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_imgcv_Test, mm_util_cv_extract_representative_color_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ unsigned char r_color;
+ unsigned char g_color;
+ unsigned char b_color;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_cv_extract_representative_color(decode_image.data, decode_image.width, decode_image.height, &r_color, &g_color, &b_color);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+
+ if (decode_image.data)
+ free(decode_image.data);
+}
+
+TEST(libmm_imgcv_Test, mm_util_cv_extract_representative_color_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ unsigned char r_color;
+ unsigned char g_color;
+ unsigned char b_color;
+
+ ret = mm_util_cv_extract_representative_color(NULL, decode_image.width, decode_image.height, &r_color, &g_color, &b_color);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_IMGCV_UNITTEST_H__
+#define __LIB_MM_IMGCV_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_IMGCV"
+
+#endif /*__LIB_MM_IMGCV_UNITTEST_H__*/
)
INCLUDE_DIRECTORIES(${INC_DIR}
../common/include
+ ../jpeg/include
)
SET(dependents "dlog glib-2.0 gmodule-2.0")
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst");
mm_util_retvm_if(dst_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_width");
mm_util_retvm_if(dst_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_height");
+ mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width");
+ mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height");
mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size");
mm_util_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format);
mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width");
mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height");
mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size");
+ mm_util_retvm_if((crop_start_x + crop_dest_width == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid crop_width [%d]]", crop_dest_width);
+ mm_util_retvm_if((crop_start_y + crop_dest_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid crop_height [%d]", crop_dest_height);
mm_util_retvm_if((crop_start_x + crop_dest_width > src_width), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid position [%d]]", crop_start_x);
mm_util_retvm_if((crop_start_y + crop_dest_height > src_height), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid position [%d]", crop_start_y);
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-imgp C CXX)
+
+SET(GTEST_TEST "gtest-libmm-imgp")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_imgp"
+ "mmutil_jpeg"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-imgp-unittest.jpg"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_imgp_unittest.h"
+#include "mm_util_jpeg.h"
+#include "mm_util_imgp.h"
+
+#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-imgp-unittest.jpg")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_imgp_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_imgp_Test, mm_util_convert_colorspace_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(data != NULL);
+ EXPECT_EQ(width, 640);
+ EXPECT_EQ(height, 480);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data)
+ free(decode_image.data);
+ if (data)
+ free(data);
+}
+
+TEST(libmm_imgp_Test, mm_util_convert_colorspace_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_convert_colorspace(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, NULL, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, NULL, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, &height, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (decode_image.data)
+ free(decode_image.data);
+}
+
+TEST(libmm_imgp_Test, mm_util_resize_image_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(data != NULL);
+ EXPECT_EQ(width, 320);
+ EXPECT_EQ(height, 240);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data)
+ free(decode_image.data);
+ if (data)
+ free(data);
+}
+
+TEST(libmm_imgp_Test, mm_util_resize_image_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_resize_image(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 240, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 0, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, NULL, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, NULL, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, &height, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (decode_image.data)
+ free(decode_image.data);
+}
+
+TEST(libmm_imgp_Test, mm_util_rotate_image_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(data != NULL);
+ EXPECT_EQ(width, 480);
+ EXPECT_EQ(height, 640);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data)
+ free(decode_image.data);
+ if (data)
+ free(data);
+}
+
+TEST(libmm_imgp_Test, mm_util_rotate_image_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_rotate_image(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, NULL, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, NULL, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, &height, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (decode_image.data)
+ free(decode_image.data);
+}
+
+TEST(libmm_imgp_Test, mm_util_crop_image_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(data != NULL);
+ EXPECT_EQ(width, 320);
+ EXPECT_EQ(height, 240);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data)
+ free(decode_image.data);
+ if (data)
+ free(data);
+}
+
+TEST(libmm_imgp_Test, mm_util_crop_image_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ unsigned char *data = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_crop_image(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 0, 240, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 0, &data, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, NULL, &width, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, NULL, &height, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, &height, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (decode_image.data)
+ free(decode_image.data);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_IMGP_UNITTEST_H__
+#define __LIB_MM_IMGP_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_IMGP"
+
+#endif /*__LIB_MM_IMGP_UNITTEST_H__*/
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
mm_image_info_s decoded;
memset(&decoded, 0, sizeof(mm_image_info_s));
- decoded.width = (int)width;
- decoded.height = (int)height;
+ mm_util_retvm_if(size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size");
+
+ decoded.width = (unsigned long)width;
+ decoded.height = (unsigned long)height;
decoded.color = color;
decoded.data = src;
ret = mm_util_encode_to_jpeg_memory(&decoded, quality, mem, &encoded_size);
- *size = (unsigned int)encoded_size;
mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_encode_to_jpeg_memory fail (%d)", ret);
+ *size = (unsigned int)encoded_size;
+
return ret;
}
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-jpeg C CXX)
+
+SET(GTEST_TEST "gtest-libmm-jpeg")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_common"
+ "mmutil_jpeg"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-jpeg-unittest.jpg"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 "FileInterface.h"
+
+FileInterface::FileInterface(const char *path)
+{
+ fp = NULL;
+ fileSize = 0;
+
+ FileInterface::Open(path);
+}
+
+FileInterface::~FileInterface(void)
+{
+ if (fp)
+ fclose(fp);
+ fp = NULL;
+
+ if (readData)
+ free(readData);
+ readData = NULL;
+}
+
+void FileInterface::Open(const char *path)
+{
+ fp = fopen(path, "r");
+ if (!fp)
+ return ;
+
+ long size = 0;
+
+ fseek(fp, 0, SEEK_END);
+ size = (size_t)ftell(fp);
+ rewind(fp);
+
+ if (size < 0)
+ return ;
+ fileSize = (size_t)size;
+}
+
+gboolean FileInterface::ReadData()
+{
+ if (!fp || fileSize == 0)
+ return FALSE;
+
+ readData = (unsigned char *)calloc(1, fileSize);
+ if (fread(readData, 1, fileSize, fp) != fileSize) {
+ return FALSE;
+ }
+ readDataSize = fileSize;
+ return TRUE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __FILE_INTERFACE_H__
+#define __FILE_INTERFACE_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+class FileInterface {
+ private:
+ FILE *fp;
+ size_t fileSize;
+
+ void Open(const char *path);
+ public:
+ unsigned char *readData;
+ size_t readDataSize;
+
+ FileInterface(const char *path);
+ ~FileInterface(void);
+ gboolean ReadData();
+};
+
+#endif /*__FILE_INTERFACE_H__*/
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_jpeg_unittest.h"
+#include "FileInterface.h"
+#include "mm_util_jpeg.h"
+
+#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-jpeg-unittest.jpg")
+#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-jpeg-result.jpg")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_jpeg_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_jpeg_Test, mm_util_decode_from_jpeg_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_jpeg_Test, mm_util_decode_from_jpeg_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+
+ ret = mm_util_decode_from_jpeg_file(NULL, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_jpeg_Test, mm_util_decode_from_jpeg_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_jpeg_memory(IFile.readData, IFile.readDataSize, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_jpeg_Test, mm_util_decode_from_jpeg_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_jpeg_memory(NULL, IFile.readDataSize, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_jpeg_memory(IFile.readData, IFile.readDataSize, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_jpeg_Test, mm_util_jpeg_encode_to_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_jpeg_encode_to_file(&decode_image, 100, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_jpeg_Test, mm_util_jpeg_encode_to_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+
+ ret = mm_util_jpeg_encode_to_file(NULL, 100, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_jpeg_encode_to_file(&decode_image, 0, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_jpeg_encode_to_file(&decode_image, 100, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_jpeg_Test, mm_util_jpeg_encode_to_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_jpeg_encode_to_memory(&buffer, &size, (unsigned char*)decode_image.data, (unsigned int)decode_image.width, (unsigned int)decode_image.height, decode_image.color, 100);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(buffer != NULL);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_jpeg_Test, mm_util_jpeg_encode_to_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ void *buffer = NULL;
+ unsigned int size = 0;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_jpeg_encode_to_memory(NULL, &size, (unsigned char*)decode_image.data, (unsigned int)decode_image.width, (unsigned int)decode_image.height, decode_image.color, 100);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_jpeg_encode_to_memory(&buffer, NULL, (unsigned char*)decode_image.data, (unsigned int)decode_image.width, (unsigned int)decode_image.height, decode_image.color, 100);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_jpeg_encode_to_memory(&buffer, &size, (unsigned char*)decode_image.data, (unsigned int)decode_image.width, (unsigned int)decode_image.height, decode_image.color, 0);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_jpeg_Test, mm_util_encode_to_jpeg_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_RGB24, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_to_jpeg_memory(&decode_image, 100, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(buffer != NULL);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+
+ if (buffer != NULL)
+ free(buffer);
+}
+
+TEST(libmm_jpeg_Test, mm_util_encode_to_jpeg_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0};
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_encode_to_jpeg_memory(NULL, 100, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_jpeg_memory(&decode_image, 100, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_jpeg_memory(&decode_image, 100, &buffer, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_JPEG_UNITTEST_H__
+#define __LIB_MM_JPEG_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_JPEG"
+
+#endif /*__LIB_MM_JPEG_UNITTEST_H__*/
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*__MM_UTILITY_MAGICK_H__*/
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-magick C CXX)
+
+SET(GTEST_TEST "gtest-libmm-magick")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_magick"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-magick-unittest.jpg"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_magick_unittest.h"
+#include "mm_util_magick.h"
+
+#define SRC_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-magick-unittest.jpg")
+#define DST_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-magick-result.jpg")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_magick_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_magick_Test, mm_util_rotate_P_P_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+
+ ret = mm_util_rotate_P_P(SRC_FILE_PATH, MM_UTIL_ROTATE_90, DST_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+}
+
+TEST(libmm_magick_Test, mm_util_rotate_P_P_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+
+ ret = mm_util_rotate_P_P(NULL, MM_UTIL_ROTATE_90, DST_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_rotate_P_P(SRC_FILE_PATH, MM_UTIL_ROTATE_90, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_magick_Test, mm_util_resize_P_P_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+
+ ret = mm_util_resize_P_P(SRC_FILE_PATH, 320, 240, DST_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+}
+
+TEST(libmm_magick_Test, mm_util_resize_P_P_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+
+ ret = mm_util_resize_P_P(NULL, 320, 240, DST_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_P_P(SRC_FILE_PATH, 0, 240, DST_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_P_P(SRC_FILE_PATH, 320, 0, DST_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_resize_P_P(SRC_FILE_PATH, 320, 240, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_MAGICK_UNITTEST_H__
+#define __LIB_MM_MAGICK_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_MAGICK"
+
+#endif /*__LIB_MM_MAGICK_UNITTEST_H__*/
BuildRequires: pkgconfig(libbmp)
BuildRequires: pkgconfig(libnsbmp)
BuildRequires: pkgconfig(GraphicsMagick)
+%if 0%{?gtests:1}
+BuildRequires: pkgconfig(gmock)
+%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
%build
export CFLAGS="$CFLAGS -DGMAGICK_DEBUG=0 -D_FORTIFY_SOURCE=2"
-%cmake .
+
+%cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0}
make %{?jobs:-j%jobs}
%install
%defattr(-,root,root,-)
%{_libdir}/*.so.*
%{_libdir}/libmmutil_imgcv.so
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%{_bindir}/libmm*unittest*
+%endif
%license LICENSE.APLv2.0
%files devel
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libmm-png C CXX)
+
+SET(GTEST_TEST "gtest-libmm-png")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+ "mmutil_common"
+ "mmutil_png"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+ "libmm-png-unittest.png"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
+INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 "FileInterface.h"
+
+FileInterface::FileInterface(const char *path)
+{
+ fp = NULL;
+ fileSize = 0;
+
+ FileInterface::Open(path);
+}
+
+FileInterface::~FileInterface(void)
+{
+ if (fp)
+ fclose(fp);
+ fp = NULL;
+
+ if (readData)
+ free(readData);
+ readData = NULL;
+}
+
+void FileInterface::Open(const char *path)
+{
+ fp = fopen(path, "r");
+ if (!fp)
+ return ;
+
+ long size = 0;
+
+ fseek(fp, 0, SEEK_END);
+ size = (size_t)ftell(fp);
+ rewind(fp);
+
+ if (size < 0)
+ return ;
+ fileSize = (size_t)size;
+}
+
+gboolean FileInterface::ReadData()
+{
+ if (!fp || fileSize == 0)
+ return FALSE;
+
+ readData = (unsigned char *)calloc(1, fileSize);
+ if (fread(readData, 1, fileSize, fp) != fileSize) {
+ return FALSE;
+ }
+ readDataSize = fileSize;
+ return TRUE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __FILE_INTERFACE_H__
+#define __FILE_INTERFACE_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+class FileInterface {
+ private:
+ FILE *fp;
+ size_t fileSize;
+
+ void Open(const char *path);
+ public:
+ unsigned char *readData;
+ size_t readDataSize;
+
+ FileInterface(const char *path);
+ ~FileInterface(void);
+ gboolean ReadData();
+};
+
+#endif /*__FILE_INTERFACE_H__*/
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <tzplatform_config.h>
+
+#include "libmm_png_unittest.h"
+#include "FileInterface.h"
+#include "mm_util_png.h"
+
+#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-png-unittest.png")
+#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-png-result.png")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_png_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(libmm_png_Test, mm_util_decode_from_png_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_png_Test, mm_util_decode_from_png_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_png_file(NULL, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_png_Test, mm_util_decode_from_png_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image;
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_png_memory(IFile.readData, IFile.readDataSize, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_EQ(decode_image.width, 640);
+ EXPECT_EQ(decode_image.height, 480);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_png_Test, mm_util_decode_from_png_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ gboolean err = TRUE;
+ mm_image_info_s decode_image;
+
+ FileInterface IFile = FileInterface(DECODE_FILE_PATH);
+ err = IFile.ReadData();
+ EXPECT_TRUE(err);
+
+ ret = mm_util_decode_from_png_memory(NULL, IFile.readDataSize, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_decode_from_png_memory(IFile.readData, IFile.readDataSize, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_png_Test, mm_util_encode_to_png_file_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_to_png_file(&decode_image, MM_UTIL_COMPRESSION_6, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+}
+
+TEST(libmm_png_Test, mm_util_encode_to_png_file_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+
+ ret = mm_util_encode_to_png_file(NULL, MM_UTIL_COMPRESSION_6, ENCODE_FILE_PATH);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_png_file(&decode_image, MM_UTIL_COMPRESSION_6, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+TEST(libmm_png_Test, mm_util_encode_to_png_memory_p)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(decode_image.data != NULL);
+
+ ret = mm_util_encode_to_png_memory(&decode_image, MM_UTIL_COMPRESSION_6, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
+ EXPECT_TRUE(buffer != NULL);
+ EXPECT_NE(size, 0);
+
+ if (decode_image.data != NULL)
+ free(decode_image.data);
+
+ if (buffer != NULL)
+ free(buffer);
+}
+
+TEST(libmm_png_Test, mm_util_encode_to_png_memory_n)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s decode_image;
+ void *buffer = NULL;
+ size_t size = 0;
+
+ ret = mm_util_encode_to_png_memory(NULL, MM_UTIL_COMPRESSION_6, &buffer, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_png_memory(&decode_image, MM_UTIL_COMPRESSION_6, NULL, &size);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+
+ ret = mm_util_encode_to_png_memory(&decode_image, MM_UTIL_COMPRESSION_6, &buffer, NULL);
+ EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __LIB_MM_PNG_UNITTEST_H__
+#define __LIB_MM_PNG_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_LIBMM_PNG"
+
+#endif /*__LIB_MM_PNG_UNITTEST_H__*/