From: Youngwoo Cho Date: Wed, 27 Dec 2023 01:53:18 +0000 (+0900) Subject: [0.3.158] separate file and test in unittest X-Git-Tag: accepted/tizen/unified/20240605.153147~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b914a265461fbf3c9a87c34c00b1f81a9ecc44a6;p=platform%2Fcore%2Fapi%2Fplayer.git [0.3.158] separate file and test in unittest - separate file : src, include files - separate test : playback and seek are separated into feature tests Change-Id: I0b854a2a265e26050f9d89b95de72b837b30ea11 Signed-off-by: Youngwoo Cho --- diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 72077f1..49e0026 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -42,11 +42,8 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR} ) -SET(UT_SRC - ut_main.cpp - player_ut.cpp - playerTCInfo.hpp - playerTCWindow.hpp +FILE(GLOB UT_SRC + src/*.cpp ) ADD_EXECUTABLE(${fw_name} ${UT_SRC}) diff --git a/unittest/include/playerTCInfo.hpp b/unittest/include/playerTCInfo.hpp new file mode 100644 index 0000000..ef7ebd7 --- /dev/null +++ b/unittest/include/playerTCInfo.hpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 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 __PLAYER_UT_INCLUDE_TC_INFO_H__ +#define __PLAYER_UT_INCLUDE_TC_INFO_H__ + +#include +#include +#include + +namespace playerUTInfo { + +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; +}; + +std::ostream& operator << (std::ostream &os, const tcInfos &tcInfos_); + +class playerTCInfo +{ +public: + explicit playerTCInfo(const std::string dirpath); + ~playerTCInfo() = default; + + std::vector getTCInfos() { return _tcInfos; }; + +private: + Json::Value openConfig(); + std::vector parseConfig(Json::Value root); + void _printTCInfos(); + + std::vector _tcInfos; + std::string _subDirpath; +}; + +} + +#endif // __PLAYER_UT_INCLUDE_TC_INFO_H__ diff --git a/unittest/include/playerTCWindow.hpp b/unittest/include/playerTCWindow.hpp new file mode 100644 index 0000000..979ceca --- /dev/null +++ b/unittest/include/playerTCWindow.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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 __PLAYER_UT_INCLUDE_TC_WINDOW_H__ +#define __PLAYER_UT_INCLUDE_TC_WINDOW_H__ + +#include + +#include + +namespace playerUTWindow { + +class PlayerTCWindow +{ +public: + ~PlayerTCWindow(); + + PlayerTCWindow(const PlayerTCWindow& rhs) = delete; + PlayerTCWindow& operator=(const PlayerTCWindow& rhs) = delete; + + static PlayerTCWindow& Instance(); + static void WindowThread(PlayerTCWindow* tcWindow); + + Evas_Object* getEvasObject() { return _evasObjectWin; } + +private: + PlayerTCWindow(); + + void createWindow_(); + + Evas_Object* _evasObjectWin = nullptr; + bool _thread_init_done = false; + std::thread _thread; +}; + +} + +#endif // __PLAYER_UT_INCLUDE_TC_WINDOW_H__ diff --git a/unittest/playerTCInfo.hpp b/unittest/playerTCInfo.hpp deleted file mode 100644 index 6e6a599..0000000 --- a/unittest/playerTCInfo.hpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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 -#include -#include -#include -#include - -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; -}; - -std::ostream& operator << (std::ostream &os, const tcInfos &tcInfos_) { - return (os << tcInfos_.filePath); -} - -class playerTCInfo -{ -private: - std::vector _tcInfos; - std::string _subDirpath; - - Json::Value openConfig(); - std::vector parseConfig(Json::Value root); - void _printTCInfos(); - -public: - explicit playerTCInfo(const std::string dirpath); - ~playerTCInfo() = default; - - std::vector 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 playerTCInfo::parseConfig(Json::Value root) -{ - Json::Value& contents = root["contents"]; - - std::vector 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 deleted file mode 100644 index 58bc384..0000000 --- a/unittest/playerTCWindow.hpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 -#include -#include - -#include - -#define PACKAGE_NAME "player_ut" - -namespace playerUTInfo { - -namespace { -class PlayerTCWindow; - -static std::unique_ptr ptr; - -class PlayerTCWindow -{ -public: - ~PlayerTCWindow(); - - PlayerTCWindow(const PlayerTCWindow& rhs) = delete; - PlayerTCWindow& operator=(const PlayerTCWindow& rhs) = delete; - - static PlayerTCWindow& Instance(); - static void WindowThread(PlayerTCWindow* tcWindow); - - Evas_Object* getEvasObject() { return _evasObjectWin; } - -private: - PlayerTCWindow(); - - void createWindow_(); - - Evas_Object* _evasObjectWin = nullptr; - bool thread_init_done_ = false; - std::thread thread_; -}; - -PlayerTCWindow& PlayerTCWindow::Instance() { - if (!ptr.get()) ptr.reset(new PlayerTCWindow()); - return *(ptr.get()); -} - -PlayerTCWindow::PlayerTCWindow() { - thread_ = std::thread(PlayerTCWindow::WindowThread, this); - while (!thread_init_done_) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } - std::cout << "PlayerTCWindow()" << std::endl; -} - -PlayerTCWindow::~PlayerTCWindow() { - ecore_thread_main_loop_begin(); - elm_exit(); - ecore_thread_main_loop_end(); - thread_.join(); - std::cout << "~PlayerTCWindow()" << std::endl; -} - -void PlayerTCWindow::WindowThread(PlayerTCWindow* tcWindow) { - elm_init(1, NULL); - tcWindow->createWindow_(); - tcWindow->thread_init_done_ = true; - elm_run(); - elm_shutdown(); -} - -void PlayerTCWindow::createWindow_() { - int w = 0; - int h = 0; - - ecore_thread_main_loop_begin(); - - _evasObjectWin = elm_win_add(NULL, PACKAGE_NAME, ELM_WIN_BASIC); - assert(_evasObjectWin); - - elm_win_title_set(_evasObjectWin, PACKAGE_NAME); - elm_win_autodel_set(_evasObjectWin, EINA_TRUE); - elm_win_aux_hint_add(_evasObjectWin, "wm.policy.win.user.geometry", "1"); - - elm_win_screen_size_get(_evasObjectWin, NULL, NULL, &w, &h); - std::cout << "width, height: " << w << ", " << h << std::endl; - evas_object_move(_evasObjectWin, 0, 0); - evas_object_resize(_evasObjectWin, w, h); - evas_object_show(_evasObjectWin); - - ecore_thread_main_loop_end(); - - std::cout << "Window [" << _evasObjectWin << "]" << std::endl; -} - -} - -} \ No newline at end of file diff --git a/unittest/player_ut.cpp b/unittest/player_ut.cpp deleted file mode 100644 index 3bd6d40..0000000 --- a/unittest/player_ut.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - * 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 -#include -#include -#include - -#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 { -public: - PlayerContentsTest() : tcWindow_(PlayerTCWindow::Instance()) { } - - virtual void SetUp() override { - ASSERT_EQ(player_create(&_player), PLAYER_ERROR_NONE); - - std::cout << "SetUp()" << std::endl; - } - - virtual void TearDown() override { - ASSERT_EQ(player_destroy(_player), PLAYER_ERROR_NONE); - - std::cout << "TearDown()" << std::endl; - } - - int TestSetPlayPosition(int milliseconds, bool accurate) { - _seek_done = false; - return player_set_play_position(_player, milliseconds, accurate, seek_completed_cb, this); - } - - static void seek_completed_cb(void *user_data) { - auto test_ = static_cast(user_data); - std::unique_lock lk(test_->_seek_done_m); - test_->_seek_done = true; - std::cout << "seek_completed_cb()" << std::endl; - lk.unlock(); - test_->_seek_done_cv.notify_all(); - } - - bool WaitForSeek() { - std::unique_lock lk(_seek_done_m); - std::cout << "WaitForSeek start" << std::endl; - if (!_seek_done) { - _seek_done_cv.wait_for(lk, std::chrono::seconds(10), - [this]() -> bool { return _seek_done; }); - } - std::cout << "WaitForSeek stop" << std::endl; - return _seek_done; - } - -public: - player_h _player {}; - PlayerTCWindow& tcWindow_; - -private: - std::mutex _seek_done_m; - std::condition_variable _seek_done_cv; - bool _seek_done = true; -}; - -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(); - std::cout << "dir: " << _tcInfos << std::endl; - - ecore_thread_main_loop_begin(); - ASSERT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, tcWindow_.getEvasObject()), PLAYER_ERROR_NONE); - ecore_thread_main_loop_end(); - - ASSERT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE); - ASSERT_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::seconds(1)); - - std::cout << "playback rate 0.5" << std::endl; - EXPECT_EQ(player_set_playback_rate(_player, 0.5), PLAYER_ERROR_NONE); - - std::cout << "playback rate 2.0" << std::endl; - EXPECT_EQ(player_set_playback_rate(_player, 2.0), PLAYER_ERROR_NONE); - - std::cout << "playback rate 1.0" << std::endl; - EXPECT_EQ(player_set_playback_rate(_player, 1.0), PLAYER_ERROR_NONE); - - std::cout << "seek to " << duration / 4 << " with accurate 0" << std::endl; - int ret = TestSetPlayPosition(duration / 4, 0); - EXPECT_EQ(ret, PLAYER_ERROR_NONE); - if (ret == PLAYER_ERROR_NONE) { - EXPECT_TRUE(WaitForSeek()); - } - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - std::cout << "seek to " << duration / 2 << " with accurate 1" << std::endl; - ret = TestSetPlayPosition(duration / 2, 1); - EXPECT_EQ(ret, PLAYER_ERROR_NONE); - if (ret == PLAYER_ERROR_NONE) { - EXPECT_TRUE(WaitForSeek()); - } - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE); - EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE); -} - -TEST_P(PlayerContentsTest, DISABLED_visual_verify_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(); - std::cout << "dir: " << _tcInfos << std::endl; - - ecore_thread_main_loop_begin(); - ASSERT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, tcWindow_.getEvasObject()), PLAYER_ERROR_NONE); - ecore_thread_main_loop_end(); - - ASSERT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE); - ASSERT_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::seconds(3)); - - std::cout << "playback rate 0.5" << std::endl; - EXPECT_EQ(player_set_playback_rate(_player, 0.5), PLAYER_ERROR_NONE); - std::this_thread::sleep_for(std::chrono::seconds(2)); - - std::cout << "playback rate 2.0" << std::endl; - EXPECT_EQ(player_set_playback_rate(_player, 2.0), PLAYER_ERROR_NONE); - std::this_thread::sleep_for(std::chrono::seconds(2)); - - std::cout << "playback rate 1.0" << std::endl; - EXPECT_EQ(player_set_playback_rate(_player, 1.0), PLAYER_ERROR_NONE); - std::this_thread::sleep_for(std::chrono::seconds(2)); - - std::cout << "seek to " << duration / 4 << " with accurate 0" << std::endl; - int ret = TestSetPlayPosition(duration / 4, 0); - EXPECT_EQ(ret, PLAYER_ERROR_NONE); - if (ret == PLAYER_ERROR_NONE) { - EXPECT_TRUE(WaitForSeek()); - } - std::this_thread::sleep_for(std::chrono::seconds(3)); - - std::cout << "seek to " << duration / 2 << " with accurate 1" << std::endl; - ret = TestSetPlayPosition(duration / 2, 1); - EXPECT_EQ(ret, PLAYER_ERROR_NONE); - if (ret == PLAYER_ERROR_NONE) { - EXPECT_TRUE(WaitForSeek()); - } - std::this_thread::sleep_for(std::chrono::seconds(3)); - - EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE); - EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE); -} - -INSTANTIATE_TEST_SUITE_P(PlayerContentsTestFull, PlayerContentsTest, - ::testing::ValuesIn(playerTCInfo("TestContents").getTCInfos()) -); \ No newline at end of file diff --git a/unittest/src/playerTCInfo.cpp b/unittest/src/playerTCInfo.cpp new file mode 100644 index 0000000..592bffe --- /dev/null +++ b/unittest/src/playerTCInfo.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2022 - 2023 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 +#include +#include + +#include "unittest/include/playerTCInfo.hpp" + +namespace playerUTInfo { + +static const std::string tcRootDIR = "/media/USBDriveA1/"; +static const std::string tcInfoFileName = "contentsInfo.config"; + +std::ostream& operator << (std::ostream &os, const tcInfos &tcInfos_) { + return (os << tcInfos_.filePath); +} + +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 playerTCInfo::parseConfig(Json::Value root) +{ + Json::Value& contents = root["contents"]; + + std::vector 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; + } +} + +} diff --git a/unittest/src/playerTCWindow.cpp b/unittest/src/playerTCWindow.cpp new file mode 100644 index 0000000..ddadef4 --- /dev/null +++ b/unittest/src/playerTCWindow.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 - 2023 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 +#include +#include + +#include +#include "unittest/include/playerTCWindow.hpp" + +#define PACKAGE_NAME "player_ut" + +namespace playerUTWindow { + +static std::unique_ptr ptr; + +PlayerTCWindow& PlayerTCWindow::Instance() { + if (!ptr.get()) ptr.reset(new PlayerTCWindow()); + return *(ptr.get()); +} + +PlayerTCWindow::PlayerTCWindow() { + _thread = std::thread(PlayerTCWindow::WindowThread, this); + while (!_thread_init_done) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + std::cout << "PlayerTCWindow()" << std::endl; +} + +PlayerTCWindow::~PlayerTCWindow() { + ecore_thread_main_loop_begin(); + elm_exit(); + ecore_thread_main_loop_end(); + _thread.join(); + std::cout << "~PlayerTCWindow()" << std::endl; +} + +void PlayerTCWindow::WindowThread(PlayerTCWindow* tcWindow) { + elm_init(1, NULL); + tcWindow->createWindow_(); + tcWindow->_thread_init_done = true; + elm_run(); + elm_shutdown(); +} + +void PlayerTCWindow::createWindow_() { + int w = 0; + int h = 0; + + ecore_thread_main_loop_begin(); + + _evasObjectWin = elm_win_add(NULL, PACKAGE_NAME, ELM_WIN_BASIC); + assert(_evasObjectWin); + + elm_win_title_set(_evasObjectWin, PACKAGE_NAME); + elm_win_autodel_set(_evasObjectWin, EINA_TRUE); + elm_win_aux_hint_add(_evasObjectWin, "wm.policy.win.user.geometry", "1"); + + elm_win_screen_size_get(_evasObjectWin, NULL, NULL, &w, &h); + std::cout << "width, height: " << w << ", " << h << std::endl; + evas_object_move(_evasObjectWin, 0, 0); + evas_object_resize(_evasObjectWin, w, h); + evas_object_show(_evasObjectWin); + + ecore_thread_main_loop_end(); + + std::cout << "Window [" << _evasObjectWin << "]" << std::endl; +} + +} diff --git a/unittest/src/ut_contents.cpp b/unittest/src/ut_contents.cpp new file mode 100644 index 0000000..a696fec --- /dev/null +++ b/unittest/src/ut_contents.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2023 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 +#include +#include + +#include "gtest/gtest.h" + +#include "player.h" +#include "player_internal.h" +#include "unittest/include/playerTCInfo.hpp" +#include "unittest/include/playerTCWindow.hpp" + +using namespace playerUTInfo; +using namespace playerUTWindow; + +class PlayerContentsTest : public ::testing::TestWithParam { +public: + PlayerContentsTest() : _tcWindow(PlayerTCWindow::Instance()) { } + + virtual void SetUp() override { + ASSERT_EQ(player_create(&_player), PLAYER_ERROR_NONE); + + std::cout << "SetUp()" << std::endl; + } + + virtual void TearDown() override { + ASSERT_EQ(player_destroy(_player), PLAYER_ERROR_NONE); + + std::cout << "TearDown()" << std::endl; + } + +public: + player_h _player {}; + PlayerTCWindow& _tcWindow; +}; + +TEST_P(PlayerContentsTest, player_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(); + std::cout << "dir: " << _tcInfos << std::endl; + + ecore_thread_main_loop_begin(); + ASSERT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, _tcWindow.getEvasObject()), PLAYER_ERROR_NONE); + ecore_thread_main_loop_end(); + + ASSERT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE); + ASSERT_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(500)); + + EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE); + EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE); +} + +TEST_P(PlayerContentsTest, DISABLED_human_verify_player_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(); + std::cout << "dir: " << _tcInfos << std::endl; + + ecore_thread_main_loop_begin(); + ASSERT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, _tcWindow.getEvasObject()), PLAYER_ERROR_NONE); + ecore_thread_main_loop_end(); + + ASSERT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE); + ASSERT_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::seconds(5)); + + EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE); + EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE); +} + +INSTANTIATE_TEST_SUITE_P(PlayerContentsTestFull, PlayerContentsTest, + ::testing::ValuesIn(playerTCInfo("TestContents").getTCInfos()) +); diff --git a/unittest/src/ut_features.cpp b/unittest/src/ut_features.cpp new file mode 100644 index 0000000..9cadabe --- /dev/null +++ b/unittest/src/ut_features.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2022 - 2023 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 +#include +#include + +#include "gtest/gtest.h" + +#include "player.h" +#include "player_internal.h" +#include "unittest/include/playerTCInfo.hpp" +#include "unittest/include/playerTCWindow.hpp" + +using namespace playerUTInfo; +using namespace playerUTWindow; + +class PlayerFeaturesTest : public ::testing::TestWithParam { +public: + PlayerFeaturesTest() : _tcWindow(PlayerTCWindow::Instance()) { } + + virtual void SetUp() override { + ASSERT_EQ(player_create(&_player), PLAYER_ERROR_NONE); + + std::cout << "SetUp()" << std::endl; + } + + virtual void TearDown() override { + ASSERT_EQ(player_destroy(_player), PLAYER_ERROR_NONE); + + std::cout << "TearDown()" << std::endl; + } + + int TestSetPlayPosition(int milliseconds, bool accurate) { + _seek_done = false; + return player_set_play_position(_player, milliseconds, accurate, seek_completed_cb, this); + } + + static void seek_completed_cb(void *user_data) { + auto test_ = static_cast(user_data); + std::unique_lock lk(test_->_seek_done_m); + test_->_seek_done = true; + std::cout << "seek_completed_cb()" << std::endl; + lk.unlock(); + test_->_seek_done_cv.notify_all(); + } + + bool WaitForSeek() { + std::unique_lock lk(_seek_done_m); + std::cout << "WaitForSeek start" << std::endl; + if (!_seek_done) { + _seek_done_cv.wait_for(lk, std::chrono::seconds(10), + [this]() -> bool { return _seek_done; }); + } + std::cout << "WaitForSeek stop" << std::endl; + return _seek_done; + } + +public: + player_h _player {}; + PlayerTCWindow& _tcWindow; + +private: + std::mutex _seek_done_m; + std::condition_variable _seek_done_cv; + bool _seek_done = true; +}; + +TEST_P(PlayerFeaturesTest, player_features_test_p) { + int duration = 0; + + tcInfos _tcInfos = GetParam(); + std::cout << "dir: " << _tcInfos << std::endl; + + ecore_thread_main_loop_begin(); + ASSERT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, _tcWindow.getEvasObject()), PLAYER_ERROR_NONE); + ecore_thread_main_loop_end(); + + ASSERT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE); + ASSERT_EQ(player_prepare(_player), PLAYER_ERROR_NONE); + + EXPECT_EQ(player_get_duration(_player, &duration), PLAYER_ERROR_NONE); + + EXPECT_EQ(player_start(_player), PLAYER_ERROR_NONE); + std::this_thread::sleep_for(std::chrono::seconds(1)); + + std::cout << "playback rate 0.5" << std::endl; + EXPECT_EQ(player_set_playback_rate(_player, 0.5), PLAYER_ERROR_NONE); + + std::cout << "playback rate 2.0" << std::endl; + EXPECT_EQ(player_set_playback_rate(_player, 2.0), PLAYER_ERROR_NONE); + + std::cout << "playback rate 1.0" << std::endl; + EXPECT_EQ(player_set_playback_rate(_player, 1.0), PLAYER_ERROR_NONE); + + std::cout << "seek to " << duration / 4 << " with accurate 0" << std::endl; + int ret = TestSetPlayPosition(duration / 4, 0); + EXPECT_EQ(ret, PLAYER_ERROR_NONE); + if (ret == PLAYER_ERROR_NONE) { + EXPECT_TRUE(WaitForSeek()); + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + std::cout << "seek to " << duration / 2 << " with accurate 1" << std::endl; + ret = TestSetPlayPosition(duration / 2, 1); + EXPECT_EQ(ret, PLAYER_ERROR_NONE); + if (ret == PLAYER_ERROR_NONE) { + EXPECT_TRUE(WaitForSeek()); + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE); + EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE); +} + +INSTANTIATE_TEST_SUITE_P(PlayerFeaturesTestFull, PlayerFeaturesTest, + ::testing::ValuesIn(playerTCInfo("TestContents/Features").getTCInfos()) +); diff --git a/unittest/src/ut_main.cpp b/unittest/src/ut_main.cpp new file mode 100644 index 0000000..8695359 --- /dev/null +++ b/unittest/src/ut_main.cpp @@ -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; + } +} diff --git a/unittest/ut_main.cpp b/unittest/ut_main.cpp deleted file mode 100644 index 8695359..0000000 --- a/unittest/ut_main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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; - } -}