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_pixmap.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace Drawing {
26 class SkiaPixmapTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 };
33 
SetUpTestCase()34 void SkiaPixmapTest::SetUpTestCase() {}
TearDownTestCase()35 void SkiaPixmapTest::TearDownTestCase() {}
SetUp()36 void SkiaPixmapTest::SetUp() {}
TearDown()37 void SkiaPixmapTest::TearDown() {}
38 
39 /**
40  * @tc.name: GetColorType001
41  * @tc.desc: Test GetColorType
42  * @tc.type: FUNC
43  * @tc.require: I8VQSW
44  */
45 HWTEST_F(SkiaPixmapTest, GetColorType001, TestSize.Level1)
46 {
47     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
48     SkPixmap skPixmap;
49     skiaPixmap->ImportSkiaPixmap(skPixmap);
50     auto ret = skiaPixmap->GetColorType();
51     EXPECT_TRUE(ret == 0);
52 }
53 
54 /**
55  * @tc.name: GetAlphaType001
56  * @tc.desc: Test GetAlphaType
57  * @tc.type: FUNC
58  * @tc.require: I8VQSW
59  */
60 HWTEST_F(SkiaPixmapTest, GetAlphaType001, TestSize.Level1)
61 {
62     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
63     SkPixmap skPixmap;
64     skiaPixmap->ImportSkiaPixmap(skPixmap);
65     auto ret = skiaPixmap->GetAlphaType();
66     EXPECT_TRUE(ret != AlphaType::ALPHATYPE_OPAQUE);
67 }
68 
69 /**
70  * @tc.name: GetColor001
71  * @tc.desc: Test GetColor
72  * @tc.type: FUNC
73  * @tc.require: I8VQSW
74  */
75 HWTEST_F(SkiaPixmapTest, GetColor001, TestSize.Level1)
76 {
77     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
78     SkPixmap skPixmap;
79     skiaPixmap->ImportSkiaPixmap(skPixmap);
80     auto ret = skiaPixmap->GetColor(0, 0);
81     EXPECT_TRUE(ret == 0);
82 }
83 
84 /**
85  * @tc.name: GetRowBytes001
86  * @tc.desc: Test GetRowBytes
87  * @tc.type: FUNC
88  * @tc.require: I8VQSW
89  */
90 HWTEST_F(SkiaPixmapTest, GetRowBytes001, TestSize.Level1)
91 {
92     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
93     SkPixmap skPixmap;
94     skiaPixmap->ImportSkiaPixmap(skPixmap);
95     auto ret = skiaPixmap->GetRowBytes();
96     EXPECT_TRUE(ret == 0);
97 }
98 
99 /**
100  * @tc.name: GetAddr001
101  * @tc.desc: Test GetAddr
102  * @tc.type: FUNC
103  * @tc.require: I8VQSW
104  */
105 HWTEST_F(SkiaPixmapTest, GetAddr001, TestSize.Level1)
106 {
107     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
108     SkPixmap skPixmap;
109     skiaPixmap->ImportSkiaPixmap(skPixmap);
110     auto ret = skiaPixmap->GetAddr();
111     EXPECT_TRUE(ret == nullptr);
112 }
113 
114 /**
115  * @tc.name: GetWidth001
116  * @tc.desc: Test GetWidth
117  * @tc.type: FUNC
118  * @tc.require: I8VQSW
119  */
120 HWTEST_F(SkiaPixmapTest, GetWidth001, TestSize.Level1)
121 {
122     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
123     SkPixmap skPixmap;
124     skiaPixmap->ImportSkiaPixmap(skPixmap);
125     auto ret = skiaPixmap->GetWidth();
126     EXPECT_TRUE(ret == 0);
127 }
128 
129 /**
130  * @tc.name: GetHeight001
131  * @tc.desc: Test GetHeight
132  * @tc.type: FUNC
133  * @tc.require: I8VQSW
134  */
135 HWTEST_F(SkiaPixmapTest, GetHeight001, TestSize.Level1)
136 {
137     std::shared_ptr<SkiaPixmap> skiaPixmap = std::make_shared<SkiaPixmap>();
138     SkPixmap skPixmap;
139     skiaPixmap->ImportSkiaPixmap(skPixmap);
140     auto ret = skiaPixmap->GetHeight();
141     EXPECT_TRUE(ret == 0);
142 }
143 } // namespace Drawing
144 } // namespace Rosen
145 } // namespace OHOS