Add unit test 38/193838/6 accepted/tizen/unified/20181130.064927 submit/tizen/20181129.024814
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 27 Nov 2018 03:30:14 +0000 (12:30 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 28 Nov 2018 05:12:28 +0000 (14:12 +0900)
- Precondition to run gtests-*
 : The executable label should be changed to "User" after install
 : The user should be "owner"

[Version] 0.3.21
[Profile] Common
[Issue Type] Update
[Dependency module] N/A

Change-Id: Iaca9b1511552406ccd4e3b1100ec9a400f88ebba
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
13 files changed:
CMakeLists.txt
legacy/CMakeLists.txt
muse/CMakeLists.txt
muse/include/muse_camera.h
muse/include/muse_camera_internal.h
packaging/mmsvc-camera.spec
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/legacy/CMakeLists.txt [new file with mode: 0644]
unittest/legacy/gtests_legacy_camera.cpp [new file with mode: 0644]
unittest/legacy/gtests_legacy_camera.h [new file with mode: 0644]
unittest/muse/CMakeLists.txt [new file with mode: 0644]
unittest/muse/gtests_muse_camera.cpp [new file with mode: 0644]
unittest/muse/gtests_muse_camera.h [new file with mode: 0644]

index 7441a9f..4d38e81 100644 (file)
@@ -37,6 +37,9 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/legacy-camera.pc DESTINATION ${LIB_INS
 
 ADD_SUBDIRECTORY(legacy)
 ADD_SUBDIRECTORY(muse)
+IF(ENABLE_GTESTS)
+ADD_SUBDIRECTORY(unittest)
+ENDIF(ENABLE_GTESTS)
 
 IF(UNIX)
 
index 1a02431..dac9bd5 100644 (file)
@@ -1,14 +1,11 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
 SET(service "legacy")
 SET(submodule "camera")
 
-# for package file
 SET(dependents "dlog mm-camcorder capi-base-common")
+SET(LEGACY "${service}-${submodule}")
 
-SET(fw_name "${service}-${submodule}")
-
-PROJECT(${fw_name})
+PROJECT(${LEGACY})
 
 SET(CMAKE_INSTALL_PREFIX /usr)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
@@ -17,8 +14,8 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_name} REQUIRED ${dependents})
-FOREACH(flag ${${fw_name}_CFLAGS})
+pkg_check_modules(${LEGACY} REQUIRED ${dependents})
+FOREACH(flag ${${LEGACY}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
@@ -35,17 +32,16 @@ ADD_DEFINITIONS("-DTIZEN_DEBUG")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 
 aux_source_directory(src LEGACY_SOURCES)
-ADD_LIBRARY(${fw_name} SHARED ${LEGACY_SOURCES})
+ADD_LIBRARY(${LEGACY} SHARED ${LEGACY_SOURCES})
 
-SET_TARGET_PROPERTIES(${fw_name}
+SET_TARGET_PROPERTIES(${LEGACY}
      PROPERTIES
      CLEAN_DIRECT_OUTPUT 1
 )
 
+TARGET_LINK_LIBRARIES(${LEGACY} ${${LEGACY}_LDFLAGS})
 
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
-
-INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${LEGACY} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(
         DIRECTORY ${INC_DIR}/ DESTINATION include/media
         FILES_MATCHING
index 0cfb59c..e76da7c 100644 (file)
@@ -3,9 +3,9 @@ SET(service "muse")
 SET(submodule "camera")
 
 SET(dependents "dlog glib-2.0 muse-server mm-common libtbm gstreamer-1.0")
-SET(fw_name "${service}-${submodule}")
+SET(MUSE_MODULE "${service}-${submodule}")
 
-PROJECT(${fw_name})
+PROJECT(${MUSE_MODULE})
 
 SET(CMAKE_INSTALL_PREFIX /usr)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
@@ -14,8 +14,8 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_name} REQUIRED ${dependents})
-FOREACH(flag ${${fw_name}_CFLAGS})
+pkg_check_modules(${MUSE_MODULE} REQUIRED ${dependents})
+FOREACH(flag ${${MUSE_MODULE}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
@@ -33,16 +33,16 @@ ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 
 aux_source_directory(src MUSED_SOURCES)
-ADD_LIBRARY(${fw_name} SHARED ${MUSED_SOURCES})
+ADD_LIBRARY(${MUSE_MODULE} SHARED ${MUSED_SOURCES})
 
-TARGET_LINK_LIBRARIES(${fw_name} legacy-camera ${${fw_name}_LDFLAGS})
+TARGET_LINK_LIBRARIES(${MUSE_MODULE} legacy-camera ${${MUSE_MODULE}_LDFLAGS})
 
-SET_TARGET_PROPERTIES(${fw_name}
+SET_TARGET_PROPERTIES(${MUSE_MODULE}
      PROPERTIES
      CLEAN_DIRECT_OUTPUT 1
 )
 
-INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${MUSE_MODULE} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(
         DIRECTORY ${INC_DIR}/ DESTINATION include/media
         FILES_MATCHING
index 990d716..1b2834f 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __MUSE_CAMERA_H__
 #define __MUSE_CAMERA_H__
 
-#ifdef _cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
index a6c6dad..98958f1 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __MUSE_CAMERA_INTERNAL_H__
 #define __MUSE_CAMERA_INTERNAL_H__
 
-#ifdef _cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
index a525e32..e6205a9 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-camera
 Summary:    A Camera module for muse server
-Version:    0.3.19
+Version:    0.3.21
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
@@ -12,6 +12,9 @@ BuildRequires:  pkgconfig(muse-server)
 BuildRequires:  pkgconfig(mm-camcorder)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(libtbm)
+%if "%{gtests}" == "1"
+BuildRequires:  pkgconfig(gmock)
+%endif
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
@@ -39,7 +42,17 @@ Development related files of a Camera module for muse server.
 export CFLAGS+=" -DTIZEN_DEBUG_ENABLE"
 %endif
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DLIBDIR=%{_libdir}
+%cmake . \
+%if "%{gtests}" == "1"
+       -DENABLE_GTESTS=On\
+%else
+       -DENABLE_GTESTS=Off\
+%endif
+       -DCMAKE_INSTALL_PREFIX=%{_prefix}\
+       -DFULLVER=%{version}\
+       -DMAJORVER=${MAJORVER}\
+       -DLIBDIR=%{_libdir}
+
 
 make %{?jobs:-j%jobs}
 
@@ -59,6 +72,9 @@ rm -rf %{buildroot}
 %license LICENSE.APLv2
 %{_libdir}/liblegacy-camera.so
 %{_libdir}/libmuse-camera.so
+%if "%{gtests}" == "1"
+%{_bindir}/gtests-*
+%endif
 
 %files devel
 %{_includedir}/media/*.h
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..332ef66
--- /dev/null
@@ -0,0 +1,3 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+ADD_SUBDIRECTORY(legacy)
+ADD_SUBDIRECTORY(muse)
diff --git a/unittest/legacy/CMakeLists.txt b/unittest/legacy/CMakeLists.txt
new file mode 100644 (file)
index 0000000..df43688
--- /dev/null
@@ -0,0 +1,22 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(LEGACY "legacy-camera")
+SET(fw_test "gtests-${LEGACY}")
+
+PROJECT(${fw_test} C CXX)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED glib-2.0 gmock mm-camcorder capi-base-common)
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+    MESSAGE(${flag})
+ENDFOREACH()
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -Wall")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy/include)
+INCLUDE_DIRECTORIES(${REQUIRED_PKGS_INCLUDE_DIRS})
+LINK_DIRECTORIES(${REQUIRED_PKGS_LIBRARY_DIRS})
+
+ADD_EXECUTABLE(${fw_test} gtests_legacy_camera.cpp)
+TARGET_LINK_LIBRARIES(${fw_test} ${LEGACY} ${LEGACY_LDFLAGS} ${REQUIRED_PKGS_LDFLAGS})
+INSTALL(TARGETS ${fw_test} DESTINATION bin)
diff --git a/unittest/legacy/gtests_legacy_camera.cpp b/unittest/legacy/gtests_legacy_camera.cpp
new file mode 100644 (file)
index 0000000..e6bed50
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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 "gtests_legacy_camera.h"
+
+using namespace std;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+
+class LegacyCameraTestF : public ::testing::Test {
+       protected:
+               camera_h handle;
+
+               void SetUp() {
+                       int ret = CAMERA_ERROR_NONE;
+
+                       cout << "[SetUp]" << endl;
+
+                       ret = legacy_camera_create(CAMERA_DEVICE_CAMERA0, &handle);
+                       ASSERT_EQ(ret, CAMERA_ERROR_NONE);
+
+                       return;
+               }
+
+               void TearDown() {
+                       cout << "[TearDown]" << endl << endl;
+
+                       if (handle) {
+                               legacy_camera_destroy(handle);
+                               handle = NULL;
+                       }
+
+                       return;
+               }
+};
+
+TEST(LegacyCameraTest, CreateP)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_h new_handle = NULL;
+
+       ret = legacy_camera_create(CAMERA_DEVICE_CAMERA0, &new_handle);
+       ASSERT_EQ(ret, CAMERA_ERROR_NONE);
+
+       legacy_camera_destroy(new_handle);
+}
+
+TEST(LegacyCameraTest, DestroyP)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_h new_handle = NULL;
+
+       ret = legacy_camera_create(CAMERA_DEVICE_CAMERA0, &new_handle);
+       ASSERT_EQ(ret, CAMERA_ERROR_NONE);
+
+       ret = legacy_camera_destroy(new_handle);
+       ASSERT_EQ(ret, CAMERA_ERROR_NONE);
+}
+
+TEST_F(LegacyCameraTestF, SetDisplayP)
+{
+       int ret = CAMERA_ERROR_NONE;
+
+       ret = legacy_camera_set_display(handle, CAMERA_DISPLAY_TYPE_NONE, NULL);
+       ASSERT_EQ(ret, CAMERA_ERROR_NONE);
+}
+
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/legacy/gtests_legacy_camera.h b/unittest/legacy/gtests_legacy_camera.h
new file mode 100644 (file)
index 0000000..3600926
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 __LEGACY_CAMERA_UNITTEST_H__
+#define __LEGACY_CAMERA_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <legacy_camera.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_LEGACY_CAMERA"
+
+#endif /*__LEGACY_CAMERA_UNITTEST_H__*/
diff --git a/unittest/muse/CMakeLists.txt b/unittest/muse/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ee85d08
--- /dev/null
@@ -0,0 +1,22 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(MUSE_MODULE "muse-camera")
+SET(fw_test "gtests-${MUSE_MODULE}")
+
+PROJECT(${fw_test} C CXX)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED glib-2.0 gmock)
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+    MESSAGE(${flag})
+ENDFOREACH()
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -Wall")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/muse/include)
+INCLUDE_DIRECTORIES(${REQUIRED_PKGS_INCLUDE_DIRS})
+LINK_DIRECTORIES(${REQUIRED_PKGS_LIBRARY_DIRS})
+
+ADD_EXECUTABLE(${fw_test} gtests_muse_camera.cpp)
+TARGET_LINK_LIBRARIES(${fw_test} ${MUSE_MODULE} ${MUSE_MODULE_LDFLAGS} ${REQUIRED_PKGS_LDFLAGS})
+INSTALL(TARGETS ${fw_test} DESTINATION bin)
diff --git a/unittest/muse/gtests_muse_camera.cpp b/unittest/muse/gtests_muse_camera.cpp
new file mode 100644 (file)
index 0000000..33e189e
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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 "gtests_muse_camera.h"
+
+using namespace std;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+
+class MuseCameraTestF : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       cout << "[SetUp]" << endl;
+                       return;
+               }
+
+               void TearDown() {
+                       cout << "[TearDown]" << endl << endl;
+                       return;
+               }
+};
+
+TEST_F(MuseCameraTestF, CreateP)
+{
+       int ret = 0;
+
+       ASSERT_EQ(ret, 0);
+}
+
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/muse/gtests_muse_camera.h b/unittest/muse/gtests_muse_camera.h
new file mode 100644 (file)
index 0000000..e2770ef
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 __MUSE_CAMERA_UNITTEST_H__
+#define __MUSE_CAMERA_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <muse_camera.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_MUSE_CAMERA"
+
+#endif /*__MUSE_CAMERA_UNITTEST_H__*/