• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_source_trans_test.h"
17 #include "screentrans_test_utils.h"
18 
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace DistributedHardware {
SetUpTestCase(void)23 void ScreenSourceTransTest::SetUpTestCase(void) {}
24 
TearDownTestCase(void)25 void ScreenSourceTransTest::TearDownTestCase(void) {}
26 
SetUp(void)27 void ScreenSourceTransTest::SetUp(void)
28 {
29     trans = std::make_shared<ScreenSourceTrans>();
30 }
31 
TearDown(void)32 void ScreenSourceTransTest::TearDown(void) {}
33 
34 /**
35  * @tc.name: RegisterChannelListener_001
36  * @tc.desc: Verify the RegisterChannelListener function.
37  * @tc.type: FUNC
38  * @tc.require: Issue Number
39  */
40 HWTEST_F(ScreenSourceTransTest, RegisterChannelListener_001, TestSize.Level1)
41 {
42     int32_t actual = trans->RegisterChannelListener();
43 
44     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
45 }
46 
47 /**
48  * @tc.name: RegisterProcessorListener_001
49  * @tc.desc: Verify the RegisterChannelListener function.
50  * @tc.type: FUNC
51  * @tc.require: Issue Number
52  */
53 HWTEST_F(ScreenSourceTransTest, RegisterProcessorListener_001, TestSize.Level1)
54 {
55     VideoParam localParam;
56     VideoParam remoteParam;
57     int32_t actual = trans->RegisterProcessorListener(localParam, remoteParam);
58 
59     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
60 }
61 
62 /**
63  * @tc.name: SetUp_001
64  * @tc.desc: Verify the SetUp function.
65  * @tc.type: FUNC
66  * @tc.require: Issue Number
67  */
68 HWTEST_F(ScreenSourceTransTest, SetUp_001, TestSize.Level1)
69 {
70     VideoParam localParam;
71     VideoParam remoteParam;
72     std::string peerDevId;
73 
74     int32_t actual = trans->SetUp(localParam, remoteParam, peerDevId);
75 
76     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
77 }
78 
79 /**
80  * @tc.name: SetUp_002
81  * @tc.desc: Verify the SetUp function.
82  * @tc.type: FUNC
83  * @tc.require: Issue Number
84  */
85 HWTEST_F(ScreenSourceTransTest, SetUp_002, TestSize.Level1)
86 {
87     VideoParam localParam;
88     localParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
89     localParam.SetVideoFormat(VIDEO_DATA_FORMAT_YUVI420);
90     localParam.SetVideoHeight(100);
91     localParam.SetVideoWidth(100);
92     localParam.SetScreenHeight(100);
93     localParam.SetScreenWidth(100);
94     VideoParam remoteParam;
95     remoteParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
96     remoteParam.SetVideoFormat(VIDEO_DATA_FORMAT_YUVI420);
97     remoteParam.SetVideoHeight(100);
98     remoteParam.SetVideoWidth(100);
99     remoteParam.SetScreenHeight(100);
100     remoteParam.SetScreenWidth(100);
101 
102     int32_t actual = trans->SetUp(localParam, remoteParam, "peerDevId");
103 
104     EXPECT_EQ(-1, actual);
105 }
106 
107 /**
108  * @tc.name: InitScreenTrans_001
109  * @tc.desc: Verify the InitScreenTrans function.
110  * @tc.type: FUNC
111  * @tc.require: Issue Number
112  */
113 HWTEST_F(ScreenSourceTransTest, InitScreenTrans_001, TestSize.Level1)
114 {
115     VideoParam localParam;
116     VideoParam remoteParam;
117     std::string peerDevId = "sinkDevId";
118     trans->screenChannel_ = std::make_shared<MockScreenDataChannelImpl>();
119     int32_t actual = trans->InitScreenTrans(localParam, remoteParam, peerDevId);
120 
121     EXPECT_EQ(-1, actual);
122 }
123 
124 /**
125  * @tc.name: Release_001
126  * @tc.desc: Verify the Release function.
127  * @tc.type: FUNC
128  * @tc.require: Issue Number
129  */
130 HWTEST_F(ScreenSourceTransTest, Release_001, TestSize.Level1)
131 {
132     int32_t actual = trans->Release();
133 
134     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
135 }
136 
137 /**
138  * @tc.name: Release_002
139  * @tc.desc: Verify the Release function.
140  * @tc.type: FUNC
141  * @tc.require: Issue Number
142  */
143 HWTEST_F(ScreenSourceTransTest, Release_002, TestSize.Level1)
144 {
145     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
146     std::string peerDevId = "sinkDevId";
147     trans->screenChannel_ = std::make_shared<ScreenDataChannelImpl>(peerDevId);
148     int32_t actual = trans->Release();
149 
150     EXPECT_EQ(DH_SUCCESS, actual);
151 }
152 
153 /**
154  * @tc.name: Start_001
155  * @tc.desc: Verify the Start function.
156  * @tc.type: FUNC
157  * @tc.require: Issue Number
158  */
159 HWTEST_F(ScreenSourceTransTest, Start_001, TestSize.Level1)
160 {
161     int32_t actual = trans->Start();
162 
163     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
164 }
165 
166 /**
167  * @tc.name: Start_002
168  * @tc.desc: Verify the Start function.
169  * @tc.type: FUNC
170  * @tc.require: Issue Number
171  */
172 HWTEST_F(ScreenSourceTransTest, Start_002, TestSize.Level1)
173 {
174     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
175     std::string peerDevId = "sinkDevId";
176     trans->screenChannel_ = std::make_shared<ScreenDataChannelImpl>(peerDevId);
177     int32_t actual = trans->Start();
178 
179     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual);
180 }
181 
182 /**
183  * @tc.name: Start_003
184  * @tc.desc: Verify the Start function.
185  * @tc.type: FUNC
186  * @tc.require: Issue Number
187  */
188 HWTEST_F(ScreenSourceTransTest, Start_003, TestSize.Level1)
189 {
190     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
191     std::string peerDevId = "sinkDevId";
192     trans->screenChannel_ = std::make_shared<MockScreenDataChannelImpl>();
193     int32_t actual = trans->Start();
194 
195     EXPECT_EQ(ERR_DH_SCREEN_TRANS_TIMEOUT, actual);
196 }
197 
198 /**
199  * @tc.name: Stop_001
200  * @tc.desc: Verify the Stop function.
201  * @tc.type: FUNC
202  * @tc.require: Issue Number
203  */
204 HWTEST_F(ScreenSourceTransTest, Stop_001, TestSize.Level1)
205 {
206     int32_t actual = trans->Stop();
207     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
208 }
209 
210 /**
211  * @tc.name: Stop_002
212  * @tc.desc: Verify the Stop function.
213  * @tc.type: FUNC
214  * @tc.require: Issue Number
215  */
216 HWTEST_F(ScreenSourceTransTest, Stop_002, TestSize.Level1)
217 {
218     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
219     std::string peerDevId = "sinkDevId";
220     trans->screenChannel_ = std::make_shared<MockScreenDataChannelImpl>();
221     int32_t actual = trans->Stop();
222 
223     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual);
224 }
225 
226 /**
227  * @tc.name: Stop_003
228  * @tc.desc: Verify the Stop function.
229  * @tc.type: FUNC
230  * @tc.require: Issue Number
231  */
232 HWTEST_F(ScreenSourceTransTest, Stop_003, TestSize.Level1)
233 {
234     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
235     std::string peerDevId = "sinkDevId";
236     trans->screenChannel_ = std::make_shared<ScreenDataChannelImpl>(peerDevId);
237     int32_t actual = trans->Stop();
238 
239     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual);
240 }
241 
242 /**
243  * @tc.name: RegisterStateCallback_001
244  * @tc.desc: Verify the RegisterStateCallback function.
245  * @tc.type: FUNC
246  * @tc.require: Issue Number
247  */
248 HWTEST_F(ScreenSourceTransTest, RegisterStateCallback_001, TestSize.Level1)
249 {
250     std::shared_ptr<IScreenSourceTransCallback> callback = nullptr;
251     int32_t actual = trans->RegisterStateCallback(callback);
252 
253     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
254 }
255 
256 /**
257  * @tc.name: RegisterStateCallback_002
258  * @tc.desc: Verify the RegisterStateCallback function.
259  * @tc.type: FUNC
260  * @tc.require: Issue Number
261  */
262 HWTEST_F(ScreenSourceTransTest, RegisterStateCallback_002, TestSize.Level1)
263 {
264     std::shared_ptr<IScreenSourceTransCallback> callback =
265         std::make_shared<MockIScreenSourceTransCallback>();
266     int32_t actual = trans->RegisterStateCallback(callback);
267 
268     EXPECT_EQ(DH_SUCCESS, actual);
269 }
270 
271 /**
272  * @tc.name: CheckVideoParam_001
273  * @tc.desc: Verify the CheckVideoParam function.
274  * @tc.type: FUNC
275  * @tc.require: Issue Number
276  */
277 HWTEST_F(ScreenSourceTransTest, CheckVideoParam_001, TestSize.Level1)
278 {
279     VideoParam localParam;
280     localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4 + 1;
281     int32_t actual = trans->CheckVideoParam(localParam);
282 
283     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
284 }
285 
286 /**
287  * @tc.name: CheckVideoParam
288  * @tc.desc: Verify the CheckVideoParam function.
289  * @tc.type: FUNC
290  * @tc.require: Issue Number
291  */
292 HWTEST_F(ScreenSourceTransTest, CheckVideoParam_002, TestSize.Level1)
293 {
294     VideoParam localParam;
295     localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
296     localParam.videoFormat_ = VIDEO_DATA_FORMAT_RGBA8888 + 1;
297     VideoParam remoteParam;
298     std::string peerDevId;
299     int32_t actual = trans->CheckVideoParam(localParam);
300 
301     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
302 }
303 
304 /**
305  * @tc.name: CheckTransParam_001
306  * @tc.desc: Verify the CheckTransParam function.
307  * @tc.type: FUNC
308  * @tc.require: Issue Number
309  */
310 HWTEST_F(ScreenSourceTransTest, CheckTransParam_001, TestSize.Level1)
311 {
312     VideoParam localParam;
313     localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
314     localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
315     localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
316     localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
317     localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
318     VideoParam remoteParam;
319     remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
320     remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
321     remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
322     remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
323     remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
324     remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
325     std::string peerDevId;
326     int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId);
327 
328     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
329 }
330 
331 /**
332  * @tc.name: CheckTransParam_002
333  * @tc.desc: Verify the CheckTransParam function.
334  * @tc.type: FUNC
335  * @tc.require: Issue Number
336  */
337 HWTEST_F(ScreenSourceTransTest, CheckTransParam_002, TestSize.Level1)
338 {
339     VideoParam localParam;
340     localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
341     localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
342     localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
343     localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH + 1;
344     localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
345     VideoParam remoteParam;
346     remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
347     remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
348     remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
349     remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
350     remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
351     remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
352     std::string peerDevId = "sinkDevId";
353     int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId);
354 
355     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
356 }
357 
358 /**
359  * @tc.name: CheckTransParam_003
360  * @tc.desc: Verify the CheckTransParam function.
361  * @tc.type: FUNC
362  * @tc.require: Issue Number
363  */
364 HWTEST_F(ScreenSourceTransTest, CheckTransParam_003, TestSize.Level1)
365 {
366     VideoParam localParam;
367     localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
368     localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
369     localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
370     localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
371     localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
372     VideoParam remoteParam;
373     remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
374     remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
375     remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH + 1;
376     remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
377     remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
378     remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
379     std::string peerDevId = "sinkDevId";
380     int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId);
381 
382     EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
383 }
384 
385 /**
386  * @tc.name: CheckTransParam_004
387  * @tc.desc: Verify the CheckTransParam function.
388  * @tc.type: FUNC
389  * @tc.require: Issue Number
390  */
391 HWTEST_F(ScreenSourceTransTest, CheckTransParam_004, TestSize.Level1)
392 {
393     VideoParam localParam;
394     localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
395     localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
396     localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
397     localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
398     localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
399     localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
400     VideoParam remoteParam;
401     remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
402     remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
403     remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
404     remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
405     remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
406     remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
407     std::string peerDevId = "sinkDevId";
408     int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId);
409 
410     EXPECT_EQ(DH_SUCCESS, actual);
411 }
412 
413 /**
414  * @tc.name: GetImageSurface_001
415  * @tc.desc: Verify the GetImageSurface function.
416  * @tc.type: FUNC
417  * @tc.require: Issue Number
418  */
419 HWTEST_F(ScreenSourceTransTest, GetImageSurface_001, TestSize.Level1)
420 {
421     VideoParam localParam;
422     localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
423     localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
424     localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
425     localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
426     localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
427     localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
428     VideoParam remoteParam;
429     remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
430     remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
431     remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
432     remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
433     remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
434     remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
435     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
436     trans->screenDecisionCenter_ = std::make_shared<ScreenDecisionCenter>(localParam);
437     trans->RegisterProcessorListener(localParam, remoteParam);
438 
439     EXPECT_NE(nullptr, trans->GetImageSurface());
440 }
441 
442 /**
443  * @tc.name: OnSessionOpened_001
444  * @tc.desc: Verify the OnSessionOpened function.
445  * @tc.type: FUNC
446  * @tc.require: Issue Number
447  */
448 HWTEST_F(ScreenSourceTransTest, OnSessionOpened_001, TestSize.Level1)
449 {
450     trans->imageProcessor_ = std::make_shared<ImageSourceProcessor>();
451 
452     trans->OnSessionOpened();
453 
454     EXPECT_EQ(false, trans->isChannelReady_);
455 }
456 
457 /**
458  * @tc.name: OnSessionOpened_002
459  * @tc.desc: Verify the OnSessionOpened function.
460  * @tc.type: FUNC
461  * @tc.require: Issue Number
462  */
463 HWTEST_F(ScreenSourceTransTest, OnSessionOpened_002, TestSize.Level1)
464 {
465     trans->imageProcessor_ = nullptr;
466 
467     trans->OnSessionOpened();
468 
469     EXPECT_EQ(false, trans->isChannelReady_);
470 }
471 
472 /**
473  * @tc.name: OnSessionClosed_001
474  * @tc.desc: Verify the OnSessionClosed function.
475  * @tc.type: FUNC
476  * @tc.require: Issue Number
477  */
478 HWTEST_F(ScreenSourceTransTest, OnSessionClosed_001, TestSize.Level1)
479 {
480     trans->transCallback_ = std::make_shared<MockIScreenSourceTransCallback>();
481 
482     trans->OnSessionClosed();
483 
484     EXPECT_EQ(false, trans->isChannelReady_);
485 }
486 
487 /**
488  * @tc.name: OnImageProcessDone_001
489  * @tc.desc: Verify the OnImageProcessDone function.
490  * @tc.type: FUNC
491  * @tc.require: Issue Number
492  */
493 HWTEST_F(ScreenSourceTransTest, OnImageProcessDone_001, TestSize.Level1)
494 {
495     std::shared_ptr<DataBuffer> data = nullptr;
496     uint32_t queueSize = trans->dataQueue_.size();
497     trans->OnImageProcessDone(data);
498 
499     EXPECT_NE(queueSize, trans->dataQueue_.size());
500 }
501 
502 /**
503  * @tc.name: OnImageProcessDone_002
504  * @tc.desc: Verify the OnImageProcessDone function.
505  * @tc.type: FUNC
506  * @tc.require: Issue Number
507  */
508 HWTEST_F(ScreenSourceTransTest, OnImageProcessDone_002, TestSize.Level1)
509 {
510     std::shared_ptr<DataBuffer> data = nullptr;
511     uint32_t queueSize = trans->dataQueue_.size();
512     for (uint32_t i = 0; i < DATA_QUEUE_MAX_SIZE + 1; i++) {
513         trans->dataQueue_.push(data);
514     }
515     trans->OnImageProcessDone(data);
516 
517     EXPECT_NE(queueSize, trans->dataQueue_.size());
518 }
519 }
520 }
521