Added skeleton of unittest 06/275406/9 accepted/tizen/unified/20220528.144349 submit/tizen/20220526.072840
authordesperadok <heechul.jeon@samsung.com>
Tue, 24 May 2022 10:20:21 +0000 (19:20 +0900)
committerdesperadok <heechul.jeon@samsung.com>
Thu, 26 May 2022 07:10:54 +0000 (16:10 +0900)
Change-Id: Iede6f9444ce2b09e1f7d1a6af29bbf6e7f365349

CMakeLists.txt
packaging/capi-media-tool.spec
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/media_tool_gtest.cpp [new file with mode: 0644]
unittest/media_tool_gtest.h [new file with mode: 0644]
unittest/unittest.cpp [new file with mode: 0644]
unittest/unittest.h [new file with mode: 0644]

index ce80c735541f24e847a21e87e7e5f843bab10cdc..37f7c9c827675d0dbe6b56b53514625c547d5213 100644 (file)
@@ -22,6 +22,10 @@ ENDFOREACH(flag)
 SET(CMAKE_C_FLAGS "-I./include -I./include/headers ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -w")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 
+IF(MEDIA_TOOL_GTESTS_BUILD)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
+ENDIF(MEDIA_TOOL_GTESTS_BUILD)
+
 IF("${ARCH}" STREQUAL "arm")
     ADD_DEFINITIONS("-DTARGET")
 ENDIF("${ARCH}" STREQUAL "arm")
@@ -66,6 +70,9 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTAL
 IF(TIZEN_FEATURE_TESTSUITE)
 ADD_SUBDIRECTORY(test)
 ENDIF(TIZEN_FEATURE_TESTSUITE)
+IF(MEDIA_TOOL_GTESTS_BUILD)
+ADD_SUBDIRECTORY(unittest)
+ENDIF(MEDIA_TOOL_GTESTS_BUILD)
 
 IF(UNIX)
 
@@ -97,4 +104,3 @@ ADD_CUSTOM_COMMAND(
 )
 
 ENDIF(UNIX)
-
index 8ad7a6440ea34e504a0316e418255e7529cd9908..ff60f70fae3f01a8b44b3b371277c5d2482d6948 100644 (file)
@@ -1,7 +1,7 @@
 Name:       capi-media-tool
 Summary:    A Core API media tool library in Tizen Native API
-Version:    0.1.52
-Release:    1
+Version:    0.1.53
+Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
@@ -10,6 +10,10 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(libtbm)
+%if "%{gtests}" == "1"
+BuildRequires:  pkgconfig(mm-common)
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 A Core API media tool library in Tizen Native API
@@ -52,7 +56,10 @@ export LDFLAGS+=" -lgcov"
 export CFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\""
 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+%if "%{gtests}" == "1"
+       -DMEDIA_TOOL_GTESTS_BUILD=On \
+%endif
 %if "%{tizen_profile_name}" != "tv"
        -DTIZEN_FEATURE_TESTSUITE=On
 %else
@@ -101,4 +108,3 @@ find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';'
 %files gcov
 %{_datadir}/gcov/obj/*
 %endif
-
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..dd479c7
--- /dev/null
@@ -0,0 +1,19 @@
+
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+SET(GTEST_MEDIA_TOOL "gtest-media-tool")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpie")
+
+FILE(GLOB GTEST_MEDIA_TOOL_SRCS *.cpp)
+
+PKG_CHECK_MODULES(GTEST_PKGS REQUIRED glib-2.0 dlog mm-common gmock)
+INCLUDE_DIRECTORIES(${GTEST_PKGS_INCLUDE_DIRS})
+LINK_DIRECTORIES(${GTEST_PKGS_LIBRARY_DIRS})
+
+ADD_EXECUTABLE(${GTEST_MEDIA_TOOL} ${GTEST_MEDIA_TOOL_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_MEDIA_TOOL} ${fw_name} ${GTEST_PKGS_LDFLAGS} -lgcov)
+
+INSTALL(TARGETS ${GTEST_MEDIA_TOOL} DESTINATION ${BINDIR})
diff --git a/unittest/media_tool_gtest.cpp b/unittest/media_tool_gtest.cpp
new file mode 100644 (file)
index 0000000..77783b0
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2022 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_tool_gtest.h"
diff --git a/unittest/media_tool_gtest.h b/unittest/media_tool_gtest.h
new file mode 100644 (file)
index 0000000..51bf85b
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2022 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 __MEDIATOOL_GTEST_H__
+#define __MEDIATOOL_GTEST_H__
+
+#include "unittest.h"
+
+#endif /*__MEDIATOOL_GTEST_H__*/
diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp
new file mode 100644 (file)
index 0000000..3cdc49c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2022 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_tool_gtest.h"
+#include "media_format.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class MediaToolTest : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       std::cout << "SetUp()" << std::endl;
+               }
+
+               void TearDown() {
+                       std::cout << "TearDown()" << std::endl;
+               }
+};
+
+TEST(MediaToolTest, media_tool_gtest_create)
+{
+       media_format_h fmt;
+       int ret = media_format_create(&fmt);
+       ASSERT_EQ(ret, MEDIA_FORMAT_ERROR_NONE);
+
+       media_format_unref(fmt);
+}
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/unittest.h b/unittest/unittest.h
new file mode 100644 (file)
index 0000000..04105f1
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2022 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 __UNITTEST_H__
+#define __UNITTEST_H__
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <iostream>
+#include <dlog.h>
+#include <mm_error.h>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#endif /*__UNITTEST_H__*/