• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "screen_client_test.h"
17 #include "accesstoken_kit.h"
18 #include "display_manager.h"
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 constexpr static uint32_t VIDEO_DATA_NUM = 480;
27 
SetUpTestCase(void)28 void ScreenClientTest::SetUpTestCase(void) {}
29 
TearDownTestCase(void)30 void ScreenClientTest::TearDownTestCase(void) {}
31 
SetUp()32 void ScreenClientTest::SetUp()
33 {
34     const char **perms = new const char *[1];
35     perms[0] = "ohos.permission.SYSTEM_FLOAT_WINDOW";
36     NativeTokenInfoParams infoInstance = {
37         .dcapsNum = 0,
38         .permsNum = 1,
39         .aclsNum = 0,
40         .dcaps = nullptr,
41         .perms = perms,
42         .acls = nullptr,
43         .processName = "screen_client_unittest",
44         .aplStr = "system_core",
45     };
46     uint64_t tokenId = GetAccessTokenId(&infoInstance);
47     SetSelfTokenID(tokenId);
48     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
49     delete[] perms;
50 
51     windowProperty_ = std::make_shared<WindowProperty>();
52     windowProperty_->width = VIDEO_DATA_NUM;
53     windowProperty_->height = VIDEO_DATA_NUM;
54     windowProperty_->displayId = Rosen::DisplayManager::GetInstance().GetDefaultDisplay()->GetId();
55 }
56 
TearDown()57 void ScreenClientTest::TearDown()
58 {
59     ScreenClient::GetInstance().DestroyAllWindow();
60     windowProperty_ = nullptr;
61 }
62 
63 /**
64  * @tc.name: AddWindow_001
65  * @tc.desc: Verify the AddWindow function.
66  * @tc.type: FUNC
67  * @tc.require: Issue Number
68  */
69 HWTEST_F(ScreenClientTest, AddWindow_001, TestSize.Level1)
70 {
71     windowProperty_ = nullptr;
72     int32_t ret = ScreenClient::GetInstance().AddWindow(windowProperty_);
73     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR, ret);
74 }
75 
76 /**
77  * @tc.name: AddWindow_002
78  * @tc.desc: Verify the AddWindow function.
79  * @tc.type: FUNC
80  * @tc.require: Issue Number
81  */
82 HWTEST_F(ScreenClientTest, AddWindow_002, TestSize.Level0)
83 {
84     int32_t expectId = ScreenClient::GetInstance().AddWindow(windowProperty_);
85     int32_t ret = ScreenClient::GetInstance().RemoveWindow(expectId);
86     EXPECT_EQ(DH_SUCCESS, ret);
87 }
88 
89 /**
90  * @tc.name: ShowWindow_001
91  * @tc.desc: Verify the ShowWindow function.
92  * @tc.type: FUNC
93  * @tc.require: Issue Number
94  */
95 HWTEST_F(ScreenClientTest, ShowWindow_001, TestSize.Level1)
96 {
97     int32_t ret = ScreenClient::GetInstance().ShowWindow(0);
98     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, ret);
99 }
100 
101 /**
102  * @tc.name: ShowWindow_002
103  * @tc.desc: Verify the ShowWindow function.
104  * @tc.type: FUNC
105  * @tc.require: Issue Number
106  */
107 HWTEST_F(ScreenClientTest, ShowWindow_002, TestSize.Level0)
108 {
109     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_);
110     int32_t ret = ScreenClient::GetInstance().ShowWindow(windowId);
111     EXPECT_EQ(DH_SUCCESS, ret);
112     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
113     EXPECT_EQ(DH_SUCCESS, ret);
114 }
115 
116 /**
117  * @tc.name: ShowWindow_003
118  * @tc.desc: Verify the ShowWindow function.
119  * @tc.type: FUNC
120  * @tc.require: Issue Number
121  */
122 HWTEST_F(ScreenClientTest, ShowWindow_003, TestSize.Level1)
123 {
124     int32_t windowId = 100;
125     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
126     int32_t ret = ScreenClient::GetInstance().ShowWindow(windowId);
127     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, ret);
128     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
129     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
130 }
131 
132 /**
133  * @tc.name: HideWindow_001
134  * @tc.desc: Verify the HideWindow function.
135  * @tc.type: FUNC
136  * @tc.require: Issue Number
137  */
138 HWTEST_F(ScreenClientTest, HideWindow_001, TestSize.Level1)
139 {
140     int32_t ret = ScreenClient::GetInstance().HideWindow(0);
141     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, ret);
142 }
143 
144 /**
145  * @tc.name: HideWindow_002
146  * @tc.desc: Verify the HideWindow function.
147  * @tc.type: FUNC
148  * @tc.require: Issue Number
149  */
150 HWTEST_F(ScreenClientTest, HideWindow_002, TestSize.Level0)
151 {
152     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_);
153     int32_t ret = ScreenClient::GetInstance().HideWindow(windowId);
154     EXPECT_EQ(DH_SUCCESS, ret);
155     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
156     EXPECT_EQ(DH_SUCCESS, ret);
157 }
158 
159 /**
160  * @tc.name: HideWindow_003
161  * @tc.desc: Verify the HideWindow function.
162  * @tc.type: FUNC
163  * @tc.require: Issue Number
164  */
165 HWTEST_F(ScreenClientTest, HideWindow_003, TestSize.Level1)
166 {
167     int32_t windowId = 0;
168     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
169     int32_t ret = ScreenClient::GetInstance().HideWindow(windowId);
170     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, ret);
171     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
172     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
173 }
174 
175 /**
176  * @tc.name: MoveWindow_001
177  * @tc.desc: Verify the MoveWindow function.
178  * @tc.type: FUNC
179  * @tc.require: Issue Number
180  */
181 HWTEST_F(ScreenClientTest, MoveWindow_001, TestSize.Level1)
182 {
183     int32_t ret = ScreenClient::GetInstance().MoveWindow(0, 0, 0);
184     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, ret);
185 }
186 
187 /**
188  * @tc.name: MoveWindow_002
189  * @tc.desc: Verify the MoveWindow function.
190  * @tc.type: FUNC
191  * @tc.require: Issue Number
192  */
193 HWTEST_F(ScreenClientTest, MoveWindow_002, TestSize.Level0)
194 {
195     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_);
196     int32_t ret = ScreenClient::GetInstance().MoveWindow(windowId, 0, 0);
197     EXPECT_EQ(DH_SUCCESS, ret);
198     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
199     EXPECT_EQ(DH_SUCCESS, ret);
200 }
201 
202 /**
203  * @tc.name: MoveWindow_003
204  * @tc.desc: Verify the MoveWindow function.
205  * @tc.type: FUNC
206  * @tc.require: Issue Number
207  */
208 HWTEST_F(ScreenClientTest, MoveWindow_003, TestSize.Level1)
209 {
210     int32_t windowId = 0;
211     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
212     int32_t ret = ScreenClient::GetInstance().MoveWindow(windowId, 0, 0);
213     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, ret);
214     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
215     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
216 }
217 
218 /**
219  * @tc.name: RemoveWindow_001
220  * @tc.desc: Verify the RemoveWindow function.
221  * @tc.type: FUNC
222  * @tc.require: Issue Number
223  */
224 HWTEST_F(ScreenClientTest, RemoveWindow_001, TestSize.Level1)
225 {
226     int32_t ret = ScreenClient::GetInstance().RemoveWindow(0);
227     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
228 }
229 
230 /**
231  * @tc.name: RemoveWindow_002
232  * @tc.desc: Verify the RemoveWindow function.
233  * @tc.type: FUNC
234  * @tc.require: Issue Number
235  */
236 HWTEST_F(ScreenClientTest, RemoveWindow_002, TestSize.Level0)
237 {
238     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_);
239     int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId);
240     EXPECT_EQ(DH_SUCCESS, ret);
241 }
242 
243 /**
244  * @tc.name: RemoveWindow_002
245  * @tc.desc: Verify the RemoveWindow function.
246  * @tc.type: FUNC
247  * @tc.require: Issue Number
248  */
249 HWTEST_F(ScreenClientTest, RemoveWindow_003, TestSize.Level1)
250 {
251     int32_t windowId = 0;
252     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
253     int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId);
254     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
255 }
256 
257 /**
258  * @tc.name: GetSurface_001
259  * @tc.desc: Verify the GetSurface function.
260  * @tc.type: FUNC
261  * @tc.require: Issue Number
262  */
263 HWTEST_F(ScreenClientTest, GetSurface_001, TestSize.Level1)
264 {
265     EXPECT_EQ(nullptr, ScreenClient::GetInstance().GetSurface(0));
266 }
267 
268 /**
269  * @tc.name: GetSurface_002
270  * @tc.desc: Verify the GetSurface function.
271  * @tc.type: FUNC
272  * @tc.require: Issue Number
273  */
274 HWTEST_F(ScreenClientTest, GetSurface_002, TestSize.Level1)
275 {
276     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_);
277     sptr<Surface> actualSurface = ScreenClient::GetInstance().GetSurface(windowId);
278     EXPECT_NE(nullptr, actualSurface);
279     int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId);
280     EXPECT_EQ(DH_SUCCESS, ret);
281 }
282 
283 /**
284  * @tc.name: DestroyAllWindow_001
285  * @tc.desc: Verify the DestroyAllWindow function.
286  * @tc.type: FUNC
287  * @tc.require: Issue Number
288  */
289 HWTEST_F(ScreenClientTest, DestroyAllWindow_001, TestSize.Level0)
290 {
291     ScreenClient::GetInstance().AddWindow(windowProperty_);
292     int32_t ret = ScreenClient::GetInstance().DestroyAllWindow();
293     EXPECT_EQ(DH_SUCCESS, ret);
294 }
295 
296 } // DistributedHardware
297 } // OHOS