1 /*
2 * Copyright (c) 2022 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 "gtest/gtest.h"
17
18 #include "effect/color_space.h"
19 #include "image/image.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class ColorSpaceTest : 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 ColorSpaceTest::SetUpTestCase() {}
TearDownTestCase()36 void ColorSpaceTest::TearDownTestCase() {}
SetUp()37 void ColorSpaceTest::SetUp() {}
TearDown()38 void ColorSpaceTest::TearDown() {}
39
40 /**
41 * @tc.name: CreateAndDestroy001
42 * @tc.desc:
43 * @tc.type: FUNC
44 * @tc.require: AR000GGNV3
45 * @tc.author:
46 */
47 HWTEST_F(ColorSpaceTest, CreateAndDestroy001, TestSize.Level1)
48 {
49 auto colorSpace = ColorSpace::CreateSRGB();
50 EXPECT_FALSE(colorSpace == nullptr);
51 }
52
53 /**
54 * @tc.name: CreatedByStaticMethod001
55 * @tc.desc:
56 * @tc.type: FUNC
57 * @tc.require: AR000GGNV3
58 * @tc.author:
59 */
60 HWTEST_F(ColorSpaceTest, CreatedByStaticMethod001, TestSize.Level1)
61 {
62 auto colorSpace = ColorSpace::CreateSRGBLinear();
63 EXPECT_FALSE(colorSpace == nullptr);
64 }
65
66 /**
67 * @tc.name: CreatedByStaticMethod003
68 * @tc.desc:
69 * @tc.type: FUNC
70 * @tc.require: AR000GGNV3
71 * @tc.author:
72 */
73 HWTEST_F(ColorSpaceTest, CreatedByStaticMethod003, TestSize.Level1)
74 {
75 Bitmap bmp;
76 BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
77 bmp.Build(10, 10, format);
78 Image image;
79 image.BuildFromBitmap(bmp);
80 auto colorSpace = ColorSpace::CreateRefImage(image);
81 EXPECT_FALSE(colorSpace == nullptr);
82 }
83
84 /**
85 * @tc.name: CreateAndGetType001
86 * @tc.desc:
87 * @tc.type: FUNC
88 * @tc.require: AR000GGNV3
89 * @tc.author:
90 */
91 HWTEST_F(ColorSpaceTest, CreateAndGetType001, TestSize.Level1)
92 {
93 auto colorSpace = std::make_unique<ColorSpace>(ColorSpace::ColorSpaceType::NO_TYPE);
94 ASSERT_TRUE(colorSpace != nullptr);
95 auto type = colorSpace->GetType();
96 EXPECT_EQ(type, ColorSpace::ColorSpaceType::NO_TYPE);
97 }
98
99 /**
100 * @tc.name: CreateAndGetType002
101 * @tc.desc:
102 * @tc.type: FUNC
103 * @tc.require: AR000GGNV3
104 * @tc.author:
105 */
106 HWTEST_F(ColorSpaceTest, CreateAndGetType002, TestSize.Level1)
107 {
108 auto colorSpace = std::make_unique<ColorSpace>(ColorSpace::ColorSpaceType::REF_IMAGE);
109 ASSERT_TRUE(colorSpace != nullptr);
110 auto type = colorSpace->GetType();
111 EXPECT_EQ(type, ColorSpace::ColorSpaceType::REF_IMAGE);
112 }
113
114 /**
115 * @tc.name: CreatedBy2Args001
116 * @tc.desc:
117 * @tc.type: FUNC
118 * @tc.require: AR000GGNV3
119 * @tc.author:
120 */
121 HWTEST_F(ColorSpaceTest, CreatedByArgs001, TestSize.Level1)
122 {
123 auto colorSpace = std::make_unique<ColorSpace>(ColorSpace::ColorSpaceType::REF_IMAGE);
124 EXPECT_TRUE(colorSpace != nullptr);
125 }
126
127 /**
128 * @tc.name: CreatedBy2Args002
129 * @tc.desc:
130 * @tc.type: FUNC
131 * @tc.require: AR000GGNV3
132 * @tc.author:
133 */
134 HWTEST_F(ColorSpaceTest, CreatedByArgs002, TestSize.Level1)
135 {
136 auto colorSpace = std::make_unique<ColorSpace>(ColorSpace::ColorSpaceType::NO_TYPE);
137 EXPECT_TRUE(colorSpace != nullptr);
138 }
139
140 /**
141 * @tc.name: CreatedByNoArgs002
142 * @tc.desc:
143 * @tc.type: FUNC
144 * @tc.require: AR000GGNV3
145 * @tc.author:
146 */
147 HWTEST_F(ColorSpaceTest, CreatedByNoArgs003, TestSize.Level1)
148 {
149 Bitmap bmp;
150 BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
151 bmp.Build(10, 10, format);
152 Image image;
153 image.BuildFromBitmap(bmp);
154 ColorSpace::ColorSpaceType colorSpaceType = ColorSpace::ColorSpaceType::SRGB_LINEAR;
155 auto colorSpace = std::make_unique<ColorSpace>(colorSpaceType, image);
156 EXPECT_TRUE(colorSpace != nullptr);
157 }
158 } // namespace Drawing
159 } // namespace Rosen
160 } // namespace OHOS
161