Adding initial structure for unittest 53/190453/6
authorSeokHoon Lee <andy.shlee@samsung.com>
Tue, 2 Oct 2018 07:04:43 +0000 (16:04 +0900)
committerSeokHoon Lee <andy.shlee@samsung.com>
Thu, 4 Oct 2018 03:55:26 +0000 (12:55 +0900)
- It has only one testcases for skeleton of unittest
- It would be enabled by gtest build with '--define "gtests 1"

Signed-off-by: SeokHoon Lee <andy.shlee@samsung.com>
Change-Id: Ic0753be99906b17a7edc4bd20a8cdb4471003112

Makefile.am
configure.ac
packaging/libmm-streamrecorder.spec
unittest/Makefile.am [new file with mode: 0644]
unittest/libmm_streamrecorder_unittest.cpp [new file with mode: 0644]
unittest/libmm_streamrecorder_unittest.h [new file with mode: 0644]

index 3839fb0c7afaf41363df3748b67fedeab8fcf34b..a4ced028503e9887f00d048fc286e1c62a4c0467 100644 (file)
@@ -1,6 +1,9 @@
 ACLOCAL_AMFLAGS='-I m4'
 
 SUBDIRS = src test
+if IS_TESTS
+SUBDIRS += unittest
+endif
 
 pcfiles = mm-streamrecorder.pc
 pkgconfigdir = $(libdir)/pkgconfig
index 2de17cc411437249cf6874f449853cbfc085e1be..b07c4c772b31a37b15450dc9a620bb0e480f5556 100644 (file)
@@ -10,6 +10,7 @@ AM_PROG_AR
 
 # Checks for programs.
 AC_PROG_CC
+AC_PROG_CXX
 AC_C_CONST
 dnl AC_FUNC_MALLOC
 AC_FUNC_MMAP
@@ -22,6 +23,7 @@ AC_HEADER_STDC
 AC_HEADER_TIME
 AC_PROG_GCC_TRADITIONAL
 AC_PROG_LIBTOOL
+AC_SUBST(GCC_CXXFLAGS)
 
 # Checks for libraries.
 PKG_CHECK_MODULES(GST, gstreamer-1.0 >= 1.2.0)
@@ -56,6 +58,23 @@ PKG_CHECK_MODULES(INIPARSER, iniparser)
 AC_SUBST(INIPARSER_CFLAGS)
 AC_SUBST(INIPARSER_LIBS)
 
+AC_ARG_ENABLE(tests, AC_HELP_STRING([--enable-tests], [unittest build]),
+     [
+        case "${enableval}" in
+        yes) IS_TESTS=yes ;;
+        no)  IS_TESTS=no ;;
+          *)   AC_MSG_ERROR(bad value ${enableval} for --enable-tests) ;;
+        esac
+    ],
+[IS_TESTS=no])
+AM_CONDITIONAL([IS_TESTS], [test "x$IS_TESTS" = "xyes"])
+
+AS_IF([test "x$enable_tests" = "xyes"], [
+    PKG_CHECK_MODULES(GTESTS, gmock)
+    AC_SUBST(GTESTS_CFLAGS)
+    AC_SUBST(GTESTS_LIBS)
+])
+
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS([fcntl.h memory.h stdlib.h string.h sys/time.h unistd.h])
@@ -77,6 +96,7 @@ AC_CONFIG_FILES([
 Makefile
 src/Makefile
 test/Makefile
+unittest/Makefile
 mm-streamrecorder.pc
 ])
 AC_OUTPUT
index 0cd8caedcf30b229682fbb75ab7e01eed0e49447..9b15991784dc1729112fd6d599e6d1c0470a6dc8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-streamrecorder
 Summary:    Media Stream Recorder library
-Version:    0.0.19
+Version:    0.0.20
 Release:    0
 Group:      Multimedia/Other
 License:    Apache-2.0
@@ -13,6 +13,9 @@ BuildRequires:  pkgconfig(gstreamer-base-1.0)
 BuildRequires:  pkgconfig(gstreamer-video-1.0)
 BuildRequires:  pkgconfig(gstreamer-app-1.0)
 BuildRequires:  pkgconfig(iniparser)
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 This library is for making video/audio files with gstreamer
@@ -37,7 +40,12 @@ Media Stream Recorder development library
 export CFLAGS+=" -Wall -Wextra -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable"
 export CFLAGS+=" -DSYSCONFDIR=\\\"%{_sysconfdir}\\\""
 ./autogen.sh
-%configure --disable-static
+%configure \
+%if 0%{?gtests:1}
+--enable-tests \
+%endif
+--disable-static
+
 make %{?jobs:-j%jobs}
 
 %install
@@ -58,6 +66,9 @@ rm -rf %{buildroot}
 %defattr(-,root,root,-)
 %{_bindir}/*
 %{_libdir}/*.so.*
+%if 0%{?gtests:1}
+%{_bindir}/gtest-libmm-streamrecorder
+%endif
 
 
 %files devel
diff --git a/unittest/Makefile.am b/unittest/Makefile.am
new file mode 100644 (file)
index 0000000..26acced
--- /dev/null
@@ -0,0 +1,12 @@
+bin_PROGRAMS = gtest-libmm-streamrecorder
+
+gtest_libmm_streamrecorder_SOURCES = libmm_streamrecorder_unittest.cpp
+
+gtest_libmm_streamrecorder_CXXFLAGS = -I$(top_srcdir)/src/include \
+                       $(GTESTS_CFLAGS)
+
+gtest_libmm_streamrecorder_DEPENDENCIES = $(top_srcdir)/src/libmmfstreamrecorder.la
+
+gtest_libmm_streamrecorder_LDADD = \
+                       $(GTESTS_LIBS) \
+                       $(top_srcdir)/src/libmmfstreamrecorder.la
diff --git a/unittest/libmm_streamrecorder_unittest.cpp b/unittest/libmm_streamrecorder_unittest.cpp
new file mode 100644 (file)
index 0000000..eb41236
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 "libmm_streamrecorder_unittest.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_streamrecorder_Test : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       std::cout << "SetUp()" << std::endl;
+               }
+
+               void TearDown() {
+                       std::cout << "TearDown()" << std::endl;
+               }
+};
+
+TEST(libmm_streamrecorderTest, __srecorder_get_fourcc_p1)
+{
+       EXPECT_EQ(1, 1);
+}
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/libmm_streamrecorder_unittest.h b/unittest/libmm_streamrecorder_unittest.h
new file mode 100644 (file)
index 0000000..bdc7956
--- /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 __LIB_MM_STREAMRECORDER_UNITTEST_H__
+#define __LIB_MM_STREAMRECORDER_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_LIBMM_STREAMRECORDER"
+
+#endif /*__LIB_MM_STREAMRECORDER_UNITTEST_H__*/