• 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 #include "gtest/gtest.h"
18 #include "skia_adapter/skia_text_blob.h"
19 #include "text/text_blob.h"
20 #include "text/rs_xform.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class SkiaTextBlobTest : 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 SkiaTextBlobTest::SetUpTestCase() {}
TearDownTestCase()37 void SkiaTextBlobTest::TearDownTestCase() {}
SetUp()38 void SkiaTextBlobTest::SetUp() {}
TearDown()39 void SkiaTextBlobTest::TearDown() {}
40 
41 /**
42  * @tc.name: MakeFromText001
43  * @tc.desc: Test MakeFromText
44  * @tc.type: FUNC
45  * @tc.require:I91EDT
46  */
47 HWTEST_F(SkiaTextBlobTest, MakeFromText001, TestSize.Level1)
48 {
49     const char* str = "asdf";
50     Font font;
51     font.SetSize(100);
52     auto textblob = SkiaTextBlob::MakeFromText(str, strlen(str), font, TextEncoding::UTF8);
53     ASSERT_TRUE(textblob != nullptr);
54 }
55 
56 /**
57  * @tc.name: MakeFromRSXform001
58  * @tc.desc: Test MakeFromRSXform
59  * @tc.type: FUNC
60  * @tc.require:I91EDT
61  */
62 HWTEST_F(SkiaTextBlobTest, MakeFromRSXform001, TestSize.Level1)
63 {
64     const char* str = "asdf";
65     Font font;
66     font.SetSize(100);
67     RSXform xform[] = {RSXform::Make(10, 10, 10, 10)}; // 10: cos, sin, tx, ty
68     auto textblob = SkiaTextBlob::MakeFromRSXform(str, strlen(str), xform, font, TextEncoding::UTF8);
69     ASSERT_TRUE(textblob != nullptr);
70 }
71 
72 /**
73  * @tc.name: MakeFromPosText001
74  * @tc.desc: Test MakeFromPosText
75  * @tc.type: FUNC
76  * @tc.require:I91EDT
77  */
78 HWTEST_F(SkiaTextBlobTest, MakeFromPosText001, TestSize.Level1)
79 {
80     const char* str = "as";
81     Font font;
82     font.SetSize(100);
83     Point p1{0, 0};
84     Point p2{1, 1};
85     Point pos[] = {p1, p2};
86     auto textblob = SkiaTextBlob::MakeFromPosText(str, strlen(str), pos, font, TextEncoding::UTF8);
87     ASSERT_TRUE(textblob != nullptr);
88 }
89 
90 /**
91  * @tc.name: GetDrawingGlyphIDforTextBlob001
92  * @tc.desc: Test GetDrawingGlyphIDforTextBlob
93  * @tc.type: FUNC
94  * @tc.require:I91EDT
95  */
96 HWTEST_F(SkiaTextBlobTest, GetDrawingGlyphIDforTextBlob001, TestSize.Level1)
97 {
98     const char* str = "asdf";
99     Font font;
100     font.SetSize(100);
101     auto textblob = SkiaTextBlob::MakeFromText(str, strlen(str), font, TextEncoding::UTF8);
102     ASSERT_TRUE(textblob != nullptr);
103     std::vector<uint16_t> glyphIds{0, 1};
104     SkiaTextBlob::GetDrawingGlyphIDforTextBlob(textblob.get(), glyphIds);
105 }
106 } // namespace Drawing
107 } // namespace Rosen
108 } // namespace OHOS