• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define private   public
17 #define protected public
18 #include <string>
19 #include <vector>
20 #include "gtest/gtest.h"
21 #include "refbase.h"
22 #include "rdb_errno.h"
23 #include "profile_utils.h"
24 #include "distributed_device_profile_constants.h"
25 #include "distributed_device_profile_errors.h"
26 #include "distributed_device_profile_enums.h"
27 #include "dm_constants.h"
28 #undef private
29 #undef protected
30 
31 namespace OHOS {
32 namespace DistributedDeviceProfile {
33 using namespace testing::ext;
34 using namespace OHOS::NativeRdb;
35 using namespace std;
36 
37 class ProfileUtilsTest : public testing::Test {
38 public:
39     static void SetUpTestCase(void);
40     static void TearDownTestCase(void);
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase(void)45 void ProfileUtilsTest::SetUpTestCase(void) {
46 }
47 
TearDownTestCase(void)48 void ProfileUtilsTest::TearDownTestCase(void) {
49 }
50 
SetUp()51 void ProfileUtilsTest::SetUp() {
52 }
53 
TearDown()54 void ProfileUtilsTest::TearDown() {
55 }
56 
57 /**
58  * @tc.name: GetDbKeyAnonyString001
59  * @tc.desc: GetDbKeyAnonyString
60  * @tc.type: FUNC
61  * @tc.require:
62  */
63 HWTEST_F(ProfileUtilsTest, GetDbKeyAnonyString001, TestSize.Level1)
64 {
65     string len2 = "";
66     string res = ProfileUtils::GetDbKeyAnonyString(len2);
67     EXPECT_EQ("***", res);
68 }
69 
70 /**
71  * @tc.name: GetDbKeyAnonyString002
72  * @tc.desc: GetDbKeyAnonyString
73  * @tc.type: FUNC
74  * @tc.require:
75  */
76 HWTEST_F(ProfileUtilsTest, GetDbKeyAnonyString002, TestSize.Level1)
77 {
78     string len2 = "ab";
79     string res = ProfileUtils::GetDbKeyAnonyString(len2);
80     EXPECT_EQ("***", res);
81 }
82 
83 /**
84  * @tc.name: GetDbKeyAnonyString003
85  * @tc.desc: GetDbKeyAnonyString
86  * @tc.type: FUNC
87  * @tc.require:
88  */
89 HWTEST_F(ProfileUtilsTest, GetDbKeyAnonyString003, TestSize.Level1)
90 {
91     string len2 = "ab#abc";
92     string res = ProfileUtils::GetDbKeyAnonyString(len2);
93     EXPECT_EQ("ab#a***c", res);
94 }
95 
96 /**
97  * @tc.name: GetAnonyString001
98  * @tc.desc: GetAnonyString failed, length < 3.
99  * @tc.type: FUNC
100  * @tc.require:
101  */
102 HWTEST_F(ProfileUtilsTest, GetAnonyString001, TestSize.Level1)
103 {
104     string len2 = "ab";
105     string res = ProfileUtils::GetAnonyString(len2);
106     EXPECT_EQ("***", res);
107 }
108 
109 /**
110  * @tc.name: GetAnonyString002
111  * @tc.desc: GetAnonyString succeed, 3 <= length <= 20.
112  * @tc.type: FUNC
113  * @tc.require:
114  */
115 HWTEST_F(ProfileUtilsTest, GetAnonyString002, TestSize.Level1)
116 {
117     string len5 = "abcde";
118     string res = ProfileUtils::GetAnonyString(len5);
119     EXPECT_EQ("a***e", res);
120 }
121 
122 /**
123  * @tc.name: GetAnonyString003
124  * @tc.desc: GetAnonyString succeed, length > 20.
125  * @tc.type: FUNC
126  * @tc.require:
127  */
128 HWTEST_F(ProfileUtilsTest, GetAnonyString003, TestSize.Level1)
129 {
130     string len22 = "abcdefghijklmnopqrstuv";
131     string res = ProfileUtils::GetAnonyString(len22);
132     EXPECT_EQ("abcd***stuv", res);
133 }
134 
135 /**
136  * @tc.name: GetProfileType001
137  * @tc.desc: GetProfileType succeed.
138  * @tc.type: FUNC
139  * @tc.require:
140  */
141 HWTEST_F(ProfileUtilsTest, GetProfileType001, TestSize.Level1)
142 {
143     string minkey = "";
144     ProfileType res = ProfileUtils::GetProfileType(minkey);
145     EXPECT_EQ(ProfileType::PROFILE_TYPE_MIN, res);
146 
147     string maxKey = "";
148     for (int32_t i = 0; i < 5000; i++) {
149         maxKey += 'a';
150     }
151     res = ProfileUtils::GetProfileType(maxKey);
152     EXPECT_EQ(ProfileType::PROFILE_TYPE_MIN, res);
153 
154     string devKey = "dev111";
155     res = ProfileUtils::GetProfileType(devKey);
156     EXPECT_EQ(ProfileType::DEVICE_PROFILE, res);
157 
158     string serKet = "svr111";
159     res = ProfileUtils::GetProfileType(serKet);
160     EXPECT_EQ(ProfileType::SERVICE_PROFILE, res);
161 
162     string charKey = "char111";
163     res = ProfileUtils::GetProfileType(charKey);
164     EXPECT_EQ(ProfileType::CHAR_PROFILE, res);
165 
166     string lastKey = "other";
167     res = ProfileUtils::GetProfileType(lastKey);
168     EXPECT_EQ(ProfileType::PROFILE_TYPE_MIN, res);
169 }
170 
171 /**
172  * @tc.name: StartsWith001
173  * @tc.desc: StartsWith succeed.
174  * @tc.type: FUNC
175  * @tc.require:
176  */
177 HWTEST_F(ProfileUtilsTest, StartsWith001, TestSize.Level1)
178 {
179     string str = "abcdefg";
180     string prefix = "abc";
181     bool res = ProfileUtils::StartsWith(str, prefix);
182     EXPECT_EQ(true, res);
183 }
184 
185 /**
186  * @tc.name: IsKeyValid001
187  * @tc.desc: IsKeyValid.
188  * @tc.type: FUNC
189  * @tc.require:
190  */
191 HWTEST_F(ProfileUtilsTest, IsKeyValid001, TestSize.Level1)
192 {
193     string key = "abc";
194     bool res = ProfileUtils::IsKeyValid(key);
195     EXPECT_EQ(true, res);
196 
197     key = "";
198     res = ProfileUtils::IsKeyValid(key);
199     EXPECT_EQ(false, res);
200 
201     key = "";
202     for (int32_t i = 0; i < 5000; i++) {
203         key += 'a';
204     }
205     res = ProfileUtils::IsKeyValid(key);
206     EXPECT_EQ(false, res);
207 
208     key = "abc#";
209     res = ProfileUtils::IsKeyValid(key);
210     EXPECT_EQ(false, res);
211 }
212 
213 /**
214  * @tc.name: GenerateDeviceProfileKey001
215  * @tc.desc: GenerateDeviceProfileKey.
216  * @tc.type: FUNC
217  * @tc.require:
218  */
219 HWTEST_F(ProfileUtilsTest, GenerateDeviceProfileKey001, TestSize.Level1)
220 {
221     string deviceId = "111";
222     string res = ProfileUtils::GenerateDeviceProfileKey(deviceId);
223     EXPECT_EQ("dev#111", res);
224 }
225 
226 /**
227  * @tc.name: GenerateServiceProfileKey001
228  * @tc.desc: GenerateServiceProfileKey.
229  * @tc.type: FUNC
230  * @tc.require:
231  */
232 HWTEST_F(ProfileUtilsTest, GenerateServiceProfileKey001, TestSize.Level1)
233 {
234     string deviceId = "111";
235     string serviceName = "222";
236     string res = ProfileUtils::GenerateServiceProfileKey(deviceId, serviceName);
237     EXPECT_EQ("svr#111#222", res);
238 }
239 
240 /**
241  * @tc.name: GenerateCharProfileKey001
242  * @tc.desc: GenerateCharProfileKey.
243  * @tc.type: FUNC
244  * @tc.require:
245  */
246 HWTEST_F(ProfileUtilsTest, GenerateCharProfileKey001, TestSize.Level1)
247 {
248     string deviceId = "111";
249     string serviceName = "222";
250     string charKey = "333";
251     string res = ProfileUtils::GenerateCharProfileKey(deviceId, serviceName, charKey);
252     EXPECT_EQ("char#111#222#333", res);
253 }
254 
255 /**
256  * @tc.name: TrustDeviceProfileTranslateEntries001
257  * @tc.desc: TrustDeviceProfileToEntries and EntriesToTrustDeviceProfile.
258  * @tc.type: FUNC
259  * @tc.require:
260  */
261 HWTEST_F(ProfileUtilsTest, TrustDeviceProfileTranslateEntries001, TestSize.Level1)
262 {
263     TrustDeviceProfile profile;
264     profile.SetDeviceId("deviceId");
265     profile.SetDeviceIdHash("deviceIdHash");
266     profile.SetDeviceIdType(1);
267     profile.SetStatus(1);
268 
269     ValuesBucket values;
270     ValueObject valueObject;
271     string strValue = "";
272     int32_t res1 = ProfileUtils::TrustDeviceProfileToEntries(profile, values);
273     EXPECT_EQ(DP_SUCCESS, res1);
274     values.GetObject(DEVICE_ID, valueObject);
275     valueObject.GetString(strValue);
276     EXPECT_EQ("deviceId", strValue);
277 
278     TrustDeviceProfile outProfile;
279     int32_t res2 = ProfileUtils::EntriesToTrustDeviceProfile(values, outProfile);
280     EXPECT_EQ(DP_SUCCESS, res2);
281     EXPECT_EQ("deviceId", outProfile.GetDeviceId());
282 }
283 
284 /**
285  * @tc.name: AccessControlProfileTranslateEntries001
286  * @tc.desc: AccessControlProfileToEntries and EntriesToAccessControlProfile.
287  * @tc.type: FUNC
288  * @tc.require:
289  */
290 HWTEST_F(ProfileUtilsTest, AccessControlProfileTranslateEntries001, TestSize.Level1)
291 {
292     Accesser accesser;
293     accesser.SetAccesserDeviceId("acer1");
294     accesser.SetAccesserUserId(11);
295     accesser.SetAccesserAccountId("a1");
296     accesser.SetAccesserTokenId(111);
297     accesser.SetAccesserBundleName("b1");
298     accesser.SetAccesserHapSignature("h1");
299     accesser.SetAccesserBindLevel(1);
300 
301     Accessee accessee;
302     accessee.SetAccesseeDeviceId("acee1");
303     accessee.SetAccesseeUserId(22);
304     accessee.SetAccesseeAccountId("a1");
305     accessee.SetAccesseeTokenId(222);
306     accessee.SetAccesseeBundleName("bb1");
307     accessee.SetAccesseeHapSignature("h1");
308     accessee.SetAccesseeBindLevel(1);
309 
310     AccessControlProfile profile;
311     profile.SetTrustDeviceId("123456");
312     profile.SetSessionKey("key1");
313     profile.SetBindType(1);
314     profile.SetAuthenticationType(1);
315     profile.SetDeviceIdType(1);
316     profile.SetDeviceIdHash("abcd");
317     profile.SetStatus(0);
318     profile.SetValidPeriod(1);
319     profile.SetLastAuthTime(5);
320     profile.SetBindLevel(0);
321 
322     profile.SetAccesser(accesser);
323     profile.SetAccessee(accessee);
324 
325     ValuesBucket values;
326     ValueObject valueObject;
327     string strValue = "";
328     int32_t res1 = ProfileUtils::AccessControlProfileToEntries(profile, values);
329     EXPECT_EQ(DP_SUCCESS, res1);
330     values.GetObject(TRUST_DEVICE_ID, valueObject);
331     valueObject.GetString(strValue);
332     EXPECT_EQ("123456", strValue);
333 
334     AccessControlProfile outProfile;
335     int32_t res2 = ProfileUtils::EntriesToAccessControlProfile(values, outProfile);
336     EXPECT_EQ(DP_SUCCESS, res2);
337     EXPECT_EQ("123456", outProfile.GetTrustDeviceId());
338 }
339 
340 HWTEST_F(ProfileUtilsTest, AccessControlProfileTranslateEntries002, TestSize.Level1)
341 {
342     Accesser accesser;
343     accesser.SetAccesserDeviceId("acer2");
344     accesser.SetAccesserUserId(11);
345     accesser.SetAccesserAccountId("a2");
346     accesser.SetAccesserTokenId(111);
347     accesser.SetAccesserBundleName("b2");
348     accesser.SetAccesserHapSignature("h2");
349     accesser.SetAccesserBindLevel(1);
350 
351     Accessee accessee;
352     accessee.SetAccesseeDeviceId("acee2");
353     accessee.SetAccesseeUserId(22);
354     accessee.SetAccesseeAccountId("a2");
355     accessee.SetAccesseeTokenId(222);
356     accessee.SetAccesseeBundleName("bb2");
357     accessee.SetAccesseeHapSignature("h2");
358     accessee.SetAccesseeBindLevel(1);
359 
360     AccessControlProfile profile;
361     profile.SetTrustDeviceId("1234567");
362     profile.SetSessionKey("key1");
363     profile.SetBindType(1);
364     profile.SetAuthenticationType(1);
365     profile.SetDeviceIdType(1);
366     profile.SetDeviceIdHash("abcd");
367     profile.SetStatus(0);
368     profile.SetValidPeriod(1);
369     profile.SetLastAuthTime(5);
370     profile.SetBindLevel(0);
371 
372     profile.SetAccesser(accesser);
373     profile.SetAccessee(accessee);
374 
375     ValuesBucket values;
376     ValueObject valueObject;
377     string strValue = "";
378     int32_t res1 = ProfileUtils::AccessControlProfileToEntries(profile, values);
379     EXPECT_EQ(DP_SUCCESS, res1);
380     values.GetObject(TRUST_DEVICE_ID, valueObject);
381     valueObject.GetString(strValue);
382     EXPECT_EQ("1234567", strValue);
383 
384     AccessControlProfile outProfile;
385     int32_t res2 = ProfileUtils::EntriesToAccessControlProfile(values, outProfile);
386     EXPECT_EQ(DP_SUCCESS, res2);
387     EXPECT_EQ("1234567", outProfile.GetTrustDeviceId());
388 }
389 
390 /**
391  * @tc.name: AccesserTranslateEntries001
392  * @tc.desc: AccesserToEntries and EntriesToAccesser.
393  * @tc.type: FUNC
394  * @tc.require:
395  */
396 HWTEST_F(ProfileUtilsTest, AccesserTranslateEntries001, TestSize.Level1)
397 {
398     Accesser accesser;
399     accesser.SetAccesserDeviceId("acer1");
400     accesser.SetAccesserUserId(11);
401     accesser.SetAccesserAccountId("a1");
402     accesser.SetAccesserTokenId(111);
403     accesser.SetAccesserBundleName("b1");
404     accesser.SetAccesserHapSignature("h1");
405     accesser.SetAccesserBindLevel(1);
406 
407     Accessee accessee;
408     accessee.SetAccesseeDeviceId("acee1");
409     accessee.SetAccesseeUserId(22);
410     accessee.SetAccesseeAccountId("a1");
411     accessee.SetAccesseeTokenId(222);
412     accessee.SetAccesseeBundleName("bb1");
413     accessee.SetAccesseeHapSignature("h1");
414     accessee.SetAccesseeBindLevel(1);
415 
416     AccessControlProfile profile;
417     profile.SetTrustDeviceId("123456");
418     profile.SetSessionKey("key1");
419     profile.SetBindType(1);
420     profile.SetAuthenticationType(1);
421     profile.SetDeviceIdType(1);
422     profile.SetDeviceIdHash("abcd");
423     profile.SetStatus(0);
424     profile.SetValidPeriod(1);
425     profile.SetLastAuthTime(5);
426     profile.SetBindLevel(0);
427 
428     profile.SetAccesser(accesser);
429     profile.SetAccessee(accessee);
430 
431     ValuesBucket values;
432     ValueObject valueObject;
433     string strValue = "";
434     int32_t res1 = ProfileUtils::AccesserToEntries(profile, values);
435     EXPECT_EQ(DP_SUCCESS, res1);
436     values.GetObject(ACCESSER_DEVICE_ID, valueObject);
437     valueObject.GetString(strValue);
438     EXPECT_EQ("acer1", strValue);
439 
440     Accesser outAccesser;
441     int32_t res2 = ProfileUtils::EntriesToAccesser(values, outAccesser);
442     EXPECT_EQ(DP_SUCCESS, res2);
443     EXPECT_EQ("acer1", outAccesser.GetAccesserDeviceId());
444 }
445 
446 /**
447  * @tc.name: AccesseeTranslateEntries001
448  * @tc.desc: AccesseeToEntries and EntriesToAccessee.
449  * @tc.type: FUNC
450  * @tc.require:
451  */
452 HWTEST_F(ProfileUtilsTest, AccesseeTranslateEntries001, TestSize.Level1)
453 {
454     Accesser accesser;
455     accesser.SetAccesserDeviceId("acer1");
456     accesser.SetAccesserUserId(11);
457     accesser.SetAccesserAccountId("a1");
458     accesser.SetAccesserTokenId(111);
459     accesser.SetAccesserBundleName("b1");
460     accesser.SetAccesserHapSignature("h1");
461     accesser.SetAccesserBindLevel(1);
462 
463     Accessee accessee;
464     accessee.SetAccesseeDeviceId("acee1");
465     accessee.SetAccesseeUserId(22);
466     accessee.SetAccesseeAccountId("a1");
467     accessee.SetAccesseeTokenId(222);
468     accessee.SetAccesseeBundleName("bb1");
469     accessee.SetAccesseeHapSignature("h1");
470     accessee.SetAccesseeBindLevel(1);
471 
472     AccessControlProfile profile;
473     profile.SetTrustDeviceId("123456");
474     profile.SetSessionKey("key1");
475     profile.SetBindType(1);
476     profile.SetAuthenticationType(1);
477     profile.SetDeviceIdType(1);
478     profile.SetDeviceIdHash("abcd");
479     profile.SetStatus(0);
480     profile.SetValidPeriod(1);
481     profile.SetLastAuthTime(5);
482     profile.SetBindLevel(0);
483 
484     profile.SetAccesser(accesser);
485     profile.SetAccessee(accessee);
486 
487     ValuesBucket values;
488     ValueObject valueObject;
489     string strValue = "";
490     int32_t res1 = ProfileUtils::AccesseeToEntries(profile, values);
491     EXPECT_EQ(DP_SUCCESS, res1);
492     values.GetObject(ACCESSEE_DEVICE_ID, valueObject);
493     valueObject.GetString(strValue);
494     EXPECT_EQ("acee1", strValue);
495 
496     Accessee outAccessee;
497     int32_t res2 = ProfileUtils::EntriesToAccessee(values, outAccessee);
498     EXPECT_EQ(DP_SUCCESS, res2);
499     EXPECT_EQ("acee1", outAccessee.GetAccesseeDeviceId());
500 }
501 
502 /**
503  * @tc.name: DeviceProfileTranslateEntries001
504  * @tc.desc: DeviceProfileToEntries and EntriesToDeviceProfile.
505  * @tc.type: FUNC
506  * @tc.require:
507  */
508 HWTEST_F(ProfileUtilsTest, DeviceProfileTranslateEntries001, TestSize.Level1)
509 {
510     DeviceProfile deviceProfile;
511     deviceProfile.SetDeviceId("anything");
512     deviceProfile.SetOsApiLevel(1);
513     deviceProfile.SetOsVersion("anything");
514     deviceProfile.SetOsType(1);
515 
516     map<string, string> entries;
517     int32_t res1 = ProfileUtils::DeviceProfileToEntries(deviceProfile, entries);
518     EXPECT_EQ(DP_SUCCESS, res1);
519 
520     DeviceProfile outDeviceProfile;
521     int32_t res2 = ProfileUtils::EntriesToDeviceProfile(entries, outDeviceProfile);
522     EXPECT_EQ(DP_SUCCESS, res2);
523 }
524 
525 /**
526  * @tc.name: ServiceProfileTranslateEntries001
527  * @tc.desc: ServiceProfileToEntries and EntriesToServiceProfile.
528  * @tc.type: FUNC
529  * @tc.require:
530  */
531 HWTEST_F(ProfileUtilsTest, ServiceProfileTranslateEntries001, TestSize.Level1)
532 {
533     ServiceProfile serviceProfile;
534     serviceProfile.SetDeviceId("deviceId");
535     serviceProfile.SetServiceName("serviceName");
536     serviceProfile.SetServiceType("serviceType");
537 
538     map<string, string> entries;
539     int32_t res1 = ProfileUtils::ServiceProfileToEntries(serviceProfile, entries);
540     EXPECT_EQ(DP_SUCCESS, res1);
541 
542     ServiceProfile outServiceProfile;
543     int32_t res2 = ProfileUtils::EntriesToServiceProfile(entries, outServiceProfile);
544     EXPECT_EQ(DP_SUCCESS, res2);
545     EXPECT_EQ("deviceId", outServiceProfile.GetDeviceId());
546 }
547 
548 HWTEST_F(ProfileUtilsTest, AccesserTranslateEntries002, TestSize.Level1)
549 {
550     Accesser accesser;
551     accesser.SetAccesserDeviceId("acer2");
552     accesser.SetAccesserUserId(11);
553     accesser.SetAccesserAccountId("a1");
554     accesser.SetAccesserTokenId(111);
555     accesser.SetAccesserBundleName("b1");
556     accesser.SetAccesserHapSignature("h1");
557     accesser.SetAccesserBindLevel(1);
558 
559     Accessee accessee;
560     accessee.SetAccesseeDeviceId("acee2");
561     accessee.SetAccesseeUserId(22);
562     accessee.SetAccesseeAccountId("a1");
563     accessee.SetAccesseeTokenId(222);
564     accessee.SetAccesseeBundleName("bb1");
565     accessee.SetAccesseeHapSignature("h1");
566     accessee.SetAccesseeBindLevel(1);
567 
568     AccessControlProfile profile;
569     profile.SetTrustDeviceId("123456");
570     profile.SetSessionKey("key1");
571     profile.SetBindType(1);
572     profile.SetAuthenticationType(1);
573     profile.SetDeviceIdType(1);
574     profile.SetDeviceIdHash("abcd");
575     profile.SetStatus(0);
576     profile.SetValidPeriod(1);
577     profile.SetLastAuthTime(5);
578     profile.SetBindLevel(0);
579 
580     profile.SetAccesser(accesser);
581     profile.SetAccessee(accessee);
582 
583     ValuesBucket values;
584     ValueObject valueObject;
585     string strValue = "";
586     int32_t res1 = ProfileUtils::AccesserToEntries(profile, values);
587     EXPECT_EQ(DP_SUCCESS, res1);
588     values.GetObject(ACCESSER_DEVICE_ID, valueObject);
589     valueObject.GetString(strValue);
590     EXPECT_EQ("acer2", strValue);
591 
592     Accesser outAccesser;
593     int32_t res2 = ProfileUtils::EntriesToAccesser(values, outAccesser);
594     EXPECT_EQ(DP_SUCCESS, res2);
595     EXPECT_EQ("acer2", outAccesser.GetAccesserDeviceId());
596 }
597 
598 HWTEST_F(ProfileUtilsTest, AccesseeTranslateEntries002, TestSize.Level1)
599 {
600     Accesser accesser;
601     accesser.SetAccesserDeviceId("acer2");
602     accesser.SetAccesserUserId(11);
603     accesser.SetAccesserAccountId("a1");
604     accesser.SetAccesserTokenId(111);
605     accesser.SetAccesserBundleName("b1");
606     accesser.SetAccesserHapSignature("h1");
607     accesser.SetAccesserBindLevel(1);
608 
609     Accessee accessee;
610     accessee.SetAccesseeDeviceId("acee2");
611     accessee.SetAccesseeUserId(22);
612     accessee.SetAccesseeAccountId("a1");
613     accessee.SetAccesseeTokenId(222);
614     accessee.SetAccesseeBundleName("bb1");
615     accessee.SetAccesseeHapSignature("h1");
616     accessee.SetAccesseeBindLevel(1);
617 
618     AccessControlProfile profile;
619     profile.SetTrustDeviceId("123456");
620     profile.SetSessionKey("key1");
621     profile.SetBindType(1);
622     profile.SetAuthenticationType(1);
623     profile.SetDeviceIdType(1);
624     profile.SetDeviceIdHash("abcd");
625     profile.SetStatus(0);
626     profile.SetValidPeriod(1);
627     profile.SetLastAuthTime(5);
628     profile.SetBindLevel(0);
629 
630     profile.SetAccesser(accesser);
631     profile.SetAccessee(accessee);
632 
633     ValuesBucket values;
634     ValueObject valueObject;
635     string strValue = "";
636     int32_t res1 = ProfileUtils::AccesseeToEntries(profile, values);
637     EXPECT_EQ(DP_SUCCESS, res1);
638     values.GetObject(ACCESSEE_DEVICE_ID, valueObject);
639     valueObject.GetString(strValue);
640     EXPECT_EQ("acee2", strValue);
641 
642     Accessee outAccessee;
643     int32_t res2 = ProfileUtils::EntriesToAccessee(values, outAccessee);
644     EXPECT_EQ(DP_SUCCESS, res2);
645     EXPECT_EQ("acee2", outAccessee.GetAccesseeDeviceId());
646 }
647 
648 /**
649  * @tc.name: CharacteristicProfileTranslateEntries001
650  * @tc.desc: CharacteristicProfileToEntries and EntriesToCharProfile.
651  * @tc.type: FUNC
652  * @tc.require:
653  */
654 HWTEST_F(ProfileUtilsTest, CharacteristicProfileTranslateEntries001, TestSize.Level1)
655 {
656     CharacteristicProfile charProfile;
657     charProfile.SetDeviceId("deviceId");
658     charProfile.SetServiceName("serviceName");
659     charProfile.SetCharacteristicKey("characteristicKey");
660     charProfile.SetCharacteristicValue("characteristicValue");
661 
662     map<string, string> entries;
663     int32_t res1 = ProfileUtils::CharacteristicProfileToEntries(charProfile, entries);
664     EXPECT_EQ(DP_SUCCESS, res1);
665 
666     CharacteristicProfile outCharProfile;
667     int32_t res2 = ProfileUtils::EntriesToCharProfile(entries, outCharProfile);
668     EXPECT_EQ(DP_SUCCESS, res2);
669     EXPECT_EQ("deviceId", outCharProfile.GetDeviceId());
670 }
671 
672 /**
673  * @tc.name: EntriesToDeviceProfile001
674  * @tc.desc: EntriesToDeviceProfile failed, Entries size is invalid.
675  * @tc.type: FUNC
676  * @tc.require:
677  */
678 HWTEST_F(ProfileUtilsTest, EntriesToDeviceProfile001, TestSize.Level1)
679 {
680     map<string, string> entries;
681     DeviceProfile deviceProfile;
682     int32_t res = ProfileUtils::EntriesToDeviceProfile(entries, deviceProfile);
683     EXPECT_EQ(DP_INVALID_PARAMS, res);
684 }
685 
686 /**
687  * @tc.name: EntriesToServiceProfile001
688  * @tc.desc: EntriesToServiceProfile failed, Entries size is invalid.
689  * @tc.type: FUNC
690  * @tc.require:
691  */
692 HWTEST_F(ProfileUtilsTest, EntriesToServiceProfile001, TestSize.Level1)
693 {
694     map<string, string> entries;
695     ServiceProfile serviceProfile;
696     int32_t res = ProfileUtils::EntriesToServiceProfile(entries, serviceProfile);
697     EXPECT_EQ(DP_INVALID_PARAMS, res);
698 }
699 
700 /**
701  * @tc.name: EntriesToCharProfile001
702  * @tc.desc: EntriesToCharProfile failed, Entries size is invalid.
703  * @tc.type: FUNC
704  * @tc.require:
705  */
706 HWTEST_F(ProfileUtilsTest, EntriesToCharProfile001, TestSize.Level1)
707 {
708     map<string, string> entries;
709     CharacteristicProfile charProfile;
710     int32_t res = ProfileUtils::EntriesToCharProfile(entries, charProfile);
711     EXPECT_EQ(DP_INVALID_PARAMS, res);
712 }
713 
714 /**
715  * @tc.name: SplitString001
716  * @tc.desc: SplitString failed, str == "".
717  * @tc.type: FUNC
718  * @tc.require:
719  */
720 HWTEST_F(ProfileUtilsTest, SplitString001, TestSize.Level1)
721 {
722     string str = "";
723     string splits = "#";
724     vector<string> res;
725     int32_t ret = ProfileUtils::SplitString(str, splits, res);
726     EXPECT_EQ(DP_INVALID_PARAMS, ret);
727 }
728 
729 /**
730  * @tc.name: SplitString002
731  * @tc.desc: SplitString succeed.
732  * @tc.type: FUNC
733  * @tc.require:
734  */
735 HWTEST_F(ProfileUtilsTest, SplitString002, TestSize.Level1)
736 {
737     string str = "a#b#c";
738     string splits = "#";
739     vector<string> res;
740     int32_t ret = ProfileUtils::SplitString(str, splits, res);
741     EXPECT_EQ(DP_SUCCESS, ret);
742     EXPECT_EQ(3, res.size());
743 }
744 
745 /**
746  * @tc.name: JoinString001
747  * @tc.desc: JoinString failed, str == "".
748  * @tc.type: FUNC
749  * @tc.require:
750  */
751 HWTEST_F(ProfileUtilsTest, JoinString001, TestSize.Level1)
752 {
753     string splits = "#";
754     vector<string> strs;
755     string ret = ProfileUtils::JoinString(strs, splits);
756     EXPECT_EQ(EMPTY_STRING, ret);
757 }
758 
759 /**
760  * @tc.name: JoinString002
761  * @tc.desc: JoinString succeed.
762  * @tc.type: FUNC
763  * @tc.require:
764  */
765 HWTEST_F(ProfileUtilsTest, JoinString002, TestSize.Level1)
766 {
767     string str = "a#b#c";
768     string splits = "#";
769     vector<string> strs {"a", "b", "c"};
770     string ret = ProfileUtils::JoinString(strs, splits);
771     EXPECT_EQ(str, ret);
772 }
773 
774 /**
775  * @tc.name: GenerateDBKey001
776  * @tc.desc: GenerateDBKey succeed.
777  * @tc.type: FUNC
778  * @tc.require:
779  */
780 HWTEST_F(ProfileUtilsTest, GenerateDBKey001, TestSize.Level1)
781 {
782     string profileKey = "profileKey";
783     string profileProperty = "profileProperty";
784     string res = ProfileUtils::GenerateDBKey(profileKey, profileProperty);
785     EXPECT_EQ("profileKey#profileProperty", res);
786 }
787 
788 /**
789  * @tc.name: GetProfileKey001
790  * @tc.desc: GetProfileKey succeed.
791  * @tc.type: FUNC
792  * @tc.require:
793  */
794 HWTEST_F(ProfileUtilsTest, GetProfileKey001, TestSize.Level1)
795 {
796     string dbKey = "profileKey#profileProperty";
797     string res = ProfileUtils::GetProfileKey(dbKey);
798     EXPECT_EQ("profileKey", res);
799 }
800 
801 /**
802  * @tc.name: GetProfileKey002
803  * @tc.desc: GetProfileKey failed , dbKey.length() == 0.
804  * @tc.type: FUNC
805  * @tc.require:
806  */
807 HWTEST_F(ProfileUtilsTest, GetProfileKey002, TestSize.Level1)
808 {
809     string dbKey = "";
810     string res = ProfileUtils::GetProfileKey(dbKey);
811     EXPECT_EQ(0, res.length());
812 }
813 
814 /**
815  * @tc.name: GetProfileKey003
816  * @tc.desc: GetProfileKey failed , dbKey.length() > 4096.
817  * @tc.type: FUNC
818  * @tc.require:
819  */
820 HWTEST_F(ProfileUtilsTest, GetProfileKey003, TestSize.Level1)
821 {
822     string dbKey = "";
823     for (int32_t i = 0; i < 5000; i++) {
824         dbKey += 'a';
825     }
826     string res = ProfileUtils::GetProfileKey(dbKey);
827     EXPECT_EQ(0, res.length());
828 }
829 
830 /**
831  * @tc.name: GetProfileProperty001
832  * @tc.desc: GetProfileProperty succeed.
833  * @tc.type: FUNC
834  * @tc.require:
835  */
836 HWTEST_F(ProfileUtilsTest, GetProfileProperty001, TestSize.Level1)
837 {
838     string dbKey = "profileKey#profileProperty";
839     string res = ProfileUtils::GetProfileProperty(dbKey);
840     EXPECT_EQ("", res);
841 }
842 
843 /**
844  * @tc.name: GetProfileProperty002
845  * @tc.desc: GetProfileProperty failed , dbKey.length() == 0.
846  * @tc.type: FUNC
847  * @tc.require:
848  */
849 HWTEST_F(ProfileUtilsTest, GetProfileProperty002, TestSize.Level1)
850 {
851     string dbKey = "";
852     string res = ProfileUtils::GetProfileProperty(dbKey);
853     EXPECT_EQ(0, res.length());
854 }
855 
856 /**
857  * @tc.name: GetProfileProperty003
858  * @tc.desc: GetProfileProperty failed , dbKey.length() > 4096.
859  * @tc.type: FUNC
860  * @tc.require:
861  */
862 HWTEST_F(ProfileUtilsTest, GetProfileProperty003, TestSize.Level1)
863 {
864     string dbKey = "";
865     for (int32_t i = 0; i < 5000; i++) {
866         dbKey += 'a';
867     }
868     string res = ProfileUtils::GetProfileProperty(dbKey);
869     EXPECT_EQ(0, res.length());
870 }
871 
872 /**
873  * @tc.name: GetDeviceIdByDBKey001
874  * @tc.desc: GetDeviceIdByDBKey succeed.
875  * @tc.type: FUNC
876  * @tc.require:
877  */
878 HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey001, TestSize.Level1)
879 {
880     string dbKey = "dev#111";
881     string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
882     EXPECT_EQ("111", res);
883 }
884 
885 /**
886  * @tc.name: GetDeviceIdByDBKey002
887  * @tc.desc: GetDeviceIdByDBKey failed , dbKey.length() == 0.
888  * @tc.type: FUNC
889  * @tc.require:
890  */
891 HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey002, TestSize.Level1)
892 {
893     string dbKey = "";
894     string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
895     EXPECT_EQ(0, res.length());
896 }
897 
898 /**
899  * @tc.name: GetDeviceIdByDBKey003
900  * @tc.desc: GetDeviceIdByDBKey failed , res.size() < 1.
901  * @tc.type: FUNC
902  * @tc.require:
903  */
904 HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey003, TestSize.Level1)
905 {
906     string dbKey = "#";
907     string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
908     EXPECT_EQ(0, res.length());
909 }
910 
911 /**
912  * @tc.name: GetDeviceIdByDBKey004
913  * @tc.desc: GetDeviceIdByDBKey failed , dbKey.length() > 4096.
914  * @tc.type: FUNC
915  * @tc.require:
916  */
917 HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey004, TestSize.Level1)
918 {
919     string dbKey = "";
920     for (int32_t i = 0; i < 5000; i++) {
921         dbKey += 'a';
922     }
923     string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
924     EXPECT_EQ(0, res.length());
925 }
926 
927 /**
928  * @tc.name: GetServiceNameByDBKey001
929  * @tc.desc: GetServiceNameByDBKey succeed.
930  * @tc.type: FUNC
931  * @tc.require:
932  */
933 HWTEST_F(ProfileUtilsTest, GetServiceNameByDBKey001, TestSize.Level1)
934 {
935     string dbKey = "ser#111#222";
936     string res = ProfileUtils::GetServiceNameByDBKey(dbKey);
937     EXPECT_EQ("222", res);
938 }
939 
940 /**
941  * @tc.name: GetServiceNameByDBKey002
942  * @tc.desc: GetServiceNameByDBKey failed , dbKey.length() == 0.
943  * @tc.type: FUNC
944  * @tc.require:
945  */
946 HWTEST_F(ProfileUtilsTest, GetServiceNameByDBKey002, TestSize.Level1)
947 {
948     string dbKey = "";
949     string res = ProfileUtils::GetServiceNameByDBKey(dbKey);
950     EXPECT_EQ(0, res.length());
951 }
952 
953 /**
954  * @tc.name: GetServiceNameByDBKey003
955  * @tc.desc: GetServiceNameByDBKey failed , dbKey.length() > 4096.
956  * @tc.type: FUNC
957  * @tc.require:
958  */
959 HWTEST_F(ProfileUtilsTest, GetServiceNameByDBKey003, TestSize.Level1)
960 {
961     string dbKey = "";
962         for (int32_t i = 0; i < 5000; i++) {
963     dbKey += 'a';
964     }
965     string res = ProfileUtils::GetServiceNameByDBKey(dbKey);
966     EXPECT_EQ(0, res.length());
967 }
968 
969 /**
970  * @tc.name: GetServiceNameByDBKey004
971  * @tc.desc: GetDeviceIdByDBKey failed , res.size() < 2.
972  * @tc.type: FUNC
973  * @tc.require:
974  */
975 HWTEST_F(ProfileUtilsTest, GetServiceNameByDBKey004, TestSize.Level1)
976 {
977     string dbKey = "ser";
978     string res = ProfileUtils::GetServiceNameByDBKey(dbKey);
979     EXPECT_EQ(0, res.length());
980 }
981 
982 /**
983  * @tc.name: GetCharKeyByDBKey001
984  * @tc.desc: GetCharKeyByDBKey succeed.
985  * @tc.type: FUNC
986  * @tc.require:
987  */
988 HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey001, TestSize.Level1)
989 {
990     string dbKey = "char#111#222#333";
991     string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
992     EXPECT_EQ("333", res);
993 }
994 
995 /**
996  * @tc.name: GetCharKeyByDBKey002
997  * @tc.desc: GetCharKeyByDBKey failed , dbKey.length() == 0.
998  * @tc.type: FUNC
999  * @tc.require:
1000  */
1001 HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey002, TestSize.Level1)
1002 {
1003     string dbKey = "";
1004     string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
1005     EXPECT_EQ(0, res.length());
1006 }
1007 
1008 /**
1009  * @tc.name: GetCharKeyByDBKey003
1010  * @tc.desc: GetCharKeyByDBKey failed , res.size() < 3.
1011  * @tc.type: FUNC
1012  * @tc.require:
1013  */
1014 HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey003, TestSize.Level1)
1015 {
1016     string dbKey = "char#";
1017     string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
1018     EXPECT_EQ(0, res.length());
1019 }
1020 
1021 /**
1022  * @tc.name: GetCharKeyByDBKey004
1023  * @tc.desc: GetCharKeyByDBKey failed , dbKey.length() > 4096.
1024  * @tc.type: FUNC
1025  * @tc.require:
1026  */
1027 HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey004, TestSize.Level1)
1028 {
1029     string dbKey = "";
1030         for (int32_t i = 0; i < 5000; i++) {
1031     dbKey += 'a';
1032     }
1033     string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
1034     EXPECT_EQ(0, res.length());
1035 }
1036 
1037 /**
1038  * @tc.name: toString001
1039  * @tc.desc: toString succeed.
1040  * @tc.type: FUNC
1041  * @tc.require:
1042  */
1043 HWTEST_F(ProfileUtilsTest, toString001, TestSize.Level1)
1044 {
1045     u16string str16 = u"abc";
1046     string res = ProfileUtils::toString(str16);
1047     EXPECT_EQ("abc", res);
1048 }
1049 
1050 /**
1051  * @tc.name: IsPropertyValid001
1052  * @tc.desc: IsPropertyValid failed, propertyMap.size() == 0.
1053  * @tc.type: FUNC
1054  * @tc.require:
1055  */
1056 HWTEST_F(ProfileUtilsTest, IsPropertyValid001, TestSize.Level1)
1057 {
1058     map<string, string> propertyMap;
1059     string property = "property";
1060     int32_t maxValue = 1;
1061     bool res1 = ProfileUtils::IsPropertyValid(propertyMap, property, maxValue);
1062     EXPECT_EQ(false, res1);
1063 
1064     int32_t minValue = 0;
1065     bool res2 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1066     EXPECT_EQ(false, res2);
1067 
1068     uint32_t u32MinValue = 0;
1069     uint32_t u32MaxValue = 1;
1070     bool res3 = ProfileUtils::IsPropertyValid(propertyMap, property, u32MinValue, u32MaxValue);
1071     EXPECT_EQ(false, res3);
1072 
1073     int64_t i64MinValue = 0;
1074     int64_t i64MaxValue = 1;
1075     bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, i64MinValue, i64MaxValue);
1076     EXPECT_EQ(false, res4);
1077 }
1078 
1079 /**
1080  * @tc.name: IsPropertyValid002
1081  * @tc.desc: IsPropertyValid overload 1.
1082  * @tc.type: FUNC
1083  * @tc.require:
1084  */
1085 HWTEST_F(ProfileUtilsTest, IsPropertyValid002, TestSize.Level1)
1086 {
1087     map<string, string> propertyMap;
1088     string property = "property";
1089     string value = "value";
1090     propertyMap[property] = value;
1091     int32_t maxValue = 10;
1092     bool res1 = ProfileUtils::IsPropertyValid(propertyMap, property, maxValue);
1093     EXPECT_EQ(true, res1);
1094 
1095     maxValue = 0;
1096     bool res2 = ProfileUtils::IsPropertyValid(propertyMap, property, maxValue);
1097     EXPECT_EQ(false, res2);
1098 
1099     value = "";
1100     propertyMap[property] = value;
1101     bool res3 = ProfileUtils::IsPropertyValid(propertyMap, property, maxValue);
1102     EXPECT_EQ(false, res3);
1103 
1104     propertyMap.erase(property);
1105     bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, maxValue);
1106     EXPECT_EQ(false, res4);
1107 }
1108 
1109 /**
1110  * @tc.name: IsPropertyValid003
1111  * @tc.desc: IsPropertyValid overload 2.
1112  * @tc.type: FUNC
1113  * @tc.require:
1114  */
1115 HWTEST_F(ProfileUtilsTest, IsPropertyValid003, TestSize.Level1)
1116 {
1117     map<string, string> propertyMap;
1118     string property = "property";
1119     string value = "5";
1120     propertyMap[property] = value;
1121     int32_t maxValue = 10;
1122     int32_t minValue = 0;
1123     bool res1 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1124     EXPECT_EQ(true, res1);
1125 
1126     maxValue = 0;
1127     bool res2 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1128     EXPECT_EQ(false, res2);
1129 
1130     value = "0";
1131     propertyMap[property] = value;
1132     bool res3 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1133     EXPECT_EQ(false, res3);
1134 
1135     propertyMap.erase(property);
1136     bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1137     EXPECT_EQ(false, res4);
1138 }
1139 
1140 /**
1141  * @tc.name: IsPropertyValid004
1142  * @tc.desc: IsPropertyValid overload 3.
1143  * @tc.type: FUNC
1144  * @tc.require:
1145  */
1146 HWTEST_F(ProfileUtilsTest, IsPropertyValid004, TestSize.Level1)
1147 {
1148     map<string, string> propertyMap;
1149     string property = "property";
1150     string value = "5";
1151     propertyMap[property] = value;
1152     uint32_t maxValue = 10;
1153     uint32_t minValue = 0;
1154     bool res1 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1155     EXPECT_EQ(true, res1);
1156 
1157     maxValue = 0;
1158     bool res2 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1159     EXPECT_EQ(false, res2);
1160 
1161     value = "0";
1162     propertyMap[property] = value;
1163     bool res3 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1164     EXPECT_EQ(false, res3);
1165 
1166     propertyMap.erase(property);
1167     bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1168     EXPECT_EQ(false, res4);
1169 }
1170 
1171 /**
1172  * @tc.name: IsPropertyValid005
1173  * @tc.desc: IsPropertyValid overload 4.
1174  * @tc.type: FUNC
1175  * @tc.require:
1176  */
1177 HWTEST_F(ProfileUtilsTest, IsPropertyValid005, TestSize.Level1)
1178 {
1179     map<string, string> propertyMap;
1180     string property = "property";
1181     string value = "5";
1182     propertyMap[property] = value;
1183     int64_t maxValue = 10;
1184     int64_t minValue = 0;
1185     bool res1 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1186     EXPECT_EQ(true, res1);
1187 
1188     maxValue = 0;
1189     bool res2 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1190     EXPECT_EQ(false, res2);
1191 
1192     value = "0";
1193     propertyMap[property] = value;
1194     bool res3 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1195     EXPECT_EQ(false, res3);
1196 
1197     propertyMap.erase(property);
1198     bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1199     EXPECT_EQ(false, res4);
1200 
1201     property = "property1";
1202     value = "";
1203     propertyMap[property] = value;
1204     bool res5 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
1205     EXPECT_EQ(false, res5);
1206 }
1207 
1208 /**
1209  * @tc.name: GetIntValue001
1210  * @tc.desc: GetIntValue failed, ValuesBucket is empty.
1211  * @tc.type: FUNC
1212  * @tc.require:
1213  */
1214 HWTEST_F(ProfileUtilsTest, GetIntValue001, TestSize.Level1)
1215 {
1216     ValuesBucket values;
1217     string property = "property";
1218     int32_t value = 0;
1219     bool res = ProfileUtils::GetIntValue(values, property, value);
1220     EXPECT_EQ(false, res);
1221 }
1222 
1223 /**
1224  * @tc.name: GetIntValue002
1225  * @tc.desc: GetIntValue all.
1226  * @tc.type: FUNC
1227  * @tc.require:
1228  */
1229 HWTEST_F(ProfileUtilsTest, GetIntValue002, TestSize.Level1)
1230 {
1231     ValuesBucket values;
1232     int32_t intValue = 1;
1233     string property = "property";
1234     values.PutInt(property, intValue);
1235     int32_t outValue = 0;
1236     bool res1 = ProfileUtils::GetIntValue(values, property, outValue);
1237     EXPECT_EQ(true, res1);
1238 
1239     string strValue = "strValue";
1240     values.Clear();
1241     values.PutString(property, strValue);
1242     bool res2 = ProfileUtils::GetIntValue(values, property, outValue);
1243     EXPECT_EQ(false, res2);
1244 
1245     values.Clear();
1246     bool res3 = ProfileUtils::GetIntValue(values, property, outValue);
1247     EXPECT_EQ(false, res3);
1248 }
1249 
1250 /**
1251  * @tc.name: GetStringValue001
1252  * @tc.desc: GetStringValue failed, ValuesBucket is empty.
1253  * @tc.type: FUNC
1254  * @tc.require:
1255  */
1256 HWTEST_F(ProfileUtilsTest, GetStringValue001, TestSize.Level1)
1257 {
1258     ValuesBucket values;
1259     string property = "property";
1260     string value = "";
1261     bool res = ProfileUtils::GetStringValue(values, property, value);
1262     EXPECT_EQ(false, res);
1263 }
1264 
1265 /**
1266  * @tc.name: GetStringValue002
1267  * @tc.desc: GetStringValue all.
1268  * @tc.type: FUNC
1269  * @tc.require:
1270  */
1271 HWTEST_F(ProfileUtilsTest, GetStringValue002, TestSize.Level1)
1272 {
1273     ValuesBucket values;
1274     string strValue = "strValue";
1275     string property = "property";
1276     values.PutString(property, strValue);
1277     string outValue = "";
1278     bool res1 = ProfileUtils::GetStringValue(values, property, outValue);
1279     EXPECT_EQ(true, res1);
1280 
1281     values.Clear();
1282     values.PutNull(property);
1283     bool res2 = ProfileUtils::GetStringValue(values, property, outValue);
1284     EXPECT_EQ(false, res2);
1285 
1286     values.Clear();
1287     bool res3 = ProfileUtils::GetStringValue(values, property, outValue);
1288     EXPECT_EQ(false, res3);
1289 }
1290 
1291 /**
1292  * @tc.name: GetLongValue001
1293  * @tc.desc: GetLongValue failed, ValuesBucket is empty.
1294  * @tc.type: FUNC
1295  * @tc.require:
1296  */
1297 HWTEST_F(ProfileUtilsTest, GetLongValue001, TestSize.Level1)
1298 {
1299     ValuesBucket values;
1300     string property = "property";
1301     int64_t value = 0;
1302     bool res = ProfileUtils::GetLongValue(values, property, value);
1303     EXPECT_EQ(false, res);
1304 }
1305 
1306 /**
1307  * @tc.name: GetLongValue002
1308  * @tc.desc: GetLongValue all.
1309  * @tc.type: FUNC
1310  * @tc.require:
1311  */
1312 HWTEST_F(ProfileUtilsTest, GetLongValue002, TestSize.Level1)
1313 {
1314     ValuesBucket values;
1315     int64_t longValue = 1;
1316     string strValue = "strValue";
1317     string property = "property";
1318     values.PutLong(property, longValue);
1319     int64_t outValue = 0;
1320     bool res1 = ProfileUtils::GetLongValue(values, property, outValue);
1321     EXPECT_EQ(true, res1);
1322 
1323     values.Clear();
1324     values.PutString(property, strValue);
1325     bool res2 = ProfileUtils::GetLongValue(values, property, outValue);
1326     EXPECT_EQ(false, res2);
1327 
1328     values.Clear();
1329     bool res3 = ProfileUtils::GetLongValue(values, property, outValue);
1330     EXPECT_EQ(false, res3);
1331 }
1332 
1333 /**
1334  * @tc.name: EntriesToTrustDeviceProfile001
1335  * @tc.desc: EntriesToTrustDeviceProfile all.
1336  * @tc.type: FUNC
1337  * @tc.require:
1338  */
1339 HWTEST_F(ProfileUtilsTest, EntriesToTrustDeviceProfile001, TestSize.Level1)
1340 {
1341     ValuesBucket values;
1342     TrustDeviceProfile profile;
1343     int32_t intValue = 1;
1344     string strValue = "strValue";
1345 
1346     values.PutString(DEVICE_ID, strValue);
1347     values.PutString(DEVICE_ID_HASH, strValue);
1348     values.PutInt(DEVICE_TYPE_ID, intValue);
1349     values.PutInt(STATUS, intValue);
1350     int32_t ret1 = ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1351     EXPECT_EQ(DP_SUCCESS, ret1);
1352 
1353     values.Delete(STATUS);
1354     values.PutNull(STATUS);
1355     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1356     values.Delete(STATUS);
1357     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1358 
1359     values.Delete(DEVICE_TYPE_ID);
1360     values.PutNull(DEVICE_TYPE_ID);
1361     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1362     values.Delete(DEVICE_TYPE_ID);
1363     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1364 
1365     values.Delete(DEVICE_ID_HASH);
1366     values.PutNull(DEVICE_ID_HASH);
1367     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1368     values.Delete(DEVICE_ID_HASH);
1369     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1370 
1371     values.Delete(DEVICE_ID);
1372     values.PutNull(DEVICE_ID);
1373     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1374     values.Delete(DEVICE_ID);
1375     ProfileUtils::EntriesToTrustDeviceProfile(values, profile);
1376 }
1377 
1378 /**
1379  * @tc.name: EntriesToAccessControlProfile001
1380  * @tc.desc: EntriesToAccessControlProfile all failed.
1381  * @tc.type: FUNC
1382  * @tc.require:
1383  */
1384 HWTEST_F(ProfileUtilsTest, EntriesToAccessControlProfile001, TestSize.Level1)
1385 {
1386     ValuesBucket values;
1387     AccessControlProfile profile;
1388     ProfileUtils::EntriesToAccessControlProfile(values, profile);
1389     string strValue = "";
1390     bool ret = ProfileUtils::GetStringValue(values, SESSION_KEY, strValue);
1391     EXPECT_EQ(false, ret);
1392 }
1393 
1394 /**
1395  * @tc.name: EntriesToAccesser001
1396  * @tc.desc: EntriesToAccesser all .
1397  * @tc.type: FUNC
1398  * @tc.require:
1399  */
1400 HWTEST_F(ProfileUtilsTest, EntriesToAccesser001, TestSize.Level1)
1401 {
1402     ValuesBucket values;
1403     ValueObject valueObject;
1404     Accesser profile;
1405     int32_t intValue = 1;
1406     int64_t longValue = 1;
1407     string strValue = "strValue";
1408 
1409     values.PutLong(ACCESSER_ID, longValue);
1410     values.PutString(ACCESSER_DEVICE_ID, strValue);
1411     values.PutInt(ACCESSER_USER_ID, intValue);
1412     values.PutString(ACCESSER_ACCOUNT_ID, strValue);
1413     values.PutLong(ACCESSER_TOKEN_ID, longValue);
1414     values.PutString(ACCESSER_BUNDLE_NAME, strValue);
1415     values.PutInt(ACCESSER_BIND_LEVEL, intValue);
1416 
1417     ProfileUtils::EntriesToAccesser(values, profile);
1418     EXPECT_EQ("strValue", profile.GetAccesserBundleName());
1419 
1420     values.Clear();
1421     values.PutNull(ACCESSER_ID);
1422     values.PutNull(ACCESSER_DEVICE_ID);
1423     values.PutNull(ACCESSER_USER_ID);
1424     values.PutNull(ACCESSER_ACCOUNT_ID);
1425     values.PutNull(ACCESSER_TOKEN_ID);
1426     values.PutNull(ACCESSER_BUNDLE_NAME);
1427     values.PutNull(ACCESSER_BIND_LEVEL);
1428     EXPECT_EQ(true, values.GetObject(ACCESSER_ACCOUNT_ID, valueObject));
1429     EXPECT_EQ(false, valueObject.GetString(strValue) == E_OK);
1430     ProfileUtils::EntriesToAccesser(values, profile);
1431 
1432     values.Clear();
1433     EXPECT_EQ(false, values.GetObject(ACCESSER_ACCOUNT_ID, valueObject));
1434     ProfileUtils::EntriesToAccesser(values, profile);
1435 }
1436 
1437 /**
1438  * @tc.name: EntriesToAccessee001
1439  * @tc.desc: EntriesToAccessee all .
1440  * @tc.type: FUNC
1441  * @tc.require:
1442  */
1443 HWTEST_F(ProfileUtilsTest, EntriesToAccessee001, TestSize.Level1)
1444 {
1445     ValuesBucket values;
1446     ValueObject valueObject;
1447     Accessee profile;
1448     int32_t intValue = 1;
1449     int64_t longValue = 1;
1450     string strValue = "strValue";
1451 
1452     values.PutLong(ACCESSEE_ID, longValue);
1453     values.PutString(ACCESSEE_DEVICE_ID, strValue);
1454     values.PutInt(ACCESSEE_USER_ID, intValue);
1455     values.PutString(ACCESSEE_ACCOUNT_ID, strValue);
1456     values.PutLong(ACCESSEE_TOKEN_ID, longValue);
1457     values.PutString(ACCESSEE_BUNDLE_NAME, strValue);
1458     values.PutInt(ACCESSEE_BIND_LEVEL, intValue);
1459 
1460     ProfileUtils::EntriesToAccessee(values, profile);
1461     EXPECT_EQ("strValue", profile.GetAccesseeBundleName());
1462 
1463     values.Clear();
1464     values.PutNull(ACCESSEE_ID);
1465     values.PutNull(ACCESSEE_DEVICE_ID);
1466     values.PutNull(ACCESSEE_USER_ID);
1467     values.PutNull(ACCESSEE_ACCOUNT_ID);
1468     values.PutNull(ACCESSEE_TOKEN_ID);
1469     values.PutNull(ACCESSEE_BUNDLE_NAME);
1470     values.PutNull(ACCESSEE_BIND_LEVEL);
1471     EXPECT_EQ(true, values.GetObject(ACCESSEE_ACCOUNT_ID, valueObject));
1472     EXPECT_EQ(false, valueObject.GetString(strValue) == E_OK);
1473     ProfileUtils::EntriesToAccessee(values, profile);
1474 
1475     values.Clear();
1476     EXPECT_EQ(false, values.GetObject(ACCESSEE_ACCOUNT_ID, valueObject));
1477     ProfileUtils::EntriesToAccessee(values, profile);
1478 }
1479 
1480 /**
1481  * @tc.name: EntriesToDeviceProfile002
1482  * @tc.desc: EntriesToDeviceProfile failed all.
1483  * @tc.type: FUNC
1484  * @tc.require:
1485  */
1486 HWTEST_F(ProfileUtilsTest, EntriesToDeviceProfile002, TestSize.Level1)
1487 {
1488     DeviceProfile profile;
1489     map<string, string> values;
1490     values["key"] = "value";
1491     auto propertiesMap = ProfileUtils::GetProfilePropertiesMap(values);
1492     bool ret1 = ProfileUtils::IsPropertyValid(propertiesMap, DEVICE_NAME, MAX_STRING_LEN);
1493     EXPECT_EQ(false, ret1);
1494     ProfileUtils::EntriesToDeviceProfile(values, profile);
1495 
1496     for (int32_t i = 0; i < MAX_DB_RECORD_SIZE + 5; i++) {
1497         values[to_string(i)] = "value";
1498     }
1499     int32_t ret2 = ProfileUtils::EntriesToDeviceProfile(values, profile);
1500     EXPECT_EQ(DP_INVALID_PARAMS, ret2);
1501 }
1502 
1503 /**
1504  * @tc.name: EntriesToServiceProfile002
1505  * @tc.desc: EntriesToServiceProfile all.
1506  * @tc.type: FUNC
1507  * @tc.require:
1508  */
1509 HWTEST_F(ProfileUtilsTest, EntriesToServiceProfile002, TestSize.Level1)
1510 {
1511     map<string, string> values;
1512     ServiceProfile profile;
1513     string strValye = "";
1514     values[SERVICE_NAME] = "serviceName";
1515     values[SERVICE_TYPE] = "serviceType";
1516 
1517     int32_t ret1 = ProfileUtils::EntriesToServiceProfile(values, profile);
1518     EXPECT_EQ(DP_SUCCESS, ret1);
1519     EXPECT_EQ("", profile.GetServiceName());
1520 
1521     for (int32_t i = 0; i < MAX_STRING_LEN + 5; i++) {
1522         strValye += "a";
1523     }
1524     values[SERVICE_NAME] = strValye;
1525     values[SERVICE_TYPE] = strValye;
1526     auto propertiesMap = ProfileUtils::GetProfilePropertiesMap(values);
1527     EXPECT_EQ(false, propertiesMap.count(SERVICE_TYPE) != 0);
1528     EXPECT_EQ(false, 0 < propertiesMap[SERVICE_TYPE].length());
1529     EXPECT_EQ(true, propertiesMap[SERVICE_TYPE].length() < MAX_STRING_LEN);
1530     ProfileUtils::EntriesToServiceProfile(values, profile);
1531 
1532     values[SERVICE_NAME] = "";
1533     values[SERVICE_TYPE] = "";
1534     propertiesMap = ProfileUtils::GetProfilePropertiesMap(values);
1535     EXPECT_EQ(false, propertiesMap.count(SERVICE_TYPE) != 0);
1536     EXPECT_EQ(false, 0 < propertiesMap[SERVICE_TYPE].length());
1537     ProfileUtils::EntriesToServiceProfile(values, profile);
1538 
1539     values.erase(SERVICE_NAME);
1540     values.erase(SERVICE_TYPE);
1541     propertiesMap = ProfileUtils::GetProfilePropertiesMap(values);
1542     EXPECT_EQ(false, propertiesMap.count(SERVICE_TYPE) != 0);
1543     ProfileUtils::EntriesToServiceProfile(values, profile);
1544 
1545     for (int32_t i = 0; i < MAX_DB_RECORD_SIZE + 5; i++) {
1546         values[to_string(i)] = "value";
1547     }
1548     int32_t ret2 = ProfileUtils::EntriesToServiceProfile(values, profile);
1549     EXPECT_EQ(DP_INVALID_PARAMS, ret2);
1550 }
1551 
1552 /**
1553  * @tc.name: EntriesToCharProfile002
1554  * @tc.desc: EntriesToCharProfile all.
1555  * @tc.type: FUNC
1556  * @tc.require:
1557  */
1558 HWTEST_F(ProfileUtilsTest, EntriesToCharProfile002, TestSize.Level1)
1559 {
1560     map<string, string> values;
1561     CharacteristicProfile profile;
1562     string strValye = "";
1563     values[CHARACTERISTIC_KEY] = "characteristicKey";
1564     values[CHARACTERISTIC_VALUE] = "characteristicValue";
1565 
1566     int32_t ret1 = ProfileUtils::EntriesToCharProfile(values, profile);
1567     EXPECT_EQ(DP_SUCCESS, ret1);
1568     EXPECT_EQ("", profile.GetCharacteristicKey());
1569 
1570     for (int32_t i = 0; i < MAX_STRING_LEN + 5; i++) {
1571         strValye += "a";
1572     }
1573     values[CHARACTERISTIC_KEY] = strValye;
1574     values[CHARACTERISTIC_VALUE] = strValye;
1575     EXPECT_EQ(true, values.count(CHARACTERISTIC_KEY) != 0);
1576     EXPECT_EQ(true, 0 < values[CHARACTERISTIC_KEY].length());
1577     EXPECT_EQ(false, values[CHARACTERISTIC_KEY].length() < MAX_STRING_LEN);
1578     ProfileUtils::EntriesToCharProfile(values, profile);
1579 
1580     values[CHARACTERISTIC_KEY] = "";
1581     values[CHARACTERISTIC_VALUE] = "";
1582     EXPECT_EQ(true, values.count(CHARACTERISTIC_KEY) != 0);
1583     EXPECT_EQ(false, 0 < values[CHARACTERISTIC_KEY].length());
1584     ProfileUtils::EntriesToCharProfile(values, profile);
1585 
1586     values.erase(CHARACTERISTIC_KEY);
1587     values.erase(CHARACTERISTIC_VALUE);
1588     EXPECT_EQ(false, values.count(CHARACTERISTIC_KEY) != 0);
1589     ProfileUtils::EntriesToCharProfile(values, profile);
1590 
1591     for (int32_t i = 0; i < MAX_DB_RECORD_SIZE + 5; i++) {
1592         values[to_string(i)] = "value";
1593     }
1594     int32_t ret2 = ProfileUtils::EntriesToCharProfile(values, profile);
1595     EXPECT_EQ(DP_INVALID_PARAMS, ret2);
1596 }
1597 
1598 /**
1599  * @tc.name: GetDbKeyByProfile001
1600  * @tc.desc:
1601  * @tc.type: FUNC
1602  * @tc.require:
1603  */
1604 HWTEST_F(ProfileUtilsTest, GetDbKeyByProfile001, TestSize.Level1)
1605 {
1606     CharacteristicProfile charProfile;
1607     charProfile.SetDeviceId("deviceId");
1608     charProfile.SetServiceName("serviceName");
1609     charProfile.SetCharacteristicKey("characteristicKey");
1610     charProfile.SetCharacteristicValue("characteristicValue");
1611     string dbKey = "";
1612     string succDbkey = "char#deviceId#serviceName#characteristicKey#characteristicValue";
1613     string failDbkey = "";
1614     dbKey = ProfileUtils::GetDbKeyByProfile(charProfile);
1615     EXPECT_EQ(dbKey, succDbkey);
1616 
1617     charProfile.SetCharacteristicKey("");
1618     dbKey = ProfileUtils::GetDbKeyByProfile(charProfile);
1619     EXPECT_EQ(dbKey, failDbkey);
1620 
1621     charProfile.SetServiceName("");
1622     dbKey = ProfileUtils::GetDbKeyByProfile(charProfile);
1623     EXPECT_EQ(dbKey, failDbkey);
1624 
1625     charProfile.SetDeviceId("");
1626     dbKey = ProfileUtils::GetDbKeyByProfile(charProfile);
1627     EXPECT_EQ(dbKey, failDbkey);
1628 }
1629 
1630 /**
1631  * @tc.name: IsNumStr001
1632  * @tc.desc:
1633  * @tc.type: FUNC
1634  * @tc.require:
1635  */
1636 HWTEST_F(ProfileUtilsTest, IsNumStr001, TestSize.Level1)
1637 {
1638     bool isNumStr = ProfileUtils::IsNumStr("");
1639     EXPECT_EQ(isNumStr, false);
1640 }
1641 } // namespace DistributedDeviceProfile
1642 } // namespace OHOS
1643