• 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, Hardware
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 "utils/matrix.h"
19 #include "utils/point.h"
20 #include "utils/scalar.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class MatrixTest : 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 MatrixTest::SetUpTestCase() {}
TearDownTestCase()37 void MatrixTest::TearDownTestCase() {}
SetUp()38 void MatrixTest::SetUp() {}
TearDown()39 void MatrixTest::TearDown() {}
40 
41 /**
42  * @tc.name: CreateAndDestroy001
43  * @tc.desc:
44  * @tc.type: FUNC
45  * @tc.require:AR000GGNV3
46  * @tc.author:
47  */
48 HWTEST_F(MatrixTest, CreateAndDestroy001, TestSize.Level1)
49 {
50     // The best way to create Matrix.
51     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
52     ASSERT_TRUE(matrix != nullptr);
53 }
54 
55 /**
56  * @tc.name: CreateAndDestroy002
57  * @tc.desc:
58  * @tc.type: FUNC
59  * @tc.require:AR000GGNV3
60  * @tc.author:
61  */
62 HWTEST_F(MatrixTest, CreateAndDestroy002, TestSize.Level1)
63 {
64     // The best way to create Matrix.
65     Matrix matrix;
66 }
67 
68 /**
69  * @tc.name: MatrixRotateTest001
70  * @tc.desc:
71  * @tc.type: FUNC
72  * @tc.require:AR000GGNV3
73  * @tc.author:
74  */
75 HWTEST_F(MatrixTest, MatrixRotateTest001, TestSize.Level1)
76 {
77     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
78     ASSERT_TRUE(matrix != nullptr);
79     matrix->Rotate(0.1f, 150.1f, 650.9f);
80 }
81 
82 /**
83  * @tc.name: MatrixRotateTest002
84  * @tc.desc:
85  * @tc.type: FUNC
86  * @tc.require:AR000GGNV3
87  * @tc.author:
88  */
89 HWTEST_F(MatrixTest, MatrixRotateTest002, TestSize.Level1)
90 {
91     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
92     ASSERT_TRUE(matrix != nullptr);
93     matrix->Rotate(20.8f, 133.0f, 100);
94 }
95 
96 /**
97  * @tc.name: MatrixTranslateTest001
98  * @tc.desc:
99  * @tc.type: FUNC
100  * @tc.require:AR000GGNV3
101  * @tc.author:
102  */
103 HWTEST_F(MatrixTest, MatrixTranslateTest001, TestSize.Level1)
104 {
105     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
106     ASSERT_TRUE(matrix != nullptr);
107     matrix->Translate(20.8f, 100);
108 }
109 
110 /**
111  * @tc.name: MatrixTranslateTest002
112  * @tc.desc:
113  * @tc.type: FUNC
114  * @tc.require:AR000GGNV3
115  * @tc.author:
116  */
117 HWTEST_F(MatrixTest, MatrixTranslateTest002, TestSize.Level1)
118 {
119     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
120     ASSERT_TRUE(matrix != nullptr);
121     matrix->Translate(77.7f, 190.2f);
122 }
123 
124 /**
125  * @tc.name: MatrixScaleTest001
126  * @tc.desc:
127  * @tc.type: FUNC
128  * @tc.require:AR000GGNV3
129  * @tc.author:
130  */
131 HWTEST_F(MatrixTest, MatrixScaleTest001, TestSize.Level1)
132 {
133     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
134     ASSERT_TRUE(matrix != nullptr);
135     matrix->Scale(32.1f, 10.6f, 800, 90.1f);
136 }
137 
138 /**
139  * @tc.name: MatrixScaleTest002
140  * @tc.desc:
141  * @tc.type: FUNC
142  * @tc.require:AR000GGNV3
143  * @tc.author:
144  */
145 HWTEST_F(MatrixTest, MatrixScaleTest002, TestSize.Level1)
146 {
147     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
148     ASSERT_TRUE(matrix != nullptr);
149     matrix->Scale(16.5f, 50.6f, 150.8f, 560.9f);
150 }
151 
152 /**
153  * @tc.name: MatrixMultiplyTest001
154  * @tc.desc:
155  * @tc.type: FUNC
156  * @tc.require:AR000GGNV3
157  * @tc.author:
158  */
159 HWTEST_F(MatrixTest, MatrixMultiplyTest001, TestSize.Level1)
160 {
161     Matrix matrix1;
162     Matrix matrix2;
163     matrix1.Rotate(3.0f, 2.0f, 1.0f);
164     matrix2.Rotate(1.5f, 2.5f, 3.5f);
165     Matrix matrix3 = matrix1 * matrix2;
166     EXPECT_TRUE(matrix3 == matrix1);
167     EXPECT_FALSE(matrix3 == matrix2);
168 }
169 
170 /**
171  * @tc.name: MatrixMultiplyTest002
172  * @tc.desc:
173  * @tc.type: FUNC
174  * @tc.require:AR000GGNV3
175  * @tc.author:
176  */
177 HWTEST_F(MatrixTest, MatrixMultiplyTest002, TestSize.Level1)
178 {
179     Matrix matrix1;
180     Matrix matrix2;
181     matrix1.Rotate(3.7f, 6.0f, 1.9f);
182     matrix2.Rotate(5.5f, 12.5f, 30.5f);
183     Matrix matrix3 = matrix1 * matrix2;
184     EXPECT_TRUE(matrix3 == matrix1);
185     EXPECT_FALSE(matrix3 == matrix2);
186 }
187 
188 /**
189  * @tc.name: MatrixEqualTest001
190  * @tc.desc:
191  * @tc.type: FUNC
192  * @tc.require:AR000GGNV3
193  * @tc.author:
194  */
195 HWTEST_F(MatrixTest, MatrixEqualTest001, TestSize.Level1)
196 {
197     Matrix matrix1;
198     Matrix matrix2 = matrix1;
199     EXPECT_TRUE(matrix1 == matrix2);
200 }
201 
202 /**
203  * @tc.name: MatrixEqualTest002
204  * @tc.desc:
205  * @tc.type: FUNC
206  * @tc.require:AR000GGNV3
207  * @tc.author:
208  */
209 HWTEST_F(MatrixTest, MatrixEqualTest002, TestSize.Level1)
210 {
211     Matrix matrix1;
212     matrix1.Rotate(1.0f, 2.0f, 3.0f);
213     Matrix matrix2;
214     EXPECT_FALSE(matrix1 == matrix2);
215 }
216 
217 /**
218  * @tc.name: MatrixSetMatrixTest001
219  * @tc.desc:
220  * @tc.type: FUNC
221  * @tc.require:AR000GGNV3
222  * @tc.author:
223  */
224 HWTEST_F(MatrixTest, MatrixSetMatrixTest001, TestSize.Level1)
225 {
226     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
227     ASSERT_TRUE(matrix != nullptr);
228     matrix->SetMatrix(200, 150, 800, 60, 200, 150, 800, 60, 90);
229 }
230 
231 /**
232  * @tc.name: MatrixSetMatrixTest002
233  * @tc.desc:
234  * @tc.type: FUNC
235  * @tc.require:AR000GGNV3
236  * @tc.author:
237  */
238 HWTEST_F(MatrixTest, MatrixSetMatrixTest002, TestSize.Level1)
239 {
240     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
241     ASSERT_TRUE(matrix != nullptr);
242     matrix->SetMatrix(20.9f, 15.8f, 80.8f, 60, 2.4f, 99.9f, 60, 60, 900);
243 }
244 
245 /**
246  * @tc.name: MatrixSetMatrixTest003
247  * @tc.desc:
248  * @tc.type: FUNC
249  * @tc.require:AR000GGNV3
250  * @tc.author:
251  */
252 HWTEST_F(MatrixTest, MatrixSetMatrixTest003, TestSize.Level1)
253 {
254     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
255     ASSERT_TRUE(matrix != nullptr);
256     matrix->SetMatrix(20.9f, 15.8f, 80.8f, 60.6f, 2.4f, 99.9f, 60.5f, 60.1f, 90.5f);
257 }
258 
259 /**
260  * @tc.name: MatrixMapPointsTest001
261  * @tc.desc:
262  * @tc.type: FUNC
263  * @tc.require:AR000GGNV3
264  * @tc.author:
265  */
266 HWTEST_F(MatrixTest, MatrixMapPointsTest001, TestSize.Level1)
267 {
268     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
269     ASSERT_TRUE(matrix != nullptr);
270     std::vector<Point> dst = { { 1, 2 } };
271     std::vector<Point> src = { { 2, 3 } };
272     matrix->MapPoints(dst, src, 100);
273 }
274 
275 /**
276  * @tc.name: MatrixMapPointsTest002
277  * @tc.desc:
278  * @tc.type: FUNC
279  * @tc.require:AR000GGNV3
280  * @tc.author:
281  */
282 HWTEST_F(MatrixTest, MatrixMapPointsTest002, TestSize.Level1)
283 {
284     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
285     ASSERT_TRUE(matrix != nullptr);
286     std::vector<Point> dst = { { 3, 2 } };
287     std::vector<Point> src = { { 1, 3 } };
288     matrix->MapPoints(dst, src, 191);
289 }
290 
291 /**
292  * @tc.name: MatrixGetTest001
293  * @tc.desc:
294  * @tc.type: FUNC
295  * @tc.require:AR000GGNV3
296  * @tc.author:
297  */
298 HWTEST_F(MatrixTest, MatrixGetTest001, TestSize.Level1)
299 {
300     std::unique_ptr<Matrix> matrix = std::make_unique<Matrix>();
301     ASSERT_TRUE(matrix != nullptr);
302     ASSERT_EQ(1, matrix->Get(0));
303 }
304 } // namespace Drawing
305 } // namespace Rosen
306 } // namespace OHOS
307