1 /*
2 * Copyright (c) 2023 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/matrix44.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 Matrix44Test : 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 Matrix44Test::SetUpTestCase() {}
TearDownTestCase()37 void Matrix44Test::TearDownTestCase() {}
SetUp()38 void Matrix44Test::SetUp() {}
TearDown()39 void Matrix44Test::TearDown() {}
40
41 /**
42 * @tc.name: CreateMatrix44Test001
43 * @tc.desc: test for creating Matrix44.
44 * @tc.type: FUNC
45 * @tc.require: I766AZ
46 */
47 HWTEST_F(Matrix44Test, CreateMatrix44Test001, TestSize.Level1)
48 {
49 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
50 ASSERT_TRUE(matrix44 != nullptr);
51 }
52
53 /**
54 * @tc.name: Matrix44TranslateTest001
55 * @tc.desc: test seting Matrix44 to translate by (dx, dy, dz).
56 * @tc.type: FUNC
57 * @tc.require: I766AZ
58 */
59 HWTEST_F(Matrix44Test, Matrix44TranslateTest001, TestSize.Level1)
60 {
61 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
62 ASSERT_TRUE(matrix44 != nullptr);
63 matrix44->Translate(20.8f, 100, 19);
64 }
65
66 /**
67 * @tc.name: Matrix44TranslateTest002
68 * @tc.desc: test seting Matrix44 to translate by (dx, dy, dz).
69 * @tc.type: FUNC
70 * @tc.require: I766AZ
71 */
72 HWTEST_F(Matrix44Test, Matrix44TranslateTest002, TestSize.Level1)
73 {
74 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
75 ASSERT_TRUE(matrix44 != nullptr);
76 matrix44->Translate(77.7f, 190.2f, 25.2f);
77 }
78
79 /**
80 * @tc.name: Matrix44ScaleTest001
81 * @tc.desc: test for seting Matrix44 to scale by sx, sy and sz about pivot point at (0, 0, 0).
82 * @tc.type: FUNC
83 * @tc.require: I766AZ
84 */
85 HWTEST_F(Matrix44Test, Matrix44ScaleTest001, TestSize.Level1)
86 {
87 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
88 ASSERT_TRUE(matrix44 != nullptr);
89 matrix44->Scale(32.1f, 10.6f, 800);
90 }
91
92 /**
93 * @tc.name: Matrix44ScaleTest002
94 * @tc.desc: test for seting Matrix44 to scale by sx, sy and sz about pivot point at (0, 0, 0).
95 * @tc.type: FUNC
96 * @tc.require: I766AZ
97 */
98 HWTEST_F(Matrix44Test, Matrix44ScaleTest002, TestSize.Level1)
99 {
100 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
101 ASSERT_TRUE(matrix44 != nullptr);
102 matrix44->Scale(16.5f, 50.6f, 150.8f);
103 }
104
105 /**
106 * @tc.name: Matrix44SetMatrix44Test001
107 * @tc.desc: test for setong Matrix44 to sixteen values in buffer.
108 * @tc.type: FUNC
109 * @tc.require: I766AZ
110 */
111 HWTEST_F(Matrix44Test, Matrix44SetMatrix44Test001, TestSize.Level1)
112 {
113 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
114 ASSERT_TRUE(matrix44 != nullptr);
115 matrix44->SetMatrix44ColMajor({200, 150, 800, 60, 200, 150, 800, 60, 90, 22,
116 3, 55, 66, 99, 14, 16});
117 }
118
119 /**
120 * @tc.name: Matrix44SetMatrix44Test002
121 * @tc.desc: test for setong Matrix44 to sixteen values in buffer.
122 * @tc.type: FUNC
123 * @tc.require: I766AZ
124 */
125 HWTEST_F(Matrix44Test, Matrix44SetMatrix44Test002, TestSize.Level1)
126 {
127 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
128 ASSERT_TRUE(matrix44 != nullptr);
129 std::array<scalar, 16> buffer = {200, 150, 80, 60, 200, 150, 80, 60,
130 900, 221, 3, 60.5f, 60.1f, 90.5f, 80.8f, 60.6f};
131 matrix44->SetMatrix44ColMajor(buffer);
132 }
133
134 /**
135 * @tc.name: Matrix44SetMatrix44Test003
136 * @tc.desc: test for setong Matrix44 to sixteen values in buffer.
137 * @tc.type: FUNC
138 * @tc.require: I766AZ
139 */
140 HWTEST_F(Matrix44Test, Matrix44SetMatrix44Test003, TestSize.Level1)
141 {
142 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
143 ASSERT_TRUE(matrix44 != nullptr);
144 std::array<scalar, 16> buffer = {20.9f, 15.8f, 80.8f, 60.6f, 2.4f, 99.9f, 60.5f, 60.1f,
145 90.5f, 2.4f, 99.9f, 60.5f, 60.1f, 90.5f, 80.8f, 60.6f};
146 matrix44->SetMatrix44ColMajor(buffer);
147 }
148
149 /**
150 * @tc.name: Matrix44MultiplyTest001
151 * @tc.desc: testing Matrix44 multiplication.
152 * @tc.type: FUNC
153 * @tc.require: I766AZ
154 */
155 HWTEST_F(Matrix44Test, Matrix44MultiplyTest001, TestSize.Level1)
156 {
157 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
158 ASSERT_TRUE(matrix44 != nullptr);
159 Matrix44 matrix1;
160 Matrix44 matrix2;
161 Matrix44 matrix3 = matrix1 * matrix2;
162 }
163
164 /**
165 * @tc.name: Matrix44MultiplyTest002
166 * @tc.desc: testing Matrix44 multiplication.
167 * @tc.type: FUNC
168 * @tc.require: I766AZ
169 */
170 HWTEST_F(Matrix44Test, Matrix44MultiplyTest002, TestSize.Level1)
171 {
172 std::unique_ptr<Matrix44> matrix44 = std::make_unique<Matrix44>();
173 ASSERT_TRUE(matrix44 != nullptr);
174 Matrix44 matrix1;
175 matrix1.SetMatrix44ColMajor({200, 150, 800, 60, 200, 150, 800, 60, 90, 22, 3, 55, 66, 99, 14, 16});
176 Matrix44 matrix2;
177 matrix2.SetMatrix44ColMajor({200, 150, 800, 60, 200, 150, 800, 60, 90, 22, 3, 55, 66, 99, 14, 16});
178 Matrix44 matrix3 = matrix1 * matrix2;
179 }
180 } // namespace Drawing
181 } // namespace Rosen
182 } // namespace OHOS
183