1 /*
2 * Copyright (c) 2023-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, 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 "drawing_error_code.h"
19 #include "drawing_matrix.h"
20 #include "drawing_rect.h"
21 #include "utils/scalar.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class NativeDrawingMatrixTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
37 constexpr uint32_t MAPPOINTS_SIZE = 5;
38 constexpr uint32_t MAPPOINTS_COUNT = 2;
39
SetUpTestCase()40 void NativeDrawingMatrixTest::SetUpTestCase() {}
TearDownTestCase()41 void NativeDrawingMatrixTest::TearDownTestCase() {}
SetUp()42 void NativeDrawingMatrixTest::SetUp() {}
TearDown()43 void NativeDrawingMatrixTest::TearDown() {}
44
45 /*
46 * @tc.name: NativeDrawingMatrixTest_SetMatrix001
47 * @tc.desc: test for SetMatrix.
48 * @tc.size : MediumTest
49 * @tc.type : Function
50 * @tc.level : Level 1
51 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetMatrix001, TestSize.Level1)52 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetMatrix001, TestSize.Level1)
53 {
54 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
55 OH_Drawing_MatrixSetMatrix(
56 matrix,
57 1, 0, 0,
58 0, -1, 0,
59 0, 0, 1);
60 OH_Drawing_MatrixDestroy(matrix);
61 OH_Drawing_MatrixDestroy(nullptr);
62 }
63
64 /*
65 * @tc.name: NativeDrawingMatrixTest_SetRectToRect002
66 * @tc.desc: test for SetRectToRect.
67 * @tc.size : MediumTest
68 * @tc.type : Function
69 * @tc.level : Level 1
70 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetRectToRect002, TestSize.Level1)71 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetRectToRect002, TestSize.Level1)
72 {
73 OH_Drawing_Rect *rectSrcOne = OH_Drawing_RectCreate(0, 0, 0, 0);
74 OH_Drawing_Rect *rectDstOne = OH_Drawing_RectCreate(0, 0, 0, 0);
75 OH_Drawing_Matrix *matrixOne = OH_Drawing_MatrixCreate();
76 bool isSuccess = OH_Drawing_MatrixSetRectToRect(matrixOne,
77 rectSrcOne, rectDstOne, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
78 EXPECT_EQ(isSuccess, false);
79 isSuccess = OH_Drawing_MatrixSetRectToRect(nullptr,
80 rectSrcOne, rectDstOne, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
81 EXPECT_EQ(isSuccess, false);
82 isSuccess = OH_Drawing_MatrixSetRectToRect(matrixOne,
83 nullptr, rectDstOne, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
84 EXPECT_EQ(isSuccess, false);
85 isSuccess = OH_Drawing_MatrixSetRectToRect(matrixOne,
86 rectSrcOne, nullptr, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
87 EXPECT_EQ(isSuccess, false);
88 isSuccess = OH_Drawing_MatrixSetRectToRect(nullptr, nullptr, nullptr, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
89 EXPECT_EQ(isSuccess, false);
90
91 OH_Drawing_Rect *rectSrcTwo = OH_Drawing_RectCreate(1, 2, 3, 4);
92 OH_Drawing_Rect *rectDstTwo = OH_Drawing_RectCreate(5, 6, 8, 9);
93 OH_Drawing_Matrix *matrixTwo = OH_Drawing_MatrixCreate();
94 bool isSuccessTwo = OH_Drawing_MatrixSetRectToRect(matrixTwo,
95 rectSrcTwo, rectDstTwo, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
96 EXPECT_EQ(isSuccessTwo, true);
97 float value;
98 value = OH_Drawing_MatrixGetValue(matrixTwo, 0);
99 EXPECT_TRUE(IsScalarAlmostEqual(value, 1.5f));
100 value = OH_Drawing_MatrixGetValue(matrixTwo, 1);
101 EXPECT_TRUE(IsScalarAlmostEqual(value, 0.0f));
102 value = OH_Drawing_MatrixGetValue(matrixTwo, 2);
103 EXPECT_TRUE(IsScalarAlmostEqual(value, 3.5f));
104
105 value = OH_Drawing_MatrixGetValue(matrixTwo, 3);
106 EXPECT_TRUE(IsScalarAlmostEqual(value, 0.0f));
107 value = OH_Drawing_MatrixGetValue(matrixTwo, 4);
108 EXPECT_TRUE(IsScalarAlmostEqual(value, 1.5f));
109 value = OH_Drawing_MatrixGetValue(matrixTwo, 5);
110 EXPECT_TRUE(IsScalarAlmostEqual(value, 3.0f));
111
112 value = OH_Drawing_MatrixGetValue(matrixTwo, 6);
113 EXPECT_TRUE(IsScalarAlmostEqual(value, 0.0f));
114 value = OH_Drawing_MatrixGetValue(matrixTwo, 7);
115 EXPECT_TRUE(IsScalarAlmostEqual(value, 0.0f));
116 value = OH_Drawing_MatrixGetValue(matrixTwo, 8);
117 EXPECT_TRUE(IsScalarAlmostEqual(value, 1.0f));
118
119 OH_Drawing_MatrixDestroy(matrixOne);
120 OH_Drawing_MatrixDestroy(matrixTwo);
121 OH_Drawing_RectDestroy(rectSrcOne);
122 OH_Drawing_RectDestroy(rectDstOne);
123 OH_Drawing_RectDestroy(rectSrcTwo);
124 OH_Drawing_RectDestroy(rectDstTwo);
125 }
126
127 /*
128 * @tc.name: NativeDrawingMatrixTest_Reset003
129 * @tc.desc: test for Reset.
130 * @tc.size : MediumTest
131 * @tc.type : Function
132 * @tc.level : Level 1
133 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Reset003, TestSize.Level1)134 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Reset003, TestSize.Level1)
135 {
136 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
137 OH_Drawing_MatrixSetMatrix(matrix, 2, 0, 0, 0, 1, 2, 0, 0, 1);
138 OH_Drawing_MatrixReset(matrix);
139 bool isIdentity = OH_Drawing_MatrixIsIdentity(matrix);
140 EXPECT_EQ(isIdentity, true);
141 OH_Drawing_MatrixDestroy(matrix);
142 }
143
144 /*
145 * @tc.name: NativeDrawingMatrixTest_CreateRotation004
146 * @tc.desc: test for CreateRotation.
147 * @tc.size : MediumTest
148 * @tc.type : Function
149 * @tc.level : Level 1
150 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_CreateRotation004, TestSize.Level1)151 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_CreateRotation004, TestSize.Level1)
152 {
153 // rotate deg: 180 pivot, point (1, 1)
154 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateRotation(180, 1, 1);
155 float value;
156 value = OH_Drawing_MatrixGetValue(matrix, 0);
157 EXPECT_TRUE(IsScalarAlmostEqual(value, -1));
158 value = OH_Drawing_MatrixGetValue(matrix, 1);
159 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
160 value = OH_Drawing_MatrixGetValue(matrix, 2);
161 EXPECT_TRUE(IsScalarAlmostEqual(value, 2));
162
163 value = OH_Drawing_MatrixGetValue(matrix, 3);
164 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
165 value = OH_Drawing_MatrixGetValue(matrix, 4);
166 EXPECT_TRUE(IsScalarAlmostEqual(value, -1));
167 value = OH_Drawing_MatrixGetValue(matrix, 5);
168 EXPECT_TRUE(IsScalarAlmostEqual(value, 2));
169
170 value = OH_Drawing_MatrixGetValue(matrix, 6);
171 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
172 value = OH_Drawing_MatrixGetValue(matrix, 7);
173 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
174 value = OH_Drawing_MatrixGetValue(matrix, 8);
175 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
176
177 OH_Drawing_MatrixDestroy(matrix);
178 }
179
180 /*
181 * @tc.name: NativeDrawingMatrixTest_CreateScale005
182 * @tc.desc: test for CreateScale.
183 * @tc.size : MediumTest
184 * @tc.type : Function
185 * @tc.level : Level 1
186 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_CreateScale005, TestSize.Level1)187 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_CreateScale005, TestSize.Level1)
188 {
189 /* The first 10 is horizontal scale factor.
190 The second 10 is vertical scale factor.
191 The third 10 is pivot on x-axis.
192 The fourth 10 is the pivot on y-axis.
193 */
194 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateScale(10, 10, 10, 10);
195 float value;
196 value = OH_Drawing_MatrixGetValue(matrix, 0);
197 EXPECT_TRUE(IsScalarAlmostEqual(value, 10));
198 value = OH_Drawing_MatrixGetValue(matrix, 1);
199 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
200 value = OH_Drawing_MatrixGetValue(matrix, 2);
201 EXPECT_TRUE(IsScalarAlmostEqual(value, -90));
202
203 value = OH_Drawing_MatrixGetValue(matrix, 3);
204 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
205 value = OH_Drawing_MatrixGetValue(matrix, 4);
206 EXPECT_TRUE(IsScalarAlmostEqual(value, 10));
207 value = OH_Drawing_MatrixGetValue(matrix, 5);
208 EXPECT_TRUE(IsScalarAlmostEqual(value, -90));
209
210 value = OH_Drawing_MatrixGetValue(matrix, 6);
211 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
212 value = OH_Drawing_MatrixGetValue(matrix, 7);
213 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
214 value = OH_Drawing_MatrixGetValue(matrix, 8);
215 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
216
217 OH_Drawing_MatrixDestroy(matrix);
218 }
219
220 /*
221 * @tc.name: NativeDrawingMatrixTest_CreateTranslation006
222 * @tc.desc: test for CreateTranslation.
223 * @tc.size : MediumTest
224 * @tc.type : Function
225 * @tc.level : Level 1
226 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_CreateTranslation006, TestSize.Level1)227 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_CreateTranslation006, TestSize.Level1)
228 {
229 // translate x= 100, y = 200
230 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateTranslation(100, 200);
231 float value;
232 value = OH_Drawing_MatrixGetValue(matrix, 0);
233 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
234 value = OH_Drawing_MatrixGetValue(matrix, 1);
235 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
236 value = OH_Drawing_MatrixGetValue(matrix, 2);
237 EXPECT_TRUE(IsScalarAlmostEqual(value, 100));
238
239 value = OH_Drawing_MatrixGetValue(matrix, 3);
240 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
241 value = OH_Drawing_MatrixGetValue(matrix, 4);
242 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
243 value = OH_Drawing_MatrixGetValue(matrix, 5);
244 EXPECT_TRUE(IsScalarAlmostEqual(value, 200));
245
246 value = OH_Drawing_MatrixGetValue(matrix, 6);
247 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
248 value = OH_Drawing_MatrixGetValue(matrix, 7);
249 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
250 value = OH_Drawing_MatrixGetValue(matrix, 8);
251 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
252
253 OH_Drawing_MatrixDestroy(matrix);
254 }
255
256 /*
257 * @tc.name: NativeDrawingMatrixTest_Concat007
258 * @tc.desc: test for Concat.
259 * @tc.size : MediumTest
260 * @tc.type : Function
261 * @tc.level : Level 1
262 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Concat007, TestSize.Level1)263 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Concat007, TestSize.Level1)
264 {
265 OH_Drawing_Matrix* matrixA = OH_Drawing_MatrixCreate();
266 OH_Drawing_Matrix* matrixB = OH_Drawing_MatrixCreate();
267 bool ret;
268 ret = OH_Drawing_MatrixIsEqual(nullptr, matrixB);
269 EXPECT_TRUE(!ret);
270 ret = OH_Drawing_MatrixIsEqual(matrixA, nullptr);
271 EXPECT_TRUE(!ret);
272 ret = OH_Drawing_MatrixIsEqual(matrixA, matrixB);
273 EXPECT_TRUE(ret);
274 OH_Drawing_MatrixSetMatrix(
275 matrixA,
276 1, 0, 0,
277 0, -1, 0,
278 0, 0, 1);
279 OH_Drawing_MatrixSetMatrix(
280 matrixB,
281 1, 0, 100,
282 0, -1, 200,
283 0, 0, 1);
284 ret = OH_Drawing_MatrixIsEqual(matrixA, matrixB);
285 EXPECT_TRUE(!ret);
286 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
287 OH_Drawing_MatrixConcat(nullptr, matrixA, matrixB);
288 OH_Drawing_MatrixConcat(matrix, nullptr, matrixB);
289 OH_Drawing_MatrixConcat(matrix, matrixA, nullptr);
290 OH_Drawing_MatrixConcat(matrix, matrixA, matrixB);
291 float value;
292 value = OH_Drawing_MatrixGetValue(matrix, 0);
293 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
294 value = OH_Drawing_MatrixGetValue(matrix, 1);
295 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
296 value = OH_Drawing_MatrixGetValue(matrix, 2);
297 EXPECT_TRUE(IsScalarAlmostEqual(value, 100));
298
299 value = OH_Drawing_MatrixGetValue(matrix, 3);
300 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
301 value = OH_Drawing_MatrixGetValue(matrix, 4);
302 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
303 value = OH_Drawing_MatrixGetValue(matrix, 5);
304 EXPECT_TRUE(IsScalarAlmostEqual(value, -200));
305
306 value = OH_Drawing_MatrixGetValue(matrix, 6);
307 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
308 value = OH_Drawing_MatrixGetValue(matrix, 7);
309 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
310 value = OH_Drawing_MatrixGetValue(matrix, 8);
311 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
312
313 OH_Drawing_MatrixDestroy(matrix);
314 OH_Drawing_MatrixDestroy(matrixA);
315 OH_Drawing_MatrixDestroy(matrixB);
316 }
317
318 /*
319 * @tc.name: NativeDrawingMatrixTest_Rotate008
320 * @tc.desc: test for Rotate.
321 * @tc.size : MediumTest
322 * @tc.type : Function
323 * @tc.level : Level 1
324 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Rotate008, TestSize.Level1)325 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Rotate008, TestSize.Level1)
326 {
327 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
328 OH_Drawing_MatrixRotate(nullptr, 180, 1, 1);
329 OH_Drawing_MatrixRotate(matrix, 180, 1, 1);
330 float value;
331 value = OH_Drawing_MatrixGetValue(matrix, 0);
332 EXPECT_TRUE(IsScalarAlmostEqual(value, -1));
333 value = OH_Drawing_MatrixGetValue(matrix, 1);
334 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
335 value = OH_Drawing_MatrixGetValue(matrix, 2);
336 EXPECT_TRUE(IsScalarAlmostEqual(value, 2));
337
338 value = OH_Drawing_MatrixGetValue(matrix, 3);
339 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
340 value = OH_Drawing_MatrixGetValue(matrix, 4);
341 EXPECT_TRUE(IsScalarAlmostEqual(value, -1));
342 value = OH_Drawing_MatrixGetValue(matrix, 5);
343 EXPECT_TRUE(IsScalarAlmostEqual(value, 2));
344
345 value = OH_Drawing_MatrixGetValue(matrix, 6);
346 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
347 value = OH_Drawing_MatrixGetValue(matrix, 7);
348 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
349 value = OH_Drawing_MatrixGetValue(matrix, 8);
350 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
351
352 value = OH_Drawing_MatrixGetValue(nullptr, 8);
353 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
354 value = OH_Drawing_MatrixGetValue(matrix, -1);
355 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
356 value = OH_Drawing_MatrixGetValue(matrix, 9);
357 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
358
359 OH_Drawing_MatrixDestroy(matrix);
360 }
361
362 /*
363 * @tc.name: NativeDrawingMatrixTest_PreRotate009
364 * @tc.desc: test for PreRotate.
365 * @tc.size : MediumTest
366 * @tc.type : Function
367 * @tc.level : Level 1
368 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PreRotate009, TestSize.Level1)369 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PreRotate009, TestSize.Level1)
370 {
371 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
372 OH_Drawing_MatrixSetMatrix(matrix, 2, 0, 0, 0, 1, 2, 0, 0, 1);
373 OH_Drawing_MatrixPreRotate(matrix, 5, 10, 20);
374 OH_Drawing_MatrixPreRotate(nullptr, 5, 10, 20);
375
376 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9);
377 OH_Drawing_MatrixPreRotate(matrix, 90, 1, 0);
378 OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate();
379 OH_Drawing_MatrixSetMatrix(matrix2, 2, -1, 2, 5, -4, 5, 8, -7, 8);
380 bool ret = false;
381 ret = OH_Drawing_MatrixIsEqual(matrix, matrix2);
382 EXPECT_EQ(ret, true);
383 OH_Drawing_MatrixDestroy(matrix);
384 OH_Drawing_MatrixDestroy(matrix2);
385 }
386
387 /*
388 * @tc.name: NativeDrawingMatrixTest_PostRotate010
389 * @tc.desc: test for PostRotate.
390 * @tc.size : MediumTest
391 * @tc.type : Function
392 * @tc.level : Level 1
393 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PostRotate010, TestSize.Level1)394 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PostRotate010, TestSize.Level1)
395 {
396 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
397 OH_Drawing_MatrixSetMatrix(matrix, 2, 0, 0, 0, 1, 2, 0, 0, 1);
398 OH_Drawing_MatrixPostRotate(matrix, 5, 10, 20);
399 OH_Drawing_MatrixPostRotate(nullptr, 5, 10, 20);
400
401 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 4, 5, 6, 7, 8, 9);
402 OH_Drawing_MatrixPostRotate(matrix, 90, 1, 0);
403 OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate();
404 OH_Drawing_MatrixSetMatrix(matrix2, 3, 3, 3, -6, -6, -6, 7, 8, 9);
405 bool ret = false;
406 ret = OH_Drawing_MatrixIsEqual(matrix, matrix2);
407 EXPECT_EQ(ret, true);
408 OH_Drawing_MatrixDestroy(matrix);
409 OH_Drawing_MatrixDestroy(matrix2);
410 }
411
412 /*
413 * @tc.name: NativeDrawingMatrixTest_Scale011
414 * @tc.desc: test for Scale.
415 * @tc.size : MediumTest
416 * @tc.type : Function
417 * @tc.level : Level 1
418 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Scale011, TestSize.Level1)419 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Scale011, TestSize.Level1)
420 {
421 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
422
423 OH_Drawing_MatrixScale(nullptr, 10, 10, 10, 10);
424 OH_Drawing_MatrixScale(matrix, 10, 10, 10, 10);
425 float value;
426 value = OH_Drawing_MatrixGetValue(matrix, 0);
427 EXPECT_TRUE(IsScalarAlmostEqual(value, 10));
428 value = OH_Drawing_MatrixGetValue(matrix, 1);
429 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
430 value = OH_Drawing_MatrixGetValue(matrix, 2);
431 EXPECT_TRUE(IsScalarAlmostEqual(value, -90));
432
433 value = OH_Drawing_MatrixGetValue(matrix, 3);
434 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
435 value = OH_Drawing_MatrixGetValue(matrix, 4);
436 EXPECT_TRUE(IsScalarAlmostEqual(value, 10));
437 value = OH_Drawing_MatrixGetValue(matrix, 5);
438 EXPECT_TRUE(IsScalarAlmostEqual(value, -90));
439
440 value = OH_Drawing_MatrixGetValue(matrix, 6);
441 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
442 value = OH_Drawing_MatrixGetValue(matrix, 7);
443 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
444 value = OH_Drawing_MatrixGetValue(matrix, 8);
445 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
446
447 OH_Drawing_MatrixDestroy(matrix);
448 }
449
450 /*
451 * @tc.name: NativeDrawingMatrixTest_PreScale012
452 * @tc.desc: test for PreScale.
453 * @tc.size : MediumTest
454 * @tc.type : Function
455 * @tc.level : Level 1
456 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PreScale012, TestSize.Level1)457 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PreScale012, TestSize.Level1)
458 {
459 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
460 OH_Drawing_MatrixPreScale(nullptr, 10, 10, 10, 10);
461 OH_Drawing_MatrixPreScale(matrix, 10, 10, 10, 10);
462 float value;
463 value = OH_Drawing_MatrixGetValue(matrix, 0);
464 EXPECT_TRUE(IsScalarAlmostEqual(value, 10));
465
466 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1);
467 OH_Drawing_MatrixPreScale(matrix, 4, 6, 5, 7);
468 OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate();
469 OH_Drawing_MatrixSetMatrix(matrix2, 8, 6, -62, 4, 12, -83, 12, 6, -79);
470 bool ret = false;
471 ret = OH_Drawing_MatrixIsEqual(matrix, matrix2);
472 EXPECT_EQ(ret, true);
473
474 OH_Drawing_MatrixDestroy(matrix);
475 OH_Drawing_MatrixDestroy(matrix2);
476 }
477
478 /*
479 * @tc.name: NativeDrawingMatrixTest_PostScale013
480 * @tc.desc: test for PostScale.
481 * @tc.size : MediumTest
482 * @tc.type : Function
483 * @tc.level : Level 1
484 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PostScale013, TestSize.Level1)485 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PostScale013, TestSize.Level1)
486 {
487 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
488 OH_Drawing_MatrixPostScale(nullptr, 10, 10, 10, 10);
489 OH_Drawing_MatrixPostScale(matrix, 10, 10, 10, 10);
490 float value;
491 value = OH_Drawing_MatrixGetValue(matrix, 0);
492 EXPECT_TRUE(IsScalarAlmostEqual(value, 10));
493
494 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1);
495 OH_Drawing_MatrixPostScale(matrix, 4, 6, 5, 7);
496 OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate();
497 OH_Drawing_MatrixSetMatrix(matrix2, -37, -11, -3, -99, -23, -23, 3, 1, 1);
498 bool ret = false;
499 ret = OH_Drawing_MatrixIsEqual(matrix, matrix2);
500 EXPECT_EQ(ret, true);
501 OH_Drawing_MatrixDestroy(matrix);
502 OH_Drawing_MatrixDestroy(matrix2);
503 }
504
505 /*
506 * @tc.name: NativeDrawingMatrixTest_Translate014
507 * @tc.desc: test for Translate.
508 * @tc.size : MediumTest
509 * @tc.type : Function
510 * @tc.level : Level 1
511 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Translate014, TestSize.Level1)512 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Translate014, TestSize.Level1)
513 {
514 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
515 bool ret;
516 ret = OH_Drawing_MatrixIsIdentity(matrix);
517 EXPECT_TRUE(ret);
518 ret = OH_Drawing_MatrixIsIdentity(nullptr);
519 EXPECT_TRUE(!ret);
520
521 OH_Drawing_MatrixTranslate(nullptr, 100, 200);
522 OH_Drawing_MatrixTranslate(matrix, 100, 200);
523 ret = OH_Drawing_MatrixIsIdentity(matrix);
524 EXPECT_TRUE(!ret);
525 float value;
526 value = OH_Drawing_MatrixGetValue(matrix, 0);
527 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
528 value = OH_Drawing_MatrixGetValue(matrix, 1);
529 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
530 value = OH_Drawing_MatrixGetValue(matrix, 2);
531 EXPECT_TRUE(IsScalarAlmostEqual(value, 100));
532
533 value = OH_Drawing_MatrixGetValue(matrix, 3);
534 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
535 value = OH_Drawing_MatrixGetValue(matrix, 4);
536 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
537 value = OH_Drawing_MatrixGetValue(matrix, 5);
538 EXPECT_TRUE(IsScalarAlmostEqual(value, 200));
539
540 value = OH_Drawing_MatrixGetValue(matrix, 6);
541 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
542 value = OH_Drawing_MatrixGetValue(matrix, 7);
543 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
544 value = OH_Drawing_MatrixGetValue(matrix, 8);
545 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
546
547 OH_Drawing_MatrixDestroy(matrix);
548 }
549
550 /*
551 * @tc.name: NativeDrawingMatrixTest_PreTranslate015
552 * @tc.desc: test for PreTranslate.
553 * @tc.size : MediumTest
554 * @tc.type : Function
555 * @tc.level : Level 1
556 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PreTranslate015, TestSize.Level1)557 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PreTranslate015, TestSize.Level1)
558 {
559 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
560 OH_Drawing_MatrixPreTranslate(nullptr, 10, 10);
561 OH_Drawing_MatrixPreTranslate(matrix, 10, 10);
562 float value;
563 value = OH_Drawing_MatrixGetValue(matrix, 0);
564 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
565
566 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1);
567 OH_Drawing_MatrixPreTranslate(matrix, 2, 4);
568 OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate();
569 OH_Drawing_MatrixSetMatrix(matrix2, 2, 1, 11, 1, 2, 12, 3, 1, 11);
570 bool ret = false;
571 ret = OH_Drawing_MatrixIsEqual(matrix, matrix2);
572 EXPECT_EQ(ret, true);
573 OH_Drawing_MatrixDestroy(matrix);
574 OH_Drawing_MatrixDestroy(matrix2);
575 }
576
577 /*
578 * @tc.name: NativeDrawingMatrixTest_PostTranslate016
579 * @tc.desc: test for PostTranslate.
580 * @tc.size : MediumTest
581 * @tc.type : Function
582 * @tc.level : Level 1
583 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PostTranslate016, TestSize.Level1)584 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_PostTranslate016, TestSize.Level1)
585 {
586 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
587 OH_Drawing_MatrixPostTranslate(nullptr, 10, 10);
588 OH_Drawing_MatrixPostTranslate(matrix, 10, 10);
589 float value;
590 value = OH_Drawing_MatrixGetValue(matrix, 0);
591 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
592
593 OH_Drawing_MatrixSetMatrix(matrix, 2, 1, 3, 1, 2, 2, 3, 1, 1);
594 OH_Drawing_MatrixPostTranslate(matrix, 2, 4);
595 OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate();
596 OH_Drawing_MatrixSetMatrix(matrix2, 8, 3, 5, 13, 6, 6, 3, 1, 1);
597 bool ret = false;
598 ret = OH_Drawing_MatrixIsEqual(matrix, matrix2);
599 EXPECT_EQ(ret, true);
600
601 OH_Drawing_MatrixDestroy(matrix);
602 OH_Drawing_MatrixDestroy(matrix2);
603 }
604
605 /*
606 * @tc.name: NativeDrawingMatrixTest_Invert017
607 * @tc.desc: test for Invert.
608 * @tc.size : MediumTest
609 * @tc.type : Function
610 * @tc.level : Level 1
611 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Invert017, TestSize.Level1)612 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_Invert017, TestSize.Level1)
613 {
614 bool ret;
615 ret = OH_Drawing_MatrixInvert(nullptr, nullptr);
616 EXPECT_TRUE(!ret);
617 OH_Drawing_Matrix* matrixA = OH_Drawing_MatrixCreate();
618 OH_Drawing_Matrix* matrixB = OH_Drawing_MatrixCreate();
619 ret = OH_Drawing_MatrixInvert(nullptr, matrixB);
620 EXPECT_TRUE(!ret);
621 ret = OH_Drawing_MatrixInvert(matrixA, nullptr);
622 EXPECT_TRUE(!ret);
623 ret = OH_Drawing_MatrixInvert(matrixA, matrixB);
624 EXPECT_TRUE(ret);
625 OH_Drawing_MatrixSetMatrix(
626 matrixA,
627 1, 0, 0,
628 0, -0.5, 0,
629 0, 0, 1);
630 ret = OH_Drawing_MatrixInvert(matrixA, matrixB);
631 EXPECT_TRUE(ret);
632
633 float value;
634 value = OH_Drawing_MatrixGetValue(matrixB, 0);
635 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
636 value = OH_Drawing_MatrixGetValue(matrixB, 1);
637 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
638 value = OH_Drawing_MatrixGetValue(matrixB, 2);
639 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
640
641 value = OH_Drawing_MatrixGetValue(matrixB, 3);
642 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
643 value = OH_Drawing_MatrixGetValue(matrixB, 4);
644 EXPECT_TRUE(IsScalarAlmostEqual(value, -2));
645 value = OH_Drawing_MatrixGetValue(matrixB, 5);
646 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
647
648 value = OH_Drawing_MatrixGetValue(matrixB, 6);
649 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
650 value = OH_Drawing_MatrixGetValue(matrixB, 7);
651 EXPECT_TRUE(IsScalarAlmostEqual(value, 0));
652 value = OH_Drawing_MatrixGetValue(matrixB, 8);
653 EXPECT_TRUE(IsScalarAlmostEqual(value, 1));
654
655 OH_Drawing_MatrixDestroy(matrixA);
656 OH_Drawing_MatrixDestroy(matrixB);
657 }
658
659 /*
660 * @tc.name: NativeDrawingMatrixTest_SetPolyToPoly018
661 * @tc.desc: test for set poly to poly of Matrix.
662 * @tc.size : MediumTest
663 * @tc.type : Function
664 * @tc.level : Level 1
665 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly018, TestSize.Level1)666 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly018, TestSize.Level1)
667 {
668 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
669 ASSERT_TRUE(matrix != nullptr);
670 OH_Drawing_MatrixSetMatrix(
671 matrix,
672 1, 0, 0,
673 0, -1, 0,
674 0, 0, 1);
675 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}};
676 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}};
677 EXPECT_TRUE(OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 0));
678 OH_Drawing_MatrixDestroy(matrix);
679 }
680
681 /*
682 * @tc.name: NativeDrawingMatrixTest_SetPolyToPoly019
683 * @tc.desc: test for set poly to poly of Matrix.
684 * @tc.size : MediumTest
685 * @tc.type : Function
686 * @tc.level : Level 1
687 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly019, TestSize.Level1)688 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly019, TestSize.Level1)
689 {
690 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
691 ASSERT_TRUE(matrix != nullptr);
692 OH_Drawing_MatrixSetMatrix(
693 matrix,
694 1, 0, 0,
695 0, -1, 0,
696 0, 0, 1);
697 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}};
698 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}};
699 EXPECT_TRUE(OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 1));
700 OH_Drawing_MatrixDestroy(matrix);
701 }
702
703 /*
704 * @tc.name: NativeDrawingMatrixTest_SetPolyToPoly020
705 * @tc.desc: test for set poly to poly of Matrix.
706 * @tc.size : MediumTest
707 * @tc.type : Function
708 * @tc.level : Level 1
709 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly020, TestSize.Level1)710 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly020, TestSize.Level1)
711 {
712 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
713 ASSERT_TRUE(matrix != nullptr);
714 OH_Drawing_MatrixSetMatrix(
715 matrix,
716 1, 0, 0,
717 0, -1, 0,
718 0, 0, 1);
719 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}};
720 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}};
721 EXPECT_TRUE(OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 4));
722 OH_Drawing_MatrixDestroy(matrix);
723 }
724
725 /*
726 * @tc.name: NativeDrawingMatrixTest_SetPolyToPoly021
727 * @tc.desc: test for set poly to poly of Matrix.
728 * @tc.size : MediumTest
729 * @tc.type : Function
730 * @tc.level : Level 1
731 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly021, TestSize.Level1)732 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetPolyToPoly021, TestSize.Level1)
733 {
734 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
735 ASSERT_TRUE(matrix != nullptr);
736 OH_Drawing_MatrixSetMatrix(
737 matrix,
738 1, 0, 0,
739 0, -1, 0,
740 0, 0, 1);
741 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}};
742 OH_Drawing_Point2D dst[] = {{0, 0}, {100, 30}, {100, 70}, {0, 100}, {0, 100}};
743 EXPECT_FALSE(OH_Drawing_MatrixSetPolyToPoly(matrix, src, dst, 5));
744 OH_Drawing_MatrixDestroy(matrix);
745 }
746
747 /**
748 * @tc.name: NativeDrawingMatrixTest_GetAll022
749 * @tc.desc: test for Copies nine scalar values contained by Matrix into buffer.
750 * @tc.type: FUNC
751 * @tc.require: AR20240104201189
752 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_GetAll022, TestSize.Level1)753 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_GetAll022, TestSize.Level1)
754 {
755 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
756 ASSERT_TRUE(matrix != nullptr);
757 float buffer[9];
758 float emptyBuffer[9] = {1, 2, 3, 3, 2, 1, 4, 5, 6};
759 OH_Drawing_MatrixSetMatrix(matrix, 1, 2, 3, 3, 2, 1, 4, 5, 6);
760 EXPECT_EQ(OH_Drawing_MatrixGetAll(matrix, buffer), OH_DRAWING_SUCCESS);
761 for (int i = 0; i < 9; ++i) {
762 EXPECT_TRUE(IsScalarAlmostEqual(buffer[i], emptyBuffer[i]));
763 }
764 OH_Drawing_MatrixDestroy(matrix);
765 }
766
767 /*
768 * @tc.name: NativeDrawingMatrixTest_IsEqualAndConcat023
769 * @tc.desc: test for IsEqual and Concat.
770 * @tc.type: FUNC
771 * @tc.require: SR000S9F0C
772 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_IsEqualAndConcat023, TestSize.Level1)773 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_IsEqualAndConcat023, TestSize.Level1)
774 {
775 OH_Drawing_Matrix* matrixA = OH_Drawing_MatrixCreate();
776 OH_Drawing_Matrix* matrixB = OH_Drawing_MatrixCreate();
777 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
778 OH_Drawing_MatrixIsEqual(nullptr, matrixB);
779 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
780 OH_Drawing_MatrixIsEqual(matrixA, nullptr);
781 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
782
783 OH_Drawing_MatrixConcat(nullptr, matrixA, matrixB);
784 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
785 OH_Drawing_MatrixConcat(matrix, nullptr, matrixB);
786 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
787 OH_Drawing_MatrixConcat(matrix, matrixA, nullptr);
788 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
789
790 OH_Drawing_MatrixDestroy(matrix);
791 OH_Drawing_MatrixDestroy(matrixA);
792 OH_Drawing_MatrixDestroy(matrixB);
793 }
794
795 /*
796 * @tc.name: NativeDrawingMatrixTest_SetRectToRect024
797 * @tc.desc: test for SetRectToRect.
798 * @tc.type: FUNC
799 * @tc.require: SR000S9F0C
800 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetRectToRect024, TestSize.Level1)801 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_SetRectToRect024, TestSize.Level1)
802 {
803 OH_Drawing_Rect *rectSrcOne = OH_Drawing_RectCreate(0, 0, 0, 0);
804 OH_Drawing_Rect *rectDstOne = OH_Drawing_RectCreate(0, 0, 0, 0);
805 OH_Drawing_Matrix *matrixOne = OH_Drawing_MatrixCreate();
806 OH_Drawing_MatrixSetRectToRect(nullptr, rectSrcOne, rectDstOne, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
807 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
808 OH_Drawing_MatrixSetRectToRect(matrixOne, nullptr, rectDstOne, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
809 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
810 OH_Drawing_MatrixSetRectToRect(matrixOne, rectSrcOne, nullptr, OH_Drawing_ScaleToFit::SCALE_TO_FIT_FILL);
811 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
812
813 OH_Drawing_MatrixDestroy(matrixOne);
814 OH_Drawing_RectDestroy(rectSrcOne);
815 OH_Drawing_RectDestroy(rectDstOne);
816 }
817
818 /**
819 * @tc.name: NativeDrawingMatrixTest_MapPoints025
820 * @tc.desc: test for maps the src point array to the dst point array by matrix transformation.
821 * @tc.type: FUNC
822 * @tc.require: AR20240104201189
823 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_MapPoints025, TestSize.Level1)824 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_MapPoints025, TestSize.Level1)
825 {
826 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
827 ASSERT_TRUE(matrix != nullptr);
828 OH_Drawing_Point2D src[] = {{0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 100}};
829 OH_Drawing_Point2D dst[MAPPOINTS_SIZE];
830
831 OH_Drawing_MatrixMapPoints(nullptr, src, dst, MAPPOINTS_COUNT);
832 OH_Drawing_MatrixTranslate(matrix, 100, 200);
833 OH_Drawing_MatrixMapPoints(matrix, src, dst, MAPPOINTS_COUNT);
834
835 EXPECT_EQ(dst[0].x, 100);
836 EXPECT_EQ(dst[0].y, 200);
837 OH_Drawing_MatrixDestroy(matrix);
838 }
839
840 /**
841 * @tc.name: NativeDrawingMatrixTest_MapRect026
842 * @tc.desc: test for sets dst to bounds of src corners mapped by matrix transformation.
843 * @tc.type: FUNC
844 * @tc.require: AR20240104201189
845 */
HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_MapRect026, TestSize.Level1)846 HWTEST_F(NativeDrawingMatrixTest, NativeDrawingMatrixTest_MapRect026, TestSize.Level1)
847 {
848 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
849 ASSERT_TRUE(matrix != nullptr);
850 OH_Drawing_Rect* src = OH_Drawing_RectCreate(0, 100, 200, 200);
851 OH_Drawing_Rect* dst = OH_Drawing_RectCreate(0, 0, 0, 0);
852
853 EXPECT_FALSE(OH_Drawing_MatrixMapRect(nullptr, src, dst));
854 OH_Drawing_MatrixTranslate(matrix, 100, 200);
855 EXPECT_TRUE(OH_Drawing_MatrixMapRect(matrix, src, dst));
856
857 EXPECT_TRUE(IsScalarAlmostEqual(OH_Drawing_RectGetHeight(dst), 100.f));
858 EXPECT_TRUE(IsScalarAlmostEqual(OH_Drawing_RectGetLeft(dst), 100.f));
859 OH_Drawing_RectDestroy(src);
860 OH_Drawing_RectDestroy(dst);
861 OH_Drawing_MatrixDestroy(matrix);
862 }
863 } // namespace Drawing
864 } // namespace Rosen
865 } // namespace OHOS
866