• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include <parameters.h>
19 #include "boot_animation_utils.h"
20 #include "boot_video_player.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS::Rosen {
26 class BootVideoPlayerTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 };
33 
SetUpTestCase()34 void BootVideoPlayerTest::SetUpTestCase() {}
TearDownTestCase()35 void BootVideoPlayerTest::TearDownTestCase() {}
SetUp()36 void BootVideoPlayerTest::SetUp() {}
TearDown()37 void BootVideoPlayerTest::TearDown() {}
38 
39 /**
40  * @tc.name: BootVideoPlayerTest_001
41  * @tc.desc: Verify the OnError
42  * @tc.type:FUNC
43  */
44 HWTEST_F(BootVideoPlayerTest, BootVideoPlayerTest_001, TestSize.Level1)
45 {
46     PlayerParams params;
47     int flag = 0;
48     BootAnimationCallback callback_ = {
49         .userData = this,
__anonc56a43d50102() 50         .callback = [&flag](void*) { flag = 1; },
51     };
52     params.callback = &callback_;
53     std::shared_ptr<BootVideoPlayer> player = std::make_shared<BootVideoPlayer>(params);
54     std::shared_ptr<VideoPlayerCallback> cb = std::make_shared<VideoPlayerCallback>(player);
55     cb->OnError(-1, "test");
56     EXPECT_EQ(flag, 1);
57 }
58 
59 /**
60  * @tc.name: BootVideoPlayerTest_002
61  * @tc.desc: Verify the StopVideo
62  * @tc.type:FUNC
63  */
64 HWTEST_F(BootVideoPlayerTest, BootVideoPlayerTest_002, TestSize.Level1)
65 {
66     PlayerParams params;
67     int flag = 0;
68     BootAnimationCallback callback_ = {
69         .userData = this,
__anonc56a43d50202() 70         .callback = [&flag](void*) { flag = 1; },
71     };
72     params.callback = &callback_;
73     std::shared_ptr<BootVideoPlayer> player = std::make_shared<BootVideoPlayer>(params);
74     player->StopVideo();
75     EXPECT_EQ(flag, 1);
76 }
77 
78 /**
79  * @tc.name: BootVideoPlayerTest_003
80  * @tc.desc: Verify the SetVideoSound
81  * @tc.type:FUNC
82  */
83 HWTEST_F(BootVideoPlayerTest, BootVideoPlayerTest_003, TestSize.Level1)
84 {
85     BootAnimationCallback callback_ = {
86         .userData = this,
__anonc56a43d50302() 87         .callback = [&](void*) {},
88     };
89 
90     PlayerParams params1;
91     params1.soundEnabled = true;
92     params1.callback = &callback_;
93     std::shared_ptr<BootVideoPlayer> player1 = std::make_shared<BootVideoPlayer>(params1);
94     player1->mediaPlayer_ = Media::PlayerFactory::CreatePlayer();
95     player1->SetVideoSound();
96 
97     PlayerParams params2;
98     params2.soundEnabled = false;
99     params2.callback = &callback_;
100     std::shared_ptr<BootVideoPlayer> player2 = std::make_shared<BootVideoPlayer>(params2);
101     player2->mediaPlayer_ = Media::PlayerFactory::CreatePlayer();
102     player2->SetVideoSound();
103 
104     PlayerParams params3;
105     params3.soundEnabled = true;
106     params3.callback = &callback_;
107     std::shared_ptr<BootVideoPlayer> player3 = std::make_shared<BootVideoPlayer>(params3);
108     player3->mediaPlayer_ = Media::PlayerFactory::CreatePlayer();
109     BootAnimationUtils::SetBootAnimationSoundEnabled(false);
110     EXPECT_EQ(BootAnimationUtils::GetBootAnimationSoundEnabled(), false);
111     player3->SetVideoSound();
112 
113     PlayerParams params4;
114     params4.soundEnabled = true;
115     params4.callback = &callback_;
116     std::shared_ptr<BootVideoPlayer> player4 = std::make_shared<BootVideoPlayer>(params4);
117     player4->mediaPlayer_ = Media::PlayerFactory::CreatePlayer();
118     BootAnimationUtils::SetBootAnimationSoundEnabled(true);
119     player4->SetVideoSound();
120 }
121 
122 /**
123  * @tc.name: BootVideoPlayerTest_004
124  * @tc.desc: Verify the OnInfo
125  * @tc.type:FUNC
126  */
127 HWTEST_F(BootVideoPlayerTest, BootVideoPlayerTest_004, TestSize.Level1)
128 {
129     PlayerParams params;
130     BootAnimationCallback callback_ = {
131         .userData = this,
__anonc56a43d50402() 132         .callback = [&](void*) {},
133     };
134     params.callback = &callback_;
135     std::shared_ptr<BootVideoPlayer> player = std::make_shared<BootVideoPlayer>(params);
136     player->mediaPlayer_ = Media::PlayerFactory::CreatePlayer();
137     std::shared_ptr<VideoPlayerCallback> cb = std::make_shared<VideoPlayerCallback>(player);
138     Media::Format format;
139     cb->OnInfo(Media::INFO_TYPE_SEEKDONE, 0, format);
140 
141     cb->OnInfo(Media::INFO_TYPE_SPEEDDONE, 0, format);
142 
143     cb->OnInfo(Media::INFO_TYPE_BITRATEDONE, 0, format);
144 
145     cb->OnInfo(Media::INFO_TYPE_EOS, 0, format);
146 
147     cb->OnInfo(Media::INFO_TYPE_BUFFERING_UPDATE, 0, format);
148 
149     cb->OnInfo(Media::INFO_TYPE_BITRATE_COLLECT, 0, format);
150 
151     cb->OnInfo(Media::INFO_TYPE_STATE_CHANGE, 0, format);
152 
153     if (player->GetMediaPlayer() != nullptr) {
154         cb->OnInfo(Media::INFO_TYPE_STATE_CHANGE, Media::PlayerStates::PLAYER_PREPARED, format);
155     }
156 
157     cb->OnInfo(Media::INFO_TYPE_POSITION_UPDATE, 0, format);
158 
159     cb->OnInfo(Media::INFO_TYPE_MESSAGE, 0, format);
160 
161     system::SetParameter(BOOT_ANIMATION_STARTED, "false");
162     cb->OnInfo(Media::INFO_TYPE_MESSAGE, 0, format);
163     EXPECT_EQ(system::GetBoolParameter(BOOT_ANIMATION_STARTED, false), true);
164 
165     cb->OnInfo(Media::INFO_TYPE_RESOLUTION_CHANGE, 0, format);
166 
167     cb->OnInfo(Media::INFO_TYPE_VOLUME_CHANGE, 0, format);
168 
169     cb->OnInfo(Media::INFO_TYPE_SUBTITLE_UPDATE, 0, format);
170 }
171 
172 /**
173  * @tc.name: BootVideoPlayerTest_005
174  * @tc.desc: Verify the Play
175  * @tc.type:FUNC
176  */
177 HWTEST_F(BootVideoPlayerTest, BootVideoPlayerTest_005, TestSize.Level1)
178 {
179     PlayerParams params;
180     params.surface = nullptr;
181     BootAnimationCallback callback_ = {
182         .userData = this,
__anonc56a43d50502() 183         .callback = [&](void*) {},
184     };
185     params.callback = &callback_;
186     std::shared_ptr<BootVideoPlayer> player = std::make_shared<BootVideoPlayer>(params);
187     player->Play();
188     ASSERT_NE(nullptr, player->mediaPlayer_);
189 }
190 }
191