From: jiyong.min Date: Tue, 20 Nov 2018 00:50:53 +0000 (+0900) Subject: Adding initial structure for unittest X-Git-Tag: accepted/tizen/unified/20181127.073312^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d78aae9c22f673cf1e2ca73566a16083d8c90bb;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Adding initial structure for unittest - It has testcases for bmp, gif, imgcv, imgp, jpeg, magick and png of unittest - It would be enabled by gtest build with '--define "gtests 1"' - In would be executed by both root and user Change-Id: I3d4bc7ad60ed59b534e25a2b81f1b2e7514513ba --- diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/bmp/CMakeLists.txt b/bmp/CMakeLists.txt index 0fb541b..abf459a 100755 --- a/bmp/CMakeLists.txt +++ b/bmp/CMakeLists.txt @@ -67,3 +67,6 @@ CONFIGURE_FILE( 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) diff --git a/bmp/unittest/CMakeLists.txt b/bmp/unittest/CMakeLists.txt new file mode 100644 index 0000000..7f47443 --- /dev/null +++ b/bmp/unittest/CMakeLists.txt @@ -0,0 +1,43 @@ +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) diff --git a/bmp/unittest/FileInterface.cpp b/bmp/unittest/FileInterface.cpp new file mode 100644 index 0000000..8dbbdee --- /dev/null +++ b/bmp/unittest/FileInterface.cpp @@ -0,0 +1,66 @@ +/* + * 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; +} diff --git a/bmp/unittest/FileInterface.h b/bmp/unittest/FileInterface.h new file mode 100644 index 0000000..5284dda --- /dev/null +++ b/bmp/unittest/FileInterface.h @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include + +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__*/ diff --git a/bmp/unittest/libmm-bmp-unittest.bmp b/bmp/unittest/libmm-bmp-unittest.bmp new file mode 100755 index 0000000..824a034 Binary files /dev/null and b/bmp/unittest/libmm-bmp-unittest.bmp differ diff --git a/bmp/unittest/libmm_bmp_unittest.cpp b/bmp/unittest/libmm_bmp_unittest.cpp new file mode 100644 index 0000000..7d44187 --- /dev/null +++ b/bmp/unittest/libmm_bmp_unittest.cpp @@ -0,0 +1,179 @@ +/* + * 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 + +#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(); +} + diff --git a/bmp/unittest/libmm_bmp_unittest.h b/bmp/unittest/libmm_bmp_unittest.h new file mode 100644 index 0000000..61d6f4d --- /dev/null +++ b/bmp/unittest/libmm_bmp_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_BMP" + +#endif /*__LIB_MM_BMP_UNITTEST_H__*/ diff --git a/gif/CMakeLists.txt b/gif/CMakeLists.txt old mode 100755 new mode 100644 index c1a6eb9..24ac8f2 --- a/gif/CMakeLists.txt +++ b/gif/CMakeLists.txt @@ -67,3 +67,6 @@ CONFIGURE_FILE( 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) diff --git a/gif/mm_util_gif.c b/gif/mm_util_gif.c index 4844320..1027381 100644 --- a/gif/mm_util_gif.c +++ b/gif/mm_util_gif.c @@ -261,6 +261,9 @@ error: 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); @@ -268,6 +271,9 @@ int mm_util_decode_from_gif_file(const char *fpath, mm_image_info_s *decoded) 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); @@ -713,8 +719,8 @@ int mm_util_encode_to_gif_file(mm_image_info_s **images, const unsigned int imag 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); @@ -747,8 +753,8 @@ int mm_util_encode_to_gif_memory(mm_image_info_s **images, const unsigned int im 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); diff --git a/gif/unittest/CMakeLists.txt b/gif/unittest/CMakeLists.txt new file mode 100644 index 0000000..84fa651 --- /dev/null +++ b/gif/unittest/CMakeLists.txt @@ -0,0 +1,43 @@ +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) diff --git a/gif/unittest/FileInterface.cpp b/gif/unittest/FileInterface.cpp new file mode 100644 index 0000000..8dbbdee --- /dev/null +++ b/gif/unittest/FileInterface.cpp @@ -0,0 +1,66 @@ +/* + * 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; +} diff --git a/gif/unittest/FileInterface.h b/gif/unittest/FileInterface.h new file mode 100644 index 0000000..5284dda --- /dev/null +++ b/gif/unittest/FileInterface.h @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include + +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__*/ diff --git a/gif/unittest/libmm-gif-unittest.gif b/gif/unittest/libmm-gif-unittest.gif new file mode 100644 index 0000000..8626503 Binary files /dev/null and b/gif/unittest/libmm-gif-unittest.gif differ diff --git a/gif/unittest/libmm_gif_unittest.cpp b/gif/unittest/libmm_gif_unittest.cpp new file mode 100644 index 0000000..4910b0c --- /dev/null +++ b/gif/unittest/libmm_gif_unittest.cpp @@ -0,0 +1,183 @@ +/* + * 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 + +#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(); +} + diff --git a/gif/unittest/libmm_gif_unittest.h b/gif/unittest/libmm_gif_unittest.h new file mode 100644 index 0000000..33b1df3 --- /dev/null +++ b/gif/unittest/libmm_gif_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_GIF" + +#endif /*__LIB_MM_GIF_UNITTEST_H__*/ diff --git a/imgcv/CMakeLists.txt b/imgcv/CMakeLists.txt old mode 100755 new mode 100644 index de86153..7d00888 --- a/imgcv/CMakeLists.txt +++ b/imgcv/CMakeLists.txt @@ -71,3 +71,6 @@ CONFIGURE_FILE( 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) diff --git a/imgcv/unittest/CMakeLists.txt b/imgcv/unittest/CMakeLists.txt new file mode 100644 index 0000000..0b24693 --- /dev/null +++ b/imgcv/unittest/CMakeLists.txt @@ -0,0 +1,43 @@ +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) diff --git a/imgcv/unittest/libmm-imgcv-unittest.jpg b/imgcv/unittest/libmm-imgcv-unittest.jpg new file mode 100644 index 0000000..a1a4fc4 Binary files /dev/null and b/imgcv/unittest/libmm-imgcv-unittest.jpg differ diff --git a/imgcv/unittest/libmm_imgcv_unittest.cpp b/imgcv/unittest/libmm_imgcv_unittest.cpp new file mode 100644 index 0000000..73c5f00 --- /dev/null +++ b/imgcv/unittest/libmm_imgcv_unittest.cpp @@ -0,0 +1,77 @@ +/* + * 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 + +#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(); +} + diff --git a/imgcv/unittest/libmm_imgcv_unittest.h b/imgcv/unittest/libmm_imgcv_unittest.h new file mode 100644 index 0000000..6aed717 --- /dev/null +++ b/imgcv/unittest/libmm_imgcv_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_IMGCV" + +#endif /*__LIB_MM_IMGCV_UNITTEST_H__*/ diff --git a/imgp/CMakeLists.txt b/imgp/CMakeLists.txt old mode 100755 new mode 100644 index 908c5d5..232f05b --- a/imgp/CMakeLists.txt +++ b/imgp/CMakeLists.txt @@ -13,6 +13,7 @@ SET(INC_DIR ) INCLUDE_DIRECTORIES(${INC_DIR} ../common/include + ../jpeg/include ) SET(dependents "dlog glib-2.0 gmodule-2.0") @@ -67,3 +68,6 @@ CONFIGURE_FILE( 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) diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 0ee4bf4..bc325be 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -579,6 +579,8 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig 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); @@ -778,6 +780,8 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid 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); diff --git a/imgp/unittest/CMakeLists.txt b/imgp/unittest/CMakeLists.txt new file mode 100644 index 0000000..1c9d130 --- /dev/null +++ b/imgp/unittest/CMakeLists.txt @@ -0,0 +1,43 @@ +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) diff --git a/imgp/unittest/libmm-imgp-unittest.jpg b/imgp/unittest/libmm-imgp-unittest.jpg new file mode 100644 index 0000000..a1a4fc4 Binary files /dev/null and b/imgp/unittest/libmm-imgp-unittest.jpg differ diff --git a/imgp/unittest/libmm_imgp_unittest.cpp b/imgp/unittest/libmm_imgp_unittest.cpp new file mode 100644 index 0000000..190a090 --- /dev/null +++ b/imgp/unittest/libmm_imgp_unittest.cpp @@ -0,0 +1,290 @@ +/* + * 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 + +#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(); +} + diff --git a/imgp/unittest/libmm_imgp_unittest.h b/imgp/unittest/libmm_imgp_unittest.h new file mode 100644 index 0000000..16fd7b0 --- /dev/null +++ b/imgp/unittest/libmm_imgp_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_IMGP" + +#endif /*__LIB_MM_IMGP_UNITTEST_H__*/ diff --git a/jpeg/CMakeLists.txt b/jpeg/CMakeLists.txt old mode 100755 new mode 100644 index 51ed9b4..bcce9e8 --- a/jpeg/CMakeLists.txt +++ b/jpeg/CMakeLists.txt @@ -68,3 +68,6 @@ CONFIGURE_FILE( 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) diff --git a/jpeg/mm_util_jpeg.c b/jpeg/mm_util_jpeg.c index f596d4f..61a9eaf 100644 --- a/jpeg/mm_util_jpeg.c +++ b/jpeg/mm_util_jpeg.c @@ -520,15 +520,18 @@ int mm_util_jpeg_encode_to_memory(void **mem, unsigned int *size, unsigned char 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; } diff --git a/jpeg/unittest/CMakeLists.txt b/jpeg/unittest/CMakeLists.txt new file mode 100644 index 0000000..634c1a8 --- /dev/null +++ b/jpeg/unittest/CMakeLists.txt @@ -0,0 +1,43 @@ +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) diff --git a/jpeg/unittest/FileInterface.cpp b/jpeg/unittest/FileInterface.cpp new file mode 100644 index 0000000..8dbbdee --- /dev/null +++ b/jpeg/unittest/FileInterface.cpp @@ -0,0 +1,66 @@ +/* + * 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; +} diff --git a/jpeg/unittest/FileInterface.h b/jpeg/unittest/FileInterface.h new file mode 100644 index 0000000..5284dda --- /dev/null +++ b/jpeg/unittest/FileInterface.h @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include + +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__*/ diff --git a/jpeg/unittest/libmm-jpeg-unittest.jpg b/jpeg/unittest/libmm-jpeg-unittest.jpg new file mode 100644 index 0000000..a1a4fc4 Binary files /dev/null and b/jpeg/unittest/libmm-jpeg-unittest.jpg differ diff --git a/jpeg/unittest/libmm_jpeg_unittest.cpp b/jpeg/unittest/libmm_jpeg_unittest.cpp new file mode 100644 index 0000000..7c4474b --- /dev/null +++ b/jpeg/unittest/libmm_jpeg_unittest.cpp @@ -0,0 +1,226 @@ +/* + * 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 + +#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(); +} + diff --git a/jpeg/unittest/libmm_jpeg_unittest.h b/jpeg/unittest/libmm_jpeg_unittest.h new file mode 100644 index 0000000..2832ac2 --- /dev/null +++ b/jpeg/unittest/libmm_jpeg_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_JPEG" + +#endif /*__LIB_MM_JPEG_UNITTEST_H__*/ diff --git a/magick/CMakeLists.txt b/magick/CMakeLists.txt old mode 100755 new mode 100644 index 9356431..1d2177b --- a/magick/CMakeLists.txt +++ b/magick/CMakeLists.txt @@ -67,3 +67,6 @@ CONFIGURE_FILE( 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) diff --git a/magick/include/mm_util_magick.h b/magick/include/mm_util_magick.h index 9c0f13b..8c1216e 100755 --- a/magick/include/mm_util_magick.h +++ b/magick/include/mm_util_magick.h @@ -72,4 +72,8 @@ int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_color_format_e req_f 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__*/ diff --git a/magick/unittest/CMakeLists.txt b/magick/unittest/CMakeLists.txt new file mode 100644 index 0000000..2dfa576 --- /dev/null +++ b/magick/unittest/CMakeLists.txt @@ -0,0 +1,42 @@ +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) diff --git a/magick/unittest/libmm-magick-unittest.jpg b/magick/unittest/libmm-magick-unittest.jpg new file mode 100644 index 0000000..a1a4fc4 Binary files /dev/null and b/magick/unittest/libmm-magick-unittest.jpg differ diff --git a/magick/unittest/libmm_magick_unittest.cpp b/magick/unittest/libmm_magick_unittest.cpp new file mode 100644 index 0000000..10a6968 --- /dev/null +++ b/magick/unittest/libmm_magick_unittest.cpp @@ -0,0 +1,90 @@ +/* + * 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 + +#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(); +} + diff --git a/magick/unittest/libmm_magick_unittest.h b/magick/unittest/libmm_magick_unittest.h new file mode 100644 index 0000000..4d4ee01 --- /dev/null +++ b/magick/unittest/libmm_magick_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_MAGICK" + +#endif /*__LIB_MM_MAGICK_UNITTEST_H__*/ diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index a4ff1b3..a638d2b 100755 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -23,6 +23,9 @@ BuildRequires: giflib-devel BuildRequires: pkgconfig(libbmp) BuildRequires: pkgconfig(libnsbmp) BuildRequires: pkgconfig(GraphicsMagick) +%if 0%{?gtests:1} +BuildRequires: pkgconfig(gmock) +%endif BuildRoot: %{_tmppath}/%{name}-%{version}-build %description @@ -42,7 +45,8 @@ cp %{SOURCE1001} . %build export CFLAGS="$CFLAGS -DGMAGICK_DEBUG=0 -D_FORTIFY_SOURCE=2" -%cmake . + +%cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} make %{?jobs:-j%jobs} %install @@ -60,6 +64,10 @@ rm -rf %{buildroot} %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 diff --git a/png/CMakeLists.txt b/png/CMakeLists.txt old mode 100755 new mode 100644 index ed36371..e2d3dc8 --- a/png/CMakeLists.txt +++ b/png/CMakeLists.txt @@ -67,3 +67,6 @@ CONFIGURE_FILE( 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) diff --git a/png/unittest/CMakeLists.txt b/png/unittest/CMakeLists.txt new file mode 100644 index 0000000..68c0a7d --- /dev/null +++ b/png/unittest/CMakeLists.txt @@ -0,0 +1,43 @@ +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) diff --git a/png/unittest/FileInterface.cpp b/png/unittest/FileInterface.cpp new file mode 100644 index 0000000..8dbbdee --- /dev/null +++ b/png/unittest/FileInterface.cpp @@ -0,0 +1,66 @@ +/* + * 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; +} diff --git a/png/unittest/FileInterface.h b/png/unittest/FileInterface.h new file mode 100644 index 0000000..5284dda --- /dev/null +++ b/png/unittest/FileInterface.h @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include + +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__*/ diff --git a/png/unittest/libmm-png-unittest.png b/png/unittest/libmm-png-unittest.png new file mode 100644 index 0000000..98a2c92 Binary files /dev/null and b/png/unittest/libmm-png-unittest.png differ diff --git a/png/unittest/libmm_png_unittest.cpp b/png/unittest/libmm_png_unittest.cpp new file mode 100644 index 0000000..6838a1c --- /dev/null +++ b/png/unittest/libmm_png_unittest.cpp @@ -0,0 +1,179 @@ +/* + * 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 + +#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(); +} + diff --git a/png/unittest/libmm_png_unittest.h b/png/unittest/libmm_png_unittest.h new file mode 100644 index 0000000..6871f0b --- /dev/null +++ b/png/unittest/libmm_png_unittest.h @@ -0,0 +1,26 @@ +/* + * 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 +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_PNG" + +#endif /*__LIB_MM_PNG_UNITTEST_H__*/