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_source_encoder_test.h"
17
18 using namespace testing::ext;
19
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void ImageSourceEncoderTest::SetUpTestCase(void) {}
23
TearDownTestCase(void)24 void ImageSourceEncoderTest::TearDownTestCase(void) {}
25
SetUp(void)26 void ImageSourceEncoderTest::SetUp(void)
27 {
28 std::shared_ptr<IImageSourceProcessorListener> imageListener = nullptr;
29 encoder = std::make_shared<ImageSourceEncoder>(imageListener);
30 }
31
TearDown(void)32 void ImageSourceEncoderTest::TearDown(void) {}
33
34 /**
35 * @tc.name: ConfigureEncoder_001
36 * @tc.desc: Verify the ConfigureEncoder function.
37 * @tc.type: FUNC
38 * @tc.require: Issue Number
39 */
40 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_001, TestSize.Level1)
41 {
42 VideoParam configParam;
43 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
44 configParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
45
46 int32_t actual = encoder->ConfigureEncoder(configParam);
47 EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, actual);
48 }
49
50 /**
51 * @tc.name: ConfigureEncoder_002
52 * @tc.desc: Verify the ConfigureEncoder function.
53 * @tc.type: FUNC
54 * @tc.require: Issue Number
55 */
56 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_002, TestSize.Level1)
57 {
58 VideoParam configParam;
59 configParam.codecType_ = -1;
60
61 int32_t actual = encoder->ConfigureEncoder(configParam);
62 EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual);
63 }
64
65 /**
66 * @tc.name: ReleaseEncoder_001
67 * @tc.desc: Verify the ReleaseEncoder function.
68 * @tc.type: FUNC
69 * @tc.require: Issue Number
70 */
71 HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_001, TestSize.Level1)
72 {
73 int32_t actual = encoder->ReleaseEncoder();
74 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
75 }
76
77 /**
78 * @tc.name: ReleaseEncoder_002
79 * @tc.desc: Verify the ReleaseEncoder function.
80 * @tc.type: FUNC
81 * @tc.require: Issue Number
82 */
83 HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_002, TestSize.Level1)
84 {
85 encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc");
86
87 int32_t actual = encoder->ReleaseEncoder();
88 EXPECT_EQ(DH_SUCCESS, actual);
89 }
90
91 /**
92 * @tc.name: StartEncoder_001
93 * @tc.desc: Verify the StartEncoder function.
94 * @tc.type: FUNC
95 * @tc.require: Issue Number
96 */
97 HWTEST_F(ImageSourceEncoderTest, StartEncoder_001, TestSize.Level1)
98 {
99 int32_t actual = encoder->StartEncoder();
100 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
101 }
102
103 /**
104 * @tc.name: StartEncoder_002
105 * @tc.desc: Verify the StartEncoder function.
106 * @tc.type: FUNC
107 * @tc.require: Issue Number
108 */
109 HWTEST_F(ImageSourceEncoderTest, StartEncoder_002, TestSize.Level1)
110 {
111 encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc");
112
113 int32_t actual = encoder->StartEncoder();
114 EXPECT_EQ(ERR_DH_SCREEN_CODEC_PREPARE_FAILED, actual);
115 }
116
117 /**
118 * @tc.name: StopEncoder_001
119 * @tc.desc: Verify the StopEncoder function.
120 * @tc.type: FUNC
121 * @tc.require: Issue Number
122 */
123 HWTEST_F(ImageSourceEncoderTest, StopEncoder_001, TestSize.Level1)
124 {
125 int32_t actual = encoder->StopEncoder();
126 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
127 }
128
129 /**
130 * @tc.name: StopEncoder_002
131 * @tc.desc: Verify the StartEncoder function.
132 * @tc.type: FUNC
133 * @tc.require: Issue Number
134 */
135 HWTEST_F(ImageSourceEncoderTest, StopEncoder_002, TestSize.Level1)
136 {
137 encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc");
138
139 int32_t actual = encoder->StopEncoder();
140 EXPECT_EQ(ERR_DH_SCREEN_CODEC_STOP_FAILED, actual);
141 }
142
143 /**
144 * @tc.name: InitVideoEncoder_001
145 * @tc.desc: Verify the InitVideoEncoder function.
146 * @tc.type: FUNC
147 * @tc.require: Issue Number
148 */
149 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_001, TestSize.Level1)
150 {
151 VideoParam configParam;
152 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
153
154 int32_t actual = encoder->InitVideoEncoder(configParam);
155 EXPECT_EQ(DH_SUCCESS, actual);
156 }
157
158 /**
159 * @tc.name: InitVideoEncoder_002
160 * @tc.desc: Verify the InitVideoEncoder function.
161 * @tc.type: FUNC
162 * @tc.require: Issue Number
163 */
164 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_002, TestSize.Level1)
165 {
166 VideoParam configParam;
167 configParam.codecType_ = -1;
168
169 int32_t actual = encoder->InitVideoEncoder(configParam);
170 EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual);
171 }
172
173 /**
174 * @tc.name: SetEncoderFormat_001
175 * @tc.desc: Verify the SetEncoderFormat function.
176 * @tc.type: FUNC
177 * @tc.require: Issue Number
178 */
179 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_001, TestSize.Level1)
180 {
181 VideoParam configParam;
182 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
183 configParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
184
185 int32_t actual = encoder->SetEncoderFormat(configParam);
186 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
187 }
188
189 /**
190 * @tc.name: SetEncoderFormat_002
191 * @tc.desc: Verify the SetEncoderFormat function.
192 * @tc.type: FUNC
193 * @tc.require: Issue Number
194 */
195 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_002, TestSize.Level1)
196 {
197 VideoParam configParam;
198 configParam.codecType_ = -1;
199
200 int32_t actual = encoder->SetEncoderFormat(configParam);
201 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
202 }
203 } // DistributedHardware
204 } // OHOS