From 5becc5977057199a45d2ad9fc324156137aef302 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 28 Nov 2018 18:05:46 +0900 Subject: [PATCH] Add unit test [Version] 0.0.4 [Profile] Common [Issue Type] Update [Dependency module] N/A [Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-unified_20181126.2] Change-Id: I7f8c79b869ff37d95996eb61366a33fba328aab2 Signed-off-by: Jeongmo Yang --- Makefile.am | 4 +++ configure.ac | 20 +++++++++++ packaging/libmm-display.spec | 11 +++++- unittest/Makefile.am | 18 ++++++++++ unittest/gtests_libmm_display.cpp | 71 +++++++++++++++++++++++++++++++++++++++ unittest/gtests_libmm_display.h | 27 +++++++++++++++ 6 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 unittest/Makefile.am create mode 100644 unittest/gtests_libmm_display.cpp create mode 100644 unittest/gtests_libmm_display.h diff --git a/Makefile.am b/Makefile.am index 0d10595..4667b84 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,10 @@ ACLOCAL_AMFLAGS='-I m4' SUBDIRS = src +if GTESTS +SUBDIRS += unittest +endif + pcfiles = mm-display-interface.pc pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = $(pcfiles) diff --git a/configure.ac b/configure.ac index 838d66e..c72f32a 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,8 @@ AC_HEADER_STDC AC_HEADER_TIME AC_PROG_GCC_TRADITIONAL AC_PROG_LIBTOOL +AC_PROG_CXX +AC_SUBST(GCC_CXXFLAGS) # Checks for libraries. PKG_CHECK_MODULES(GLIB, glib-2.0) @@ -67,6 +69,7 @@ PKG_CHECK_MODULES(TIZEN_EXTENSION_CLIENT, tizen-extension-client) AC_SUBST(TIZEN_EXTENSION_CLIENT_CFLAGS) AC_SUBST(TIZEN_EXTENSION_CLIENT_LIBS) +# Evas Renderer AC_ARG_ENABLE(evas-renderer, AC_HELP_STRING([--enable-evas-renderer], [enable evas renderer]), [ case "${enableval}" in @@ -82,6 +85,22 @@ AC_SUBST(EVAS_RENDERER_LIBS) fi AM_CONDITIONAL([TIZEN_FEATURE_EVAS_RENDERER], [test "x$TIZEN_FEATURE_EVAS_RENDERER" = "xyes"]) +# GTESTS +AC_ARG_ENABLE(gtests, AC_HELP_STRING([--enable-gtests], [enable gtests]), +[ + case "${enableval}" in + yes) GTESTS=yes ;; + no) GTESTS=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-gtests) ;; + esac +],[GTESTS=no]) +if test "x$GTESTS" = "xyes"; then +PKG_CHECK_MODULES(GMOCK, gmock) +AC_SUBST(GMOCK_CFLAGS) +AC_SUBST(GMOCK_LIBS) +fi +AM_CONDITIONAL([GTESTS], [test "x$GTESTS" = "xyes"]) + # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([fcntl.h memory.h stdlib.h string.h sys/time.h unistd.h]) @@ -102,6 +121,7 @@ AC_CHECK_FUNCS([memset select]) AC_CONFIG_FILES([ Makefile src/Makefile +unittest/Makefile mm-display-interface.pc ]) AC_OUTPUT diff --git a/packaging/libmm-display.spec b/packaging/libmm-display.spec index 3b74978..925602c 100644 --- a/packaging/libmm-display.spec +++ b/packaging/libmm-display.spec @@ -1,6 +1,6 @@ Name: libmm-display Summary: Multimedia framework display library -Version: 0.0.3 +Version: 0.0.4 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 @@ -21,6 +21,9 @@ BuildRequires: pkgconfig(tizen-extension-client) %if "%{tizen_profile_name}" != "tv" BuildRequires: pkgconfig(mm-evas-renderer) %endif +%if "%{gtests}" == "1" +BuildRequires: pkgconfig(gmock) +%endif %description Multimedia framework display library. @@ -56,6 +59,9 @@ export CFLAGS+=" -D_LARGEFILE64_SOURCE -DMM_DISPLAY_LIBDIR=\\\"%{_libdir}\\\" -D %if "%{tizen_profile_name}" != "tv" --enable-evas-renderer \ %endif +%if "%{gtests}" == "1" + --enable-gtests \ +%endif --disable-static make %{?jobs:-j%jobs} @@ -73,6 +79,9 @@ make %{?jobs:-j%jobs} %license LICENSE.APLv2 %defattr(-,root,root,-) %{_libdir}/libmmfdisplay.so* +%if "%{gtests}" == "1" +%{_bindir}/gtests-libmm-display +%endif %files interface %manifest libmm-display-interface.manifest diff --git a/unittest/Makefile.am b/unittest/Makefile.am new file mode 100644 index 0000000..8c3fb84 --- /dev/null +++ b/unittest/Makefile.am @@ -0,0 +1,18 @@ +bin_PROGRAMS = gtests-libmm-display + +gtests_libmm_display_SOURCES = gtests_libmm_display.cpp + +gtests_libmm_display_CXXFLAGS = \ + -I$(top_srcdir)/src/include\ + $(MM_COMMON_CFLAGS)\ + $(MEDIA_TOOL_CFLAGS)\ + $(GMOCK_CFLAGS) + +gtests_libmm_display_DEPENDENCIES = \ + $(top_srcdir)/src/libmmfdisplay.la + +gtests_libmm_display_LDADD = \ + $(GMOCK_LIBS)\ + $(MEDIA_TOOL_LIBS)\ + $(top_srcdir)/src/libmmfdisplay.la + diff --git a/unittest/gtests_libmm_display.cpp b/unittest/gtests_libmm_display.cpp new file mode 100644 index 0000000..95f0328 --- /dev/null +++ b/unittest/gtests_libmm_display.cpp @@ -0,0 +1,71 @@ +/* + * 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 +#include "gtests_libmm_display.h" + +using namespace std; +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + + + +class MMDisplayTestF : public ::testing::Test { + protected: + mm_display_h handle; + + void SetUp() { + cout << "[SetUp]" << endl; + ASSERT_EQ(mm_display_init(&handle), MM_ERROR_NONE); + return; + } + + void TearDown() { + cout << "[TearDown]" << endl << endl; + if (handle) { + mm_display_deinit(handle); + handle = NULL; + } + return; + } +}; + +TEST(MMDisplayTest, InitP) +{ + mm_display_h new_handle = NULL; + + ASSERT_EQ(mm_display_init(&new_handle), MM_ERROR_NONE); + + mm_display_deinit(new_handle); +} + +TEST(MMDisplayTest, DeinitP) +{ + mm_display_h new_handle = NULL; + + ASSERT_EQ(mm_display_init(&new_handle), MM_ERROR_NONE); + + ASSERT_EQ(mm_display_deinit(new_handle), MM_ERROR_NONE); +} + + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/unittest/gtests_libmm_display.h b/unittest/gtests_libmm_display.h new file mode 100644 index 0000000..4a51dec --- /dev/null +++ b/unittest/gtests_libmm_display.h @@ -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 __MM_DISPLAY_UNITTEST_H__ +#define __MM_DISPLAY_UNITTEST_H__ + +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_MM_DISPLAY" + +#endif /*__MM_DISPLAY_UNITTEST_H__*/ -- 2.7.4