BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(capi-media-sound-manager)
BuildRequires: pkgconfig(libtbm)
-%if 0%{?gtests:1}
+%if "%{gtests}" == "1"
BuildRequires: pkgconfig(gmock)
%endif
# 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 \
%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
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));
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;
}
}
# 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) \
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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;
+}
* 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__*/
--- /dev/null
+/*
+ * 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__*/
+++ /dev/null
-/*
- * 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();
-}
--- /dev/null
+/*
+ * 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();
+}