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 #include <transaction/rs_transaction.h>
18 
19 #include "display_manager.h"
20 #include "iremote_object_mocker.h"
21 #include "window_helper.h"
22 #include "window_system_effect.h"
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 class WindowSystemEffectTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 
35     sptr<WindowProperty> CreateWindowProperty();
36 private:
37     RSSurfaceNode::SharedPtr CreateRSSurfaceNode(std::string name);
38     sptr<WindowNode> node_ = nullptr;
39     AppWindowEffectConfig effectConfig_;
40     sptr<WindowRoot> windowRoot_;
41 };
42 
SetUpTestCase()43 void WindowSystemEffectTest::SetUpTestCase()
44 {
45 }
46 
TearDownTestCase()47 void WindowSystemEffectTest::TearDownTestCase()
48 {
49 }
50 
SetUp()51 void WindowSystemEffectTest::SetUp()
52 {
53     auto display = DisplayManager::GetInstance().GetDefaultDisplay();
54     ASSERT_TRUE((display != nullptr));
55     sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
56     ASSERT_TRUE((displayInfo != nullptr));
57     auto property = CreateWindowProperty();
58     node_ = new WindowNode(); // 101 is windowId
59     node_->SetWindowProperty(property);
60     node_->SetWindowRect({0, 0, 100, 100}); // 100 test data
61     node_->leashWinSurfaceNode_ = CreateRSSurfaceNode("leashSurfaceNodeTest");
62     node_->surfaceNode_ = CreateRSSurfaceNode("SurfaceNodeTest");
63     effectConfig_.fullScreenCornerRadius_ = 16.0f; // 16.f test data
64     effectConfig_.splitCornerRadius_ = 16.0f; // 16.f test data
65     effectConfig_.floatCornerRadius_ = 16.0f; // 16.f test data
66     effectConfig_.focusedShadow_ = {80, "#000000", 0, 5, 0.45};
67     effectConfig_.unfocusedShadow_ = {55, "#000000", 0, 10, 0.25};
68     WindowSystemEffect::SetWindowSystemEffectConfig(effectConfig_);
69     windowRoot_ = new WindowRoot([](Event event, const sptr<IRemoteObject>& remoteObject) {});
70     ASSERT_NE(nullptr, windowRoot_);
71     WindowSystemEffect::SetWindowRoot(windowRoot_);
72 }
73 
TearDown()74 void WindowSystemEffectTest::TearDown()
75 {
76     node_ = nullptr;
77     AppWindowEffectConfig config;
78     effectConfig_ = config;
79 }
80 
CreateRSSurfaceNode(std::string name)81 RSSurfaceNode::SharedPtr WindowSystemEffectTest::CreateRSSurfaceNode(std::string name)
82 {
83     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
84     rsSurfaceNodeConfig.SurfaceNodeName = name;
85     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
86     return surfaceNode;
87 }
88 
CreateWindowProperty()89 sptr<WindowProperty> WindowSystemEffectTest::CreateWindowProperty()
90 {
91     sptr<WindowProperty> property = new WindowProperty();
92     return property;
93 }
94 namespace {
95 /**
96  * @tc.name: SetWindowEffectAndCornerRadius01
97  * @tc.desc: set window corner radius with different parameter
98  * @tc.type: FUNC
99  */
HWTEST_F(WindowSystemEffectTest, SetWindowEffectAndCornerRadius01, Function | SmallTest | Level2)100 HWTEST_F(WindowSystemEffectTest, SetWindowEffectAndCornerRadius01, Function | SmallTest | Level2)
101 {
102     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetWindowEffect(node_));
103     // fullscreen
104     node_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
105     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
106     WindowSystemEffect::windowSystemEffectConfig_.fullScreenCornerRadius_ = 0.0f;
107     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
108 
109     // splitmode
110     node_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
111     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
112     WindowSystemEffect::windowSystemEffectConfig_.splitCornerRadius_ = 0.0f;
113     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
114 
115     // float mode
116     node_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
117     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
118     WindowSystemEffect::windowSystemEffectConfig_.floatCornerRadius_ = 0.0f;
119     ASSERT_EQ(WMError::WM_DO_NOTHING, WindowSystemEffect::SetCornerRadius(node_));
120 
121     node_->leashWinSurfaceNode_ = nullptr;
122     WindowSystemEffect::windowSystemEffectConfig_.floatCornerRadius_ = 16.0f;
123     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
124 
125     node_->leashWinSurfaceNode_ = CreateRSSurfaceNode("leashSurfaceNodeTest");
126     node_->surfaceNode_ = nullptr;
127     ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_));
128 
129     node_->leashWinSurfaceNode_ = nullptr;
130     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetCornerRadius(node_));
131 
132     WindowSystemEffect::SetWindowRoot(nullptr);
133     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetCornerRadius(node_));
134 }
135 }
136 }
137 }
138