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