15ba71b47Sopenharmony_ci/*
25ba71b47Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
35ba71b47Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ba71b47Sopenharmony_ci * you may not use this file except in compliance with the License.
55ba71b47Sopenharmony_ci * You may obtain a copy of the License at
65ba71b47Sopenharmony_ci *
75ba71b47Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ba71b47Sopenharmony_ci *
95ba71b47Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ba71b47Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ba71b47Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ba71b47Sopenharmony_ci * See the License for the specific language governing permissions and
135ba71b47Sopenharmony_ci * limitations under the License.
145ba71b47Sopenharmony_ci */
155ba71b47Sopenharmony_ci#include "gtest/gtest.h"
165ba71b47Sopenharmony_ci#include "string_ex.h"
175ba71b47Sopenharmony_ci#include "system_ability_definition.h"
185ba71b47Sopenharmony_ci#include "test_log.h"
195ba71b47Sopenharmony_ci#include "tools.h"
205ba71b47Sopenharmony_ci
215ba71b47Sopenharmony_ci#define private public
225ba71b47Sopenharmony_ci#include "parse_util.h"
235ba71b47Sopenharmony_ciusing namespace std;
245ba71b47Sopenharmony_ciusing namespace testing;
255ba71b47Sopenharmony_ciusing namespace testing::ext;
265ba71b47Sopenharmony_ci
275ba71b47Sopenharmony_cinamespace OHOS {
285ba71b47Sopenharmony_cinamespace SAMGR {
295ba71b47Sopenharmony_cinamespace {
305ba71b47Sopenharmony_ci    const std::string TEST_RESOURCE_PATH = "/data/test/resource/samgr/profile/";
315ba71b47Sopenharmony_ci    const std::u16string TEST_PROCESS_NAME = u"sa_test";
325ba71b47Sopenharmony_ci    const std::string EVENT_STRING;
335ba71b47Sopenharmony_ci    const std::string EVENT_TYPE ;
345ba71b47Sopenharmony_ci    const std::string EVENT_NAME ;
355ba71b47Sopenharmony_ci    const std::string EVENT_VALUE ;
365ba71b47Sopenharmony_ci    const int32_t TEST_NUM = 123;
375ba71b47Sopenharmony_ci    const int32_t MOCK_SAID = 1492;
385ba71b47Sopenharmony_ci    const int32_t TEST_PROFILE_SAID = 9999;
395ba71b47Sopenharmony_ci    const int32_t TEST_PROFILE_SAID_INVAILD = 9990;
405ba71b47Sopenharmony_ci    constexpr const char* SA_TAG_DEVICE_ON_LINE = "deviceonline";
415ba71b47Sopenharmony_ci    constexpr const char* SA_TAG_SETTING_SWITCH = "settingswitch";
425ba71b47Sopenharmony_ci    constexpr const char* SA_TAG_COMMON_EVENT = "commonevent";
435ba71b47Sopenharmony_ci    constexpr const char* SA_TAG_PARAM = "param";
445ba71b47Sopenharmony_ci    constexpr const char* SA_TAG_TIEMD_EVENT = "timedevent";
455ba71b47Sopenharmony_ci    const string EXTENSIOON_BACKUP = "backup";
465ba71b47Sopenharmony_ci    const string EXTENSIOON_RESTORE = "restore";
475ba71b47Sopenharmony_ci    constexpr int32_t MAX_JSON_STRING_LENGTH = 128;
485ba71b47Sopenharmony_ci    constexpr int32_t MAX_EXTENSIONO_NUM = 100;
495ba71b47Sopenharmony_ci}
505ba71b47Sopenharmony_ci
515ba71b47Sopenharmony_ciclass ParseUtilTest : public testing::Test {
525ba71b47Sopenharmony_cipublic:
535ba71b47Sopenharmony_ci    static void SetUpTestCase();
545ba71b47Sopenharmony_ci    static void TearDownTestCase();
555ba71b47Sopenharmony_ci    void SetUp();
565ba71b47Sopenharmony_ci    void TearDown();
575ba71b47Sopenharmony_ciprotected:
585ba71b47Sopenharmony_ci    std::shared_ptr<ParseUtil> parser_;
595ba71b47Sopenharmony_ci};
605ba71b47Sopenharmony_ci
615ba71b47Sopenharmony_civoid ParseUtilTest::SetUpTestCase()
625ba71b47Sopenharmony_ci{
635ba71b47Sopenharmony_ci    DTEST_LOG << "SetUpTestCase" << std::endl;
645ba71b47Sopenharmony_ci}
655ba71b47Sopenharmony_ci
665ba71b47Sopenharmony_civoid ParseUtilTest::TearDownTestCase()
675ba71b47Sopenharmony_ci{
685ba71b47Sopenharmony_ci    DTEST_LOG << "TearDownTestCase" << std::endl;
695ba71b47Sopenharmony_ci}
705ba71b47Sopenharmony_ci
715ba71b47Sopenharmony_civoid ParseUtilTest::SetUp()
725ba71b47Sopenharmony_ci{
735ba71b47Sopenharmony_ci    DTEST_LOG << "SetUp" << std::endl;
745ba71b47Sopenharmony_ci    if (parser_ == nullptr) {
755ba71b47Sopenharmony_ci        parser_ = std::make_shared<ParseUtil>();
765ba71b47Sopenharmony_ci    }
775ba71b47Sopenharmony_ci}
785ba71b47Sopenharmony_ci
795ba71b47Sopenharmony_civoid ParseUtilTest::TearDown()
805ba71b47Sopenharmony_ci{
815ba71b47Sopenharmony_ci    DTEST_LOG << "TearDown" << std::endl;
825ba71b47Sopenharmony_ci    if (parser_ != nullptr) {
835ba71b47Sopenharmony_ci        parser_->ClearResource();
845ba71b47Sopenharmony_ci    }
855ba71b47Sopenharmony_ci}
865ba71b47Sopenharmony_ci
875ba71b47Sopenharmony_ci/**
885ba71b47Sopenharmony_ci * @tc.name: ParseSaProfile001
895ba71b47Sopenharmony_ci * @tc.desc: Verify if can load not exist file
905ba71b47Sopenharmony_ci * @tc.type: FUNC
915ba71b47Sopenharmony_ci */
925ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseSaProfile001, TestSize.Level2)
935ba71b47Sopenharmony_ci{
945ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSaProfile001 start " << std::endl;
955ba71b47Sopenharmony_ci    /**
965ba71b47Sopenharmony_ci     * @tc.steps: step1. parse not exsit config file
975ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load not exist file
985ba71b47Sopenharmony_ci     */
995ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "notExist");
1005ba71b47Sopenharmony_ci    EXPECT_FALSE(ret);
1015ba71b47Sopenharmony_ci}
1025ba71b47Sopenharmony_ci
1035ba71b47Sopenharmony_ci/**
1045ba71b47Sopenharmony_ci * @tc.name: GetSaProfiles001
1055ba71b47Sopenharmony_ci * @tc.desc:  Verify if not load sa file return empty list
1065ba71b47Sopenharmony_ci * @tc.type: FUNC
1075ba71b47Sopenharmony_ci */
1085ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetSaProfiles001, TestSize.Level3)
1095ba71b47Sopenharmony_ci{
1105ba71b47Sopenharmony_ci    DTEST_LOG << " GetSaProfiles001 start " << std::endl;
1115ba71b47Sopenharmony_ci    /**
1125ba71b47Sopenharmony_ci     * @tc.steps: step1. Get empty config when not parse sa file.
1135ba71b47Sopenharmony_ci     * @tc.expected: step1. return empty list when not load sa file
1145ba71b47Sopenharmony_ci     */
1155ba71b47Sopenharmony_ci    list<SaProfile> profiles = parser_->GetAllSaProfiles();
1165ba71b47Sopenharmony_ci    EXPECT_TRUE(profiles.empty());
1175ba71b47Sopenharmony_ci}
1185ba71b47Sopenharmony_ci
1195ba71b47Sopenharmony_ci/**
1205ba71b47Sopenharmony_ci * @tc.name: GetSaProfiles002
1215ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load normal sa profile
1225ba71b47Sopenharmony_ci * @tc.type: FUNC
1235ba71b47Sopenharmony_ci */
1245ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetSaProfiles002, TestSize.Level3)
1255ba71b47Sopenharmony_ci{
1265ba71b47Sopenharmony_ci    DTEST_LOG << " GetSaProfiles002 start " << std::endl;
1275ba71b47Sopenharmony_ci    /**
1285ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct profile when parse sa file.
1295ba71b47Sopenharmony_ci     * @tc.expected: step1. return correct profile object when load correct config file
1305ba71b47Sopenharmony_ci     */
1315ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "profile.json");
1325ba71b47Sopenharmony_ci    ASSERT_TRUE(ret);
1335ba71b47Sopenharmony_ci    SaProfile saRunOnCreateTrue;
1345ba71b47Sopenharmony_ci    saRunOnCreateTrue.runOnCreate = true;
1355ba71b47Sopenharmony_ci    SaProfile saRunOnCreateFalse;
1365ba71b47Sopenharmony_ci    parser_->saProfiles_.emplace_back(saRunOnCreateTrue);
1375ba71b47Sopenharmony_ci    parser_->saProfiles_.emplace_back(saRunOnCreateFalse);
1385ba71b47Sopenharmony_ci    list<SaProfile> profiles = parser_->GetAllSaProfiles();
1395ba71b47Sopenharmony_ci    if (!profiles.empty()) {
1405ba71b47Sopenharmony_ci        SaProfile& profile = *(profiles.begin());
1415ba71b47Sopenharmony_ci        EXPECT_EQ(profile.process, TEST_PROCESS_NAME);
1425ba71b47Sopenharmony_ci        EXPECT_EQ(profile.saId, TEST_PROFILE_SAID);
1435ba71b47Sopenharmony_ci    }
1445ba71b47Sopenharmony_ci}
1455ba71b47Sopenharmony_ci
1465ba71b47Sopenharmony_ci/**
1475ba71b47Sopenharmony_ci * @tc.name: ParseTrustConfig001
1485ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load file with one sa
1495ba71b47Sopenharmony_ci * @tc.type: FUNC
1505ba71b47Sopenharmony_ci */
1515ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseTrustConfig001, TestSize.Level1)
1525ba71b47Sopenharmony_ci{
1535ba71b47Sopenharmony_ci    DTEST_LOG << " ParseTrustConfig001 start " << std::endl;
1545ba71b47Sopenharmony_ci    /**
1555ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct map when parse config file.
1565ba71b47Sopenharmony_ci     * @tc.expected: step1. return correct profile object when load correct config file
1575ba71b47Sopenharmony_ci     */
1585ba71b47Sopenharmony_ci    std::map<std::u16string, std::set<int32_t>> values;
1595ba71b47Sopenharmony_ci    bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "test_trust_one_sa.json", values);
1605ba71b47Sopenharmony_ci    ASSERT_TRUE(ret);
1615ba71b47Sopenharmony_ci    /**
1625ba71b47Sopenharmony_ci     * @tc.steps: step2. Check map values
1635ba71b47Sopenharmony_ci     * @tc.expected: step2. return expect values
1645ba71b47Sopenharmony_ci     */
1655ba71b47Sopenharmony_ci    for (const auto& [process, saIds] : values) {
1665ba71b47Sopenharmony_ci        EXPECT_EQ(Str16ToStr8(process), "test");
1675ba71b47Sopenharmony_ci        EXPECT_EQ(saIds.size(), 1);
1685ba71b47Sopenharmony_ci        EXPECT_EQ(saIds.count(1401), 1);
1695ba71b47Sopenharmony_ci    }
1705ba71b47Sopenharmony_ci}
1715ba71b47Sopenharmony_ci
1725ba71b47Sopenharmony_ci/**
1735ba71b47Sopenharmony_ci * @tc.name: ParseTrustConfig002
1745ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load file with muti sa
1755ba71b47Sopenharmony_ci * @tc.type: FUNC
1765ba71b47Sopenharmony_ci */
1775ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseTrustConfig002, TestSize.Level1)
1785ba71b47Sopenharmony_ci{
1795ba71b47Sopenharmony_ci    DTEST_LOG << " ParseTrustConfig002 start " << std::endl;
1805ba71b47Sopenharmony_ci    /**
1815ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct map when parse config file.
1825ba71b47Sopenharmony_ci     * @tc.expected: step1. return correct profile object when load correct config file
1835ba71b47Sopenharmony_ci     */
1845ba71b47Sopenharmony_ci    std::map<std::u16string, std::set<int32_t>> values;
1855ba71b47Sopenharmony_ci    bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "test_trust_muti_sa.json", values);
1865ba71b47Sopenharmony_ci    ASSERT_TRUE(ret);
1875ba71b47Sopenharmony_ci    /**
1885ba71b47Sopenharmony_ci     * @tc.steps: step2. Check map values
1895ba71b47Sopenharmony_ci     * @tc.expected: step2. return expect values
1905ba71b47Sopenharmony_ci     */
1915ba71b47Sopenharmony_ci    for (const auto& [process, saIds] : values) {
1925ba71b47Sopenharmony_ci        EXPECT_EQ(Str16ToStr8(process), "test");
1935ba71b47Sopenharmony_ci        EXPECT_EQ(saIds.size(), 5);
1945ba71b47Sopenharmony_ci        EXPECT_EQ(saIds.count(1401), 1);
1955ba71b47Sopenharmony_ci    }
1965ba71b47Sopenharmony_ci}
1975ba71b47Sopenharmony_ci
1985ba71b47Sopenharmony_ci/**
1995ba71b47Sopenharmony_ci * @tc.name: ParseTrustConfig003
2005ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load not invalid root file
2015ba71b47Sopenharmony_ci * @tc.type: FUNC
2025ba71b47Sopenharmony_ci */
2035ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseTrustConfig003, TestSize.Level1)
2045ba71b47Sopenharmony_ci{
2055ba71b47Sopenharmony_ci    DTEST_LOG << " ParseTrustConfig003 start " << std::endl;
2065ba71b47Sopenharmony_ci    /**
2075ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct map when parse config file.
2085ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load invalid root file
2095ba71b47Sopenharmony_ci     */
2105ba71b47Sopenharmony_ci    std::map<std::u16string, std::set<int32_t>> values;
2115ba71b47Sopenharmony_ci    bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_root_trust.json", values);
2125ba71b47Sopenharmony_ci    ASSERT_FALSE(ret);
2135ba71b47Sopenharmony_ci}
2145ba71b47Sopenharmony_ci
2155ba71b47Sopenharmony_ci/**
2165ba71b47Sopenharmony_ci * @tc.name: ParseTrustConfig004
2175ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load not exist file
2185ba71b47Sopenharmony_ci * @tc.type: FUNC
2195ba71b47Sopenharmony_ci */
2205ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseTrustConfig004, TestSize.Level1)
2215ba71b47Sopenharmony_ci{
2225ba71b47Sopenharmony_ci    DTEST_LOG << " ParseTrustConfig004 start " << std::endl;
2235ba71b47Sopenharmony_ci    /**
2245ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct profile when parse sa file.
2255ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when not exist file
2265ba71b47Sopenharmony_ci     */
2275ba71b47Sopenharmony_ci    std::map<std::u16string, std::set<int32_t>> values;
2285ba71b47Sopenharmony_ci    bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "notExist", values);
2295ba71b47Sopenharmony_ci    ASSERT_FALSE(ret);
2305ba71b47Sopenharmony_ci}
2315ba71b47Sopenharmony_ci
2325ba71b47Sopenharmony_ci/**
2335ba71b47Sopenharmony_ci * @tc.name: ParseTrustConfig005
2345ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load invalid element config
2355ba71b47Sopenharmony_ci * @tc.type: FUNC
2365ba71b47Sopenharmony_ci */
2375ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseTrustConfig005, TestSize.Level1)
2385ba71b47Sopenharmony_ci{
2395ba71b47Sopenharmony_ci    DTEST_LOG << " ParseTrustConfig005 start " << std::endl;
2405ba71b47Sopenharmony_ci    /**
2415ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct profile when parse invalid element config.
2425ba71b47Sopenharmony_ci     * @tc.expected: step1. return correct profile object when load correct config file
2435ba71b47Sopenharmony_ci     */
2445ba71b47Sopenharmony_ci    std::map<std::u16string, std::set<int32_t>> values;
2455ba71b47Sopenharmony_ci    bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_element_trust.json", values);
2465ba71b47Sopenharmony_ci    ASSERT_TRUE(ret);
2475ba71b47Sopenharmony_ci    for (const auto& [process, saIds] : values) {
2485ba71b47Sopenharmony_ci        EXPECT_EQ(Str16ToStr8(process), "test");
2495ba71b47Sopenharmony_ci        EXPECT_EQ(saIds.size(), 3);
2505ba71b47Sopenharmony_ci        EXPECT_EQ(saIds.count(1401), 1);
2515ba71b47Sopenharmony_ci    }
2525ba71b47Sopenharmony_ci}
2535ba71b47Sopenharmony_ci
2545ba71b47Sopenharmony_ci/**
2555ba71b47Sopenharmony_ci * @tc.name: ParseTrustConfig006
2565ba71b47Sopenharmony_ci * @tc.desc:  Verify if can load invalid muti root file
2575ba71b47Sopenharmony_ci * @tc.type: FUNC
2585ba71b47Sopenharmony_ci */
2595ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseTrustConfig006, TestSize.Level1)
2605ba71b47Sopenharmony_ci{
2615ba71b47Sopenharmony_ci    DTEST_LOG << " ParseTrustConfig006 start " << std::endl;
2625ba71b47Sopenharmony_ci    /**
2635ba71b47Sopenharmony_ci     * @tc.steps: step1. Get correct profile when parse sa file.
2645ba71b47Sopenharmony_ci     * @tc.expected: step1. return correct profile object when load correct config file
2655ba71b47Sopenharmony_ci     */
2665ba71b47Sopenharmony_ci    std::map<std::u16string, std::set<int32_t>> values;
2675ba71b47Sopenharmony_ci    bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_muti_root_trust.json", values);
2685ba71b47Sopenharmony_ci    ASSERT_FALSE(ret);
2695ba71b47Sopenharmony_ci}
2705ba71b47Sopenharmony_ci
2715ba71b47Sopenharmony_ci/**
2725ba71b47Sopenharmony_ci * @tc.name: RemoveSaProfile001
2735ba71b47Sopenharmony_ci * @tc.desc:  Verify if can remove not-existed id
2745ba71b47Sopenharmony_ci * @tc.type: FUNC
2755ba71b47Sopenharmony_ci */
2765ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, RemoveSaProfile001, TestSize.Level3)
2775ba71b47Sopenharmony_ci{
2785ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSaProfile001 start " << std::endl;
2795ba71b47Sopenharmony_ci    /**
2805ba71b47Sopenharmony_ci     * @tc.steps: step1. parse not exsit config file
2815ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load not exist file
2825ba71b47Sopenharmony_ci     */
2835ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "notExist");
2845ba71b47Sopenharmony_ci    EXPECT_FALSE(ret);
2855ba71b47Sopenharmony_ci    /**
2865ba71b47Sopenharmony_ci     * @tc.steps: step2. remove not-existed id
2875ba71b47Sopenharmony_ci     * @tc.expected: step2. not crash
2885ba71b47Sopenharmony_ci     */
2895ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(111);
2905ba71b47Sopenharmony_ci    auto profiles = parser_->GetAllSaProfiles();
2915ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 0);
2925ba71b47Sopenharmony_ci}
2935ba71b47Sopenharmony_ci
2945ba71b47Sopenharmony_ci/**
2955ba71b47Sopenharmony_ci * @tc.name: RemoveSaProfile002
2965ba71b47Sopenharmony_ci * @tc.desc:  Verify if can can remove not-existed id
2975ba71b47Sopenharmony_ci * @tc.type: FUNC
2985ba71b47Sopenharmony_ci */
2995ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, RemoveSaProfile002, TestSize.Level3)
3005ba71b47Sopenharmony_ci{
3015ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSaProfile002 start " << std::endl;
3025ba71b47Sopenharmony_ci    /**
3035ba71b47Sopenharmony_ci     * @tc.steps: step1. parse multi-sa profile
3045ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load multi-sa profile
3055ba71b47Sopenharmony_ci     */
3065ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
3075ba71b47Sopenharmony_ci    EXPECT_TRUE(ret);
3085ba71b47Sopenharmony_ci    auto profiles = parser_->GetAllSaProfiles();
3095ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 4);
3105ba71b47Sopenharmony_ci    /**
3115ba71b47Sopenharmony_ci     * @tc.steps: step2. remove not-existed id
3125ba71b47Sopenharmony_ci     * @tc.expected: step2. not crash
3135ba71b47Sopenharmony_ci     */
3145ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(111);
3155ba71b47Sopenharmony_ci    profiles = parser_->GetAllSaProfiles();
3165ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 4);
3175ba71b47Sopenharmony_ci}
3185ba71b47Sopenharmony_ci
3195ba71b47Sopenharmony_ci/**
3205ba71b47Sopenharmony_ci * @tc.name: RemoveSaProfile003
3215ba71b47Sopenharmony_ci * @tc.desc:  Verify if can remove one existed id
3225ba71b47Sopenharmony_ci * @tc.type: FUNC
3235ba71b47Sopenharmony_ci */
3245ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, RemoveSaProfile003, TestSize.Level3)
3255ba71b47Sopenharmony_ci{
3265ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSaProfile003 start " << std::endl;
3275ba71b47Sopenharmony_ci    /**
3285ba71b47Sopenharmony_ci     * @tc.steps: step1. parse multi-sa profile
3295ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load multi-sa profile
3305ba71b47Sopenharmony_ci     */
3315ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
3325ba71b47Sopenharmony_ci    EXPECT_TRUE(ret);
3335ba71b47Sopenharmony_ci    auto profiles = parser_->GetAllSaProfiles();
3345ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 4);
3355ba71b47Sopenharmony_ci    /**
3365ba71b47Sopenharmony_ci     * @tc.steps: step2. remove one existed id
3375ba71b47Sopenharmony_ci     * @tc.expected: step2. remove successfully
3385ba71b47Sopenharmony_ci     */
3395ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(9999);
3405ba71b47Sopenharmony_ci    profiles = parser_->GetAllSaProfiles();
3415ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 3);
3425ba71b47Sopenharmony_ci}
3435ba71b47Sopenharmony_ci
3445ba71b47Sopenharmony_ci/**
3455ba71b47Sopenharmony_ci * @tc.name: RemoveSaProfile004
3465ba71b47Sopenharmony_ci * @tc.desc:  Verify if can remove one existed id
3475ba71b47Sopenharmony_ci * @tc.type: FUNC
3485ba71b47Sopenharmony_ci */
3495ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, RemoveSaProfile004, TestSize.Level3)
3505ba71b47Sopenharmony_ci{
3515ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSaProfile004 start " << std::endl;
3525ba71b47Sopenharmony_ci    /**
3535ba71b47Sopenharmony_ci     * @tc.steps: step1. parse multi-sa profile
3545ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load multi-sa profile
3555ba71b47Sopenharmony_ci     */
3565ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
3575ba71b47Sopenharmony_ci    EXPECT_TRUE(ret);
3585ba71b47Sopenharmony_ci    auto profiles = parser_->GetAllSaProfiles();
3595ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 4);
3605ba71b47Sopenharmony_ci    /**
3615ba71b47Sopenharmony_ci     * @tc.steps: step2. remove one existed id
3625ba71b47Sopenharmony_ci     * @tc.expected: step2. remove successfully
3635ba71b47Sopenharmony_ci     */
3645ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(9997);
3655ba71b47Sopenharmony_ci    profiles = parser_->GetAllSaProfiles();
3665ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 2);
3675ba71b47Sopenharmony_ci}
3685ba71b47Sopenharmony_ci
3695ba71b47Sopenharmony_ci/**
3705ba71b47Sopenharmony_ci * @tc.name: RemoveSaProfile005
3715ba71b47Sopenharmony_ci * @tc.desc:  Verify if can remove more existed id
3725ba71b47Sopenharmony_ci * @tc.type: FUNC
3735ba71b47Sopenharmony_ci */
3745ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, RemoveSaProfile005, TestSize.Level3)
3755ba71b47Sopenharmony_ci{
3765ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSaProfile004 start " << std::endl;
3775ba71b47Sopenharmony_ci    /**
3785ba71b47Sopenharmony_ci     * @tc.steps: step1. parse multi-sa profile
3795ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load multi-sa profile
3805ba71b47Sopenharmony_ci     */
3815ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
3825ba71b47Sopenharmony_ci    EXPECT_TRUE(ret);
3835ba71b47Sopenharmony_ci    auto profiles = parser_->GetAllSaProfiles();
3845ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 4);
3855ba71b47Sopenharmony_ci    /**
3865ba71b47Sopenharmony_ci     * @tc.steps: step2. remove more existed id
3875ba71b47Sopenharmony_ci     * @tc.expected: step2. remove successfully
3885ba71b47Sopenharmony_ci     */
3895ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(9997);
3905ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(9998);
3915ba71b47Sopenharmony_ci    parser_->RemoveSaProfile(9998);
3925ba71b47Sopenharmony_ci    profiles = parser_->GetAllSaProfiles();
3935ba71b47Sopenharmony_ci    EXPECT_EQ(profiles.size(), 1);
3945ba71b47Sopenharmony_ci}
3955ba71b47Sopenharmony_ci
3965ba71b47Sopenharmony_ci/**
3975ba71b47Sopenharmony_ci * @tc.name: CheckPathExist001
3985ba71b47Sopenharmony_ci * @tc.desc:  Verify if can check not exist file
3995ba71b47Sopenharmony_ci * @tc.type: FUNC
4005ba71b47Sopenharmony_ci */
4015ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, CheckPathExist001, TestSize.Level2)
4025ba71b47Sopenharmony_ci{
4035ba71b47Sopenharmony_ci    DTEST_LOG << " CheckPathExist001 start " << std::endl;
4045ba71b47Sopenharmony_ci    /**
4055ba71b47Sopenharmony_ci     * @tc.steps: step1. check not exsit config file
4065ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when check not exist file
4075ba71b47Sopenharmony_ci     */
4085ba71b47Sopenharmony_ci    bool ret = parser_->CheckPathExist(TEST_RESOURCE_PATH + "not_exist.json");
4095ba71b47Sopenharmony_ci    EXPECT_FALSE(ret);
4105ba71b47Sopenharmony_ci}
4115ba71b47Sopenharmony_ci
4125ba71b47Sopenharmony_ci/**
4135ba71b47Sopenharmony_ci * @tc.name: CheckPathExist002
4145ba71b47Sopenharmony_ci * @tc.desc:  Verify if can check exist file
4155ba71b47Sopenharmony_ci * @tc.type: FUNC
4165ba71b47Sopenharmony_ci */
4175ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, CheckPathExist002, TestSize.Level2)
4185ba71b47Sopenharmony_ci{
4195ba71b47Sopenharmony_ci    DTEST_LOG << " CheckPathExist002 start " << std::endl;
4205ba71b47Sopenharmony_ci    /**
4215ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit config file
4225ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load not exist file
4235ba71b47Sopenharmony_ci     */
4245ba71b47Sopenharmony_ci    bool ret = parser_->CheckPathExist(TEST_RESOURCE_PATH + "multi_sa_profile.json");
4255ba71b47Sopenharmony_ci    EXPECT_TRUE(ret);
4265ba71b47Sopenharmony_ci}
4275ba71b47Sopenharmony_ci
4285ba71b47Sopenharmony_ci/**
4295ba71b47Sopenharmony_ci * @tc.name: GetProfile001
4305ba71b47Sopenharmony_ci * @tc.desc: Verify if can get not-exist profile
4315ba71b47Sopenharmony_ci * @tc.type: FUNC
4325ba71b47Sopenharmony_ci * @tc.require: I5KMF7
4335ba71b47Sopenharmony_ci */
4345ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetProfile001, TestSize.Level2)
4355ba71b47Sopenharmony_ci{
4365ba71b47Sopenharmony_ci    DTEST_LOG << " GetProfile001 start " << std::endl;
4375ba71b47Sopenharmony_ci    /**
4385ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit config file
4395ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load not exist file
4405ba71b47Sopenharmony_ci     */
4415ba71b47Sopenharmony_ci    SaProfile saProfile;
4425ba71b47Sopenharmony_ci    bool ret = parser_->GetProfile(TEST_PROFILE_SAID, saProfile);
4435ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
4445ba71b47Sopenharmony_ci}
4455ba71b47Sopenharmony_ci
4465ba71b47Sopenharmony_ci/**
4475ba71b47Sopenharmony_ci * @tc.name: GetProfile002
4485ba71b47Sopenharmony_ci * @tc.desc: Verify if can get exist profile
4495ba71b47Sopenharmony_ci * @tc.type: FUNC
4505ba71b47Sopenharmony_ci * @tc.require: I5KMF7
4515ba71b47Sopenharmony_ci */
4525ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetProfile002, TestSize.Level2)
4535ba71b47Sopenharmony_ci{
4545ba71b47Sopenharmony_ci    DTEST_LOG << " GetProfile002 start " << std::endl;
4555ba71b47Sopenharmony_ci    /**
4565ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit config file
4575ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load not exist file
4585ba71b47Sopenharmony_ci     */
4595ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
4605ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
4615ba71b47Sopenharmony_ci    SaProfile saProfile;
4625ba71b47Sopenharmony_ci    ret = parser_->GetProfile(TEST_PROFILE_SAID, saProfile);
4635ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
4645ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.saId, TEST_PROFILE_SAID);
4655ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.runOnCreate, true);
4665ba71b47Sopenharmony_ci}
4675ba71b47Sopenharmony_ci
4685ba71b47Sopenharmony_ci/**
4695ba71b47Sopenharmony_ci * @tc.name: LoadSaLib001
4705ba71b47Sopenharmony_ci * @tc.desc: Verify if can load salib
4715ba71b47Sopenharmony_ci * @tc.type: FUNC
4725ba71b47Sopenharmony_ci * @tc.require: I5KMF7
4735ba71b47Sopenharmony_ci */
4745ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, LoadSaLib001, TestSize.Level2)
4755ba71b47Sopenharmony_ci{
4765ba71b47Sopenharmony_ci    DTEST_LOG << " LoadSaLib001 start " << std::endl;
4775ba71b47Sopenharmony_ci    /**
4785ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit salib
4795ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when load exist salib
4805ba71b47Sopenharmony_ci     */
4815ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
4825ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
4835ba71b47Sopenharmony_ci    ret = parser_->LoadSaLib(TEST_PROFILE_SAID);
4845ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
4855ba71b47Sopenharmony_ci}
4865ba71b47Sopenharmony_ci
4875ba71b47Sopenharmony_ci/**
4885ba71b47Sopenharmony_ci * @tc.name: LoadSaLib002
4895ba71b47Sopenharmony_ci * @tc.desc: Verify if can load salib
4905ba71b47Sopenharmony_ci * @tc.type: FUNC
4915ba71b47Sopenharmony_ci * @tc.require: I5KMF7
4925ba71b47Sopenharmony_ci */
4935ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, LoadSaLib002, TestSize.Level2)
4945ba71b47Sopenharmony_ci{
4955ba71b47Sopenharmony_ci    DTEST_LOG << " LoadSaLib002 start " << std::endl;
4965ba71b47Sopenharmony_ci    /**
4975ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit salib
4985ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load not exist salib
4995ba71b47Sopenharmony_ci     */
5005ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
5015ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5025ba71b47Sopenharmony_ci    ret = parser_->LoadSaLib(TEST_PROFILE_SAID_INVAILD);
5035ba71b47Sopenharmony_ci    parser_->CloseSo(MOCK_SAID);
5045ba71b47Sopenharmony_ci    EXPECT_NE(ret, true);
5055ba71b47Sopenharmony_ci}
5065ba71b47Sopenharmony_ci
5075ba71b47Sopenharmony_ci/**
5085ba71b47Sopenharmony_ci * @tc.name: LoadSaLib003
5095ba71b47Sopenharmony_ci * @tc.desc: Verify if can load salib
5105ba71b47Sopenharmony_ci * @tc.type: FUNC
5115ba71b47Sopenharmony_ci * @tc.require: I5KMF7
5125ba71b47Sopenharmony_ci */
5135ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, LoadSaLib003, TestSize.Level2)
5145ba71b47Sopenharmony_ci{
5155ba71b47Sopenharmony_ci    DTEST_LOG << " LoadSaLib003 start " << std::endl;
5165ba71b47Sopenharmony_ci    /**
5175ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit salib
5185ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load not exist salib
5195ba71b47Sopenharmony_ci     */
5205ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "mock.json");
5215ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5225ba71b47Sopenharmony_ci    ret = parser_->LoadSaLib(MOCK_SAID);
5235ba71b47Sopenharmony_ci    parser_->CloseSo(MOCK_SAID);
5245ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5255ba71b47Sopenharmony_ci}
5265ba71b47Sopenharmony_ci
5275ba71b47Sopenharmony_ci/**
5285ba71b47Sopenharmony_ci * @tc.name: LoadSaLib004
5295ba71b47Sopenharmony_ci * @tc.desc: Verify if can load salib
5305ba71b47Sopenharmony_ci * @tc.type: FUNC
5315ba71b47Sopenharmony_ci * @tc.require: I5KMF7
5325ba71b47Sopenharmony_ci */
5335ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, LoadSaLib004, TestSize.Level2)
5345ba71b47Sopenharmony_ci{
5355ba71b47Sopenharmony_ci    DTEST_LOG << " LoadSaLib004 start " << std::endl;
5365ba71b47Sopenharmony_ci    /**
5375ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit salib
5385ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load not exist salib
5395ba71b47Sopenharmony_ci     */
5405ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "mock.json");
5415ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5425ba71b47Sopenharmony_ci    ret = parser_->LoadSaLib(MOCK_SAID);
5435ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5445ba71b47Sopenharmony_ci    parser_->LoadSaLib(MOCK_SAID);
5455ba71b47Sopenharmony_ci}
5465ba71b47Sopenharmony_ci
5475ba71b47Sopenharmony_ci/**
5485ba71b47Sopenharmony_ci * @tc.name: LoadSaLib005
5495ba71b47Sopenharmony_ci * @tc.desc: Verify if can load salib
5505ba71b47Sopenharmony_ci * @tc.type: FUNC
5515ba71b47Sopenharmony_ci * @tc.require: I5KMF7
5525ba71b47Sopenharmony_ci */
5535ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, LoadSaLib005, TestSize.Level2)
5545ba71b47Sopenharmony_ci{
5555ba71b47Sopenharmony_ci    DTEST_LOG << " LoadSaLib005 start " << std::endl;
5565ba71b47Sopenharmony_ci    /**
5575ba71b47Sopenharmony_ci     * @tc.steps: step1. check exsit salib
5585ba71b47Sopenharmony_ci     * @tc.expected: step1. return false when load not exist salib
5595ba71b47Sopenharmony_ci     */
5605ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "empty_libpath.json");
5615ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5625ba71b47Sopenharmony_ci    ret = parser_->LoadSaLib(MOCK_SAID);
5635ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5645ba71b47Sopenharmony_ci}
5655ba71b47Sopenharmony_ci/**
5665ba71b47Sopenharmony_ci * @tc.name: GetProcessName001
5675ba71b47Sopenharmony_ci * @tc.desc: Verify if can get procesname
5685ba71b47Sopenharmony_ci * @tc.type: FUNC
5695ba71b47Sopenharmony_ci * @tc.require: I5KMF7
5705ba71b47Sopenharmony_ci */
5715ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetProcessName001, TestSize.Level3)
5725ba71b47Sopenharmony_ci{
5735ba71b47Sopenharmony_ci    DTEST_LOG << " GetProcessName001 " << std::endl;
5745ba71b47Sopenharmony_ci    /**
5755ba71b47Sopenharmony_ci     * @tc.steps: step1. get SaProfiles
5765ba71b47Sopenharmony_ci     * @tc.expected: step1. return true when SaProfiles
5775ba71b47Sopenharmony_ci     */
5785ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
5795ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5805ba71b47Sopenharmony_ci    std::u16string Name = parser_->GetProcessName();
5815ba71b47Sopenharmony_ci    EXPECT_EQ(Str16ToStr8(Name), "test");
5825ba71b47Sopenharmony_ci}
5835ba71b47Sopenharmony_ci
5845ba71b47Sopenharmony_ci/**
5855ba71b47Sopenharmony_ci * @tc.name: GetProcessName002
5865ba71b47Sopenharmony_ci * @tc.desc: Verify if can get procesname
5875ba71b47Sopenharmony_ci * @tc.type: FUNC
5885ba71b47Sopenharmony_ci * @tc.require: I5KMF7
5895ba71b47Sopenharmony_ci */
5905ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetProcessName002, TestSize.Level3)
5915ba71b47Sopenharmony_ci{
5925ba71b47Sopenharmony_ci    DTEST_LOG << " GetProcessName002 " << std::endl;
5935ba71b47Sopenharmony_ci    /**
5945ba71b47Sopenharmony_ci    * @tc.steps: step1. get SaProfiles
5955ba71b47Sopenharmony_ci    * @tc.expected: step1. return true when SaProfiles
5965ba71b47Sopenharmony_ci    */
5975ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.json");
5985ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
5995ba71b47Sopenharmony_ci    std::u16string Name = parser_->GetProcessName();
6005ba71b47Sopenharmony_ci    EXPECT_NE(Str16ToStr8(Name), "test_1");
6015ba71b47Sopenharmony_ci}
6025ba71b47Sopenharmony_ci
6035ba71b47Sopenharmony_ci
6045ba71b47Sopenharmony_ci/**
6055ba71b47Sopenharmony_ci * @tc.name: DeleteAllMark001
6065ba71b47Sopenharmony_ci * @tc.desc: Verify if can DeleteAllMark
6075ba71b47Sopenharmony_ci * @tc.type: FUNC
6085ba71b47Sopenharmony_ci * @tc.require: I5KMF7
6095ba71b47Sopenharmony_ci */
6105ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, DeleteAllMark001, TestSize.Level3)
6115ba71b47Sopenharmony_ci{
6125ba71b47Sopenharmony_ci    DTEST_LOG << " DeleteAllMark001 " << std::endl;
6135ba71b47Sopenharmony_ci    u16string temp = u"stests";
6145ba71b47Sopenharmony_ci    u16string mask = u"s";
6155ba71b47Sopenharmony_ci    u16string res = DeleteAllMark(temp, mask);
6165ba71b47Sopenharmony_ci    EXPECT_EQ(res, u"tet");
6175ba71b47Sopenharmony_ci}
6185ba71b47Sopenharmony_ci
6195ba71b47Sopenharmony_ci/**
6205ba71b47Sopenharmony_ci * @tc.name: GetOnDemandConditionsFromJson001
6215ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandConditions, conditions is empty.
6225ba71b47Sopenharmony_ci * @tc.type: FUNC
6235ba71b47Sopenharmony_ci * @tc.require: I6JE38
6245ba71b47Sopenharmony_ci */
6255ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandConditionsFromJson001, TestSize.Level3)
6265ba71b47Sopenharmony_ci{
6275ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson001 BEGIN" << std::endl;
6285ba71b47Sopenharmony_ci    nlohmann::json obj;
6295ba71b47Sopenharmony_ci    std::string key;
6305ba71b47Sopenharmony_ci    std::vector<OnDemandCondition> out;
6315ba71b47Sopenharmony_ci    SaProfile saProfile;
6325ba71b47Sopenharmony_ci    parser_->GetOnDemandConditionsFromJson(obj, key, out);
6335ba71b47Sopenharmony_ci    EXPECT_TRUE(out.empty());
6345ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson001 END" << std::endl;
6355ba71b47Sopenharmony_ci}
6365ba71b47Sopenharmony_ci
6375ba71b47Sopenharmony_ci/**
6385ba71b47Sopenharmony_ci * @tc.name: GetOnDemandConditionsFromJson002
6395ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandConditions, one condition.
6405ba71b47Sopenharmony_ci * @tc.type: FUNC
6415ba71b47Sopenharmony_ci * @tc.require: I6JE38
6425ba71b47Sopenharmony_ci */
6435ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandConditionsFromJson002, TestSize.Level3)
6445ba71b47Sopenharmony_ci{
6455ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson002 BEGIN" << std::endl;
6465ba71b47Sopenharmony_ci    nlohmann::json obj;
6475ba71b47Sopenharmony_ci    nlohmann::json conditions;
6485ba71b47Sopenharmony_ci    nlohmann::json condition;
6495ba71b47Sopenharmony_ci    condition["eventId"] = SA_TAG_DEVICE_ON_LINE;
6505ba71b47Sopenharmony_ci    condition["name"] = "mockName";
6515ba71b47Sopenharmony_ci    condition["value"] = "mockValue";
6525ba71b47Sopenharmony_ci    conditions[0] = condition;
6535ba71b47Sopenharmony_ci    obj["conditions"] = conditions;
6545ba71b47Sopenharmony_ci
6555ba71b47Sopenharmony_ci    std::string key = "conditions";
6565ba71b47Sopenharmony_ci    std::vector<OnDemandCondition> out;
6575ba71b47Sopenharmony_ci    SaProfile saProfile;
6585ba71b47Sopenharmony_ci    parser_->GetOnDemandConditionsFromJson(obj, key, out);
6595ba71b47Sopenharmony_ci    EXPECT_EQ(out.size(), 1);
6605ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson002 END" << std::endl;
6615ba71b47Sopenharmony_ci}
6625ba71b47Sopenharmony_ci
6635ba71b47Sopenharmony_ci/**
6645ba71b47Sopenharmony_ci * @tc.name: GetOnDemandConditionsFromJson003
6655ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandConditions, five condition.
6665ba71b47Sopenharmony_ci * @tc.type: FUNC
6675ba71b47Sopenharmony_ci * @tc.require: I6JE38
6685ba71b47Sopenharmony_ci */
6695ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandConditionsFromJson003, TestSize.Level3)
6705ba71b47Sopenharmony_ci{
6715ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson003 BEGIN" << std::endl;
6725ba71b47Sopenharmony_ci    nlohmann::json obj;
6735ba71b47Sopenharmony_ci    nlohmann::json conditions;
6745ba71b47Sopenharmony_ci    nlohmann::json condition;
6755ba71b47Sopenharmony_ci    condition["eventId"] = SA_TAG_DEVICE_ON_LINE;
6765ba71b47Sopenharmony_ci    condition["name"] = "mockName";
6775ba71b47Sopenharmony_ci    condition["value"] = "mockValue";
6785ba71b47Sopenharmony_ci    nlohmann::json condition2;
6795ba71b47Sopenharmony_ci    condition2["eventId"] = SA_TAG_SETTING_SWITCH;
6805ba71b47Sopenharmony_ci    condition2["name"] = "mockName";
6815ba71b47Sopenharmony_ci    condition2["value"] = "mockValue";
6825ba71b47Sopenharmony_ci    nlohmann::json condition3;
6835ba71b47Sopenharmony_ci    condition3["eventId"] = SA_TAG_COMMON_EVENT;
6845ba71b47Sopenharmony_ci    condition3["name"] = "mockName";
6855ba71b47Sopenharmony_ci    condition3["value"] = "mockValue";
6865ba71b47Sopenharmony_ci    nlohmann::json condition4;
6875ba71b47Sopenharmony_ci    condition4["eventId"] = SA_TAG_PARAM;
6885ba71b47Sopenharmony_ci    condition4["name"] = "mockName";
6895ba71b47Sopenharmony_ci    condition4["value"] = "mockValue";
6905ba71b47Sopenharmony_ci    nlohmann::json condition5;
6915ba71b47Sopenharmony_ci    condition5["eventId"] = SA_TAG_TIEMD_EVENT;
6925ba71b47Sopenharmony_ci    condition5["name"] = "mockName";
6935ba71b47Sopenharmony_ci    condition5["value"] = "mockValue";
6945ba71b47Sopenharmony_ci    conditions[0] = condition;
6955ba71b47Sopenharmony_ci    conditions[1] = condition2;
6965ba71b47Sopenharmony_ci    conditions[2] = condition3;
6975ba71b47Sopenharmony_ci    conditions[3] = condition4;
6985ba71b47Sopenharmony_ci    conditions[4] = condition5;
6995ba71b47Sopenharmony_ci    obj["conditions"] = conditions;
7005ba71b47Sopenharmony_ci
7015ba71b47Sopenharmony_ci    std::string key = "conditions";
7025ba71b47Sopenharmony_ci    std::vector<OnDemandCondition> out;
7035ba71b47Sopenharmony_ci    SaProfile saProfile;
7045ba71b47Sopenharmony_ci    parser_->GetOnDemandConditionsFromJson(obj, key, out);
7055ba71b47Sopenharmony_ci    EXPECT_EQ(out.size(), 5);
7065ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson003 END" << std::endl;
7075ba71b47Sopenharmony_ci}
7085ba71b47Sopenharmony_ci
7095ba71b47Sopenharmony_ci/**
7105ba71b47Sopenharmony_ci * @tc.name: GetOnDemandConditionsFromJson004
7115ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandConditions, invalid condition.
7125ba71b47Sopenharmony_ci * @tc.type: FUNC
7135ba71b47Sopenharmony_ci * @tc.require: I6JE38
7145ba71b47Sopenharmony_ci */
7155ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandConditionsFromJson004, TestSize.Level3)
7165ba71b47Sopenharmony_ci{
7175ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson004 BEGIN" << std::endl;
7185ba71b47Sopenharmony_ci    nlohmann::json obj;
7195ba71b47Sopenharmony_ci    nlohmann::json conditions;
7205ba71b47Sopenharmony_ci    nlohmann::json condition;
7215ba71b47Sopenharmony_ci    condition["eventId"] = "mockeventId";
7225ba71b47Sopenharmony_ci    condition["name"] = "mockName";
7235ba71b47Sopenharmony_ci    condition["value"] = "mockValue";
7245ba71b47Sopenharmony_ci    conditions[0] = condition;
7255ba71b47Sopenharmony_ci    obj["conditions"] = conditions;
7265ba71b47Sopenharmony_ci
7275ba71b47Sopenharmony_ci    std::string key = "conditions";
7285ba71b47Sopenharmony_ci    std::vector<OnDemandCondition> out;
7295ba71b47Sopenharmony_ci    SaProfile saProfile;
7305ba71b47Sopenharmony_ci    parser_->GetOnDemandConditionsFromJson(obj, key, out);
7315ba71b47Sopenharmony_ci    EXPECT_EQ(out.size(), 0);
7325ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandConditionsFromJson004 END" << std::endl;
7335ba71b47Sopenharmony_ci}
7345ba71b47Sopenharmony_ci
7355ba71b47Sopenharmony_ci
7365ba71b47Sopenharmony_ci/**
7375ba71b47Sopenharmony_ci * @tc.name: GetOnDemandExtraMessagesFromJson001
7385ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandExtraMessages, ExtraMessages is empty.
7395ba71b47Sopenharmony_ci * @tc.type: FUNC
7405ba71b47Sopenharmony_ci */
7415ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandExtraMessagesFromJson001, TestSize.Level3)
7425ba71b47Sopenharmony_ci{
7435ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandExtraMessagesFromJson001 BEGIN" << std::endl;
7445ba71b47Sopenharmony_ci    nlohmann::json obj;
7455ba71b47Sopenharmony_ci    std::string key;
7465ba71b47Sopenharmony_ci    std::map<std::string, std::string> out;
7475ba71b47Sopenharmony_ci    parser_->GetOnDemandExtraMessagesFromJson(obj, key, out);
7485ba71b47Sopenharmony_ci    EXPECT_TRUE(out.empty());
7495ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandExtraMessagesFromJson001 END" << std::endl;
7505ba71b47Sopenharmony_ci}
7515ba71b47Sopenharmony_ci
7525ba71b47Sopenharmony_ci/**
7535ba71b47Sopenharmony_ci * @tc.name: GetOnDemandExtraMessagesFromJson002
7545ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandExtraMessages, five ExtraMessages.
7555ba71b47Sopenharmony_ci * @tc.type: FUNC
7565ba71b47Sopenharmony_ci */
7575ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandExtraMessagesFromJson002, TestSize.Level3)
7585ba71b47Sopenharmony_ci{
7595ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandExtraMessagesFromJson002 BEGIN" << std::endl;
7605ba71b47Sopenharmony_ci    nlohmann::json obj;
7615ba71b47Sopenharmony_ci    nlohmann::json extraMessages;
7625ba71b47Sopenharmony_ci    extraMessages["eventId"] = SA_TAG_DEVICE_ON_LINE;
7635ba71b47Sopenharmony_ci    extraMessages["name"] = "mockName";
7645ba71b47Sopenharmony_ci    extraMessages["value"] = "mockValue";
7655ba71b47Sopenharmony_ci    extraMessages["123"] = "123";
7665ba71b47Sopenharmony_ci    extraMessages["abc"] = "";
7675ba71b47Sopenharmony_ci    obj["extra-messages"] = extraMessages;
7685ba71b47Sopenharmony_ci    std::string key = "extra-messages";
7695ba71b47Sopenharmony_ci    std::map<std::string, std::string> out;
7705ba71b47Sopenharmony_ci    parser_->GetOnDemandExtraMessagesFromJson(obj, key, out);
7715ba71b47Sopenharmony_ci    EXPECT_EQ(out.size(), 5);
7725ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandExtraMessagesFromJson002 END" << std::endl;
7735ba71b47Sopenharmony_ci}
7745ba71b47Sopenharmony_ci
7755ba71b47Sopenharmony_ci/**
7765ba71b47Sopenharmony_ci * @tc.name: GetOnDemandExtraMessagesFromJson003
7775ba71b47Sopenharmony_ci * @tc.desc: parse OnDemandExtraMessages, invalid ExtraMessage.
7785ba71b47Sopenharmony_ci * @tc.type: FUNC
7795ba71b47Sopenharmony_ci */
7805ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOnDemandExtraMessagesFromJson003, TestSize.Level3)
7815ba71b47Sopenharmony_ci{
7825ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandExtraMessagesFromJson003 BEGIN" << std::endl;
7835ba71b47Sopenharmony_ci    nlohmann::json obj;
7845ba71b47Sopenharmony_ci    nlohmann::json extraMessages;
7855ba71b47Sopenharmony_ci    extraMessages["123"] = 123;
7865ba71b47Sopenharmony_ci    extraMessages["abc"] = 456.7;
7875ba71b47Sopenharmony_ci    obj["extra-messages"] = extraMessages;
7885ba71b47Sopenharmony_ci    std::string key = "extra-messages";
7895ba71b47Sopenharmony_ci    std::map<std::string, std::string> out;
7905ba71b47Sopenharmony_ci    parser_->GetOnDemandExtraMessagesFromJson(obj, key, out);
7915ba71b47Sopenharmony_ci    EXPECT_EQ(out.size(), 0);
7925ba71b47Sopenharmony_ci    DTEST_LOG << " GetOnDemandExtraMessagesFromJson003 END" << std::endl;
7935ba71b47Sopenharmony_ci}
7945ba71b47Sopenharmony_ci
7955ba71b47Sopenharmony_ci
7965ba71b47Sopenharmony_ci/**
7975ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile001
7985ba71b47Sopenharmony_ci * @tc.desc: parse json file using big json file
7995ba71b47Sopenharmony_ci * @tc.type: FUNC
8005ba71b47Sopenharmony_ci */
8015ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile001, TestSize.Level3)
8025ba71b47Sopenharmony_ci{
8035ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile001 BEGIN" << std::endl;
8045ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8055ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_large.json");
8065ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
8075ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile001 END" << std::endl;
8085ba71b47Sopenharmony_ci}
8095ba71b47Sopenharmony_ci
8105ba71b47Sopenharmony_ci/**
8115ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile002
8125ba71b47Sopenharmony_ci * @tc.desc: parse json file using too long proces.
8135ba71b47Sopenharmony_ci * @tc.type: FUNC
8145ba71b47Sopenharmony_ci */
8155ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile002, TestSize.Level3)
8165ba71b47Sopenharmony_ci{
8175ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile002 BEGIN" << std::endl;
8185ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8195ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_long_process.json");
8205ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
8215ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile002 END" << std::endl;
8225ba71b47Sopenharmony_ci}
8235ba71b47Sopenharmony_ci
8245ba71b47Sopenharmony_ci/**
8255ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile003
8265ba71b47Sopenharmony_ci * @tc.desc: parse json file using error said.
8275ba71b47Sopenharmony_ci * @tc.type: FUNC
8285ba71b47Sopenharmony_ci */
8295ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile003, TestSize.Level3)
8305ba71b47Sopenharmony_ci{
8315ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile003 BEGIN" << std::endl;
8325ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8335ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_error_said.json");
8345ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
8355ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile003 END" << std::endl;
8365ba71b47Sopenharmony_ci}
8375ba71b47Sopenharmony_ci
8385ba71b47Sopenharmony_ci/**
8395ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile004
8405ba71b47Sopenharmony_ci * @tc.desc: parse json file using too long libpath.
8415ba71b47Sopenharmony_ci * @tc.type: FUNC
8425ba71b47Sopenharmony_ci */
8435ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile004, TestSize.Level3)
8445ba71b47Sopenharmony_ci{
8455ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile004 BEGIN" << std::endl;
8465ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8475ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_long_libpath.json");
8485ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
8495ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile004 END" << std::endl;
8505ba71b47Sopenharmony_ci}
8515ba71b47Sopenharmony_ci
8525ba71b47Sopenharmony_ci/**
8535ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile005
8545ba71b47Sopenharmony_ci * @tc.desc: parse json file using error bootPhase
8555ba71b47Sopenharmony_ci * @tc.type: FUNC
8565ba71b47Sopenharmony_ci */
8575ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile005, TestSize.Level3)
8585ba71b47Sopenharmony_ci{
8595ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile005 BEGIN" << std::endl;
8605ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8615ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_error_bootphase.json");
8625ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
8635ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile005 END" << std::endl;
8645ba71b47Sopenharmony_ci}
8655ba71b47Sopenharmony_ci
8665ba71b47Sopenharmony_ci/**
8675ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile006
8685ba71b47Sopenharmony_ci * @tc.desc: parse json file using error ondemand tag
8695ba71b47Sopenharmony_ci * @tc.type: FUNC
8705ba71b47Sopenharmony_ci */
8715ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile006, TestSize.Level3)
8725ba71b47Sopenharmony_ci{
8735ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile006 BEGIN" << std::endl;
8745ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8755ba71b47Sopenharmony_ci    // name or vale is more than 128 bytes
8765ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_error_ondemanad_tag.json");
8775ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
8785ba71b47Sopenharmony_ci    SaProfile saProfile;
8795ba71b47Sopenharmony_ci    parser_->GetProfile(1401, saProfile);
8805ba71b47Sopenharmony_ci    EXPECT_EQ(true, saProfile.startOnDemand.onDemandEvents.empty());
8815ba71b47Sopenharmony_ci    EXPECT_EQ(true, saProfile.stopOnDemand.onDemandEvents.empty());
8825ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile006 END" << std::endl;
8835ba71b47Sopenharmony_ci}
8845ba71b47Sopenharmony_ci
8855ba71b47Sopenharmony_ci/**
8865ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile007
8875ba71b47Sopenharmony_ci * @tc.desc: parse json file using correct profile
8885ba71b47Sopenharmony_ci * @tc.type: FUNC
8895ba71b47Sopenharmony_ci */
8905ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile007, TestSize.Level3)
8915ba71b47Sopenharmony_ci{
8925ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile007 BEGIN" << std::endl;
8935ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
8945ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile.json");
8955ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
8965ba71b47Sopenharmony_ci    EXPECT_EQ(parser_->saProfiles_.empty(), false);
8975ba71b47Sopenharmony_ci    SaProfile saProfile1;
8985ba71b47Sopenharmony_ci    parser_->GetProfile(1401, saProfile1);
8995ba71b47Sopenharmony_ci    EXPECT_EQ(1401, saProfile1.saId);
9005ba71b47Sopenharmony_ci    EXPECT_EQ(true, !saProfile1.startOnDemand.onDemandEvents.empty());
9015ba71b47Sopenharmony_ci    EXPECT_EQ(1, saProfile1.startOnDemand.onDemandEvents[0].eventId);
9025ba71b47Sopenharmony_ci    EXPECT_EQ("deviceonline", saProfile1.startOnDemand.onDemandEvents[0].name);
9035ba71b47Sopenharmony_ci    EXPECT_EQ("on", saProfile1.startOnDemand.onDemandEvents[0].value);
9045ba71b47Sopenharmony_ci    EXPECT_EQ(true, !saProfile1.stopOnDemand.onDemandEvents.empty());
9055ba71b47Sopenharmony_ci    EXPECT_EQ(1, saProfile1.stopOnDemand.onDemandEvents[0].eventId);
9065ba71b47Sopenharmony_ci    EXPECT_EQ("deviceonline", saProfile1.stopOnDemand.onDemandEvents[0].name);
9075ba71b47Sopenharmony_ci    EXPECT_EQ("off", saProfile1.stopOnDemand.onDemandEvents[0].value);
9085ba71b47Sopenharmony_ci    SaProfile saProfile2;
9095ba71b47Sopenharmony_ci    parser_->GetProfile(6001, saProfile2);
9105ba71b47Sopenharmony_ci    EXPECT_EQ(6001, saProfile2.saId);
9115ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile007 END" << std::endl;
9125ba71b47Sopenharmony_ci}
9135ba71b47Sopenharmony_ci
9145ba71b47Sopenharmony_ci/**
9155ba71b47Sopenharmony_ci * @tc.name: ParseJsonFile008
9165ba71b47Sopenharmony_ci * @tc.desc: parse json file using extension profile
9175ba71b47Sopenharmony_ci * @tc.type: FUNC
9185ba71b47Sopenharmony_ci */
9195ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseJsonFile008, TestSize.Level3)
9205ba71b47Sopenharmony_ci{
9215ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile008 BEGIN" << std::endl;
9225ba71b47Sopenharmony_ci    parser_->saProfiles_.clear();
9235ba71b47Sopenharmony_ci    bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "sa_profile_extension.json");
9245ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
9255ba71b47Sopenharmony_ci    EXPECT_EQ(parser_->saProfiles_.empty(), false);
9265ba71b47Sopenharmony_ci    SaProfile saProfile;
9275ba71b47Sopenharmony_ci    parser_->GetProfile(9999, saProfile);
9285ba71b47Sopenharmony_ci    EXPECT_EQ(9999, saProfile.saId);
9295ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 2);
9305ba71b47Sopenharmony_ci    auto iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), EXTENSIOON_BACKUP);
9315ba71b47Sopenharmony_ci    EXPECT_NE(iter, saProfile.extension.end());
9325ba71b47Sopenharmony_ci    iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), EXTENSIOON_RESTORE);
9335ba71b47Sopenharmony_ci    EXPECT_NE(iter, saProfile.extension.end());
9345ba71b47Sopenharmony_ci
9355ba71b47Sopenharmony_ci    DTEST_LOG << " ParseJsonFile008 END" << std::endl;
9365ba71b47Sopenharmony_ci}
9375ba71b47Sopenharmony_ci
9385ba71b47Sopenharmony_ci/**
9395ba71b47Sopenharmony_ci * @tc.name: ParseSystemAbility001
9405ba71b47Sopenharmony_ci * @tc.desc: parse sytemability tag with error param.
9415ba71b47Sopenharmony_ci * @tc.type: FUNC
9425ba71b47Sopenharmony_ci */
9435ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseSystemAbility001, TestSize.Level3)
9445ba71b47Sopenharmony_ci{
9455ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbility001 BEGIN" << std::endl;
9465ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
9475ba71b47Sopenharmony_ci    SaProfile saProfile;
9485ba71b47Sopenharmony_ci    bool ret = parser_->ParseSystemAbility(saProfile, systemAbilityJson);
9495ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
9505ba71b47Sopenharmony_ci    systemAbilityJson["name"] = -1; // invalid said
9515ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbility(saProfile, systemAbilityJson);
9525ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
9535ba71b47Sopenharmony_ci    systemAbilityJson["name"] = DISTRIBUTED_DEVICE_PROFILE_SA_ID;
9545ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbility(saProfile, systemAbilityJson);
9555ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
9565ba71b47Sopenharmony_ci    systemAbilityJson["libpath"] = "/system/lib/test.so";
9575ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbility(saProfile, systemAbilityJson);
9585ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
9595ba71b47Sopenharmony_ci    systemAbilityJson["bootphase"] = "aaa";
9605ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbility(saProfile, systemAbilityJson);
9615ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
9625ba71b47Sopenharmony_ci
9635ba71b47Sopenharmony_ci    int32_t testTime = 9999;
9645ba71b47Sopenharmony_ci    systemAbilityJson["stop-on-demand"] = {{"longtimeunused-unload", testTime}, {"unreferenced-unload", true}};
9655ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbility(saProfile, systemAbilityJson);
9665ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
9675ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.stopOnDemand.unusedTimeout, testTime);
9685ba71b47Sopenharmony_ci
9695ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.stopOnDemand.unrefUnload, true);
9705ba71b47Sopenharmony_ci
9715ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbility001 END" << std::endl;
9725ba71b47Sopenharmony_ci}
9735ba71b47Sopenharmony_ci
9745ba71b47Sopenharmony_ci/**
9755ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
9765ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is nullptr
9775ba71b47Sopenharmony_ci * @tc.type: FUNC
9785ba71b47Sopenharmony_ci * @tc.require: I6MNUA
9795ba71b47Sopenharmony_ci */
9805ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap001, TestSize.Level3)
9815ba71b47Sopenharmony_ci{
9825ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap001 BEGIN" << std::endl;
9835ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
9845ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
9855ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
9865ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap001 END" << std::endl;
9875ba71b47Sopenharmony_ci}
9885ba71b47Sopenharmony_ci/**
9895ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
9905ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_type,evnt_name and event_value
9915ba71b47Sopenharmony_ci * @tc.type: FUNC
9925ba71b47Sopenharmony_ci * @tc.require: I6MNUA
9935ba71b47Sopenharmony_ci */
9945ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap002, TestSize.Level3)
9955ba71b47Sopenharmony_ci{
9965ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap002 BEGIN" << std::endl;
9975ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
9985ba71b47Sopenharmony_ci    strMap[EVENT_TYPE] = "test";
9995ba71b47Sopenharmony_ci    strMap[EVENT_NAME] = "test";
10005ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = "test";
10015ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
10025ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
10035ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
10045ba71b47Sopenharmony_ci    }
10055ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
10065ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
10075ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap002 END" << std::endl;
10085ba71b47Sopenharmony_ci}
10095ba71b47Sopenharmony_ci/**
10105ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
10115ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is evnt_name and event_value
10125ba71b47Sopenharmony_ci * @tc.type: FUNC
10135ba71b47Sopenharmony_ci * @tc.require: I6MNUA
10145ba71b47Sopenharmony_ci */
10155ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap003, TestSize.Level3)
10165ba71b47Sopenharmony_ci{
10175ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap003 BEGIN" << std::endl;
10185ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
10195ba71b47Sopenharmony_ci    strMap[EVENT_NAME] = "test";
10205ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = "test";
10215ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
10225ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
10235ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
10245ba71b47Sopenharmony_ci    }
10255ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
10265ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
10275ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap003 END" << std::endl;
10285ba71b47Sopenharmony_ci}
10295ba71b47Sopenharmony_ci/**
10305ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
10315ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_type and event_value
10325ba71b47Sopenharmony_ci * @tc.type: FUNC
10335ba71b47Sopenharmony_ci * @tc.require: I6MNUA
10345ba71b47Sopenharmony_ci */
10355ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap004, TestSize.Level3)
10365ba71b47Sopenharmony_ci{
10375ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap004 BEGIN" << std::endl;
10385ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
10395ba71b47Sopenharmony_ci    strMap[EVENT_TYPE] = "test";
10405ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = "test";
10415ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
10425ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
10435ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
10445ba71b47Sopenharmony_ci    }
10455ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
10465ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
10475ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap004 END" << std::endl;
10485ba71b47Sopenharmony_ci}
10495ba71b47Sopenharmony_ci/**
10505ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
10515ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_type and evnt_name
10525ba71b47Sopenharmony_ci * @tc.type: FUNC
10535ba71b47Sopenharmony_ci * @tc.require: I6MNUA
10545ba71b47Sopenharmony_ci */
10555ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap005, TestSize.Level3)
10565ba71b47Sopenharmony_ci{
10575ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap005 BEGIN" << std::endl;
10585ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
10595ba71b47Sopenharmony_ci    strMap[EVENT_TYPE] = "test";
10605ba71b47Sopenharmony_ci    strMap[EVENT_NAME] = "test";
10615ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
10625ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
10635ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
10645ba71b47Sopenharmony_ci    }
10655ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
10665ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
10675ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap005 END" << std::endl;
10685ba71b47Sopenharmony_ci}
10695ba71b47Sopenharmony_ci/**
10705ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
10715ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_type
10725ba71b47Sopenharmony_ci * @tc.type: FUNC
10735ba71b47Sopenharmony_ci * @tc.require: I6MNUA
10745ba71b47Sopenharmony_ci */
10755ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap006, TestSize.Level3)
10765ba71b47Sopenharmony_ci{
10775ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap006 BEGIN" << std::endl;
10785ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
10795ba71b47Sopenharmony_ci    strMap[EVENT_TYPE] = "test";
10805ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
10815ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
10825ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
10835ba71b47Sopenharmony_ci    }
10845ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
10855ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
10865ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap006 END" << std::endl;
10875ba71b47Sopenharmony_ci}
10885ba71b47Sopenharmony_ci/**
10895ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
10905ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_name
10915ba71b47Sopenharmony_ci * @tc.type: FUNC
10925ba71b47Sopenharmony_ci * @tc.require: I6MNUA
10935ba71b47Sopenharmony_ci */
10945ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap007, TestSize.Level3)
10955ba71b47Sopenharmony_ci{
10965ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap007 BEGIN" << std::endl;
10975ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
10985ba71b47Sopenharmony_ci    strMap[EVENT_NAME] = "test";
10995ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
11005ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
11015ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
11025ba71b47Sopenharmony_ci    }
11035ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
11045ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
11055ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap007 END" << std::endl;
11065ba71b47Sopenharmony_ci}
11075ba71b47Sopenharmony_ci/**
11085ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
11095ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_value
11105ba71b47Sopenharmony_ci * @tc.type: FUNC
11115ba71b47Sopenharmony_ci * @tc.require: I6MNUA
11125ba71b47Sopenharmony_ci */
11135ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap008, TestSize.Level3)
11145ba71b47Sopenharmony_ci{
11155ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap008 BEGIN" << std::endl;
11165ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> strMap;
11175ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = "test";
11185ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
11195ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
11205ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
11215ba71b47Sopenharmony_ci    }
11225ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
11235ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
11245ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap008 END" << std::endl;
11255ba71b47Sopenharmony_ci}
11265ba71b47Sopenharmony_ci/**
11275ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
11285ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_type,evnt_name and event_value;eventJson.is_string is false
11295ba71b47Sopenharmony_ci * @tc.type: FUNC
11305ba71b47Sopenharmony_ci * @tc.require: I6MNUA
11315ba71b47Sopenharmony_ci */
11325ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap009, TestSize.Level3)
11335ba71b47Sopenharmony_ci{
11345ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap009 BEGIN" << std::endl;
11355ba71b47Sopenharmony_ci    std::unordered_map<std::string, int> strMap;
11365ba71b47Sopenharmony_ci    strMap[EVENT_TYPE] = TEST_NUM;
11375ba71b47Sopenharmony_ci    strMap[EVENT_NAME] = TEST_NUM;
11385ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = TEST_NUM;
11395ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
11405ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
11415ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
11425ba71b47Sopenharmony_ci    }
11435ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
11445ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
11455ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap009 END" << std::endl;
11465ba71b47Sopenharmony_ci}
11475ba71b47Sopenharmony_ci/**
11485ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
11495ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is evnt_name and event_value;eventJson.is_string is false
11505ba71b47Sopenharmony_ci * @tc.type: FUNC
11515ba71b47Sopenharmony_ci * @tc.require: I6MNUA
11525ba71b47Sopenharmony_ci */
11535ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap010, TestSize.Level3)
11545ba71b47Sopenharmony_ci{
11555ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap010 BEGIN" << std::endl;
11565ba71b47Sopenharmony_ci    std::unordered_map<std::string, int> strMap;
11575ba71b47Sopenharmony_ci    strMap[EVENT_NAME] = TEST_NUM;
11585ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = TEST_NUM;
11595ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
11605ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
11615ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
11625ba71b47Sopenharmony_ci    }
11635ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
11645ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
11655ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap010 END" << std::endl;
11665ba71b47Sopenharmony_ci}
11675ba71b47Sopenharmony_ci/**
11685ba71b47Sopenharmony_ci * @tc.name: JsonObjToMap
11695ba71b47Sopenharmony_ci * @tc.desc: eventJson.contains is event_value;eventJson.is_string is false
11705ba71b47Sopenharmony_ci * @tc.type: FUNC
11715ba71b47Sopenharmony_ci * @tc.require: I6MNUA
11725ba71b47Sopenharmony_ci */
11735ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, JsonObjToMap011, TestSize.Level3)
11745ba71b47Sopenharmony_ci{
11755ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap011 BEGIN" << std::endl;
11765ba71b47Sopenharmony_ci    std::unordered_map<std::string, int> strMap;
11775ba71b47Sopenharmony_ci    strMap[EVENT_VALUE] = TEST_NUM;
11785ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
11795ba71b47Sopenharmony_ci    for (auto it = strMap.begin(); it != strMap.end(); it++) {
11805ba71b47Sopenharmony_ci        systemAbilityJson[it->first] = it->second;
11815ba71b47Sopenharmony_ci    }
11825ba71b47Sopenharmony_ci    std::unordered_map<std::string, std::string> res = parser_->JsonObjToMap(systemAbilityJson);
11835ba71b47Sopenharmony_ci    EXPECT_EQ(res.size(), 3);
11845ba71b47Sopenharmony_ci    DTEST_LOG << " JsonObjToMap011 END" << std::endl;
11855ba71b47Sopenharmony_ci}
11865ba71b47Sopenharmony_ci
11875ba71b47Sopenharmony_ci/**
11885ba71b47Sopenharmony_ci * @tc.name: StringToMap001
11895ba71b47Sopenharmony_ci * @tc.desc: test StringToMap with empty string
11905ba71b47Sopenharmony_ci * @tc.type: FUNC
11915ba71b47Sopenharmony_ci * @tc.require: I6YJH6
11925ba71b47Sopenharmony_ci */
11935ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, StringtoMap001, TestSize.Level3)
11945ba71b47Sopenharmony_ci{
11955ba71b47Sopenharmony_ci    unordered_map<std::string, std::string> ret = parser_->StringToMap(EVENT_STRING);
11965ba71b47Sopenharmony_ci    EXPECT_FALSE(ret.empty());
11975ba71b47Sopenharmony_ci}
11985ba71b47Sopenharmony_ci
11995ba71b47Sopenharmony_ci/**
12005ba71b47Sopenharmony_ci * @tc.name: CloseHandle001
12015ba71b47Sopenharmony_ci * @tc.desc: test CloseHandle with nullptr
12025ba71b47Sopenharmony_ci * @tc.type: FUNC
12035ba71b47Sopenharmony_ci * @tc.require: I7G775
12045ba71b47Sopenharmony_ci */
12055ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, CloseHandle001, TestSize.Level3)
12065ba71b47Sopenharmony_ci{
12075ba71b47Sopenharmony_ci    SaProfile saProfile;
12085ba71b47Sopenharmony_ci    parser_->CloseHandle(saProfile);
12095ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.handle, nullptr);
12105ba71b47Sopenharmony_ci}
12115ba71b47Sopenharmony_ci
12125ba71b47Sopenharmony_ci/**
12135ba71b47Sopenharmony_ci * @tc.name: CheckLogicRelationship001
12145ba71b47Sopenharmony_ci * @tc.desc: test CheckLogicRelationship
12155ba71b47Sopenharmony_ci * @tc.type: FUNC
12165ba71b47Sopenharmony_ci */
12175ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, CheckLogicRelationship001, TestSize.Level3)
12185ba71b47Sopenharmony_ci{
12195ba71b47Sopenharmony_ci    bool ret;
12205ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", "");
12215ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12225ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", "1");
12235ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12245ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("", "1");
12255ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
12265ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", ">1");
12275ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
12285ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("2", ">1");
12295ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12305ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", ">=1");
12315ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12325ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", "<1");
12335ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
12345ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("0", "<1");
12355ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12365ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", "<=1");
12375ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12385ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("1", ">=abc");
12395ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
12405ba71b47Sopenharmony_ci    ret = parser_->CheckLogicRelationship("abc", ">=1");
12415ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
12425ba71b47Sopenharmony_ci}
12435ba71b47Sopenharmony_ci
12445ba71b47Sopenharmony_ci/**
12455ba71b47Sopenharmony_ci * @tc.name: ParseSystemAbilityGetExtension001
12465ba71b47Sopenharmony_ci * @tc.desc: parse sytemability extension tag
12475ba71b47Sopenharmony_ci * @tc.type: FUNC
12485ba71b47Sopenharmony_ci */
12495ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseSystemAbilityGetExtension001, TestSize.Level3)
12505ba71b47Sopenharmony_ci{
12515ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbilityGetExtension001 BEGIN" << std::endl;
12525ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
12535ba71b47Sopenharmony_ci    SaProfile saProfile;
12545ba71b47Sopenharmony_ci    bool ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
12555ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12565ba71b47Sopenharmony_ci    systemAbilityJson["extension"] = nlohmann::json::array();
12575ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(EXTENSIOON_BACKUP);
12585ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
12595ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12605ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 1);
12615ba71b47Sopenharmony_ci    auto iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), EXTENSIOON_BACKUP);
12625ba71b47Sopenharmony_ci    EXPECT_NE(iter, saProfile.extension.end());
12635ba71b47Sopenharmony_ci
12645ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(EXTENSIOON_RESTORE);
12655ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
12665ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12675ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 2);
12685ba71b47Sopenharmony_ci    iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), EXTENSIOON_RESTORE);
12695ba71b47Sopenharmony_ci    EXPECT_NE(iter, saProfile.extension.end());
12705ba71b47Sopenharmony_ci
12715ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(EXTENSIOON_BACKUP);
12725ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(EXTENSIOON_RESTORE);
12735ba71b47Sopenharmony_ci
12745ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
12755ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
12765ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 2);
12775ba71b47Sopenharmony_ci
12785ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbilityGetExtension001 END" << std::endl;
12795ba71b47Sopenharmony_ci}
12805ba71b47Sopenharmony_ci
12815ba71b47Sopenharmony_ci/**
12825ba71b47Sopenharmony_ci * @tc.name: ParseSystemAbilityGetExtension002
12835ba71b47Sopenharmony_ci * @tc.desc: parse sytemability extension string length test
12845ba71b47Sopenharmony_ci * @tc.type: FUNC
12855ba71b47Sopenharmony_ci */
12865ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseSystemAbilityGetExtension002, TestSize.Level3)
12875ba71b47Sopenharmony_ci{
12885ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbilityGetExtension002 BEGIN" << std::endl;
12895ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
12905ba71b47Sopenharmony_ci    SaProfile saProfile;
12915ba71b47Sopenharmony_ci    systemAbilityJson["extension"] = nlohmann::json::array();
12925ba71b47Sopenharmony_ci
12935ba71b47Sopenharmony_ci    char ch = 'a';
12945ba71b47Sopenharmony_ci    std::string aExceedstr(MAX_JSON_STRING_LENGTH + 1, ch);
12955ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(aExceedstr);
12965ba71b47Sopenharmony_ci    bool ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
12975ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
12985ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 0);
12995ba71b47Sopenharmony_ci
13005ba71b47Sopenharmony_ci    systemAbilityJson["extension"].clear();
13015ba71b47Sopenharmony_ci
13025ba71b47Sopenharmony_ci    ch = 'a';
13035ba71b47Sopenharmony_ci    std::string astr(MAX_JSON_STRING_LENGTH, ch);
13045ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(astr);
13055ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
13065ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
13075ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 1);
13085ba71b47Sopenharmony_ci    auto iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), astr);
13095ba71b47Sopenharmony_ci    EXPECT_NE(iter, saProfile.extension.end());
13105ba71b47Sopenharmony_ci
13115ba71b47Sopenharmony_ci    ch = 'b';
13125ba71b47Sopenharmony_ci    std::string bstr(MAX_JSON_STRING_LENGTH - 1, ch);
13135ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(bstr);
13145ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
13155ba71b47Sopenharmony_ci    EXPECT_EQ(ret, true);
13165ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), 2);
13175ba71b47Sopenharmony_ci    iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), bstr);
13185ba71b47Sopenharmony_ci    EXPECT_NE(iter, saProfile.extension.end());
13195ba71b47Sopenharmony_ci
13205ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbilityGetExtension002 END" << std::endl;
13215ba71b47Sopenharmony_ci}
13225ba71b47Sopenharmony_ci
13235ba71b47Sopenharmony_ci/**
13245ba71b47Sopenharmony_ci * @tc.name: ParseSystemAbilityGetExtension002
13255ba71b47Sopenharmony_ci * @tc.desc: parse sytemability extension string num test
13265ba71b47Sopenharmony_ci * @tc.type: FUNC
13275ba71b47Sopenharmony_ci */
13285ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, ParseSystemAbilityGetExtension003, TestSize.Level3)
13295ba71b47Sopenharmony_ci{
13305ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbilityGetExtension003 BEGIN" << std::endl;
13315ba71b47Sopenharmony_ci    nlohmann::json systemAbilityJson;
13325ba71b47Sopenharmony_ci    SaProfile saProfile;
13335ba71b47Sopenharmony_ci    systemAbilityJson["extension"] = nlohmann::json::array();
13345ba71b47Sopenharmony_ci
13355ba71b47Sopenharmony_ci    bool ret;
13365ba71b47Sopenharmony_ci    char ch = 0;
13375ba71b47Sopenharmony_ci    for (int32_t loop = 0; loop < MAX_EXTENSIONO_NUM; ++loop) {
13385ba71b47Sopenharmony_ci        std::string str(MAX_JSON_STRING_LENGTH, ch + loop);
13395ba71b47Sopenharmony_ci        systemAbilityJson["extension"].push_back(str);
13405ba71b47Sopenharmony_ci        ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
13415ba71b47Sopenharmony_ci        EXPECT_EQ(ret, true);
13425ba71b47Sopenharmony_ci        EXPECT_EQ(saProfile.extension.size(), loop + 1);
13435ba71b47Sopenharmony_ci        auto iter = std::find(saProfile.extension.begin(), saProfile.extension.end(), str);
13445ba71b47Sopenharmony_ci        EXPECT_NE(iter, saProfile.extension.end());
13455ba71b47Sopenharmony_ci    }
13465ba71b47Sopenharmony_ci
13475ba71b47Sopenharmony_ci    std::string str(MAX_JSON_STRING_LENGTH, ch + MAX_EXTENSIONO_NUM);
13485ba71b47Sopenharmony_ci    systemAbilityJson["extension"].push_back(str);
13495ba71b47Sopenharmony_ci    ret = parser_->ParseSystemAbilityGetExtension(saProfile, systemAbilityJson);
13505ba71b47Sopenharmony_ci    EXPECT_EQ(ret, false);
13515ba71b47Sopenharmony_ci    EXPECT_EQ(saProfile.extension.size(), MAX_EXTENSIONO_NUM);
13525ba71b47Sopenharmony_ci
13535ba71b47Sopenharmony_ci    DTEST_LOG << " ParseSystemAbilityGetExtension003 END" << std::endl;
13545ba71b47Sopenharmony_ci}
13555ba71b47Sopenharmony_ci
13565ba71b47Sopenharmony_ci/**
13575ba71b47Sopenharmony_ci * @tc.name: GetOndemandPriorityPara001
13585ba71b47Sopenharmony_ci * @tc.desc: GetOndemandPriorityPara
13595ba71b47Sopenharmony_ci * @tc.type: FUNC
13605ba71b47Sopenharmony_ci */
13615ba71b47Sopenharmony_ciHWTEST_F(ParseUtilTest, GetOndemandPriorityPara001, TestSize.Level3)
13625ba71b47Sopenharmony_ci{
13635ba71b47Sopenharmony_ci    DTEST_LOG << " GetOndemandPriorityPara001 BEGIN" << std::endl;
13645ba71b47Sopenharmony_ci    std::string loadPriority = "HighPriority";
13655ba71b47Sopenharmony_ci    uint32_t ret = parser_->GetOndemandPriorityPara(loadPriority);
13665ba71b47Sopenharmony_ci    EXPECT_EQ(ret, static_cast<uint32_t>(HIGH_PRIORITY));
13675ba71b47Sopenharmony_ci
13685ba71b47Sopenharmony_ci    loadPriority = "MediumPriority";
13695ba71b47Sopenharmony_ci    ret = parser_->GetOndemandPriorityPara(loadPriority);
13705ba71b47Sopenharmony_ci    EXPECT_EQ(ret, static_cast<uint32_t>(MEDIUM_PRIORITY));
13715ba71b47Sopenharmony_ci
13725ba71b47Sopenharmony_ci    loadPriority = "NEW_TEST";
13735ba71b47Sopenharmony_ci    ret = parser_->GetOndemandPriorityPara(loadPriority);
13745ba71b47Sopenharmony_ci    EXPECT_EQ(ret, static_cast<uint32_t>(LOW_PRIORITY));
13755ba71b47Sopenharmony_ci}
13765ba71b47Sopenharmony_ci
13775ba71b47Sopenharmony_ci} // namespace SAMGR
13785ba71b47Sopenharmony_ci} // namespace OHOS
1379