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