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 long result = Long::Unbox(ILong::Query(SkillsOut_->GetWantParams().GetParam(keyStr)));
138 EXPECT_EQ(valueLong, result);
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 EXPECT_EQ(*iter, "a");
391 }
392
393 /**
394 * @tc.number: AaFwk_Skills_Entity_0100
395 * @tc.name: CountEntities/HasEntity/CountEntities/GetEntity
396 * @tc.desc: Verify the function when the input string is default.
397 */
398 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Entity_0100, Function | MediumTest | Level1)
399 {
400 std::string empty;
401 std::string entity = "entity.system.test";
402 int entityCount = 1;
403
404 for (int i = 0; i < SET_COUNT; i++) {
405 base_->AddEntity(entity);
406 }
407
408 EXPECT_EQ(entityCount, base_->CountEntities());
409 EXPECT_EQ(true, base_->HasEntity(entity));
410 EXPECT_EQ(entity, base_->GetEntity(0));
411
412 base_->RemoveEntity(entity);
413 EXPECT_EQ(0, base_->CountEntities());
414 EXPECT_EQ(false, base_->HasEntity(entity));
415 }
416
417 /**
418 * @tc.number: AaFwk_Skills_Authority_0100
419 * @tc.name: CountAuthorities/HasAuthority/GetAuthority
420 * @tc.desc: Verify the function when the input string contains special characters.
421 */
422 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Authority_0100, Function | MediumTest | Level1)
423 {
424 std::string empty;
425 std::string authority = "Authority.system.test";
426 int authorityCount = 1;
427
428 for (int i = 0; i < SET_COUNT; i++) {
429 base_->AddAuthority(authority);
430 }
431
432 EXPECT_EQ(authorityCount, base_->CountAuthorities());
433 EXPECT_EQ(true, base_->HasAuthority(authority));
434 EXPECT_EQ(authority, base_->GetAuthority(0));
435
436 base_->RemoveAuthority(authority);
437 EXPECT_EQ(0, base_->CountAuthorities());
438 EXPECT_EQ(false, base_->HasAuthority(authority));
439 }
440
441 /**
442 * @tc.number: AaFwk_Skills_Path_0100
443 * @tc.name: CountPaths/HasPath/GetPath
444 * @tc.desc: Verify the function when the input string contains special characters.
445 */
446 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Path_0100, Function | MediumTest | Level1)
447 {
448 std::string empty;
449 std::string path = "Path.system.test";
450 int pathCount = 1;
451
452 for (int i = 0; i < SET_COUNT; i++) {
453 base_->AddPath(path);
454 }
455
456 EXPECT_EQ(pathCount, base_->CountPaths());
457 EXPECT_EQ(true, base_->HasPath(path));
458 EXPECT_EQ(path, base_->GetPath(0));
459
460 base_->RemovePath(path);
461 EXPECT_EQ(0, base_->CountPaths());
462 EXPECT_EQ(false, base_->HasPath(path));
463 }
464
465 /**
466 * @tc.number: AaFwk_Skills_Scheme_0100
467 * @tc.name: CountSchemes/HasScheme/GetScheme
468 * @tc.desc: Verify the function when the input string contains special characters.
469 */
470 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Scheme_0100, Function | MediumTest | Level1)
471 {
472 std::string empty;
473 std::string scheme = "scheme.system.test";
474 int schemeCount = 1;
475
476 for (int i = 0; i < SET_COUNT; i++) {
477 base_->AddScheme(scheme);
478 }
479
480 EXPECT_EQ(schemeCount, base_->CountSchemes());
481 EXPECT_EQ(true, base_->HasScheme(scheme));
482 EXPECT_EQ(scheme, base_->GetScheme(0));
483
484 base_->RemoveScheme(scheme);
485 EXPECT_EQ(0, base_->CountSchemes());
486 EXPECT_EQ(false, base_->HasScheme(scheme));
487 }
488
489 /**
490 * @tc.number: AaFwk_Skills_SchemeSpecificPart_0100
491 * @tc.name: CountSchemeSpecificParts/HasSchemeSpecificPart/GetSchemeSpecificPart
492 * @tc.desc: Verify the function when the input string contains special characters.
493 */
494 HWTEST_F(SkillsBaseTest, AaFwk_Skills_SchemeSpecificPart_0100, Function | MediumTest | Level1)
495 {
496 std::string empty;
497 std::string schemespecificpart = "schemespecificpart.system.test";
498 int schemespecificpartCount = 1;
499
500 for (int i = 0; i < SET_COUNT; i++) {
501 base_->AddSchemeSpecificPart(schemespecificpart);
502 }
503
504 EXPECT_EQ(schemespecificpartCount, base_->CountSchemeSpecificParts());
505 EXPECT_EQ(true, base_->HasSchemeSpecificPart(schemespecificpart));
506 EXPECT_EQ(schemespecificpart, base_->GetSchemeSpecificPart(0));
507
508 base_->RemoveSchemeSpecificPart(schemespecificpart);
509 EXPECT_EQ(0, base_->CountSchemeSpecificParts());
510 EXPECT_EQ(false, base_->HasSchemeSpecificPart(schemespecificpart));
511 }
512
513 /**
514 * @tc.number: AaFwk_Skills_Type_0100
515 * @tc.name: CountTypes/HasType/GetType
516 * @tc.desc: Verify the function when the input string contains special characters.
517 */
518 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Type_0100, Function | MediumTest | Level1)
519 {
520 std::string empty;
521 std::string type = "type/system.test";
522 int typeCount = 1;
523
524 for (int i = 0; i < SET_COUNT; i++) {
525 base_->AddType(type);
526 }
527
528 EXPECT_EQ(typeCount, base_->CountTypes());
529 EXPECT_EQ(true, base_->HasType(type));
530 EXPECT_EQ(type, base_->GetType(0));
531
532 base_->RemoveType(type);
533 EXPECT_EQ(0, base_->CountTypes());
534 EXPECT_EQ(false, base_->HasType(type));
535 }
536
537 /**
538 * @tc.number: AaFwk_Skills_Actions_0100
539 * @tc.name: CountActions/HasAuthority/GetAuthority
540 * @tc.desc: Verify the function when the input string contains special characters.
541 */
542 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Actions_0100, Function | MediumTest | Level1)
543 {
544 std::string empty;
545 std::string actions = "actions.system.test";
546 EXPECT_EQ(0, base_->CountActions());
547 EXPECT_EQ(false, base_->HasAuthority(actions));
548 EXPECT_EQ(empty, base_->GetAuthority(0));
549
550 base_->RemoveAuthority(actions);
551 EXPECT_EQ(0, base_->CountActions());
552 EXPECT_EQ(false, base_->HasAuthority(actions));
553 }
554
555 /**
556 * @tc.number: AaFwk_Skills_Schemes_0100
557 * @tc.name: CountSchemes/HasAuthority/GetAuthority
558 * @tc.desc: Verify the function when the input string contains special characters.
559 */
560 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Schemes_0100, Function | MediumTest | Level1)
561 {
562 std::string empty;
563 std::string schemes = "schemes.system.test";
564 EXPECT_EQ(0, base_->CountSchemes());
565 EXPECT_EQ(false, base_->HasAuthority(schemes));
566 EXPECT_EQ(empty, base_->GetAuthority(0));
567
568 base_->RemoveAuthority(schemes);
569 EXPECT_EQ(0, base_->CountSchemes());
570 EXPECT_EQ(false, base_->HasAuthority(schemes));
571 }
572
573 /**
574 * @tc.number: AaFwk_Skills_SchemeSpecificParts_0100
575 * @tc.name: CountSchemeSpecificParts/HasAuthority/GetAuthority
576 * @tc.desc: Verify the function when the input string contains special characters.
577 */
578 HWTEST_F(SkillsBaseTest, AaFwk_Skills_SchemeSpecificParts_0100, Function | MediumTest | Level1)
579 {
580 std::string empty;
581 std::string schemespecificparts = "schemespecificparts.system.test";
582 EXPECT_EQ(0, base_->CountSchemeSpecificParts());
583 EXPECT_EQ(false, base_->HasAuthority(schemespecificparts));
584 EXPECT_EQ(empty, base_->GetAuthority(0));
585
586 base_->RemoveAuthority(schemespecificparts);
587 EXPECT_EQ(0, base_->CountSchemeSpecificParts());
588 EXPECT_EQ(false, base_->HasAuthority(schemespecificparts));
589 }
590
591 /**
592 * @tc.number: AaFwk_Skills_Types_0100
593 * @tc.name: CountTypes/HasAuthority/GetAuthority
594 * @tc.desc: Verify the function when the input string contains special characters.
595 */
596 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Types_0100, Function | MediumTest | Level1)
597 {
598 std::string empty;
599 std::string types = "types.system.test";
600 GTEST_LOG_(INFO) << "---------------a ";
601 EXPECT_EQ(0, base_->CountTypes());
602 GTEST_LOG_(INFO) << "---------------b ";
603 EXPECT_EQ(false, base_->HasAuthority(types));
604 GTEST_LOG_(INFO) << "---------------1 ";
605 EXPECT_EQ(empty, base_->GetAuthority(0));
606 GTEST_LOG_(INFO) << "---------------2 ";
607
608 base_->RemoveAuthority(types);
609 EXPECT_EQ(0, base_->CountTypes());
610 EXPECT_EQ(false, base_->HasAuthority(types));
611 }
612
613 /**
614 * @tc.number: AaFwk_Skills_Action_0200
615 * @tc.name: CountActions/HasAction/GetAction
616 * @tc.desc: Verify the function when action is not exist.
617 */
618 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Action_0200, Function | MediumTest | Level1)
619 {
620 std::string empty;
621 std::string action = "action.system.test";
622 EXPECT_EQ(0, base_->CountActions());
623 EXPECT_EQ(false, base_->HasAction(action));
624 EXPECT_EQ(empty, base_->GetAction(0));
625
626 base_->RemoveAction(action);
627 EXPECT_EQ(0, base_->CountActions());
628 EXPECT_EQ(false, base_->HasAction(action));
629 }
630
631 /**
632 * @tc.number: AaFwk_Skills_Authority_0200
633 * @tc.name: CountAuthorities/HasAuthority/GetAuthority
634 * @tc.desc: Verify the function when action is not exist.
635 */
636 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Authority_0200, Function | MediumTest | Level1)
637 {
638 std::string empty;
639 std::string authority = "authority.system.test";
640 EXPECT_EQ(0, base_->CountAuthorities());
641 EXPECT_EQ(false, base_->HasAuthority(authority));
642 EXPECT_EQ(empty, base_->GetAuthority(0));
643
644 base_->RemoveAuthority(authority);
645 EXPECT_EQ(0, base_->CountAuthorities());
646 EXPECT_EQ(false, base_->HasAuthority(authority));
647 }
648
649 /**
650 * @tc.number: AaFwk_Skills_Path_0200
651 * @tc.name: CountPaths/HasPath/GetPath
652 * @tc.desc: Verify the function when action is not exist.
653 */
654 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Path_0200, Function | MediumTest | Level1)
655 {
656 std::string empty;
657 std::string path = "path.system.test";
658 base_->AddPath(path, MatchType::DEFAULT);
659
660 EXPECT_EQ(1, base_->CountPaths());
661 EXPECT_EQ(true, base_->HasPath(path));
662 EXPECT_EQ(path, base_->GetPath(0));
663
664 base_->RemovePath(path, MatchType::DEFAULT);
665 EXPECT_EQ(0, base_->CountPaths());
666 EXPECT_EQ(false, base_->HasPath(path));
667 }
668
669 /**
670 * @tc.number: AaFwk_Skills_Scheme_0200
671 * @tc.name: CountSchemes/HasScheme/GetScheme
672 * @tc.desc: Verify the function when action is not exist.
673 */
674 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Scheme_0200, Function | MediumTest | Level1)
675 {
676 std::string empty;
677 std::string scheme = "scheme.system.test";
678 EXPECT_EQ(0, base_->CountSchemes());
679 EXPECT_EQ(false, base_->HasScheme(scheme));
680 EXPECT_EQ(empty, base_->GetScheme(0));
681
682 base_->RemoveScheme(scheme);
683 EXPECT_EQ(0, base_->CountSchemes());
684 EXPECT_EQ(false, base_->HasScheme(scheme));
685 }
686
687 /**
688 * @tc.number: AaFwk_Skills_SchemeSpecificPart_0200
689 * @tc.name: CountSchemeSpecificParts/HasSchemeSpecificPart/GetSchemeSpecificPart
690 * @tc.desc: Verify the function when action is not exist.
691 */
692 HWTEST_F(SkillsBaseTest, AaFwk_Skills_SchemeSpecificPart_0200, Function | MediumTest | Level1)
693 {
694 std::string empty;
695 std::string schemespecificpart = "schemespecificpart.system.test";
696 EXPECT_EQ(0, base_->CountSchemeSpecificParts());
697 EXPECT_EQ(false, base_->HasSchemeSpecificPart(schemespecificpart));
698 EXPECT_EQ(empty, base_->GetSchemeSpecificPart(0));
699
700 base_->RemoveSchemeSpecificPart(schemespecificpart);
701 EXPECT_EQ(0, base_->CountSchemeSpecificParts());
702 EXPECT_EQ(false, base_->HasSchemeSpecificPart(schemespecificpart));
703 }
704
705 /**
706 * @tc.number: AaFwk_Skills_Type_0300
707 * @tc.name: CountTypes/HasType/GetType
708 * @tc.desc: Verify the function when action is not exist.
709 */
710 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Type_0300, Function | MediumTest | Level1)
711 {
712 std::string empty;
713 std::string type = "type.system.test";
714 EXPECT_EQ(0, base_->CountTypes());
715
716 EXPECT_EQ(false, base_->HasType(type));
717 EXPECT_EQ(empty, base_->GetType(0));
718
719 base_->RemoveType(type);
720 EXPECT_EQ(0, base_->CountTypes());
721 EXPECT_EQ(false, base_->HasType(type));
722 }
723
724 using SkillsMatchType = std::tuple<std::string, std::string, bool>;
725 class SkillsMatchTest : public testing::TestWithParam<SkillsMatchType> {
726 public:
SkillsMatchTest()727 SkillsMatchTest()
728 {}
~SkillsMatchTest()729 ~SkillsMatchTest()
730 {}
731 static void SetUpTestCase(void);
732 static void TearDownTestCase(void);
733 void SetUp();
734 void TearDown();
735 std::shared_ptr<Skills> skills_ = nullptr;
736 };
737
SetUpTestCase(void)738 void SkillsMatchTest::SetUpTestCase(void)
739 {}
740
TearDownTestCase(void)741 void SkillsMatchTest::TearDownTestCase(void)
742 {}
743
SetUp(void)744 void SkillsMatchTest::SetUp(void)
745 {
746 skills_ = std::make_shared<Skills>();
747 }
748
TearDown(void)749 void SkillsMatchTest::TearDown(void)
750 {}
751
752 /**
753 * @tc.number: AaFwk_Skills_match_0100
754 * @tc.name: CountTypes/HasType/GetType
755 * @tc.desc: Verify whether parameter change.
756 */
757 HWTEST_P(SkillsMatchTest, AaFwk_Skills_match_0100, Function | MediumTest | Level1)
758 {
759 std::string filterEntity = "entity.system.entity1";
760 std::string filterAction1 = "action.system.action1";
761 std::string filterAction2 = "action.system.action2";
762 std::string wantEntity = std::get<0>(GetParam());
763 std::string wantAction = std::get<1>(GetParam());
764 bool result = std::get<2>(GetParam());
765
766 skills_->AddEntity(filterEntity);
767 skills_->AddAction(filterAction1);
768 skills_->AddAction(filterAction2);
769
770 Want want;
771 want.AddEntity(wantEntity);
772 want.SetAction(wantAction);
773
774 EXPECT_EQ(result, skills_->Match(want));
775 }
776
777 INSTANTIATE_TEST_SUITE_P(SkillsMatchTestP, SkillsMatchTest,
778 testing::Values(SkillsMatchType("entity.system.entityA", "action.system.actionA", false),
779 SkillsMatchType("entity.system.entity1", "action.system.actionA", false),
780 SkillsMatchType("entity.system.entityA", "action.system.action2", false),
781 SkillsMatchType("entity.system.entity1", "action.system.action1", true)));
782
783 /**
784 * @tc.name: AaFwk_Skills_match_0200
785 * @tc.desc: Verify Matching rules action segment
786 * @tc.type: FUNC
787 * @tc.require: I5PZK2
788 */
789 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0200, Function | MediumTest | Level1)
790 {
791 Skills skills;
792 std::string filterEntity = "entity.system.entity1";
793 skills.AddEntity(filterEntity);
794 Want want;
795 want.AddEntity(filterEntity);
796 // Both actions are empty.
797 EXPECT_EQ(true, skills.Match(want));
798 }
799
800 /**
801 * @tc.name: AaFwk_Skills_match_0300
802 * @tc.desc: Verify Matching rules action segment
803 * @tc.type: FUNC
804 * @tc.require: I5PZK2
805 */
806 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0300, Function | MediumTest | Level1)
807 {
808 Skills skills;
809 std::string filterEntity = "entity.system.entity1";
810 skills.AddEntity(filterEntity);
811 Want want;
812 want.AddEntity(filterEntity);
813 want.SetAction("action.system.action1");
814 // empty actions in skill vs non-empty actions in want
815 EXPECT_EQ(false, skills.Match(want));
816 }
817
818 /**
819 * @tc.name: AaFwk_Skills_match_0400
820 * @tc.desc: Verify Matching rules action segment
821 * @tc.type: FUNC
822 * @tc.require: I5PZK2
823 */
824 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0400, Function | MediumTest | Level1)
825 {
826 Skills skills;
827 std::string filterEntity = "entity.system.entity1";
828 std::string filterAction1 = "action.system.action1";
829 std::string filterAction2 = "action.system.action2";
830 skills.AddEntity(filterEntity);
831 skills.AddAction(filterAction1);
832 skills.AddAction(filterAction2);
833 Want want;
834 want.AddEntity(filterEntity);
835 want.SetAction(filterAction1);
836 // actions that in skill contains non-empty actions in want
837 EXPECT_EQ(true, skills.Match(want));
838 }
839
840 /**
841 * @tc.name: AaFwk_Skills_match_0500
842 * @tc.desc: Verify Matching rules action segment
843 * @tc.type: FUNC
844 * @tc.require: I5PZK2
845 */
846 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0600, Function | MediumTest | Level1)
847 {
848 Skills skills;
849 std::string filterEntity = "entity.system.entity1";
850 std::string filterAction1 = "action.system.action1";
851 std::string filterAction2 = "action.system.action2";
852 skills.AddEntity(filterEntity);
853 skills.AddAction(filterAction2);
854 Want want;
855 want.AddEntity(filterEntity);
856 // non-empty actions that in skill vs empty actions in want
857 EXPECT_EQ(false, skills.Match(want));
858 }
859
860 /**
861 * @tc.name: AaFwk_Skills_match_0600
862 * @tc.desc: Verify Matching rules action segment
863 * @tc.type: FUNC
864 * @tc.require: I5PZK2
865 */
866 HWTEST_F(SkillsBaseTest, AaFwk_Skills_match_0500, Function | MediumTest | Level1)
867 {
868 Skills skills;
869 std::string filterEntity = "entity.system.entity1";
870 std::string filterAction1 = "action.system.action1";
871 std::string filterAction2 = "action.system.action2";
872 skills.AddEntity(filterEntity);
873 skills.AddAction(filterAction2);
874 Want want;
875 want.AddEntity(filterEntity);
876 want.SetAction(filterAction1);
877 // actions that in skill doesn't contain non-empty actions in want
878 EXPECT_EQ(false, skills.Match(want));
879 }
880
881 /**
882 * @tc.number: AaFwk_Skills_Skills_0100
883 * @tc.name: Skills() and Skills(Skills)
884 * @tc.desc: Verify Skills().
885 */
886 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Skills_0100, Function | MediumTest | Level1)
887 {
888 Skills skills;
889
890 EXPECT_EQ(0, skills.CountEntities());
891 EXPECT_EQ(0, skills.CountActions());
892 EXPECT_EQ(0, skills.CountAuthorities());
893 EXPECT_EQ(0, skills.CountSchemes());
894
895 EXPECT_EQ(0, skills.CountPaths());
896 EXPECT_EQ(0, skills.CountSchemeSpecificParts());
897 EXPECT_EQ(0, skills.CountTypes());
898 EXPECT_EQ(0, skills.GetWantParams().Size());
899 }
900
901 /**
902 * @tc.number: AaFwk_Skills_Skills_0200
903 * @tc.name: Skills() and Skills(Skills)
904 * @tc.desc: Verify Skills().
905 */
906 HWTEST_F(SkillsBaseTest, AaFwk_Skills_Skills_0200, Function | MediumTest | Level1)
907 {
908 Skills skillsBase;
909 std::string entityString = "entity";
910 skillsBase.AddEntity(entityString);
911 std::string actionString = "action";
912 skillsBase.AddAction(actionString);
913 std::string authorityString = "authority";
914 skillsBase.AddAuthority(authorityString);
915 std::string schemeString = "scheme";
916 skillsBase.AddScheme(schemeString);
917 std::string pathString = "path";
918 skillsBase.AddPath(pathString);
919 std::string schemeSpecificPartsString = "schemeSpecificParts";
920 skillsBase.AddSchemeSpecificPart(schemeSpecificPartsString);
921 std::string typeString = "/type";
922 skillsBase.AddType(typeString);
923 Skills skills(skillsBase);
924
925 EXPECT_EQ(entityString, skills.GetEntity(0));
926 int index = -5;
927 std::string entityString1 = "";
928 EXPECT_EQ(entityString1, skills.GetEntity(index));
929 EXPECT_EQ(actionString, skills.GetAction(0));
930 EXPECT_EQ(entityString1, skills.GetAction(index));
931 EXPECT_EQ(authorityString, skills.GetAuthority(0));
932 EXPECT_EQ(entityString1, skills.GetAuthority(index));
933 EXPECT_EQ(schemeString, skills.GetScheme(0));
934 EXPECT_EQ(entityString1, skills.GetScheme(index));
935 EXPECT_EQ(pathString, skills.GetPath(0));
936 EXPECT_EQ(entityString1, skills.GetPath(index));
937 EXPECT_EQ(schemeSpecificPartsString, skills.GetSchemeSpecificPart(0));
938 EXPECT_EQ(entityString1, skills.GetSchemeSpecificPart(index));
939 EXPECT_EQ(typeString, skills.GetType(0));
940 }
941
942 /**
943 * @tc.number: AaFwk_Skills_addremoveType_0100
944 * @tc.name: addType(PatternsMatcher)/ removeType(PatternsMatcher)
945 * @tc.desc: Verify addType/removeType result.
946 */
947 HWTEST_F(SkillsBaseTest, AaFwk_Skills_addremoveType_0100, Function | MediumTest | Level1)
948 {
949 std::string patternStr = std::string("systems/*t");
950
951 PatternsMatcher pattern(patternStr, MatchType::DEFAULT);
952
953 base_->AddType(pattern);
954 std::string type1 = base_->GetType(0);
955 EXPECT_EQ(patternStr, type1);
956
957 base_->RemoveType(patternStr);
958
959 EXPECT_EQ(0, base_->CountEntities());
960
961 base_->AddType(pattern);
962
963 std::string patternStr2 = std::string("systems/*test");
964 PatternsMatcher pattern2(patternStr2, MatchType::PREFIX);
965 base_->AddType(pattern2);
966 std::string type2 = base_->GetType(1);
967 EXPECT_EQ(patternStr2, type2);
968
969 base_->RemoveType(pattern2);
970 EXPECT_EQ(0, base_->CountEntities());
971
972 std::string patternStr3 = std::string("systems/*test3");
973 base_->AddType(patternStr3, MatchType::GLOBAL);
974
975 std::string type3 = base_->GetType(1);
976 EXPECT_EQ(patternStr3, type3);
977
978 std::string patternStr4 = std::string("");
979 std::string type4 = base_->GetType(-5);
980 EXPECT_EQ(patternStr4, type4);
981
982 base_->RemoveType(patternStr3, MatchType::GLOBAL);
983
984 EXPECT_EQ(0, base_->CountEntities());
985 }
986
987 /**
988 * @tc.number: AaFwk_Skills_MatchData_0100
989 * @tc.name: MatchData
990 * @tc.desc: Test MatchData.
991 * @tc.require: issueI648W6
992 */
993 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchData_0100, Function | MediumTest | Level1)
994 {
995 std::string type = "this is type";
996 std::string scheme = "this is scheme";
997 std::string value = "this is value";
998 OHOS::Uri data(value);
999 int result = base_->MatchData(type, scheme, data);
1000 EXPECT_EQ(result, DISMATCH_DATA);
1001 }
1002
1003 /**
1004 * @tc.number: AaFwk_Skills_MatchData_0200
1005 * @tc.name: MatchData
1006 * @tc.desc: Test MatchData.
1007 * @tc.require: issueI648W6
1008 */
1009 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchData_0200, Function | MediumTest | Level1)
1010 {
1011 std::string type = "";
1012 std::string scheme = "";
1013 std::string value = "this is value";
1014 OHOS::Uri data(value);
1015 int result = base_->MatchData(type, scheme, data);
1016 EXPECT_EQ(result, DISMATCH_TYPE);
1017 }
1018
1019 /**
1020 * @tc.number: AaFwk_Skills_MatchData_0300
1021 * @tc.name: MatchData
1022 * @tc.desc: Test MatchData.
1023 * @tc.require: issueI648W6
1024 */
1025 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchData_0300, Function | MediumTest | Level1)
1026 {
1027 std::string type = "this is type";
1028 std::string scheme = "this is scheme";
1029 std::string value = "this is value";
1030 OHOS::Uri data(value);
1031 std::string pattern = "this is pattern";
1032 PatternsMatcherIn_ = std::make_shared<PatternsMatcher>(pattern, MatchType::DEFAULT);
1033 std::string ret = PatternsMatcherIn_->GetPattern();
1034 EXPECT_EQ(ret, pattern);
1035 base_->AddScheme("12345");
1036 int result = base_->MatchData(type, scheme, data);
1037 EXPECT_EQ(result, DISMATCH_DATA);
1038 }
1039
1040 /**
1041 * @tc.number: AaFwk_Skills_FindMimeType_0100
1042 * @tc.name: FindMimeType
1043 * @tc.desc: Test FindMimeType.
1044 * @tc.require: issueI653GZ
1045 */
1046 HWTEST_F(SkillsBaseTest, AaFwk_Skills_FindMimeType_0100, Function | MediumTest | Level1)
1047 {
1048 std::string type = "";
1049 bool result = base_->FindMimeType(type);
1050 EXPECT_EQ(result, false);
1051
1052 std::string type1 = "this is type";
1053 bool result1 = base_->FindMimeType(type1);
1054 EXPECT_EQ(result1, false);
1055 }
1056
1057 /**
1058 * @tc.number: AaFwk_Skills_FindMimeType_0200
1059 * @tc.name: FindMimeType
1060 * @tc.desc: Test FindMimeType.
1061 * @tc.require: issue
1062 */
1063 HWTEST_F(SkillsBaseTest, AaFwk_Skills_FindMimeType_0200, Function | MediumTest | Level1)
1064 {
1065 std::string empty;
1066 std::string type = "*/*";
1067 int typeCount = 1;
1068
1069 for (int i = 0; i < SET_COUNT; i++) {
1070 base_->AddType(type);
1071 }
1072 EXPECT_EQ(typeCount, base_->CountTypes());
1073
1074 PatternsMatcherIn_ = std::make_shared<PatternsMatcher>(type, MatchType::DEFAULT);
1075 std::string ret = PatternsMatcherIn_->GetPattern();
1076 EXPECT_EQ(ret, type);
1077 bool result = base_->FindMimeType(type);
1078 EXPECT_EQ(result, true);
1079 }
1080
1081 /**
1082 * @tc.number: AaFwk_Skills_FindMimeType_0300
1083 * @tc.name: FindMimeType
1084 * @tc.desc: Test FindMimeType.
1085 * @tc.require: issue
1086 */
1087 HWTEST_F(SkillsBaseTest, AaFwk_Skills_FindMimeType_0300, Function | MediumTest | Level1)
1088 {
1089 std::string empty;
1090 std::string type = "type/system.test";
1091 int typeCount = 1;
1092
1093 for (int i = 0; i < SET_COUNT; i++) {
1094 base_->AddType(type);
1095 }
1096 EXPECT_EQ(typeCount, base_->CountTypes());
1097
1098 PatternsMatcherIn_ = std::make_shared<PatternsMatcher>(type, MatchType::DEFAULT);
1099 std::string ret = PatternsMatcherIn_->GetPattern();
1100 EXPECT_EQ(ret, type);
1101 bool result = base_->FindMimeType(type);
1102 EXPECT_EQ(result, true);
1103 EXPECT_EQ(true, base_->HasType(type));
1104 EXPECT_EQ(type, base_->GetType(0));
1105
1106 base_->RemoveType(type);
1107 EXPECT_EQ(0, base_->CountTypes());
1108 EXPECT_EQ(false, base_->FindMimeType(type));
1109 }
1110
1111 /**
1112 * @tc.number: AaFwk_Skills_RegionMatches_0100
1113 * @tc.name: RegionMatches
1114 * @tc.desc: Test RegionMatches.
1115 * @tc.require: issueI653GZ
1116 */
1117 HWTEST_F(SkillsBaseTest, AaFwk_Skills_RegionMatches_0100, Function | MediumTest | Level1)
1118 {
1119 std::string type = "this is type";
1120 int toffset = -1;
1121 std::string other = "this is other";
1122 int ooffset = -2;
1123 int len = 1;
1124 bool result = base_->RegionMatches(type, toffset, other, ooffset, len);
1125 EXPECT_EQ(result, false);
1126 }
1127
1128 /**
1129 * @tc.number: AaFwk_Skills_RegionMatches_0200
1130 * @tc.name: RegionMatches
1131 * @tc.desc: Test RegionMatches.
1132 * @tc.require: issueI653GZ
1133 */
1134 HWTEST_F(SkillsBaseTest, AaFwk_Skills_RegionMatches_0200, Function | MediumTest | Level1)
1135 {
1136 std::string type = "this is type";
1137 int toffset = 1;
1138 std::string other = "this is other";
1139 int ooffset = 2;
1140 int len = 2;
1141 bool result = base_->RegionMatches(type, toffset, other, ooffset, len);
1142 EXPECT_EQ(result, false);
1143
1144 int len1 = 0;
1145 bool result1 = base_->RegionMatches(type, toffset, other, ooffset, len1);
1146 EXPECT_EQ(result1, true);
1147 }
1148
1149 /**
1150 * @tc.number: AaFwk_Skills_RegionMatches_0300
1151 * @tc.name: RegionMatches
1152 * @tc.desc: Test RegionMatches.
1153 * @tc.require: issueI653GZ
1154 */
1155 HWTEST_F(SkillsBaseTest, AaFwk_Skills_RegionMatches_0300, Function | MediumTest | Level1)
1156 {
1157 std::string type = "this is type";
1158 int toffset = 1;
1159 std::string other = "this is other";
1160 int ooffset = -2;
1161 int len = 20;
1162 bool result = base_->RegionMatches(type, toffset, other, ooffset, len);
1163 EXPECT_EQ(result, false);
1164 }
1165
1166 /**
1167 * @tc.number: AaFwk_Skills_MatchEntities_0200
1168 * @tc.name: MatchEntities
1169 * @tc.desc: Test MatchEntities.
1170 * @tc.require: issue
1171 */
1172 HWTEST_F(SkillsBaseTest, AaFwk_Skills_MatchEntities_0200, Function | MediumTest | Level1)
1173 {
1174 std::vector<std::string> entities;
1175 std::string ret = "";
1176 std::string result = base_->MatchEntities(entities);
1177 EXPECT_EQ(result, ret);
1178 }
1179
1180 using testParamsType = std::tuple<std::string, std::string>;
1181 class SkillsParamsTest : public testing::TestWithParam<testParamsType> {
1182 public:
SkillsParamsTest()1183 SkillsParamsTest()
1184 {}
~SkillsParamsTest()1185 ~SkillsParamsTest()
1186 {}
1187 static void SetUpTestCase(void);
1188 static void TearDownTestCase(void);
1189 void SetUp();
1190 void TearDown();
1191 std::shared_ptr<Skills> skills_ = nullptr;
1192 };
1193
SetUpTestCase(void)1194 void SkillsParamsTest::SetUpTestCase(void)
1195 {}
1196
TearDownTestCase(void)1197 void SkillsParamsTest::TearDownTestCase(void)
1198 {}
1199
SetUp(void)1200 void SkillsParamsTest::SetUp(void)
1201 {
1202 skills_ = std::make_shared<Skills>();
1203 }
1204
TearDown(void)1205 void SkillsParamsTest::TearDown(void)
1206 {}
1207
1208 /**
1209 * @tc.number: AaFwk_Skills_Params_0100
1210 * @tc.name: SetWantParams/GetWantParams
1211 * @tc.desc: Verify addType/removeType result.
1212 */
1213 HWTEST_P(SkillsParamsTest, AaFwk_Skills_Params_0100, Function | MediumTest | Level1)
1214 {
1215 std::string keyStr = std::get<0>(GetParam());
1216 std::string valueStr = std::get<1>(GetParam());
1217 WantParams wantParams;
1218 wantParams.SetParam(keyStr, String::Box(valueStr));
1219 skills_->SetWantParams(wantParams);
1220 EXPECT_EQ(valueStr, String::Unbox(IString::Query(skills_->GetWantParams().GetParam(keyStr))));
1221 }
1222
1223 INSTANTIATE_TEST_SUITE_P(SkillsParamsTestCaseP, SkillsParamsTest,
1224 testing::Values(testParamsType("", "asdsdsdasa"), testParamsType(std::string(LARGE_STR_LEN + 1, 's'), "sadsdsdads"),
1225 testParamsType("#$%^&*(!@\":<>{}", "asdsdsdasa"), testParamsType("3456677", ""),
1226 testParamsType("1234", std::string(LARGE_STR_LEN + 1, 's')),
1227 testParamsType("2323sdasdZ", "#$%^&*(!@\":<>{}sadsdasdsaf"), testParamsType("12345667", "sdasdfdsffdgfdg"),
1228 testParamsType("", ""),
1229 testParamsType(std::string(LARGE_STR_LEN + 1, 'k'), std::string(LARGE_STR_LEN + 1, 'k')),
1230 testParamsType("#$%^&*(!@\":<>{},/", "#$%^&*(!@\":<>{},/")));
1231 } // namespace AAFwk
1232 } // namespace OHOS