• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "ability_manager_service.h"
20 #undef private
21 #undef protected
22 
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace OHOS::AppExecFwk;
26 
27 namespace OHOS {
28 namespace AAFwk {
29 class AbilityManagerServiceTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp();
34     void TearDown();
35 public:
36     AbilityRequest abilityRequest_;
37     std::shared_ptr<AbilityRecord> abilityRecord_{ nullptr };
38 };
39 
SetUpTestCase()40 void AbilityManagerServiceTest::SetUpTestCase() {}
41 
TearDownTestCase()42 void AbilityManagerServiceTest::TearDownTestCase() {}
43 
SetUp()44 void AbilityManagerServiceTest::SetUp() {}
45 
TearDown()46 void AbilityManagerServiceTest::TearDown() {}
47 
48 /**
49  * @tc.name: CheckStartByCallPermission_001
50  * @tc.desc: Verify function CheckStartByCallPermission return RESOLVE_CALL_NO_PERMISSIONS
51  * @tc.type: FUNC
52  * @tc.require:
53  */
54 HWTEST_F(AbilityManagerServiceTest, CheckStartByCallPermission_001, TestSize.Level1)
55 {
56     auto abilityMs_ = std::make_shared<AbilityManagerService>();
57     abilityMs_->OnStart();
58     if (abilityRecord_ == nullptr) {
59         abilityRequest_.appInfo.bundleName = "data.client.bundle";
60         abilityRequest_.abilityInfo.name = "ClientAbility";
61         abilityRequest_.abilityInfo.type = AbilityType::DATA;
62         abilityRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
63     }
64     abilityRequest_.callerUid = 0;
65     EXPECT_EQ(RESOLVE_CALL_ABILITY_TYPE_ERR, abilityMs_->CheckStartByCallPermission(abilityRequest_));
66 }
67 
68 /**
69  * @tc.name: CheckStartByCallPermission_002
70  * @tc.desc: Verify function CheckStartByCallPermission return ERR_OK
71  * @tc.type: FUNC
72  * @tc.require:
73  */
74 HWTEST_F(AbilityManagerServiceTest, CheckStartByCallPermission_002, TestSize.Level1)
75 {
76     auto abilityMs_ = std::make_shared<AbilityManagerService>();
77     abilityMs_->OnStart();
78     if (abilityRecord_ == nullptr) {
79         abilityRequest_.appInfo.bundleName = "data.client.bundle";
80         abilityRequest_.abilityInfo.name = "ClientAbility";
81         abilityRequest_.abilityInfo.type = AbilityType::DATA;
82         abilityRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
83     }
84     abilityRequest_.callerUid = 1000;
85     abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::PAGE;
86     abilityRequest_.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON;
87     EXPECT_EQ(RESOLVE_CALL_NO_PERMISSIONS, abilityMs_->CheckStartByCallPermission(abilityRequest_));
88 }
89 }
90 }
91