Adding initial structure for internal unittest 66/189766/17 accepted/tizen/unified/20180927.174426 submit/tizen/20180921.070636
authorheechul.jeon <heechul.jeon@samsung.com>
Thu, 20 Sep 2018 08:56:24 +0000 (17:56 +0900)
committerHeechul Jeon <heechul.jeon@samsung.com>
Fri, 21 Sep 2018 06:58:43 +0000 (06:58 +0000)
- 'using' member from mm_player_video_bo_info_t has replaced with 'used' as 'using' is reserved keyword on c++
- static constraints on __mmplayer_parse_profile() has removed for calling it from unittest
- initialy, it has only two testcases with __parse_profile
- Enabling gtest build with '--define "gtests 1"

Change-Id: I00414f1bf3a6d80cf312ff516cabc4df270b9509

Makefile.am
configure.ac
packaging/libmm-player.spec
src/include/mm_player_priv.h
src/mm_player_priv.c
unittest/Makefile.am [new file with mode: 0644]
unittest/libmm-player_internal.cpp [new file with mode: 0644]
unittest/libmm-player_internal.h [new file with mode: 0644]

index 7ee8b62..9be5eca 100644 (file)
@@ -1,5 +1,8 @@
 ACLOCAL_AMFLAGS='-I m4'
 SUBDIRS = src
+if IS_TESTS
+SUBDIRS += unittest
+endif
 
 pcfiles = mm-player.pc
 pkgconfigdir = $(libdir)/pkgconfig
index 003ac5d..4642268 100644 (file)
@@ -10,6 +10,7 @@ AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
 # Checks for programs.
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
 AC_PROG_CC
+AC_PROG_CXX
 
 AC_PROG_LIBTOOL
 
@@ -34,6 +35,7 @@ AC_HEADER_STDBOOL
 AC_C_CONST
 AC_TYPE_INT64_T
 AC_HEADER_TIME
+AC_SUBST(GCC_CXXFLAGS)
 
 # Checks for library functions.
 AC_FUNC_MALLOC
@@ -119,6 +121,23 @@ PKG_CHECK_MODULES(TBM, libtbm)
 AC_SUBST(TBM_CFLAGS)
 AC_SUBST(TBM_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)
+])
+
 AC_ARG_ENABLE(sdk, AC_HELP_STRING([--enable-sdk], [sdk build]),
         [
                case "${enableval}" in
@@ -132,6 +151,7 @@ AM_CONDITIONAL([IS_SDK], [test "x$IS_SDK" = "xyes"])
 
 AC_CONFIG_FILES([Makefile
                 src/Makefile
+                unittest/Makefile
                 mm-player.pc
 ])
 AC_OUTPUT
index 20158c6..7810ea2 100644 (file)
@@ -26,6 +26,9 @@ BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(capi-media-sound-manager)
 BuildRequires:  pkgconfig(libtbm)
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 Multimedia Framework Player Library files.
@@ -51,8 +54,11 @@ export CFLAGS+=" -DHAVE_X11"
 LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--hash-style=both -Wl,--as-needed"; export LDFLAGS
 ./autogen.sh
 # always enable sdk build. This option should go away
-CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --enable-sdk --prefix=%{_prefix} --disable-static
+#CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --enable-sdk --prefix=%{_prefix} --disable-static
 %configure \
+%if 0%{?gtests:1}
+--enable-tests \
+%endif
 --disable-static \
 --enable-wayland
 
@@ -71,7 +77,9 @@ make %{?jobs:-j%jobs}
 %license LICENSE.Apache-2.0
 %defattr(-,root,root,-)
 %{_libdir}/*.so.*
-
+%if 0%{?gtests:1}
+%{_bindir}/gtest_libmm_player
+%endif
 
 %files devel
 %manifest %{name}.manifest
index 3cc5069..c767fb1 100644 (file)
@@ -505,7 +505,7 @@ typedef struct {
  * @since_tizen 3.0
  */
 typedef struct {
-       gboolean using;
+       gboolean used;
        void* bo;
 } mm_player_video_bo_info_t;
 
@@ -971,6 +971,8 @@ GstElement* __mmplayer_create_decodebin(mm_player_t* player);
 int __mmplayer_gst_element_add_bucket_to_bin(GstBin* bin, GList* element_bucket);
 int __mmplayer_gst_element_link_bucket(GList* element_bucket);
 void __mmplayer_typefind_have_type(GstElement *tf, guint probability, GstCaps *caps, gpointer data);
+int __mmplayer_parse_profile(const char *uri, void *param, MMPlayerParseProfile* data);
+
 
 #ifdef __cplusplus
        }
index 8a3c025..d4ad871 100644 (file)
@@ -3562,7 +3562,7 @@ int _mmplayer_video_stream_release_bo(mm_player_t* player, void* bo)
                for (l = g_list_first(player->video_bo_list); l; l = g_list_next(l)) {
                        mm_player_video_bo_info_t* tmp = (mm_player_video_bo_info_t *)l->data;
                        if (tmp && tmp->bo == bo) {
-                               tmp->using = FALSE;
+                               tmp->used = FALSE;
                                LOGD("release bo %p", bo);
                                tbm_bo_unref(tmp->bo);
                                MMPLAYER_VIDEO_BO_UNLOCK(player);
@@ -3650,7 +3650,7 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size)
                                g_free(bo_info);
                                break;
                        }
-                       bo_info->using = FALSE;
+                       bo_info->used = FALSE;
                        player->video_bo_list = g_list_append(player->video_bo_list, bo_info);
                }
 
@@ -3671,9 +3671,9 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size)
                /* get bo from list*/
                for (l = g_list_first(player->video_bo_list); l; l = g_list_next(l)) {
                        mm_player_video_bo_info_t* tmp = (mm_player_video_bo_info_t *)l->data;
-                       if (tmp && (tmp->using == FALSE)) {
+                       if (tmp && (tmp->used == FALSE)) {
                                LOGD("found bo %p to use", tmp->bo);
-                               tmp->using = TRUE;
+                               tmp->used = TRUE;
                                MMPLAYER_VIDEO_BO_UNLOCK(player);
                                return tbm_bo_ref(tmp->bo);
                        }
@@ -5035,7 +5035,7 @@ __mmplayer_gst_set_message_callback(mm_player_t* player, MMMessageCallback callb
        return MM_ERROR_NONE;
 }
 
-static int __mmplayer_parse_profile(const char *uri, void *param, MMPlayerParseProfile* data)
+int __mmplayer_parse_profile(const char *uri, void *param, MMPlayerParseProfile* data)
 {
        int ret = MM_ERROR_PLAYER_INVALID_URI;
        char *path = NULL;
diff --git a/unittest/Makefile.am b/unittest/Makefile.am
new file mode 100644 (file)
index 0000000..02742d7
--- /dev/null
@@ -0,0 +1,50 @@
+# Unit tests
+bin_PROGRAMS = gtest_libmm_player
+
+gtest_libmm_player_SOURCES  = libmm-player_internal.cpp
+
+gtest_libmm_player_CXXFLAGS =  -I$(top_srcdir)/src/include \
+                       $(MMCOMMON_CFLAGS) \
+                       $(MMUTIL_CFLAGS) \
+                       $(GST_CFLAGS) \
+                       $(GST_VIDEO_CFLAGS) \
+                       $(GST_APP_CFLAGS) \
+                       $(MMSOUND_CFLAGS) \
+                       $(MM_RESOURCE_MANAGER_CFLAGS) \
+                       $(ICU_CFLAGS) \
+                       $(UTILX_CFLAGS) \
+                       $(MEDIAPACKET_CFLAGS) \
+                       $(DLOG_CFLAGS) \
+                       $(SYSTEMINFO_CFLAGS) \
+                       $(STORAGE_CFLAGS) \
+                       $(TZPLATFORM_CONFIG_CFLAGS) \
+                       $(MEDIASOUNDMGR_CFLAGS) \
+                       $(TBM_CFLAGS) \
+                       $(GST_ALLOCATORS_CFLAGS) \
+                       $(GTESTS_CFLAGS) \
+                       -Werror -Wno-deprecated -Wno-deprecated-declarations -Wno-cpp
+
+gtest_libmm_player_DEPENDENCIES = $(top_srcdir)/src/.libs/libmmfplayer.la
+
+gtest_libmm_player_LDADD = \
+                       $(GST_LIBS) \
+                       $(MMCOMMON_LIBS) \
+                       $(MMUTIL_LIBS) \
+                       $(GST_INTERFACE_LIBS) \
+                       $(GST_VIDEO_LIBS) \
+                       $(GST_APP_LIBS) \
+                       $(INIPARSER_LIBS) \
+                       $(MMSOUND_LIBS) \
+                       $(MM_RESOURCE_MANAGER_LIBS) \
+                       $(ICU_LIBS) \
+                       $(MEDIAPACKET_LIBS) \
+                       $(DLOG_LIBS) \
+                       $(UTILX_LIBS) \
+                       $(SYSTEMINFO_LIBS) \
+                       $(STORAGE_LIBS) \
+                       $(TZPLATFORM_CONFIG_LIBS) \
+                       $(TBM_LIBS) \
+                       $(GST_ALLOCATORS_LIBS) \
+                       $(GTESTS_LIBS) \
+                       $(MEDIASOUNDMGR_LIBS) \
+                       $(top_srcdir)/src/.libs/libmmfplayer.la
diff --git a/unittest/libmm-player_internal.cpp b/unittest/libmm-player_internal.cpp
new file mode 100644 (file)
index 0000000..bd9a0ac
--- /dev/null
@@ -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 "libmm-player_internal.h"
+#include "mm_error.h"
+#include "mm_player_priv.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class libmm_player_Test : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       std::cout << "SetUp()" << std::endl;
+               }
+
+               void TearDown() {
+                       std::cout << "TearDown()" << std::endl;
+               }
+};
+
+TEST(libmm_playerTest, __mmplayer_parse_profile_p)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayerParseProfile profile;
+       gchar* uri = NULL;
+       memset((void*)&profile, 0, sizeof(MMPlayerParseProfile));
+
+       uri = g_strdup("http://test-url");
+       ret = __mmplayer_parse_profile(uri, NULL, &profile);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+       EXPECT_EQ(profile.uri_type, MM_PLAYER_URI_TYPE_URL_HTTP);
+       g_free(uri);
+       memset((void*)&profile, 0, sizeof(MMPlayerParseProfile));
+}
+
+TEST(libmm_playerTest, __mmplayer_parse_profile_n)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayerParseProfile profile;
+       gchar* uri = NULL;
+       memset((void*)&profile, 0, sizeof(MMPlayerParseProfile));
+
+       uri = g_strdup("file://non-existing-file.mp4");
+       ret = __mmplayer_parse_profile(uri, NULL, &profile);
+       EXPECT_EQ(ret, MM_ERROR_PLAYER_FILE_NOT_FOUND);
+       g_free(uri);
+       memset((void*)&profile, 0, sizeof(MMPlayerParseProfile));
+}
+
+gint main(gint argc, gchar **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/libmm-player_internal.h b/unittest/libmm-player_internal.h
new file mode 100644 (file)
index 0000000..a1cb60d
--- /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_PLAYER_UNITTEST_H__
+#define __LIB_MM_PLAYER_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_LIBMM_PLAYER"
+
+#endif /*__LIB_MM_PLAYER_UNITTEST_H__*/