• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "gtest/gtest.h"
19 #include "skia_adapter/skia_static_factory.h"
20 
21 #include "text/rs_xform.h"
22 #include "text/text_blob.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class SkiaStaticFactoryTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp() override;
35     void TearDown() override;
36 };
37 
SetUpTestCase()38 void SkiaStaticFactoryTest::SetUpTestCase() {}
TearDownTestCase()39 void SkiaStaticFactoryTest::TearDownTestCase() {}
SetUp()40 void SkiaStaticFactoryTest::SetUp() {}
TearDown()41 void SkiaStaticFactoryTest::TearDown() {}
42 
43 /**
44  * @tc.name: MakeFromRSXform001
45  * @tc.desc: Test MakeFromRSXform
46  * @tc.type: FUNC
47  * @tc.require:I91EDT
48  */
49 HWTEST_F(SkiaStaticFactoryTest, MakeFromRSXform001, TestSize.Level1)
50 {
51     const char* str = "asdf";
52     Font font;
53     font.SetSize(100);
54     RSXform xform[] = { RSXform::Make(10, 10, 10, 10) }; // 10: cos, sin, tx, ty
55     auto skiaStatic = SkiaStaticFactory::MakeFromRSXform(str, strlen(str), xform, font, TextEncoding::UTF8);
56     ASSERT_TRUE(skiaStatic != nullptr);
57 }
58 
59 /**
60  * @tc.name: MakeFromStream001
61  * @tc.desc: Test MakeFromStream
62  * @tc.type: FUNC
63  * @tc.require:I91EDT
64  */
65 
66 HWTEST_F(SkiaStaticFactoryTest, MakeFromStream001, TestSize.Level1)
67 {
68     MemoryStream memoryStream;
69     int index = 0;
70     auto skiaStatic = SkiaStaticFactory::MakeFromStream(std::make_unique<MemoryStream>(memoryStream), index);
71 
72     ASSERT_TRUE(skiaStatic == nullptr);
73 }
74 
75 /**
76  * @tc.name: MakeFromName001
77  * @tc.desc: Test MakeFromName
78  * @tc.type: FUNC
79  * @tc.require:I91EDT
80  */
81 
82 HWTEST_F(SkiaStaticFactoryTest, MakeFromName001, TestSize.Level1)
83 {
84     char familyName[] = "qewe";
85 
86     FontStyle foustyle;
87 
88     auto skiaStatic = SkiaStaticFactory::MakeFromName(familyName, foustyle);
89     ASSERT_TRUE(skiaStatic != nullptr);
90 }
91 
92 /**
93  * @tc.name: MakeFromBackendRenderTarget001
94  * @tc.desc: Test MakeFromYUVAPixmaps
95  * @tc.type: FUNC
96  * @tc.require:I91EDT
97  */
98 
99 #ifdef RS_ENABLE_VK
100 HWTEST_F(SkiaStaticFactoryTest, MakeFromBackendRenderTarget001, TestSize.Level1)
101 {
102     OHOS::Rosen::Drawing::GPUContext gpuContext;
103     TextureInfo texttureinfo;
104     auto colorSpace = std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::NO_TYPE);
105     void (*deleteVkImage)(void*) = nullptr;
106 
107     void* cleanHelper = nullptr;
108     auto skiaStatic = SkiaStaticFactory::MakeFromBackendRenderTarget(gpuContext, texttureinfo, TextureOrigin::TOP_LEFT,
109         ColorType::COLORTYPE_ALPHA_8, colorSpace, deleteVkImage, cleanHelper);
110     ASSERT_TRUE(skiaStatic, nullptr);
111     delete (skiaStatic);
112 }
113 #endif
114 
115 /**
116  * @tc.name: MakeFromYUVAPixmaps001
117  * @tc.desc: Test MakeFromYUVAPixmaps
118  * @tc.type: FUNC
119  * @tc.require:I91EDT
120  */
121 
122 HWTEST_F(SkiaStaticFactoryTest, MakeFromYUVAPixmaps001, TestSize.Level1)
123 {
124     OHOS::Rosen::Drawing::GPUContext gpuContext;
125     YUVInfo info(100, 100, YUVInfo::PlaneConfig::Y_UV, YUVInfo::SubSampling::K420,
126         YUVInfo::YUVColorSpace::JPEG_FULL_YUVCOLORSPACE,
127         YUVInfo::YUVDataType::UNORM_8);
128 
129     auto skiaStatic = SkiaStaticFactory::MakeFromYUVAPixmaps(gpuContext, info, nullptr);
130 
131     ASSERT_TRUE(skiaStatic == nullptr);
132 }
133 
134 /**
135  * @tc.name: DeserializeTypeface001
136  * @tc.desc: Test DeserializeTypeface
137  * @tc.type: FUNC
138  * @tc.require:I91EDT
139  */
140 
141 HWTEST_F(SkiaStaticFactoryTest, DeserializeTypeface001, TestSize.Level1)
142 {
143     const char* data = "fcdsafsa";
144 
145     auto skiaStatic = SkiaStaticFactory::DeserializeTypeface(data, strlen(data));
146     ASSERT_TRUE(skiaStatic == nullptr);
147 }
148 /**
149  * @tc.name: AsBlendMode001
150  * @tc.desc: Test AsBlendMode
151  * @tc.type: FUNC
152  * @tc.require:I91EDT
153  */
154 
155 HWTEST_F(SkiaStaticFactoryTest, AsBlendMode001, TestSize.Level1)
156 {
157     Brush brush;
158     brush.SetAntiAlias(true);
159 
160     bool skiaStatic = SkiaStaticFactory::AsBlendMode(brush);
161     ASSERT_TRUE(skiaStatic);
162 }
163 
164 /**
165  * @tc.name: MakeDataFromFileName001
166  * @tc.desc: Test MakeDataFromFileName
167  * @tc.type: FUNC
168  * @tc.require:I91EDT
169  */
170 
171 HWTEST_F(SkiaStaticFactoryTest, MakeDataFromFileName001, TestSize.Level1)
172 {
173     const char data[] = "";
174     auto skiaStatic = SkiaStaticFactory::MakeDataFromFileName(data);
175     ASSERT_TRUE(skiaStatic == nullptr);
176 }
177 
178 /**
179  * @tc.name: GetDrawingPathforTextBlob001
180  * @tc.desc: Test GetDrawingPathforTextBlob
181  * @tc.type: FUNC
182  * @tc.require:I91EDT
183  */
184 HWTEST_F(SkiaStaticFactoryTest, GetDrawingPathforTextBlob001, TestSize.Level1)
185 {
186     uint16_t glyphId = 65;
187 
188     Rosen::Drawing::Font font;
189     font.SetSize(100);
190 
191     auto textBlob = TextBlob::MakeFromString("11", font, TextEncoding::UTF8);
192     ASSERT_TRUE(textBlob.get() != nullptr);
193     auto skiaStatic = SkiaStaticFactory::GetDrawingPathforTextBlob(glyphId, textBlob.get());
194     ASSERT_TRUE(skiaStatic.IsValid());
195 }
196 
197 /**
198  * @tc.name: GetDrawingPointsForTextBlob001
199  * @tc.desc: Test GetDrawingPointsForTextBlob
200  * @tc.type: FUNC
201  * @tc.require:I91EDT
202  */
203 
204 HWTEST_F(SkiaStaticFactoryTest, GetDrawingPointsForTextBlob001, TestSize.Level1)
205 {
206     Rosen::Drawing::Font font;
207     font.SetSize(100);
208     auto textBlob = TextBlob::MakeFromString("11", font, TextEncoding::UTF8);
209     Point p1 { 0, 0 };
210     Point p2 { 1, 1 };
211     vector<Point> point;
212     point.push_back(p1);
213     point.push_back(p2);
214     ASSERT_TRUE(textBlob.get() != nullptr);
215     SkiaStaticFactory::GetDrawingPointsForTextBlob(textBlob.get(), point);
216 }
217 
218 /**
219  * @tc.name: GetGroupParameters001
220  * @tc.desc: Test GetGroupParameters
221  * @tc.type: FUNC
222  * @tc.require:I91EDT
223  */
224 
225 HWTEST_F(SkiaStaticFactoryTest, GetGroupParameters001, TestSize.Level1)
226 {
227     uint16_t groupSum = 1;
228     uint16_t animationMode = 1;
229     auto skiaStatic = SkiaStaticFactory::GetGroupParameters(
230         DrawingAnimationType::SCALE_TYPE, groupSum, animationMode, DrawingCommonSubType::UP);
231     if (!skiaStatic.empty()) {
232         EXPECT_EQ(skiaStatic.size(), groupSum);
233     }
234 }
235 
236 } // namespace Drawing
237 } // namespace Rosen
238 } // namespace OHOS