[0.3.158] Remove profile tag from header description
[platform/core/api/player.git] / unittest / player_ut.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <chrono>
19 #include <thread>
20 #include <iostream>
21
22 #include "gtest/gtest.h"
23
24 #include "player.h"
25 #include "player_internal.h"
26 #include "unittest/playerTCInfo.hpp"
27 #include "unittest/playerTCWindow.hpp"
28
29 using namespace playerUTInfo;
30
31 class PlayerContentsTest : public ::testing::TestWithParam<tcInfos> {
32 public:
33         virtual void SetUp() override {
34                 std::cout << "SetUp()" << std::endl;
35                 _tcWindow = std::make_shared<playerTCWindow>();
36         }
37
38         virtual void TearDown() override {
39                 std::cout << "TearDown()" << std::endl;
40         }
41
42         player_h _player;
43
44         std::shared_ptr<playerTCWindow> GetAppWindow() {
45                 return _tcWindow;
46         }
47
48 private:
49         std::shared_ptr<playerTCWindow> _tcWindow;
50 };
51
52 TEST_P(PlayerContentsTest, contents_test_p) {
53         int duration = 0;
54         int sample_rate = 0;
55         int channel = 0;
56         int bit_rate = 0;
57         int fps = 0;
58         int v_bit_rate = 0;
59         char *audio_codec = NULL;
60         char *video_codec = NULL;
61         int w = 0;
62         int h = 0;
63
64         tcInfos _tcInfos = GetParam();
65
66         auto tcWindow = GetAppWindow();
67
68         ASSERT_EQ(player_create(&_player), PLAYER_ERROR_NONE);
69         EXPECT_EQ(player_set_display(_player, PLAYER_DISPLAY_TYPE_OVERLAY, tcWindow->getEvasObject()), PLAYER_ERROR_NONE);
70
71         EXPECT_EQ(player_set_uri(_player, _tcInfos.filePath.c_str()), PLAYER_ERROR_NONE);
72         EXPECT_EQ(player_prepare(_player), PLAYER_ERROR_NONE);
73         EXPECT_EQ(player_get_duration(_player, &duration), PLAYER_ERROR_NONE);
74         EXPECT_EQ(duration, _tcInfos.totalDuration);
75
76         EXPECT_EQ(player_get_audio_stream_info(_player, &sample_rate, &channel, &bit_rate), PLAYER_ERROR_NONE);
77         EXPECT_EQ(sample_rate, _tcInfos.audio.sampleRate);
78         EXPECT_EQ(channel, _tcInfos.audio.channels);
79         EXPECT_EQ(bit_rate, _tcInfos.audio.bitrate);
80
81         EXPECT_EQ(player_get_video_stream_info(_player, &fps, &v_bit_rate), PLAYER_ERROR_NONE);
82         EXPECT_EQ(fps, _tcInfos.video.fps);
83         EXPECT_EQ(v_bit_rate, _tcInfos.video.bitrate);
84
85         EXPECT_EQ(player_get_video_size(_player, &w, &h), PLAYER_ERROR_NONE);
86         EXPECT_EQ(w, _tcInfos.video.width);
87         EXPECT_EQ(h, _tcInfos.video.height);
88
89         EXPECT_EQ(player_get_codec_info(_player, &audio_codec, &video_codec), PLAYER_ERROR_NONE);
90         std::string audioCodecName = audio_codec;
91         EXPECT_NE(audioCodecName.find(_tcInfos.audio.codecName), std::string::npos);
92         if (audio_codec)
93                 free(audio_codec);
94
95         std::string videoCodecName = video_codec;
96         EXPECT_NE(videoCodecName.find(_tcInfos.video.codecName), std::string::npos);
97         if (video_codec)
98                 free(video_codec);
99
100         EXPECT_EQ(player_start(_player), PLAYER_ERROR_NONE);
101         std::this_thread::sleep_for(std::chrono::milliseconds(5000));
102
103         EXPECT_EQ(player_stop(_player), PLAYER_ERROR_NONE);
104
105         EXPECT_EQ(player_unprepare(_player), PLAYER_ERROR_NONE);
106         EXPECT_EQ(player_destroy(_player), PLAYER_ERROR_NONE);
107
108 }
109
110 INSTANTIATE_TEST_SUITE_P(PlayerContentsTestFull, PlayerContentsTest,
111                 ::testing::ValuesIn(playerTCInfo("codec").getTCInfos())
112 );