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/rect.h"
19 #include "utils/scalar.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class RectTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void RectTest::SetUpTestCase() {}
TearDownTestCase()36 void RectTest::TearDownTestCase() {}
SetUp()37 void RectTest::SetUp() {}
TearDown()38 void RectTest::TearDown() {}
39
40 /**
41 * @tc.name: RectFCreateAndDestroy001
42 * @tc.desc:
43 * @tc.type: FUNC
44 * @tc.require:AR000GGNV3
45 * @tc.author:
46 */
47 HWTEST_F(RectTest, RectFCreateAndDestroy001, TestSize.Level1)
48 {
49 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
50 EXPECT_EQ(0.0f, rectF->GetLeft());
51 EXPECT_EQ(0.0f, rectF->GetTop());
52 EXPECT_EQ(0.0f, rectF->GetRight());
53 EXPECT_EQ(0.0f, rectF->GetBottom());
54 }
55
56 /**
57 * @tc.name: RectFCreateAndDestroy002
58 * @tc.desc:
59 * @tc.type: FUNC
60 * @tc.require:AR000GGNV3
61 * @tc.author:
62 */
63 HWTEST_F(RectTest, RectFCreateAndDestroy002, TestSize.Level1)
64 {
65 RectF rectf1;
66 rectf1.SetLeft(1.0f);
67 RectF rectf2(rectf1);
68 EXPECT_EQ(rectf1.GetLeft(), rectf2.GetLeft());
69 }
70
71 /**
72 * @tc.name: RectFCreateAndDestroy003
73 * @tc.desc:
74 * @tc.type: FUNC
75 * @tc.require:AR000GGNV3
76 * @tc.author:
77 */
78 HWTEST_F(RectTest, RectFCreateAndDestroy003, TestSize.Level1)
79 {
80 RectF rectf1;
81 rectf1.SetLeft(2.0f);
82 RectF rectf2(rectf1);
83 EXPECT_EQ(rectf1.GetLeft(), rectf2.GetLeft());
84 }
85
86 /**
87 * @tc.name: RectFCreateAndDestroy004
88 * @tc.desc:
89 * @tc.type: FUNC
90 * @tc.require:AR000GGNV3
91 * @tc.author:
92 */
93 HWTEST_F(RectTest, RectFCreateAndDestroy004, TestSize.Level1)
94 {
95 std::unique_ptr<RectF> rectF = std::make_unique<RectF>(1.0f, 2.0f, 3.0f, 4.0f);
96 EXPECT_EQ(1.0f, rectF->GetLeft());
97 EXPECT_EQ(2.0f, rectF->GetTop());
98 EXPECT_EQ(3.0f, rectF->GetRight());
99 EXPECT_EQ(4.0f, rectF->GetBottom());
100 }
101
102 /**
103 * @tc.name: RectFCreateAndDestroy005
104 * @tc.desc:
105 * @tc.type: FUNC
106 * @tc.require:AR000GGNV3
107 * @tc.author:
108 */
109 HWTEST_F(RectTest, RectFCreateAndDestroy005, TestSize.Level1)
110 {
111 std::unique_ptr<RectF> rectF = std::make_unique<RectF>(4.0f, 3.0f, 2.0f, 1.0f);
112 EXPECT_EQ(4.0f, rectF->GetLeft());
113 EXPECT_EQ(3.0f, rectF->GetTop());
114 EXPECT_EQ(2.0f, rectF->GetRight());
115 EXPECT_EQ(1.0f, rectF->GetBottom());
116 }
117
118 /**
119 * @tc.name: RectFIsValid001
120 * @tc.desc:
121 * @tc.type: FUNC
122 * @tc.require:AR000GGNV3
123 * @tc.author:
124 */
125 HWTEST_F(RectTest, RectFIsValid001, TestSize.Level1)
126 {
127 std::unique_ptr<RectF> rectF = std::make_unique<RectF>(4.0f, 3.0f, 2.0f, 1.0f);
128 EXPECT_FALSE(rectF->IsValid());
129 }
130
131 /**
132 * @tc.name: RectFIsValid002
133 * @tc.desc:
134 * @tc.type: FUNC
135 * @tc.require:AR000GGNV3
136 * @tc.author:
137 */
138 HWTEST_F(RectTest, RectFIsValid002, TestSize.Level1)
139 {
140 std::unique_ptr<RectF> rectF = std::make_unique<RectF>(1.0f, 2.0f, 3.0f, 4.0f);
141 EXPECT_TRUE(rectF->IsValid());
142 }
143
144 /**
145 * @tc.name: RectFSetAndGetLeft001
146 * @tc.desc:
147 * @tc.type: FUNC
148 * @tc.require:AR000GGNV3
149 * @tc.author:
150 */
151 HWTEST_F(RectTest, RectFSetAndGetLeft001, TestSize.Level1)
152 {
153 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
154 rectF->SetLeft(1.0f);
155 EXPECT_EQ(1.0f, rectF->GetLeft());
156 }
157
158 /**
159 * @tc.name: RectFSetAndGetLeft002
160 * @tc.desc:
161 * @tc.type: FUNC
162 * @tc.require:AR000GGNV3
163 * @tc.author:
164 */
165 HWTEST_F(RectTest, RectFSetAndGetLeft002, TestSize.Level1)
166 {
167 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
168 rectF->SetLeft(2.0f);
169 EXPECT_EQ(2.0f, rectF->GetLeft());
170 }
171
172 /**
173 * @tc.name: RectFSetAndGetRight001
174 * @tc.desc:
175 * @tc.type: FUNC
176 * @tc.require:AR000GGNV3
177 * @tc.author:
178 */
179 HWTEST_F(RectTest, RectFSetAndGetRight001, TestSize.Level1)
180 {
181 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
182 rectF->SetRight(1.0f);
183 EXPECT_EQ(1.0f, rectF->GetRight());
184 }
185
186 /**
187 * @tc.name: RectFSetAndGetRight002
188 * @tc.desc:
189 * @tc.type: FUNC
190 * @tc.require:AR000GGNV3
191 * @tc.author:
192 */
193 HWTEST_F(RectTest, RectFSetAndGetRight002, TestSize.Level1)
194 {
195 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
196 rectF->SetRight(2.0f);
197 EXPECT_EQ(2.0f, rectF->GetRight());
198 }
199
200 /**
201 * @tc.name: RectFSetAndGetTop001
202 * @tc.desc:
203 * @tc.type: FUNC
204 * @tc.require:AR000GGNV3
205 * @tc.author:
206 */
207 HWTEST_F(RectTest, RectFSetAndGetTop001, TestSize.Level1)
208 {
209 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
210 rectF->SetTop(1.0f);
211 EXPECT_EQ(1.0f, rectF->GetTop());
212 }
213
214 /**
215 * @tc.name: RectFSetAndGetTop002
216 * @tc.desc:
217 * @tc.type: FUNC
218 * @tc.require:AR000GGNV3
219 * @tc.author:
220 */
221 HWTEST_F(RectTest, RectFSetAndGetTop002, TestSize.Level1)
222 {
223 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
224 rectF->SetTop(2.0f);
225 EXPECT_EQ(2.0f, rectF->GetTop());
226 }
227
228 /**
229 * @tc.name: RectFSetAndGetBottom001
230 * @tc.desc:
231 * @tc.type: FUNC
232 * @tc.require:AR000GGNV3
233 * @tc.author:
234 */
235 HWTEST_F(RectTest, RectFSetAndGetBottom001, TestSize.Level1)
236 {
237 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
238 rectF->SetBottom(1.0f);
239 EXPECT_EQ(1.0f, rectF->GetBottom());
240 }
241
242 /**
243 * @tc.name: RectFSetAndGetBottom002
244 * @tc.desc:
245 * @tc.type: FUNC
246 * @tc.require:AR000GGNV3
247 * @tc.author:
248 */
249 HWTEST_F(RectTest, RectFSetAndGetBottom002, TestSize.Level1)
250 {
251 std::unique_ptr<RectF> rectF = std::make_unique<RectF>();
252 rectF->SetBottom(2.0f);
253 EXPECT_EQ(2.0f, rectF->GetBottom());
254 }
255
256 /**
257 * @tc.name: RectFOffset001
258 * @tc.desc:
259 * @tc.type: FUNC
260 * @tc.require:AR000GGNV3
261 * @tc.author:
262 */
263 HWTEST_F(RectTest, RectFOffset001, TestSize.Level1)
264 {
265 std::unique_ptr<RectF> rectF = std::make_unique<RectF>(1.0f, 2.0f, 3.0f, 4.0f);
266 rectF->Offset(1.0f, 2.0f);
267 EXPECT_EQ(2.0f, rectF->GetLeft());
268 EXPECT_EQ(4.0f, rectF->GetRight());
269 EXPECT_EQ(4.0f, rectF->GetTop());
270 EXPECT_EQ(6.0f, rectF->GetBottom());
271 }
272
273 /**
274 * @tc.name: RectFOffset002
275 * @tc.desc:
276 * @tc.type: FUNC
277 * @tc.require:AR000GGNV3
278 * @tc.author:
279 */
280 HWTEST_F(RectTest, RectFOffset002, TestSize.Level1)
281 {
282 std::unique_ptr<RectF> rectF = std::make_unique<RectF>(1.0f, 2.0f, 3.0f, 4.0f);
283 rectF->Offset(2.0f, 1.0f);
284 EXPECT_EQ(3.0f, rectF->GetLeft());
285 EXPECT_EQ(5.0f, rectF->GetRight());
286 EXPECT_EQ(3.0f, rectF->GetTop());
287 EXPECT_EQ(5.0f, rectF->GetBottom());
288 }
289
290 /**
291 * @tc.name: RectFEqual001
292 * @tc.desc:
293 * @tc.type: FUNC
294 * @tc.require:AR000GGNV3
295 * @tc.author:
296 */
297 HWTEST_F(RectTest, RectFEqual001, TestSize.Level1)
298 {
299 RectF rectf1;
300 RectF rectf2;
301 rectf1.SetLeft(1.0f);
302 EXPECT_FALSE(rectf1 == rectf2);
303 }
304
305 /**
306 * @tc.name: RectFEqual002
307 * @tc.desc:
308 * @tc.type: FUNC
309 * @tc.require:AR000GGNV3
310 * @tc.author:
311 */
312 HWTEST_F(RectTest, RectFEqual002, TestSize.Level1)
313 {
314 RectF rectf1;
315 RectF rectf2;
316 EXPECT_TRUE(rectf1 == rectf2);
317 }
318
319 /**
320 * @tc.name: RectFNotEqual001
321 * @tc.desc:
322 * @tc.type: FUNC
323 * @tc.require:AR000GGNV3
324 * @tc.author:
325 */
326 HWTEST_F(RectTest, RectFNotEqual001, TestSize.Level1)
327 {
328 RectF rectf1;
329 RectF rectf2;
330 EXPECT_FALSE(rectf1 != rectf2);
331 }
332
333 /**
334 * @tc.name: RectFNotEqual002
335 * @tc.desc:
336 * @tc.type: FUNC
337 * @tc.require:AR000GGNV3
338 * @tc.author:
339 */
340 HWTEST_F(RectTest, RectFNotEqual002, TestSize.Level1)
341 {
342 RectF rectf1;
343 RectF rectf2;
344 rectf2.SetLeft(2.0f);
345 EXPECT_TRUE(rectf1 != rectf2);
346 }
347
348 /**
349 * @tc.name: RectICreateAndDestroy001
350 * @tc.desc:
351 * @tc.type: FUNC
352 * @tc.require:AR000GGNV3
353 * @tc.author:
354 */
355 HWTEST_F(RectTest, RectICreateAndDestroy001, TestSize.Level1)
356 {
357 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
358 EXPECT_EQ(0.0f, rectI->GetLeft());
359 EXPECT_EQ(0.0f, rectI->GetTop());
360 EXPECT_EQ(0.0f, rectI->GetRight());
361 EXPECT_EQ(0.0f, rectI->GetBottom());
362 }
363
364 /**
365 * @tc.name: RectICreateAndDestroy002
366 * @tc.desc:
367 * @tc.type: FUNC
368 * @tc.require:AR000GGNV3
369 * @tc.author:
370 */
371 HWTEST_F(RectTest, RectICreateAndDestroy002, TestSize.Level1)
372 {
373 RectI recti1;
374 recti1.SetLeft(1.0f);
375 RectI recti2(recti1);
376 EXPECT_EQ(recti1.GetLeft(), recti2.GetLeft());
377 }
378
379 /**
380 * @tc.name: RectICreateAndDestroy003
381 * @tc.desc:
382 * @tc.type: FUNC
383 * @tc.require:AR000GGNV3
384 * @tc.author:
385 */
386 HWTEST_F(RectTest, RectICreateAndDestroy003, TestSize.Level1)
387 {
388 RectI recti1;
389 recti1.SetLeft(2.0f);
390 RectI recti2(recti1);
391 EXPECT_EQ(recti1.GetLeft(), recti2.GetLeft());
392 }
393
394 /**
395 * @tc.name: RectICreateAndDestroy004
396 * @tc.desc:
397 * @tc.type: FUNC
398 * @tc.require:AR000GGNV3
399 * @tc.author:
400 */
401 HWTEST_F(RectTest, RectICreateAndDestroy004, TestSize.Level1)
402 {
403 std::unique_ptr<RectI> rectI = std::make_unique<RectI>(1.0f, 2.0f, 3.0f, 4.0f);
404 EXPECT_EQ(1.0f, rectI->GetLeft());
405 EXPECT_EQ(2.0f, rectI->GetTop());
406 EXPECT_EQ(3.0f, rectI->GetRight());
407 EXPECT_EQ(4.0f, rectI->GetBottom());
408 }
409
410 /**
411 * @tc.name: RectICreateAndDestroy005
412 * @tc.desc:
413 * @tc.type: FUNC
414 * @tc.require:AR000GGNV3
415 * @tc.author:
416 */
417 HWTEST_F(RectTest, RectICreateAndDestroy005, TestSize.Level1)
418 {
419 std::unique_ptr<RectI> rectI = std::make_unique<RectI>(4.0f, 3.0f, 2.0f, 1.0f);
420 EXPECT_EQ(4.0f, rectI->GetLeft());
421 EXPECT_EQ(3.0f, rectI->GetTop());
422 EXPECT_EQ(2.0f, rectI->GetRight());
423 EXPECT_EQ(1.0f, rectI->GetBottom());
424 }
425
426 /**
427 * @tc.name: RectIIsValid001
428 * @tc.desc:
429 * @tc.type: FUNC
430 * @tc.require:AR000GGNV3
431 * @tc.author:
432 */
433 HWTEST_F(RectTest, RectIIsValid001, TestSize.Level1)
434 {
435 std::unique_ptr<RectI> rectI = std::make_unique<RectI>(4.0f, 3.0f, 2.0f, 1.0f);
436 EXPECT_FALSE(rectI->IsValid());
437 }
438
439 /**
440 * @tc.name: RectIIsValid002
441 * @tc.desc:
442 * @tc.type: FUNC
443 * @tc.require:AR000GGNV3
444 * @tc.author:
445 */
446 HWTEST_F(RectTest, RectIIsValid002, TestSize.Level1)
447 {
448 std::unique_ptr<RectI> rectI = std::make_unique<RectI>(1.0f, 2.0f, 3.0f, 4.0f);
449 EXPECT_TRUE(rectI->IsValid());
450 }
451
452 /**
453 * @tc.name: RectISetAndGetLeft001
454 * @tc.desc:
455 * @tc.type: FUNC
456 * @tc.require:AR000GGNV3
457 * @tc.author:
458 */
459 HWTEST_F(RectTest, RectISetAndGetLeft001, TestSize.Level1)
460 {
461 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
462 rectI->SetLeft(1.0f);
463 EXPECT_EQ(1.0f, rectI->GetLeft());
464 }
465
466 /**
467 * @tc.name: RectISetAndGetLeft002
468 * @tc.desc:
469 * @tc.type: FUNC
470 * @tc.require:AR000GGNV3
471 * @tc.author:
472 */
473 HWTEST_F(RectTest, RectISetAndGetLeft002, TestSize.Level1)
474 {
475 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
476 rectI->SetLeft(2.0f);
477 EXPECT_EQ(2.0f, rectI->GetLeft());
478 }
479
480 /**
481 * @tc.name: RectISetAndGetRight001
482 * @tc.desc:
483 * @tc.type: FUNC
484 * @tc.require:AR000GGNV3
485 * @tc.author:
486 */
487 HWTEST_F(RectTest, RectISetAndGetRight001, TestSize.Level1)
488 {
489 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
490 rectI->SetRight(1.0f);
491 EXPECT_EQ(1.0f, rectI->GetRight());
492 }
493
494 /**
495 * @tc.name: RectISetAndGetRight002
496 * @tc.desc:
497 * @tc.type: FUNC
498 * @tc.require:AR000GGNV3
499 * @tc.author:
500 */
501 HWTEST_F(RectTest, RectISetAndGetRight002, TestSize.Level1)
502 {
503 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
504 rectI->SetRight(2.0f);
505 EXPECT_EQ(2.0f, rectI->GetRight());
506 }
507
508 /**
509 * @tc.name: RectISetAndGetTop001
510 * @tc.desc:
511 * @tc.type: FUNC
512 * @tc.require:AR000GGNV3
513 * @tc.author:
514 */
515 HWTEST_F(RectTest, RectISetAndGetTop001, TestSize.Level1)
516 {
517 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
518 rectI->SetTop(1.0f);
519 EXPECT_EQ(1.0f, rectI->GetTop());
520 }
521
522 /**
523 * @tc.name: RectISetAndGetTop002
524 * @tc.desc:
525 * @tc.type: FUNC
526 * @tc.require:AR000GGNV3
527 * @tc.author:
528 */
529 HWTEST_F(RectTest, RectISetAndGetTop002, TestSize.Level1)
530 {
531 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
532 rectI->SetTop(2.0f);
533 EXPECT_EQ(2.0f, rectI->GetTop());
534 }
535
536 /**
537 * @tc.name: RectISetAndGetBottom001
538 * @tc.desc:
539 * @tc.type: FUNC
540 * @tc.require:AR000GGNV3
541 * @tc.author:
542 */
543 HWTEST_F(RectTest, RectISetAndGetBottom001, TestSize.Level1)
544 {
545 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
546 rectI->SetBottom(1.0f);
547 EXPECT_EQ(1.0f, rectI->GetBottom());
548 }
549
550 /**
551 * @tc.name: RectISetAndGetBottom002
552 * @tc.desc:
553 * @tc.type: FUNC
554 * @tc.require:AR000GGNV3
555 * @tc.author:
556 */
557 HWTEST_F(RectTest, RectISetAndGetBottom002, TestSize.Level1)
558 {
559 std::unique_ptr<RectI> rectI = std::make_unique<RectI>();
560 rectI->SetBottom(2.0f);
561 EXPECT_EQ(2.0f, rectI->GetBottom());
562 }
563
564 /**
565 * @tc.name: RectIOffset001
566 * @tc.desc:
567 * @tc.type: FUNC
568 * @tc.require:AR000GGNV3
569 * @tc.author:
570 */
571 HWTEST_F(RectTest, RectIOffset001, TestSize.Level1)
572 {
573 std::unique_ptr<RectI> rectI = std::make_unique<RectI>(1.0f, 2.0f, 3.0f, 4.0f);
574 rectI->Offset(1.0f, 2.0f);
575 EXPECT_EQ(2.0f, rectI->GetLeft());
576 EXPECT_EQ(4.0f, rectI->GetRight());
577 EXPECT_EQ(4.0f, rectI->GetTop());
578 EXPECT_EQ(6.0f, rectI->GetBottom());
579 }
580
581 /**
582 * @tc.name: RectIOffset002
583 * @tc.desc:
584 * @tc.type: FUNC
585 * @tc.require:AR000GGNV3
586 * @tc.author:
587 */
588 HWTEST_F(RectTest, RectIOffset002, TestSize.Level1)
589 {
590 std::unique_ptr<RectI> rectI = std::make_unique<RectI>(1.0f, 2.0f, 3.0f, 4.0f);
591 rectI->Offset(2.0f, 1.0f);
592 EXPECT_EQ(3.0f, rectI->GetLeft());
593 EXPECT_EQ(5.0f, rectI->GetRight());
594 EXPECT_EQ(3.0f, rectI->GetTop());
595 EXPECT_EQ(5.0f, rectI->GetBottom());
596 }
597
598 /**
599 * @tc.name: RectIEqual001
600 * @tc.desc:
601 * @tc.type: FUNC
602 * @tc.require:AR000GGNV3
603 * @tc.author:
604 */
605 HWTEST_F(RectTest, RectIEqual001, TestSize.Level1)
606 {
607 RectI recti1;
608 RectI recti2;
609 recti1.SetLeft(1.0f);
610 EXPECT_FALSE(recti1 == recti2);
611 }
612
613 /**
614 * @tc.name: RectIEqual002
615 * @tc.desc:
616 * @tc.type: FUNC
617 * @tc.require:AR000GGNV3
618 * @tc.author:
619 */
620 HWTEST_F(RectTest, RectIEqual002, TestSize.Level1)
621 {
622 RectI recti1;
623 RectI recti2;
624 EXPECT_TRUE(recti1 == recti2);
625 }
626
627 /**
628 * @tc.name: RectINotEqual001
629 * @tc.desc:
630 * @tc.type: FUNC
631 * @tc.require:AR000GGNV3
632 * @tc.author:
633 */
634 HWTEST_F(RectTest, RectINotEqual001, TestSize.Level1)
635 {
636 RectI recti1;
637 RectI recti2;
638 EXPECT_FALSE(recti1 != recti2);
639 }
640
641 /**
642 * @tc.name: RectINotEqual002
643 * @tc.desc:
644 * @tc.type: FUNC
645 * @tc.require:AR000GGNV3
646 * @tc.author:
647 */
648 HWTEST_F(RectTest, RectINotEqual002, TestSize.Level1)
649 {
650 RectI recti1;
651 RectI recti2;
652 recti2.SetLeft(2.0f);
653 EXPECT_TRUE(recti1 != recti2);
654 }
655 } // namespace Drawing
656 } // namespace Rosen
657 } // namespace OHOS