diff options
author | jiyong.min <jiyong.min@samsung.com> | 2018-11-21 17:00:08 +0900 |
---|---|---|
committer | jiyong.min <jiyong.min@samsung.com> | 2018-11-23 07:32:35 +0900 |
commit | 26c43b899bdda098768019cfdf1fd8171c203d6d (patch) | |
tree | 7453785631f45d6868569dfa0216f46af2c6bcc0 | |
parent | f894c38b126cbcd69b0810889ac8733b3ce3cd45 (diff) | |
download | libmm-fileinfo-26c43b899bdda098768019cfdf1fd8171c203d6d.tar.gz libmm-fileinfo-26c43b899bdda098768019cfdf1fd8171c203d6d.tar.bz2 libmm-fileinfo-26c43b899bdda098768019cfdf1fd8171c203d6d.zip |
Adding initial structure for unittest
- 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
-rw-r--r--[-rwxr-xr-x] | Makefile.am | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | configure.ac | 20 | ||||
-rw-r--r--[-rwxr-xr-x] | packaging/libmm-fileinfo.spec | 19 | ||||
-rw-r--r-- | unittest/Makefile.am | 17 | ||||
-rw-r--r-- | unittest/libmm-fileinfo-unittest.mp3 | bin | 0 -> 192404 bytes | |||
-rw-r--r-- | unittest/libmm-fileinfo-unittest.mp4 | bin | 0 -> 1427695 bytes | |||
-rwxr-xr-x | unittest/libmm_fileinfo_unittest.cpp | 132 | ||||
-rw-r--r-- | unittest/libmm_fileinfo_unittest.h | 26 |
8 files changed, 215 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index 07c0278..32f4bb2 100755..100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,6 +5,9 @@ SUBDIRS = utils \ formats \ . \ tests +if IS_TESTS +SUBDIRS += unittest +endif lib_LTLIBRARIES = libmmffile.la diff --git a/configure.ac b/configure.ac index db9a9a6..ef17980 100755..100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/packaging/libmm-fileinfo.spec b/packaging/libmm-fileinfo.spec index 632e056..a4d00c1 100755..100644 --- a/packaging/libmm-fileinfo.spec +++ b/packaging/libmm-fileinfo.spec @@ -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 index 0000000..b82ccba --- /dev/null +++ b/unittest/Makefile.am @@ -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 Binary files differnew file mode 100644 index 0000000..8db1dfe --- /dev/null +++ b/unittest/libmm-fileinfo-unittest.mp3 diff --git a/unittest/libmm-fileinfo-unittest.mp4 b/unittest/libmm-fileinfo-unittest.mp4 Binary files differnew file mode 100644 index 0000000..d6e1050 --- /dev/null +++ b/unittest/libmm-fileinfo-unittest.mp4 diff --git a/unittest/libmm_fileinfo_unittest.cpp b/unittest/libmm_fileinfo_unittest.cpp new file mode 100755 index 0000000..7fd5319 --- /dev/null +++ b/unittest/libmm_fileinfo_unittest.cpp @@ -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 index 0000000..720d0cd --- /dev/null +++ b/unittest/libmm_fileinfo_unittest.h @@ -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__*/ |