• 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 <configuration.h>
17 #include <gtest/gtest.h>
18 
19 #include "ability_context_impl.h"
20 #include "mock_static_call.h"
21 #include "mock_session.h"
22 #include "oh_window.h"
23 #include "singleton_mocker.h"
24 #include "window_impl.h"
25 #include "window_scene.h"
26 #include "window_session_impl.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Rosen {
33 using Mocker = SingletonMocker<StaticCall, MockStaticCall>;
34 class OHWindowTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40 
41     sptr<WindowScene> scene_ = nullptr;
42     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
43 };
44 
SetUpTestCase()45 void OHWindowTest::SetUpTestCase()
46 {
47 }
48 
TearDownTestCase()49 void OHWindowTest::TearDownTestCase()
50 {
51 }
52 
SetUp()53 void OHWindowTest::SetUp()
54 {
55     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
56     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
57     sptr<WindowOption> option = new WindowOption();
58     EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option)));
59     DisplayId displayId = 0;
60     sptr<IWindowLifeCycle> listener = nullptr;
61     scene_ = sptr<WindowScene>::MakeSptr();
62     ASSERT_EQ(WMError::WM_OK, scene_->Init(displayId, abilityContext_, listener));
63 }
64 
TearDown()65 void OHWindowTest::TearDown()
66 {
67     scene_->GoDestroy();
68     scene_ = nullptr;
69     abilityContext_ = nullptr;
70 }
71 
72 namespace {
73 /**
74  * @tc.name: ShowWindow01
75  * @tc.desc: return OK when show window
76  * @tc.type: FUNC
77  */
78 HWTEST_F(OHWindowTest, ShowWindow01, Function | SmallTest | Level2)
79 {
80     ASSERT_NE(nullptr, scene_);
81     ASSERT_NE(nullptr, scene_->GetMainWindow());
82     auto ret = OH_WindowManager_ShowWindow(scene_->GetMainWindow()->GetWindowId());
83     EXPECT_EQ(static_cast<int32_t>(WindowManager_ErrorCode::OK), ret);
84 }
85 
86 /**
87  * @tc.name: IsWindowShown01
88  * @tc.desc: return OK when window is shown
89  * @tc.type: FUNC
90  */
91 HWTEST_F(OHWindowTest, IsWindowShowing01, Function | SmallTest | Level2)
92 {
93     ASSERT_NE(nullptr, scene_);
94     ASSERT_NE(nullptr, scene_->GetMainWindow());
95     bool isShow;
96     auto ret = OH_WindowManager_IsWindowShown(scene_->GetMainWindow()->GetWindowId(), &isShow);
97     EXPECT_EQ(static_cast<int32_t>(WindowManager_ErrorCode::OK), ret);
98 }
99 
100 /**
101  * @tc.name: OH_WindowManager_GetAllWindowLayoutInfoList
102  * @tc.desc: OH_WindowManager_GetAllWindowLayoutInfoList test
103  * @tc.type: FUNC
104  */
105 HWTEST_F(OHWindowTest, OH_WindowManager_GetAllWindowLayoutInfoList, Function | SmallTest | Level2)
106 {
107     int64_t displayId = -1;
108     WindowManager_Rect** windowLayoutInfo = nullptr;
109     size_t* windowLayoutInfoSize = nullptr;
110     auto ret = OH_WindowManager_GetAllWindowLayoutInfoList(displayId, windowLayoutInfo, windowLayoutInfoSize);
111     EXPECT_EQ(static_cast<int32_t>(WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM), ret);
112     displayId = 0;
113     EXPECT_EQ(static_cast<int32_t>(WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM), ret);
114     windowLayoutInfo = (WindowManager_Rect**)malloc(sizeof(WindowManager_Rect**));
115     windowLayoutInfoSize = (size_t*)malloc(sizeof(size_t*));
116     ret = OH_WindowManager_GetAllWindowLayoutInfoList(displayId, windowLayoutInfo, windowLayoutInfoSize);
117     EXPECT_EQ(static_cast<int32_t>(WindowManager_ErrorCode::OK), ret);
118     OH_WindowManager_ReleaseAllWindowLayoutInfoList(*windowLayoutInfo);
119     *windowLayoutInfo = NULL;
120     free(windowLayoutInfo);
121     windowLayoutInfo = NULL;
122     free(windowLayoutInfoSize);
123     windowLayoutInfoSize = NULL;
124 }
125 }
126 } // namespace Rosen
127 } // namespace OHOS