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 "event_handler.h"
19 #include "vsync_receiver.h"
20 #include "util.h"
21 #include "boot_animation_operation.h"
22 #include "boot_picture_player.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS::Rosen {
28 class BootPicturePlayerTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase()36 void BootPicturePlayerTest::SetUpTestCase() {}
TearDownTestCase()37 void BootPicturePlayerTest::TearDownTestCase() {}
SetUp()38 void BootPicturePlayerTest::SetUp() {}
TearDown()39 void BootPicturePlayerTest::TearDown() {}
40
41 /**
42 * @tc.name: BootPicturePlayerTest_001
43 * @tc.desc: Verify the ReadPicZipFile
44 * @tc.type:FUNC
45 */
46 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_001, TestSize.Level1)
47 {
48 PlayerParams params;
49 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
50 ImageStructVec imgVec;
51 int32_t freq = 30;
52 EXPECT_EQ(player->ReadPicZipFile(imgVec, freq), true);
53 }
54
55 /**
56 * @tc.name: BootPicturePlayerTest_002
57 * @tc.desc: Verify the CheckFrameRateValid
58 * @tc.type:FUNC
59 */
60 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_002, TestSize.Level1)
61 {
62 PlayerParams params;
63 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
64 int32_t frameRate = 0;
65 EXPECT_EQ(player->CheckFrameRateValid(frameRate), false);
66 }
67
68 /**
69 * @tc.name: BootPicturePlayerTest_003
70 * @tc.desc: Verify the CheckFrameRateValid
71 * @tc.type:FUNC
72 */
73 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_003, TestSize.Level1)
74 {
75 PlayerParams params;
76 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
77 int32_t frameRate = 30;
78 EXPECT_EQ(player->CheckFrameRateValid(frameRate), true);
79 }
80
81 /**
82 * @tc.name: BootPicturePlayerTest_004
83 * @tc.desc: Verify the Play
84 * @tc.type:FUNC
85 */
86 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_004, TestSize.Level1)
87 {
88 PlayerParams params;
89 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
90 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(false);
91 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler = std::make_shared<AppExecFwk::EventHandler>(runner);
92 int flag = 0;
__anonb09abd5a0102null93 handler->PostTask([&] {
94 player->Play();
95 flag = 1;
96 runner->Stop();
97 });
98 runner->Run();
99 EXPECT_EQ(flag, 1);
100
101 player->receiver_ = nullptr;
102 auto& rsClient = OHOS::Rosen::RSInterfaces::GetInstance();
103 player->receiver_ = rsClient.CreateVSyncReceiver("BootAnimation", handler);
__anonb09abd5a0202null104 handler->PostTask([&] {
105 player->Play();
106 flag = 0;
107 runner->Stop();
108 });
109 runner->Run();
110 EXPECT_EQ(flag, 0);
111
112 ImageStructVec imgVec;
113 player->imageVector_ = imgVec;
__anonb09abd5a0302null114 handler->PostTask([&] {
115 player->Play();
116 flag = 1;
117 runner->Stop();
118 });
119 runner->Run();
120 EXPECT_EQ(flag, 1);
121 }
122
123 /**
124 * @tc.name: BootPicturePlayerTest_005
125 * @tc.desc: Verify the GetPicZipPath
126 * @tc.type:FUNC
127 */
128 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_005, TestSize.Level1)
129 {
130 PlayerParams params;
131 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
132 params.resPath = "/system/etc/graphic/bootpic.zip";
133 EXPECT_EQ(player->GetPicZipPath(), "/system/etc/graphic/bootpic.zip");
134 }
135
136 /**
137 * @tc.name: BootPicturePlayerTest_006
138 * @tc.desc: Verify the Draw
139 * @tc.type:FUNC
140 */
141 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_006, TestSize.Level1)
142 {
143 BootAnimationOperation operation;
144 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(false);
145 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler = std::make_shared<AppExecFwk::EventHandler>(runner);
146 int32_t degree = 0;
147 operation.InitRsDisplayNode();
148 operation.InitRsSurfaceNode(degree);
149 operation.InitRsSurface();
150 ASSERT_NE(nullptr, operation.rsSurface_);
151 PlayerParams params;
152 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
153 player->rsSurface_ = operation.rsSurface_;
154 player->picCurNo_ = 2;
155 player->imgVecSize_ = 0;
__anonb09abd5a0402null156 handler->PostTask([&] {
157 player->Draw();
158 runner->Stop();
159 });
160 runner->Run();
161
162 ImageStructVec imgVec;
163 player->imageVector_ = imgVec;
164 player->picCurNo_ = -2;
165 player->imgVecSize_ = 0;
__anonb09abd5a0502null166 handler->PostTask([&] {
167 player->Draw();
168 runner->Stop();
169 });
170 runner->Run();
171 }
172
173 /**
174 * @tc.name: BootPicturePlayerTest_007
175 * @tc.desc: Verify the OnDraw
176 * @tc.type:FUNC
177 */
178 HWTEST_F(BootPicturePlayerTest, BootPicturePlayerTest_007, TestSize.Level1)
179 {
180 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(false);
181 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler = std::make_shared<AppExecFwk::EventHandler>(runner);
182 PlayerParams params;
183 bool flag = false;
184 std::shared_ptr<BootPicturePlayer> player = std::make_shared<BootPicturePlayer>(params);
__anonb09abd5a0602null185 handler->PostTask([&] {
186 flag = player->OnDraw(nullptr, 0);
187 runner->Stop();
188 });
189 runner->Run();
190 EXPECT_EQ(flag, false);
191
192 Rosen::Drawing::CoreCanvas canvas;
__anonb09abd5a0702null193 handler->PostTask([&] {
194 flag = player->OnDraw(&canvas, 0);
195 runner->Stop();
196 });
197 runner->Run();
198 EXPECT_EQ(flag, false);
199
200 player->imgVecSize_ = 1;
__anonb09abd5a0802null201 handler->PostTask([&] {
202 flag = player->OnDraw(&canvas, -1);
203 runner->Stop();
204 });
205 runner->Run();
206 EXPECT_EQ(flag, false);
207
208 player->imgVecSize_ = -1;
__anonb09abd5a0902null209 handler->PostTask([&] {
210 flag = player->OnDraw(&canvas, -1);
211 runner->Stop();
212 });
213 runner->Run();
214 EXPECT_EQ(flag, false);
215
216 ImageStructVec imgVec;
217 player->imageVector_ = imgVec;
218 player->picCurNo_ = 0;
219 player->imgVecSize_ = 2;
220 player->OnVsync();
221 flag = player->Stop();
222 EXPECT_EQ(flag, false);
223 }
224 }
225