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