1 /*
2  * Copyright (c) 2024-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 <gtest/gtest.h>
17 #include <map>
18 #include "window_adapter_lite.h"
19 #include "wm_common.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 class WindowAdapterLiteTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 };
33 
SetUpTestCase()34 void WindowAdapterLiteTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void WindowAdapterLiteTest::TearDownTestCase()
39 {
40 }
41 
SetUp()42 void WindowAdapterLiteTest::SetUp()
43 {
44 }
45 
TearDown()46 void WindowAdapterLiteTest::TearDown()
47 {
48 }
49 
50 namespace {
51 /**
52  * @tc.name: UnregisterWindowManagerAgent
53  * @tc.desc: WindowAdapterLite/UnregisterWindowManagerAgent
54  * @tc.type: FUNC
55  */
56 HWTEST_F(WindowAdapterLiteTest, UnregisterWindowManagerAgent, Function | SmallTest | Level2)
57 {
58     std::shared_ptr<WindowAdapterLite> windowAdapterLite_ = std::make_shared<WindowAdapterLite>();
59     if (!windowAdapterLite_) {
60         return;
61     }
62     sptr<IWindowManagerAgent> windowManagerAgent = nullptr;
63 
64     std::set<sptr<IWindowManagerAgent>> iWindowManagerAgent = {nullptr};
65     windowAdapterLite_->windowManagerLiteAgentMap_.insert(
66         std::make_pair(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, iWindowManagerAgent));
67     int32_t pid = 0;
68     auto ret = windowAdapterLite_->CheckWindowId(0, pid);
69 
70     ASSERT_NE(WMError::WM_OK, ret);
71 }
72 
73 /**
74  * @tc.name: UnregisterWindowManagerAgent
75  * @tc.desc: WindowAdapterLite/UnregisterWindowManagerAgent
76  * @tc.type: FUNC
77  */
78 HWTEST_F(WindowAdapterLiteTest, UnregisterWindowManagerAgent01, Function | SmallTest | Level2)
79 {
80     std::shared_ptr<WindowAdapterLite> windowAdapterLite_ = std::make_shared<WindowAdapterLite>();
81     if (!windowAdapterLite_) {
82         return;
83     }
84     windowAdapterLite_->ReregisterWindowManagerLiteAgent();
85     windowAdapterLite_->OnUserSwitch();
86     windowAdapterLite_->ClearWindowAdapter();
87 
88     sptr<WMSDeathRecipient> wmSDeathRecipient = new (std::nothrow) WMSDeathRecipient();
89     if (!wmSDeathRecipient) {
90         return;
91     }
92     wptr<IRemoteObject> wptrDeath;
93     wmSDeathRecipient->OnRemoteDied(wptrDeath);
94 
95     FocusChangeInfo focusInfo;
96     windowAdapterLite_->GetFocusWindowInfo(focusInfo);
97     WindowModeType windowModeType;
98     windowAdapterLite_->GetWindowModeType(windowModeType);
99     int32_t pid = 0;
100     auto ret = windowAdapterLite_->CheckWindowId(0, pid);
101 
102     ASSERT_NE(WMError::WM_OK, ret);
103 }
104 
105 /**
106  * @tc.name: GetWindowStyleType
107  * @tc.desc: WindowAdapterLite/GetWindowStyleType
108  * @tc.type: FUNC
109  */
110 HWTEST_F(WindowAdapterLiteTest, GetWindowStyleType, Function | SmallTest | Level2)
111 {
112     std::shared_ptr<WindowAdapterLite> windowAdapterLite_ = std::make_shared<WindowAdapterLite>();
113     WindowStyleType windowStyleType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
114     windowAdapterLite_->GetWindowStyleType(windowStyleType);
115     ASSERT_EQ(Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT, windowStyleType);
116 }
117 
118 }
119 }
120 }