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
165ba71b47Sopenharmony_ci#include "gtest/gtest.h"
175ba71b47Sopenharmony_ci#include "if_system_ability_manager.h"
185ba71b47Sopenharmony_ci#include "iservice_registry.h"
195ba71b47Sopenharmony_ci#include "itest_transaction_service.h"
205ba71b47Sopenharmony_ci#include "parameter.h"
215ba71b47Sopenharmony_ci#include "system_ability_definition.h"
225ba71b47Sopenharmony_ci#include "test_log.h"
235ba71b47Sopenharmony_ci
245ba71b47Sopenharmony_ci#define private public
255ba71b47Sopenharmony_ci#include "system_ability_manager.h"
265ba71b47Sopenharmony_ci
275ba71b47Sopenharmony_cinamespace OHOS {
285ba71b47Sopenharmony_cinamespace SAMGR {
295ba71b47Sopenharmony_cinamespace {
305ba71b47Sopenharmony_ciconstexpr int32_t LOOP_SIZE = 1000;
315ba71b47Sopenharmony_ci}
325ba71b47Sopenharmony_ci
335ba71b47Sopenharmony_ciclass SystemAbilityManagerTest : public testing::Test {
345ba71b47Sopenharmony_cipublic:
355ba71b47Sopenharmony_ci    static void SetUpTestCase();
365ba71b47Sopenharmony_ci    static void TearDownTestCase();
375ba71b47Sopenharmony_ci    void SetUp();
385ba71b47Sopenharmony_ci    void TearDown();
395ba71b47Sopenharmony_ci};
405ba71b47Sopenharmony_ci
415ba71b47Sopenharmony_civoid SystemAbilityManagerTest::SetUpTestCase()
425ba71b47Sopenharmony_ci{
435ba71b47Sopenharmony_ci    DTEST_LOG << "SystemAbilityManagerTest SetUpTestCase" << std::endl;
445ba71b47Sopenharmony_ci}
455ba71b47Sopenharmony_ci
465ba71b47Sopenharmony_civoid SystemAbilityManagerTest::TearDownTestCase()
475ba71b47Sopenharmony_ci{
485ba71b47Sopenharmony_ci    DTEST_LOG << "SystemAbilityManagerTest TearDownTestCase" << std::endl;
495ba71b47Sopenharmony_ci}
505ba71b47Sopenharmony_ci
515ba71b47Sopenharmony_civoid SystemAbilityManagerTest::SetUp()
525ba71b47Sopenharmony_ci{
535ba71b47Sopenharmony_ci    DTEST_LOG << "SystemAbilityManagerTest SetUp" << std::endl;
545ba71b47Sopenharmony_ci}
555ba71b47Sopenharmony_ci
565ba71b47Sopenharmony_civoid SystemAbilityManagerTest::TearDown()
575ba71b47Sopenharmony_ci{
585ba71b47Sopenharmony_ci    DTEST_LOG << "SystemAbilityManagerTest TearDown" << std::endl;
595ba71b47Sopenharmony_ci}
605ba71b47Sopenharmony_ci
615ba71b47Sopenharmony_ci/**
625ba71b47Sopenharmony_ci * @tc.name: param check samgr ready event
635ba71b47Sopenharmony_ci * @tc.desc: param check samgr ready event
645ba71b47Sopenharmony_ci * @tc.type: FUNC
655ba71b47Sopenharmony_ci */
665ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, SamgrReady001, TestSize.Level1)
675ba71b47Sopenharmony_ci{
685ba71b47Sopenharmony_ci    DTEST_LOG << " SamgrReady001 start " << std::endl;
695ba71b47Sopenharmony_ci    /**
705ba71b47Sopenharmony_ci     * @tc.steps: step1. param check samgr ready event
715ba71b47Sopenharmony_ci     * @tc.expected: step1. param check samgr ready event
725ba71b47Sopenharmony_ci     */
735ba71b47Sopenharmony_ci    auto ret = WaitParameter("bootevent.samgr.ready", "true", 1);
745ba71b47Sopenharmony_ci    ASSERT_EQ(ret, 0);
755ba71b47Sopenharmony_ci}
765ba71b47Sopenharmony_ci
775ba71b47Sopenharmony_ci/**
785ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest001
795ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
805ba71b47Sopenharmony_ci * @tc.type: FUNC
815ba71b47Sopenharmony_ci */
825ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest001, TestSize.Level1)
835ba71b47Sopenharmony_ci{
845ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest001 start " << std::endl;
855ba71b47Sopenharmony_ci    /**
865ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
875ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
885ba71b47Sopenharmony_ci     */
895ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
905ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
915ba71b47Sopenharmony_ci    /**
925ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with deviceid
935ba71b47Sopenharmony_ci     * @tc.expected: step2. get system ability with deviceid
945ba71b47Sopenharmony_ci     */
955ba71b47Sopenharmony_ci    std::string mockDeviceid = "12345678";
965ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, mockDeviceid);
975ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
985ba71b47Sopenharmony_ci}
995ba71b47Sopenharmony_ci
1005ba71b47Sopenharmony_ci/**
1015ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest002
1025ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
1035ba71b47Sopenharmony_ci * @tc.type: FUNC
1045ba71b47Sopenharmony_ci */
1055ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest002, TestSize.Level1)
1065ba71b47Sopenharmony_ci{
1075ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest002 start " << std::endl;
1085ba71b47Sopenharmony_ci    /**
1095ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
1105ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
1115ba71b47Sopenharmony_ci     */
1125ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1135ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
1145ba71b47Sopenharmony_ci    /**
1155ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with deviceid
1165ba71b47Sopenharmony_ci     * @tc.expected: step2. get system ability with deviceid
1175ba71b47Sopenharmony_ci     */
1185ba71b47Sopenharmony_ci    std::string mockDeviceid = "012345679000111";
1195ba71b47Sopenharmony_ci    int32_t mockSaid = 0;
1205ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(mockSaid, mockDeviceid);
1215ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
1225ba71b47Sopenharmony_ci}
1235ba71b47Sopenharmony_ci
1245ba71b47Sopenharmony_ci/**
1255ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest003
1265ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
1275ba71b47Sopenharmony_ci * @tc.type: FUNC
1285ba71b47Sopenharmony_ci */
1295ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest003, TestSize.Level1)
1305ba71b47Sopenharmony_ci{
1315ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest003 start " << std::endl;
1325ba71b47Sopenharmony_ci    /**
1335ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
1345ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
1355ba71b47Sopenharmony_ci     */
1365ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1375ba71b47Sopenharmony_ci    /**
1385ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with deviceid
1395ba71b47Sopenharmony_ci     * @tc.expected: step2. get system ability with deviceid
1405ba71b47Sopenharmony_ci     */
1415ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
1425ba71b47Sopenharmony_ci    int32_t mockSaid = -1;
1435ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(mockSaid, "");
1445ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
1455ba71b47Sopenharmony_ci}
1465ba71b47Sopenharmony_ci
1475ba71b47Sopenharmony_ci/**
1485ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest004
1495ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
1505ba71b47Sopenharmony_ci * @tc.type: FUNC
1515ba71b47Sopenharmony_ci */
1525ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest004, TestSize.Level3)
1535ba71b47Sopenharmony_ci{
1545ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest004 start " << std::endl;
1555ba71b47Sopenharmony_ci    /**
1565ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
1575ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
1585ba71b47Sopenharmony_ci     */
1595ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1605ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
1615ba71b47Sopenharmony_ci    /**
1625ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with deviceid
1635ba71b47Sopenharmony_ci     * @tc.expected: step2. get system ability with deviceid
1645ba71b47Sopenharmony_ci     */
1655ba71b47Sopenharmony_ci    for (int32_t i = 0; i < LOOP_SIZE; ++i) {
1665ba71b47Sopenharmony_ci        sptr<IRemoteObject> ability = sm->CheckSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, "");
1675ba71b47Sopenharmony_ci        ASSERT_TRUE(ability == nullptr);
1685ba71b47Sopenharmony_ci    }
1695ba71b47Sopenharmony_ci}
1705ba71b47Sopenharmony_ci
1715ba71b47Sopenharmony_ci/**
1725ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest005
1735ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
1745ba71b47Sopenharmony_ci * @tc.type: FUNC
1755ba71b47Sopenharmony_ci */
1765ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest005, TestSize.Level1)
1775ba71b47Sopenharmony_ci{
1785ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest005 start " << std::endl;
1795ba71b47Sopenharmony_ci    /**
1805ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
1815ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
1825ba71b47Sopenharmony_ci     */
1835ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1845ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
1855ba71b47Sopenharmony_ci    /**
1865ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with mock said
1875ba71b47Sopenharmony_ci     * @tc.expected: step2. not get sa
1885ba71b47Sopenharmony_ci     */
1895ba71b47Sopenharmony_ci    int32_t mockSaid = -1;
1905ba71b47Sopenharmony_ci    bool isExist = true;
1915ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(mockSaid, isExist);
1925ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
1935ba71b47Sopenharmony_ci}
1945ba71b47Sopenharmony_ci
1955ba71b47Sopenharmony_ci/**
1965ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest006
1975ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
1985ba71b47Sopenharmony_ci * @tc.type: FUNC
1995ba71b47Sopenharmony_ci */
2005ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest006, TestSize.Level1)
2015ba71b47Sopenharmony_ci{
2025ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest006 start " << std::endl;
2035ba71b47Sopenharmony_ci    /**
2045ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
2055ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
2065ba71b47Sopenharmony_ci     */
2075ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
2085ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
2095ba71b47Sopenharmony_ci    /**
2105ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with mock said
2115ba71b47Sopenharmony_ci     * @tc.expected: step2. not get sa
2125ba71b47Sopenharmony_ci     */
2135ba71b47Sopenharmony_ci    int32_t mockSaid = -1;
2145ba71b47Sopenharmony_ci    bool isExist = false;
2155ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(mockSaid, isExist);
2165ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
2175ba71b47Sopenharmony_ci}
2185ba71b47Sopenharmony_ci
2195ba71b47Sopenharmony_ci/**
2205ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest007
2215ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
2225ba71b47Sopenharmony_ci * @tc.type: FUNC
2235ba71b47Sopenharmony_ci */
2245ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest007, TestSize.Level1)
2255ba71b47Sopenharmony_ci{
2265ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest007 start " << std::endl;
2275ba71b47Sopenharmony_ci    /**
2285ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
2295ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
2305ba71b47Sopenharmony_ci     */
2315ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
2325ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
2335ba71b47Sopenharmony_ci    /**
2345ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with mock said
2355ba71b47Sopenharmony_ci     * @tc.expected: step2. not get sa
2365ba71b47Sopenharmony_ci     */
2375ba71b47Sopenharmony_ci    bool isExist = false;
2385ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, isExist);
2395ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
2405ba71b47Sopenharmony_ci}
2415ba71b47Sopenharmony_ci
2425ba71b47Sopenharmony_ci/**
2435ba71b47Sopenharmony_ci * @tc.name: CheckSystemAbilityTest008
2445ba71b47Sopenharmony_ci * @tc.desc: check system ability with deviceid
2455ba71b47Sopenharmony_ci * @tc.type: FUNC
2465ba71b47Sopenharmony_ci */
2475ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, CheckSystemAbilityTest008, TestSize.Level1)
2485ba71b47Sopenharmony_ci{
2495ba71b47Sopenharmony_ci    DTEST_LOG << " CheckSystemAbilityTest008 start " << std::endl;
2505ba71b47Sopenharmony_ci    /**
2515ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
2525ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
2535ba71b47Sopenharmony_ci     */
2545ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
2555ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
2565ba71b47Sopenharmony_ci    /**
2575ba71b47Sopenharmony_ci     * @tc.steps: step2. get system ability with mock said
2585ba71b47Sopenharmony_ci     * @tc.expected: step2. not get sa
2595ba71b47Sopenharmony_ci     */
2605ba71b47Sopenharmony_ci    bool isExist = true;
2615ba71b47Sopenharmony_ci    sptr<IRemoteObject> ability = sm->CheckSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, isExist);
2625ba71b47Sopenharmony_ci    ASSERT_TRUE(ability == nullptr);
2635ba71b47Sopenharmony_ci}
2645ba71b47Sopenharmony_ci
2655ba71b47Sopenharmony_ci/**
2665ba71b47Sopenharmony_ci * @tc.name: AddSystemProcess001
2675ba71b47Sopenharmony_ci * @tc.desc: check add process remoteobject
2685ba71b47Sopenharmony_ci */
2695ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, AddSystemProcess001, TestSize.Level1)
2705ba71b47Sopenharmony_ci{
2715ba71b47Sopenharmony_ci    DTEST_LOG << " AddSystemProcess001 start " << std::endl;
2725ba71b47Sopenharmony_ci    /**
2735ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
2745ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
2755ba71b47Sopenharmony_ci     */
2765ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
2775ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
2785ba71b47Sopenharmony_ci    /**
2795ba71b47Sopenharmony_ci     * @tc.steps: step2. add system process remote obejct
2805ba71b47Sopenharmony_ci     * @tc.expected: step2. add system process remote obejct
2815ba71b47Sopenharmony_ci     */
2825ba71b47Sopenharmony_ci    int32_t ret = sm->AddSystemProcess("", nullptr);
2835ba71b47Sopenharmony_ci    ASSERT_TRUE(ret != ERR_OK);
2845ba71b47Sopenharmony_ci}
2855ba71b47Sopenharmony_ci
2865ba71b47Sopenharmony_ci/**
2875ba71b47Sopenharmony_ci * @tc.name: AddSystemProcess002
2885ba71b47Sopenharmony_ci * @tc.desc: check add process remoteobject
2895ba71b47Sopenharmony_ci * @tc.type: FUNC
2905ba71b47Sopenharmony_ci */
2915ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, AddSystemProcess002, TestSize.Level1)
2925ba71b47Sopenharmony_ci{
2935ba71b47Sopenharmony_ci    DTEST_LOG << " AddSystemProcess002 start " << std::endl;
2945ba71b47Sopenharmony_ci    /**
2955ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
2965ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
2975ba71b47Sopenharmony_ci     */
2985ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
2995ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
3005ba71b47Sopenharmony_ci    /**
3015ba71b47Sopenharmony_ci     * @tc.steps: step2. add system process remote obejct
3025ba71b47Sopenharmony_ci     * @tc.expected: step2. add system process remote obejct
3035ba71b47Sopenharmony_ci     */
3045ba71b47Sopenharmony_ci    int32_t ret = sm->AddSystemProcess("test_process", nullptr);
3055ba71b47Sopenharmony_ci    ASSERT_TRUE(ret != ERR_OK);
3065ba71b47Sopenharmony_ci}
3075ba71b47Sopenharmony_ci
3085ba71b47Sopenharmony_ci/**
3095ba71b47Sopenharmony_ci * @tc.name: AddSystemProcess003
3105ba71b47Sopenharmony_ci * @tc.desc: check add process remoteobject
3115ba71b47Sopenharmony_ci * @tc.type: FUNC
3125ba71b47Sopenharmony_ci */
3135ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, AddSystemProcess003, TestSize.Level1)
3145ba71b47Sopenharmony_ci{
3155ba71b47Sopenharmony_ci    DTEST_LOG << " AddSystemProcess003 start " << std::endl;
3165ba71b47Sopenharmony_ci    /**
3175ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
3185ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
3195ba71b47Sopenharmony_ci     */
3205ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
3215ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
3225ba71b47Sopenharmony_ci    /**
3235ba71b47Sopenharmony_ci     * @tc.steps: step2. add system process remote obejct
3245ba71b47Sopenharmony_ci     * @tc.expected: step2. add system process remote obejct
3255ba71b47Sopenharmony_ci     */
3265ba71b47Sopenharmony_ci    int32_t ret = sm->AddSystemProcess("test_process", nullptr);
3275ba71b47Sopenharmony_ci    ASSERT_TRUE(ret != ERR_OK);
3285ba71b47Sopenharmony_ci}
3295ba71b47Sopenharmony_ci
3305ba71b47Sopenharmony_ci/**
3315ba71b47Sopenharmony_ci * @tc.name: AddSystemProcess004
3325ba71b47Sopenharmony_ci * @tc.desc: check add system process remoteobject
3335ba71b47Sopenharmony_ci * @tc.type: FUNC
3345ba71b47Sopenharmony_ci */
3355ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, AddSystemProcess004, TestSize.Level1)
3365ba71b47Sopenharmony_ci{
3375ba71b47Sopenharmony_ci    DTEST_LOG << " AddSystemProcess004 start " << std::endl;
3385ba71b47Sopenharmony_ci    /**
3395ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
3405ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
3415ba71b47Sopenharmony_ci     */
3425ba71b47Sopenharmony_ci    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
3435ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
3445ba71b47Sopenharmony_ci    /**
3455ba71b47Sopenharmony_ci     * @tc.steps: step2. add system process remote obejct
3465ba71b47Sopenharmony_ci     * @tc.expected: step2. add system process remote obejct
3475ba71b47Sopenharmony_ci     */
3485ba71b47Sopenharmony_ci    for (int32_t i = 0; i < LOOP_SIZE; ++i) {
3495ba71b47Sopenharmony_ci        sptr<IRemoteObject> ability = sm->AddSystemProcess("", nullptr);
3505ba71b47Sopenharmony_ci        ASSERT_TRUE(ret != ERR_OK);
3515ba71b47Sopenharmony_ci    }
3525ba71b47Sopenharmony_ci}
3535ba71b47Sopenharmony_ci
3545ba71b47Sopenharmony_ci/**
3555ba71b47Sopenharmony_ci * @tc.name: RemoveSystemProcess001
3565ba71b47Sopenharmony_ci * @tc.desc: check remove system process remoteobject
3575ba71b47Sopenharmony_ci * @tc.type: FUNC
3585ba71b47Sopenharmony_ci */
3595ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, RemoveSystemProcess001, TestSize.Level1)
3605ba71b47Sopenharmony_ci{
3615ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSystemProcess001 start " << std::endl;
3625ba71b47Sopenharmony_ci    /**
3635ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
3645ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
3655ba71b47Sopenharmony_ci     */
3665ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
3675ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
3685ba71b47Sopenharmony_ci    /**
3695ba71b47Sopenharmony_ci     * @tc.steps: step2. remove system process remote obejct
3705ba71b47Sopenharmony_ci     * @tc.expected: step2. remove system process remote obejct
3715ba71b47Sopenharmony_ci     */
3725ba71b47Sopenharmony_ci    int32_t ret = saMgr->RemoveSystemProcess(nullptr);
3735ba71b47Sopenharmony_ci    ASSERT_TRUE(ret != ERR_OK);
3745ba71b47Sopenharmony_ci}
3755ba71b47Sopenharmony_ci
3765ba71b47Sopenharmony_ci/**
3775ba71b47Sopenharmony_ci * @tc.name: RemoveSystemProcess002
3785ba71b47Sopenharmony_ci * @tc.desc: check remove system process remoteobject
3795ba71b47Sopenharmony_ci * @tc.type: FUNC
3805ba71b47Sopenharmony_ci */
3815ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, RemoveSystemProcess002, TestSize.Level1)
3825ba71b47Sopenharmony_ci{
3835ba71b47Sopenharmony_ci    DTEST_LOG << " RemoveSystemProcess001 star2 " << std::endl;
3845ba71b47Sopenharmony_ci    /**
3855ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
3865ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
3875ba71b47Sopenharmony_ci     */
3885ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
3895ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
3905ba71b47Sopenharmony_ci    /**
3915ba71b47Sopenharmony_ci     * @tc.steps: step2. remove system process remote obejct
3925ba71b47Sopenharmony_ci     * @tc.expected: step2. remove system process remote obejct
3935ba71b47Sopenharmony_ci     */
3945ba71b47Sopenharmony_ci    for (int32_t i = 0; i < LOOP_SIZE; ++i) {
3955ba71b47Sopenharmony_ci        int32_t ret = saMgr->RemoveSystemProcess(nullptr);
3965ba71b47Sopenharmony_ci        ASSERT_TRUE(ret != ERR_OK);
3975ba71b47Sopenharmony_ci    }
3985ba71b47Sopenharmony_ci}
3995ba71b47Sopenharmony_ci
4005ba71b47Sopenharmony_ci/**
4015ba71b47Sopenharmony_ci * @tc.name: GetSystemAbilityFromRemote001
4025ba71b47Sopenharmony_ci * @tc.desc: check get system ability from remote function
4035ba71b47Sopenharmony_ci * @tc.type: FUNC
4045ba71b47Sopenharmony_ci */
4055ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, GetSystemAbilityFromRemote001, TestSize.Level1)
4065ba71b47Sopenharmony_ci{
4075ba71b47Sopenharmony_ci    DTEST_LOG << " GetSystemAbilityFromRemote001 start " << std::endl;
4085ba71b47Sopenharmony_ci    /**
4095ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
4105ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
4115ba71b47Sopenharmony_ci     */
4125ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
4135ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
4145ba71b47Sopenharmony_ci    /**
4155ba71b47Sopenharmony_ci     * @tc.steps: step2. GetSystemAbilityFromRemote with invalid said
4165ba71b47Sopenharmony_ci     * @tc.expected: step2. not found sa
4175ba71b47Sopenharmony_ci     */
4185ba71b47Sopenharmony_ci    sptr<IRemoteObject> object = saMgr->GetSystemAbilityFromRemote(-1);
4195ba71b47Sopenharmony_ci    ASSERT_TRUE(object == nullptr);
4205ba71b47Sopenharmony_ci}
4215ba71b47Sopenharmony_ci
4225ba71b47Sopenharmony_ci/**
4235ba71b47Sopenharmony_ci * @tc.name: GetSystemAbilityFromRemote002
4245ba71b47Sopenharmony_ci * @tc.desc: check get system ability from remote function
4255ba71b47Sopenharmony_ci * @tc.type: FUNC
4265ba71b47Sopenharmony_ci */
4275ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, GetSystemAbilityFromRemote002, TestSize.Level1)
4285ba71b47Sopenharmony_ci{
4295ba71b47Sopenharmony_ci    DTEST_LOG << " GetSystemAbilityFromRemote002 start " << std::endl;
4305ba71b47Sopenharmony_ci    /**
4315ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
4325ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
4335ba71b47Sopenharmony_ci     */
4345ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
4355ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
4365ba71b47Sopenharmony_ci    /**
4375ba71b47Sopenharmony_ci     * @tc.steps: step2. GetSystemAbilityFromRemote with invalid said
4385ba71b47Sopenharmony_ci     * @tc.expected: step2. not found sa
4395ba71b47Sopenharmony_ci     */
4405ba71b47Sopenharmony_ci    sptr<IRemoteObject> object = saMgr->GetSystemAbilityFromRemote(0);
4415ba71b47Sopenharmony_ci    ASSERT_TRUE(object == nullptr);
4425ba71b47Sopenharmony_ci}
4435ba71b47Sopenharmony_ci
4445ba71b47Sopenharmony_ci/**
4455ba71b47Sopenharmony_ci * @tc.name: GetSystemAbilityFromRemote003
4465ba71b47Sopenharmony_ci * @tc.desc: check get system ability from remote function
4475ba71b47Sopenharmony_ci * @tc.type: FUNC
4485ba71b47Sopenharmony_ci */
4495ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, GetSystemAbilityFromRemote003, TestSize.Level1)
4505ba71b47Sopenharmony_ci{
4515ba71b47Sopenharmony_ci    DTEST_LOG << " GetSystemAbilityFromRemote003 start " << std::endl;
4525ba71b47Sopenharmony_ci    /**
4535ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
4545ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
4555ba71b47Sopenharmony_ci     */
4565ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
4575ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
4585ba71b47Sopenharmony_ci    /**
4595ba71b47Sopenharmony_ci     * @tc.steps: step2. GetSystemAbilityFromRemote with not-exist said
4605ba71b47Sopenharmony_ci     * @tc.expected: step2. not found sa
4615ba71b47Sopenharmony_ci     */
4625ba71b47Sopenharmony_ci    sptr<IRemoteObject> object = saMgr->GetSystemAbilityFromRemote(DISTRIBUTED_SCHED_TEST_TT_ID);
4635ba71b47Sopenharmony_ci    ASSERT_TRUE(object == nullptr);
4645ba71b47Sopenharmony_ci}
4655ba71b47Sopenharmony_ci
4665ba71b47Sopenharmony_ci/**
4675ba71b47Sopenharmony_ci * @tc.name: GetSystemAbilityFromRemote004
4685ba71b47Sopenharmony_ci * @tc.desc: check get system ability from remote function
4695ba71b47Sopenharmony_ci * @tc.type: FUNC
4705ba71b47Sopenharmony_ci */
4715ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, GetSystemAbilityFromRemote004, TestSize.Level1)
4725ba71b47Sopenharmony_ci{
4735ba71b47Sopenharmony_ci    DTEST_LOG << " GetSystemAbilityFromRemote004 start " << std::endl;
4745ba71b47Sopenharmony_ci    /**
4755ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
4765ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
4775ba71b47Sopenharmony_ci     */
4785ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
4795ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
4805ba71b47Sopenharmony_ci    /**
4815ba71b47Sopenharmony_ci     * @tc.steps: step2. mock add system ability with not distributed
4825ba71b47Sopenharmony_ci     * @tc.expected: step2. add successfully
4835ba71b47Sopenharmony_ci     */
4845ba71b47Sopenharmony_ci    ISystemAbilityManager::SAExtraProp saExtraProp(false, ISystemAbilityManager::DUMP_FLAG_PRIORITY_DEFAULT,
4855ba71b47Sopenharmony_ci        u"", u"");
4865ba71b47Sopenharmony_ci    int32_t ret = sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, new TestTransactionService(), saExtraProp);
4875ba71b47Sopenharmony_ci    ASSERT_TRUE(ret == ERR_OK);
4885ba71b47Sopenharmony_ci    /**
4895ba71b47Sopenharmony_ci     * @tc.steps: step3.  GetSystemAbilityFromRemote with mock said
4905ba71b47Sopenharmony_ci     * @tc.expected: step3. not found sa
4915ba71b47Sopenharmony_ci     */
4925ba71b47Sopenharmony_ci    sptr<IRemoteObject> object = saMgr->GetSystemAbilityFromRemote(DISTRIBUTED_SCHED_TEST_TT_ID);
4935ba71b47Sopenharmony_ci    ASSERT_TRUE(object == nullptr);
4945ba71b47Sopenharmony_ci    /**
4955ba71b47Sopenharmony_ci     * @tc.steps: step4. Remove mock sa
4965ba71b47Sopenharmony_ci     * @tc.expected: step4. Remove mock sa
4975ba71b47Sopenharmony_ci     */
4985ba71b47Sopenharmony_ci    saMgr->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID);
4995ba71b47Sopenharmony_ci}
5005ba71b47Sopenharmony_ci
5015ba71b47Sopenharmony_ci/**
5025ba71b47Sopenharmony_ci * @tc.name: GetSystemAbilityFromRemote005
5035ba71b47Sopenharmony_ci * @tc.desc: check get system ability from remote function
5045ba71b47Sopenharmony_ci * @tc.type: FUNC
5055ba71b47Sopenharmony_ci */
5065ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, GetSystemAbilityFromRemote005, TestSize.Level1)
5075ba71b47Sopenharmony_ci{
5085ba71b47Sopenharmony_ci    DTEST_LOG << " GetSystemAbilityFromRemote005 start " << std::endl;
5095ba71b47Sopenharmony_ci    /**
5105ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
5115ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
5125ba71b47Sopenharmony_ci     */
5135ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
5145ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
5155ba71b47Sopenharmony_ci    /**
5165ba71b47Sopenharmony_ci     * @tc.steps: step2. mock add system ability with not distributed
5175ba71b47Sopenharmony_ci     * @tc.expected: step2. add successfully
5185ba71b47Sopenharmony_ci     */
5195ba71b47Sopenharmony_ci    ISystemAbilityManager::SAExtraProp saExtraProp(true, ISystemAbilityManager::DUMP_FLAG_PRIORITY_DEFAULT,
5205ba71b47Sopenharmony_ci        u"", u"");
5215ba71b47Sopenharmony_ci    int32_t ret = sm->AddSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, new TestTransactionService(), saExtraProp);
5225ba71b47Sopenharmony_ci    ASSERT_TRUE(ret == ERR_OK);
5235ba71b47Sopenharmony_ci    /**
5245ba71b47Sopenharmony_ci     * @tc.steps: step3.  GetSystemAbilityFromRemote with mock said
5255ba71b47Sopenharmony_ci     * @tc.expected: step3. not found sa
5265ba71b47Sopenharmony_ci     */
5275ba71b47Sopenharmony_ci    sptr<IRemoteObject> object = saMgr->GetSystemAbilityFromRemote(DISTRIBUTED_SCHED_TEST_TT_ID);
5285ba71b47Sopenharmony_ci    ASSERT_TRUE(object != nullptr);
5295ba71b47Sopenharmony_ci    /**
5305ba71b47Sopenharmony_ci     * @tc.steps: step4. Remove mock sa
5315ba71b47Sopenharmony_ci     * @tc.expected: step4. Remove mock sa
5325ba71b47Sopenharmony_ci     */
5335ba71b47Sopenharmony_ci    saMgr->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID);
5345ba71b47Sopenharmony_ci}
5355ba71b47Sopenharmony_ci
5365ba71b47Sopenharmony_ci/**
5375ba71b47Sopenharmony_ci * @tc.name: GetSystemAbilityFromRemote006
5385ba71b47Sopenharmony_ci * @tc.desc: check get system ability from remote function
5395ba71b47Sopenharmony_ci * @tc.type: FUNC
5405ba71b47Sopenharmony_ci */
5415ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, GetSystemAbilityFromRemote006, TestSize.Level3)
5425ba71b47Sopenharmony_ci{
5435ba71b47Sopenharmony_ci    DTEST_LOG << " GetSystemAbilityFromRemote006 start " << std::endl;
5445ba71b47Sopenharmony_ci    /**
5455ba71b47Sopenharmony_ci     * @tc.steps: step1. get samgr instance
5465ba71b47Sopenharmony_ci     * @tc.expected: step1. samgr instance not nullptr
5475ba71b47Sopenharmony_ci     */
5485ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
5495ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
5505ba71b47Sopenharmony_ci    /**
5515ba71b47Sopenharmony_ci     * @tc.steps: step2. GetSystemAbilityFromRemote with invalid said
5525ba71b47Sopenharmony_ci     * @tc.expected: step2. not found sa
5535ba71b47Sopenharmony_ci     */
5545ba71b47Sopenharmony_ci    for (int32_t i = 0; i < LOOP_SIZE; ++i) {
5555ba71b47Sopenharmony_ci        int32_t ret = saMgr->GetSystemAbilityFromRemote(0);
5565ba71b47Sopenharmony_ci        ASSERT_TRUE(object == nullptr);
5575ba71b47Sopenharmony_ci    }
5585ba71b47Sopenharmony_ci}
5595ba71b47Sopenharmony_ci
5605ba71b47Sopenharmony_ci/**
5615ba71b47Sopenharmony_ci * @tc.name: ProcessOnDemandEvent001
5625ba71b47Sopenharmony_ci * @tc.desc: test ProcessOnDemandEvent with empty saControlList
5635ba71b47Sopenharmony_ci * @tc.type: FUNC
5645ba71b47Sopenharmony_ci */
5655ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, ProcessOnDemandEvent001, TestSize.Level3)
5665ba71b47Sopenharmony_ci{
5675ba71b47Sopenharmony_ci    DTEST_LOG << " ProcessOnDemandEvent001 start " << std::endl;
5685ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
5695ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
5705ba71b47Sopenharmony_ci    std::list<SaControlInfo> saControlList;
5715ba71b47Sopenharmony_ci    OnDemandEvent event;
5725ba71b47Sopenharmony_ci    saMgr->ProcessOnDemandEvent(event, saControlList);
5735ba71b47Sopenharmony_ci    DTEST_LOG << " ProcessOnDemandEvent001 end " << std::endl;
5745ba71b47Sopenharmony_ci}
5755ba71b47Sopenharmony_ci
5765ba71b47Sopenharmony_ci/**
5775ba71b47Sopenharmony_ci * @tc.name: ProcessOnDemandEvent002
5785ba71b47Sopenharmony_ci * @tc.desc: test ProcessOnDemandEvent with  saControlList
5795ba71b47Sopenharmony_ci * @tc.type: FUNC
5805ba71b47Sopenharmony_ci */
5815ba71b47Sopenharmony_ciHWTEST_F(SystemAbilityManagerTest, ProcessOnDemandEvent002, TestSize.Level3)
5825ba71b47Sopenharmony_ci{
5835ba71b47Sopenharmony_ci    DTEST_LOG << " ProcessOnDemandEvent002 start " << std::endl;
5845ba71b47Sopenharmony_ci    sptr<SystemAbilityManager> saMgr = SystemAbilityManager::GetInstance();
5855ba71b47Sopenharmony_ci    ASSERT_TRUE(sm != nullptr);
5865ba71b47Sopenharmony_ci    std::list<SaControlInfo> saControlList;
5875ba71b47Sopenharmony_ci    OnDemandEvent event;
5885ba71b47Sopenharmony_ci    SaControlInfo saControlInfo1 = {START_ON_DEMAND, DISTRIBUTED_SCHED_SA_ID};
5895ba71b47Sopenharmony_ci    SaControlInfo saControlInfo2 = {START_ON_DEMAND, DISTRIBUTED_SCHED_ADAPTER_SA_ID};
5905ba71b47Sopenharmony_ci    SaControlInfo saControlInfo3 = {STOP_ON_DEMAND, DISTRIBUTED_SCHED_ADAPTER_SA_ID};
5915ba71b47Sopenharmony_ci    SaControlInfo saControlInfo4 = {STOP_ON_DEMAND + 1, DISTRIBUTED_SCHED_ADAPTER_SA_ID};
5925ba71b47Sopenharmony_ci    SaProfile saInfo1 = {u"distributedsched", DISTRIBUTED_SCHED_SA_ID};
5935ba71b47Sopenharmony_ci    SaProfile saInfo2 = {u"distributedadapter", DISTRIBUTED_SCHED_ADAPTER_SA_ID};
5945ba71b47Sopenharmony_ci    saMgr->saProfileMap_[DISTRIBUTED_SCHED_SA_ID] = saInfo1;
5955ba71b47Sopenharmony_ci    saMgr->saProfileMap_[DISTRIBUTED_SCHED_ADAPTER_SA_ID] = saInfo2;
5965ba71b47Sopenharmony_ci    saControlList.emplace_back(saControlInfo1);
5975ba71b47Sopenharmony_ci    saControlList.emplace_back(saControlInfo2);
5985ba71b47Sopenharmony_ci    saControlList.emplace_back(saControlInfo3);
5995ba71b47Sopenharmony_ci    saControlList.emplace_back(saControlInfo4);
6005ba71b47Sopenharmony_ci    saMgr->ProcessOnDemandEvent(event, saControlList);
6015ba71b47Sopenharmony_ci    DTEST_LOG << " ProcessOnDemandEvent002 end " << std::endl;
6025ba71b47Sopenharmony_ci}
6035ba71b47Sopenharmony_ci}
6045ba71b47Sopenharmony_ci}