• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "gtest/gtest.h"
16 #include "string_ex.h"
17 #include "test_log.h"
18 #include "tools.h"
19 
20 #define private public
21 #include "parse_util.h"
22 using namespace std;
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace SAMGR {
28 namespace {
29     const std::string TEST_RESOURCE_PATH = "/data/test/resource/samgr/profile/";
30     const std::u16string TEST_PROCESS_NAME = u"sa_test";
31     const int32_t TEST_NUM = 123;
32     const int32_t MOCK_SAID = 1492;
33     const int32_t TEST_PROFILE_SAID = 9999;
34     const int32_t TEST_PROFILE_SAID_INVAILD = 9990;
35 }
36 
37 class ParseUtilTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43 protected:
44     std::shared_ptr<ParseUtil> parser_;
45 };
46 
SetUpTestCase()47 void ParseUtilTest::SetUpTestCase()
48 {
49     DTEST_LOG << "SetUpTestCase" << std::endl;
50 }
51 
TearDownTestCase()52 void ParseUtilTest::TearDownTestCase()
53 {
54     DTEST_LOG << "TearDownTestCase" << std::endl;
55 }
56 
SetUp()57 void ParseUtilTest::SetUp()
58 {
59     DTEST_LOG << "SetUp" << std::endl;
60     if (parser_ == nullptr) {
61         parser_ = std::make_shared<ParseUtil>();
62     }
63 }
64 
TearDown()65 void ParseUtilTest::TearDown()
66 {
67     DTEST_LOG << "TearDown" << std::endl;
68     if (parser_ != nullptr) {
69         parser_->ClearResource();
70     }
71 }
72 
73 /**
74  * @tc.name: ParseSaProfile001
75  * @tc.desc: Verify if can load not exist file
76  * @tc.type: FUNC
77  */
78 HWTEST_F(ParseUtilTest, ParseSaProfile001, TestSize.Level2)
79 {
80     DTEST_LOG << " ParseSaProfile001 start " << std::endl;
81     /**
82      * @tc.steps: step1. parse not exsit config file
83      * @tc.expected: step1. return false when load not exist file
84      */
85     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "notExist");
86     EXPECT_FALSE(ret);
87 }
88 
89 /**
90  * @tc.name: ParseSaProfile002
91  * @tc.desc: Verify if can load invalid root file
92  * @tc.type: FUNC
93  */
94 HWTEST_F(ParseUtilTest, ParseSaProfile002, TestSize.Level2)
95 {
96     DTEST_LOG << " ParseSaProfile002 start " << std::endl;
97     /**
98      * @tc.steps: step1. load invalid root config file
99      * @tc.expected: step1. return false when load invalid format config file
100      */
101     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "invalid_root.xml");
102     EXPECT_FALSE(ret);
103 }
104 
105 /**
106  * @tc.name: ParseSaProfile003
107  * @tc.desc: Verify if can load normal profile
108  * @tc.type: FUNC
109  */
110 HWTEST_F(ParseUtilTest, ParseSaProfile003, TestSize.Level2)
111 {
112     DTEST_LOG << " ParseSaProfile003 start " << std::endl;
113     /**
114      * @tc.steps: step1. load correct system ability profile
115      * @tc.expected: step1. return true when load invalid format config file
116      */
117     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "profile.xml");
118     EXPECT_TRUE(ret);
119 }
120 
121 /**
122  * @tc.name: ParseSaProfile004
123  * @tc.desc: Verify if can load normal profile
124  * @tc.type: FUNC
125  */
126 HWTEST_F(ParseUtilTest, ParseSaProfile004, TestSize.Level2)
127 {
128     DTEST_LOG << " ParseSaProfile004 start " << std::endl;
129     /**
130      * @tc.steps: step1. load correct system ability profile
131      * @tc.expected: step1. return false when load noxmlfile
132      */
133     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "no_xml_file");
134     EXPECT_FALSE(ret);
135 }
136 
137 /**
138  * @tc.name: ParseSaProfile005
139  * @tc.desc: Verify if can load normal profile
140  * @tc.type: FUNC
141  */
142 HWTEST_F(ParseUtilTest, ParseSaProfile005, TestSize.Level2)
143 {
144     DTEST_LOG << " ParseSaProfile005 start " << std::endl;
145     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "empty_process.xml");
146     EXPECT_FALSE(ret);
147 }
148 
149 /**
150  * @tc.name: ParseSaProfile006
151  * @tc.desc: Verify if can load normal profile
152  * @tc.type: FUNC
153  */
154 HWTEST_F(ParseUtilTest, ParseSaProfile006, TestSize.Level2)
155 {
156     DTEST_LOG << " ParseSaProfile006 start " << std::endl;
157     /**
158      * @tc.steps: step1. load correct system ability profile
159      * @tc.expected: step1. return false when load invalid format config file
160      */
161     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "empty_systemability.xml");
162     EXPECT_FALSE(ret);
163 }
164 
165 /**
166  * @tc.name: GetSaProfiles001
167  * @tc.desc:  Verify if not load sa file return empty list
168  * @tc.type: FUNC
169  */
170 HWTEST_F(ParseUtilTest, GetSaProfiles001, TestSize.Level3)
171 {
172     DTEST_LOG << " GetSaProfiles001 start " << std::endl;
173     /**
174      * @tc.steps: step1. Get empty config when not parse sa file.
175      * @tc.expected: step1. return empty list when not load sa file
176      */
177     list<SaProfile> profiles = parser_->GetAllSaProfiles();
178     EXPECT_TRUE(profiles.empty());
179 }
180 
181 /**
182  * @tc.name: GetSaProfiles002
183  * @tc.desc:  Verify if can load normal sa profile
184  * @tc.type: FUNC
185  */
186 HWTEST_F(ParseUtilTest, GetSaProfiles002, TestSize.Level3)
187 {
188     DTEST_LOG << " GetSaProfiles002 start " << std::endl;
189     /**
190      * @tc.steps: step1. Get correct profile when parse sa file.
191      * @tc.expected: step1. return correct profile object when load correct config file
192      */
193     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "profile.xml");
194     ASSERT_TRUE(ret);
195     SaProfile saRunOnCreateTrue;
196     saRunOnCreateTrue.runOnCreate = true;
197     SaProfile saRunOnCreateFalse;
198     parser_->saProfiles_.emplace_back(saRunOnCreateTrue);
199     parser_->saProfiles_.emplace_back(saRunOnCreateFalse);
200     parser_->OpenSo();
201     list<SaProfile> profiles = parser_->GetAllSaProfiles();
202     if (!profiles.empty()) {
203         SaProfile& profile = *(profiles.begin());
204         EXPECT_EQ(profile.process, TEST_PROCESS_NAME);
205         EXPECT_EQ(profile.saId, TEST_PROFILE_SAID);
206     }
207 }
208 
209 /**
210  * @tc.name: ParseTrustConfig001
211  * @tc.desc:  Verify if can load file with one sa
212  * @tc.type: FUNC
213  */
214 HWTEST_F(ParseUtilTest, ParseTrustConfig001, TestSize.Level1)
215 {
216     DTEST_LOG << " ParseTrustConfig001 start " << std::endl;
217     /**
218      * @tc.steps: step1. Get correct map when parse config file.
219      * @tc.expected: step1. return correct profile object when load correct config file
220      */
221     std::map<std::u16string, std::set<int32_t>> values;
222     bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "test_trust_one_sa.xml", values);
223     ASSERT_TRUE(ret);
224     /**
225      * @tc.steps: step2. Check map values
226      * @tc.expected: step2. return expect values
227      */
228     for (const auto& [process, saIds] : values) {
229         EXPECT_EQ(Str16ToStr8(process), "test");
230         EXPECT_EQ(saIds.size(), 1);
231         EXPECT_EQ(saIds.count(1401), 1);
232     }
233 }
234 
235 /**
236  * @tc.name: ParseTrustConfig002
237  * @tc.desc:  Verify if can load file with muti sa
238  * @tc.type: FUNC
239  */
240 HWTEST_F(ParseUtilTest, ParseTrustConfig002, TestSize.Level1)
241 {
242     DTEST_LOG << " ParseTrustConfig002 start " << std::endl;
243     /**
244      * @tc.steps: step1. Get correct map when parse config file.
245      * @tc.expected: step1. return correct profile object when load correct config file
246      */
247     std::map<std::u16string, std::set<int32_t>> values;
248     bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "test_trust_muti_sa.xml", values);
249     ASSERT_TRUE(ret);
250     /**
251      * @tc.steps: step2. Check map values
252      * @tc.expected: step2. return expect values
253      */
254     for (const auto& [process, saIds] : values) {
255         EXPECT_EQ(Str16ToStr8(process), "test");
256         EXPECT_EQ(saIds.size(), 5);
257         EXPECT_EQ(saIds.count(1401), 1);
258     }
259 }
260 
261 /**
262  * @tc.name: ParseTrustConfig003
263  * @tc.desc:  Verify if can load not invalid root file
264  * @tc.type: FUNC
265  */
266 HWTEST_F(ParseUtilTest, ParseTrustConfig003, TestSize.Level1)
267 {
268     DTEST_LOG << " ParseTrustConfig003 start " << std::endl;
269     /**
270      * @tc.steps: step1. Get correct map when parse config file.
271      * @tc.expected: step1. return false when load invalid root file
272      */
273     std::map<std::u16string, std::set<int32_t>> values;
274     bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_root_trust.xml", values);
275     ASSERT_FALSE(ret);
276 }
277 
278 /**
279  * @tc.name: ParseTrustConfig004
280  * @tc.desc:  Verify if can load not exist file
281  * @tc.type: FUNC
282  */
283 HWTEST_F(ParseUtilTest, ParseTrustConfig004, TestSize.Level1)
284 {
285     DTEST_LOG << " ParseTrustConfig004 start " << std::endl;
286     /**
287      * @tc.steps: step1. Get correct profile when parse sa file.
288      * @tc.expected: step1. return false when not exist file
289      */
290     std::map<std::u16string, std::set<int32_t>> values;
291     bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "notExist", values);
292     ASSERT_FALSE(ret);
293 }
294 
295 /**
296  * @tc.name: ParseTrustConfig005
297  * @tc.desc:  Verify if can load invalid element config
298  * @tc.type: FUNC
299  */
300 HWTEST_F(ParseUtilTest, ParseTrustConfig005, TestSize.Level1)
301 {
302     DTEST_LOG << " ParseTrustConfig005 start " << std::endl;
303     /**
304      * @tc.steps: step1. Get correct profile when parse invalid element config.
305      * @tc.expected: step1. return correct profile object when load correct config file
306      */
307     std::map<std::u16string, std::set<int32_t>> values;
308     bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_element_trust.xml", values);
309     ASSERT_TRUE(ret);
310     for (const auto& [process, saIds] : values) {
311         EXPECT_EQ(Str16ToStr8(process), "test");
312         EXPECT_EQ(saIds.size(), 3);
313         EXPECT_EQ(saIds.count(1401), 1);
314     }
315 }
316 
317 /**
318  * @tc.name: ParseTrustConfig006
319  * @tc.desc:  Verify if can load invalid muti root file
320  * @tc.type: FUNC
321  */
322 HWTEST_F(ParseUtilTest, ParseTrustConfig006, TestSize.Level1)
323 {
324     DTEST_LOG << " ParseTrustConfig006 start " << std::endl;
325     /**
326      * @tc.steps: step1. Get correct profile when parse sa file.
327      * @tc.expected: step1. return correct profile object when load correct config file
328      */
329     std::map<std::u16string, std::set<int32_t>> values;
330     bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_muti_root_trust.xml", values);
331     ASSERT_FALSE(ret);
332 }
333 
334 /**
335  * @tc.name: RemoveSaProfile001
336  * @tc.desc:  Verify if can remove not-existed id
337  * @tc.type: FUNC
338  */
339 HWTEST_F(ParseUtilTest, RemoveSaProfile001, TestSize.Level3)
340 {
341     DTEST_LOG << " RemoveSaProfile001 start " << std::endl;
342     /**
343      * @tc.steps: step1. parse not exsit config file
344      * @tc.expected: step1. return false when load not exist file
345      */
346     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "notExist");
347     EXPECT_FALSE(ret);
348     /**
349      * @tc.steps: step2. remove not-existed id
350      * @tc.expected: step2. not crash
351      */
352     parser_->RemoveSaProfile(111);
353     auto profiles = parser_->GetAllSaProfiles();
354     EXPECT_EQ(profiles.size(), 0);
355 }
356 
357 /**
358  * @tc.name: RemoveSaProfile002
359  * @tc.desc:  Verify if can can remove not-existed id
360  * @tc.type: FUNC
361  */
362 HWTEST_F(ParseUtilTest, RemoveSaProfile002, TestSize.Level3)
363 {
364     DTEST_LOG << " RemoveSaProfile002 start " << std::endl;
365     /**
366      * @tc.steps: step1. parse multi-sa profile
367      * @tc.expected: step1. return true when load multi-sa profile
368      */
369     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
370     EXPECT_TRUE(ret);
371     auto profiles = parser_->GetAllSaProfiles();
372     EXPECT_EQ(profiles.size(), 4);
373     /**
374      * @tc.steps: step2. remove not-existed id
375      * @tc.expected: step2. not crash
376      */
377     parser_->RemoveSaProfile(111);
378     profiles = parser_->GetAllSaProfiles();
379     EXPECT_EQ(profiles.size(), 4);
380 }
381 
382 /**
383  * @tc.name: RemoveSaProfile003
384  * @tc.desc:  Verify if can remove one existed id
385  * @tc.type: FUNC
386  */
387 HWTEST_F(ParseUtilTest, RemoveSaProfile003, TestSize.Level3)
388 {
389     DTEST_LOG << " RemoveSaProfile003 start " << std::endl;
390     /**
391      * @tc.steps: step1. parse multi-sa profile
392      * @tc.expected: step1. return true when load multi-sa profile
393      */
394     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
395     EXPECT_TRUE(ret);
396     auto profiles = parser_->GetAllSaProfiles();
397     EXPECT_EQ(profiles.size(), 4);
398     /**
399      * @tc.steps: step2. remove one existed id
400      * @tc.expected: step2. remove successfully
401      */
402     parser_->RemoveSaProfile(9999);
403     profiles = parser_->GetAllSaProfiles();
404     EXPECT_EQ(profiles.size(), 3);
405 }
406 
407 /**
408  * @tc.name: RemoveSaProfile004
409  * @tc.desc:  Verify if can remove one existed id
410  * @tc.type: FUNC
411  */
412 HWTEST_F(ParseUtilTest, RemoveSaProfile004, TestSize.Level3)
413 {
414     DTEST_LOG << " RemoveSaProfile004 start " << std::endl;
415     /**
416      * @tc.steps: step1. parse multi-sa profile
417      * @tc.expected: step1. return true when load multi-sa profile
418      */
419     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
420     EXPECT_TRUE(ret);
421     auto profiles = parser_->GetAllSaProfiles();
422     EXPECT_EQ(profiles.size(), 4);
423     /**
424      * @tc.steps: step2. remove one existed id
425      * @tc.expected: step2. remove successfully
426      */
427     parser_->RemoveSaProfile(9997);
428     profiles = parser_->GetAllSaProfiles();
429     EXPECT_EQ(profiles.size(), 2);
430 }
431 
432 /**
433  * @tc.name: RemoveSaProfile005
434  * @tc.desc:  Verify if can remove more existed id
435  * @tc.type: FUNC
436  */
437 HWTEST_F(ParseUtilTest, RemoveSaProfile005, TestSize.Level3)
438 {
439     DTEST_LOG << " RemoveSaProfile004 start " << std::endl;
440     /**
441      * @tc.steps: step1. parse multi-sa profile
442      * @tc.expected: step1. return true when load multi-sa profile
443      */
444     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
445     EXPECT_TRUE(ret);
446     auto profiles = parser_->GetAllSaProfiles();
447     EXPECT_EQ(profiles.size(), 4);
448     /**
449      * @tc.steps: step2. remove more existed id
450      * @tc.expected: step2. remove successfully
451      */
452     parser_->RemoveSaProfile(9997);
453     parser_->RemoveSaProfile(9998);
454     parser_->RemoveSaProfile(9998);
455     profiles = parser_->GetAllSaProfiles();
456     EXPECT_EQ(profiles.size(), 1);
457 }
458 
459 /**
460  * @tc.name: CheckPathExist001
461  * @tc.desc:  Verify if can check not exist file
462  * @tc.type: FUNC
463  */
464 HWTEST_F(ParseUtilTest, CheckPathExist001, TestSize.Level2)
465 {
466     DTEST_LOG << " CheckPathExist001 start " << std::endl;
467     /**
468      * @tc.steps: step1. check not exsit config file
469      * @tc.expected: step1. return false when check not exist file
470      */
471     bool ret = parser_->CheckPathExist(TEST_RESOURCE_PATH + "not_exist.xml");
472     EXPECT_FALSE(ret);
473 }
474 
475 /**
476  * @tc.name: CheckPathExist002
477  * @tc.desc:  Verify if can check exist file
478  * @tc.type: FUNC
479  */
480 HWTEST_F(ParseUtilTest, CheckPathExist002, TestSize.Level2)
481 {
482     DTEST_LOG << " CheckPathExist002 start " << std::endl;
483     /**
484      * @tc.steps: step1. check exsit config file
485      * @tc.expected: step1. return true when load not exist file
486      */
487     bool ret = parser_->CheckPathExist(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
488     EXPECT_TRUE(ret);
489 }
490 
491 /**
492  * @tc.name: GetProfile001
493  * @tc.desc: Verify if can get not-exist profile
494  * @tc.type: FUNC
495  * @tc.require: I5KMF7
496  */
497 HWTEST_F(ParseUtilTest, GetProfile001, TestSize.Level2)
498 {
499     DTEST_LOG << " GetProfile001 start " << std::endl;
500     /**
501      * @tc.steps: step1. check exsit config file
502      * @tc.expected: step1. return true when load not exist file
503      */
504     SaProfile saProfile;
505     bool ret = parser_->GetProfile(TEST_PROFILE_SAID, saProfile);
506     EXPECT_EQ(ret, false);
507 }
508 
509 /**
510  * @tc.name: GetProfile002
511  * @tc.desc: Verify if can get exist profile
512  * @tc.type: FUNC
513  * @tc.require: I5KMF7
514  */
515 HWTEST_F(ParseUtilTest, GetProfile002, TestSize.Level2)
516 {
517     DTEST_LOG << " GetProfile002 start " << std::endl;
518     /**
519      * @tc.steps: step1. check exsit config file
520      * @tc.expected: step1. return true when load not exist file
521      */
522     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
523     EXPECT_EQ(ret, true);
524     SaProfile saProfile;
525     ret = parser_->GetProfile(TEST_PROFILE_SAID, saProfile);
526     EXPECT_EQ(ret, true);
527     EXPECT_EQ(saProfile.saId, TEST_PROFILE_SAID);
528     EXPECT_EQ(saProfile.runOnCreate, true);
529 }
530 
531 /**
532  * @tc.name: LoadSaLib001
533  * @tc.desc: Verify if can load salib
534  * @tc.type: FUNC
535  * @tc.require: I5KMF7
536  */
537 HWTEST_F(ParseUtilTest, LoadSaLib001, TestSize.Level2)
538 {
539     DTEST_LOG << " LoadSaLib001 start " << std::endl;
540     /**
541      * @tc.steps: step1. check exsit salib
542      * @tc.expected: step1. return true when load exist salib
543      */
544     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
545     EXPECT_EQ(ret, true);
546     ret = parser_->LoadSaLib(TEST_PROFILE_SAID);
547     EXPECT_EQ(ret, true);
548 }
549 
550 /**
551  * @tc.name: LoadSaLib002
552  * @tc.desc: Verify if can load salib
553  * @tc.type: FUNC
554  * @tc.require: I5KMF7
555  */
556 HWTEST_F(ParseUtilTest, LoadSaLib002, TestSize.Level2)
557 {
558     DTEST_LOG << " LoadSaLib002 start " << std::endl;
559     /**
560      * @tc.steps: step1. check exsit salib
561      * @tc.expected: step1. return false when load not exist salib
562      */
563     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
564     EXPECT_EQ(ret, true);
565     ret = parser_->LoadSaLib(TEST_PROFILE_SAID_INVAILD);
566     parser_->CloseSo(MOCK_SAID);
567     EXPECT_NE(ret, true);
568 }
569 
570 /**
571  * @tc.name: LoadSaLib003
572  * @tc.desc: Verify if can load salib
573  * @tc.type: FUNC
574  * @tc.require: I5KMF7
575  */
576 HWTEST_F(ParseUtilTest, LoadSaLib003, TestSize.Level2)
577 {
578     DTEST_LOG << " LoadSaLib003 start " << std::endl;
579     /**
580      * @tc.steps: step1. check exsit salib
581      * @tc.expected: step1. return false when load not exist salib
582      */
583     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "mock.xml");
584     EXPECT_EQ(ret, true);
585     ret = parser_->LoadSaLib(MOCK_SAID);
586     parser_->CloseSo(MOCK_SAID);
587     EXPECT_EQ(ret, true);
588 }
589 
590 /**
591  * @tc.name: LoadSaLib004
592  * @tc.desc: Verify if can load salib
593  * @tc.type: FUNC
594  * @tc.require: I5KMF7
595  */
596 HWTEST_F(ParseUtilTest, LoadSaLib004, TestSize.Level2)
597 {
598     DTEST_LOG << " LoadSaLib004 start " << std::endl;
599     /**
600      * @tc.steps: step1. check exsit salib
601      * @tc.expected: step1. return false when load not exist salib
602      */
603     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "mock.xml");
604     EXPECT_EQ(ret, true);
605     ret = parser_->LoadSaLib(MOCK_SAID);
606     EXPECT_EQ(ret, true);
607     parser_->LoadSaLib(MOCK_SAID);
608 }
609 
610 /**
611  * @tc.name: LoadSaLib005
612  * @tc.desc: Verify if can load salib
613  * @tc.type: FUNC
614  * @tc.require: I5KMF7
615  */
616 HWTEST_F(ParseUtilTest, LoadSaLib005, TestSize.Level2)
617 {
618     DTEST_LOG << " LoadSaLib005 start " << std::endl;
619     /**
620      * @tc.steps: step1. check exsit salib
621      * @tc.expected: step1. return false when load not exist salib
622      */
623     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "empty_libpath.xml");
624     EXPECT_EQ(ret, true);
625     ret = parser_->LoadSaLib(MOCK_SAID);
626     EXPECT_EQ(ret, true);
627 }
628 /**
629  * @tc.name: GetProcessName001
630  * @tc.desc: Verify if can get procesname
631  * @tc.type: FUNC
632  * @tc.require: I5KMF7
633  */
634 HWTEST_F(ParseUtilTest, GetProcessName001, TestSize.Level3)
635 {
636     DTEST_LOG << " GetProcessName001 " << std::endl;
637     /**
638      * @tc.steps: step1. get SaProfiles
639      * @tc.expected: step1. return true when SaProfiles
640      */
641     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
642     EXPECT_EQ(ret, true);
643     std::u16string Name = parser_->GetProcessName();
644     EXPECT_EQ(Str16ToStr8(Name), "test");
645 }
646 
647 /**
648  * @tc.name: GetProcessName002
649  * @tc.desc: Verify if can get procesname
650  * @tc.type: FUNC
651  * @tc.require: I5KMF7
652  */
653 HWTEST_F(ParseUtilTest, GetProcessName002, TestSize.Level3)
654 {
655     DTEST_LOG << " GetProcessName002 " << std::endl;
656     /**
657     * @tc.steps: step1. get SaProfiles
658     * @tc.expected: step1. return true when SaProfiles
659     */
660     bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml");
661     EXPECT_EQ(ret, true);
662     std::u16string Name = parser_->GetProcessName();
663     EXPECT_NE(Str16ToStr8(Name), "test_1");
664 }
665 
666 /**
667  * @tc.name: ParseSAProp001
668  * @tc.desc: Verify if can ParseSAProp
669  * @tc.type: FUNC
670  * @tc.require: I5KMF7
671  */
672 HWTEST_F(ParseUtilTest, ParseSAProp001, TestSize.Level3)
673 {
674     DTEST_LOG << " ParseSAProp001 " << std::endl;
675     string nodeName = "depend";
676     string nodeContent = "TEST";
677     SaProfile saProfile;
678     parser_->ParseSAProp(nodeName, nodeContent, saProfile);
679     EXPECT_EQ(saProfile.dependSa.size(), 1);
680 }
681 
682 /**
683  * @tc.name: ParseSAProp002
684  * @tc.desc: Verify if can ParseSAProp
685  * @tc.type: FUNC
686  * @tc.require: I5KMF7
687  */
688 HWTEST_F(ParseUtilTest, ParseSAProp002, TestSize.Level3)
689 {
690     DTEST_LOG << " ParseSAProp002 " << std::endl;
691     string nodeName = "depend-time-out";
692     string nodeContent = "123";
693     SaProfile saProfile;
694     parser_->ParseSAProp(nodeName, nodeContent, saProfile);
695     EXPECT_EQ(saProfile.dependTimeout, TEST_NUM);
696 }
697 
698 /**
699  * @tc.name: ParseSAProp003
700  * @tc.desc: Verify if can ParseSAProp
701  * @tc.type: FUNC
702  * @tc.require: I5KMF7
703  */
704 HWTEST_F(ParseUtilTest, ParseSAProp003, TestSize.Level3)
705 {
706     DTEST_LOG << " ParseSAProp003 " << std::endl;
707     string nodeName = "capability";
708     string nodeContent = "TEST";
709     SaProfile saProfile;
710     parser_->ParseSAProp(nodeName, nodeContent, saProfile);
711     EXPECT_EQ(nodeContent, Str16ToStr8(saProfile.capability));
712 }
713 
714 /**
715  * @tc.name: ParseSAProp004
716  * @tc.desc: Verify if can ParseSAProp
717  * @tc.type: FUNC
718  * @tc.require: I5KMF7
719  */
720 HWTEST_F(ParseUtilTest, ParseSAProp004, TestSize.Level3)
721 {
722     DTEST_LOG << " ParseSAProp004 " << std::endl;
723     string nodeName = "permission";
724     string nodeContent = "TEST";
725     SaProfile saProfile;
726     parser_->ParseSAProp(nodeName, nodeContent, saProfile);
727     EXPECT_EQ(nodeContent, Str16ToStr8(saProfile.permission));
728 }
729 
730 /**
731  * @tc.name: ParseSAProp005
732  * @tc.desc: Verify if can ParseSAProp
733  * @tc.type: FUNC
734  * @tc.require: I5KMF7
735  */
736 HWTEST_F(ParseUtilTest, ParseSAProp005, TestSize.Level3)
737 {
738     DTEST_LOG << " ParseSAProp005 " << std::endl;
739     string nodeName = "bootphase";
740     string nodeContent = "TEST";
741     SaProfile saProfile;
742     parser_->ParseSAProp(nodeName, nodeContent, saProfile);
743     EXPECT_EQ(nodeContent, Str16ToStr8(saProfile.bootPhase));
744 }
745 
746 /**
747  * @tc.name: ParseSystemAbility001
748  * @tc.desc: Verify if can ParseSystemAbility
749  * @tc.type: FUNC
750  * @tc.require: I5KMF7
751  */
752 HWTEST_F(ParseUtilTest, ParseSystemAbility001, TestSize.Level3)
753 {
754     DTEST_LOG << " ParseSystemAbility001 " << std::endl;
755     xmlNode rootNode;
756     rootNode.xmlChildrenNode = nullptr;
757     u16string process = u"tempprocess";
758     bool res = parser_->ParseSystemAbility(rootNode, process);
759     EXPECT_EQ(res, false);
760 }
761 
762 /**
763  * @tc.name: ParseSystemAbility002
764  * @tc.desc: Verify if can ParseSystemAbility
765  * @tc.type: FUNC
766  * @tc.require: I5KMF7
767  */
768 HWTEST_F(ParseUtilTest, ParseSystemAbility002, TestSize.Level3)
769 {
770     DTEST_LOG << " ParseSystemAbility002 " << std::endl;
771     xmlNode rootNode;
772     xmlNode tempNode;
773     xmlNode* childrenNode = &tempNode;
774     const char* nodeName = "test";
775     childrenNode->name = reinterpret_cast<const xmlChar*>(nodeName);
776     childrenNode->type = XML_PI_NODE;
777     childrenNode->content = nullptr;
778     childrenNode->next = nullptr;
779     rootNode.xmlChildrenNode = childrenNode;
780     u16string process = u"tempprocess";
781     bool res = parser_->ParseSystemAbility(rootNode, process);
782     EXPECT_EQ(res, true);
783 }
784 
785 /**
786  * @tc.name: ParseProcess001
787  * @tc.desc: Verify if can ParseProcess
788  * @tc.type: FUNC
789  * @tc.require: I5KMF7
790  */
791 HWTEST_F(ParseUtilTest, ParseProcess001, TestSize.Level3)
792 {
793     DTEST_LOG << " ParseProcess001 " << std::endl;
794     xmlNode tempNode;
795     xmlNode* rootNode = &tempNode;
796     u16string process = u"tempprocess";
797     bool res = parser_->ParseProcess(rootNode, process);
798     EXPECT_EQ(res, false);
799 }
800 
801 /**
802  * @tc.name: ParseProcess002
803  * @tc.desc: Verify if can ParseProcess
804  * @tc.type: FUNC
805  * @tc.require: I5KMF7
806  */
807 HWTEST_F(ParseUtilTest, ParseProcess002, TestSize.Level3)
808 {
809     DTEST_LOG << " ParseProcess002 " << std::endl;
810     xmlNode tempNode;
811     xmlNode* rootNode = &tempNode;
812     const char* nodeName = "test";
813     rootNode->name = reinterpret_cast<const xmlChar*>(nodeName);
814     rootNode->type = XML_PI_NODE;
815     rootNode->content = nullptr;
816     u16string process = u"tempprocess";
817     bool res = parser_->ParseProcess(rootNode, process);
818     EXPECT_EQ(res, false);
819 }
820 
821 /**
822  * @tc.name: ParseTrustConfigInner001
823  * @tc.desc: Verify if can ParseTrustConfigInner
824  * @tc.type: FUNC
825  * @tc.require: I5KMF7
826  */
827 HWTEST_F(ParseUtilTest, ParseTrustConfigInner001, TestSize.Level2)
828 {
829     DTEST_LOG << " ParseTrustConfigInner001 " << std::endl;
830     xmlNode tempNode;
831     xmlNode* rootNode = &tempNode;
832     rootNode->xmlChildrenNode = nullptr;
833     std::map<std::u16string, std::set<int32_t>> values;
834     bool res = parser_->ParseTrustConfigInner(rootNode, values);
835     EXPECT_EQ(res, false);
836 }
837 
838 /**
839  * @tc.name: ParseTrustConfigInner002
840  * @tc.desc: Verify if can ParseTrustConfigInner
841  * @tc.type: FUNC
842  * @tc.require: I5KMF7
843  */
844 HWTEST_F(ParseUtilTest, ParseTrustConfigInner002, TestSize.Level2)
845 {
846     DTEST_LOG << " ParseTrustConfigInner002 " << std::endl;
847     xmlNode rootNode;
848     xmlNode* rootNodeptr = &rootNode;
849     xmlNode tempNode;
850     xmlNode* childrenNode = &tempNode;
851     const char* nodeName = "name";
852     childrenNode->name = reinterpret_cast<const xmlChar*>(nodeName);
853     childrenNode->type = XML_PI_NODE;
854     childrenNode->content = nullptr;
855     childrenNode->next = nullptr;
856     rootNodeptr->xmlChildrenNode = childrenNode;
857     std::map<std::u16string, std::set<int32_t>> values;
858     bool res = parser_->ParseTrustConfigInner(rootNodeptr, values);
859     EXPECT_EQ(res, false);
860 }
861 
862 /**
863  * @tc.name: ParseSaid001
864  * @tc.desc: Verify if can ParseSaid
865  * @tc.type: FUNC
866  * @tc.require: I5KMF7
867  */
868 HWTEST_F(ParseUtilTest, ParseSaid001, TestSize.Level1)
869 {
870     DTEST_LOG << " ParseSaid001 " << std::endl;
871     xmlNode rootNode;
872     xmlNode* rootNodeptr = &rootNode;
873     rootNodeptr->name = nullptr;
874     int32_t tempSaId = -1;
875     bool res = parser_->ParseSaId(rootNodeptr, tempSaId);
876     EXPECT_EQ(res, false);
877 }
878 
879 /**
880  * @tc.name: ParseSaid002
881  * @tc.desc: Verify if can ParseSaid
882  * @tc.type: FUNC
883  * @tc.require: I5KMF7
884  */
885 HWTEST_F(ParseUtilTest, ParseSaid002, TestSize.Level1)
886 {
887     DTEST_LOG << " ParseSaid002 " << std::endl;
888     xmlNode rootNode;
889     xmlNode* rootNodeptr = &rootNode;
890     const char* nodeName = "noNull";
891     rootNodeptr->name = reinterpret_cast<const xmlChar*>(nodeName);
892     rootNodeptr->type = XML_PI_NODE;
893     rootNodeptr->content = nullptr;
894     int32_t tempSaId = -1;
895     bool res = parser_->ParseSaId(rootNodeptr, tempSaId);
896     EXPECT_EQ(res, false);
897 }
898 
899 /**
900  * @tc.name: DeleteAllMark001
901  * @tc.desc: Verify if can DeleteAllMark
902  * @tc.type: FUNC
903  * @tc.require: I5KMF7
904  */
905 HWTEST_F(ParseUtilTest, DeleteAllMark001, TestSize.Level3)
906 {
907     DTEST_LOG << " DeleteAllMark001 " << std::endl;
908     u16string temp = u"stests";
909     u16string mask = u"s";
910     u16string res = DeleteAllMark(temp, mask);
911     EXPECT_EQ(res, u"tet");
912 }
913 } // namespace SAMGR
914 } // namespace OHOS
915