1 /*
2  * Copyright (c) 2023 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 #include "animation/rs_animation.h"
18 #include "ui/rs_node.h"
19 #include <unistd.h>
20 #ifdef ROSEN_OHOS
21 #include "base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include/hisysevent.h"
22 #include "sandbox_utils.h"
23 #endif
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS::Rosen {
28 class RSAnimationTest : 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 RSAnimationTest::SetUpTestCase() {}
TearDownTestCase()37 void RSAnimationTest::TearDownTestCase() {}
SetUp()38 void RSAnimationTest::SetUp() {}
TearDown()39 void RSAnimationTest::TearDown() {}
40 
41 /**
42  * @tc.name: SetFinishCallbackTest
43  * @tc.desc:
44  * @tc.type:FUNC
45  */
HWTEST_F(RSAnimationTest,SetFinishCallbackTest,Level1)46 HWTEST_F(RSAnimationTest, SetFinishCallbackTest, Level1)
47 {
48     RSAnimation rsAnimation;
49     auto finishCallback = std::function<void()>();
50     rsAnimation.SetFinishCallback(finishCallback);
51     ASSERT_EQ(finishCallback, nullptr);
52 }
53 
54 /**
55  * @tc.name: StartTest001
56  * @tc.desc:
57  * @tc.type:FUNC
58  */
HWTEST_F(RSAnimationTest,StartTest001,Level1)59 HWTEST_F(RSAnimationTest, StartTest001, Level1)
60 {
61     RSAnimation rsAnimation;
62     auto target = std::shared_ptr<RSNode>();
63     rsAnimation.Start(target);
64     ASSERT_EQ(target, nullptr);
65 }
66 
67 /**
68  * @tc.name: StartTest002
69  * @tc.desc:
70  * @tc.type:FUNC
71  */
HWTEST_F(RSAnimationTest,StartTest002,Level1)72 HWTEST_F(RSAnimationTest, StartTest002, Level1)
73 {
74     RSAnimation rsAnimation;
75     auto per = std::make_shared<RSNode>(true);
76     rsAnimation.StartInner(per);
77     rsAnimation.Start(per);
78     ASSERT_NE(per, nullptr);
79 }
80 
81 /**
82  * @tc.name: StartInnerTest
83  * @tc.desc:
84  * @tc.type:FUNC
85  */
HWTEST_F(RSAnimationTest,StartInnerTest,Level1)86 HWTEST_F(RSAnimationTest, StartInnerTest, Level1)
87 {
88     RSAnimation rsAnimation;
89     auto target = std::shared_ptr<RSNode>();
90     rsAnimation.StartInner(target);
91     ASSERT_EQ(target, nullptr);
92 }
93 
94 /**
95  * @tc.name: OnPauseTest
96  * @tc.desc:
97  * @tc.type:FUNC
98  */
HWTEST_F(RSAnimationTest,OnPauseTest,Level1)99 HWTEST_F(RSAnimationTest, OnPauseTest, Level1)
100 {
101     RSAnimation rsAnimation;
102     auto target = std::shared_ptr<RSNode>();
103     rsAnimation.OnPause();
104     ASSERT_EQ(target, nullptr);
105 }
106 
107 /**
108  * @tc.name: ResumeTest001
109  * @tc.desc:
110  * @tc.type:FUNC
111  */
HWTEST_F(RSAnimationTest,ResumeTest001,Level1)112 HWTEST_F(RSAnimationTest, ResumeTest001, Level1)
113 {
114     RSAnimation rsAnimation;
115     auto target = std::shared_ptr<RSNode>();
116     rsAnimation.Resume();
117     ASSERT_EQ(target, nullptr);
118 }
119 
120 /**
121  * @tc.name: ResumeTest002
122  * @tc.desc:
123  * @tc.type:FUNC
124  */
HWTEST_F(RSAnimationTest,ResumeTest002,Level1)125 HWTEST_F(RSAnimationTest, ResumeTest002, Level1)
126 {
127     RSAnimation rsAnimation;
128     auto per = std::make_shared<RSNode>(true);
129     rsAnimation.StartInner(per);
130     rsAnimation.Resume();
131     ASSERT_NE(per, nullptr);
132 }
133 
134 /**
135  * @tc.name: OnResumeTest
136  * @tc.desc:
137  * @tc.type:FUNC
138  */
HWTEST_F(RSAnimationTest,OnResumeTest,Level1)139 HWTEST_F(RSAnimationTest, OnResumeTest, Level1)
140 {
141     RSAnimation rsAnimation;
142     auto target = std::shared_ptr<RSNode>();
143     rsAnimation.OnResume();
144     ASSERT_EQ(target, nullptr);
145 }
146 
147 /**
148  * @tc.name: FinishTest001
149  * @tc.desc:
150  * @tc.type:FUNC
151  */
HWTEST_F(RSAnimationTest,FinishTest001,Level1)152 HWTEST_F(RSAnimationTest, FinishTest001, Level1)
153 {
154     RSAnimation rsAnimation;
155     auto target = std::shared_ptr<RSNode>();
156     rsAnimation.Finish();
157     ASSERT_EQ(target, nullptr);
158 }
159 
160 /**
161  * @tc.name: FinishTest002
162  * @tc.desc:
163  * @tc.type:FUNC
164  */
HWTEST_F(RSAnimationTest,FinishTest002,Level1)165 HWTEST_F(RSAnimationTest, FinishTest002, Level1)
166 {
167     RSAnimation rsAnimation;
168     auto per = std::make_shared<RSNode>(true);
169     rsAnimation.CallFinishCallback();
170     rsAnimation.Finish();
171     ASSERT_NE(per, nullptr);
172 }
173 
174 /**
175  * @tc.name: OnFinishTest
176  * @tc.desc:
177  * @tc.type:FUNC
178  */
HWTEST_F(RSAnimationTest,OnFinishTest,Level1)179 HWTEST_F(RSAnimationTest, OnFinishTest, Level1)
180 {
181     RSAnimation rsAnimation;
182     auto target = std::shared_ptr<RSNode>();
183     rsAnimation.OnFinish();
184     ASSERT_EQ(target, nullptr);
185 }
186 
187 /**
188  * @tc.name: ReverseTest001
189  * @tc.desc:
190  * @tc.type:FUNC
191  */
HWTEST_F(RSAnimationTest,ReverseTest001,Level1)192 HWTEST_F(RSAnimationTest, ReverseTest001, Level1)
193 {
194     RSAnimation rsAnimation;
195     auto target = std::shared_ptr<RSNode>();
196     rsAnimation.Reverse();
197     ASSERT_EQ(target, nullptr);
198 }
199 
200 /**
201  * @tc.name: ReverseTest002
202  * @tc.desc:
203  * @tc.type:FUNC
204  */
HWTEST_F(RSAnimationTest,ReverseTest002,Level1)205 HWTEST_F(RSAnimationTest, ReverseTest002, Level1)
206 {
207     RSAnimation rsAnimation;
208     auto per = std::make_shared<RSNode>(true);
209     rsAnimation.CallFinishCallback();
210     rsAnimation.Reverse();
211     ASSERT_NE(per, nullptr);
212 }
213 
214 /**
215  * @tc.name: OnReverseTest
216  * @tc.desc:
217  * @tc.type:FUNC
218  */
HWTEST_F(RSAnimationTest,OnReverseTest,Level1)219 HWTEST_F(RSAnimationTest, OnReverseTest, Level1)
220 {
221     RSAnimation rsAnimation;
222     auto target = std::shared_ptr<RSNode>();
223     rsAnimation.OnReverse();
224     ASSERT_EQ(target, nullptr);
225 }
226 
227 /**
228  * @tc.name: SetFractionTest001
229  * @tc.desc:
230  * @tc.type:FUNC
231  */
HWTEST_F(RSAnimationTest,SetFractionTest001,Level1)232 HWTEST_F(RSAnimationTest, SetFractionTest001, Level1)
233 {
234     RSAnimation rsAnimation;
235     auto target = std::shared_ptr<RSNode>();
236     float frac = 3.f;
237     rsAnimation.SetFraction(frac);
238     ASSERT_EQ(target, nullptr);
239 }
240 
241 /**
242  * @tc.name: SetFractionTest002
243  * @tc.desc:
244  * @tc.type:FUNC
245  */
HWTEST_F(RSAnimationTest,SetFractionTest002,Level1)246 HWTEST_F(RSAnimationTest, SetFractionTest002, Level1)
247 {
248     RSAnimation rsAnimation;
249     float frac = 0.0f;
250     auto per = std::make_shared<RSNode>(true);
251     rsAnimation.CallFinishCallback();
252     rsAnimation.SetFraction(frac);
253     ASSERT_NE(per, nullptr);
254 }
255 
256 /**
257  * @tc.name: UpdateParamToRenderAnimationTest
258  * @tc.desc:
259  * @tc.type:FUNC
260  */
HWTEST_F(RSAnimationTest,UpdateParamToRenderAnimationTest,Level1)261 HWTEST_F(RSAnimationTest, UpdateParamToRenderAnimationTest, Level1)
262 {
263     RSAnimation rsAnimation;
264     auto animation = std::make_shared<RSRenderAnimation>();
265     rsAnimation.UpdateParamToRenderAnimation(animation);
266     ASSERT_NE(animation, nullptr);
267 }
268 
269 /**
270  * @tc.name: StartCustomAnimationTest
271  * @tc.desc:
272  * @tc.type:FUNC
273  */
HWTEST_F(RSAnimationTest,StartCustomAnimationTest,Level1)274 HWTEST_F(RSAnimationTest, StartCustomAnimationTest, Level1)
275 {
276     RSAnimation rsAnimation;
277     auto animation = std::make_shared<RSRenderAnimation>();
278     rsAnimation.StartCustomAnimation(animation);
279     ASSERT_NE(animation, nullptr);
280 }
281 
282 /**
283  * @tc.name: PauseTest001
284  * @tc.desc:
285  * @tc.type:FUNC
286  */
HWTEST_F(RSAnimationTest,PauseTest001,Level1)287 HWTEST_F(RSAnimationTest, PauseTest001, Level1)
288 {
289     RSAnimation rsAnimation;
290     auto target = std::shared_ptr<RSNode>();
291     rsAnimation.Pause();
292     ASSERT_EQ(target, nullptr);
293 }
294 
295 /**
296  * @tc.name: PauseTest002
297  * @tc.desc:
298  * @tc.type:FUNC
299  */
HWTEST_F(RSAnimationTest,PauseTest002,Level1)300 HWTEST_F(RSAnimationTest, PauseTest002, Level1)
301 {
302     RSAnimation rsAnimation;
303     auto per = std::make_shared<RSNode>(true);
304     rsAnimation.StartInner(per);
305     rsAnimation.Pause();
306     ASSERT_NE(per, nullptr);
307 }
308 }