• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #define protected public
20 #include "bool_wrapper.h"
21 #include "int_wrapper.h"
22 #include "long_wrapper.h"
23 #include "refbase.h"
24 #include "skills.h"
25 #include "string_wrapper.h"
26 #undef private
27 #undef protected
28 #include "patterns_matcher.h"
29 
30 using namespace testing::ext;
31 using namespace OHOS::AAFwk;
32 using OHOS::Parcel;
33 
34 namespace OHOS {
35 namespace AAFwk {
36 static const int LARGE_STR_LEN = 65534;
37 static const int SET_COUNT = 20;
38 static const int DISMATCH_TYPE = 67584;
39 static const int DISMATCH_DATA = -102;
40 class SkillsBaseTest : public testing::Test {
41 public:
SkillsBaseTest()42     SkillsBaseTest()
43     {}
~SkillsBaseTest()44     ~SkillsBaseTest()
45     {}
46     static void SetUpTestCase(void);
47     static void TearDownTestCase(void);
48     void SetUp();
49     void TearDown();
50 
51     std::shared_ptr<Skills> base_ = nullptr;
52     std::shared_ptr<PatternsMatcher> PatternsMatcherIn_ = nullptr;
53     void CompareSkills(const std::shared_ptr<Skills> &skills1, const std::shared_ptr<Skills> &skills2) const;
54 };
55 
SetUpTestCase(void)56 void SkillsBaseTest::SetUpTestCase(void)
57 {}
58 
TearDownTestCase(void)59 void SkillsBaseTest::TearDownTestCase(void)
60 {}
61 
SetUp(void)62 void SkillsBaseTest::SetUp(void)
63 {
64     base_ = std::make_shared<Skills>();
65     PatternsMatcherIn_ = std::make_shared<PatternsMatcher>();
66 }
67 
TearDown(void)68 void SkillsBaseTest::TearDown(void)
69 {}
70 
71 /**
72  * @tc.number: AaFwk_Skills_Parcelable_0100
73  * @tc.name: Marshalling/Unmarshalling
74  * @tc.desc: marshalling Skills, and then check result.
75  */
76 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Parcelable_0100, Function | MediumTest | Level1)
77 {
78     std::shared_ptr<Skills> SkillsIn_ = std::make_shared<Skills>();
79     if (SkillsIn_ == nullptr) {
80         return;
81     }
82     SkillsIn_->AddEntity("12345");
83     SkillsIn_->AddAction("12345");
84     SkillsIn_->AddAuthority("12345");
85     SkillsIn_->AddScheme("12345");
86     SkillsIn_->AddPath("12345");
87     SkillsIn_->AddSchemeSpecificPart("12345");
88     SkillsIn_->AddType("12345");
89     WantParams wantParams;
90     std::string keyStr = "12345667";
91     bool valueBool = true;
92     wantParams.SetParam(keyStr, Boolean::Box(valueBool));
93     SkillsIn_->SetWantParams(wantParams);
94 
95     Parcel in;
96     std::shared_ptr<Skills> SkillsOut_(Skills::Unmarshalling(in));
97     SkillsIn_->Marshalling(in);
98     if (SkillsOut_ != nullptr) {
99         CompareSkills(SkillsIn_, SkillsOut_);
100         EXPECT_EQ(valueBool, Boolean::Unbox(IBoolean::Query(SkillsOut_->GetWantParams().GetParam(keyStr))));
101     }
102 }
103 
104 /**
105  * @tc.number: AaFwk_Skills_Parcelable_0200
106  * @tc.name: Marshalling/Unmarshalling
107  * @tc.desc: marshalling Skills, and then check result.
108  */
109 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Parcelable_0200, Function | MediumTest | Level1)
110 {
111     std::shared_ptr<Skills> SkillsIn_ = std::make_shared<Skills>();
112     if (SkillsIn_ == nullptr) {
113         return;
114     }
115 
116     SkillsIn_->AddEntity("@#¥#3243adsafdf_中文");
117     SkillsIn_->AddAction("@#¥#3243adsafdf_中文");
118     SkillsIn_->AddAuthority("@#¥#3243adsafdf_中文");
119     SkillsIn_->AddScheme("@#¥#3243adsafdf_中文");
120     SkillsIn_->AddPath("@#¥#3243adsafdf_中文");
121     SkillsIn_->AddSchemeSpecificPart("@#¥#3243adsafdf_中文");
122     SkillsIn_->AddType("@#¥#3243adsafdf_中文");
123     WantParams wantParams;
124     std::string keyStr = "@#¥#3243adsafdf_中文";
125     long valueLong = 12345L;
126     wantParams.SetParam(keyStr, Long::Box(valueLong));
127     EXPECT_EQ(valueLong, Long::Unbox(ILong::Query(wantParams.GetParam(keyStr))));
128 
129     SkillsIn_->SetWantParams(wantParams);
130 
131     Parcel in;
132     SkillsIn_->Marshalling(in);
133     std::shared_ptr<Skills> SkillsOut_(Skills::Unmarshalling(in));
134 
135     if (SkillsOut_ != nullptr) {
136         CompareSkills(SkillsIn_, SkillsOut_);
137         std::string result = String::Unbox(IString::Query(SkillsOut_->GetWantParams().GetParam(keyStr)));
138         EXPECT_STREQ(std::to_string(valueLong).c_str(), result.c_str());
139     }
140 }
141 
142 /**
143  * @tc.number: AaFwk_Skills_Parcelable_0300
144  * @tc.name: Marshalling/Unmarshalling
145  * @tc.desc: marshalling Skills, and then check result.
146  */
147 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Parcelable_0300, Function | MediumTest | Level1)
148 {
149     std::shared_ptr<Skills> SkillsIn_ = std::make_shared<Skills>();
150     if (SkillsIn_ == nullptr) {
151         return;
152     }
153 
154     SkillsIn_->AddEntity("");
155     SkillsIn_->AddAction("");
156     SkillsIn_->AddAuthority("");
157     SkillsIn_->AddScheme("");
158     SkillsIn_->AddPath("");
159     SkillsIn_->AddSchemeSpecificPart("");
160     SkillsIn_->AddType("");
161     WantParams wantParams;
162     std::string keyStr = "";
163     int valueInt = 123;
164     wantParams.SetParam(keyStr, Integer::Box(valueInt));
165 
166     SkillsIn_->SetWantParams(wantParams);
167     EXPECT_EQ(valueInt, Integer::Unbox(IInteger::Query(wantParams.GetParam(keyStr))));
168 
169     Parcel in;
170     SkillsIn_->Marshalling(in);
171     std::shared_ptr<Skills> SkillsOut_(Skills::Unmarshalling(in));
172 
173     if (SkillsOut_ != nullptr) {
174         CompareSkills(SkillsIn_, SkillsOut_);
175         EXPECT_EQ(valueInt, Integer::Unbox(IInteger::Query(SkillsOut_->GetWantParams().GetParam(keyStr))));
176     }
177 }
178 
179 /**
180  * @tc.number: AaFwk_Skills_Parcelable_0400
181  * @tc.name: Marshalling/Unmarshalling
182  * @tc.desc: marshalling Skills, and then check result.
183  */
184 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Parcelable_0400, Function | MediumTest | Level1)
185 {
186     std::shared_ptr<Skills> SkillsIn_ = std::make_shared<Skills>();
187     if (SkillsIn_ == nullptr) {
188         return;
189     }
190     SkillsIn_->AddEntity("12345");
191     SkillsIn_->AddAction("12345");
192     SkillsIn_->AddAuthority("12345");
193     SkillsIn_->AddScheme("12345");
194     SkillsIn_->AddPath("12345");
195     SkillsIn_->AddSchemeSpecificPart("12345");
196     SkillsIn_->AddType("12345");
197     SkillsIn_->AddEntity("@#¥#3243adsafdf_中文");
198     SkillsIn_->AddAction("@#¥#3243adsafdf_中文");
199     SkillsIn_->AddAuthority("@#¥#3243adsafdf_中文");
200     SkillsIn_->AddScheme("@#¥#3243adsafdf_中文");
201     SkillsIn_->AddPath("@#¥#3243adsafdf_中文");
202     SkillsIn_->AddSchemeSpecificPart("@#¥#3243adsafdf_中文");
203     SkillsIn_->AddType("@#¥#3243adsafdf_中文");
204     SkillsIn_->AddEntity("");
205     SkillsIn_->AddAction("");
206     SkillsIn_->AddAuthority("");
207     SkillsIn_->AddScheme("");
208     SkillsIn_->AddPath("");
209     SkillsIn_->AddSchemeSpecificPart("");
210     SkillsIn_->AddType("");
211     WantParams wantParams;
212     std::string keyStr = "12345667";
213     std::string valueString = "123";
214     wantParams.SetParam(keyStr, String::Box(valueString));
215     SkillsIn_->SetWantParams(wantParams);
216 
217     Parcel in;
218     SkillsIn_->Marshalling(in);
219     std::shared_ptr<Skills> SkillsOut_(Skills::Unmarshalling(in));
220 
221     if (SkillsOut_ != nullptr) {
222         CompareSkills(SkillsIn_, SkillsOut_);
223         EXPECT_EQ(valueString, String::Unbox(IString::Query(SkillsOut_->GetWantParams().GetParam(keyStr))));
224     }
225 }
226 
CompareSkills(const std::shared_ptr<Skills> & skills1,const std::shared_ptr<Skills> & skills2) const227 void SkillsBaseTest::CompareSkills(const std::shared_ptr<Skills> &skills1, const std::shared_ptr<Skills> &skills2) const
228 {
229     EXPECT_EQ(skills1->CountEntities(), skills2->CountEntities());
230     EXPECT_EQ(skills1->CountActions(), skills2->CountActions());
231     EXPECT_EQ(skills1->CountAuthorities(), skills2->CountAuthorities());
232     EXPECT_EQ(skills1->CountSchemes(), skills2->CountSchemes());
233     EXPECT_EQ(skills1->CountPaths(), skills2->CountPaths());
234     EXPECT_EQ(skills1->CountSchemeSpecificParts(), skills2->CountSchemeSpecificParts());
235     EXPECT_EQ(skills1->CountTypes(), skills2->CountTypes());
236 
237     int count = skills1->CountEntities();
238     for (int i = 0; i < count; i++) {
239         EXPECT_EQ(skills1->GetEntity(i), skills1->GetEntity(i));
240     }
241     count = skills1->CountActions();
242     for (int i = 0; i < count; i++) {
243         EXPECT_EQ(skills1->GetAction(i), skills1->GetAction(i));
244     }
245     count = skills1->CountAuthorities();
246     for (int i = 0; i < count; i++) {
247         EXPECT_EQ(skills1->GetAuthority(i), skills1->GetAuthority(i));
248     }
249     count = skills1->CountSchemes();
250     for (int i = 0; i < count; i++) {
251         EXPECT_EQ(skills1->GetScheme(i), skills1->GetScheme(i));
252     }
253     count = skills1->CountPaths();
254     for (int i = 0; i < count; i++) {
255         EXPECT_EQ(skills1->GetPath(i), skills1->GetPath(i));
256     }
257     count = skills1->CountSchemeSpecificParts();
258     for (int i = 0; i < count; i++) {
259         EXPECT_EQ(skills1->GetSchemeSpecificPart(i), skills1->GetSchemeSpecificPart(i));
260     }
261     count = skills1->CountTypes();
262     for (int i = 0; i < count; i++) {
263         EXPECT_EQ(skills1->GetType(i), skills1->GetType(i));
264     }
265 
266     std::set<std::string> key1;
267     std::set<std::string> key2;
268     key1 = skills1->GetWantParams().KeySet();
269     key2 = skills2->GetWantParams().KeySet();
270     EXPECT_EQ(key1.size(), key2.size());
271 
272     if (key1.size() > 0 && key2.size() > 0) {
273         std::set<std::string>::iterator iter1 = key1.begin();
274         std::set<std::string>::iterator iter2 = key2.begin();
275         for (; (iter1 != key1.end() && iter2 != key2.end()); iter1++, iter2++) {
276             EXPECT_EQ(*iter1, *iter2);
277         }
278     }
279 }
280 
281 /**
282  * @tc.number: AaFwk_Skills_Entities_0100
283  * @tc.name: CountEntitie/HasEntity/GetEntity
284  * @tc.desc: Verify the function when the input string contains special characters.
285  */
286 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Entities_0100, Function | MediumTest | Level1)
287 {
288     std::string empty;
289     std::string entities = "entities.system.test";
290     EXPECT_EQ(0, base_->CountEntities());
291     EXPECT_EQ(false, base_->HasEntity(entities));
292     EXPECT_EQ(empty, base_->GetEntity(0));
293 
294     base_->RemoveEntity(entities);
295     EXPECT_EQ(0, base_->CountEntities());
296     EXPECT_EQ(false, base_->HasEntity(entities));
297 }
298 /**
299  * @tc.number: AaFwk_Skills_GetEntities_0100
300  * @tc.name: AddEntity and GetEntities
301  * @tc.desc: Verify AddEntity and GetEntities.
302  */
303 HWTEST_F(SkillsBaseTest, AaFwk_Skills_GetEntities_0100, Function | MediumTest | Level1)
304 {
305     std::string entity = "12345667";
306     base_->AddEntity(entity);
307 
308     size_t length = base_->GetEntities().size();
309 
310     EXPECT_EQ((size_t)1, length);
311     EXPECT_EQ(entity, base_->GetEntities().at(0));
312 }
313 
314 /**
315  * @tc.number: AaFwk_Skills_Authorities_0100
316  * @tc.name: CountEntitie/HasEntity/GetEntity
317  * @tc.desc: Verify the function when the input string has a long size.
318  */
319 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Authorities_0100, Function | MediumTest | Level1)
320 {
321     std::string empty;
322     std::string authorities = "authorities.system.test";
323     EXPECT_EQ(0, base_->CountAuthorities());
324     EXPECT_EQ(false, base_->HasAuthority(authorities));
325     EXPECT_EQ(empty, base_->GetAuthority(0));
326 
327     base_->RemoveAuthority(authorities);
328     EXPECT_EQ(0, base_->CountAuthorities());
329     EXPECT_EQ(false, base_->HasAuthority(authorities));
330 }
331 
332 /**
333  * @tc.number: AaFwk_Skills_Path_0300
334  * @tc.name: CountPaths/HasPath/GetPath
335  * @tc.desc: Verify the function when the input string is overrided.
336  */
337 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Path_0300, Function | MediumTest | Level1)
338 {
339     std::string empty;
340     std::string path = "paths.system.test";
341     PatternsMatcher pm(path, MatchType::DEFAULT);
342     base_->AddPath(pm);
343 
344     EXPECT_EQ(1, base_->CountPaths());
345     EXPECT_EQ(true, base_->HasPath(path));
346     EXPECT_EQ(path, base_->GetPath(0));
347 
348     base_->RemovePath(pm);
349     EXPECT_EQ(0, base_->CountPaths());
350     EXPECT_EQ(false, base_->HasPath(path));
351 
352     Parcel parcel;
353     EXPECT_EQ(true, base_->Marshalling(parcel));
354 }
355 
356 /**
357  * @tc.number: AaFwk_Skills_Action_0100
358  * @tc.name: AddAction/CountActions/HasAction/GetAction
359  * @tc.desc: Verify the function when the input string is set 20 times.
360  */
361 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Action_0100, Function | MediumTest | Level1)
362 {
363     std::string empty;
364     std::string action = "action.system.test";
365     int actionCount = 1;
366 
367     for (int i = 0; i < SET_COUNT; i++) {
368         base_->AddAction(action);
369     }
370 
371     EXPECT_EQ(actionCount, base_->CountActions());
372     EXPECT_EQ(true, base_->HasAction(action));
373     EXPECT_EQ(action, base_->GetAction(0));
374 
375     base_->RemoveAction(action);
376     EXPECT_EQ(0, base_->CountActions());
377     EXPECT_EQ(false, base_->HasAction(action));
378 }
379 
380 /**
381  * @tc.number: AaFwk_Skills_ActionsIterator_0100
382  * @tc.name: ActionsIterator
383  * @tc.desc: Test the function of ActionsIterator.
384  */
385 HWTEST_F(SkillsBaseTest, AaFwk_Skills_ActionsIterator_0100, Function | MediumTest | Level1)
386 {
387     base_->actions_.push_back("a");
388     base_->actions_.push_back("b");
389     auto iter = base_->ActionsIterator();
390 
391     EXPECT_EQ(*iter, "a");
392 }
393 
394 /**
395  * @tc.number: AaFwk_Skills_Entity_0100
396  * @tc.name: CountEntities/HasEntity/CountEntities/GetEntity
397  * @tc.desc: Verify the function when the input string is default.
398  */
399 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Entity_0100, Function | MediumTest | Level1)
400 {
401     std::string empty;
402     std::string entity = "entity.system.test";
403     int entityCount = 1;
404 
405     for (int i = 0; i < SET_COUNT; i++) {
406         base_->AddEntity(entity);
407     }
408 
409     EXPECT_EQ(entityCount, base_->CountEntities());
410     EXPECT_EQ(true, base_->HasEntity(entity));
411     EXPECT_EQ(entity, base_->GetEntity(0));
412 
413     base_->RemoveEntity(entity);
414     EXPECT_EQ(0, base_->CountEntities());
415     EXPECT_EQ(false, base_->HasEntity(entity));
416 }
417 
418 /**
419  * @tc.number: AaFwk_Skills_Authority_0100
420  * @tc.name: CountAuthorities/HasAuthority/GetAuthority
421  * @tc.desc: Verify the function when the input string contains special characters.
422  */
423 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Authority_0100, Function | MediumTest | Level1)
424 {
425     std::string empty;
426     std::string authority = "Authority.system.test";
427     int authorityCount = 1;
428 
429     for (int i = 0; i < SET_COUNT; i++) {
430         base_->AddAuthority(authority);
431     }
432 
433     EXPECT_EQ(authorityCount, base_->CountAuthorities());
434     EXPECT_EQ(true, base_->HasAuthority(authority));
435     EXPECT_EQ(authority, base_->GetAuthority(0));
436 
437     base_->RemoveAuthority(authority);
438     EXPECT_EQ(0, base_->CountAuthorities());
439     EXPECT_EQ(false, base_->HasAuthority(authority));
440 }
441 
442 /**
443  * @tc.number: AaFwk_Skills_Path_0100
444  * @tc.name: CountPaths/HasPath/GetPath
445  * @tc.desc: Verify the function when the input string contains special characters.
446  */
447 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Path_0100, Function | MediumTest | Level1)
448 {
449     std::string empty;
450     std::string path = "Path.system.test";
451     int pathCount = 1;
452 
453     for (int i = 0; i < SET_COUNT; i++) {
454         base_->AddPath(path);
455     }
456 
457     EXPECT_EQ(pathCount, base_->CountPaths());
458     EXPECT_EQ(true, base_->HasPath(path));
459     EXPECT_EQ(path, base_->GetPath(0));
460 
461     base_->RemovePath(path);
462     EXPECT_EQ(0, base_->CountPaths());
463     EXPECT_EQ(false, base_->HasPath(path));
464 }
465 
466 /**
467  * @tc.number: AaFwk_Skills_Scheme_0100
468  * @tc.name: CountSchemes/HasScheme/GetScheme
469  * @tc.desc: Verify the function when the input string contains special characters.
470  */
471 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Scheme_0100, Function | MediumTest | Level1)
472 {
473     std::string empty;
474     std::string scheme = "scheme.system.test";
475     int schemeCount = 1;
476 
477     for (int i = 0; i < SET_COUNT; i++) {
478         base_->AddScheme(scheme);
479     }
480 
481     EXPECT_EQ(schemeCount, base_->CountSchemes());
482     EXPECT_EQ(true, base_->HasScheme(scheme));
483     EXPECT_EQ(scheme, base_->GetScheme(0));
484 
485     base_->RemoveScheme(scheme);
486     EXPECT_EQ(0, base_->CountSchemes());
487     EXPECT_EQ(false, base_->HasScheme(scheme));
488 }
489 
490 /**
491  * @tc.number: AaFwk_Skills_SchemeSpecificPart_0100
492  * @tc.name: CountSchemeSpecificParts/HasSchemeSpecificPart/GetSchemeSpecificPart
493  * @tc.desc: Verify the function when the input string contains special characters.
494  */
495 HWTEST_F(SkillsBaseTest, AaFwk_Skills_SchemeSpecificPart_0100, Function | MediumTest | Level1)
496 {
497     std::string empty;
498     std::string schemespecificpart = "schemespecificpart.system.test";
499     int schemespecificpartCount = 1;
500 
501     for (int i = 0; i < SET_COUNT; i++) {
502         base_->AddSchemeSpecificPart(schemespecificpart);
503     }
504 
505     EXPECT_EQ(schemespecificpartCount, base_->CountSchemeSpecificParts());
506     EXPECT_EQ(true, base_->HasSchemeSpecificPart(schemespecificpart));
507     EXPECT_EQ(schemespecificpart, base_->GetSchemeSpecificPart(0));
508 
509     base_->RemoveSchemeSpecificPart(schemespecificpart);
510     EXPECT_EQ(0, base_->CountSchemeSpecificParts());
511     EXPECT_EQ(false, base_->HasSchemeSpecificPart(schemespecificpart));
512 }
513 
514 /**
515  * @tc.number: AaFwk_Skills_Type_0100
516  * @tc.name: CountTypes/HasType/GetType
517  * @tc.desc: Verify the function when the input string contains special characters.
518  */
519 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Type_0100, Function | MediumTest | Level1)
520 {
521     std::string empty;
522     std::string type = "type/system.test";
523     int typeCount = 1;
524 
525     for (int i = 0; i < SET_COUNT; i++) {
526         base_->AddType(type);
527     }
528 
529     EXPECT_EQ(typeCount, base_->CountTypes());
530     EXPECT_EQ(true, base_->HasType(type));
531     EXPECT_EQ(type, base_->GetType(0));
532 
533     base_->RemoveType(type);
534     EXPECT_EQ(0, base_->CountTypes());
535     EXPECT_EQ(false, base_->HasType(type));
536 }
537 
538 /**
539  * @tc.number: AaFwk_Skills_Actions_0100
540  * @tc.name: CountActions/HasAuthority/GetAuthority
541  * @tc.desc: Verify the function when the input string contains special characters.
542  */
543 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Actions_0100, Function | MediumTest | Level1)
544 {
545     std::string empty;
546     std::string actions = "actions.system.test";
547     EXPECT_EQ(0, base_->CountActions());
548     EXPECT_EQ(false, base_->HasAuthority(actions));
549     EXPECT_EQ(empty, base_->GetAuthority(0));
550 
551     base_->RemoveAuthority(actions);
552     EXPECT_EQ(0, base_->CountActions());
553     EXPECT_EQ(false, base_->HasAuthority(actions));
554 }
555 
556 /**
557  * @tc.number: AaFwk_Skills_Schemes_0100
558  * @tc.name: CountSchemes/HasAuthority/GetAuthority
559  * @tc.desc: Verify the function when the input string contains special characters.
560  */
561 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Schemes_0100, Function | MediumTest | Level1)
562 {
563     std::string empty;
564     std::string schemes = "schemes.system.test";
565     EXPECT_EQ(0, base_->CountSchemes());
566     EXPECT_EQ(false, base_->HasAuthority(schemes));
567     EXPECT_EQ(empty, base_->GetAuthority(0));
568 
569     base_->RemoveAuthority(schemes);
570     EXPECT_EQ(0, base_->CountSchemes());
571     EXPECT_EQ(false, base_->HasAuthority(schemes));
572 }
573 
574 /**
575  * @tc.number: AaFwk_Skills_SchemeSpecificParts_0100
576  * @tc.name: CountSchemeSpecificParts/HasAuthority/GetAuthority
577  * @tc.desc: Verify the function when the input string contains special characters.
578  */
579 HWTEST_F(SkillsBaseTest, AaFwk_Skills_SchemeSpecificParts_0100, Function | MediumTest | Level1)
580 {
581     std::string empty;
582     std::string schemespecificparts = "schemespecificparts.system.test";
583     EXPECT_EQ(0, base_->CountSchemeSpecificParts());
584     EXPECT_EQ(false, base_->HasAuthority(schemespecificparts));
585     EXPECT_EQ(empty, base_->GetAuthority(0));
586 
587     base_->RemoveAuthority(schemespecificparts);
588     EXPECT_EQ(0, base_->CountSchemeSpecificParts());
589     EXPECT_EQ(false, base_->HasAuthority(schemespecificparts));
590 }
591 
592 /**
593  * @tc.number: AaFwk_Skills_Types_0100
594  * @tc.name: CountTypes/HasAuthority/GetAuthority
595  * @tc.desc: Verify the function when the input string contains special characters.
596  */
597 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Types_0100, Function | MediumTest | Level1)
598 {
599     std::string empty;
600     std::string types = "types.system.test";
601     GTEST_LOG_(INFO) << "---------------a ";
602     EXPECT_EQ(0, base_->CountTypes());
603     GTEST_LOG_(INFO) << "---------------b ";
604     EXPECT_EQ(false, base_->HasAuthority(types));
605     GTEST_LOG_(INFO) << "---------------1 ";
606     EXPECT_EQ(empty, base_->GetAuthority(0));
607     GTEST_LOG_(INFO) << "---------------2 ";
608 
609     base_->RemoveAuthority(types);
610     EXPECT_EQ(0, base_->CountTypes());
611     EXPECT_EQ(false, base_->HasAuthority(types));
612 }
613 
614 /**
615  * @tc.number: AaFwk_Skills_Action_0200
616  * @tc.name: CountActions/HasAction/GetAction
617  * @tc.desc: Verify the function when action is not exist.
618  */
619 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Action_0200, Function | MediumTest | Level1)
620 {
621     std::string empty;
622     std::string action = "action.system.test";
623     EXPECT_EQ(0, base_->CountActions());
624     EXPECT_EQ(false, base_->HasAction(action));
625     EXPECT_EQ(empty, base_->GetAction(0));
626 
627     base_->RemoveAction(action);
628     EXPECT_EQ(0, base_->CountActions());
629     EXPECT_EQ(false, base_->HasAction(action));
630 }
631 
632 /**
633  * @tc.number: AaFwk_Skills_Authority_0200
634  * @tc.name: CountAuthorities/HasAuthority/GetAuthority
635  * @tc.desc: Verify the function when action is not exist.
636  */
637 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Authority_0200, Function | MediumTest | Level1)
638 {
639     std::string empty;
640     std::string authority = "authority.system.test";
641     EXPECT_EQ(0, base_->CountAuthorities());
642     EXPECT_EQ(false, base_->HasAuthority(authority));
643     EXPECT_EQ(empty, base_->GetAuthority(0));
644 
645     base_->RemoveAuthority(authority);
646     EXPECT_EQ(0, base_->CountAuthorities());
647     EXPECT_EQ(false, base_->HasAuthority(authority));
648 }
649 
650 /**
651  * @tc.number: AaFwk_Skills_Path_0200
652  * @tc.name: CountPaths/HasPath/GetPath
653  * @tc.desc: Verify the function when action is not exist.
654  */
655 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Path_0200, Function | MediumTest | Level1)
656 {
657     std::string empty;
658     std::string path = "path.system.test";
659     base_->AddPath(path, MatchType::DEFAULT);
660 
661     EXPECT_EQ(1, base_->CountPaths());
662     EXPECT_EQ(true, base_->HasPath(path));
663     EXPECT_EQ(path, base_->GetPath(0));
664 
665     base_->RemovePath(path, MatchType::DEFAULT);
666     EXPECT_EQ(0, base_->CountPaths());
667     EXPECT_EQ(false, base_->HasPath(path));
668 }
669 
670 /**
671  * @tc.number: AaFwk_Skills_Scheme_0200
672  * @tc.name: CountSchemes/HasScheme/GetScheme
673  * @tc.desc: Verify the function when action is not exist.
674  */
675 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Scheme_0200, Function | MediumTest | Level1)
676 {
677     std::string empty;
678     std::string scheme = "scheme.system.test";
679     EXPECT_EQ(0, base_->CountSchemes());
680     EXPECT_EQ(false, base_->HasScheme(scheme));
681     EXPECT_EQ(empty, base_->GetScheme(0));
682 
683     base_->RemoveScheme(scheme);
684     EXPECT_EQ(0, base_->CountSchemes());
685     EXPECT_EQ(false, base_->HasScheme(scheme));
686 }
687 
688 /**
689  * @tc.number: AaFwk_Skills_SchemeSpecificPart_0200
690  * @tc.name: CountSchemeSpecificParts/HasSchemeSpecificPart/GetSchemeSpecificPart
691  * @tc.desc: Verify the function when action is not exist.
692  */
693 HWTEST_F(SkillsBaseTest, AaFwk_Skills_SchemeSpecificPart_0200, Function | MediumTest | Level1)
694 {
695     std::string empty;
696     std::string schemespecificpart = "schemespecificpart.system.test";
697     EXPECT_EQ(0, base_->CountSchemeSpecificParts());
698     EXPECT_EQ(false, base_->HasSchemeSpecificPart(schemespecificpart));
699     EXPECT_EQ(empty, base_->GetSchemeSpecificPart(0));
700 
701     base_->RemoveSchemeSpecificPart(schemespecificpart);
702     EXPECT_EQ(0, base_->CountSchemeSpecificParts());
703     EXPECT_EQ(false, base_->HasSchemeSpecificPart(schemespecificpart));
704 }
705 
706 /**
707  * @tc.number: AaFwk_Skills_Type_0300
708  * @tc.name: CountTypes/HasType/GetType
709  * @tc.desc: Verify the function when action is not exist.
710  */
711 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Type_0300, Function | MediumTest | Level1)
712 {
713     std::string empty;
714     std::string type = "type.system.test";
715     EXPECT_EQ(0, base_->CountTypes());
716 
717     EXPECT_EQ(false, base_->HasType(type));
718     EXPECT_EQ(empty, base_->GetType(0));
719 
720     base_->RemoveType(type);
721     EXPECT_EQ(0, base_->CountTypes());
722     EXPECT_EQ(false, base_->HasType(type));
723 }
724 
725 using SkillsMatchType = std::tuple<std::string, std::string, bool>;
726 class SkillsMatchTest : public testing::TestWithParam<SkillsMatchType> {
727 public:
SkillsMatchTest()728     SkillsMatchTest()
729     {}
~SkillsMatchTest()730     ~SkillsMatchTest()
731     {}
732     static void SetUpTestCase(void);
733     static void TearDownTestCase(void);
734     void SetUp();
735     void TearDown();
736     std::shared_ptr<Skills> skills_ = nullptr;
737 };
738 
SetUpTestCase(void)739 void SkillsMatchTest::SetUpTestCase(void)
740 {}
741 
TearDownTestCase(void)742 void SkillsMatchTest::TearDownTestCase(void)
743 {}
744 
SetUp(void)745 void SkillsMatchTest::SetUp(void)
746 {
747     skills_ = std::make_shared<Skills>();
748 }
749 
TearDown(void)750 void SkillsMatchTest::TearDown(void)
751 {}
752 
753 /**
754  * @tc.number: AaFwk_Skills_match_0100
755  * @tc.name: CountTypes/HasType/GetType
756  * @tc.desc: Verify whether parameter change.
757  */
758 HWTEST_P(SkillsMatchTest, AaFwk_Skills_match_0100, Function | MediumTest | Level1)
759 {
760     std::string filterEntity = "entity.system.entity1";
761     std::string filterAction1 = "action.system.action1";
762     std::string filterAction2 = "action.system.action2";
763     std::string wantEntity = std::get<0>(GetParam());
764     std::string wantAction = std::get<1>(GetParam());
765     bool result = std::get<2>(GetParam());
766 
767     skills_->AddEntity(filterEntity);
768     skills_->AddAction(filterAction1);
769     skills_->AddAction(filterAction2);
770 
771     Want want;
772     want.AddEntity(wantEntity);
773     want.SetAction(wantAction);
774 
775     EXPECT_EQ(result, skills_->Match(want));
776 }
777 
778 INSTANTIATE_TEST_SUITE_P(SkillsMatchTestP, SkillsMatchTest,
779     testing::Values(SkillsMatchType("entity.system.entityA", "action.system.actionA", false),
780         SkillsMatchType("entity.system.entity1", "action.system.actionA", false),
781         SkillsMatchType("entity.system.entityA", "action.system.action2", false),
782         SkillsMatchType("entity.system.entity1", "action.system.action1", true)));
783 
784 /**
785  * @tc.name: AaFwk_Skills_match_0200
786  * @tc.desc: Verify Matching rules action segment
787  * @tc.type: FUNC
788  * @tc.require: I5PZK2
789  */
790 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0200, Function | MediumTest | Level1)
791 {
792     Skills skills;
793     std::string filterEntity = "entity.system.entity1";
794     skills.AddEntity(filterEntity);
795     Want want;
796     want.AddEntity(filterEntity);
797     // Both actions are empty.
798     EXPECT_EQ(true, skills.Match(want));
799 }
800 
801 /**
802  * @tc.name: AaFwk_Skills_match_0300
803  * @tc.desc: Verify Matching rules action segment
804  * @tc.type: FUNC
805  * @tc.require: I5PZK2
806  */
807 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0300, Function | MediumTest | Level1)
808 {
809     Skills skills;
810     std::string filterEntity = "entity.system.entity1";
811     skills.AddEntity(filterEntity);
812     Want want;
813     want.AddEntity(filterEntity);
814     want.SetAction("action.system.action1");
815     // empty actions in skill vs non-empty actions in want
816     EXPECT_EQ(false, skills.Match(want));
817 }
818 
819 /**
820  * @tc.name: AaFwk_Skills_match_0400
821  * @tc.desc: Verify Matching rules action segment
822  * @tc.type: FUNC
823  * @tc.require: I5PZK2
824  */
825 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0400, Function | MediumTest | Level1)
826 {
827     Skills skills;
828     std::string filterEntity = "entity.system.entity1";
829     std::string filterAction1 = "action.system.action1";
830     std::string filterAction2 = "action.system.action2";
831     skills.AddEntity(filterEntity);
832     skills.AddAction(filterAction1);
833     skills.AddAction(filterAction2);
834     Want want;
835     want.AddEntity(filterEntity);
836     want.SetAction(filterAction1);
837     // actions that in skill contains non-empty actions in want
838     EXPECT_EQ(true, skills.Match(want));
839 }
840 
841 /**
842  * @tc.name: AaFwk_Skills_match_0500
843  * @tc.desc: Verify Matching rules action segment
844  * @tc.type: FUNC
845  * @tc.require: I5PZK2
846  */
847 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0600, Function | MediumTest | Level1)
848 {
849     Skills skills;
850     std::string filterEntity = "entity.system.entity1";
851     std::string filterAction1 = "action.system.action1";
852     std::string filterAction2 = "action.system.action2";
853     skills.AddEntity(filterEntity);
854     skills.AddAction(filterAction2);
855     Want want;
856     want.AddEntity(filterEntity);
857     // non-empty actions that in skill vs empty actions in want
858     EXPECT_EQ(false, skills.Match(want));
859 }
860 
861 /**
862  * @tc.name: AaFwk_Skills_match_0600
863  * @tc.desc: Verify Matching rules action segment
864  * @tc.type: FUNC
865  * @tc.require: I5PZK2
866  */
867 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0500, Function | MediumTest | Level1)
868 {
869     Skills skills;
870     std::string filterEntity = "entity.system.entity1";
871     std::string filterAction1 = "action.system.action1";
872     std::string filterAction2 = "action.system.action2";
873     skills.AddEntity(filterEntity);
874     skills.AddAction(filterAction2);
875     Want want;
876     want.AddEntity(filterEntity);
877     want.SetAction(filterAction1);
878     // actions that in skill doesn't contain non-empty actions in want
879     EXPECT_EQ(false, skills.Match(want));
880 }
881 
882 /**
883  * @tc.number: AaFwk_Skills_Skills_0100
884  * @tc.name: Skills() and Skills(Skills)
885  * @tc.desc:  Verify Skills().
886  */
887 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Skills_0100, Function | MediumTest | Level1)
888 {
889     Skills skills;
890 
891     EXPECT_EQ(0, skills.CountEntities());
892     EXPECT_EQ(0, skills.CountActions());
893     EXPECT_EQ(0, skills.CountAuthorities());
894     EXPECT_EQ(0, skills.CountSchemes());
895 
896     EXPECT_EQ(0, skills.CountPaths());
897     EXPECT_EQ(0, skills.CountSchemeSpecificParts());
898     EXPECT_EQ(0, skills.CountTypes());
899     EXPECT_EQ(0, skills.GetWantParams().Size());
900 }
901 
902 /**
903  * @tc.number: AaFwk_Skills_Skills_0200
904  * @tc.name: Skills() and Skills(Skills)
905  * @tc.desc:  Verify Skills().
906  */
907 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Skills_0200, Function | MediumTest | Level1)
908 {
909     Skills skillsBase;
910     std::string entityString = "entity";
911     skillsBase.AddEntity(entityString);
912     std::string actionString = "action";
913     skillsBase.AddAction(actionString);
914     std::string authorityString = "authority";
915     skillsBase.AddAuthority(authorityString);
916     std::string schemeString = "scheme";
917     skillsBase.AddScheme(schemeString);
918     std::string pathString = "path";
919     skillsBase.AddPath(pathString);
920     std::string schemeSpecificPartsString = "schemeSpecificParts";
921     skillsBase.AddSchemeSpecificPart(schemeSpecificPartsString);
922     std::string typeString = "/type";
923     skillsBase.AddType(typeString);
924     Skills skills(skillsBase);
925 
926     EXPECT_EQ(entityString, skills.GetEntity(0));
927     int index = -5;
928     std::string entityString1 = "";
929     EXPECT_EQ(entityString1, skills.GetEntity(index));
930     EXPECT_EQ(actionString, skills.GetAction(0));
931     EXPECT_EQ(entityString1, skills.GetAction(index));
932     EXPECT_EQ(authorityString, skills.GetAuthority(0));
933     EXPECT_EQ(entityString1, skills.GetAuthority(index));
934     EXPECT_EQ(schemeString, skills.GetScheme(0));
935     EXPECT_EQ(entityString1, skills.GetScheme(index));
936     EXPECT_EQ(pathString, skills.GetPath(0));
937     EXPECT_EQ(entityString1, skills.GetPath(index));
938     EXPECT_EQ(schemeSpecificPartsString, skills.GetSchemeSpecificPart(0));
939     EXPECT_EQ(entityString1, skills.GetSchemeSpecificPart(index));
940     EXPECT_EQ(typeString, skills.GetType(0));
941 }
942 
943 /**
944  * @tc.number: AaFwk_Skills_addremoveType_0100
945  * @tc.name: addType(PatternsMatcher)/ removeType(PatternsMatcher)
946  * @tc.desc: Verify addType/removeType result.
947  */
948 HWTEST_F(SkillsBaseTest, AaFwk_Skills_addremoveType_0100, Function | MediumTest | Level1)
949 {
950     std::string patternStr = std::string("systems/*t");
951 
952     PatternsMatcher pattern(patternStr, MatchType::DEFAULT);
953 
954     base_->AddType(pattern);
955     std::string type1 = base_->GetType(0);
956     EXPECT_EQ(patternStr, type1);
957 
958     base_->RemoveType(patternStr);
959 
960     EXPECT_EQ(0, base_->CountEntities());
961 
962     base_->AddType(pattern);
963 
964     std::string patternStr2 = std::string("systems/*test");
965     PatternsMatcher pattern2(patternStr2, MatchType::PREFIX);
966     base_->AddType(pattern2);
967     std::string type2 = base_->GetType(1);
968     EXPECT_EQ(patternStr2, type2);
969 
970     base_->RemoveType(pattern2);
971     EXPECT_EQ(0, base_->CountEntities());
972 
973     std::string patternStr3 = std::string("systems/*test3");
974     base_->AddType(patternStr3, MatchType::GLOBAL);
975 
976     std::string type3 = base_->GetType(1);
977     EXPECT_EQ(patternStr3, type3);
978 
979     std::string patternStr4 = std::string("");
980     std::string type4 = base_->GetType(-5);
981     EXPECT_EQ(patternStr4, type4);
982 
983     base_->RemoveType(patternStr3, MatchType::GLOBAL);
984 
985     EXPECT_EQ(0, base_->CountEntities());
986 }
987 
988 /**
989  * @tc.number: AaFwk_Skills_MatchData_0100
990  * @tc.name: MatchData
991  * @tc.desc: Test MatchData.
992  * @tc.require: issueI648W6
993  */
994 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchData_0100, Function | MediumTest | Level1)
995 {
996     std::string type = "this is type";
997     std::string scheme = "this is scheme";
998     std::string value = "this is value";
999     OHOS::Uri data(value);
1000     int result = base_->MatchData(type, scheme, data);
1001     EXPECT_EQ(result, DISMATCH_DATA);
1002 }
1003 
1004 /**
1005  * @tc.number: AaFwk_Skills_MatchData_0200
1006  * @tc.name: MatchData
1007  * @tc.desc: Test MatchData.
1008  * @tc.require: issueI648W6
1009  */
1010 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchData_0200, Function | MediumTest | Level1)
1011 {
1012     std::string type = "";
1013     std::string scheme = "";
1014     std::string value = "this is value";
1015     OHOS::Uri data(value);
1016     int result = base_->MatchData(type, scheme, data);
1017     EXPECT_EQ(result, DISMATCH_TYPE);
1018 }
1019 
1020 /**
1021  * @tc.number: AaFwk_Skills_MatchData_0300
1022  * @tc.name: MatchData
1023  * @tc.desc: Test MatchData.
1024  * @tc.require: issueI648W6
1025  */
1026 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchData_0300, Function | MediumTest | Level1)
1027 {
1028     std::string type = "this is type";
1029     std::string scheme = "this is scheme";
1030     std::string value = "this is value";
1031     OHOS::Uri data(value);
1032     std::string pattern = "this is pattern";
1033     PatternsMatcherIn_ = std::make_shared<PatternsMatcher>(pattern, MatchType::DEFAULT);
1034     std::string ret = PatternsMatcherIn_->GetPattern();
1035     EXPECT_EQ(ret, pattern);
1036     base_->AddScheme("12345");
1037     int result = base_->MatchData(type, scheme, data);
1038     EXPECT_EQ(result, DISMATCH_DATA);
1039 }
1040 
1041 /**
1042  * @tc.number: AaFwk_Skills_FindMimeType_0100
1043  * @tc.name: FindMimeType
1044  * @tc.desc: Test FindMimeType.
1045  * @tc.require: issueI653GZ
1046  */
1047 HWTEST_F(SkillsBaseTest, AaFwk_Skills_FindMimeType_0100, Function | MediumTest | Level1)
1048 {
1049     std::string type = "";
1050     bool result = base_->FindMimeType(type);
1051     EXPECT_EQ(result, false);
1052 
1053     std::string type1 = "this is type";
1054     bool result1 = base_->FindMimeType(type1);
1055     EXPECT_EQ(result1, false);
1056 }
1057 
1058 /**
1059  * @tc.number: AaFwk_Skills_FindMimeType_0200
1060  * @tc.name: FindMimeType
1061  * @tc.desc: Test FindMimeType.
1062  * @tc.require: issue
1063  */
1064 HWTEST_F(SkillsBaseTest, AaFwk_Skills_FindMimeType_0200, Function | MediumTest | Level1)
1065 {
1066     std::string empty;
1067     std::string type = "*/*";
1068     int typeCount = 1;
1069 
1070     for (int i = 0; i < SET_COUNT; i++) {
1071         base_->AddType(type);
1072     }
1073     EXPECT_EQ(typeCount, base_->CountTypes());
1074 
1075     PatternsMatcherIn_ = std::make_shared<PatternsMatcher>(type, MatchType::DEFAULT);
1076     std::string ret = PatternsMatcherIn_->GetPattern();
1077     EXPECT_EQ(ret, type);
1078     bool result = base_->FindMimeType(type);
1079     EXPECT_EQ(result, true);
1080 }
1081 
1082 /**
1083  * @tc.number: AaFwk_Skills_FindMimeType_0300
1084  * @tc.name: FindMimeType
1085  * @tc.desc: Test FindMimeType.
1086  * @tc.require: issue
1087  */
1088 HWTEST_F(SkillsBaseTest, AaFwk_Skills_FindMimeType_0300, Function | MediumTest | Level1)
1089 {
1090     std::string empty;
1091     std::string type = "type/system.test";
1092     int typeCount = 1;
1093 
1094     for (int i = 0; i < SET_COUNT; i++) {
1095         base_->AddType(type);
1096     }
1097     EXPECT_EQ(typeCount, base_->CountTypes());
1098 
1099     PatternsMatcherIn_ = std::make_shared<PatternsMatcher>(type, MatchType::DEFAULT);
1100     std::string ret = PatternsMatcherIn_->GetPattern();
1101     EXPECT_EQ(ret, type);
1102     bool result = base_->FindMimeType(type);
1103     EXPECT_EQ(result, true);
1104     EXPECT_EQ(true, base_->HasType(type));
1105     EXPECT_EQ(type, base_->GetType(0));
1106 
1107     base_->RemoveType(type);
1108     EXPECT_EQ(0, base_->CountTypes());
1109     EXPECT_EQ(false, base_->FindMimeType(type));
1110 }
1111 
1112 /**
1113  * @tc.number: AaFwk_Skills_RegionMatches_0100
1114  * @tc.name: RegionMatches
1115  * @tc.desc: Test RegionMatches.
1116  * @tc.require: issueI653GZ
1117  */
1118 HWTEST_F(SkillsBaseTest, AaFwk_Skills_RegionMatches_0100, Function | MediumTest | Level1)
1119 {
1120     std::string type = "this is type";
1121     int toffset = -1;
1122     std::string other = "this is other";
1123     int ooffset = -2;
1124     int len = 1;
1125     bool result = base_->RegionMatches(type, toffset, other, ooffset, len);
1126     EXPECT_EQ(result, false);
1127 }
1128 
1129 /**
1130  * @tc.number: AaFwk_Skills_RegionMatches_0200
1131  * @tc.name: RegionMatches
1132  * @tc.desc: Test RegionMatches.
1133  * @tc.require: issueI653GZ
1134  */
1135 HWTEST_F(SkillsBaseTest, AaFwk_Skills_RegionMatches_0200, Function | MediumTest | Level1)
1136 {
1137     std::string type = "this is type";
1138     int toffset = 1;
1139     std::string other = "this is other";
1140     int ooffset = 2;
1141     int len = 2;
1142     bool result = base_->RegionMatches(type, toffset, other, ooffset, len);
1143     EXPECT_EQ(result, false);
1144 
1145     int len1 = 0;
1146     bool result1 = base_->RegionMatches(type, toffset, other, ooffset, len1);
1147     EXPECT_EQ(result1, true);
1148 }
1149 
1150 /**
1151  * @tc.number: AaFwk_Skills_RegionMatches_0300
1152  * @tc.name: RegionMatches
1153  * @tc.desc: Test RegionMatches.
1154  * @tc.require: issueI653GZ
1155  */
1156 HWTEST_F(SkillsBaseTest, AaFwk_Skills_RegionMatches_0300, Function | MediumTest | Level1)
1157 {
1158     std::string type = "this is type";
1159     int toffset = 1;
1160     std::string other = "this is other";
1161     int ooffset = -2;
1162     int len = 20;
1163     bool result = base_->RegionMatches(type, toffset, other, ooffset, len);
1164     EXPECT_EQ(result, false);
1165 }
1166 
1167 /**
1168  * @tc.number: AaFwk_Skills_MatchEntities_0200
1169  * @tc.name: MatchEntities
1170  * @tc.desc: Test MatchEntities.
1171  * @tc.require: issue
1172  */
1173 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchEntities_0200, Function | MediumTest | Level1)
1174 {
1175     std::vector<std::string> entities;
1176     std::string ret = "";
1177     std::string result = base_->MatchEntities(entities);
1178     EXPECT_EQ(result, ret);
1179 }
1180 
1181 using testParamsType = std::tuple<std::string, std::string>;
1182 class SkillsParamsTest : public testing::TestWithParam<testParamsType> {
1183 public:
SkillsParamsTest()1184     SkillsParamsTest()
1185     {}
~SkillsParamsTest()1186     ~SkillsParamsTest()
1187     {}
1188     static void SetUpTestCase(void);
1189     static void TearDownTestCase(void);
1190     void SetUp();
1191     void TearDown();
1192     std::shared_ptr<Skills> skills_ = nullptr;
1193 };
1194 
SetUpTestCase(void)1195 void SkillsParamsTest::SetUpTestCase(void)
1196 {}
1197 
TearDownTestCase(void)1198 void SkillsParamsTest::TearDownTestCase(void)
1199 {}
1200 
SetUp(void)1201 void SkillsParamsTest::SetUp(void)
1202 {
1203     skills_ = std::make_shared<Skills>();
1204 }
1205 
TearDown(void)1206 void SkillsParamsTest::TearDown(void)
1207 {}
1208 
1209 /**
1210  * @tc.number: AaFwk_Skills_Params_0100
1211  * @tc.name: SetWantParams/GetWantParams
1212  * @tc.desc: Verify addType/removeType result.
1213  */
1214 HWTEST_P(SkillsParamsTest, AaFwk_Skills_Params_0100, Function | MediumTest | Level1)
1215 {
1216     std::string keyStr = std::get<0>(GetParam());
1217     std::string valueStr = std::get<1>(GetParam());
1218     WantParams wantParams;
1219     wantParams.SetParam(keyStr, String::Box(valueStr));
1220     skills_->SetWantParams(wantParams);
1221     EXPECT_EQ(valueStr, String::Unbox(IString::Query(skills_->GetWantParams().GetParam(keyStr))));
1222 }
1223 
1224 INSTANTIATE_TEST_SUITE_P(SkillsParamsTestCaseP, SkillsParamsTest,
1225     testing::Values(testParamsType("", "asdsdsdasa"), testParamsType(std::string(LARGE_STR_LEN + 1, 's'), "sadsdsdads"),
1226         testParamsType("#$%^&*(!@\":<>{}", "asdsdsdasa"), testParamsType("3456677", ""),
1227         testParamsType("1234", std::string(LARGE_STR_LEN + 1, 's')),
1228         testParamsType("2323sdasdZ", "#$%^&*(!@\":<>{}sadsdasdsaf"), testParamsType("12345667", "sdasdfdsffdgfdg"),
1229         testParamsType("", ""),
1230         testParamsType(std::string(LARGE_STR_LEN + 1, 'k'), std::string(LARGE_STR_LEN + 1, 'k')),
1231         testParamsType("#$%^&*(!@\":<>{},/", "#$%^&*(!@\":<>{},/")));
1232 }  // namespace AAFwk
1233 }  // namespace OHOS