• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "window_adapter.h"
17 
18 #include <gtest/gtest.h>
19 
20 #include <functional>
21 
22 #include "global.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 using namespace testing::ext;
27 class WindowAdapterTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase()
30     {
31     }
TearDownTestCase()32     static void TearDownTestCase()
33     {
34     }
SetUp()35     void SetUp() override
36     {
37         WindowDisplayChangeHandler callback = [](OHOS::Rosen::CallingWindowInfo callingWindowInfo) {
38             IMSA_HILOGD("callback result:%{public}s",
39                 WindowDisplayChangeListener::CallingWindowInfoToString(callingWindowInfo).c_str());
40         };
41         WindowAdapter::GetInstance().RegisterCallingWindowInfoChangedListener(callback);
42     }
TearDown()43     void TearDown() override
44     {
45     }
46 };
47 
48 /**
49  * @tc.name: WindowAdapter_GetCallingWindowInfo
50  * @tc.desc:
51  * @tc.type: FUNC
52  * @tc.require:
53  */
54 HWTEST_F(WindowAdapterTest, WindowAdapter_GetCallingWindowInfo, TestSize.Level0)
55 {
56     OHOS::Rosen::CallingWindowInfo callingWindowInfo;
57     uint32_t windId = 0;
58     int32_t userId = -1;
59     auto ret = WindowAdapter::GetInstance().GetCallingWindowInfo(windId, userId, callingWindowInfo);
60     EXPECT_FALSE(ret);
61 }
62 
63 /**
64  * @tc.name: WindowAdapter_GetFocusInfo
65  * @tc.desc:
66  * @tc.type: FUNC
67  * @tc.require:
68  */
69 HWTEST_F(WindowAdapterTest, WindowAdapter_GetFocusInfo, TestSize.Level0)
70 {
71     OHOS::Rosen::FocusChangeInfo focusInfo;
72     WindowAdapter::GetInstance().GetFocusInfo(focusInfo);
73     EXPECT_TRUE(focusInfo.displayId_ >= 0);
74 }
75 
76 /**
77  * @tc.name: WindowAdapter_GetDisplayId
78  * @tc.desc:
79  * @tc.type: FUNC
80  * @tc.require:
81  */
82 HWTEST_F(WindowAdapterTest, WindowAdapter_GetDisplayId, TestSize.Level0)
83 {
84     int64_t callingPid = -1000;
85     uint64_t displayId = 0;
86     auto ret = WindowAdapter::GetInstance().GetDisplayId(callingPid, displayId);
87     EXPECT_TRUE(ret);
88 }
89 } // namespace MiscServices
90 } // namespace OHOS
91