1 /*
2  * Copyright (c) 2023 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 "render/rs_filter.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS::Rosen {
24 class RSFilterTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30 };
31 
SetUpTestCase()32 void RSFilterTest::SetUpTestCase() {}
TearDownTestCase()33 void RSFilterTest::TearDownTestCase() {}
SetUp()34 void RSFilterTest::SetUp() {}
TearDown()35 void RSFilterTest::TearDown() {}
36 
37 /**
38  * @tc.name: CreateBlurFilter
39  * @tc.desc:
40  * @tc.type:FUNC
41  */
42 HWTEST_F(RSFilterTest, CreateBlurFilter, TestSize.Level1)
43 {
44     float blurRadiusX = 1.0f;
45     float blurRadiusY = 1.0f;
46     auto filter = RSFilter::CreateBlurFilter(blurRadiusX, blurRadiusY);
47     ASSERT_NE(filter, nullptr);
48 
49     float dipScale = 1.0f;
50     float ratio = 1.0f;
51     auto filter2 = RSFilter::CreateMaterialFilter(0, dipScale, BLUR_COLOR_MODE::DEFAULT, ratio);
52     ASSERT_NE(filter2, nullptr);
53 
54     float radius = 1.0f;
55     float saturation = 1.0f;
56     float brightness = 1.0f;
57     auto filter3 = RSFilter::CreateMaterialFilter(radius, saturation, brightness, 0, BLUR_COLOR_MODE::DEFAULT);
58     ASSERT_NE(filter3, nullptr);
59 }
60 
61 /**
62  * @tc.name: GetDescriptionTest
63  * @tc.desc: Verify function GetDescription
64  * @tc.type:FUNC
65  * @tc.require: issueI9I98H
66  */
67 HWTEST_F(RSFilterTest, GetDescriptionTest, TestSize.Level1)
68 {
69     RSFilter rSFilter;
70     auto filter = rSFilter.GetDescription();
71     EXPECT_EQ(filter, "RSFilter 0");
72 }
73 
74 /**
75  * @tc.name: CreateMaterialFilterTest001
76  * @tc.desc: Verify function CreateMaterialFilter
77  * @tc.type:FUNC
78  * @tc.require: issueI9I98H
79  */
80 HWTEST_F(RSFilterTest, CreateMaterialFilterTest001, TestSize.Level1)
81 {
82     float dipScale = 1.0f;
83     float ratio = 1.0f;
84     auto filter = RSFilter::CreateMaterialFilter(0, dipScale, BLUR_COLOR_MODE::DEFAULT, ratio);
85     ASSERT_NE(filter, nullptr);
86 }
87 
88 /**
89  * @tc.name: CreateMaterialFilterTest002
90  * @tc.desc: Verify function CreateMaterialFilter
91  * @tc.type:FUNC
92  * @tc.require: issueI9I98H
93  */
94 HWTEST_F(RSFilterTest, CreateMaterialFilterTest002, TestSize.Level1)
95 {
96     float lightUpDegree = 1.0f;
97     auto filter = RSFilter::CreateLightUpEffectFilter(lightUpDegree);
98     ASSERT_NE(filter, nullptr);
99 }
100 
101 /**
102  * @tc.name: operatorTest001
103  * @tc.desc: Verify function operator+
104  * @tc.type:FUNC
105  * @tc.require: issueI9I98H
106  */
107 HWTEST_F(RSFilterTest, operatorTest001, TestSize.Level1)
108 {
109     std::shared_ptr<RSFilter> lhs;
110     std::shared_ptr<RSFilter> rhs;
111     EXPECT_EQ(lhs + rhs, rhs);
112     lhs = std::make_shared<RSFilter>();
113     EXPECT_EQ(lhs + rhs, lhs);
114     rhs = std::make_shared<RSFilter>();
115     EXPECT_EQ(lhs + rhs, nullptr);
116 }
117 
118 /**
119  * @tc.name: operatorTest002
120  * @tc.desc: Verify function operator-
121  * @tc.type:FUNC
122  * @tc.require: issueI9I98H
123  */
124 HWTEST_F(RSFilterTest, operatorTest002, TestSize.Level1)
125 {
126     std::shared_ptr<RSFilter> lhs;
127     std::shared_ptr<RSFilter> rhs;
128     std::shared_ptr<RSFilter> lhss;
129     lhs = std::make_shared<RSFilter>();
130     EXPECT_EQ(lhs - rhs, lhs);
131     rhs = std::make_shared<RSFilter>();
132     EXPECT_EQ(lhss - rhs, lhss);
133     EXPECT_EQ(lhs - rhs, nullptr);
134 }
135 
136 /**
137  * @tc.name: operatorTest003
138  * @tc.desc: Verify function operator*
139  * @tc.type:FUNC
140  * @tc.require: issueI9I98H
141  */
142 HWTEST_F(RSFilterTest, operatorTest003, TestSize.Level1)
143 {
144     std::shared_ptr<RSFilter> lhs;
145     EXPECT_EQ(lhs * 1.0f, nullptr);
146     lhs = std::make_shared<RSFilter>();
147     EXPECT_EQ(lhs * 1.0f, nullptr);
148 }
149 
150 /**
151  * @tc.name: CreateLightUpEffectFilter
152  * @tc.desc:
153  * @tc.type:FUNC
154  */
155 HWTEST_F(RSFilterTest, CreateLightUpEffectFilter, TestSize.Level1)
156 {
157     float lightUpDegree = 0.5f;
158     auto filter = RSFilter::CreateLightUpEffectFilter(lightUpDegree);
159     ASSERT_NE(filter, nullptr);
160 }
161 
162 /**
163  * @tc.name: GetDetailedDescriptionTest
164  * @tc.desc: Verify function GetDetailedDescription
165  * @tc.type:FUNC
166  * @tc.require: issuesI9MO9U
167  */
168 HWTEST_F(RSFilterTest, GetDetailedDescriptionTest, TestSize.Level1)
169 {
170     auto filter = std::make_shared<RSFilter>();
171     EXPECT_EQ(filter->GetDetailedDescription(), "RSFilter 0");
172 }
173 
174 /**
175  * @tc.name: IsValidTest
176  * @tc.desc: Verify function IsValid
177  * @tc.type:FUNC
178  * @tc.require: issuesI9MO9U
179  */
180 HWTEST_F(RSFilterTest, IsValidTest, TestSize.Level1)
181 {
182     auto filter = std::make_shared<RSFilter>();
183     EXPECT_FALSE(filter->IsValid());
184 }
185 
186 /**
187  * @tc.name: SetFilterType
188  * @tc.desc:
189  * @tc.type:FUNC
190  */
191 HWTEST_F(RSFilterTest, SetFilterType, TestSize.Level1)
192 {
193     RSFilter rSFilter;
194     rSFilter.SetFilterType(RSFilter::MATERIAL);
195     EXPECT_EQ(rSFilter.GetFilterType(), RSFilter::MATERIAL);
196 }
197 
198 /**
199  * @tc.name: RadiusVp2SigmaTest001
200  * @tc.desc: Verify function RadiusVp2Sigma
201  * @tc.type:FUNC
202  */
203 HWTEST_F(RSFilterTest, RadiusVp2SigmaTest001, TestSize.Level1)
204 {
205     RSFilter rSFilter;
206     auto rsFilter = std::make_shared<RSFilter>();
207     EXPECT_EQ(rsFilter->RadiusVp2Sigma(0.f, 0.f), 0.0f);
208 }
209 
210 /**
211  * @tc.name: SetSnapshotOutset
212  * @tc.desc:
213  * @tc.type:FUNC
214  */
215 HWTEST_F(RSFilterTest, SetSnapshotOutset, TestSize.Level1)
216 {
217     RSFilter rSFilter;
218     rSFilter.SetSnapshotOutset(1);
219     EXPECT_EQ(rSFilter.NeedSnapshotOutset(), 1);
220 }
221 } // namespace OHOS::Rosen