1 /*
2 * Copyright (c) 2021 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 #define private public
18 #include "component_loader.h"
19 #undef private
20 #include "versionmanager/version_manager.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 namespace {
27 std::map<DHType, CompHandler> g_compHandlerMap;
28 }
29
SetUpTestCase(void)30 void ComponentLoaderTest::SetUpTestCase(void) {}
31
TearDownTestCase(void)32 void ComponentLoaderTest::TearDownTestCase(void) {}
33
SetUp()34 void ComponentLoaderTest::SetUp()
35 {
36 ComponentLoader::GetInstance().Init();
37 g_compHandlerMap = ComponentLoader::GetInstance().compHandlerMap_;
38 }
39
TearDown()40 void ComponentLoaderTest::TearDown()
41 {
42 ComponentLoader::GetInstance().UnInit();
43 g_compHandlerMap.clear();
44 }
45
46 /**
47 * @tc.name: component_loader_test_001
48 * @tc.desc: Verify the GetLocalDHVersion function.
49 * @tc.type: FUNC
50 * @tc.require: AR000GHSK3
51 */
52 HWTEST_F(ComponentLoaderTest, component_loader_test_001, TestSize.Level0)
53 {
54 DHVersion dhVersion;
55 auto ret = ComponentLoader::GetInstance().GetLocalDHVersion(dhVersion);
56 EXPECT_EQ(DH_FWK_SUCCESS, ret);
57 }
58
59 /**
60 * @tc.name: component_loader_test_002
61 * @tc.desc: Verify the GetHardwareHandler function.
62 * @tc.type: FUNC
63 * @tc.require: AR000GHSK3
64 */
65 HWTEST_F(ComponentLoaderTest, component_loader_test_002, TestSize.Level0)
66 {
67 for (const auto &iter : g_compHandlerMap) {
68 IHardwareHandler *hardwareHandlerPtr = nullptr;
69 auto ret = ComponentLoader::GetInstance().GetHardwareHandler(iter.first, hardwareHandlerPtr);
70 EXPECT_EQ(DH_FWK_SUCCESS, ret);
71 EXPECT_TRUE(hardwareHandlerPtr != nullptr);
72 }
73 }
74
75 /**
76 * @tc.name: component_loader_test_004
77 * @tc.desc: Verify the GetSource function.
78 * @tc.type: FUNC
79 * @tc.require: AR000GHSK3
80 */
81 HWTEST_F(ComponentLoaderTest, component_loader_test_003, TestSize.Level0)
82 {
83 for (const auto &iter : g_compHandlerMap) {
84 IDistributedHardwareSource *sourcePtr = nullptr;
85 auto ret = ComponentLoader::GetInstance().GetSource(iter.first, sourcePtr);
86 EXPECT_EQ(DH_FWK_SUCCESS, ret);
87 EXPECT_TRUE(sourcePtr != nullptr);
88 }
89 }
90
91 /**
92 * @tc.name: component_loader_test_005
93 * @tc.desc: Verify the GetSink function.
94 * @tc.type: FUNC
95 * @tc.require: AR000GHSK3
96 */
97 HWTEST_F(ComponentLoaderTest, component_loader_test_004, TestSize.Level0)
98 {
99 for (const auto &iter : g_compHandlerMap) {
100 IDistributedHardwareSink *sinkPtr = nullptr;
101 auto ret = ComponentLoader::GetInstance().GetSink(iter.first, sinkPtr);
102 EXPECT_EQ(DH_FWK_SUCCESS, ret);
103 EXPECT_TRUE(sinkPtr != nullptr);
104 }
105 }
106
107 /**
108 * @tc.name: component_loader_test_006
109 * @tc.desc: Verify the ReleaseHardwareHandler function.
110 * @tc.type: FUNC
111 * @tc.require: AR000GHSK3
112 */
113 HWTEST_F(ComponentLoaderTest, component_loader_test_005, TestSize.Level0)
114 {
115 for (const auto &iter : g_compHandlerMap) {
116 auto ret = ComponentLoader::GetInstance().ReleaseHardwareHandler(iter.first);
117 EXPECT_EQ(DH_FWK_SUCCESS, ret);
118 EXPECT_TRUE(ComponentLoader::GetInstance().compHandlerMap_[iter.first].hardwareHandler == nullptr);
119 }
120 }
121
122 /**
123 * @tc.name: component_loader_test_007
124 * @tc.desc: Verify the ReleaseSource function.
125 * @tc.type: FUNC
126 * @tc.require: AR000GHSK3
127 */
128 HWTEST_F(ComponentLoaderTest, component_loader_test_006, TestSize.Level0)
129 {
130 for (const auto &iter : g_compHandlerMap) {
131 auto ret = ComponentLoader::GetInstance().ReleaseSource(iter.first);
132 EXPECT_EQ(DH_FWK_SUCCESS, ret);
133 EXPECT_TRUE(ComponentLoader::GetInstance().compHandlerMap_[iter.first].sourceHandler == nullptr);
134 }
135 }
136
137 /**
138 * @tc.name: component_loader_test_008
139 * @tc.desc: Verify the ReleaseSink function.
140 * @tc.type: FUNC
141 * @tc.require: AR000GHSK3
142 */
143 HWTEST_F(ComponentLoaderTest, component_loader_test_007, TestSize.Level0)
144 {
145 for (const auto &iter : g_compHandlerMap) {
146 auto ret = ComponentLoader::GetInstance().ReleaseSink(iter.first);
147 EXPECT_EQ(DH_FWK_SUCCESS, ret);
148 EXPECT_TRUE(ComponentLoader::GetInstance().compHandlerMap_[iter.first].sinkHandler == nullptr);
149 }
150 }
151 }
152 }
153