Adding initial structure for unittest 75/193375/5 accepted/tizen/unified/20181127.073302 submit/tizen/20181126.011146
authorjiyong.min <jiyong.min@samsung.com>
Tue, 20 Nov 2018 02:50:19 +0000 (11:50 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 26 Nov 2018 00:15:37 +0000 (09:15 +0900)
- It has testcases for dcm-face library of unittest
- It would be enabled by gtest build with '--define "gtests 1"'

Change-Id: Ie0b7f098391e2153034311ebd245d2ec2e6f6b4a

CMakeLists.txt [changed mode: 0755->0644]
include/dcm_svc_debug.h
packaging/dcm-service.spec [changed mode: 0755->0644]
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/DcmFaceUnittest.cpp [new file with mode: 0644]
unittest/DcmFaceUnittest.h [new file with mode: 0644]
unittest/dcm-service-unittest.jpg [new file with mode: 0644]
unittest/dcm_service_unittest.cpp [new file with mode: 0644]
unittest/dcm_service_unittest.h [new file with mode: 0644]

old mode 100755 (executable)
new mode 100644 (file)
index 7721000..802b56c
@@ -72,6 +72,9 @@ CONFIGURE_FILE(dcm-service.pc.in dcm-service.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/dcm-service.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 ADD_SUBDIRECTORY(svc)
+IF(BUILD_GTESTS)
+       ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
 
 LINK_DIRECTORIES(${LIB_INSTALL_DIR})
 
index e8d01cacc2fd9ff2f738e34af985aafcb63f93a6..c810eee1eb161fb897b8947d352e4f10292a20a5 100755 (executable)
                } while (0)
 
 #define dcm_debug_fenter() do { \
-                       LOGD(FONT_COLOR_YELLOW"<ENTER>"FONT_COLOR_RESET); \
+                       LOGD(FONT_COLOR_YELLOW "<ENTER>" FONT_COLOR_RESET); \
                } while (0)
 
 #define dcm_debug_fleave() do { \
-                       LOGD(FONT_COLOR_YELLOW"<LEAVE>"FONT_COLOR_RESET); \
+                       LOGD(FONT_COLOR_YELLOW "<LEAVE>" FONT_COLOR_RESET); \
                } while (0)
 
 #define dcm_retm_if(expr, fmt, arg...) do { \
@@ -93,7 +93,7 @@
 #define ERR_BUF_LENGHT 256
 #define dcm_stderror(fmt) do { \
                                        char dcm_stderror_buf[ERR_BUF_LENGHT] = {0, }; \
-                                       LOGE(FONT_COLOR_RED""fmt""" : STANDARD ERROR [%s]"FONT_COLOR_RESET, strerror_r(errno, dcm_stderror_buf, ERR_BUF_LENGHT)); \
+                                       LOGE(FONT_COLOR_RED"" fmt "" " : STANDARD ERROR [%s]" FONT_COLOR_RESET, strerror_r(errno, dcm_stderror_buf, ERR_BUF_LENGHT)); \
                                } while (0)
 
 #define DCM_CHECK_VAL(expr, val)               dcm_retvm_if(!(expr), val, "Invalid parameter, return ERROR code!")
old mode 100755 (executable)
new mode 100644 (file)
index 7deea8c..c4419ae
@@ -18,6 +18,9 @@ BuildRequires:  pkgconfig(capi-media-vision)
 BuildRequires:  pkgconfig(libmedia-utils)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(mmutil-magick)
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 This package provides a media DCM(Digital Contents Management) service
@@ -40,7 +43,7 @@ export CFLAGS="$(echo $CFLAGS | sed 's/-Wl,--as-needed//g')"
 export CXXFLAGS="$(echo $CXXFLAGS | sed 's/-Wl,--as-needed//g')"
 export FFLAGS="$(echo $FFLAGS | sed 's/-Wl,--as-needed//g')"
 
-%cmake .
+%cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0}
 make %{?jobs:-j%jobs}
 #export CFLAGS+=" -Wextra -Wno-array-bounds -D_FORTIFY_SOURCE=2"
 #export CFLAGS+=" -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow"
@@ -56,7 +59,11 @@ make %{?jobs:-j%jobs}
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
 %{_libdir}/*.so*
-%{_bindir}/*
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%{_bindir}/dcm-service-unittest*
+%endif
+%{_bindir}/dcm-svc
 %license LICENSE.APLv2.0
 
 %files devel
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..acf9051
--- /dev/null
@@ -0,0 +1,46 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-dcm-service C CXX)
+
+SET(GTEST_TEST "gtest-dcm-service")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+       glib-2.0
+       gio-2.0
+       gmock
+       dlog
+       libmedia-utils
+       capi-media-vision
+       mmutil-magick
+       libtzplatform-config
+)
+
+SET(PKG_LIBRARIES ${PKG_LIBRARIES}
+       "dcm-face"
+       "dcm-util"
+)
+
+SET(RESOURCE_LIST ${RESOURCE_LIST}
+       "dcm-service-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/unittest/DcmFaceUnittest.cpp b/unittest/DcmFaceUnittest.cpp
new file mode 100644 (file)
index 0000000..006fd50
--- /dev/null
@@ -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 "DcmFaceUnittest.h"
+
+DcmFaceUnittest::DcmFaceUnittest(void)
+{
+       handle = NULL;
+       sourceImage = NULL;
+       data = NULL;
+       width = 0;
+       height = 0;
+       color = MM_UTIL_COLOR_RGB24;
+       dataSize = 0;
+       faceInfo = { NULL, 0 };
+}
+
+DcmFaceUnittest::~DcmFaceUnittest(void)
+{
+       if (sourceImage) {
+               mm_util_destroy_handle(sourceImage);
+               sourceImage = NULL;
+       }
+
+       if (faceInfo.rects) {
+               free(faceInfo.rects);
+               faceInfo.rects = NULL;
+       }
+
+       if (handle) {
+               Deinit();
+               handle = NULL;
+       }
+}
+
+int DcmFaceUnittest::Init(void)
+{
+       return dcm_face_create(&handle);
+}
+
+int DcmFaceUnittest::Deinit(void)
+{
+       int ret = dcm_face_destroy(handle);
+
+       handle = NULL;
+
+       return ret;
+}
+
+int DcmFaceUnittest::DecodeImage(const char *path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       ret = mm_util_rotate_P_B(path, MM_UTIL_ROTATE_0, MM_UTIL_COLOR_RGB24, &sourceImage);
+       if (ret != MS_MEDIA_ERR_NONE) {
+               return ret;
+       }
+
+       return mm_util_get_image(sourceImage, &data, &width, &height, &dataSize, &color);
+}
+
+int DcmFaceUnittest::SetImageInfo(const char *path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       ret = DecodeImage(path);
+       if (ret != MS_MEDIA_ERR_NONE) {
+               return ret;
+       }
+
+       return dcm_face_set_image_info(handle, FACE_IMAGE_COLORSPACE_RGB888, data, width, height, dataSize);
+}
+
+int DcmFaceUnittest::GetFaceInfo(void)
+{
+       return dcm_face_get_face_info(handle, &faceInfo);
+}
diff --git a/unittest/DcmFaceUnittest.h b/unittest/DcmFaceUnittest.h
new file mode 100644 (file)
index 0000000..d5ace73
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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 __DCM_FACE_UNITTEST_H__
+#define __DCM_FACE_UNITTEST_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <media-util.h>
+#include <mm_util_magick.h>
+
+#include "dcm-face.h"
+
+class DcmFaceUnittest {
+       private:
+               dcm_face_h handle;
+               mm_util_image_h sourceImage;
+
+               int DecodeImage(const char *path);
+       public:
+               unsigned char *data;
+               unsigned int width;
+               unsigned int height;
+               mm_util_color_format_e color;
+               size_t dataSize;
+               face_info_s faceInfo;
+
+               DcmFaceUnittest(void);
+               ~DcmFaceUnittest(void);
+               int Init(void);
+               int Deinit(void);
+               int SetImageInfo(const char *path);
+               int GetFaceInfo(void);
+};
+
+#endif /*__DCM_FACE_UNITTEST_H__*/
diff --git a/unittest/dcm-service-unittest.jpg b/unittest/dcm-service-unittest.jpg
new file mode 100644 (file)
index 0000000..a1a4fc4
Binary files /dev/null and b/unittest/dcm-service-unittest.jpg differ
diff --git a/unittest/dcm_service_unittest.cpp b/unittest/dcm_service_unittest.cpp
new file mode 100644 (file)
index 0000000..090de27
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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 <media-util.h>
+#include <tzplatform_config.h>
+
+#include "dcm_service_unittest.h"
+#include "DcmFaceUnittest.h"
+
+#define TEST_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "dcm-service-unittest.jpg")
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class dcm_service_Test : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       std::cout << "SetUp()" << std::endl;
+               }
+
+               void TearDown() {
+                       std::cout << "TearDown()" << std::endl;
+               }
+};
+
+TEST(dcm_service_Test, dcm_face_create_p)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       DcmFaceUnittest dcmFace;
+
+       ret = dcmFace.Init();
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+}
+
+TEST(dcm_service_Test, dcm_face_destroy_p)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       DcmFaceUnittest dcmFace;
+
+       ret = dcmFace.Init();
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+
+       ret = dcmFace.Deinit();
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+}
+
+TEST(dcm_service_Test, dcm_face_set_image_info_p)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       DcmFaceUnittest dcmFace;
+
+       ret = dcmFace.Init();
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+
+       ret = dcmFace.SetImageInfo(TEST_FILE_PATH);
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+       EXPECT_TRUE(dcmFace.data != NULL);
+       EXPECT_NE(dcmFace.width, 0);
+       EXPECT_NE(dcmFace.height, 0);
+       EXPECT_EQ(dcmFace.color, MM_UTIL_COLOR_RGB24);
+       EXPECT_NE(dcmFace.dataSize, 0);
+}
+
+TEST(dcm_service_Test, dcm_face_get_face_info_p)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       DcmFaceUnittest dcmFace;
+
+       ret = dcmFace.Init();
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+
+       ret = dcmFace.SetImageInfo(TEST_FILE_PATH);
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+
+       ret = dcmFace.GetFaceInfo();
+       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+       EXPECT_EQ(dcmFace.faceInfo.count, 0);
+       if (dcmFace.faceInfo.count != 0)
+               EXPECT_TRUE(dcmFace.faceInfo.rects != NULL);
+}
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/dcm_service_unittest.h b/unittest/dcm_service_unittest.h
new file mode 100644 (file)
index 0000000..60eaaf4
--- /dev/null
@@ -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 __DCM_SERVICE_UNITTEST_H__
+#define __DCM_SERVICE_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_DCM_SERVICE"
+
+#endif /*__DCM_SERVICE_UNITTEST_H__*/