• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "base/memory/referenced.h"
18 // Add the following two macro definitions to test the private and protected method.
19 #define private public
20 #define protected public
21 #include "base/geometry/animatable_matrix4.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS::Ace {
27 namespace {
28 const int32_t VALID_ROW0 = 0;
29 const int32_t VALID_COL0 = 0;
30 const double DEFAULT_DOUBLE0 = 0.0;
31 }
32 
33 class AnimatableMatrix4Test : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase()41 void AnimatableMatrix4Test::SetUpTestCase()
42 {
43     GTEST_LOG_(INFO) << "AnimatableMatrix4Test SetUpTestCase";
44 }
45 
TearDownTestCase()46 void AnimatableMatrix4Test::TearDownTestCase()
47 {
48     GTEST_LOG_(INFO) << "AnimatableMatrix4Test TearDownTestCase";
49 }
50 
SetUp()51 void AnimatableMatrix4Test::SetUp()
52 {
53     GTEST_LOG_(INFO) << "AnimatableMatrix4Test SetUp";
54 }
55 
TearDown()56 void AnimatableMatrix4Test::TearDown()
57 {
58     GTEST_LOG_(INFO) << "AnimatableMatrix4Test TearDown";
59 }
60 
61 /**
62  * @tc.name: AnimatableMatrix4Test001
63  * @tc.desc: Test the function operator= of the class AnimatableMatrix4.
64  * @tc.type: FUNC
65  */
66 HWTEST_F(AnimatableMatrix4Test, AnimatableMatrix4Test001, TestSize.Level1)
67 {
68     /**
69      * @tc.steps: Test the function operator= with given Matrix4 object.
70      */
71     AnimatableMatrix4 animatableMatrix4Obj1;
72     Matrix4 matrixObj1 = Matrix4::CreateIdentity();
73     animatableMatrix4Obj1 = matrixObj1;
74     EXPECT_TRUE(animatableMatrix4Obj1.IsIdentityMatrix());
75     matrixObj1.Set(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE0);
76 
77     /**
78      * @tc.steps: Test the function MoveTo with given Matrix4 object.
79      */
80     animatableMatrix4Obj1.MoveTo(matrixObj1);
81     EXPECT_DOUBLE_EQ(animatableMatrix4Obj1.Get(VALID_ROW0, VALID_COL0), DEFAULT_DOUBLE0);
82 
83     /**
84      * @tc.steps: Test the function operator= with given AnimatableMatrix4 object.
85      */
86     AnimatableMatrix4 animatableMatrix4Obj2;
87     animatableMatrix4Obj2 = animatableMatrix4Obj1;
88     EXPECT_DOUBLE_EQ(animatableMatrix4Obj2.Get(VALID_ROW0, VALID_COL0), DEFAULT_DOUBLE0);
89 }
90 
91 /**
92  * @tc.name: AnimatableMatrix4Test002
93  * @tc.desc: Test the function AnimateTo of the class AnimatableMatrix4.
94  * @tc.type: FUNC
95  */
96 HWTEST_F(AnimatableMatrix4Test, AnimatableMatrix4Test002, TestSize.Level1)
97 {
98     /**
99      * @tc.steps: initialize parameters.
100      */
101     AnimatableMatrix4 animatableMatrix4Obj1;
102     Matrix4 endValue = Matrix4::CreateIdentity();
103     EXPECT_TRUE(animatableMatrix4Obj1.isFirstAssign_);
104 
105     /**
106      * @tc.steps: Test the function AnimateTo firstly, enter the first if-branch.
107      */
108     animatableMatrix4Obj1.AnimateTo(endValue);
109     EXPECT_FALSE(animatableMatrix4Obj1.isFirstAssign_);
110     EXPECT_TRUE(animatableMatrix4Obj1.IsIdentityMatrix());
111     EXPECT_EQ(animatableMatrix4Obj1.animationController_, nullptr);
112 
113     /**
114      * @tc.steps: Test the function AnimateTo secondly, enter the second if-branch.
115      */
116     animatableMatrix4Obj1.AnimateTo(animatableMatrix4Obj1);
117     EXPECT_EQ(animatableMatrix4Obj1.animationController_, nullptr);
118 
119     /**
120      * @tc.steps: Test the function AnimateTo thirdly, the function will run until the end of it.
121      */
122     animatableMatrix4Obj1.AnimateTo(endValue);
123     EXPECT_EQ(animatableMatrix4Obj1.animationController_, nullptr);
124 }
125 
126 /**
127  * @tc.name: AnimatableMatrix4Test003
128  * @tc.desc: Test the function ResetController of the class AnimatableMatrix4.
129  * @tc.type: FUNC
130  */
131 HWTEST_F(AnimatableMatrix4Test, AnimatableMatrix4Test003, TestSize.Level1)
132 {
133     AnimatableMatrix4 animatableMatrix4Obj1;
134     animatableMatrix4Obj1.ResetController();
135     animatableMatrix4Obj1.animationController_ = AceType::MakeRefPtr<Animator>(nullptr);
136     EXPECT_NE(animatableMatrix4Obj1.animationController_, nullptr);
137     animatableMatrix4Obj1.ResetController();
138     EXPECT_EQ(animatableMatrix4Obj1.animationController_, nullptr);
139 }
140 
141 /**
142  * @tc.name: AnimatableMatrix4Test004
143  * @tc.desc: Test the function OnAnimationCallback of the class AnimatableMatrix4.
144  * @tc.type: FUNC
145  */
146 HWTEST_F(AnimatableMatrix4Test, AnimatableMatrix4Test004, TestSize.Level1)
147 {
148     /**
149      * @tc.steps: initialize parameters.
150      */
151     TransformOperation transformOperation;
152     AnimatableMatrix4 animatableMatrix4Obj1;
153     animatableMatrix4Obj1.OnAnimationCallback(transformOperation);
154     bool flagEventCbk = false;
__anona0263f010202() 155     animatableMatrix4Obj1.SetContextAndCallback(nullptr, [&flagEventCbk] () { flagEventCbk = true; });
156     /**
157      * @tc.steps: Set the animationCallback_ as the function which changes the value of flagEventCbk,
158      *            the value will be modified when the onReadyEvent is fired.
159      */
160     animatableMatrix4Obj1.OnAnimationCallback(transformOperation);
161     EXPECT_TRUE(flagEventCbk);
162 }
163 
164 /**
165  * @tc.name: AnimatableMatrix4Test005
166  * @tc.desc: Test the function ResetAnimatableMatrix of the class AnimatableMatrix4.
167  * @tc.type: FUNC
168  */
169 HWTEST_F(AnimatableMatrix4Test, AnimatableMatrix4Test005, TestSize.Level1)
170 {
171     AnimatableMatrix4 animatableMatrix4Obj1;
172     animatableMatrix4Obj1.isFirstAssign_ = false;
173     animatableMatrix4Obj1.ResetAnimatableMatrix();
174     EXPECT_TRUE(animatableMatrix4Obj1.isFirstAssign_);
175 }
176 } // namespace OHOS::Ace