• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "image_sink_processor_test.h"
17 
18 #include <chrono>
19 #include <securec.h>
20 
21 #include "dscreen_constants.h"
22 #include "dscreen_errcode.h"
23 
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace DistributedHardware {
SetUpTestCase(void)28 void ImageSinkProcessorTest::SetUpTestCase(void) {}
29 
TearDownTestCase(void)30 void ImageSinkProcessorTest::TearDownTestCase(void) {}
31 
SetUp(void)32 void ImageSinkProcessorTest::SetUp(void)
33 {
34     param_.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
35     param_.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
36     param_.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
37     param_.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
38     param_.fps_ = FPS;
39     param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
40     param_.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
41 
42     processor_ = std::make_shared<ImageSinkProcessor>();
43     imageListener_ = std::make_shared<MockIImageSinkProcessorListener>();
44     processor_->imageDecoder_ = std::make_shared<ImageSinkDecoder>(imageListener_);
45     processor_->imageDecoder_->videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/avc");
46 }
47 
TearDown(void)48 void ImageSinkProcessorTest::TearDown(void) {}
49 
50 /**
51  * @tc.name: configure_image_processor_test_001
52  * @tc.desc: Verify the ConfigureImageProcessor function.
53  * @tc.type: FUNC
54  * @tc.require: Issue Number
55  */
56 HWTEST_F(ImageSinkProcessorTest, configure_image_processor_test_001, TestSize.Level1)
57 {
58     EXPECT_EQ(DH_SUCCESS, processor_->ConfigureImageProcessor(param_, param_, imageListener_));
59 }
60 
61 /**
62  * @tc.name: configure_image_processor_test_002
63  * @tc.desc: Verify the ConfigureImageProcessor function.
64  * @tc.type: FUNC
65  * @tc.require: Issue Number
66  */
67 HWTEST_F(ImageSinkProcessorTest, configure_image_processor_test_002, TestSize.Level1)
68 {
69     param_.codecType_ = VIDEO_CODEC_TYPE_INVALID;
70     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE,
71         processor_->ConfigureImageProcessor(param_, param_, imageListener_));
72 }
73 
74 /**
75  * @tc.name: release_image_processor_test_001
76  * @tc.desc: Verify the ReleaseImageProcessor function.
77  * @tc.type: FUNC
78  * @tc.require: Issue Number
79  */
80 HWTEST_F(ImageSinkProcessorTest, release_image_processor_test_001, TestSize.Level1)
81 {
82     EXPECT_EQ(DH_SUCCESS, processor_->ReleaseImageProcessor());
83 }
84 
85 /**
86  * @tc.name: release_image_processor_test_002
87  * @tc.desc: Verify the ReleaseImageProcessor function.
88  * @tc.type: FUNC
89  * @tc.require: Issue Number
90  */
91 HWTEST_F(ImageSinkProcessorTest, release_image_processor_test_002, TestSize.Level1)
92 {
93     processor_->imageDecoder_ = nullptr;
94     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->ReleaseImageProcessor());
95 }
96 
97 /**
98  * @tc.name: start_image_processor_test_001
99  * @tc.desc: Verify the StartImageProcessor function.
100  * @tc.type: FUNC
101  * @tc.require: Issue Number
102  */
103 HWTEST_F(ImageSinkProcessorTest, start_image_processor_test_001, TestSize.Level1)
104 {
105     EXPECT_EQ(ERR_DH_SCREEN_CODEC_PREPARE_FAILED, processor_->StartImageProcessor());
106 }
107 
108 /**
109  * @tc.name: start_image_processor_test_002
110  * @tc.desc: Verify the StartImageProcessor function.
111  * @tc.type: FUNC
112  * @tc.require: Issue Number
113  */
114 HWTEST_F(ImageSinkProcessorTest, start_image_processor_test_002, TestSize.Level1)
115 {
116     processor_->imageDecoder_ = nullptr;
117     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->StartImageProcessor());
118 }
119 
120 /**
121  * @tc.name: stop_image_processor_test_001
122  * @tc.desc: Verify the StopImageProcessor function.
123  * @tc.type: FUNC
124  * @tc.require: Issue Number
125  */
126 HWTEST_F(ImageSinkProcessorTest, stop_image_processor_test_001, TestSize.Level1)
127 {
128     EXPECT_EQ(ERR_DH_SCREEN_CODEC_FLUSH_FAILED, processor_->StopImageProcessor());
129 }
130 
131 /**
132  * @tc.name: stop_image_processor_test_002
133  * @tc.desc: Verify the StopImageProcessor function.
134  * @tc.type: FUNC
135  * @tc.require: Issue Number
136  */
137 HWTEST_F(ImageSinkProcessorTest, stop_image_processor_test_002, TestSize.Level1)
138 {
139     processor_->imageDecoder_ = nullptr;
140     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->StopImageProcessor());
141 }
142 
143 /**
144  * @tc.name: set_image_surface_test_001
145  * @tc.desc: Verify the StopImageProcessor function.
146  * @tc.type: FUNC
147  * @tc.require: Issue Number
148  */
149 HWTEST_F(ImageSinkProcessorTest, set_image_surface_test_001, TestSize.Level1)
150 {
151     sptr<Surface> surface = Surface::CreateSurfaceAsConsumer("test");
152     EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, processor_->SetImageSurface(surface));
153 }
154 
155 /**
156  * @tc.name: set_image_surface_test_002
157  * @tc.desc: Verify the StopImageProcessor function.
158  * @tc.type: FUNC
159  * @tc.require: Issue Number
160  */
161 HWTEST_F(ImageSinkProcessorTest, set_image_surface_test_002, TestSize.Level1)
162 {
163     processor_->imageDecoder_ = nullptr;
164     sptr<Surface> surface = Surface::CreateSurfaceAsConsumer("test");
165     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->SetImageSurface(surface));
166 }
167 
168 /**
169  * @tc.name: processimage_test_001
170  * @tc.desc: Verify the StopImageProcessor function.
171  * @tc.type: FUNC
172  * @tc.require: Issue Number
173  */
174 HWTEST_F(ImageSinkProcessorTest, processimage_test_001, TestSize.Level1)
175 {
176     std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(DATA_LEN);
177     EXPECT_EQ(DH_SUCCESS, processor_->ProcessImage(data));
178 }
179 
180 /**
181  * @tc.name: processimage_test_002
182  * @tc.desc: Verify the StopImageProcessor function.
183  * @tc.type: FUNC
184  * @tc.require: Issue Number
185  */
186 HWTEST_F(ImageSinkProcessorTest, processimage_test_002, TestSize.Level1)
187 {
188     processor_->imageDecoder_ = nullptr;
189     std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(DATA_LEN);
190     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->ProcessImage(data));
191 }
192 }
193 }