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})
} 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 { \
#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!")
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
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"
%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
--- /dev/null
+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)
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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);
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __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__*/
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <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();
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __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__*/