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 <gtest/gtest.h>
17
18 #include "utils.h"
19
20 #define private public
21 #define protected public
22 #include "dp_device_manager.h"
23 #undef private
24 #undef protected
25
26 namespace OHOS {
27 namespace DeviceProfile {
28 using namespace testing;
29 using namespace testing::ext;
30
31 class ProfileDmTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void ProfileDmTest::SetUpTestCase()
40 {
41 DTEST_LOG << "SetUpTestCase" << std::endl;
42 }
43
TearDownTestCase()44 void ProfileDmTest::TearDownTestCase()
45 {
46 DTEST_LOG << "TearDownTestCase" << std::endl;
47 }
48
SetUp()49 void ProfileDmTest::SetUp()
50 {
51 DTEST_LOG << "SetUp" << std::endl;
52 }
53
TearDown()54 void ProfileDmTest::TearDown()
55 {
56 DTEST_LOG << "TearDown" << std::endl;
57 }
58
59 /**
60 * @tc.name: WaitForDnetworkReady_001
61 * @tc.desc: marshalling
62 * @tc.type: FUNC
63 * @tc.require: I4OH94
64 */
65 HWTEST_F(ProfileDmTest, WaitForDnetworkReady_001, TestSize.Level3)
66 {
67 bool res = DpDeviceManager::GetInstance().WaitForDnetworkReady();
68 EXPECT_EQ(true, res);
69 }
70
71 /**
72 * @tc.name: GetUdidByNetworkId_001
73 * @tc.desc: marshalling
74 * @tc.type: FUNC
75 * @tc.require: I4OH94
76 */
77 HWTEST_F(ProfileDmTest, GetUdidByNetworkId_001, TestSize.Level3)
78 {
79 std::string udid;
80 bool res = DpDeviceManager::GetInstance().GetUdidByNetworkId("", udid);
81 EXPECT_EQ(false, res);
82 }
83
84 /**
85 * @tc.name: GetUuidByNetworkId_001
86 * @tc.desc: marshalling
87 * @tc.type: FUNC
88 * @tc.require: I4OH94
89 */
90 HWTEST_F(ProfileDmTest, GetUuidByNetworkId_001, TestSize.Level3)
91 {
92 std::string uuid;
93 DpDeviceManager::GetInstance().AddLocalDeviceIds();
94 DpDeviceManager::GetInstance().RecoverDevicesIfNeeded();
95 bool res = DpDeviceManager::GetInstance().GetUuidByNetworkId("", uuid);
96 EXPECT_EQ(false, res);
97 }
98
99 /**
100 * @tc.name: TransformDeviceId
101 * @tc.desc: marshalling
102 * @tc.type: FUNC
103 * @tc.require: I4OH94
104 */
105 HWTEST_F(ProfileDmTest, TransformDeviceId_001, TestSize.Level3)
106 {
107 std::string queryUdid;
108 std::string udid;
109 DpDeviceManager::GetInstance().RemoveDeviceIds("");
110 DpDeviceManager::GetInstance().GetLocalDeviceUdid(udid);
111 DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid("");
112 DpDeviceManager::GetInstance().RemoveExpiredDeviceIds("");
113 bool res = DpDeviceManager::GetInstance().TransformDeviceId("", queryUdid, DeviceIdType::UUID);
114 EXPECT_EQ(false, res);
115 }
116
117 /**
118 * @tc.name: Init_001
119 * @tc.desc: set service profile json
120 * @tc.type: FUNC
121 * @tc.require: I4OH94
122 */
123 HWTEST_F(ProfileDmTest, Init_001, TestSize.Level3)
124 {
125 bool res = DpDeviceManager::GetInstance().Init();
126 EXPECT_EQ(true, res);
127 }
128
129 /**
130 * @tc.name: WaitForDnetworkReady_002
131 * @tc.desc: marshalling
132 * @tc.type: FUNC
133 * @tc.require: I4OH94
134 */
135 HWTEST_F(ProfileDmTest, WaitForDnetworkReady_002, TestSize.Level3)
136 {
137 bool res = DpDeviceManager::GetInstance().WaitForDnetworkReady();
138 EXPECT_EQ(true, res);
139 }
140
141 /**
142 * @tc.name: ConnectDeviceManager_001
143 * @tc.desc: marshalling
144 * @tc.type: FUNC
145 * @tc.require: I4OH94
146 */
147 HWTEST_F(ProfileDmTest, ConnectDeviceManager_001, TestSize.Level3)
148 {
149 bool res = DpDeviceManager::GetInstance().ConnectDeviceManager();
150 EXPECT_EQ(true, res);
151 }
152
153 /**
154 * @tc.name: GetUdidByNetworkId_002
155 * @tc.desc: marshalling
156 * @tc.type: FUNC
157 * @tc.require: I4OH94
158 */
159 HWTEST_F(ProfileDmTest, GetUdidByNetworkId_002, TestSize.Level3)
160 {
161 auto dpDeviceInfo = std::make_shared<DeviceInfo>(
162 "12345678", "12345678", 0x00);
163 DpDeviceManager::GetInstance().OnNodeOnline(dpDeviceInfo);
164 std::string udid;
165 bool res = DpDeviceManager::GetInstance().GetUdidByNetworkId("", udid);
166 EXPECT_EQ(false, res);
167 }
168
169 /**
170 * @tc.name: GetUuidByNetworkId_002
171 * @tc.desc: marshalling
172 * @tc.type: FUNC
173 * @tc.require: I4OH94
174 */
175 HWTEST_F(ProfileDmTest, GetUuidByNetworkId_002, TestSize.Level3)
176 {
177 std::string uuid;
178 DpDeviceManager::GetInstance().OnNodeOffline("");
179 DpDeviceManager::GetInstance().AddLocalDeviceIds();
180 DpDeviceManager::GetInstance().RecoverDevicesIfNeeded();
181 bool res = DpDeviceManager::GetInstance().GetUuidByNetworkId("", uuid);
182 EXPECT_EQ(false, res);
183 }
184
185 /**
186 * @tc.name: TransformDeviceId_002
187 * @tc.desc: marshalling
188 * @tc.type: FUNC
189 * @tc.require: I4OH94
190 */
191 HWTEST_F(ProfileDmTest, TransformDeviceId_002, TestSize.Level3)
192 {
193 std::string queryUdid;
194 std::string udid;
195 DpDeviceManager::GetInstance().RemoveDeviceIds("");
196 DpDeviceManager::GetInstance().GetLocalDeviceUdid(udid);
197 DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid("");
198 DpDeviceManager::GetInstance().RemoveExpiredDeviceIds("");
199 std::list<std::string> deviceIdList;
200 deviceIdList.emplace_back("testttt");
201 DpDeviceManager::GetInstance().GetDeviceIdList(deviceIdList);
202 std::shared_ptr<DeviceInfo> device;
203 std::list<std::shared_ptr<DeviceInfo>> deviceList;
204 DpDeviceManager::GetInstance().GetDeviceList(deviceList);
205 bool res = DpDeviceManager::GetInstance().TransformDeviceId("", queryUdid, DeviceIdType::UUID);
206 EXPECT_EQ(false, res);
207 }
208
209 /**
210 * @tc.name: DisconnectDeviceManager_001
211 * @tc.desc: marshalling
212 * @tc.type: FUNC
213 * @tc.require: I4OH94
214 */
215 HWTEST_F(ProfileDmTest, DisconnectDeviceManager_001, TestSize.Level3)
216 {
217 std::string queryUdid;
218 std::string udid;
219 std::list<std::string> deviceIdList;
220 std::map<std::string, std::shared_ptr<DeviceInfo>> remoteDeviceInfoMap_;
221 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>("test", "test", 1);
222 DpDeviceManager::GetInstance().remoteDeviceInfoMap_["testttt"] = deviceInfo;
223 deviceIdList.emplace_back("testttt");
224 DpDeviceManager::GetInstance().GetDeviceIdList(deviceIdList);
225 std::shared_ptr<DeviceInfo> device;
226 std::list<std::shared_ptr<DeviceInfo>> deviceList;
227 DpDeviceManager::GetInstance().GetDeviceList(deviceList);
228 bool res = DpDeviceManager::GetInstance().DisconnectDeviceManager();
229 EXPECT_EQ(true, res);
230 }
231 }
232 }