• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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_pixmap.h"
19 #include "image/pixmap.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaPixmapTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33 };
34 
SetUpTestCase()35 void SkiaPixmapTest::SetUpTestCase() {}
TearDownTestCase()36 void SkiaPixmapTest::TearDownTestCase() {}
SetUp()37 void SkiaPixmapTest::SetUp() {}
TearDown()38 void SkiaPixmapTest::TearDown() {}
39 
40 /**
41  * @tc.name: GetColorType001
42  * @tc.desc: Test GetColorType
43  * @tc.type: FUNC
44  * @tc.require: I8VQSW
45  */
46 HWTEST_F(SkiaPixmapTest, GetColorType001, TestSize.Level1)
47 {
48     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
49     SkPixmap skPixmap;
50     skiaPixmap->ImportSkiaPixmap(skPixmap);
51     auto ret = skiaPixmap->GetColorType();
52     EXPECT_TRUE(ret == 0);
53 }
54 
55 /**
56  * @tc.name: GetAlphaType001
57  * @tc.desc: Test GetAlphaType
58  * @tc.type: FUNC
59  * @tc.require: I8VQSW
60  */
61 HWTEST_F(SkiaPixmapTest, GetAlphaType001, TestSize.Level1)
62 {
63     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
64     SkPixmap skPixmap;
65     skiaPixmap->ImportSkiaPixmap(skPixmap);
66     auto ret = skiaPixmap->GetAlphaType();
67     EXPECT_TRUE(ret != AlphaType::ALPHATYPE_OPAQUE);
68 }
69 
70 /**
71  * @tc.name: GetColor001
72  * @tc.desc: Test GetColor
73  * @tc.type: FUNC
74  * @tc.require: I8VQSW
75  */
76 HWTEST_F(SkiaPixmapTest, GetColor001, TestSize.Level1)
77 {
78     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
79     SkPixmap skPixmap;
80     skiaPixmap->ImportSkiaPixmap(skPixmap);
81     auto ret = skiaPixmap->GetColor(0, 0);
82     EXPECT_TRUE(ret == 0);
83 }
84 
85 /**
86  * @tc.name: GetRowBytes001
87  * @tc.desc: Test GetRowBytes
88  * @tc.type: FUNC
89  * @tc.require: I8VQSW
90  */
91 HWTEST_F(SkiaPixmapTest, GetRowBytes001, TestSize.Level1)
92 {
93     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
94     SkPixmap skPixmap;
95     skiaPixmap->ImportSkiaPixmap(skPixmap);
96     auto ret = skiaPixmap->GetRowBytes();
97     EXPECT_TRUE(ret == 0);
98 }
99 
100 /**
101  * @tc.name: GetAddr001
102  * @tc.desc: Test GetAddr
103  * @tc.type: FUNC
104  * @tc.require: I8VQSW
105  */
106 HWTEST_F(SkiaPixmapTest, GetAddr001, TestSize.Level1)
107 {
108     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
109     SkPixmap skPixmap;
110     skiaPixmap->ImportSkiaPixmap(skPixmap);
111     auto ret = skiaPixmap->GetAddr();
112     EXPECT_TRUE(ret == nullptr);
113 }
114 
115 /**
116  * @tc.name: GetWidth001
117  * @tc.desc: Test GetWidth
118  * @tc.type: FUNC
119  * @tc.require: I8VQSW
120  */
121 HWTEST_F(SkiaPixmapTest, GetWidth001, TestSize.Level1)
122 {
123     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
124     SkPixmap skPixmap;
125     skiaPixmap->ImportSkiaPixmap(skPixmap);
126     auto ret = skiaPixmap->GetWidth();
127     EXPECT_TRUE(ret == 0);
128 }
129 
130 /**
131  * @tc.name: GetHeight001
132  * @tc.desc: Test GetHeight
133  * @tc.type: FUNC
134  * @tc.require: I8VQSW
135  */
136 HWTEST_F(SkiaPixmapTest, GetHeight001, TestSize.Level1)
137 {
138     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
139     SkPixmap skPixmap;
140     skiaPixmap->ImportSkiaPixmap(skPixmap);
141     auto ret = skiaPixmap->GetHeight();
142     EXPECT_TRUE(ret == 0);
143 }
144 
145 /**
146  * @tc.name: ScalePixels001
147  * @tc.desc: Test ScalePixels
148  * @tc.type: FUNC
149  * @tc.require: IAKGJ7
150  */
151 HWTEST_F(SkiaPixmapTest, ScalePixels001, TestSize.Level1)
152 {
153     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
154     Pixmap pixmap;
155     CubicResampler cubicResampler;
156     SamplingOptions options1 { cubicResampler };
157     ASSERT_TRUE(!skiaPixmap->ScalePixels(pixmap, options1));
158 }
159 
160 /**
161  * @tc.name: ScalePixels002
162  * @tc.desc: Test ScalePixels
163  * @tc.type: FUNC
164  * @tc.require: IAKGJ7
165  */
166 HWTEST_F(SkiaPixmapTest, ScalePixels002, TestSize.Level1)
167 {
168     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
169     Pixmap pixmap;
170     SamplingOptions options1 {FilterMode::NEAREST, MipmapMode::NEAREST};
171     ASSERT_TRUE(!skiaPixmap->ScalePixels(pixmap, options1));
172 }
173 } // namespace Drawing
174 } // namespace Rosen
175 } // namespace OHOS