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_color_space.h"
19 #include "effect/color_space.h"
20 #include "image/bitmap.h"
21 #include "image/image.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class SkiaColorSpaceTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
SetUpTestCase()37 void SkiaColorSpaceTest::SetUpTestCase() {}
TearDownTestCase()38 void SkiaColorSpaceTest::TearDownTestCase() {}
SetUp()39 void SkiaColorSpaceTest::SetUp() {}
TearDown()40 void SkiaColorSpaceTest::TearDown() {}
41
42 /**
43 * @tc.name: InitWithSRGB001
44 * @tc.desc: Test InitWithSRGB
45 * @tc.type: FUNC
46 * @tc.require: I91F9L
47 */
48 HWTEST_F(SkiaColorSpaceTest, InitWithSRGB001, TestSize.Level1)
49 {
50 SkiaColorSpace skiaColorSpace;
51 skiaColorSpace.InitWithSRGB();
52 }
53
54 /**
55 * @tc.name: InitWithSRGBLinear001
56 * @tc.desc: Test InitWithSRGBLinear
57 * @tc.type: FUNC
58 * @tc.require: I91F9L
59 */
60 HWTEST_F(SkiaColorSpaceTest, InitWithSRGBLinear001, TestSize.Level1)
61 {
62 SkiaColorSpace skiaColorSpace;
63 skiaColorSpace.InitWithSRGBLinear();
64 }
65
66 /**
67 * @tc.name: InitWithImage001
68 * @tc.desc: Test InitWithImage
69 * @tc.type: FUNC
70 * @tc.require: I91F9L
71 */
72 HWTEST_F(SkiaColorSpaceTest, InitWithImage001, TestSize.Level1)
73 {
74 Bitmap bmp;
75 BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
76 bmp.Build(10, 10, format); // 10: width, height
77 Image image;
78 image.BuildFromBitmap(bmp);
79 SkiaColorSpace skiaColorSpace;
80 skiaColorSpace.InitWithImage(image);
81 }
82
83 /**
84 * @tc.name: GetColorSpace001
85 * @tc.desc: Test GetColorSpace
86 * @tc.type: FUNC
87 * @tc.require: I91F9L
88 */
89 HWTEST_F(SkiaColorSpaceTest, GetColorSpace001, TestSize.Level1)
90 {
91 SkiaColorSpace skiaColorSpace;
92 skiaColorSpace.GetColorSpace();
93 }
94
95 /**
96 * @tc.name: GetSkColorSpace001
97 * @tc.desc: Test GetSkColorSpace
98 * @tc.type: FUNC
99 * @tc.require: I91F9L
100 */
101 HWTEST_F(SkiaColorSpaceTest, GetSkColorSpace001, TestSize.Level1)
102 {
103 SkiaColorSpace skiaColorSpace;
104 skiaColorSpace.GetSkColorSpace();
105 }
106
107 /**
108 * @tc.name: Deserialize001
109 * @tc.desc: Test Deserialize
110 * @tc.type: FUNC
111 * @tc.require: I91F9L
112 */
113 HWTEST_F(SkiaColorSpaceTest, Deserialize001, TestSize.Level1)
114 {
115 SkiaColorSpace skiaColorSpace;
116 skiaColorSpace.Deserialize(nullptr);
117 }
118
119 /**
120 * @tc.name: IsSRGB001
121 * @tc.desc: Test IsSRGB
122 * @tc.type: FUNC
123 * @tc.require:
124 */
125 HWTEST_F(SkiaColorSpaceTest, IsSRGB001, TestSize.Level1)
126 {
127 SkiaColorSpace skiaColorSpace;
128 skiaColorSpace.InitWithSRGB();
129 EXPECT_TRUE(skiaColorSpace.IsSRGB());
130 }
131
132 /**
133 * @tc.name: Equals001
134 * @tc.desc: Test Equals
135 * @tc.type: FUNC
136 * @tc.require:
137 */
138 HWTEST_F(SkiaColorSpaceTest, Equals001, TestSize.Level1)
139 {
140 std::shared_ptr<ColorSpaceImpl> colorSpaceImpl = std::make_shared<SkiaColorSpace>();
141 colorSpaceImpl->InitWithSRGB();
142 std::shared_ptr<ColorSpace> colorSpace = ColorSpace::CreateFromImpl(colorSpaceImpl);
143
144 SkiaColorSpace skiaColorSpace;
145 skiaColorSpace.InitWithSRGB();
146 EXPECT_TRUE(skiaColorSpace.Equals(colorSpace));
147 }
148 } // namespace Drawing
149 } // namespace Rosen
150 } // namespace OHOS