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_operation.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS::Rosen {
25 class BootAnimationOperationTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31 };
32
SetUpTestCase()33 void BootAnimationOperationTest::SetUpTestCase() {}
TearDownTestCase()34 void BootAnimationOperationTest::TearDownTestCase() {}
SetUp()35 void BootAnimationOperationTest::SetUp() {}
TearDown()36 void BootAnimationOperationTest::TearDown() {}
37
38 /**
39 * @tc.name: BootAnimationOperationTest_001
40 * @tc.desc: Verify the SetSoundEnable
41 * @tc.type:FUNC
42 */
43 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_001, TestSize.Level0)
44 {
45 BootAnimationOperation operation;
46 operation.SetSoundEnable(true);
47 EXPECT_EQ(operation.isSoundEnabled_, true);
48 }
49
50 /**
51 * @tc.name: BootAnimationOperationTest_002
52 * @tc.desc: Verify the SetSoundEnable
53 * @tc.type:FUNC
54 */
55 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_002, TestSize.Level0)
56 {
57 BootAnimationOperation operation;
58 operation.SetSoundEnable(false);
59 EXPECT_EQ(operation.isSoundEnabled_, false);
60 }
61
62 /**
63 * @tc.name: BootAnimationOperationTest_003
64 * @tc.desc: Verify the InitRsDisplayNode
65 * @tc.type:FUNC
66 */
67 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_003, TestSize.Level1)
68 {
69 BootAnimationOperation operation;
70 operation.InitRsDisplayNode();
71 ASSERT_NE(nullptr, operation.rsDisplayNode_);
72 }
73
74 /**
75 * @tc.name: BootAnimationOperationTest_004
76 * @tc.desc: Verify the InitRsSurfaceNode
77 * @tc.type:FUNC
78 */
79 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_004, TestSize.Level1)
80 {
81 BootAnimationOperation operation;
82 int32_t degree = 0;
83 operation.InitRsDisplayNode();
84 operation.InitRsSurfaceNode(degree);
85 ASSERT_NE(nullptr, operation.rsSurfaceNode_);
86 }
87
88 /**
89 * @tc.name: BootAnimationOperationTest_005
90 * @tc.desc: Verify the InitRsSurface
91 * @tc.type:FUNC
92 */
93 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_005, TestSize.Level1)
94 {
95 BootAnimationOperation operation;
96 int32_t degree = 0;
97 operation.InitRsDisplayNode();
98 operation.InitRsSurfaceNode(degree);
99 operation.InitRsSurface();
100 ASSERT_NE(nullptr, operation.rsSurface_);
101 }
102
103 /**
104 * @tc.name: BootAnimationOperationTest_006
105 * @tc.desc: Verify the IsBootVideoEnabled
106 * @tc.type:FUNC
107 */
108 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_006, TestSize.Level0)
109 {
110 BootAnimationOperation operation;
111 BootAnimationConfig config;
112 config.picZipPath = "abc";
113 EXPECT_EQ(false, operation.IsBootVideoEnabled(config));
114 }
115
116 /**
117 * @tc.name: BootAnimationOperationTest_007
118 * @tc.desc: Verify the IsBootVideoEnabled
119 * @tc.type:FUNC
120 */
121 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_007, TestSize.Level0)
122 {
123 BootAnimationOperation operation;
124 BootAnimationConfig config;
125 config.videoDefaultPath = "abc";
126 EXPECT_EQ(true, operation.IsBootVideoEnabled(config));
127 }
128
129 /**
130 * @tc.name: BootAnimationOperationTest_008
131 * @tc.desc: Verify the StartEventHandler
132 * @tc.type:FUNC
133 */
134 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_008, TestSize.Level1)
135 {
136 BootAnimationOperation operation;
137 BootAnimationConfig config1;
138 config1.videoDefaultPath = "abc";
139 EXPECT_EQ(true, operation.IsBootVideoEnabled(config1));
140 operation.StartEventHandler(config1);
141
142 BootAnimationConfig config2;
143 config2.picZipPath = "abc";
144 EXPECT_EQ(false, operation.IsBootVideoEnabled(config2));
145 operation.StartEventHandler(config2);
146 }
147
148 /**
149 * @tc.name: BootAnimationOperationTest_009
150 * @tc.desc: Verify the InitRsSurfaceNode
151 * @tc.type:FUNC
152 */
153 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_009, TestSize.Level1)
154 {
155 BootAnimationOperation operation;
156 int32_t degree = 0;
157 system::SetParameter(BOOT_ANIMATION_READY, "true");
158 operation.InitRsDisplayNode();
159 operation.InitRsSurfaceNode(degree);
160 ASSERT_NE(nullptr, operation.rsSurfaceNode_);
161 }
162
163 /**
164 * @tc.name: BootAnimationOperationTest_010
165 * @tc.desc: Verify the PlayPicture
166 * @tc.type:FUNC
167 */
168 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_010, TestSize.Level1)
169 {
170 BootAnimationOperation operation;
171 std::string path = "abc";
172 operation.runner_ = AppExecFwk::EventRunner::Create(false);
173 system::SetParameter(BOOT_ANIMATION_STARTED, "false");
174 operation.PlayPicture(path);
175
176 system::SetParameter(BOOT_ANIMATION_STARTED, "true");
177 operation.PlayPicture(path);
178 EXPECT_EQ(system::GetParameter(BOOT_ANIMATION_STARTED, "false"), "true");
179 }
180
181 /**
182 * @tc.name: BootAnimationOperationTest_011
183 * @tc.desc: Verify the IsBootVideoEnabled
184 * @tc.type:FUNC
185 */
186 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_011, TestSize.Level1)
187 {
188 BootAnimationOperation operation;
189 BootAnimationConfig config;
190 EXPECT_EQ(true, operation.IsBootVideoEnabled(config));
191
192 config.videoDefaultPath = "abc";
193 config.picZipPath = "abc";
194 EXPECT_EQ(true, operation.IsBootVideoEnabled(config));
195 }
196
197 /**
198 * @tc.name: BootAnimationOperationTest_012
199 * @tc.desc: Verify the StopBootAnimation
200 * @tc.type:FUNC
201 */
202 HWTEST_F(BootAnimationOperationTest, BootAnimationOperationTest_012, TestSize.Level1)
203 {
204 BootAnimationOperation operation;
205 operation.runner_ = AppExecFwk::EventRunner::Create(false);
206 operation.mainHandler_ = std::make_shared<AppExecFwk::EventHandler>(operation.runner_);
207 system::SetParameter(BOOT_ANIMATION_STARTED, "false");
__anon4ca7a6240102null208 operation.mainHandler_->PostTask([&operation] { operation.StopBootAnimation(); });
209 EXPECT_EQ(system::GetParameter(BOOT_ANIMATION_STARTED, "true"), "false");
210 operation.runner_->Run();
211
212 operation.mainHandler_ = std::make_shared<AppExecFwk::EventHandler>(operation.runner_);
213 system::SetParameter(BOOT_ANIMATION_STARTED, "true");
__anon4ca7a6240202null214 operation.mainHandler_->PostTask([&operation] { operation.StopBootAnimation(); });
215 EXPECT_EQ(system::GetParameter(BOOT_ANIMATION_STARTED, "false"), "true");
216 operation.runner_->Run();
217 }
218 }
219