[0.3.153] Add contents unittest 26/285526/10
authorGilbok Lee <gilbok.lee@samsung.com>
Wed, 14 Dec 2022 04:39:49 +0000 (13:39 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Thu, 22 Dec 2022 06:30:15 +0000 (15:30 +0900)
Change-Id: I4418ad54470c3ebeb0c5d2e1daffbfb20fcf56a2

CMakeLists.txt
packaging/capi-media-player.spec
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/playerTCInfo.hpp [new file with mode: 0644]
unittest/playerTCWindow.hpp [new file with mode: 0644]
unittest/player_ut.cpp [new file with mode: 0644]
unittest/ut_main.cpp [new file with mode: 0644]

index bd24037..e5bd1df 100644 (file)
@@ -77,6 +77,9 @@ CONFIGURE_FILE(
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 ADD_SUBDIRECTORY(test)
+IF(BUILD_UNITTEST)
+ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_UNITTEST)
 
 IF(UNIX)
 
index 1843a3e..02a3f00 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-player
 Summary:    A Media Player API
-Version:    0.3.152
+Version:    0.3.153
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -28,6 +28,11 @@ BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(libinput)
 
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+BuildRequires:  pkgconfig(jsoncpp)
+%endif
+
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
@@ -50,6 +55,16 @@ Requires: %{name} = %{version}-%{release}
 %description utils
 A test app for Media Player API
 
+%if 0%{?gtests:1}
+%package ut
+Summary: A unittest app for Media Player API
+Group:   Utils/Multimedia
+Requires: %{name} = %{version}-%{release}
+
+%description ut
+A unittest app for Media Player API
+%endif
+
 %if 0%{?gcov:1}
 %package gcov
 Summary: Line Coverage of Player library in Tizen C API
@@ -78,7 +93,12 @@ export LDFLAGS+=" -lgcov"
 %endif
 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+%if 0%{?gtests:1}
+  -DBUILD_UNITTEST=YES
+%else
+  -DBUILD_UNITTEST=NO
+%endif
 
 make %{?jobs:-j%jobs}
 
@@ -126,6 +146,13 @@ find . -name '*.gcno' ! -name '*internal*' -exec cp --parents '{}' "$gcno_obj_di
 %{_bindir}/player_audio_test
 %{_libdir}/libmm-navevent-handler.so*
 
+%if 0%{?gtests:1}
+%files ut
+%manifest %{name}.manifest
+%license LICENSE.APLv2
+%{_bindir}/player_ut
+%endif
+
 %if 0%{?gcov:1}
 %files gcov
 %{_datadir}/gcov/obj/*
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..72077f1
--- /dev/null
@@ -0,0 +1,67 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
+SET(fw_name "player_ut")
+
+SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
+
+SET(${fw_name}_CXXFLAGS "-Wall -pthread -fPIE -Wl,-z,relro -fstack-protector -fno-delete-null-pointer-checks -DEFL_BETA_API_SUPPORT")
+
+SET(${fw_name}_LDFLAGS)
+
+SET(ADD_LIBS
+  "capi-media-player"
+)
+
+SET(dependents
+  "glib-2.0 dlog capi-media-sound-manager"
+  "jsoncpp"
+  "appcore-efl elementary"
+)
+
+find_package(GTest REQUIRED)
+set(GTEST_LIBRARY gtest)
+
+INCLUDE(FindPkgConfig)
+
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+
+FOREACH(flag ${${fw_name}_CFLAGS})
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
+ENDFOREACH(flag)
+FOREACH(flag ${${fw_name}_CXXFLAGS})
+SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
+
+INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/src
+  ${PROJECT_SOURCE_DIR}/include
+  ${PROJECT_SOURCE_DIR}
+)
+
+SET(UT_SRC
+  ut_main.cpp
+  player_ut.cpp
+  playerTCInfo.hpp
+  playerTCWindow.hpp
+)
+
+ADD_EXECUTABLE(${fw_name} ${UT_SRC})
+
+LINK_DIRECTORIES(${LIB_INSTALL_DIR})
+
+TARGET_LINK_LIBRARIES(${fw_name}
+  ${GTEST_LIBRARY}
+  ${CMAKE_THREAD_LIBS_INIT}
+  ${ADD_LIBS}
+  ${${fw_name}_LDFLAGS}
+  "-pie"
+)
+
+INSTALL(
+  TARGETS ${fw_name}
+  DESTINATION bin
+)
diff --git a/unittest/playerTCInfo.hpp b/unittest/playerTCInfo.hpp
new file mode 100644 (file)
index 0000000..eaf74d3
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022 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 <iostream>
+#include <string.h>
+#include <fstream>
+#include <vector>
+#include <json/json.h>
+
+namespace playerUTInfo {
+
+static const std::string tcRootDIR = "/media/USBDriveA1/";
+static const std::string tcInfoFileName = "contentsInfo.config";
+
+class playerTCInfo;
+
+struct tcInfos {
+       std::string filePath;
+       int totalDuration = 0;
+
+       struct {
+               int sampleRate = 0;
+               int channels = 0;
+               int bitrate = 0;
+               std::string codecName;
+       } audio;
+
+       struct {
+               int fps = 0;
+               int bitrate = 0;
+               int width = 0;
+               int height = 0;
+               std::string codecName;
+       } video;
+};
+
+class playerTCInfo
+{
+private:
+       std::vector<tcInfos> _tcInfos;
+       std::string _subDirpath;
+
+       Json::Value openConfig();
+       std::vector<tcInfos> parseConfig(Json::Value root);
+       void _printTCInfos();
+
+public:
+       explicit playerTCInfo(const std::string dirpath);
+       ~playerTCInfo() = default;
+
+       std::vector<tcInfos> getTCInfos() { return _tcInfos; };
+};
+
+playerTCInfo::playerTCInfo(const std::string dirpath)
+{
+       _subDirpath = dirpath;
+       _tcInfos = parseConfig(openConfig());
+       _printTCInfos();
+}
+
+Json::Value playerTCInfo::openConfig()
+{
+       std::string configFilePath = tcRootDIR + _subDirpath + "/" + tcInfoFileName;
+       std::ifstream jsonFile(configFilePath, std::ifstream::binary);
+
+       Json::Value root;
+       jsonFile >> root;
+
+       jsonFile.close();
+
+       return root;
+
+}
+
+std::vector<tcInfos> playerTCInfo::parseConfig(Json::Value root)
+{
+       Json::Value& contents = root["contents"];
+
+       std::vector<tcInfos> infos;
+
+       for (auto& content : contents) {
+               Json::Value& audio = content["audio"];
+               Json::Value& video = content["video"];
+
+               tcInfos info {
+                       .filePath = tcRootDIR + _subDirpath + "/" + content["path"].asString(),
+                       .totalDuration = content["duration"].asInt(),
+
+                       .audio = {
+                               .sampleRate = audio["samplerate"].asInt(),
+                               .channels = audio["channels"].asInt(),
+                               .bitrate = audio["bitrate"].asInt(),
+                               .codecName = audio["codec"].asString(),
+                       },
+
+                       .video = {
+                               .fps = video["FPS"].asInt(),
+                               .bitrate = video["bitrate"].asInt(),
+                               .width = video["width"].asInt(),
+                               .height = video["height"].asInt(),
+                               .codecName = video["codec"].asString(),
+                       }
+               };
+
+               infos.push_back(info);
+       }
+
+       return infos;
+}
+
+void playerTCInfo::_printTCInfos()
+{
+       for (auto tcinfo : _tcInfos) {
+               std::cout << "filePath: " << tcinfo.filePath << std::endl;
+               std::cout << "totalDuration: " << tcinfo.totalDuration << std::endl;
+               std::cout << "audioSampleRate: " << tcinfo.audio.sampleRate << std::endl;
+               std::cout << "audioChannels: " << tcinfo.audio.channels << std::endl;
+               std::cout << "audioBitrate: " << tcinfo.audio.bitrate << std::endl;
+               std::cout << "audioCodecName: " << tcinfo.audio.codecName << std::endl;
+               std::cout << "videoFPS: " << tcinfo.video.fps << std::endl;
+               std::cout << "videoBitrate: " << tcinfo.video.bitrate << std::endl;
+               std::cout << "videoWidth: " << tcinfo.video.width << std::endl;
+               std::cout << "videoHeight: " << tcinfo.video.height << std::endl;
+               std::cout << "videoCodecName: " << tcinfo.video.codecName << std::endl << std::endl;
+       }
+}
+
+}
\ No newline at end of file
diff --git a/unittest/playerTCWindow.hpp b/unittest/playerTCWindow.hpp
new file mode 100644 (file)
index 0000000..1ecdffd
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2022 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 <cassert>
+#include <chrono>
+#include <thread>
+
+#include <Elementary.h>
+
+namespace playerUTInfo {
+
+namespace {
+
+class playerTCWindow
+{
+public:
+       playerTCWindow() {
+               elm_init(0, NULL);
+               _create();
+       }
+
+       ~playerTCWindow() {
+               _destroy();
+               elm_shutdown();
+       }
+
+       Evas_Object* getEvasObject() { return _evasObject; }
+
+private:
+       Evas_Object* _evasObject = nullptr;
+
+       void _create();
+       void _destroy();
+};
+
+void playerTCWindow::_create()
+{
+       int w = 0;
+       int h = 0;
+
+       elm_config_accel_preference_set("opengl");
+       _evasObject = elm_win_add(NULL, "player_ut", ELM_WIN_BASIC);
+       assert(_evasObject && "window is NULL.");
+
+       elm_win_title_set(_evasObject, "player_ut");
+       elm_win_borderless_set(_evasObject, EINA_TRUE);
+       elm_win_screen_size_get(_evasObject, NULL, NULL, &w, &h);
+       evas_object_resize(_evasObject, w, h);
+       elm_win_autodel_set(_evasObject, EINA_TRUE);
+       elm_win_alpha_set(_evasObject, EINA_TRUE);
+       elm_win_activate(_evasObject);
+       evas_object_show(_evasObject);
+}
+
+void playerTCWindow::_destroy()
+{
+       if (_evasObject) {
+               evas_object_del(_evasObject);
+               _evasObject = nullptr;
+       }
+}
+
+}
+
+}
\ No newline at end of file
diff --git a/unittest/player_ut.cpp b/unittest/player_ut.cpp
new file mode 100644 (file)
index 0000000..b30672b
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2022 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 <stdio.h>
+#include <chrono>
+#include <thread>
+#include <iostream>
+
+#include "gtest/gtest.h"
+
+#include "player.h"
+#include "player_internal.h"
+#include "unittest/playerTCInfo.hpp"
+#include "unittest/playerTCWindow.hpp"
+
+using namespace playerUTInfo;
+
+class PlayerContentsTest : public ::testing::TestWithParam<tcInfos> {
+public:
+       virtual void SetUp() override {
+               std::cout << "SetUp()" << std::endl;
+               _tcWindow = std::make_shared<playerTCWindow>();
+       }
+
+       virtual void TearDown() override {
+               std::cout << "TearDown()" << std::endl;
+       }
+
+       player_h _player;
+
+       std::shared_ptr<playerTCWindow> GetAppWindow() {
+               return _tcWindow;
+       }
+
+private:
+       std::shared_ptr<playerTCWindow> _tcWindow;
+};
+
+TEST_P(PlayerContentsTest, contents_test_p) {
+       int duration = 0;
+       int sample_rate = 0;
+       int channel = 0;
+       int bit_rate = 0;
+       int fps = 0;
+       int v_bit_rate = 0;
+       char *audio_codec = NULL;
+       char *video_codec = NULL;
+       int w = 0;
+       int h = 0;
+
+       tcInfos _tcInfos = GetParam();
+
+       auto tcWindow = GetAppWindow();
+
+       ASSERT_EQ(player_create(&_player), PLAYER_ERROR_NONE);
+       EXPECT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, tcWindow->getEvasObject()), PLAYER_ERROR_NONE);
+
+       EXPECT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE);
+       EXPECT_EQ(player_prepare(_player), PLAYER_ERROR_NONE);
+       EXPECT_EQ(player_get_duration(_player, &duration), PLAYER_ERROR_NONE);
+       EXPECT_EQ(duration, _tcInfos.totalDuration);
+
+       EXPECT_EQ(player_get_audio_stream_info(_player, &sample_rate, &channel, &bit_rate), PLAYER_ERROR_NONE);
+       EXPECT_EQ(sample_rate, _tcInfos.audio.sampleRate);
+       EXPECT_EQ(channel, _tcInfos.audio.channels);
+       EXPECT_EQ(bit_rate, _tcInfos.audio.bitrate);
+
+       EXPECT_EQ(player_get_video_stream_info(_player, &fps, &v_bit_rate), PLAYER_ERROR_NONE);
+       EXPECT_EQ(fps, _tcInfos.video.fps);
+       EXPECT_EQ(v_bit_rate, _tcInfos.video.bitrate);
+
+       EXPECT_EQ(player_get_video_size(_player, &w, &h), PLAYER_ERROR_NONE);
+       EXPECT_EQ(w, _tcInfos.video.width);
+       EXPECT_EQ(h, _tcInfos.video.height);
+
+       EXPECT_EQ(player_get_codec_info(_player, &audio_codec, &video_codec), PLAYER_ERROR_NONE);
+       std::string audioCodecName = audio_codec;
+       EXPECT_NE(audioCodecName.find(_tcInfos.audio.codecName), std::string::npos);
+       if (audio_codec)
+               free(audio_codec);
+
+       std::string videoCodecName = video_codec;
+       EXPECT_NE(videoCodecName.find(_tcInfos.video.codecName), std::string::npos);
+       if (video_codec)
+               free(video_codec);
+
+       EXPECT_EQ(player_start(_player), PLAYER_ERROR_NONE);
+       std::this_thread::sleep_for(std::chrono::milliseconds(5000));
+
+       EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE);
+
+       EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE);
+       EXPECT_EQ(player_destroy(_player), PLAYER_ERROR_NONE);
+
+}
+
+INSTANTIATE_TEST_SUITE_P(PlayerContentsTestFull, PlayerContentsTest,
+               ::testing::ValuesIn(playerTCInfo("codec").getTCInfos())
+);
\ No newline at end of file
diff --git a/unittest/ut_main.cpp b/unittest/ut_main.cpp
new file mode 100644 (file)
index 0000000..8695359
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2022 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 "gtest/gtest.h"
+
+int main(int argc, char *argv[])
+{
+       try {
+               ::testing::InitGoogleTest(&argc, argv);
+               return RUN_ALL_TESTS();
+       } catch (const std::exception &e) {
+               std::cout << "caught exception: " << e.what() << std::endl;
+               return -1;
+       }
+}