Adding initial structure for unittest 93/193493/5
authorjiyong.min <jiyong.min@samsung.com>
Wed, 21 Nov 2018 08:00:08 +0000 (17:00 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 22 Nov 2018 22:32:35 +0000 (07:32 +0900)
- It has only one testcases for libmedia_utils of unittest
- It would be enabled by gtest build with '--define "gtests 1"'
- Two test contents would be copyied to '/usr/bin' directory

Change-Id: I6988de63bfd3c2cea7aa8518bf83d700d09d38cd

Makefile.am [changed mode: 0755->0644]
configure.ac [changed mode: 0755->0644]
packaging/libmm-fileinfo.spec [changed mode: 0755->0644]
unittest/Makefile.am [new file with mode: 0644]
unittest/libmm-fileinfo-unittest.mp3 [new file with mode: 0644]
unittest/libmm-fileinfo-unittest.mp4 [new file with mode: 0644]
unittest/libmm_fileinfo_unittest.cpp [new file with mode: 0755]
unittest/libmm_fileinfo_unittest.h [new file with mode: 0644]

old mode 100755 (executable)
new mode 100644 (file)
index 07c0278..32f4bb2
@@ -5,6 +5,9 @@ SUBDIRS = utils \
          formats \
          . \
          tests
+if IS_TESTS
+SUBDIRS += unittest
+endif
 
 lib_LTLIBRARIES = libmmffile.la
 
old mode 100755 (executable)
new mode 100644 (file)
index db9a9a6..ef17980
@@ -13,6 +13,7 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
 AM_PROG_AR
 AC_PROG_CC
 AM_PROG_CC_C_O
+AC_PROG_CXX
 AC_PROG_LIBTOOL
 
 # Checks for libraries.
@@ -95,6 +96,24 @@ PKG_CHECK_MODULES(VCONF, vconf)
 AC_SUBST(VCONF_CFLAGS)
 AC_SUBST(VCONF_LIBS)
 
+# for gtests
+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)
+])
+
 dnl use dyn --------------------------------------------------------------------------
 AC_ARG_ENABLE(dyn, AC_HELP_STRING([--enable-dyn], [using dyn]),
 [
@@ -164,6 +183,7 @@ AC_CONFIG_FILES([Makefile
                  formats/ffmpeg/Makefile
                  utils/Makefile
                  tests/Makefile
+                unittest/Makefile
                 mm-fileinfo.pc
 ])
 AC_OUTPUT
old mode 100755 (executable)
new mode 100644 (file)
index 632e056..a4d00c1
@@ -1,7 +1,7 @@
 Name:      libmm-fileinfo
 Summary:    Media Fileinfo
 Version:    0.6.75
-Release:    0
+Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
@@ -19,6 +19,9 @@ BuildRequires: pkgconfig(libavutil)
 BuildRequires: pkgconfig(libavformat)
 BuildRequires: pkgconfig(icu-i18n)
 BuildRequires: pkgconfig(vconf)
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 Multimedia Framework FileInfo Library
@@ -51,7 +54,12 @@ export CFLAGS+=" -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fgnu89-inlin
 ./autogen.sh
 
 %reconfigure \
-CFLAGS="${CFLAGS} -D_MM_PROJECT_FLOATER -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" " LDFLAGS="${LDFLAGS}" ./configure --disable-testmode --disable-dump --enable-dyn --disable-iommap --prefix=/usr --disable-gtk
+CFLAGS="${CFLAGS} -D_MM_PROJECT_FLOATER -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" " LDFLAGS="${LDFLAGS}" \
+./configure --disable-testmode --disable-dump --enable-dyn --disable-iommap --prefix=/usr \
+%if 0%{?gtests:1}
+       --enable-tests \
+%endif
+       --disable-gtk
 
 %__make
 
@@ -60,6 +68,9 @@ CFLAGS="${CFLAGS} -D_MM_PROJECT_FLOATER -DEXPORT_API=\"__attribute__((visibility
 
 mkdir -p %{buildroot}%{_sysconfdir}/multimedia
 cp -rf %{_builddir}/%{name}-%{version}/mm_file_config.ini %{buildroot}%{_sysconfdir}/multimedia/mm_file_config.ini
+mkdir -p %{buildroot}%{_bindir}
+cp -rf %{_builddir}/%{name}-%{version}/unittest/*.mp4 %{buildroot}%{_bindir}/
+cp -rf %{_builddir}/%{name}-%{version}/unittest/*.mp3 %{buildroot}%{_bindir}/
 
 %post -p /sbin/ldconfig
 
@@ -76,6 +87,10 @@ cp -rf %{_builddir}/%{name}-%{version}/mm_file_config.ini %{buildroot}%{_sysconf
 %{_libdir}/libmmfile_formats.so
 %{_libdir}/libmmfile_utils.so
 %{_sysconfdir}/multimedia/mm_file_config.ini
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%{_bindir}/libmm-fileinfo-unittest*
+%endif
 %license LICENSE.APLv2.0
 
 %files tool
diff --git a/unittest/Makefile.am b/unittest/Makefile.am
new file mode 100644 (file)
index 0000000..b82ccba
--- /dev/null
@@ -0,0 +1,17 @@
+# Unit tests
+bin_PROGRAMS = gtest-libmm-fileinfo
+
+gtest_libmm_fileinfo_SOURCES  = libmm_fileinfo_unittest.cpp
+
+gtest_libmm_fileinfo_CXXFLAGS =  -I$(top_srcdir)/include \
+                       $(MMCOMMON_CFLAGS) \
+                       $(GLIB_CFLAGS) \
+                       $(GTESTS_CFLAGS)
+
+gtest_libmm_fileinfo_DEPENDENCIES = $(top_srcdir)/libmmffile.la
+
+gtest_libmm_fileinfo_LDADD = \
+                       $(MMCOMMON_LIBS) \
+                       $(GLIB_LIBS) \
+                       $(GTESTS_LIBS) \
+                       $(top_srcdir)/libmmffile.la
diff --git a/unittest/libmm-fileinfo-unittest.mp3 b/unittest/libmm-fileinfo-unittest.mp3
new file mode 100644 (file)
index 0000000..8db1dfe
Binary files /dev/null and b/unittest/libmm-fileinfo-unittest.mp3 differ
diff --git a/unittest/libmm-fileinfo-unittest.mp4 b/unittest/libmm-fileinfo-unittest.mp4
new file mode 100644 (file)
index 0000000..d6e1050
Binary files /dev/null and b/unittest/libmm-fileinfo-unittest.mp4 differ
diff --git a/unittest/libmm_fileinfo_unittest.cpp b/unittest/libmm_fileinfo_unittest.cpp
new file mode 100755 (executable)
index 0000000..7fd5319
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * 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_fileinfo_unittest.h"
+#include "mm_file.h"
+
+#define GTEST_VIDEO_FILE_PATH          "/usr/bin/libmm-fileinfo-unittest.mp4"
+#define GTEST_SOUND_FILE_PATH          "/usr/bin/libmm-fileinfo-unittest.mp3"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_fileinfo_Test : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       std::cout << "SetUp()" << std::endl;
+               }
+
+               void TearDown() {
+                       std::cout << "TearDown()" << std::endl;
+               }
+};
+
+TEST(libmm_fileinfo_Test, mm_file_create_content_attrs_p)
+{
+       int ret = FILEINFO_ERROR_NONE;
+       MMHandleType content_attrs;
+
+       ret = mm_file_create_content_attrs(&content_attrs, GTEST_VIDEO_FILE_PATH);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+
+       ret = mm_file_destroy_content_attrs(content_attrs);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+}
+
+TEST(libmm_fileinfo_Test, mm_file_get_content_attrs_p)
+{
+       int ret = FILEINFO_ERROR_NONE;
+       MMHandleType content_attrs;
+       char *err_attr_name = NULL;
+       int p = 0;
+
+       ret = mm_file_create_content_attrs(&content_attrs, GTEST_VIDEO_FILE_PATH);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+
+       ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_DURATION, &p, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_EQ(p, 11883);
+
+       ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &p, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_EQ(p, 909428);
+
+       ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_FPS, &p, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_EQ(p, 30);
+
+       ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &p, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_EQ(p, 320);
+
+       ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &p, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_EQ(p, 240);
+
+       ret = mm_file_destroy_content_attrs(content_attrs);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+}
+
+TEST(libmm_fileinfo_Test, mm_file_create_tag_attrs_p)
+{
+       int ret = FILEINFO_ERROR_NONE;
+       MMHandleType tag_attrs;
+
+       ret = mm_file_create_tag_attrs(&tag_attrs, GTEST_VIDEO_FILE_PATH);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+
+       ret = mm_file_destroy_tag_attrs(tag_attrs);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+}
+
+TEST(libmm_fileinfo_Test, mm_file_get_tag_attrs_p)
+{
+       int ret = FILEINFO_ERROR_NONE;
+       MMHandleType tag_attrs;
+       char *err_attr_name = NULL;
+       char *p = NULL;
+       unsigned int size = 0;
+
+       ret = mm_file_create_tag_attrs(&tag_attrs, GTEST_VIDEO_FILE_PATH);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+
+       ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_STREQ(p, "Test");
+
+       ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_STREQ(p, "Test");
+
+       ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_STREQ(p, "Test");
+
+       ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+       EXPECT_STREQ(p, "Test");
+
+       ret = mm_file_destroy_tag_attrs(tag_attrs);
+       EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
+}
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/libmm_fileinfo_unittest.h b/unittest/libmm_fileinfo_unittest.h
new file mode 100644 (file)
index 0000000..720d0cd
--- /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_FILEINFO_UNITTEST_H__
+#define __LIB_MM_FILEINFO_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_LIBMM_FILEINFO"
+
+#endif /*__LIB_MM_FILEINFO_UNITTEST_H__*/