• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 "component_loader_test.h"
17 
18 #include "config_policy_utils.h"
19 #include "component_loader.h"
20 #include "distributed_hardware_log.h"
21 #include "hitrace_meter.h"
22 #include "hidump_helper.h"
23 #include "kvstore_observer.h"
24 #include "cJSON.h"
25 #include "versionmanager/version_manager.h"
26 
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace DistributedHardware {
SetUpTestCase(void)31 void ComponentLoaderTest::SetUpTestCase(void) {}
32 
TearDownTestCase(void)33 void ComponentLoaderTest::TearDownTestCase(void) {}
34 
SetUp()35 void ComponentLoaderTest::SetUp()
36 {
37 }
38 
TearDown()39 void ComponentLoaderTest::TearDown()
40 {
41 }
42 
43 HWTEST_F(ComponentLoaderTest, CheckComponentEnable_001, TestSize.Level0)
44 {
45     CompConfig config = {
46         .name = "name",
47         .type = DHType::UNKNOWN,
48         .compSourceSaId = 4801,
49         .compSinkSaId = 4802
50     };
51     auto ret = ComponentLoader::GetInstance().CheckComponentEnable(config);
52     EXPECT_EQ(true, ret);
53 
54     CompConfig config1 = {
55         .name = "name",
56         .type = DHType::INPUT,
57         .compSourceSaId = 4801,
58         .compSinkSaId = 4802
59     };
60     ret = ComponentLoader::GetInstance().CheckComponentEnable(config1);
61     EXPECT_EQ(false, ret);
62 }
63 
64 /**
65  * @tc.name: GetLocalDHVersion_001
66  * @tc.desc: Verify the GetLocalDHVersion function.
67  * @tc.type: FUNC
68  * @tc.require: AR000GHSK3
69  */
70 HWTEST_F(ComponentLoaderTest, GetLocalDHVersion_001, TestSize.Level0)
71 {
72     DHVersion dhVersion;
73     ComponentLoader::GetInstance().isLocalVersionInit_.store(false);
74     ComponentLoader::GetInstance().StoreLocalDHVersionInDB();
75     auto ret = ComponentLoader::GetInstance().GetLocalDHVersion(dhVersion);
76     EXPECT_EQ(ERR_DH_FWK_LOADER_GET_LOCAL_VERSION_FAIL, ret);
77 
78     ComponentLoader::GetInstance().isLocalVersionInit_.store(true);
79     ret = ComponentLoader::GetInstance().GetLocalDHVersion(dhVersion);
80     EXPECT_EQ(DH_FWK_SUCCESS, ret);
81 }
82 
83 /**
84  * @tc.name: GetHardwareHandler_001
85  * @tc.desc: Verify the GetHardwareHandler function.
86  * @tc.type: FUNC
87  * @tc.require: AR000GHSK3
88  */
89 HWTEST_F(ComponentLoaderTest, GetHardwareHandler_001, TestSize.Level0)
90 {
91     IHardwareHandler *hardwareHandlerPtr = nullptr;
92     auto ret = ComponentLoader::GetInstance().GetHardwareHandler(DHType::UNKNOWN, hardwareHandlerPtr);
93     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
94 
95     CompHandler comHandler;
96     comHandler.hardwareHandler = nullptr;
97     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
98     ret = ComponentLoader::GetInstance().GetHardwareHandler(DHType::AUDIO, hardwareHandlerPtr);
99     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
100     ComponentLoader::GetInstance().compHandlerMap_.clear();
101 }
102 
103 #ifdef DHARDWARE_CLOSE_UT
104     /**
105      * @tc.name: GetHardwareHandler_002
106      * @tc.desc: Verify the GetHardwareHandler function.
107      * @tc.type: FUNC
108      * @tc.require: AR000GHSK3
109      */
110     HWTEST_F(ComponentLoaderTest, GetHardwareHandler_002, TestSize.Level0)
111     {
112         ComponentLoader::GetInstance().Init();
113         IHardwareHandler *hardwareHandlerPtr = nullptr;
114         auto ret = ComponentLoader::GetInstance().GetHardwareHandler(DHType::AUDIO, hardwareHandlerPtr);
115         EXPECT_EQ(DH_FWK_SUCCESS, ret);
116         ComponentLoader::GetInstance().UnInit();
117     }
118 #endif
119 
120 /**
121  * @tc.name: GetSource_001
122  * @tc.desc: Verify the GetSource function.
123  * @tc.type: FUNC
124  * @tc.require: AR000GHSK3
125  */
126 HWTEST_F(ComponentLoaderTest, GetSource_001, TestSize.Level0)
127 {
128     IDistributedHardwareSource *sourcePtr = nullptr;
129     auto ret = ComponentLoader::GetInstance().GetSource(DHType::UNKNOWN, sourcePtr);
130     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
131 
132     CompHandler comHandler;
133     comHandler.sourceHandler = nullptr;
134     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
135     ret = ComponentLoader::GetInstance().GetSource(DHType::AUDIO, sourcePtr);
136     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
137 }
138 
139 #ifdef DHARDWARE_CLOSE_UT
140     /**
141      * @tc.name: GetSource_002
142      * @tc.desc: Verify the GetSource function.
143      * @tc.type: FUNC
144      * @tc.require: AR000GHSK3
145      */
146     HWTEST_F(ComponentLoaderTest, GetSource_002, TestSize.Level0)
147     {
148         ComponentLoader::GetInstance().Init();
149         IDistributedHardwareSource *sourcePtr = nullptr;
150         auto ret = ComponentLoader::GetInstance().GetSource(DHType::AUDIO, sourcePtr);
151         EXPECT_EQ(DH_FWK_SUCCESS, ret);
152         ComponentLoader::GetInstance().UnInit();
153     }
154 #endif
155 
156 /**
157  * @tc.name: GetSink_001
158  * @tc.desc: Verify the GetSink function.
159  * @tc.type: FUNC
160  * @tc.require: AR000GHSK3
161  */
162 HWTEST_F(ComponentLoaderTest, GetSink_001, TestSize.Level0)
163 {
164     IDistributedHardwareSink *sinkPtr = nullptr;
165     auto ret = ComponentLoader::GetInstance().GetSink(DHType::UNKNOWN, sinkPtr);
166     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
167 
168     CompHandler comHandler;
169     comHandler.sinkHandler = nullptr;
170     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
171     ret = ComponentLoader::GetInstance().GetSink(DHType::AUDIO, sinkPtr);
172     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
173     ComponentLoader::GetInstance().compHandlerMap_.clear();
174 }
175 
176 #ifdef DHARDWARE_CLOSE_UT
177     /**
178      * @tc.name: GetSink_002
179      * @tc.desc: Verify the GetSink function.
180      * @tc.type: FUNC
181      * @tc.require: AR000GHSK3
182      */
183     HWTEST_F(ComponentLoaderTest, GetSink_002, TestSize.Level0)
184     {
185         ComponentLoader::GetInstance().Init();
186         IDistributedHardwareSink *sinkPtr = nullptr;
187         auto ret = ComponentLoader::GetInstance().GetSink(DHType::AUDIO, sinkPtr);
188         EXPECT_EQ(DH_FWK_SUCCESS, ret);
189         ComponentLoader::GetInstance().UnInit();
190     }
191 #endif
192 
193 /**
194  * @tc.name: Readfile_001
195  * @tc.desc: Verify the Readfile function.
196  * @tc.type: FUNC
197  * @tc.require: AR000GHSK3
198  */
199 HWTEST_F(ComponentLoaderTest, Readfile_001, TestSize.Level0)
200 {
201     std::string filePath = "";
202     auto ret = ComponentLoader::GetInstance().Readfile(filePath);
203     EXPECT_EQ("", ret);
204 }
205 
206 /**
207  * @tc.name: ReleaseHardwareHandler_001
208  * @tc.desc: Verify the ReleaseHardwareHandler function.
209  * @tc.type: FUNC
210  * @tc.require: AR000GHSK3
211  */
212 HWTEST_F(ComponentLoaderTest, ReleaseHardwareHandler_001, TestSize.Level0)
213 {
214     auto ret = ComponentLoader::GetInstance().ReleaseHardwareHandler(DHType::AUDIO);
215     EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret);
216 
217     CompHandler comHandler;
218     comHandler.hardwareHandler = nullptr;
219     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
220     ret = ComponentLoader::GetInstance().ReleaseHardwareHandler(DHType::AUDIO);
221     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_UNLOAD, ret);
222     ComponentLoader::GetInstance().compHandlerMap_.clear();
223 }
224 
225 /**
226  * @tc.name: ReleaseSource_001
227  * @tc.desc: Verify the ReleaseSource function.
228  * @tc.type: FUNC
229  * @tc.require: AR000GHSK3
230  */
231 HWTEST_F(ComponentLoaderTest, ReleaseSource_001, TestSize.Level0)
232 {
233     auto ret = ComponentLoader::GetInstance().ReleaseSource(DHType::AUDIO);
234     EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret);
235 
236     CompHandler comHandler;
237     comHandler.sourceHandler = nullptr;
238     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
239     ret = ComponentLoader::GetInstance().ReleaseSource(DHType::AUDIO);
240     EXPECT_EQ(ERR_DH_FWK_LOADER_SOURCE_UNLOAD, ret);
241     ComponentLoader::GetInstance().compHandlerMap_.clear();
242 }
243 
244 /**
245  * @tc.name: ReleaseSink_001
246  * @tc.desc: Verify the ReleaseSink function.
247  * @tc.type: FUNC
248  * @tc.require: AR000GHSK3
249  */
250 HWTEST_F(ComponentLoaderTest, ReleaseSink_001, TestSize.Level0)
251 {
252     auto ret = ComponentLoader::GetInstance().ReleaseSink(DHType::AUDIO);
253     EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret);
254 
255     CompHandler comHandler;
256     comHandler.sinkHandler = nullptr;
257     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
258     ret = ComponentLoader::GetInstance().ReleaseSink(DHType::AUDIO);
259     EXPECT_EQ(ERR_DH_FWK_LOADER_SINK_UNLOAD, ret);
260     ComponentLoader::GetInstance().compHandlerMap_.clear();
261 }
262 
263 /**
264  * @tc.name: GetHandler_001
265  * @tc.desc: Verify the GetHandler function.
266  * @tc.type: FUNC
267  * @tc.require: AR000GHSK3
268  */
269 HWTEST_F(ComponentLoaderTest, GetHandler_001, TestSize.Level0)
270 {
271     std::string soNameEmpty = "";
272     auto handler = ComponentLoader::GetInstance().GetHandler(soNameEmpty);
273     EXPECT_EQ(nullptr, handler);
274 }
275 
276 /**
277  * @tc.name: component_loader_test_017
278  * @tc.desc: Verify the GetCompPathAndVersion function.
279  * @tc.type: FUNC
280  * @tc.require: AR000GHSK3
281  */
282 HWTEST_F(ComponentLoaderTest, component_loader_test_017, TestSize.Level0)
283 {
284     std::string jsonStr = "";
285     std::map<DHType, CompConfig> dhtypeMap;
286     int32_t ret = ComponentLoader::GetInstance().GetCompPathAndVersion(jsonStr, dhtypeMap);
287     EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
288 }
289 
290 /**
291  * @tc.name: component_loader_test_018
292  * @tc.desc: Verify the GetCompPathAndVersion function.
293  * @tc.type: FUNC
294  * @tc.require: AR000GHSK3
295  */
296 HWTEST_F(ComponentLoaderTest, component_loader_test_018, TestSize.Level0)
297 {
298     const char *NAME = "NAME";
299     const char *TYPE = "TYPE";
300     const char *PATH = "PATH";
301     cJSON* json0bject = cJSON_CreateObject();
302     ASSERT_TRUE(json0bject != nullptr);
303     cJSON* compVers = cJSON_CreateObject();
304     if (compVers == nullptr) {
305         cJSON_Delete(json0bject);
306         return;
307     }
308     cJSON_AddStringToObject(compVers, NAME, "name");
309     cJSON_AddNumberToObject(compVers, TYPE, 1111);
310     cJSON_AddItemToObject(json0bject, PATH, compVers);
311     char* cjson = cJSON_PrintUnformatted(json0bject);
312     if (cjson == nullptr) {
313         cJSON_Delete(json0bject);
314         return;
315     }
316     std::string jsonStr(cjson);
317     std::map<DHType, CompConfig> dhtypeMap;
318     int32_t ret = ComponentLoader::GetInstance().GetCompPathAndVersion(jsonStr, dhtypeMap);
319     cJSON_free(cjson);
320     cJSON_Delete(json0bject);
321     EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
322 }
323 
324 /**
325  * @tc.name: IsDHTypeExist_001
326  * @tc.desc: Verify the IsDHTypeExist function.
327  * @tc.type: FUNC
328  * @tc.require: AR000GHSK3
329  */
330 HWTEST_F(ComponentLoaderTest, IsDHTypeExist_001, TestSize.Level0)
331 {
332     CompHandler comHandler;
333     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
334     bool ret = ComponentLoader::GetInstance().IsDHTypeExist(DHType::AUDIO);
335     EXPECT_EQ(true, ret);
336     ComponentLoader::GetInstance().compHandlerMap_.clear();
337 }
338 
339 /**
340  * @tc.name: GetSourceSaId_001
341  * @tc.desc: Verify the GetSourceSaId function.
342  * @tc.type: FUNC
343  * @tc.require: AR000GHSK3
344  */
345 HWTEST_F(ComponentLoaderTest, GetSourceSaId_001, TestSize.Level0)
346 {
347     CompHandler comHandler;
348     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
349     int32_t ret = ComponentLoader::GetInstance().GetSourceSaId(DHType::UNKNOWN);
350     EXPECT_EQ(DEFAULT_SA_ID, ret);
351 
352     comHandler.sourceSaId = 1;
353     ComponentLoader::GetInstance().compHandlerMap_[DHType::AUDIO] = comHandler;
354     ret = ComponentLoader::GetInstance().GetSourceSaId(DHType::AUDIO);
355     EXPECT_EQ(1, ret);
356 }
357 
358 /**
359  * @tc.name: component_loader_test_022
360  * @tc.desc: Verify the ParseConfig function.
361  * @tc.type: FUNC
362  * @tc.require: AR000GHSK3
363  */
364 HWTEST_F(ComponentLoaderTest, component_loader_test_022, TestSize.Level0)
365 {
366     int32_t ret = ComponentLoader::GetInstance().ParseConfig();
367     EXPECT_EQ(DH_FWK_SUCCESS, ret);
368 }
369 
370 /**
371  * @tc.name: component_loader_test_023
372  * @tc.desc: Verify the ReleaseHandler function.
373  * @tc.type: FUNC
374  * @tc.require: AR000GHSK3
375  */
376 HWTEST_F(ComponentLoaderTest, component_loader_test_023, TestSize.Level0)
377 {
378     void *handler = nullptr;
379     int32_t ret = ComponentLoader::GetInstance().ReleaseHandler(handler);
380     EXPECT_EQ(ERR_DH_FWK_LOADER_HANDLER_IS_NULL, ret);
381 }
382 
383 /**
384  * @tc.name: component_loader_test_024
385  * @tc.desc: Verify the ReleaseHardwareHandler function.
386  * @tc.type: FUNC
387  * @tc.require: AR000GHSK3
388  */
389 HWTEST_F(ComponentLoaderTest, component_loader_test_024, TestSize.Level0)
390 {
391     DHType dhType = DHType::GPS;
392     int32_t ret = ComponentLoader::GetInstance().ReleaseHardwareHandler(dhType);
393     EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret);
394 }
395 
396 /**
397  * @tc.name: component_loader_test_025
398  * @tc.desc: Verify the ReleaseSource function.
399  * @tc.type: FUNC
400  * @tc.require: AR000GHSK3
401  */
402 HWTEST_F(ComponentLoaderTest, component_loader_test_025, TestSize.Level0)
403 {
404     DHType dhType = DHType::GPS;
405     int32_t ret = ComponentLoader::GetInstance().ReleaseSource(dhType);
406     EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret);
407 }
408 
409 /**
410  * @tc.name: component_loader_test_026
411  * @tc.desc: Verify the ReleaseSink function.
412  * @tc.type: FUNC
413  * @tc.require: AR000GHSK3
414  */
415 HWTEST_F(ComponentLoaderTest, component_loader_test_026, TestSize.Level0)
416 {
417     DHType dhType = DHType::GPS;
418     int32_t ret = ComponentLoader::GetInstance().ReleaseSink(dhType);
419     EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret);
420 }
421 
422 /**
423  * @tc.name: component_loader_test_027
424  * @tc.desc: Verify the ReleaseSink function.
425  * @tc.type: FUNC
426  * @tc.require: AR000GHSK3
427  */
428 HWTEST_F(ComponentLoaderTest, component_loader_test_027, TestSize.Level0)
429 {
430     DHType dhType = DHType::GPS;
431     bool ret = ComponentLoader::GetInstance().IsDHTypeExist(dhType);
432     EXPECT_EQ(false, ret);
433 }
434 
435 /**
436  * @tc.name: component_loader_test_028
437  * @tc.desc: Verify the GetDHTypeBySrcSaId function.
438  * @tc.type: FUNC
439  * @tc.require: AR000GHSK3
440  */
441 HWTEST_F(ComponentLoaderTest, component_loader_test_028, TestSize.Level0)
442 {
443     int32_t saId = 4801;
444     DHType dhType = ComponentLoader::GetInstance().GetDHTypeBySrcSaId(saId);
445     EXPECT_EQ(dhType, DHType::UNKNOWN);
446 }
447 
448 /**
449  * @tc.name: component_loader_test_029
450  * @tc.desc: Verify the from_json function.
451  * @tc.type: FUNC
452  * @tc.require: AR000GHSK3
453  */
454 HWTEST_F(ComponentLoaderTest, component_loader_test_029, TestSize.Level0)
455 {
456     CompConfig cfg;
457     cJSON *json = cJSON_CreateObject();
458     ASSERT_TRUE(json != nullptr);
459     cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 4801);
460 
461     from_json(json, cfg);
462     cJSON_Delete(json);
463     EXPECT_EQ(true, cfg.name.empty());
464 }
465 
466 /**
467  * @tc.name: component_loader_test_030
468  * @tc.desc: Verify the from_json function.
469  * @tc.type: FUNC
470  * @tc.require: AR000GHSK3
471  */
472 HWTEST_F(ComponentLoaderTest, component_loader_test_030, TestSize.Level0)
473 {
474     CompConfig cfg;
475     cJSON *json = cJSON_CreateObject();
476     ASSERT_TRUE(json != nullptr);
477     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
478     cJSON_AddNumberToObject(json, COMP_TYPE.c_str(), 0x02);
479 
480     from_json(json, cfg);
481     cJSON_Delete(json);
482     EXPECT_NE(DHType::AUDIO, cfg.type);
483 }
484 
485 /**
486  * @tc.name: component_loader_test_031
487  * @tc.desc: Verify the from_json function.
488  * @tc.type: FUNC
489  * @tc.require: AR000GHSK3
490  */
491 HWTEST_F(ComponentLoaderTest, component_loader_test_031, TestSize.Level0)
492 {
493     CompConfig cfg;
494     cJSON *json = cJSON_CreateObject();
495     ASSERT_TRUE(json != nullptr);
496     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
497     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
498     cJSON_AddNumberToObject(json, COMP_HANDLER_LOC.c_str(), 4801);
499 
500     from_json(json, cfg);
501     cJSON_Delete(json);
502     EXPECT_EQ(true, cfg.compHandlerLoc.empty());
503 }
504 
505 /**
506  * @tc.name: component_loader_test_032
507  * @tc.desc: Verify the from_json function.
508  * @tc.type: FUNC
509  * @tc.require: AR000GHSK3
510  */
511 HWTEST_F(ComponentLoaderTest, component_loader_test_032, TestSize.Level0)
512 {
513     CompConfig cfg;
514     cJSON *json = cJSON_CreateObject();
515     ASSERT_TRUE(json != nullptr);
516     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
517     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
518     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
519     cJSON_AddNumberToObject(json, COMP_HANDLER_VERSION.c_str(), 4801);
520 
521     from_json(json, cfg);
522     cJSON_Delete(json);
523     EXPECT_EQ(true, cfg.compHandlerVersion.empty());
524 }
525 
526 /**
527  * @tc.name: component_loader_test_033
528  * @tc.desc: Verify the from_json function.
529  * @tc.type: FUNC
530  * @tc.require: AR000GHSK3
531  */
532 HWTEST_F(ComponentLoaderTest, component_loader_test_033, TestSize.Level0)
533 {
534     CompConfig cfg;
535     cJSON *json = cJSON_CreateObject();
536     ASSERT_TRUE(json != nullptr);
537     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
538     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
539     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
540     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
541     cJSON_AddNumberToObject(json, COMP_SOURCE_LOC.c_str(), 4801);
542 
543     from_json(json, cfg);
544     cJSON_Delete(json);
545     EXPECT_EQ(true, cfg.compSourceLoc.empty());
546 }
547 
548 /**
549  * @tc.name: component_loader_test_034
550  * @tc.desc: Verify the from_json function.
551  * @tc.type: FUNC
552  * @tc.require: AR000GHSK3
553  */
554 HWTEST_F(ComponentLoaderTest, component_loader_test_034, TestSize.Level0)
555 {
556     CompConfig cfg;
557     cJSON *json = cJSON_CreateObject();
558     ASSERT_TRUE(json != nullptr);
559     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
560     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
561     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
562     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
563     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc");
564     cJSON_AddNumberToObject(json, COMP_SOURCE_VERSION.c_str(), 4801);
565 
566     from_json(json, cfg);
567     cJSON_Delete(json);
568     EXPECT_EQ(true, cfg.compSourceVersion.empty());
569 }
570 
571 /**
572  * @tc.name: component_loader_test_035
573  * @tc.desc: Verify the from_json function.
574  * @tc.type: FUNC
575  * @tc.require: AR000GHSK3
576  */
577 HWTEST_F(ComponentLoaderTest, component_loader_test_035, TestSize.Level0)
578 {
579     CompConfig cfg;
580     cJSON *json = cJSON_CreateObject();
581     ASSERT_TRUE(json != nullptr);
582     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
583     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
584     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
585     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
586     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc");
587     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "comp_source_version");
588     cJSON_AddStringToObject(json, COMP_SOURCE_SA_ID.c_str(), "comp_source_sa_id");
589 
590     from_json(json, cfg);
591     cJSON_Delete(json);
592     EXPECT_NE(4801, cfg.compSourceSaId);
593 }
594 
595 /**
596  * @tc.name: component_loader_test_036
597  * @tc.desc: Verify the from_json function.
598  * @tc.type: FUNC
599  * @tc.require: AR000GHSK3
600  */
601 HWTEST_F(ComponentLoaderTest, component_loader_test_036, TestSize.Level0)
602 {
603     CompConfig cfg;
604     cJSON *json = cJSON_CreateObject();
605     ASSERT_TRUE(json != nullptr);
606     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
607     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
608     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
609     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
610     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc");
611     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "comp_source_version");
612     cJSON_AddStringToObject(json, COMP_SOURCE_SA_ID.c_str(), "4801");
613     cJSON_AddNumberToObject(json, COMP_SINK_LOC.c_str(), 4802);
614 
615     from_json(json, cfg);
616     cJSON_Delete(json);
617     EXPECT_EQ(true, cfg.compSinkLoc.empty());
618 }
619 
620 /**
621  * @tc.name: component_loader_test_037
622  * @tc.desc: Verify the from_json function.
623  * @tc.type: FUNC
624  * @tc.require: AR000GHSK3
625  */
626 HWTEST_F(ComponentLoaderTest, component_loader_test_037, TestSize.Level0)
627 {
628     CompConfig cfg;
629     cJSON *json = cJSON_CreateObject();
630     ASSERT_TRUE(json != nullptr);
631     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
632     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
633     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
634     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
635     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc");
636     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "comp_source_version");
637     cJSON_AddNumberToObject(json, COMP_SOURCE_SA_ID.c_str(), 4801);
638     cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc");
639     cJSON_AddNumberToObject(json, COMP_SINK_VERSION.c_str(), 4802);
640 
641     from_json(json, cfg);
642     cJSON_Delete(json);
643     EXPECT_EQ(true, cfg.compSinkVersion.empty());
644 }
645 
646 /**
647  * @tc.name: component_loader_test_038
648  * @tc.desc: Verify the from_json function.
649  * @tc.type: FUNC
650  * @tc.require: AR000GHSK3
651  */
652 HWTEST_F(ComponentLoaderTest, component_loader_test_038, TestSize.Level0)
653 {
654     CompConfig cfg;
655     cJSON *json = cJSON_CreateObject();
656     ASSERT_TRUE(json != nullptr);
657     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
658     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
659     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
660     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
661     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc");
662     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "comp_source_version");
663     cJSON_AddNumberToObject(json, COMP_SOURCE_SA_ID.c_str(), 4801);
664     cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc");
665     cJSON_AddStringToObject(json, COMP_SINK_VERSION.c_str(), "comp_sink_version");
666     cJSON_AddStringToObject(json, COMP_SINK_SA_ID.c_str(), "4802");
667 
668     from_json(json, cfg);
669     cJSON_Delete(json);
670     EXPECT_NE(4802, cfg.compSinkSaId);
671 }
672 
673 /**
674  * @tc.name: component_loader_test_039
675  * @tc.desc: Verify the from_json function.
676  * @tc.type: FUNC
677  * @tc.require: AR000GHSK3
678  */
679 HWTEST_F(ComponentLoaderTest, component_loader_test_039, TestSize.Level0)
680 {
681     CompConfig cfg;
682     cJSON *json = cJSON_CreateObject();
683     ASSERT_TRUE(json != nullptr);
684     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name");
685     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO");
686     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc");
687     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "comp_handler_version");
688     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc");
689     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "comp_source_version");
690     cJSON_AddNumberToObject(json, COMP_SOURCE_SA_ID.c_str(), 4801);
691     cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc");
692     cJSON_AddStringToObject(json, COMP_SINK_VERSION.c_str(), "comp_sink_version");
693     cJSON_AddNumberToObject(json, COMP_SINK_SA_ID.c_str(), 4802);
694 
695     from_json(json, cfg);
696     cJSON_Delete(json);
697     EXPECT_EQ(4802, cfg.compSinkSaId);
698 }
699 
700 HWTEST_F(ComponentLoaderTest, ParseSink_001, TestSize.Level0)
701 {
702     CompConfig cfg;
703     cJSON *json = cJSON_CreateObject();
704     ASSERT_TRUE(json != nullptr);
705     cJSON_AddNumberToObject(json, COMP_SINK_LOC.c_str(), 100);
706     auto ret = ParseSink(json, cfg);
707     cJSON_Delete(json);
708     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
709 }
710 
711 HWTEST_F(ComponentLoaderTest, ParseSink_002, TestSize.Level0)
712 {
713     CompConfig cfg;
714     cJSON *json = cJSON_CreateObject();
715     ASSERT_TRUE(json != nullptr);
716     cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc_test");
717     cJSON_AddNumberToObject(json, COMP_SINK_VERSION.c_str(), 100);
718     auto ret = ParseSink(json, cfg);
719     cJSON_Delete(json);
720     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
721 }
722 
723 HWTEST_F(ComponentLoaderTest, ParseSink_003, TestSize.Level0)
724 {
725     CompConfig cfg;
726     cJSON *json = cJSON_CreateObject();
727     ASSERT_TRUE(json != nullptr);
728     cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc_test");
729     cJSON_AddStringToObject(json, COMP_SINK_VERSION.c_str(), "1.0");
730     cJSON_AddStringToObject(json, COMP_SINK_SA_ID.c_str(), "comp_sink_sa_id_test");
731     auto ret = ParseSink(json, cfg);
732     cJSON_Delete(json);
733     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
734 }
735 
736 HWTEST_F(ComponentLoaderTest, ParseSink_004, TestSize.Level0)
737 {
738     CompConfig cfg;
739     cJSON *json = cJSON_CreateObject();
740     ASSERT_TRUE(json != nullptr);
741     cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc_test");
742     cJSON_AddStringToObject(json, COMP_SINK_VERSION.c_str(), "1.0");
743     cJSON_AddNumberToObject(json, COMP_SINK_SA_ID.c_str(), 4801);
744     auto ret = ParseSink(json, cfg);
745     cJSON_Delete(json);
746     EXPECT_EQ(ret, DH_FWK_SUCCESS);
747 }
748 
749 HWTEST_F(ComponentLoaderTest, ParseResourceDesc_001, TestSize.Level0)
750 {
751     CompConfig cfg;
752     cJSON *array = cJSON_CreateArray();
753     ASSERT_TRUE(array != nullptr);
754     cJSON *obj = cJSON_CreateObject();
755     if (obj == nullptr) {
756         cJSON_Delete(array);
757         return;
758     }
759     cJSON_AddStringToObject(obj, COMP_SUBTYPE.c_str(), "comp_subtype");
760     cJSON_AddBoolToObject(obj, COMP_SENSITIVE.c_str(), true);
761     cJSON_AddItemToArray(array, obj);
762     cJSON *json = cJSON_CreateObject();
763     if (json == nullptr) {
764         cJSON_Delete(array);
765         return;
766     }
767     cJSON_AddItemToObject(json, COMP_RESOURCE_DESC.c_str(), array);
768     auto ret = ParseResourceDesc(json, cfg);
769     cJSON_Delete(json);
770 
771     CompConfig config;
772     cJSON *component = cJSON_CreateObject();
773     ASSERT_TRUE(component != nullptr);
774     cJSON_AddNumberToObject(component, COMP_NAME.c_str(), 1);
775     cJSON_AddNumberToObject(component, COMP_TYPE.c_str(), 1);
776     cJSON_AddNumberToObject(component, COMP_HANDLER_LOC.c_str(), 1);
777     cJSON_AddNumberToObject(component, COMP_HANDLER_VERSION.c_str(), 1.0);
778     cJSON_AddNumberToObject(component, COMP_SOURCE_LOC.c_str(), 1);
779     cJSON_AddNumberToObject(component, COMP_SOURCE_VERSION.c_str(), 1.0);
780     cJSON_AddStringToObject(component, COMP_SOURCE_SA_ID.c_str(), "4801");
781     cJSON_AddNumberToObject(component, COMP_SINK_LOC.c_str(), 1);
782     cJSON_AddNumberToObject(component, COMP_SINK_VERSION.c_str(), 1.0);
783     cJSON_AddStringToObject(component, COMP_SINK_SA_ID.c_str(), "4802");
784     cJSON_AddStringToObject(component, COMP_RESOURCE_DESC.c_str(), "comp_resource_desc");
785     ComponentLoader::GetInstance().ParseCompConfigFromJson(component, config);
786     cJSON_Delete(component);
787     EXPECT_EQ(ret, DH_FWK_SUCCESS);
788 }
789 
790 HWTEST_F(ComponentLoaderTest, ParseResourceDesc_002, TestSize.Level0)
791 {
792     CompConfig cfg;
793     cJSON *json = cJSON_CreateObject();
794     ASSERT_TRUE(json != nullptr);
795     cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 100);
796     auto ret = ParseComponent(json, cfg);
797     cJSON_Delete(json);
798     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
799 
800     CompConfig config1;
801     cJSON *component1 = cJSON_CreateObject();
802     ASSERT_TRUE(component1 != nullptr);
803     cJSON_AddStringToObject(component1, COMP_NAME.c_str(), "comp_name_test");
804     cJSON_AddStringToObject(component1, COMP_TYPE.c_str(), "comp_type_test");
805     cJSON_AddStringToObject(component1, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test");
806     cJSON_AddStringToObject(component1, COMP_HANDLER_VERSION.c_str(), "comp_handler_version_test");
807     cJSON_AddStringToObject(component1, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test");
808     cJSON_AddStringToObject(component1, COMP_SOURCE_VERSION.c_str(), "comp_source_verison_test");
809     cJSON_AddNumberToObject(component1, COMP_SOURCE_SA_ID.c_str(), 4801);
810     cJSON_AddStringToObject(component1, COMP_SINK_LOC.c_str(), "comp_sink_loc_test");
811     cJSON_AddStringToObject(component1, COMP_SINK_VERSION.c_str(), "com_sink_version_test");
812     cJSON_AddNumberToObject(component1, COMP_SINK_SA_ID.c_str(), 4802);
813     cJSON_AddStringToObject(component1, COMP_RESOURCE_DESC.c_str(), "comp_resource_desc");
814     ComponentLoader::GetInstance().ParseCompConfigFromJson(component1, config1);
815     cJSON_Delete(component1);
816 }
817 
818 HWTEST_F(ComponentLoaderTest, ParseResourceDesc_003, TestSize.Level0)
819 {
820     CompConfig cfg;
821     cJSON *jsonArr = cJSON_CreateArray();
822     ASSERT_TRUE(jsonArr != nullptr);
823     cJSON *json = cJSON_CreateObject();
824     if (json == nullptr) {
825         cJSON_Delete(jsonArr);
826         return;
827     }
828     cJSON_AddNumberToObject(json, COMP_SUBTYPE.c_str(), 1);
829     cJSON_AddItemToArray(jsonArr, json);
830     auto ret = ParseResourceDesc(jsonArr, cfg);
831     cJSON_Delete(jsonArr);
832     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
833 }
834 
835 HWTEST_F(ComponentLoaderTest, ParseResourceDescFromJson_003, TestSize.Level0)
836 {
837     CompConfig config;
838     cJSON *resourceDescs = cJSON_CreateArray();
839     ASSERT_TRUE(resourceDescs != nullptr);
840     cJSON *sensitive = cJSON_CreateObject();
841     if (sensitive == nullptr) {
842         cJSON_Delete(resourceDescs);
843         return;
844     }
845     cJSON_AddBoolToObject(sensitive, COMP_SENSITIVE.c_str(), true);
846     cJSON_AddItemToArray(resourceDescs, sensitive);
847     cJSON *subtype = cJSON_CreateObject();
848     if (subtype == nullptr) {
849         cJSON_Delete(resourceDescs);
850         return;
851     }
852     cJSON_AddBoolToObject(subtype, COMP_SUBTYPE.c_str(), true);
853     cJSON_AddItemToArray(resourceDescs, subtype);
854     ComponentLoader::GetInstance().ParseResourceDescFromJson(resourceDescs, config);
855     cJSON_Delete(resourceDescs);
856     EXPECT_TRUE(config.compResourceDesc.empty());
857 }
858 
859 HWTEST_F(ComponentLoaderTest, from_json_001, TestSize.Level0)
860 {
861     CompConfig cfg;
862     cJSON *json = cJSON_CreateObject();
863     ASSERT_TRUE(json != nullptr);
864     cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 100);
865     from_json(json, cfg);
866     cJSON_Delete(json);
867 
868     cJSON *Json1 = cJSON_CreateObject();
869     ASSERT_TRUE(Json1 != nullptr);
870     cJSON_AddStringToObject(Json1, COMP_NAME.c_str(), "comp_name_test");
871     cJSON_AddStringToObject(Json1, COMP_TYPE.c_str(), "comp_type_test");
872     cJSON_AddStringToObject(Json1, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test");
873     cJSON_AddStringToObject(Json1, COMP_HANDLER_VERSION.c_str(), "1.0");
874     cJSON_AddNumberToObject(Json1, COMP_SOURCE_LOC.c_str(), 100);
875     from_json(Json1, cfg);
876     cJSON_Delete(Json1);
877 
878     cJSON *Json2 = cJSON_CreateObject();
879     ASSERT_TRUE(Json2 != nullptr);
880     cJSON_AddStringToObject(Json2, COMP_NAME.c_str(), "comp_name_test");
881     cJSON_AddStringToObject(Json2, COMP_TYPE.c_str(), "comp_type_test");
882     cJSON_AddStringToObject(Json2, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test");
883     cJSON_AddStringToObject(Json2, COMP_HANDLER_VERSION.c_str(), "1.0");
884     cJSON_AddStringToObject(Json2, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test");
885     cJSON_AddStringToObject(Json2, COMP_SOURCE_VERSION.c_str(), "1.0");
886     cJSON_AddNumberToObject(Json2, COMP_SOURCE_SA_ID.c_str(), 4801);
887     cJSON_AddNumberToObject(Json2, COMP_SINK_LOC.c_str(), 100);
888     EXPECT_NO_FATAL_FAILURE(from_json(Json2, cfg));
889     cJSON_Delete(Json2);
890 }
891 
892 HWTEST_F(ComponentLoaderTest, ParseComponent_001, TestSize.Level0)
893 {
894     CompConfig cfg;
895     cJSON *json = cJSON_CreateObject();
896     ASSERT_TRUE(json != nullptr);
897     cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 100);
898     auto ret = ParseComponent(json, cfg);
899     cJSON_Delete(json);
900     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
901 }
902 
903 HWTEST_F(ComponentLoaderTest, ParseComponent_002, TestSize.Level0)
904 {
905     CompConfig cfg;
906     cJSON *json = cJSON_CreateObject();
907     ASSERT_TRUE(json != nullptr);
908     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test");
909     cJSON_AddNumberToObject(json, COMP_TYPE.c_str(), 100);
910     auto ret = ParseComponent(json, cfg);
911     cJSON_Delete(json);
912     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
913 }
914 
915 HWTEST_F(ComponentLoaderTest, ParseComponent_003, TestSize.Level0)
916 {
917     CompConfig cfg;
918     cJSON *json = cJSON_CreateObject();
919     ASSERT_TRUE(json != nullptr);
920     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test");
921     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "comp_type_test");
922     cJSON_AddNumberToObject(json, COMP_HANDLER_LOC.c_str(), 100);
923     auto ret = ParseComponent(json, cfg);
924     cJSON_Delete(json);
925     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
926 }
927 
928 HWTEST_F(ComponentLoaderTest, ParseComponent_004, TestSize.Level0)
929 {
930     CompConfig cfg;
931     cJSON *json = cJSON_CreateObject();
932     ASSERT_TRUE(json != nullptr);
933     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test");
934     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "comp_type_test");
935     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test");
936     cJSON_AddNumberToObject(json, COMP_HANDLER_VERSION.c_str(), 100);
937     auto ret = ParseComponent(json, cfg);
938     cJSON_Delete(json);
939     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
940 }
941 
942 HWTEST_F(ComponentLoaderTest, ParseComponent_005, TestSize.Level0)
943 {
944     CompConfig cfg;
945     cJSON *json = cJSON_CreateObject();
946     ASSERT_TRUE(json != nullptr);
947     cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test");
948     cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "comp_type_test");
949     cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test");
950     cJSON_AddStringToObject(json, COMP_HANDLER_VERSION.c_str(), "1.0");
951     auto ret = ParseComponent(json, cfg);
952     cJSON_Delete(json);
953     EXPECT_EQ(ret, DH_FWK_SUCCESS);
954 }
955 
956 HWTEST_F(ComponentLoaderTest, ParseSource_001, TestSize.Level0)
957 {
958     CompConfig cfg;
959     cJSON *json = cJSON_CreateObject();
960     ASSERT_TRUE(json != nullptr);
961     cJSON_AddNumberToObject(json, COMP_SOURCE_LOC.c_str(), 100);
962     auto ret = ParseSource(json, cfg);
963     cJSON_Delete(json);
964     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
965 }
966 
967 HWTEST_F(ComponentLoaderTest, ParseSource_002, TestSize.Level0)
968 {
969     CompConfig cfg;
970     cJSON *json = cJSON_CreateObject();
971     ASSERT_TRUE(json != nullptr);
972     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test");
973     cJSON_AddNumberToObject(json, COMP_SOURCE_VERSION.c_str(), 100);
974     auto ret = ParseSource(json, cfg);
975     cJSON_Delete(json);
976     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
977 }
978 
979 HWTEST_F(ComponentLoaderTest, ParseSource_003, TestSize.Level0)
980 {
981     CompConfig cfg;
982     cJSON *json = cJSON_CreateObject();
983     ASSERT_TRUE(json != nullptr);
984     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test");
985     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "1.0");
986     cJSON_AddStringToObject(json, COMP_SOURCE_SA_ID.c_str(), "4801");
987     auto ret = ParseSource(json, cfg);
988     cJSON_Delete(json);
989     EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED);
990 }
991 
992 HWTEST_F(ComponentLoaderTest, ParseSource_004, TestSize.Level0)
993 {
994     CompConfig cfg;
995     cJSON *json = cJSON_CreateObject();
996     ASSERT_TRUE(json != nullptr);
997     cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test");
998     cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "1.0");
999     cJSON_AddNumberToObject(json, COMP_SOURCE_SA_ID.c_str(), 4801);
1000     auto ret = ParseSource(json, cfg);
1001     cJSON_Delete(json);
1002     EXPECT_EQ(ret, DH_FWK_SUCCESS);
1003 }
1004 
1005 HWTEST_F(ComponentLoaderTest, GetHardwareHandler_003, TestSize.Level0)
1006 {
1007     ComponentLoader::GetInstance().compHandlerMap_.clear();
1008     DHType dhType = DHType::AUDIO;
1009     IHardwareHandler *hardwareHandlerPtr = nullptr;
1010     auto ret = ComponentLoader::GetInstance().GetHardwareHandler(dhType, hardwareHandlerPtr);
1011     EXPECT_EQ(ret, ERR_DH_FWK_LOADER_HANDLER_IS_NULL);
1012 }
1013 
1014 HWTEST_F(ComponentLoaderTest, GetSource_003, TestSize.Level0)
1015 {
1016     ComponentLoader::GetInstance().compHandlerMap_.clear();
1017     DHType dhType = DHType::AUDIO;
1018     IDistributedHardwareSource *dhSourcePtr = nullptr;
1019     auto ret = ComponentLoader::GetInstance().GetSource(dhType, dhSourcePtr);
1020     EXPECT_EQ(ret, ERR_DH_FWK_LOADER_HANDLER_IS_NULL);
1021 }
1022 
1023 HWTEST_F(ComponentLoaderTest, GetSink_003, TestSize.Level0)
1024 {
1025     ComponentLoader::GetInstance().compHandlerMap_.clear();
1026     DHType dhType = DHType::AUDIO;
1027     IDistributedHardwareSink *dhSinkPtr = nullptr;
1028     auto ret = ComponentLoader::GetInstance().GetSink(dhType, dhSinkPtr);
1029     EXPECT_EQ(ret, ERR_DH_FWK_LOADER_HANDLER_IS_NULL);
1030 }
1031 
1032 HWTEST_F(ComponentLoaderTest, ReleaseHardwareHandler_002, TestSize.Level0)
1033 {
1034     ComponentLoader::GetInstance().compHandlerMap_.clear();
1035     DHType dhType = DHType::AUDIO;
1036     auto ret = ComponentLoader::GetInstance().ReleaseHardwareHandler(dhType);
1037     EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST);
1038 
1039     ret = ComponentLoader::GetInstance().ReleaseSource(dhType);
1040     EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST);
1041 
1042     ret = ComponentLoader::GetInstance().ReleaseSource(dhType);
1043     EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST);
1044 
1045     ret = ComponentLoader::GetInstance().GetSourceSaId(dhType);
1046     EXPECT_EQ(ret, DEFAULT_SA_ID);
1047 }
1048 
1049 HWTEST_F(ComponentLoaderTest, GetDHTypeBySrcSaId_001, TestSize.Level0)
1050 {
1051     ComponentLoader::GetInstance().compHandlerMap_.clear();
1052     int32_t saId = 4801;
1053     auto ret = ComponentLoader::GetInstance().GetDHTypeBySrcSaId(saId);
1054     EXPECT_EQ(ret, DHType::UNKNOWN);
1055 }
1056 
1057 HWTEST_F(ComponentLoaderTest, GetSource_004, TestSize.Level0)
1058 {
1059     auto ret = ComponentLoader::GetInstance().GetSource(DHType::AUDIO);
1060     EXPECT_EQ(ret, ERR_DH_FWK_LOADER_HANDLER_IS_NULL);
1061 }
1062 
1063 HWTEST_F(ComponentLoaderTest, GetSink_004, TestSize.Level0)
1064 {
1065     auto ret = ComponentLoader::GetInstance().GetSink(DHType::AUDIO);
1066     EXPECT_EQ(ret, ERR_DH_FWK_LOADER_HANDLER_IS_NULL);
1067 }
1068 
1069 HWTEST_F(ComponentLoaderTest, GetHardwareHandler_004, TestSize.Level0)
1070 {
1071     auto ret = ComponentLoader::GetInstance().GetHardwareHandler(DHType::AUDIO);
1072     EXPECT_EQ(ret, ERR_DH_FWK_LOADER_HANDLER_IS_NULL);
1073 }
1074 
1075 HWTEST_F(ComponentLoaderTest, IsDHTypeSupport_001, TestSize.Level0)
1076 {
1077     auto ret = ComponentLoader::GetInstance().IsDHTypeSupport(DHType::AUDIO);
1078     EXPECT_EQ(ret, false);
1079 }
1080 } // namespace DistributedHardware
1081 } // namespace OHOS
1082