1 /*
2 * Copyright (c) 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, 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 <cstddef>
17 #include <parameter.h>
18 #include <parameters.h>
19
20 #include "engine_adapter/static_factory.h"
21 #include "gtest/gtest.h"
22
23 #include "utils/memory_stream.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace Drawing {
31 class StaticFactoryTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 };
38
SetUpTestCase()39 void StaticFactoryTest::SetUpTestCase() {}
TearDownTestCase()40 void StaticFactoryTest::TearDownTestCase() {}
SetUp()41 void StaticFactoryTest::SetUp() {}
TearDown()42 void StaticFactoryTest::TearDown() {}
43
44 /**
45 * @tc.name: MakeFromRSXform001
46 * @tc.desc: Test StaticFactory
47 * @tc.type: FUNC
48 * @tc.require:I91EDT
49 */
50 HWTEST_F(StaticFactoryTest, MakeFromRSXform001, TestSize.Level1)
51 {
52 char text[10] = { 0 };
53 RSXform xform[] = { { 25, 36, 2, 5 }, { 7, 8, 9, 12 } };
54 Font font;
55 auto factory = StaticFactory::MakeFromRSXform(text, 10, xform, font, TextEncoding::UTF8);
56 ASSERT_TRUE(factory != nullptr);
57 }
58
59 /**
60 * @tc.name: MakeFromStream001
61 * @tc.desc: Test StaticFactory
62 * @tc.type: FUNC
63 * @tc.require:I91EDT
64 */
65 HWTEST_F(StaticFactoryTest, MakeFromStream001, TestSize.Level1)
66 {
67 char data[10] = { 0 };
68 auto stream = std::make_unique<MemoryStream>(data, 10);
69 ASSERT_TRUE(stream != nullptr);
70 auto factory = StaticFactory::MakeFromStream(std::move(stream), 0);
71 ASSERT_TRUE(factory == nullptr);
72 }
73
74 /**
75 * @tc.name: MakeFromName001
76 * @tc.desc: Test StaticFactory
77 * @tc.type: FUNC
78 * @tc.require:I91EDT
79 */
80 HWTEST_F(StaticFactoryTest, MakeFromName001, TestSize.Level1)
81 {
82 char familyName[] = "Arial";
83 auto factory = StaticFactory::MakeFromName(familyName, Drawing::FontStyle());
84 ASSERT_TRUE(factory != nullptr);
85 }
86
87 #ifdef RS_ENABLE_VK
88 /**
89 * @tc.name: MakeFromBackendRenderTarget001
90 * @tc.desc: Test StaticFactory
91 * @tc.type: FUNC
92 * @tc.require:I91EDT
93 */
94 HWTEST_F(StaticFactoryTest, MakeFromBackendRenderTarget001, TestSize.Level1)
95 {
96 auto gpuContext = new GPUContext();
97 ASSERT_TRUE(gpuContext != nullptr);
98 TextureInfo info;
99 info.SetWidth(10);
100 auto colorSpace = std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::NO_TYPE);
101 ASSERT_TRUE(colorSpace != nullptr);
102 auto type = system::GetParameter("persist.sys.graphic.GpuApitype", "-1");
103 system::SetParameter("persist.sys.graphic.GpuApitype", "0");
104 auto surface = StaticFactory::MakeFromBackendRenderTarget(gpuContext, info, TextureOrigin::TOP_LEFT,
105 ColorType::COLORTYPE_RGBA_8888, colorSpace, nullptr, nullptr);
106 ASSERT_TRUE(surface == nullptr);
107 system::SetParameter("persist.sys.graphic.GpuApitype", "1");
108 surface = StaticFactory::MakeFromBackendRenderTarget(gpuContext, info, TextureOrigin::TOP_LEFT,
109 ColorType::COLORTYPE_RGBA_8888, colorSpace, nullptr, nullptr);
110 ASSERT_TRUE(surface == nullptr);
111 system::SetParameter("persist.sys.graphic.GpuApitype", type);
112 delete gpuContext;
113 }
114 #endif
115
116 /**
117 * @tc.name: DeserializeTypeface001
118 * @tc.desc: Test StaticFactory
119 * @tc.type: FUNC
120 * @tc.require:I91EDT
121 */
122 HWTEST_F(StaticFactoryTest, DeserializeTypeface001, TestSize.Level1)
123 {
124 char data[10] = { 0 };
125 auto deserialize = StaticFactory::DeserializeTypeface(data, 10);
126 ASSERT_TRUE(deserialize == nullptr);
127 }
128
129 /**
130 * @tc.name: AsBlendMode001
131 * @tc.desc: Test StaticFactory
132 * @tc.type: FUNC
133 * @tc.require:I91EDT
134 */
135 HWTEST_F(StaticFactoryTest, AsBlendMode001, TestSize.Level1)
136 {
137 Brush brush;
138 ASSERT_TRUE(StaticFactory::AsBlendMode(brush) == true);
139 }
140
141 /**
142 * @tc.name: GetDrawingGlyphIDforTextBlob001
143 * @tc.desc: Test StaticFactory
144 * @tc.type: FUNC
145 * @tc.require:I91EDT
146 */
147 HWTEST_F(StaticFactoryTest, GetDrawingGlyphIDforTextBlob001, TestSize.Level1)
148 {
149 std::vector<uint16_t> glyphId;
150 char text[] = "hello";
151 int byteLength = 5;
152 Font font;
153 std::shared_ptr<TextBlob> blob =
154 TextBlob::MakeFromText(text, byteLength, font, static_cast<TextEncoding>(TextEncoding::UTF8));
155 StaticFactory::GetDrawingGlyphIDforTextBlob(blob.get(), glyphId);
156 ASSERT_TRUE(blob != nullptr);
157 }
158
159 /**
160 * @tc.name: GetDrawingPointsForTextBlob001
161 * @tc.desc: Test StaticFactory
162 * @tc.type: FUNC
163 * @tc.require:I91EDT
164 */
165 HWTEST_F(StaticFactoryTest, GetDrawingPointsForTextBlob001, TestSize.Level1)
166 {
167 char text[] = "hello";
168 int byteLength = 5;
169 Font font;
170 std::shared_ptr<TextBlob> blob =
171 TextBlob::MakeFromText(text, byteLength, font, static_cast<TextEncoding>(TextEncoding::UTF8));
172 std::vector<Point> points;
173 StaticFactory::GetDrawingPointsForTextBlob(blob.get(), points);
174 ASSERT_TRUE(blob != nullptr);
175 }
176
177 /**
178 * @tc.name: GetGroupParameters001
179 * @tc.desc: Test StaticFactory
180 * @tc.type: FUNC
181 * @tc.require:I91EDT
182 */
183 HWTEST_F(StaticFactoryTest, GetGroupParameters001, TestSize.Level1)
184 {
185 DrawingAnimationType type = DrawingAnimationType::SCALE_TYPE;
186 DrawingCommonSubType subType = DrawingCommonSubType::DOWN;
187 auto param = StaticFactory::GetGroupParameters(type, 0, 0, subType);
188 ASSERT_TRUE(param.empty());
189 }
190
191 } // namespace Drawing
192 } // namespace Rosen
193 } // namespace OHOS