1 /*
2 * Copyright (c) 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 "histreamer_ability_querier_test.h"
17 #include "histreamer_ability_querier.h"
18
19 #include <string>
20 #include <cstring>
21 #include <vector>
22 #include <gtest/gtest.h>
23
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace DistributedHardware {
SetUpTestCase(void)28 void HistreamerAbilityQuerierTest::SetUpTestCase(void) {}
29
TearDownTestCase(void)30 void HistreamerAbilityQuerierTest::TearDownTestCase(void) {}
31
SetUp()32 void HistreamerAbilityQuerierTest::SetUp() {}
33
TearDown()34 void HistreamerAbilityQuerierTest::TearDown() {}
35
36 namespace {
37 int32_t g_maxMessagesLen = 1 * 1024 * 1024;
38 static const std::uint16_t UINT16_ONE = 1;
39 static const std::vector<VideoEncoder>::size_type VIDEO_ENCODER_FOUR = 4;
40 static const std::vector<VideoDecoder>::size_type VIDEO_DECODER_FOUR = 4;
41
42 static const std::string TEST_STR = "test string";
43 static const std::string KEY = "key";
44 static const std::string NAME = "name";
45 static const std::string MIME = "mime";
46 static const std::string SAMPLE_RATE = "sample_rate";
47 static const std::string AUDIO_ENCODER_NAME = "ffmpegAuEnc_aac";
48 static const std::string AUDIO_ENCODERIN_MIME = "audio/raw";
49 static const std::string AUDIO_ENCODEROUT_MIME = "audio/mp4a-latm";
50 static const std::string AD_MPEG_VER = "ad_mpeg_ver";
51 static const std::uint32_t AD_MPEG_VER_VALUE = 4;
52 static const std::string AUDIO_AAC_PROFILE = "aac_profile";
53 static const std::uint32_t AUDIO_AAC_PROFILE_VALUE = 0;
54 static const std::string AUDIO_AAC_STREAM_FORMAT = "aac_stm_fmt";
55
56 static const std::string AUDIO_DECODER_NAME = "ffmpegAuDec_aac";
57 static const std::string AUDIO_DECODERIN_MIME = "audio/mp4a-latm";
58 static const std::string AUDIO_DECODEROUT_MIME = "audio/raw";
59
60 static const std::string VIDEO_ENCODER_NAME = "HdiCodecAdapter.OMX.rk.video_encoder.hevc";
61 static const std::string VIDEO_ENCODERIN_MIME = "video/raw";
62
63 static const std::string VIDEO_DECODER_NAME = "HdiCodecAdapter.OMX.rk.video_decoder.hevc";
64 static const std::string VIDEO_DECODERIN_MIME = "video/hevc";
65 static const std::string VIDEO_DECODEROUT_MIME = "video/raw";
66
67 static const std::vector<std::string> AUDIO_ENCODER_WANT = { "ffmpegAuEnc_aac" };
68 static const std::vector<std::string> AUDIO_DECODER_WANT = { "ffmpegAuDec_aac" };
69 static const std::vector<std::string> VIDEO_ENCODER_WANT = {
70 "HdiCodecAdapter.OMX.hisi.video.encoder.hevc",
71 "HdiCodecAdapter.OMX.hisi.video.encoder.avc",
72 "HdiCodecAdapter.OMX.rk.video_encoder.hevc",
73 "HdiCodecAdapter.OMX.rk.video_encoder.avc"
74 };
75 static const std::vector<std::string> VIDEO_DECODER_WANT = {
76 "HdiCodecAdapter.OMX.hisi.video.decoder.hevc",
77 "HdiCodecAdapter.OMX.hisi.video.decoder.avc",
78 "HdiCodecAdapter.OMX.rk.video_decoder.hevc",
79 "HdiCodecAdapter.OMX.rk.video_decoder.avc"
80 };
81 }
82
83 /**
84 * @tc.name:histreamer_ability_querier_test_001
85 * @tc.desc: Verify the QueryAudioEncoderAbility function.
86 * @tc.type: FUNC
87 * @tc.require: issuelI7MJPJ
88 */
89 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_001, TestSize.Level0)
90 {
91 std::vector<AudioEncoder> audioEncoders = QueryAudioEncoderAbility();
92 EXPECT_FALSE(audioEncoders.empty());
93 for (std::vector<AudioEncoder>::size_type i = 0; i < audioEncoders.size(); i++) {
94 auto it = find(AUDIO_ENCODER_WANT.begin(), AUDIO_ENCODER_WANT.end(), audioEncoders[i].name);
95 EXPECT_TRUE(it != AUDIO_ENCODER_WANT.end());
96 }
97 }
98
99 /**
100 * @tc.name: histreamer_ability_querier_test_002
101 * @tc.desc: Verify QueryAudioDecoderAbility function
102 * @tc.type: FUNC
103 * @tc.require: issuelI7MJPJ
104 */
105 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_002, TestSize.Level0)
106 {
107 std::vector<AudioDecoder> audioDecoders = QueryAudioDecoderAbility();
108 EXPECT_FALSE(audioDecoders.empty());
109 for (std::vector<AudioDecoder>::size_type i = 0; i < audioDecoders.size(); i++) {
110 auto it = find(AUDIO_DECODER_WANT.begin(), AUDIO_DECODER_WANT.end(), audioDecoders[i].name);
111 EXPECT_TRUE(it != AUDIO_DECODER_WANT.end());
112 }
113 }
114
115 /**
116 * @tc.name: histreamer_ability_querier_test_003
117 * @tc.desc: Verify QueryVideoEncoderAbility function
118 * @tc.type: FUNC
119 * @tc.require: issuelI7MJPJ
120 */
121 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_003, TestSize.Level0)
122 {
123 std::vector<VideoEncoder> videoEncoders = QueryVideoEncoderAbility();
124 EXPECT_FALSE(videoEncoders.empty() || videoEncoders.size() > VIDEO_ENCODER_FOUR);
125 for (std::vector<VideoEncoder>::size_type i = 0; i < videoEncoders.size(); i++) {
126 auto it = find(VIDEO_ENCODER_WANT.begin(), VIDEO_ENCODER_WANT.end(), videoEncoders[i].name);
127 EXPECT_TRUE(it != VIDEO_ENCODER_WANT.end());
128 }
129 }
130
131 /**
132 * @tc.name: histreamer_ability_querier_test_004
133 * @tc.desc: Verify QueryVideoDecoderAbility function
134 * @tc.type: FUNC
135 * @tc.require: issuelI7MJPJ
136 *
137 */
138 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_004, TestSize.Level0)
139 {
140 std::vector<VideoDecoder> videoDecoders = QueryVideoDecoderAbility();
141 EXPECT_FALSE(videoDecoders.empty() || videoDecoders.size() > VIDEO_DECODER_FOUR);
142 for (std::vector<VideoDecoder>::size_type i = 0; i < videoDecoders.size(); i++) {
143 auto it = find(VIDEO_DECODER_WANT.begin(), VIDEO_DECODER_WANT.end(), videoDecoders[i].name);
144 EXPECT_TRUE(it != VIDEO_DECODER_WANT.end());
145 }
146 }
147
148 /**
149 * @tc.name: histreamer_ability_querier_test_005
150 * @tc.desc: Verify QueryAudioEncoderAbilityStr function
151 * @tc.type: FUNC
152 * @tc.require: issuelI7MJPJ
153 */
154 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_005, TestSize.Level0)
155 {
156 char* RES_MAX = new char[g_maxMessagesLen];
157 EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) >= 0);
158 EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) <= g_maxMessagesLen);
159 delete[] RES_MAX;
160 }
161
162 /**
163 * @tc.name: histreamer_ability_querier_test_006
164 * @tc.desc: Verify QueryAudioDecoderAbilityStr function
165 * @tc.type: FUNC
166 * @tc.require: issuelI7MJPJ
167 */
168 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_006, TestSize.Level0)
169 {
170 char* RES_MAX = new char[g_maxMessagesLen];
171 EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) >= 0);
172 EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) <= g_maxMessagesLen);
173 delete[] RES_MAX;
174 }
175
176 /**
177 * @tc.name: histreamer_ability_querier_test_007
178 * @tc.desc: Verify QueryVideoEncoderAbilityStr function
179 * @tc.type: FUNC
180 * @tc.require: issuelI7MJPJ
181 */
182 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_007, TestSize.Level0)
183 {
184 char* RES_MAX = new char[g_maxMessagesLen];
185 EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) >= 0);
186 EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) <= g_maxMessagesLen);
187 delete[] RES_MAX;
188 }
189
190 /**
191 * @tc.name: histreamer_ability_querier_test_008
192 * @tc.desc: Verify the QueryVideoDecoderAbilityStr function.
193 * @tc.type: FUNC
194 * @tc.require: issuelI7MJPJ
195 */
196 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_008, TestSize.Level0)
197 {
198 char* RES_MAX = new char[g_maxMessagesLen];
199 EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) >= 0);
200 EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) <= g_maxMessagesLen);
201 delete[] RES_MAX;
202 }
203
204 /**
205 * @tc.name: histreamer_ability_querier_test_009
206 * @tc.desc: Verify the IsString function.
207 * @tc.type: FUNC
208 * @tc.require: issuelI7MJPJ
209 */
210 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_009, TestSize.Level0)
211 {
212 cJSON *jsonObject = cJSON_CreateObject();
213 if (jsonObject == nullptr) {
214 return;
215 }
216 cJSON_AddStringToObject(jsonObject, KEY.c_str(), TEST_STR.c_str());
217 EXPECT_TRUE(IsString(jsonObject, KEY));
218 cJSON_Delete(jsonObject);
219
220 cJSON *jsonObject2 = cJSON_CreateObject();
221 if (jsonObject2 == nullptr) {
222 return;
223 }
224 cJSON_AddNumberToObject(jsonObject2, KEY.c_str(), 1);
225 EXPECT_FALSE(IsString(jsonObject2, KEY));
226 cJSON_Delete(jsonObject2);
227 }
228
229 /**
230 * @tc.name: histreamer_ability_querier_test_010
231 * @tc.desc: Verify the IsUint8 function.
232 * @tc.type: FUNC
233 * @tc.require: issuelI7MJPJ
234 */
235 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_010, TestSize.Level0)
236 {
237 cJSON *jsonObject = cJSON_CreateObject();
238 if (jsonObject == nullptr) {
239 return;
240 }
241 const uint8_t num_s = 1;
242 cJSON_AddNumberToObject(jsonObject, KEY.c_str(), num_s);
243 EXPECT_TRUE(IsUInt8(jsonObject, KEY));
244
245 const uint16_t num_b = UINT8_MAX + 1 ;
246 cJSON_AddNumberToObject(jsonObject, KEY.c_str(), num_b);
247 EXPECT_TRUE(IsUInt8(jsonObject, KEY));
248 cJSON_Delete(jsonObject);
249 }
250
251 /**
252 * @tc.name: histreamer_ability_querier_test_011
253 * @tc.desc: Verify the IsUInt32 function.
254 * @tc.type: FUNC
255 * @tc.require: issuelI7MJPJ
256 */
257 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_011, TestSize.Level0)
258 {
259 cJSON *jsonObject = cJSON_CreateObject();
260 if (jsonObject == nullptr) {
261 return;
262 }
263 const uint32_t num_s = 1;
264 cJSON_AddNumberToObject(jsonObject, KEY.c_str(), num_s);
265 EXPECT_TRUE(IsUInt32(jsonObject, KEY));
266
267 const int32_t num_i = -1;
268 cJSON_AddNumberToObject(jsonObject, KEY.c_str(), num_i);
269 EXPECT_TRUE(IsUInt32(jsonObject, KEY));
270 cJSON_Delete(jsonObject);
271 }
272
273 /**
274 * @tc.name: histreamer_ability_querier_test_012
275 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) function.
276 * @tc.type: FUNC
277 * @tc.require: issuelI7MJPJ
278 */
279 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_012, TestSize.Level0)
280 {
281 cJSON *jsonObject = cJSON_CreateObject();
282 if (jsonObject == nullptr) {
283 return;
284 }
285 AudioEncoderIn audioEncoderIn;
286 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
287 FromJson(jsonObject, audioEncoderIn);
288 EXPECT_TRUE(audioEncoderIn.mime.empty());
289 cJSON_Delete(jsonObject);
290 }
291
292 /**
293 * @tc.name: histreamer_ability_querier_test_013
294 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut) function.
295 * @tc.type: FUNC
296 * @tc.require: issuelI7MJPJ
297 */
298 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_013, TestSize.Level0)
299 {
300 cJSON *jsonObject = cJSON_CreateObject();
301 if (jsonObject == nullptr) {
302 return;
303 }
304 AudioEncoderOut audioEncoderOut;
305 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
306 FromJson(jsonObject, audioEncoderOut);
307 EXPECT_TRUE(audioEncoderOut.mime.empty());
308 cJSON_Delete(jsonObject);
309 cJSON *jsonObject2 = cJSON_CreateObject();
310 if (jsonObject2 == nullptr) {
311 return;
312 }
313
314 cJSON_AddStringToObject(jsonObject2, MIME.c_str(), AUDIO_ENCODEROUT_MIME.c_str());
315 cJSON_AddNumberToObject(jsonObject2, AD_MPEG_VER.c_str(), AD_MPEG_VER_VALUE);
316 FromJson(jsonObject2, audioEncoderOut);
317 EXPECT_EQ(AUDIO_ENCODEROUT_MIME, audioEncoderOut.mime);
318 EXPECT_EQ(AD_MPEG_VER_VALUE, (uint32_t)audioEncoderOut.ad_mpeg_ver);
319
320 cJSON_AddNumberToObject(jsonObject2, AUDIO_AAC_PROFILE.c_str(), AUDIO_AAC_PROFILE_VALUE);
321 cJSON_AddStringToObject(jsonObject2, AUDIO_AAC_STREAM_FORMAT.c_str(), TEST_STR.c_str());
322 FromJson(jsonObject2, audioEncoderOut);
323 EXPECT_EQ(AUDIO_AAC_PROFILE_VALUE, (uint32_t)audioEncoderOut.aac_profile);
324 cJSON_Delete(jsonObject2);
325 }
326
327 /**
328 * @tc.name: histreamer_ability_querier_test_014
329 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) function.
330 * @tc.type: FUNC
331 * @tc.require: issuelI7MJPJ
332 */
333 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_014, TestSize.Level0)
334 {
335 cJSON *jsonObject = nullptr;
336 AudioEncoder audioEncoder;
337 ToJson(jsonObject, audioEncoder);
338 jsonObject = cJSON_CreateObject();
339 if (jsonObject == nullptr) {
340 return;
341 }
342 cJSON_AddNumberToObject(jsonObject, NAME.c_str(), UINT16_ONE);
343 FromJson(jsonObject, audioEncoder);
344 EXPECT_TRUE(audioEncoder.name.empty());
345 cJSON_Delete(jsonObject);
346
347 cJSON *jsonObject2 = cJSON_CreateObject();
348 if (jsonObject2 == nullptr) {
349 return;
350 }
351
352 cJSON_AddStringToObject(jsonObject2, NAME.c_str(), AUDIO_ENCODER_NAME.c_str());
353 FromJson(jsonObject2, audioEncoder);
354 EXPECT_EQ(AUDIO_ENCODER_NAME, audioEncoder.name);
355 EXPECT_TRUE(audioEncoder.ins.empty());
356
357 AudioEncoderIn audioEncoderIn;
358 audioEncoderIn.mime = AUDIO_ENCODERIN_MIME;
359 audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000};
360 audioEncoder.ins.push_back(audioEncoderIn);
361 FromJson(jsonObject2, audioEncoder);
362 EXPECT_FALSE(audioEncoder.ins.empty());
363 EXPECT_TRUE(audioEncoder.outs.empty());
364 cJSON_Delete(jsonObject2);
365 }
366
367 /**
368 * @tc.name: histreamer_ability_querier_test_015
369 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) function.
370 * @tc.type: FUNC
371 * @tc.require: issuelI7MJPJ
372 */
373 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_015, TestSize.Level0)
374 {
375 cJSON *jsonObject = nullptr;
376 AudioDecoderIn audioDecoderIn;
377 ToJson(jsonObject, audioDecoderIn);
378 jsonObject = cJSON_CreateObject();
379 if (jsonObject == nullptr) {
380 return;
381 }
382 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
383 FromJson(jsonObject, audioDecoderIn);
384 EXPECT_TRUE(audioDecoderIn.mime.empty());
385 cJSON_Delete(jsonObject);
386
387 cJSON *jsonObject2 = cJSON_CreateObject();
388 if (jsonObject2 == nullptr) {
389 return;
390 }
391
392 cJSON_AddStringToObject(jsonObject2, MIME.c_str(), AUDIO_DECODERIN_MIME.c_str());
393 FromJson(jsonObject2, audioDecoderIn);
394 EXPECT_EQ(AUDIO_DECODERIN_MIME, audioDecoderIn.mime);
395 EXPECT_TRUE(audioDecoderIn.channel_layout.empty());
396 cJSON_Delete(jsonObject2);
397 }
398
399 /**
400 * @tc.name: histreamer_ability_querier_test_016
401 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) function.
402 * @tc.type: FUNC
403 * @tc.require: issuelI7MJPJ
404 */
405 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_016, TestSize.Level0)
406 {
407 cJSON *jsonObject = nullptr;
408 AudioDecoderOut audioDecoderOut;
409 ToJson(jsonObject, audioDecoderOut);
410 jsonObject = cJSON_CreateObject();
411 if (jsonObject == nullptr) {
412 return;
413 }
414 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
415 FromJson(jsonObject, audioDecoderOut);
416 EXPECT_TRUE(audioDecoderOut.mime.empty());
417 cJSON_Delete(jsonObject);
418
419 cJSON *jsonObject2 = cJSON_CreateObject();
420 if (jsonObject2 == nullptr) {
421 return;
422 }
423
424 cJSON_AddStringToObject(jsonObject2, MIME.c_str(), AUDIO_DECODEROUT_MIME.c_str());
425 FromJson(jsonObject2, audioDecoderOut);
426 EXPECT_EQ(AUDIO_DECODEROUT_MIME, audioDecoderOut.mime);
427 EXPECT_TRUE(audioDecoderOut.sample_fmt.empty());
428 cJSON_Delete(jsonObject2);
429 }
430
431 /**
432 * @tc.name: histreamer_ability_querier_test_017
433 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) function.
434 * @tc.type: FUNC
435 * @tc.require: issuelI7MJPJ
436 */
437 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_017, TestSize.Level0)
438 {
439 cJSON *jsonObject = nullptr;
440 AudioDecoder audioDecoder;
441 ToJson(jsonObject, audioDecoder);
442 jsonObject = cJSON_CreateObject();
443 if (jsonObject == nullptr) {
444 return;
445 }
446 cJSON_AddNumberToObject(jsonObject, NAME.c_str(), UINT16_ONE);
447 FromJson(jsonObject, audioDecoder);
448 EXPECT_TRUE(audioDecoder.name.empty());
449 cJSON_Delete(jsonObject);
450
451 cJSON *jsonObject2 = cJSON_CreateObject();
452 if (jsonObject2 == nullptr) {
453 return;
454 }
455
456 cJSON_AddStringToObject(jsonObject2, NAME.c_str(), AUDIO_DECODER_NAME.c_str());
457 FromJson(jsonObject2, audioDecoder);
458 EXPECT_EQ(AUDIO_DECODER_NAME, audioDecoder.name);
459 EXPECT_TRUE(audioDecoder.ins.empty());
460
461 AudioDecoderIn audioDecoderIn;
462 audioDecoderIn.mime = AUDIO_DECODERIN_MIME;
463 audioDecoderIn.channel_layout = {
464 AudioChannelLayout::CH_2POINT1,
465 AudioChannelLayout::CH_2_1,
466 AudioChannelLayout::SURROUND,
467 };
468 audioDecoder.ins.push_back(audioDecoderIn);
469 FromJson(jsonObject2, audioDecoder);
470 EXPECT_FALSE(audioDecoder.ins.empty());
471 EXPECT_TRUE(audioDecoder.outs.empty());
472 cJSON_Delete(jsonObject2);
473 }
474
475 /**
476 * @tc.name: histreamer_ability_querier_test_018
477 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) function.
478 * @tc.type: FUNC
479 * @tc.require: issuelI7MJPJ
480 */
481 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_018, TestSize.Level0)
482 {
483 cJSON *jsonObject = nullptr;
484 VideoEncoderIn videoEncoderIn;
485 ToJson(jsonObject, videoEncoderIn);
486 FromJson(jsonObject, videoEncoderIn);
487 jsonObject = cJSON_CreateObject();
488 if (jsonObject == nullptr) {
489 return;
490 }
491 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
492 FromJson(jsonObject, videoEncoderIn);
493 EXPECT_TRUE(videoEncoderIn.mime.empty());
494 cJSON_Delete(jsonObject);
495
496 cJSON *jsonObject2 = cJSON_CreateObject();
497 if (jsonObject2 == nullptr) {
498 return;
499 }
500
501 cJSON_AddStringToObject(jsonObject2, MIME.c_str(), VIDEO_ENCODERIN_MIME.c_str());
502 FromJson(jsonObject2, videoEncoderIn);
503 EXPECT_EQ(VIDEO_ENCODERIN_MIME, videoEncoderIn.mime);
504 EXPECT_TRUE(videoEncoderIn.pixel_fmt.empty());
505 cJSON_Delete(jsonObject2);
506 }
507
508 /**
509 * @tc.name: histreamer_ability_querier_test_019
510 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut) function.
511 * @tc.type: FUNC
512 * @tc.require: issuelI7MJPJ
513 */
514 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_019, TestSize.Level0)
515 {
516 cJSON *jsonObject = nullptr;
517 VideoEncoderOut videoEncoderOut;
518 ToJson(jsonObject, videoEncoderOut);
519 FromJson(jsonObject, videoEncoderOut);
520 jsonObject = cJSON_CreateObject();
521 if (jsonObject == nullptr) {
522 return;
523 }
524 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
525 FromJson(jsonObject, videoEncoderOut);
526 EXPECT_TRUE(videoEncoderOut.mime.empty());
527 cJSON_Delete(jsonObject);
528 }
529
530 /**
531 * @tc.name: histreamer_ability_querier_test_020
532 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) function.
533 * @tc.type: FUNC
534 * @tc.require: issuelI7MJPJ
535 */
536 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_020, TestSize.Level0)
537 {
538 cJSON *jsonObject = nullptr;
539 VideoEncoder videoEncoder;
540 ToJson(jsonObject, videoEncoder);
541 FromJson(jsonObject, videoEncoder);
542 jsonObject = cJSON_CreateObject();
543 if (jsonObject == nullptr) {
544 return;
545 }
546 cJSON_AddNumberToObject(jsonObject, NAME.c_str(), UINT16_ONE);
547 FromJson(jsonObject, videoEncoder);
548 EXPECT_TRUE(videoEncoder.name.empty());
549 cJSON_Delete(jsonObject);
550
551 cJSON *jsonObject2 = cJSON_CreateObject();
552 if (jsonObject2 == nullptr) {
553 return;
554 }
555
556 cJSON_AddStringToObject(jsonObject2, NAME.c_str(), VIDEO_ENCODER_NAME.c_str());
557 FromJson(jsonObject2, videoEncoder);
558 EXPECT_EQ(VIDEO_ENCODER_NAME, videoEncoder.name);
559 EXPECT_TRUE(videoEncoder.ins.empty());
560
561 VideoEncoderIn videoEncoderIn;
562 videoEncoderIn.mime = VIDEO_ENCODERIN_MIME;
563 videoEncoderIn.pixel_fmt = {
564 VideoPixelFormat::YUV410P,
565 VideoPixelFormat::RGBA,
566 };
567 videoEncoder.ins.push_back(videoEncoderIn);
568 FromJson(jsonObject2, videoEncoder);
569 EXPECT_FALSE(videoEncoder.ins.empty());
570 EXPECT_TRUE(videoEncoder.outs.empty());
571 cJSON_Delete(jsonObject2);
572 }
573
574 /**
575 * @tc.name: histreamer_ability_querier_test_021
576 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) function.
577 * @tc.type: FUNC
578 * @tc.require: issuelI7MJPJ
579 */
580 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_021, TestSize.Level0)
581 {
582 cJSON *jsonObject = cJSON_CreateObject();
583 if (jsonObject == nullptr) {
584 return;
585 }
586 VideoDecoderIn videoDecoderIn;
587 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
588 FromJson(jsonObject, videoDecoderIn);
589 EXPECT_TRUE(videoDecoderIn.mime.empty());
590 cJSON_Delete(jsonObject);
591
592 cJSON *jsonObject2 = cJSON_CreateObject();
593 if (jsonObject2 == nullptr) {
594 return;
595 }
596
597 cJSON_AddStringToObject(jsonObject2, MIME.c_str(), VIDEO_DECODERIN_MIME.c_str());
598 FromJson(jsonObject2, videoDecoderIn);
599 EXPECT_EQ(VIDEO_DECODERIN_MIME, videoDecoderIn.mime);
600 EXPECT_TRUE(videoDecoderIn.vd_bit_stream_fmt.empty());
601 cJSON_Delete(jsonObject2);
602 }
603
604 /**
605 * @tc.name: histreamer_ability_querier_test_022
606 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) function.
607 * @tc.type: FUNC
608 * @tc.require: issuelI7MJPJ
609 */
610 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_022, TestSize.Level0)
611 {
612 cJSON *jsonObject = cJSON_CreateObject();
613 if (jsonObject == nullptr) {
614 return;
615 }
616 VideoDecoderOut videoDecoderOut;
617 cJSON_AddNumberToObject(jsonObject, MIME.c_str(), UINT16_ONE);
618 FromJson(jsonObject, videoDecoderOut);
619 EXPECT_TRUE(videoDecoderOut.mime.empty());
620 cJSON_Delete(jsonObject);
621
622 cJSON *jsonObject2 = cJSON_CreateObject();
623 if (jsonObject2 == nullptr) {
624 return;
625 }
626
627 cJSON_AddStringToObject(jsonObject2, MIME.c_str(), VIDEO_DECODEROUT_MIME.c_str());
628 FromJson(jsonObject2, videoDecoderOut);
629 EXPECT_EQ(VIDEO_DECODEROUT_MIME, videoDecoderOut.mime);
630 EXPECT_TRUE(videoDecoderOut.pixel_fmt.empty());
631 cJSON_Delete(jsonObject2);
632 }
633
634 /**
635 * @tc.name: histreamer_ability_querier_test_023
636 * @tc.desc: Verify the FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) function.
637 * @tc.type: FUNC
638 * @tc.require: issuelI7MJPJ
639 */
640 HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_023, TestSize.Level0)
641 {
642 cJSON *jsonObject = cJSON_CreateObject();
643 if (jsonObject == nullptr) {
644 return;
645 }
646 VideoDecoder videoDecoder;
647 cJSON_AddNumberToObject(jsonObject, NAME.c_str(), UINT16_ONE);
648 FromJson(jsonObject, videoDecoder);
649 EXPECT_TRUE(videoDecoder.name.empty());
650 cJSON_Delete(jsonObject);
651
652 cJSON *jsonObject2 = cJSON_CreateObject();
653 if (jsonObject2 == nullptr) {
654 return;
655 }
656
657 cJSON_AddStringToObject(jsonObject2, NAME.c_str(), VIDEO_DECODER_NAME.c_str());
658 FromJson(jsonObject2, videoDecoder);
659 EXPECT_EQ(VIDEO_DECODER_NAME, videoDecoder.name);
660 EXPECT_TRUE(videoDecoder.ins.empty());
661
662 VideoDecoderIn videoDecoderIn;
663 videoDecoderIn.mime = VIDEO_DECODERIN_MIME;
664 videoDecoderIn.vd_bit_stream_fmt = {
665 VideoBitStreamFormat::AVC1,
666 VideoBitStreamFormat::HEVC,
667 };
668 videoDecoder.ins.push_back(videoDecoderIn);
669 FromJson(jsonObject2, videoDecoder);
670 EXPECT_FALSE(videoDecoder.ins.empty());
671 EXPECT_TRUE(videoDecoder.outs.empty());
672 cJSON_Delete(jsonObject2);
673 }
674 } // namespace DistributedHardware
675 } // namespace OHOS