[0.6.150] add unittest cases 17/193517/3
authorEunhae Choi <eunhae1.choi@samsung.com>
Wed, 21 Nov 2018 10:48:44 +0000 (19:48 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Thu, 22 Nov 2018 02:38:29 +0000 (11:38 +0900)
- add more test cases
- define class per each mm player file for test
- fix err return bug of _pare_profile

Change-Id: I0b89b65b669880b3e120df0f5ad8036613f3754d

packaging/libmm-player.spec
src/mm_player_priv.c
unittest/Makefile.am
unittest/gtest_mm_player.cpp [new file with mode: 0644]
unittest/gtest_mm_player_priv.cpp [new file with mode: 0644]
unittest/include/gtest_mm_player.h [moved from unittest/libmm-player_internal.h with 68% similarity]
unittest/include/gtest_mm_player_priv.h [new file with mode: 0644]
unittest/libmm-player_internal.cpp [deleted file]
unittest/unittest.cpp [new file with mode: 0644]

index 8672c1d..1c6b60a 100644 (file)
@@ -26,7 +26,7 @@ BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(capi-media-sound-manager)
 BuildRequires:  pkgconfig(libtbm)
-%if 0%{?gtests:1}
+%if "%{gtests}" == "1"
 BuildRequires:  pkgconfig(gmock)
 %endif
 
@@ -56,7 +56,7 @@ LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--hash-style=both -Wl,--as-needed"; exp
 # always enable sdk build. This option should go away
 #CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --enable-sdk --prefix=%{_prefix} --disable-static
 %configure \
-%if 0%{?gtests:1}
+%if "%{gtests}" == "1"
 --enable-tests \
 %endif
 --disable-static \
@@ -77,8 +77,8 @@ make %{?jobs:-j%jobs}
 %license LICENSE.Apache-2.0
 %defattr(-,root,root,-)
 %{_libdir}/*.so.*
-%if 0%{?gtests:1}
-%{_bindir}/gtest_libmm_player
+%if "%{gtests}" == "1"
+%{_bindir}/gtest-libmm-player
 %endif
 
 %files devel
index 78dc9a0..46baf11 100755 (executable)
@@ -4232,9 +4232,9 @@ int __mmplayer_parse_profile(const char *uri, void *param, MMPlayerParseProfile*
 
        MMPLAYER_FENTER();
 
-       MMPLAYER_RETURN_VAL_IF_FAIL(uri , FALSE);
-       MMPLAYER_RETURN_VAL_IF_FAIL(data , FALSE);
-       MMPLAYER_RETURN_VAL_IF_FAIL((strlen(uri) <= MM_MAX_URL_LEN), FALSE);
+       MMPLAYER_RETURN_VAL_IF_FAIL(uri, MM_ERROR_PLAYER_INVALID_URI);
+       MMPLAYER_RETURN_VAL_IF_FAIL(data, MM_ERROR_PLAYER_INTERNAL);
+       MMPLAYER_RETURN_VAL_IF_FAIL((strlen(uri) <= MM_MAX_URL_LEN), MM_ERROR_PLAYER_INVALID_URI);
 
        memset(data, 0, sizeof(MMPlayerParseProfile));
 
@@ -4861,7 +4861,7 @@ _mmplayer_realize(MMHandleType hplayer)
                ret = __mmplayer_parse_profile((const char*)uri, param, &player->profile);
 
                if (ret != MM_ERROR_NONE) {
-                       LOGE("failed to parse profile\n");
+                       LOGE("failed to parse profile");
                        return ret;
                }
        }
index 02742d7..f7aad95 100644 (file)
@@ -1,9 +1,12 @@
 # Unit tests
-bin_PROGRAMS = gtest_libmm_player
+bin_PROGRAMS = gtest-libmm-player
 
-gtest_libmm_player_SOURCES  = libmm-player_internal.cpp
+gtest_libmm_player_SOURCES  = unittest.cpp \
+                       gtest_mm_player.cpp \
+                       gtest_mm_player_priv.cpp
 
 gtest_libmm_player_CXXFLAGS =  -I$(top_srcdir)/src/include \
+                       -I$(top_srcdir)/unittest/include \
                        $(MMCOMMON_CFLAGS) \
                        $(MMUTIL_CFLAGS) \
                        $(GST_CFLAGS) \
diff --git a/unittest/gtest_mm_player.cpp b/unittest/gtest_mm_player.cpp
new file mode 100644 (file)
index 0000000..b9fa23f
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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 "mm_player.h"
+#include "mm_error.h"
+#include "gtest_mm_player.h"
+
+MMPlayer::MMPlayer()
+{
+       mm_handle = NULL;
+}
+
+MMPlayer::~MMPlayer()
+{
+       if (mm_handle) {
+               LOGD("[Cleanup] %p", mm_handle);
+               mm_player_destroy(mm_handle);
+               mm_handle = NULL;
+       }
+}
+
+int MMPlayer::Create(void)
+{
+       int ret = mm_player_create(&mm_handle);
+       LOGD("[Create] %p", mm_handle);
+       return ret;
+}
+
+int MMPlayer::Destroy(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       LOGD("[Destroy] %p", mm_handle);
+
+       ret = mm_player_destroy(mm_handle);
+       mm_handle = NULL;
+
+       return ret;
+}
diff --git a/unittest/gtest_mm_player_priv.cpp b/unittest/gtest_mm_player_priv.cpp
new file mode 100644 (file)
index 0000000..f0f86e0
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * 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 "mm_error.h"
+#include "mm_player_utils.h"
+#include "gtest_mm_player_priv.h"
+
+MMPlayerPriv::MMPlayerPriv()
+{
+       priv_player = NULL;
+}
+
+MMPlayerPriv::~MMPlayerPriv()
+{
+       if (priv_player) {
+               _mmplayer_destroy((MMHandleType)priv_player);
+               g_mutex_clear(&priv_player->cmd_lock);
+               g_mutex_clear(&priv_player->playback_lock);
+
+               g_free(priv_player);
+               priv_player = NULL;
+       }
+}
+
+int MMPlayerPriv::Create(void)
+{
+       int ret = MM_ERROR_NONE;
+       mm_player_t *new_player = NULL;
+
+       /* alloc player structure */
+       new_player = (mm_player_t *)g_malloc0(sizeof(mm_player_t));
+
+       /* create player lock */
+       g_mutex_init(&new_player->cmd_lock);
+
+       /* create player lock */
+       g_mutex_init(&new_player->playback_lock);
+
+       /* load ini files */
+       if (mm_player_ini_load(&new_player->ini) != MM_ERROR_NONE) {
+               LOGE("can't load ini");
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
+       if (mm_player_audio_effect_ini_load(&new_player->ini) != MM_ERROR_NONE) {
+               LOGE("can't load audio ini");
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
+       /* create player */
+       ret = _mmplayer_create_player((MMHandleType)new_player);
+
+       priv_player = new_player;
+
+       return ret;
+}
+
+int MMPlayerPriv::Destroy(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!priv_player)
+               return MM_ERROR_PLAYER_NOT_INITIALIZED;
+
+       __mmplayer_bus_msg_thread_destroy(priv_player);
+
+       MMPLAYER_CMD_LOCK(priv_player);
+
+       ret = _mmplayer_destroy(priv_player);
+
+       MMPLAYER_CMD_UNLOCK(priv_player);
+
+       g_mutex_clear(&((mm_player_t*)priv_player)->cmd_lock);
+       g_mutex_clear(&((mm_player_t*)priv_player)->playback_lock);
+
+       memset((mm_player_t*)priv_player, 0x00, sizeof(mm_player_t));
+
+       /* free player */
+       g_free((void*)priv_player);
+       priv_player = NULL;
+
+       return ret;
+}
+
+int MMPlayerPriv::SetUri(const gchar *uri)
+{
+       int ret = MM_ERROR_NONE;
+
+       MMPLAYER_CMD_LOCK(priv_player);
+       ret= _mmplayer_set_uri(priv_player, uri);
+       MMPLAYER_CMD_UNLOCK(priv_player);
+
+       return ret;
+}
+
+int MMPlayerPriv::Realize(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       MMPLAYER_CMD_LOCK(priv_player);
+       ret = _mmplayer_realize(priv_player);
+       MMPLAYER_CMD_UNLOCK(priv_player);
+
+       return ret;
+}
+
+int MMPlayerPriv::Unrealize(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       MMPLAYER_CMD_LOCK(priv_player);
+       ret = _mmplayer_unrealize(priv_player);
+       MMPLAYER_CMD_UNLOCK(priv_player);
+
+       return ret;
+}
+
+int MMPlayerPriv::GetCurrentState(MMPlayerStateType *state)
+{
+       int ret = MM_ERROR_NONE;
+
+       *state = MM_PLAYER_STATE_NULL;
+       ret = _mmplayer_get_state(priv_player, (int*)state);
+
+       return ret;
+}
+
+int MMPlayerPriv::ParseProfile(const gchar *uri, int *uri_type)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayerParseProfile profile;
+
+       memset((void*)&profile, 0, sizeof(MMPlayerParseProfile));
+
+       ret = __mmplayer_parse_profile(uri, NULL, &profile);
+       if (uri_type)
+               *uri_type = profile.uri_type;
+
+       return ret;
+}
similarity index 68%
rename from unittest/libmm-player_internal.h
rename to unittest/include/gtest_mm_player.h
index a1cb60d..1188672 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __LIB_MM_PLAYER_UNITTEST_H__
-#define __LIB_MM_PLAYER_UNITTEST_H__
+#ifndef __GTEST_MM_PLAYER_H__
+#define __GTEST_MM_PLAYER_H__
 
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include "mm_types.h"
+#include "gtest_mm_player_priv.h"
 
-#undef LOG_TAG
-#define LOG_TAG                "GTEST_LIBMM_PLAYER"
+class MMPlayer {
+private:
+       MMHandleType mm_handle;
 
-#endif /*__LIB_MM_PLAYER_UNITTEST_H__*/
+public:
+       MMPlayer();
+       virtual ~MMPlayer();
+
+       int Create(void);
+       int Destroy(void);
+};
+
+#endif /*__GTEST_MM_PLAYER_H__*/
diff --git a/unittest/include/gtest_mm_player_priv.h b/unittest/include/gtest_mm_player_priv.h
new file mode 100644 (file)
index 0000000..9dec326
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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 __GTEST_MM_PLAYER_PRIV_H__
+#define __GTEST_MM_PLAYER_PRIV_H__
+
+#include <dlog.h>
+#include "mm_player.h"
+#include "mm_player_priv.h"
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_MM_PLAYER"
+
+class MMPlayerPriv {
+private:
+       mm_player_t *priv_player;
+
+public:
+       MMPlayerPriv();
+       virtual ~MMPlayerPriv();
+
+       int Create(void);
+       int Destroy(void);
+       int SetUri(const gchar *uri);
+       int Realize(void);
+       int Unrealize(void);
+       int GetCurrentState(MMPlayerStateType *state);
+       int ParseProfile(const gchar *uri, int *uri_type);
+};
+
+#endif /*__GTEST_MM_PLAYER_PRIV_H__*/
diff --git a/unittest/libmm-player_internal.cpp b/unittest/libmm-player_internal.cpp
deleted file mode 100644 (file)
index bd9a0ac..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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/unittest.cpp b/unittest/unittest.cpp
new file mode 100644 (file)
index 0000000..28b7aa2
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * 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 <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <iostream>
+#include "mm_error.h"
+#include "mm_player_priv.h"
+#include "gtest_mm_player.h"
+#include "gtest_mm_player_priv.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+TEST(MMPlayerPreTest, Create_p)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayer player;
+
+       ret = player.Create();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST(MMPlayerPreTest, Destroy_p)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayer player;
+
+       ret = player.Create();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       ret = player.Destroy();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST(MMPlayerPrePrivTest, Create_p)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayerPriv player;
+
+       ret = player.Create();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST(MMPlayerPrePrivTest, Destroy_p)
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayerPriv player;
+
+       ret = player.Create();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       ret = player.Destroy();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+class MMPlayerPrivTest : public ::testing::Test {
+       public:
+               virtual void SetUp();
+               virtual void TearDown();
+
+       protected:
+               MMPlayerPriv priv_player;
+};
+
+void MMPlayerPrivTest::SetUp()
+{
+       int ret = MM_ERROR_NONE;
+       ret = priv_player.Create();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+void MMPlayerPrivTest::TearDown()
+{
+       int ret = MM_ERROR_NONE;
+       MMPlayerStateType state = MM_PLAYER_STATE_NULL;
+
+       ret = priv_player.GetCurrentState(&state);
+       if (ret != MM_ERROR_NONE)
+               LOGE("failed to get current state");
+
+       if (state > MM_PLAYER_STATE_NULL) {
+               ret = priv_player.Unrealize();
+               if (ret != MM_ERROR_NONE)
+                       LOGE("failed to unrealize");
+       }
+
+       ret = priv_player.Destroy();
+       if (ret != MM_ERROR_NONE)
+               LOGE("failed to destroy");
+}
+
+TEST_F(MMPlayerPrivTest, Realize_P)
+{
+       int ret = MM_ERROR_NONE;
+       const gchar* uri = "http://test-url.mp4";
+
+       ret = priv_player.SetUri(uri);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       ret = priv_player.Realize();
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMPlayerPrivTest, Realize_N)
+{
+       int ret = MM_ERROR_NONE;
+       ret = priv_player.Realize();
+       EXPECT_EQ(ret, MM_ERROR_PLAYER_INVALID_URI);
+}
+
+TEST_F(MMPlayerPrivTest, ParseProfile_p)
+{
+       int ret = MM_ERROR_NONE;
+       const gchar* uri = "http://test-url";
+       int uri_type = MM_PLAYER_URI_TYPE_NONE;
+
+       ret = priv_player.ParseProfile(uri, &uri_type);
+
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+       EXPECT_EQ(uri_type, MM_PLAYER_URI_TYPE_URL_HTTP);
+}
+
+TEST_F(MMPlayerPrivTest, ParseProfile_n)
+{
+       int ret = MM_ERROR_NONE;
+       const gchar* uri = "file://non-existing-file.mp4";
+
+       ret = priv_player.ParseProfile(uri, NULL);
+
+       EXPECT_EQ(ret, MM_ERROR_PLAYER_FILE_NOT_FOUND);
+}
+
+gint main(gint argc, gchar **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}