• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "pipeline/rs_paint_filter_canvas.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS::Rosen {
24 class RSPaintFilterCanvasTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30     static inline RSPaintFilterCanvas* canvas_;
31     static inline SkCanvas skCanvas_;
32 };
33 
SetUpTestCase()34 void RSPaintFilterCanvasTest::SetUpTestCase()
35 {
36     canvas_ = new RSPaintFilterCanvas(&skCanvas_);
37 }
TearDownTestCase()38 void RSPaintFilterCanvasTest::TearDownTestCase()
39 {
40     delete canvas_;
41 }
SetUp()42 void RSPaintFilterCanvasTest::SetUp() {}
TearDown()43 void RSPaintFilterCanvasTest::TearDown() {}
44 
45 /**
46  * @tc.name: SetHighContrast001
47  * @tc.desc:
48  * @tc.type:FUNC
49  * @tc.require:issueI5NMHT
50  */
51 HWTEST_F(RSPaintFilterCanvasTest, SetHighContrast001, TestSize.Level1)
52 {
53     bool mode = true;
54     canvas_->SetHighContrast(mode);
55     ASSERT_EQ(canvas_->isHighContrastEnabled(), mode);
56 
57     mode = false;
58     canvas_->SetHighContrast(mode);
59     ASSERT_EQ(canvas_->isHighContrastEnabled(), mode);
60 }
61 
62 /**
63  * @tc.name: RestoreAlpha001
64  * @tc.desc:
65  * @tc.type:FUNC
66  * @tc.require:
67  */
68 HWTEST_F(RSPaintFilterCanvasTest, RestoreAlpha001, TestSize.Level1)
69 {
70     canvas_->RestoreAlpha();
71 }
72 
73 /**
74  * @tc.name: RestoreAlphaToCountTest
75  * @tc.desc:
76  * @tc.type:FUNC
77  * @tc.require:
78  */
79 HWTEST_F(RSPaintFilterCanvasTest, RestoreAlphaToCountTest, TestSize.Level1)
80 {
81     int count = 0;
82     canvas_->RestoreAlphaToCount(count);
83     ASSERT_EQ(canvas_->GetAlphaSaveCount(), 1);
84 }
85 
86 /**
87  * @tc.name: RestoreAlphaToCount
88  * @tc.desc:
89  * @tc.type:FUNC
90  * @tc.require:
91  */
92 HWTEST_F(RSPaintFilterCanvasTest, RestoreEnvTest, TestSize.Level1)
93 {
94     canvas_->RestoreEnv();
95 }
96 
97 /**
98  * @tc.name: RestoreEnvToCountTest
99  * @tc.desc:
100  * @tc.type:FUNC
101  * @tc.require:
102  */
103 HWTEST_F(RSPaintFilterCanvasTest, RestoreEnvToCountTest, TestSize.Level1)
104 {
105     int count = 0;
106     canvas_->RestoreEnvToCount(count);
107     ASSERT_EQ(canvas_->GetAlphaSaveCount(), 1);
108 }
109 
110 /**
111  * @tc.name: SetEnvForegroundColorTest
112  * @tc.desc:
113  * @tc.type:FUNC
114  * @tc.require:
115  */
116 HWTEST_F(RSPaintFilterCanvasTest, SetEnvForegroundColorTest, TestSize.Level1)
117 {
118     Color color;
119     canvas_->SetEnvForegroundColor(color);
120 }
121 
122 /**
123  * @tc.name: GetEnvForegroundColorTest
124  * @tc.desc:
125  * @tc.type:FUNC
126  * @tc.require:
127  */
128 HWTEST_F(RSPaintFilterCanvasTest, GetEnvForegroundColorTest, TestSize.Level1)
129 {
130     Color color {0xFF000000};
131     Color setColor {};
132     canvas_->SetEnvForegroundColor(setColor);
133 }
134 
135 /**
136  * @tc.name: onFilterTest
137  * @tc.desc:
138  * @tc.type:FUNC
139  * @tc.require:
140  */
141 HWTEST_F(RSPaintFilterCanvasTest, onFilterTest, TestSize.Level1)
142 {
143     SkColor color {0x00000001};
144     SkPaint paint;
145     paint.setColor(color);
146     canvas_->onFilter(paint);
147 }
148 } // namespace OHOS::Rosen