1 /*
2 * Copyright (c) 2020-2021 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 "gfx_utils/transform.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 class TransformTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26 static void TearDownTestCase(void);
27 static TransformMap* transform_;
28 };
29
30 TransformMap* TransformTest::transform_ = nullptr;
31
SetUpTestCase(void)32 void TransformTest::SetUpTestCase(void)
33 {
34 if (transform_ == nullptr) {
35 transform_ = new TransformMap();
36 }
37 }
38
TearDownTestCase(void)39 void TransformTest::TearDownTestCase(void)
40 {
41 if (transform_ != nullptr) {
42 delete transform_;
43 transform_ = nullptr;
44 }
45 }
46
47 /**
48 * @tc.name: TransformSetPolygon_001
49 * @tc.desc: Verify SetPolygon function, equal.
50 * @tc.type: FUNC
51 * @tc.require: AR000EEMQ9
52 */
53 HWTEST_F(TransformTest, TransformSetPolygon_001, TestSize.Level0)
54 {
55 if (transform_ == nullptr) {
56 EXPECT_EQ(1, 0);
57 return;
58 }
59 Polygon poly;
60 const uint8_t verterNum = 8;
61 poly.SetVertexNum(verterNum);
62 transform_->SetPolygon(poly);
63 EXPECT_EQ(transform_->GetPolygon().GetVertexNum(), verterNum);
64 }
65
66 /**
67 * @tc.name: TransformGetPivot_001
68 * @tc.desc: Verify GetPivot function, equal.
69 * @tc.type: FUNC
70 * @tc.require: AR000EEMQ9
71 */
72 HWTEST_F(TransformTest, TransformGetPivot_001, TestSize.Level0)
73 {
74 if (transform_ == nullptr) {
75 EXPECT_EQ(1, 0);
76 return;
77 }
78 EXPECT_EQ(transform_->GetPivot().x, 0);
79 EXPECT_EQ(transform_->GetPivot().y, 0);
80 }
81
82 /**
83 * @tc.name: TransformGetClockWise_001
84 * @tc.desc: Verify GetClockWise function, equal.
85 * @tc.type: FUNC
86 * @tc.require: AR000EEMQ9
87 */
88 HWTEST_F(TransformTest, TransformGetClockWise_001, TestSize.Level0)
89 {
90 if (transform_ == nullptr) {
91 EXPECT_EQ(1, 0);
92 return;
93 }
94 transform_->GetPolygon().SetVertexNum(2); // 2 < VERTEX_NUM_MIN
95 EXPECT_EQ(transform_->GetClockWise(), false);
96 }
97
98 /**
99 * @tc.name: TransformIsInvalid_001
100 * @tc.desc: Verify IsInvalid function, equal.
101 * @tc.type: FUNC
102 * @tc.require: AR000EEMQ9
103 */
104 HWTEST_F(TransformTest, TransformIsInvalid_001, TestSize.Level0)
105 {
106 if (transform_ == nullptr) {
107 EXPECT_EQ(1, 0);
108 return;
109 }
110 EXPECT_EQ(transform_->IsInvalid(), true);
111 }
112
113 /**
114 * @tc.name: TransformIsInvalid_002
115 * @tc.desc: Verify IsInvalid function, equal.
116 * @tc.type: FUNC
117 * @tc.require: AR000EEMQ9
118 */
119 HWTEST_F(TransformTest, TransformIsInvalid_002, TestSize.Level0)
120 {
121 TransformMap* transform = new TransformMap(Rect(1, 1, 1, 1));
122 if (transform == nullptr) {
123 EXPECT_EQ(1, 0);
124 return;
125 }
126 EXPECT_EQ(transform->IsInvalid(), false);
127 delete transform;
128 }
129
130 /**
131 * @tc.name: TransformGetTransMapRect_001
132 * @tc.desc: Verify IsInvalid function, equal.
133 * @tc.type: FUNC
134 * @tc.require: AR000EEMQ9
135 */
136 HWTEST_F(TransformTest, TransformGetTransMapRect_001, TestSize.Level0)
137 {
138 TransformMap* transform = new TransformMap(Rect(1, 1, 1, 1));
139 if (transform == nullptr) {
140 EXPECT_EQ(1, 0);
141 return;
142 }
143 EXPECT_EQ(transform->GetTransMapRect().GetLeft(), 1);
144 EXPECT_EQ(transform->GetTransMapRect().GetTop(), 1);
145 EXPECT_EQ(transform->GetTransMapRect().GetRight(), 1);
146 EXPECT_EQ(transform->GetTransMapRect().GetBottom(), 1);
147 delete transform;
148 }
149 } // namespace OHOS
150