1 /*
2 * Copyright (c) 2024 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 #include "service_router_mgr_service.h"
19 #undef private
20
21 #include "hilog_tag_wrapper.h"
22 #include "hilog_wrapper.h"
23 #include "ability_manager_errors.h"
24 #include "accesstoken_kit.h"
25 #include "tokenid_kit.h"
26
27 using namespace testing;
28 using namespace testing::ext;
29 using OHOS::DelayedSingleton;
30
31 namespace OHOS {
32 namespace AbilityRuntime {
33 namespace {
34 const int RESULT_CODE = 8521225;
35 }
36 class ServiceRouterMgrServiceTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp() override;
41 void TearDown() override;
42 public:
43 static std::shared_ptr<ServiceRouterMgrService> serviceRouterMgrService_;
44 };
SetUpTestCase(void)45 void ServiceRouterMgrServiceTest::SetUpTestCase(void)
46 {}
47
TearDownTestCase(void)48 void ServiceRouterMgrServiceTest::TearDownTestCase(void)
49 {
50 serviceRouterMgrService_->OnStop();
51 }
52
SetUp()53 void ServiceRouterMgrServiceTest::SetUp()
54 {
55 serviceRouterMgrService_->OnStart();
56 }
57
TearDown()58 void ServiceRouterMgrServiceTest::TearDown()
59 {}
60
61 std::shared_ptr<ServiceRouterMgrService> ServiceRouterMgrServiceTest::serviceRouterMgrService_ =
62 DelayedSingleton<ServiceRouterMgrService>::GetInstance();
63
64 /**
65 * @tc.name: test StartUIExtensionAbility_001
66 * @tc.desc: StartUIExtensionAbility
67 */
68 HWTEST_F(ServiceRouterMgrServiceTest, StartUIExtensionAbility_001, Function | SmallTest | Level0)
69 {
70 TAG_LOGI(AAFwkTag::TEST, "StartUIExtensionAbility_001 start");
71 SessionInfo sessionInfo;
72 int32_t userId = 1;
73 int32_t funcResult = -1;
74 serviceRouterMgrService_->StartUIExtensionAbility(sessionInfo, userId, funcResult);
75 EXPECT_EQ(funcResult, AAFwk::CHECK_PERMISSION_FAILED);
76 TAG_LOGI(AAFwkTag::TEST, "StartUIExtensionAbility_001 result %{public}d", funcResult);
77 TAG_LOGI(AAFwkTag::TEST, "StartUIExtensionAbility_001 end");
78 }
79
80 /**
81 * @tc.name: test ConnectUIExtensionAbility_001
82 * @tc.desc: ConnectUIExtensionAbility
83 */
84 HWTEST_F(ServiceRouterMgrServiceTest, ConnectUIExtensionAbility_001, Function | SmallTest | Level0)
85 {
86 TAG_LOGI(AAFwkTag::TEST, "ConnectUIExtensionAbility_001 start");
87 Want want;
88 sptr<IAbilityConnection> connect = nullptr;
89 SessionInfo sessionInfo;
90 int32_t userId = 1;
91 int32_t funcResult = -1;
92 serviceRouterMgrService_->ConnectUIExtensionAbility(want, connect, sessionInfo, userId, funcResult);
93 EXPECT_EQ(funcResult, ERR_INVALID_VALUE);
94 TAG_LOGI(AAFwkTag::TEST, "ConnectUIExtensionAbility_001 result %{public}d", funcResult);
95 TAG_LOGI(AAFwkTag::TEST, "ConnectUIExtensionAbility_001 end");
96 }
97
98 /**
99 * @tc.name: test QueryPurposeInfos_001
100 * @tc.desc: QueryPurposeInfos
101 */
102 HWTEST_F(ServiceRouterMgrServiceTest, QueryPurposeInfos_001, Function | SmallTest | Level0)
103 {
104 TAG_LOGI(AAFwkTag::TEST, "QueryPurposeInfos_001 start");
105 Want want;
106 int32_t funcResult = -1;
107 std::vector<PurposeInfo> purposeInfos;
108 serviceRouterMgrService_->QueryPurposeInfos(want, "", purposeInfos, funcResult);
109 EXPECT_EQ(funcResult, RESULT_CODE);
110 TAG_LOGI(AAFwkTag::TEST, "QueryPurposeInfos_001 result %{public}d", funcResult);
111 TAG_LOGI(AAFwkTag::TEST, "QueryPurposeInfos_001 end");
112 }
113
114 /**
115 * @tc.name: test QueryBusinessAbilityInfosInner_001
116 * @tc.desc: QueryBusinessAbilityInfosInner
117 */
118 HWTEST_F(ServiceRouterMgrServiceTest, QueryBusinessAbilityInfos_001, Function | SmallTest | Level0)
119 {
120 TAG_LOGI(AAFwkTag::TEST, "QueryBusinessAbilityInfos_001 start");
121 BusinessAbilityFilter filter;
122 int32_t funcResult = -1;
123 filter.businessType = BusinessType::UNSPECIFIED;
124 std::vector<BusinessAbilityInfo> abilityInfos;
125 serviceRouterMgrService_->QueryBusinessAbilityInfosInner(filter, abilityInfos, funcResult);
126 EXPECT_EQ(funcResult, RESULT_CODE);
127 TAG_LOGI(AAFwkTag::TEST, "QueryBusinessAbilityInfos_001 result %{public}d", funcResult);
128 TAG_LOGI(AAFwkTag::TEST, "QueryBusinessAbilityInfos_001 end");
129 }
130
131 /**
132 * @tc.name: test VerifySystemApp_001
133 * @tc.desc: VerifySystemApp
134 */
135 HWTEST_F(ServiceRouterMgrServiceTest, VerifySystemApp_001, Function | SmallTest | Level0)
136 {
137 TAG_LOGI(AAFwkTag::TEST, "VerifySystemApp_001 start");
138 uint32_t callerToken = 3;
139 auto tokenType = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken);
140 tokenType = OHOS::Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE;
141 auto ret = serviceRouterMgrService_->VerifySystemApp();
142 EXPECT_TRUE(ret);
143 TAG_LOGI(AAFwkTag::TEST, "VerifySystemApp_001 end");
144 }
145
146 /**
147 * @tc.name: test VerifyCallingPermission_001
148 * @tc.desc: VerifyCallingPermission
149 */
150 HWTEST_F(ServiceRouterMgrServiceTest, VerifyCallingPermission_001, Function | SmallTest | Level0)
151 {
152 TAG_LOGI(AAFwkTag::TEST, "VerifyCallingPermission_001 start");
153 auto ret = serviceRouterMgrService_->VerifyCallingPermission("");
154 EXPECT_FALSE(ret);
155 TAG_LOGI(AAFwkTag::TEST, "VerifyCallingPermission_001 end");
156 }
157 }
158 }
159