1 /*
2 * Copyright (c) 2024 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 <mutex>
19 #include <memory>
20 #include <algorithm>
21 #include <dlfcn.h>
22 #include <vector>
23 #include <list>
24
25 #include "kv_adapter.h"
26 #include "profile_cache.h"
27 #include "profile_control_utils.h"
28 #include "content_sensor_manager_utils.h"
29 #include "device_manager.h"
30 #include "distributed_device_profile_errors.h"
31 #include "distributed_device_profile_enums.h"
32 #include "distributed_device_profile_log.h"
33 #include "listener/kv_data_change_listener.h"
34 #include "listener/kv_sync_completed_listener.h"
35 #include "listener/kv_store_death_recipient.h"
36 #include "switch_adapter.h"
37 #include "trusted_device_info.h"
38
39
40 namespace OHOS {
41 namespace DistributedDeviceProfile {
42 using namespace testing;
43 using namespace testing::ext;
44 using namespace std;
45
46 namespace {
47 const std::string TAG = "ProfileControlUtilsTest";
48 const std::string APP_ID = "distributed_device_profile_service";
49 const std::string STORE_ID = "dp_kv_store";
50 }
51
52 class ProfileControlUtilsTest : public testing::Test {
53 public:
54 static void SetUpTestCase();
55 static void TearDownTestCase();
56 void SetUp();
57 void TearDown();
58 };
59
SetUpTestCase()60 void ProfileControlUtilsTest::SetUpTestCase() {
61 }
62
TearDownTestCase()63 void ProfileControlUtilsTest::TearDownTestCase() {
64 }
65
SetUp()66 void ProfileControlUtilsTest::SetUp() {
67 }
68
TearDown()69 void ProfileControlUtilsTest::TearDown() {
70 }
71
72 /**
73 * @tc.name: PutDeviceProfile001
74 * @tc.desc: PutDeviceProfile
75 * @tc.type: FUNC
76 * @tc.require:
77 */
78 HWTEST_F(ProfileControlUtilsTest, PutDeviceProfile001, TestSize.Level1)
79 {
80 std::shared_ptr<IKVAdapter> kvStore = nullptr;
81 DeviceProfile deviceProfile;
82 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
83 int32_t ret = profileControlUtils->PutDeviceProfile(kvStore, deviceProfile);
84 EXPECT_EQ(ret, DP_INVALID_PARAMS);
85 }
86
87 /**
88 * @tc.name: PutDeviceProfile002
89 * @tc.desc: PutDeviceProfile
90 * @tc.type: FUNC
91 * @tc.require:
92 */
93 HWTEST_F(ProfileControlUtilsTest, PutDeviceProfile002, TestSize.Level1)
94 {
95 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
96 std::make_shared<KvDataChangeListener>(STORE_ID),
97 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
98 DistributedKv::TYPE_DYNAMICAL);
99 DeviceProfile deviceProfile;
100 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
101 int32_t ret = profileControlUtils->PutDeviceProfile(kvStore, deviceProfile);
102 EXPECT_EQ(ret, DP_INVALID_PARAMS);
103 }
104
105 /**
106 * @tc.name: PutDeviceProfile003
107 * @tc.desc: PutDeviceProfile
108 * @tc.type: FUNC
109 * @tc.require:
110 */
111 HWTEST_F(ProfileControlUtilsTest, PutDeviceProfile003, TestSize.Level1)
112 {
113 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
114 std::make_shared<KvDataChangeListener>(STORE_ID),
115 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
116 DistributedKv::TYPE_DYNAMICAL);
117 DeviceProfile deviceProfile;
118 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
119 deviceProfile.SetDeviceId("deviceId");
120 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
121 int32_t ret = profileControlUtils->PutDeviceProfile(kvStore, deviceProfile);
122 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
123 }
124
125 /**
126 * @tc.name: PutDeviceProfile004
127 * @tc.desc: PutDeviceProfile
128 * @tc.type: FUNC
129 * @tc.require:
130 */
131 HWTEST_F(ProfileControlUtilsTest, PutDeviceProfile004, TestSize.Level1)
132 {
133 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
134 std::make_shared<KvDataChangeListener>(STORE_ID),
135 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
136 DistributedKv::TYPE_DYNAMICAL);
137 DeviceProfile deviceProfile1;
138 ContentSensorManagerUtils::GetInstance().localUdid_ = "anything1";
139 deviceProfile1.SetDeviceId("anything1");
140 deviceProfile1.SetDeviceName("anything");
141 deviceProfile1.SetManufactureName("anything");
142 deviceProfile1.SetDeviceModel("anything");
143 deviceProfile1.SetStorageCapability(1);
144 deviceProfile1.SetOsSysCap("anything");
145 deviceProfile1.SetOsApiLevel(1);
146 deviceProfile1.SetOsVersion("anything");
147 deviceProfile1.SetOsType(1);
148 ProfileCache::GetInstance().AddDeviceProfile(deviceProfile1);
149 ProfileCache::GetInstance().IsDeviceProfileExist(deviceProfile1);
150 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
151 int32_t ret = profileControlUtils->PutDeviceProfile(kvStore, deviceProfile1);
152 EXPECT_EQ(ret, DP_CACHE_EXIST);
153 }
154
155 /**
156 * @tc.name: PutServiceProfile001
157 * @tc.desc: PutServiceProfile
158 * @tc.type: FUNC
159 * @tc.require:
160 */
161 HWTEST_F(ProfileControlUtilsTest, PutServiceProfile001, TestSize.Level1)
162 {
163 std::shared_ptr<IKVAdapter> kvStore = nullptr;
164 ServiceProfile serviceProfile;
165 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
166 int32_t ret = profileControlUtils->PutServiceProfile(kvStore, serviceProfile);
167 EXPECT_EQ(ret, DP_INVALID_PARAMS);
168 }
169
170 /**
171 * @tc.name: PutServiceProfile002
172 * @tc.desc: PutServiceProfile
173 * @tc.type: FUNC
174 * @tc.require:
175 */
176 HWTEST_F(ProfileControlUtilsTest, PutServiceProfile002, TestSize.Level1)
177 {
178 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
179 std::make_shared<KvDataChangeListener>(STORE_ID),
180 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
181 DistributedKv::TYPE_DYNAMICAL);
182 ServiceProfile serviceProfile;
183 serviceProfile.SetDeviceId("deviceId");
184 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
185 int32_t ret = profileControlUtils->PutServiceProfile(kvStore, serviceProfile);
186 EXPECT_EQ(ret, DP_INVALID_PARAMS);
187 }
188
189 /**
190 * @tc.name: PutServiceProfile003
191 * @tc.desc: PutServiceProfile
192 * @tc.type: FUNC
193 * @tc.require:
194 */
195 HWTEST_F(ProfileControlUtilsTest, PutServiceProfile003, TestSize.Level1)
196 {
197 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
198 std::make_shared<KvDataChangeListener>(STORE_ID),
199 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
200 DistributedKv::TYPE_DYNAMICAL);
201 ServiceProfile serviceProfile;
202 serviceProfile.SetServiceName("ServiceName");
203 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
204 int32_t ret = profileControlUtils->PutServiceProfile(kvStore, serviceProfile);
205 EXPECT_EQ(ret, DP_INVALID_PARAMS);
206 }
207
208 /**
209 * @tc.name: PutServiceProfile004
210 * @tc.desc: PutServiceProfile
211 * @tc.type: FUNC
212 * @tc.require:
213 */
214 HWTEST_F(ProfileControlUtilsTest, PutServiceProfile004, TestSize.Level1)
215 {
216 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
217 std::make_shared<KvDataChangeListener>(STORE_ID),
218 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
219 DistributedKv::TYPE_DYNAMICAL);
220 ServiceProfile serviceProfile;
221 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
222 serviceProfile.SetDeviceId("deviceId");
223 serviceProfile.SetServiceName("ServiceName");
224 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
225 int32_t ret = profileControlUtils->PutServiceProfile(kvStore, serviceProfile);
226 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
227 }
228
229 /**
230 * @tc.name: PutServiceProfile005
231 * @tc.desc: PutServiceProfile
232 * @tc.type: FUNC
233 * @tc.require:
234 */
235 HWTEST_F(ProfileControlUtilsTest, PutServiceProfile005, TestSize.Level1)
236 {
237 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
238 std::make_shared<KvDataChangeListener>(STORE_ID),
239 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
240 DistributedKv::TYPE_DYNAMICAL);
241 ServiceProfile serviceProfile1;
242 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId1";
243 serviceProfile1.SetDeviceId("deviceId1");
244 serviceProfile1.SetServiceName("serviceName1");
245 serviceProfile1.SetServiceType("serviceType1");
246 ProfileCache::GetInstance().AddServiceProfile(serviceProfile1);
247 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
248 int32_t ret = profileControlUtils->PutServiceProfile(kvStore, serviceProfile1);
249 EXPECT_EQ(ret, DP_CACHE_EXIST);
250 }
251
252 /**
253 * @tc.name: PutServiceProfileBatch001
254 * @tc.desc: PutServiceProfileBatch
255 * @tc.type: FUNC
256 * @tc.require:
257 */
258 HWTEST_F(ProfileControlUtilsTest, PutServiceProfileBatch001, TestSize.Level1)
259 {
260 std::shared_ptr<IKVAdapter> kvStore = nullptr;
261 ServiceProfile serviceProfile;
262 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
263 int32_t ret = profileControlUtils->PutServiceProfile(kvStore, serviceProfile);
264 EXPECT_EQ(ret, DP_INVALID_PARAMS);
265 }
266
267 /**
268 * @tc.name: PutCharacteristicProfile001
269 * @tc.desc: PutCharacteristicProfile
270 * @tc.type: FUNC
271 * @tc.require:
272 */
273 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile001, TestSize.Level1)
274 {
275 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
276 std::make_shared<KvDataChangeListener>(STORE_ID),
277 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
278 DistributedKv::TYPE_DYNAMICAL);
279 CharacteristicProfile charProfile;
280 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
281 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
282 EXPECT_EQ(ret, DP_INVALID_PARAMS);
283 }
284
285 /**
286 * @tc.name: PutCharacteristicProfile002
287 * @tc.desc: PutCharacteristicProfile
288 * @tc.type: FUNC
289 * @tc.require:
290 */
291 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile002, TestSize.Level1)
292 {
293 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
294 std::make_shared<KvDataChangeListener>(STORE_ID),
295 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
296 DistributedKv::TYPE_DYNAMICAL);
297 CharacteristicProfile charProfile;
298 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
299 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
300 EXPECT_EQ(ret, DP_INVALID_PARAMS);
301 }
302
303 /**
304 * @tc.name: PutCharacteristicProfile003
305 * @tc.desc: PutCharacteristicProfile
306 * @tc.type: FUNC
307 * @tc.require:
308 */
309 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile003, TestSize.Level1)
310 {
311 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
312 std::make_shared<KvDataChangeListener>(STORE_ID),
313 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
314 DistributedKv::TYPE_DYNAMICAL);
315 CharacteristicProfile charProfile;
316 charProfile.SetServiceName("ServiceName");
317 charProfile.SetCharacteristicKey("CharacteristicKey");
318 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
319 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
320 EXPECT_EQ(ret, DP_INVALID_PARAMS);
321 }
322
323 /**
324 * @tc.name: PutCharacteristicProfile004
325 * @tc.desc: PutCharacteristicProfile
326 * @tc.type: FUNC
327 * @tc.require:
328 */
329 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile004, TestSize.Level1)
330 {
331 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
332 std::make_shared<KvDataChangeListener>(STORE_ID),
333 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
334 DistributedKv::TYPE_DYNAMICAL);
335 CharacteristicProfile charProfile;
336 charProfile.SetDeviceId("DeviceId");
337 charProfile.SetCharacteristicKey("CharacteristicKey");
338 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
339 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
340 EXPECT_EQ(ret, DP_INVALID_PARAMS);
341 }
342
343 /**
344 * @tc.name: PutCharacteristicProfile005
345 * @tc.desc: PutCharacteristicProfile
346 * @tc.type: FUNC
347 * @tc.require:
348 */
349 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile005, TestSize.Level1)
350 {
351 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
352 std::make_shared<KvDataChangeListener>(STORE_ID),
353 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
354 DistributedKv::TYPE_DYNAMICAL);
355 CharacteristicProfile charProfile;
356 charProfile.SetDeviceId("DeviceId");
357 charProfile.SetServiceName("ServiceName");
358 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
359 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
360 EXPECT_EQ(ret, DP_INVALID_PARAMS);
361 }
362
363 /**
364 * @tc.name: PutCharacteristicProfile006
365 * @tc.desc: PutCharacteristicProfile
366 * @tc.type: FUNC
367 * @tc.require:
368 */
369 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile006, TestSize.Level1)
370 {
371 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
372 std::make_shared<KvDataChangeListener>(STORE_ID),
373 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
374 DistributedKv::TYPE_DYNAMICAL);
375 CharacteristicProfile charProfile;
376 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
377 charProfile.SetDeviceId("DeviceId");
378 charProfile.SetServiceName("ServiceName");
379 charProfile.SetCharacteristicKey("CharacteristicKey");
380 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
381 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
382 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
383 }
384
385 /**
386 * @tc.name: PutCharacteristicProfile007
387 * @tc.desc: PutCharacteristicProfile
388 * @tc.type: FUNC
389 * @tc.require:
390 */
391 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfile007, TestSize.Level1)
392 {
393 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
394 std::make_shared<KvDataChangeListener>(STORE_ID),
395 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
396 DistributedKv::TYPE_DYNAMICAL);
397 CharacteristicProfile charProfile;
398 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
399 charProfile.SetDeviceId("DeviceId");
400 charProfile.SetServiceName("ServiceName");
401 charProfile.SetCharacteristicKey("CharacteristicKey");
402 ProfileCache::GetInstance().AddCharProfile(charProfile);
403 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
404 int32_t ret = profileControlUtils->PutCharacteristicProfile(kvStore, charProfile);
405 EXPECT_EQ(ret, DP_CACHE_EXIST);
406 }
407
408 /**
409 * @tc.name: PutSwitchCharacteristicProfile001
410 * @tc.desc: PutSwitchCharacteristicProfile
411 * @tc.type: FUNC
412 * @tc.require:
413 */
414 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile001, TestSize.Level1)
415 {
416 std::string appId;
417 CharacteristicProfile charProfile;
418 charProfile.SetServiceName("ServiceName");
419 charProfile.SetCharacteristicKey("CharacteristicKey");
420 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
421 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
422 EXPECT_EQ(ret, DP_INVALID_PARAMS);
423 }
424
425 /**
426 * @tc.name: PutSwitchCharacteristicProfile002
427 * @tc.desc: PutSwitchCharacteristicProfile
428 * @tc.type: FUNC
429 * @tc.require:
430 */
431 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile002, TestSize.Level1)
432 {
433 std::string appId;
434 CharacteristicProfile charProfile;
435 charProfile.SetDeviceId("DeviceId");
436 charProfile.SetCharacteristicKey("CharacteristicKey");
437 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
438 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
439 EXPECT_EQ(ret, DP_INVALID_PARAMS);
440 }
441
442 /**
443 * @tc.name: PutSwitchCharacteristicProfile003
444 * @tc.desc: PutSwitchCharacteristicProfile
445 * @tc.type: FUNC
446 * @tc.require:
447 */
448 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile003, TestSize.Level1)
449 {
450 std::string appId;
451 CharacteristicProfile charProfile;
452 charProfile.SetDeviceId("DeviceId");
453 charProfile.SetServiceName("ServiceName");
454 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
455 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
456 EXPECT_EQ(ret, DP_INVALID_PARAMS);
457 }
458
459 /**
460 * @tc.name: PutSwitchCharacteristicProfile004
461 * @tc.desc: PutSwitchCharacteristicProfile
462 * @tc.type: FUNC
463 * @tc.require:
464 */
465 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile004, TestSize.Level1)
466 {
467 std::string appId;
468 CharacteristicProfile charProfile;
469 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
470 charProfile.SetDeviceId("DeviceId");
471 charProfile.SetServiceName("ServiceName");
472 charProfile.SetCharacteristicKey("CharacteristicKey");
473 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
474 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
475 EXPECT_EQ(ret, DP_CACHE_EXIST);
476 }
477
478 /**
479 * @tc.name: PutSwitchCharacteristicProfile005
480 * @tc.desc: PutSwitchCharacteristicProfile
481 * @tc.type: FUNC
482 * @tc.require:
483 */
484 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile005, TestSize.Level1)
485 {
486 std::string appId;
487 CharacteristicProfile charProfile;
488 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
489 charProfile.SetDeviceId("DeviceId");
490 charProfile.SetServiceName("ServiceName");
491 charProfile.SetCharacteristicKey("CharacteristicKey");
492 ProfileCache::GetInstance().AddCharProfile(charProfile);
493 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
494 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
495 EXPECT_EQ(ret, DP_CACHE_EXIST);
496 }
497
498 /**
499 * @tc.name: PutSwitchCharacteristicProfile006
500 * @tc.desc: PutSwitchCharacteristicProfile
501 * @tc.type: FUNC
502 * @tc.require:
503 */
504 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile006, TestSize.Level1)
505 {
506 std::string appId;
507 CharacteristicProfile charProfile;
508 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
509 charProfile.SetDeviceId("DeviceId");
510 charProfile.SetServiceName("deviceStatus");
511 charProfile.SetCharacteristicKey(SWITCH_STATUS);
512 charProfile.SetCharacteristicValue("1");
513
514 ProfileCache::GetInstance().AddCharProfile(charProfile);
515 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
516 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
517 EXPECT_EQ(ret, DP_CACHE_EXIST);
518 }
519
520 /**
521 * @tc.name: PutSwitchCharacteristicProfile007
522 * @tc.desc: PutSwitchCharacteristicProfile
523 * @tc.type: FUNC
524 * @tc.require:
525 */
526 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfile007, TestSize.Level1)
527 {
528 std::string appId = "appId";
529 CharacteristicProfile charProfile;
530 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
531 charProfile.SetDeviceId("DeviceId");
532 charProfile.SetServiceName("deviceStatus");
533 charProfile.SetCharacteristicKey(SWITCH_STATUS);
534 charProfile.SetCharacteristicValue("1");
535
536 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
537 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfile(appId, charProfile);
538 EXPECT_EQ(ret, DP_CACHE_EXIST);
539 }
540
541 /**
542 * @tc.name: PutSwitchCharacteristicProfileBatch001
543 * @tc.desc: PutSwitchCharacteristicProfileBatch
544 * @tc.type: FUNC
545 * @tc.require:
546 */
547 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch001, TestSize.Level1)
548 {
549 std::string appId = "appId";
550 std::vector<CharacteristicProfile> charProfiles;
551
552 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
553 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
554 EXPECT_EQ(ret, DP_INVALID_PARAMS);
555 }
556
557 /**
558 * @tc.name: PutSwitchCharacteristicProfileBatch002
559 * @tc.desc: PutSwitchCharacteristicProfileBatch
560 * @tc.type: FUNC
561 * @tc.require:
562 */
563 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch002, TestSize.Level1)
564 {
565 std::string appId = "appId";
566 std::vector<CharacteristicProfile> charProfiles;
567
568 CharacteristicProfile charProfile;
569 charProfile.SetCharacteristicKey(SWITCH_STATUS);
570 charProfile.SetCharacteristicValue("1");
571 charProfiles.push_back(charProfile);
572 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
573 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
574 EXPECT_EQ(ret, DP_INVALID_PARAMS);
575 }
576
577 /**
578 * @tc.name: PutSwitchCharacteristicProfileBatch003
579 * @tc.desc: PutSwitchCharacteristicProfileBatch
580 * @tc.type: FUNC
581 * @tc.require:
582 */
583 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch003, TestSize.Level1)
584 {
585 std::string appId = "appId";
586 std::vector<CharacteristicProfile> charProfiles;
587
588 CharacteristicProfile charProfile;
589 charProfile.SetDeviceId("DeviceId");
590 charProfile.SetCharacteristicValue("1");
591 charProfiles.push_back(charProfile);
592 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
593 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
594 EXPECT_EQ(ret, DP_INVALID_PARAMS);
595 }
596
597 /**
598 * @tc.name: PutSwitchCharacteristicProfileBatch004
599 * @tc.desc: PutSwitchCharacteristicProfileBatch
600 * @tc.type: FUNC
601 * @tc.require:
602 */
603 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch004, TestSize.Level1)
604 {
605 std::string appId = "appId";
606 std::vector<CharacteristicProfile> charProfiles;
607
608 CharacteristicProfile charProfile;
609 charProfile.SetDeviceId("DeviceId");
610 charProfile.SetServiceName("deviceStatus");
611 charProfiles.push_back(charProfile);
612 charProfiles.push_back(charProfile);
613 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
614 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
615 EXPECT_EQ(ret, DP_INVALID_PARAMS);
616 }
617
618 /**
619 * @tc.name: PutSwitchCharacteristicProfileBatch005
620 * @tc.desc: PutSwitchCharacteristicProfileBatch
621 * @tc.type: FUNC
622 * @tc.require:
623 */
624 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch005, TestSize.Level1)
625 {
626 std::string appId = "appId";
627 std::vector<CharacteristicProfile> charProfiles;
628
629 CharacteristicProfile charProfile;
630 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
631 charProfile.SetDeviceId("DeviceId");
632 charProfile.SetServiceName("deviceStatus");
633 charProfile.SetCharacteristicKey(SWITCH_STATUS);
634 charProfile.SetCharacteristicValue("1");
635
636 charProfiles.push_back(charProfile);
637 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
638 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
639 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
640 }
641
642 /**
643 * @tc.name: PutSwitchCharacteristicProfileBatch006
644 * @tc.desc: PutSwitchCharacteristicProfileBatch
645 * @tc.type: FUNC
646 * @tc.require:
647 */
648 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch006, TestSize.Level1)
649 {
650 std::string appId = "appId";
651 std::vector<CharacteristicProfile> charProfiles;
652
653 CharacteristicProfile charProfile;
654 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
655 charProfile.SetDeviceId("DeviceId");
656 charProfile.SetServiceName("deviceStatus");
657 charProfile.SetCharacteristicKey("key");
658 charProfile.SetCharacteristicValue("1");
659
660 ProfileCache::GetInstance().AddCharProfile(charProfile);
661
662 charProfiles.push_back(charProfile);
663 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
664 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
665 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
666 }
667
668 /**
669 * @tc.name: PutSwitchCharacteristicProfileBatch007
670 * @tc.desc: PutSwitchCharacteristicProfileBatch
671 * @tc.type: FUNC
672 * @tc.require:
673 */
674 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch007, TestSize.Level1)
675 {
676 std::string appId = "appId";
677 std::vector<CharacteristicProfile> charProfiles;
678
679 CharacteristicProfile charProfile;
680 ContentSensorManagerUtils::GetInstance().localUdid_ = "DeviceId";
681 charProfile.SetDeviceId("DeviceId");
682 charProfile.SetServiceName("deviceStatus");
683 charProfile.SetCharacteristicKey(SWITCH_STATUS);
684 charProfile.SetCharacteristicValue("1");
685
686 ProfileCache::GetInstance().AddCharProfile(charProfile);
687 charProfiles.push_back(charProfile);
688 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
689 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
690 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
691 }
692
693 /**
694 * @tc.name: PutSwitchCharacteristicProfileBatch008
695 * @tc.desc: PutSwitchCharacteristicProfileBatch
696 * @tc.type: FUNC
697 * @tc.require:
698 */
699 HWTEST_F(ProfileControlUtilsTest, PutSwitchCharacteristicProfileBatch008, TestSize.Level1)
700 {
701 std::string appId = "";
702 std::vector<CharacteristicProfile> charProfiles;
703
704 CharacteristicProfile charProfile;
705 charProfile.SetDeviceId("DeviceId");
706 charProfile.SetServiceName("deviceStatus");
707 charProfile.SetCharacteristicKey(SWITCH_STATUS);
708 charProfile.SetCharacteristicValue("1");
709
710 ProfileCache::GetInstance().AddCharProfile(charProfile);
711
712 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
713 int32_t ret = profileControlUtils->PutSwitchCharacteristicProfileBatch(appId, charProfiles);
714 EXPECT_EQ(ret, DP_INVALID_PARAMS);
715 }
716
717 /**
718 * @tc.name: PutCharacteristicProfileBatch001
719 * @tc.desc: PutCharacteristicProfileBatch
720 * @tc.type: FUNC
721 * @tc.require:
722 */
723 HWTEST_F(ProfileControlUtilsTest, PutCharacteristicProfileBatch001, TestSize.Level1)
724 {
725 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
726 std::make_shared<KvDataChangeListener>(STORE_ID),
727 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
728 DistributedKv::TYPE_DYNAMICAL);
729 std::vector<CharacteristicProfile> charProfiles;
730
731 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
732 int32_t ret = profileControlUtils->PutCharacteristicProfileBatch(kvStore, charProfiles);
733 EXPECT_EQ(ret, DP_SUCCESS);
734 }
735
736 /**
737 * @tc.name: GetDeviceProfile001
738 * @tc.desc: GetDeviceProfile
739 * @tc.type: FUNC
740 * @tc.require:
741 */
742 HWTEST_F(ProfileControlUtilsTest, GetDeviceProfile001, TestSize.Level1)
743 {
744 std::shared_ptr<IKVAdapter> kvStore = nullptr;
745 DeviceProfile deviceProfile;
746 std::string deviceId;
747
748 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
749 int32_t ret = profileControlUtils->GetDeviceProfile(kvStore, deviceId, deviceProfile);
750 EXPECT_EQ(ret, DP_INVALID_PARAMS);
751 }
752
753 /**
754 * @tc.name: GetDeviceProfile002
755 * @tc.desc: GetDeviceProfile
756 * @tc.type: FUNC
757 * @tc.require:
758 */
759 HWTEST_F(ProfileControlUtilsTest, GetDeviceProfile002, TestSize.Level1)
760 {
761 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
762 std::make_shared<KvDataChangeListener>(STORE_ID),
763 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
764 DistributedKv::TYPE_DYNAMICAL);
765 DeviceProfile deviceProfile;
766 std::string deviceId;
767
768 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
769 int32_t ret = profileControlUtils->GetDeviceProfile(kvStore, deviceId, deviceProfile);
770 EXPECT_EQ(ret, DP_INVALID_PARAMS);
771 }
772
773 /**
774 * @tc.name: GetDeviceProfile003
775 * @tc.desc: GetDeviceProfile
776 * @tc.type: FUNC
777 * @tc.require:
778 */
779 HWTEST_F(ProfileControlUtilsTest, GetDeviceProfile003, TestSize.Level1)
780 {
781 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
782 std::make_shared<KvDataChangeListener>(STORE_ID),
783 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
784 DistributedKv::TYPE_DYNAMICAL);
785 DeviceProfile deviceProfile;
786 std::string deviceId = "deviceId";
787
788 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
789 int32_t ret = profileControlUtils->GetDeviceProfile(kvStore, deviceId, deviceProfile);
790 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
791 }
792
793 /**
794 * @tc.name: GetDeviceProfile004
795 * @tc.desc: GetDeviceProfile
796 * @tc.type: FUNC
797 * @tc.require:
798 */
799 HWTEST_F(ProfileControlUtilsTest, GetDeviceProfile004, TestSize.Level1)
800 {
801 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
802 std::make_shared<KvDataChangeListener>(STORE_ID),
803 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
804 DistributedKv::TYPE_DYNAMICAL);
805 DeviceProfile deviceProfile;
806 std::string deviceId = "deviceId";
807
808 ContentSensorManagerUtils::GetInstance().localUdid_ = deviceId;
809
810 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
811 int32_t ret = profileControlUtils->GetDeviceProfile(kvStore, deviceId, deviceProfile);
812 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
813 ContentSensorManagerUtils::GetInstance().localUdid_ = "";
814 }
815
816 /**
817 * @tc.name: GetServiceProfile001
818 * @tc.desc: GetServiceProfile
819 * @tc.type: FUNC
820 * @tc.require:
821 */
822 HWTEST_F(ProfileControlUtilsTest, GetServiceProfile001, TestSize.Level1)
823 {
824 std::shared_ptr<IKVAdapter> kvStore = nullptr;
825 std::string deviceId = "deviceId";
826 std::string serviceName;
827 ServiceProfile serviceProfile;
828
829 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
830 int32_t ret = profileControlUtils->GetServiceProfile(kvStore, deviceId, serviceName, serviceProfile);
831 EXPECT_EQ(ret, DP_INVALID_PARAMS);
832 }
833
834 /**
835 * @tc.name: GetServiceProfile002
836 * @tc.desc: GetServiceProfile
837 * @tc.type: FUNC
838 * @tc.require:
839 */
840 HWTEST_F(ProfileControlUtilsTest, GetServiceProfile002, TestSize.Level1)
841 {
842 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
843 std::make_shared<KvDataChangeListener>(STORE_ID),
844 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
845 DistributedKv::TYPE_DYNAMICAL);
846 std::string deviceId = "deviceId";
847 std::string serviceName;
848 ServiceProfile serviceProfile;
849
850 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
851 int32_t ret = profileControlUtils->GetServiceProfile(kvStore, deviceId, serviceName, serviceProfile);
852 EXPECT_EQ(ret, DP_INVALID_PARAMS);
853 }
854
855 /**
856 * @tc.name: GetServiceProfile003
857 * @tc.desc: GetServiceProfile
858 * @tc.type: FUNC
859 * @tc.require:
860 */
861 HWTEST_F(ProfileControlUtilsTest, GetServiceProfile003, TestSize.Level1)
862 {
863 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
864 std::make_shared<KvDataChangeListener>(STORE_ID),
865 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
866 DistributedKv::TYPE_DYNAMICAL);
867 std::string deviceId;
868 std::string serviceName = "serviceName";
869 ServiceProfile serviceProfile;
870
871 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
872 int32_t ret = profileControlUtils->GetServiceProfile(kvStore, deviceId, serviceName, serviceProfile);
873 EXPECT_EQ(ret, DP_INVALID_PARAMS);
874 }
875
876 /**
877 * @tc.name: GetServiceProfile004
878 * @tc.desc: GetServiceProfile
879 * @tc.type: FUNC
880 * @tc.require:
881 */
882 HWTEST_F(ProfileControlUtilsTest, GetServiceProfile004, TestSize.Level1)
883 {
884 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
885 std::make_shared<KvDataChangeListener>(STORE_ID),
886 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
887 DistributedKv::TYPE_DYNAMICAL);
888 std::string deviceId = "deviceId";
889 std::string serviceName = "serviceName";
890 ServiceProfile serviceProfile;
891
892 ContentSensorManagerUtils::GetInstance().localUdid_ = "";
893 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
894 int32_t ret = profileControlUtils->GetServiceProfile(kvStore, deviceId, serviceName, serviceProfile);
895 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
896 }
897
898 /**
899 * @tc.name: GetServiceProfile005
900 * @tc.desc: GetServiceProfile
901 * @tc.type: FUNC
902 * @tc.require:
903 */
904 HWTEST_F(ProfileControlUtilsTest, GetServiceProfile005, TestSize.Level1)
905 {
906 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
907 std::make_shared<KvDataChangeListener>(STORE_ID),
908 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
909 DistributedKv::TYPE_DYNAMICAL);
910
911 std::string peerNetworkId = "peerNetworkId";
912 TrustedDeviceInfo deviceInfo;
913 deviceInfo.SetNetworkId(peerNetworkId);
914 std::string deviceId = "deviceId";
915 deviceInfo.SetUdid(deviceId);
916 std::string serviceName = "serviceName";
917 ServiceProfile serviceProfile;
918
919 ProfileCache::GetInstance().onlineDevMap_[deviceId] = deviceInfo;
920 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
921 int32_t ret = profileControlUtils->GetServiceProfile(kvStore, deviceId, serviceName, serviceProfile);
922 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
923 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
924 }
925
926 /**
927 * @tc.name: GetServiceProfile006
928 * @tc.desc: GetServiceProfile
929 * @tc.type: FUNC
930 * @tc.require:
931 */
932 HWTEST_F(ProfileControlUtilsTest, GetServiceProfile006, TestSize.Level1)
933 {
934 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
935 std::make_shared<KvDataChangeListener>(STORE_ID),
936 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
937 DistributedKv::TYPE_DYNAMICAL);
938 std::string peerNetworkId = "peerNetworkId";
939 TrustedDeviceInfo deviceInfo;
940 deviceInfo.SetNetworkId(peerNetworkId);
941 std::string deviceId = "deviceId";
942 deviceInfo.SetUdid(deviceId);
943 std::string serviceName = "serviceName";
944 ServiceProfile serviceProfile;
945
946 ProfileCache::GetInstance().onlineDevMap_[deviceId] = deviceInfo;
947 std::string serviceProfileKey = SVR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName;
948 ProfileCache::GetInstance().serviceProfileMap_[serviceProfileKey] = serviceProfile;
949 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
950 int32_t ret = profileControlUtils->GetServiceProfile(kvStore, deviceId, serviceName, serviceProfile);
951 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
952 EXPECT_EQ(ret, DP_SUCCESS);
953 }
954
955 /**
956 * @tc.name: GetCharacteristicProfile001
957 * @tc.desc: GetCharacteristicProfile
958 * @tc.type: FUNC
959 * @tc.require:
960 */
961 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile001, TestSize.Level1)
962 {
963 std::shared_ptr<IKVAdapter> kvStore = nullptr;
964 std::string deviceId = "deviceId";
965 std::string serviceName = "serviceName";
966 std::string characteristicKey;
967 CharacteristicProfile charProfile;
968
969 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
970 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
971 characteristicKey, charProfile);
972 EXPECT_EQ(ret, DP_INVALID_PARAMS);
973 }
974
975 /**
976 * @tc.name: GetCharacteristicProfile002
977 * @tc.desc: GetCharacteristicProfile
978 * @tc.type: FUNC
979 * @tc.require:
980 */
981 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile002, TestSize.Level1)
982 {
983 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
984 std::make_shared<KvDataChangeListener>(STORE_ID),
985 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
986 DistributedKv::TYPE_DYNAMICAL);
987 std::string deviceId;
988 std::string serviceName = "serviceName";
989 std::string characteristicKey = "characteristicKey";
990 CharacteristicProfile charProfile;
991
992 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
993 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
994 characteristicKey, charProfile);
995 EXPECT_EQ(ret, DP_INVALID_PARAMS);
996 }
997
998 /**
999 * @tc.name: GetCharacteristicProfile003
1000 * @tc.desc: GetCharacteristicProfile
1001 * @tc.type: FUNC
1002 * @tc.require:
1003 */
1004 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile003, TestSize.Level1)
1005 {
1006 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
1007 std::make_shared<KvDataChangeListener>(STORE_ID),
1008 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
1009 DistributedKv::TYPE_DYNAMICAL);
1010 std::string deviceId = "deviceId";
1011 std::string serviceName = "serviceName";
1012 std::string characteristicKey;
1013 CharacteristicProfile charProfile;
1014
1015 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1016 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
1017 characteristicKey, charProfile);
1018 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1019 }
1020
1021 /**
1022 * @tc.name: GetCharacteristicProfile004
1023 * @tc.desc: GetCharacteristicProfile
1024 * @tc.type: FUNC
1025 * @tc.require:
1026 */
1027 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile004, TestSize.Level1)
1028 {
1029 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
1030 std::make_shared<KvDataChangeListener>(STORE_ID),
1031 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
1032 DistributedKv::TYPE_DYNAMICAL);
1033 std::string deviceId = "deviceId";
1034 std::string serviceName = "serviceName";
1035 std::string characteristicKey;
1036 CharacteristicProfile charProfile;
1037
1038 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1039 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
1040 characteristicKey, charProfile);
1041 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1042 }
1043
1044 /**
1045 * @tc.name: GetCharacteristicProfile005
1046 * @tc.desc: GetCharacteristicProfile
1047 * @tc.type: FUNC
1048 * @tc.require:
1049 */
1050 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile005, TestSize.Level1)
1051 {
1052 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
1053 std::make_shared<KvDataChangeListener>(STORE_ID),
1054 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
1055 DistributedKv::TYPE_DYNAMICAL);
1056 std::string peerNetworkId = "peerNetworkId";
1057 TrustedDeviceInfo deviceInfo;
1058 deviceInfo.SetNetworkId(peerNetworkId);
1059 std::string deviceId = "deviceId";
1060 deviceInfo.SetUdid(deviceId);
1061 std::string serviceName = "serviceName";
1062 std::string characteristicKey = "characteristicKey";
1063 CharacteristicProfile charProfile;
1064
1065 ContentSensorManagerUtils::GetInstance().localUdid_ = "";
1066 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
1067 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1068 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
1069 characteristicKey, charProfile);
1070 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
1071 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1072 }
1073
1074 /**
1075 * @tc.name: GetCharacteristicProfile006
1076 * @tc.desc: GetCharacteristicProfile
1077 * @tc.type: FUNC
1078 * @tc.require:
1079 */
1080 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile006, TestSize.Level1)
1081 {
1082 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
1083 std::make_shared<KvDataChangeListener>(STORE_ID),
1084 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
1085 DistributedKv::TYPE_DYNAMICAL);
1086 std::string peerNetworkId = "peerNetworkId";
1087 TrustedDeviceInfo deviceInfo;
1088 deviceInfo.SetNetworkId(peerNetworkId);
1089 std::string deviceId = "deviceId";
1090 deviceInfo.SetUdid(deviceId);
1091 std::string serviceName = "serviceName";
1092 std::string characteristicKey = "characteristicKey";
1093 CharacteristicProfile charProfile;
1094
1095 ProfileCache::GetInstance().onlineDevMap_[deviceId] = deviceInfo;
1096 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1097 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
1098 characteristicKey, charProfile);
1099 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
1100 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1101 }
1102
1103 /**
1104 * @tc.name: GetCharacteristicProfile007
1105 * @tc.desc: GetCharacteristicProfile
1106 * @tc.type: FUNC
1107 * @tc.require:
1108 */
1109 HWTEST_F(ProfileControlUtilsTest, GetCharacteristicProfile007, TestSize.Level1)
1110 {
1111 std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>(APP_ID, STORE_ID,
1112 std::make_shared<KvDataChangeListener>(STORE_ID),
1113 std::make_shared<KvSyncCompletedListener>(STORE_ID), std::make_shared<KvDeathRecipient>(STORE_ID),
1114 DistributedKv::TYPE_DYNAMICAL);
1115 std::string peerNetworkId = "peerNetworkId";
1116 TrustedDeviceInfo deviceInfo;
1117 deviceInfo.SetNetworkId(peerNetworkId);
1118 std::string deviceId = "deviceId";
1119 deviceInfo.SetUdid(deviceId);
1120 std::string serviceName = "serviceName";
1121 std::string characteristicKey = "characteristicKey";
1122 CharacteristicProfile charProfile;
1123
1124 ProfileCache::GetInstance().onlineDevMap_[deviceId] = deviceInfo;
1125 std::string charProfileKey =
1126 CHAR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName + SEPARATOR + characteristicKey;
1127 ProfileCache::GetInstance().charProfileMap_[charProfileKey] = charProfile;
1128 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1129 int32_t ret = profileControlUtils->GetCharacteristicProfile(kvStore, deviceId, serviceName,
1130 characteristicKey, charProfile);
1131 ProfileCache::GetInstance().charProfileMap_.erase(charProfileKey);
1132 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
1133 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1134 }
1135
1136 /**
1137 * @tc.name: RefreshLocalSwitchProfile001
1138 * @tc.desc: RefreshLocalSwitchProfile
1139 * @tc.type: FUNC
1140 * @tc.require:
1141 */
1142 HWTEST_F(ProfileControlUtilsTest, RefreshLocalSwitchProfile001, TestSize.Level1)
1143 {
1144 std::string appId = "appId";
1145 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1146 int32_t ret = profileControlUtils->RefreshLocalSwitchProfile(appId);
1147 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1148 }
1149
1150 /**
1151 * @tc.name: RefreshLocalSwitchProfile002
1152 * @tc.desc: RefreshLocalSwitchProfile
1153 * @tc.type: FUNC
1154 * @tc.require:
1155 */
1156 HWTEST_F(ProfileControlUtilsTest, RefreshLocalSwitchProfile002, TestSize.Level1)
1157 {
1158 std::string appId = "";
1159 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1160 ProfileCache::GetInstance().localNetworkId_ = "localNetwork";
1161 int32_t ret = profileControlUtils->RefreshLocalSwitchProfile(appId);
1162 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1163 }
1164
1165 /**
1166 * @tc.name: RefreshLocalSwitchProfile003
1167 * @tc.desc: RefreshLocalSwitchProfile
1168 * @tc.type: FUNC
1169 * @tc.require:
1170 */
1171 HWTEST_F(ProfileControlUtilsTest, RefreshLocalSwitchProfile003, TestSize.Level1)
1172 {
1173 std::string appId = "appId";
1174
1175 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1176 ProfileCache::GetInstance().localNetworkId_ = "localNetwork";
1177 int32_t ret = profileControlUtils->RefreshLocalSwitchProfile(appId);
1178 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1179 }
1180
1181 /**
1182 * @tc.name: GetSwitchCharacteristicProfile001
1183 * @tc.desc: GetSwitchCharacteristicProfile
1184 * @tc.type: FUNC
1185 * @tc.require:
1186 */
1187 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile001, TestSize.Level1)
1188 {
1189 std::string appId = "appId";
1190 std::string deviceId = "";
1191 std::string serviceName = "serviceName";
1192 std::string characteristicKey = "characteristicKey";
1193 CharacteristicProfile charProfile;
1194
1195 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1196 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1197 serviceName, characteristicKey, charProfile);
1198 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1199 }
1200
1201 /**
1202 * @tc.name: GetSwitchCharacteristicProfile002
1203 * @tc.desc: GetSwitchCharacteristicProfile
1204 * @tc.type: FUNC
1205 * @tc.require:
1206 */
1207 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile002, TestSize.Level1)
1208 {
1209 std::string appId = "appId";
1210 std::string deviceId = "deviceId";
1211 std::string serviceName = "";
1212 std::string characteristicKey = "characteristicKey";
1213 CharacteristicProfile charProfile;
1214
1215 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1216 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1217 serviceName, characteristicKey, charProfile);
1218 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1219 }
1220
1221 /**
1222 * @tc.name: GetSwitchCharacteristicProfile003
1223 * @tc.desc: GetSwitchCharacteristicProfile
1224 * @tc.type: FUNC
1225 * @tc.require:
1226 */
1227 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile003, TestSize.Level1)
1228 {
1229 std::string appId = "appId";
1230 std::string deviceId = "deviceId";
1231 std::string serviceName = "serviceName";
1232 std::string characteristicKey = "";
1233 CharacteristicProfile charProfile;
1234
1235 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1236 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1237 serviceName, characteristicKey, charProfile);
1238 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1239 }
1240
1241 /**
1242 * @tc.name: GetSwitchCharacteristicProfile004
1243 * @tc.desc: GetSwitchCharacteristicProfile
1244 * @tc.type: FUNC
1245 * @tc.require:
1246 */
1247 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile004, TestSize.Level1)
1248 {
1249 std::string appId = "";
1250 std::string deviceId = "deviceId";
1251 std::string serviceName = "serviceName";
1252 std::string characteristicKey = "characteristicKey";
1253 CharacteristicProfile charProfile;
1254
1255 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1256 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1257 serviceName, characteristicKey, charProfile);
1258 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1259 }
1260
1261 /**
1262 * @tc.name: GetSwitchCharacteristicProfile005
1263 * @tc.desc: GetSwitchCharacteristicProfile
1264 * @tc.type: FUNC
1265 * @tc.require:
1266 */
1267 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile005, TestSize.Level1)
1268 {
1269 std::string appId = "appId";
1270 std::string deviceId = "deviceId";
1271 std::string serviceName = "serviceName";
1272 std::string characteristicKey = "characteristicKey";
1273 CharacteristicProfile charProfile;
1274
1275 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1276 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1277 serviceName, characteristicKey, charProfile);
1278 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1279 }
1280
1281 /**
1282 * @tc.name: GetSwitchCharacteristicProfile006
1283 * @tc.desc: GetSwitchCharacteristicProfile
1284 * @tc.type: FUNC
1285 * @tc.require:
1286 */
1287 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile006, TestSize.Level1)
1288 {
1289 std::string peerNetworkId = "peerNetworkId";
1290 TrustedDeviceInfo deviceInfo;
1291 deviceInfo.SetNetworkId(peerNetworkId);
1292 std::string appId = "appId";
1293 std::string deviceId = "deviceId";
1294 deviceInfo.SetUdid(deviceId);
1295 std::string serviceName = "serviceName";
1296 std::string characteristicKey = "characteristicKey";
1297 CharacteristicProfile charProfile;
1298
1299 ProfileCache::GetInstance().onlineDevMap_[deviceId] = deviceInfo;
1300 std::string charProfileKey =
1301 CHAR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName + SEPARATOR + characteristicKey;
1302 ProfileCache::GetInstance().charProfileMap_[charProfileKey] = charProfile;
1303
1304 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1305 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1306 serviceName, characteristicKey, charProfile);
1307 EXPECT_EQ(ret, DP_SUCCESS);
1308 ProfileCache::GetInstance().charProfileMap_.erase(charProfileKey);
1309 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
1310 }
1311
1312 /**
1313 * @tc.name: GetSwitchCharacteristicProfile007
1314 * @tc.desc: GetSwitchCharacteristicProfile
1315 * @tc.type: FUNC
1316 * @tc.require:
1317 */
1318 HWTEST_F(ProfileControlUtilsTest, GetSwitchCharacteristicProfile007, TestSize.Level1)
1319 {
1320 std::string peerNetworkId = "peerNetworkId";
1321 TrustedDeviceInfo deviceInfo;
1322 deviceInfo.SetNetworkId(peerNetworkId);
1323 std::string appId = "appId";
1324 std::string deviceId = "deviceId";
1325 deviceInfo.SetUdid(deviceId);
1326 std::string serviceName = "serviceName";
1327 std::string characteristicKey = "SwitchStatus";
1328 CharacteristicProfile charProfile;
1329
1330 ProfileCache::GetInstance().onlineDevMap_[deviceId] = deviceInfo;
1331
1332 auto profileControlUtils = std::shared_ptr<ProfileControlUtils>();
1333 int32_t ret = profileControlUtils->GetSwitchCharacteristicProfile(appId, deviceId,
1334 serviceName, characteristicKey, charProfile);
1335 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1336 ProfileCache::GetInstance().onlineDevMap_.erase(deviceId);
1337 }
1338 } // namespace DistributedDeviceProfile
1339 } // namespace OHOS
1340