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
TearDownTestCase()36 void WindowAdapterLiteTest::TearDownTestCase() {}
37
SetUp()38 void WindowAdapterLiteTest::SetUp() {}
39
TearDown()40 void WindowAdapterLiteTest::TearDown() {}
41
42 namespace {
43 /**
44 * @tc.name: UnregisterWindowManagerAgent
45 * @tc.desc: WindowAdapterLite/UnregisterWindowManagerAgent
46 * @tc.type: FUNC
47 */
48 HWTEST_F(WindowAdapterLiteTest, UnregisterWindowManagerAgent, Function | SmallTest | Level2)
49 {
50 std::shared_ptr<WindowAdapterLite> windowAdapterLite_ = std::make_shared<WindowAdapterLite>();
51 if (!windowAdapterLite_) {
52 return;
53 }
54 sptr<IWindowManagerAgent> windowManagerAgent = nullptr;
55
56 std::set<sptr<IWindowManagerAgent>> iWindowManagerAgent = { nullptr };
57 windowAdapterLite_->windowManagerLiteAgentMap_.insert(
58 std::make_pair(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, iWindowManagerAgent));
59 int32_t pid = 0;
60 auto ret = windowAdapterLite_->CheckWindowId(0, pid);
61
62 ASSERT_NE(WMError::WM_OK, ret);
63 }
64
65 /**
66 * @tc.name: UnregisterWindowManagerAgent
67 * @tc.desc: WindowAdapterLite/UnregisterWindowManagerAgent
68 * @tc.type: FUNC
69 */
70 HWTEST_F(WindowAdapterLiteTest, UnregisterWindowManagerAgent01, Function | SmallTest | Level2)
71 {
72 std::shared_ptr<WindowAdapterLite> windowAdapterLite_ = std::make_shared<WindowAdapterLite>();
73 if (!windowAdapterLite_) {
74 return;
75 }
76 windowAdapterLite_->ReregisterWindowManagerLiteAgent();
77 windowAdapterLite_->OnUserSwitch();
78 windowAdapterLite_->ClearWindowAdapter();
79
80 sptr<WMSDeathRecipient> wmSDeathRecipient = new (std::nothrow) WMSDeathRecipient();
81 if (!wmSDeathRecipient) {
82 return;
83 }
84 wptr<IRemoteObject> wptrDeath;
85 wmSDeathRecipient->OnRemoteDied(wptrDeath);
86
87 FocusChangeInfo focusInfo;
88 windowAdapterLite_->GetFocusWindowInfo(focusInfo);
89 WindowModeType windowModeType;
90 windowAdapterLite_->GetWindowModeType(windowModeType);
91 int32_t pid = 0;
92 auto ret = windowAdapterLite_->CheckWindowId(0, pid);
93
94 ASSERT_NE(WMError::WM_OK, ret);
95 }
96
97 /**
98 * @tc.name: GetWindowStyleType
99 * @tc.desc: WindowAdapterLite/GetWindowStyleType
100 * @tc.type: FUNC
101 */
102 HWTEST_F(WindowAdapterLiteTest, GetWindowStyleType, Function | SmallTest | Level2)
103 {
104 std::shared_ptr<WindowAdapterLite> windowAdapterLite_ = std::make_shared<WindowAdapterLite>();
105 WindowStyleType windowStyleType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
106 windowAdapterLite_->GetWindowStyleType(windowStyleType);
107 ASSERT_EQ(Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT, windowStyleType);
108 }
109
110 /**
111 * @tc.name: ListWindowInfo01
112 * @tc.desc: WindowAdapter/ListWindowInfo
113 * @tc.type: FUNC
114 */
115 HWTEST_F(WindowAdapterLiteTest, ListWindowInfo01, Function | SmallTest | Level2)
116 {
117 WindowAdapterLite WindowAdapterLite;
118 WindowInfoOption windowInfoOption;
119 std::vector<sptr<WindowInfo>> infos;
120 auto err = WindowAdapterLite.ListWindowInfo(windowInfoOption, infos);
121 ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, err);
122 }
123 } // namespace
124 } // namespace Rosen
125 } // namespace OHOS