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 #include "service_router_mgr_service.h"
18
19 #include "hilog_tag_wrapper.h"
20 #include "hilog_wrapper.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24 using OHOS::DelayedSingleton;
25
26 namespace OHOS {
27 namespace AbilityRuntime {
28 namespace {
29 const int RESULT_CODE = 8521225;
30 }
31 class ServiceRouterMgrServiceTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 public:
38 static std::shared_ptr<ServiceRouterMgrService> serviceRouterMgrService_;
39 };
SetUpTestCase(void)40 void ServiceRouterMgrServiceTest::SetUpTestCase(void)
41 {}
42
TearDownTestCase(void)43 void ServiceRouterMgrServiceTest::TearDownTestCase(void)
44 {
45 serviceRouterMgrService_->OnStop();
46 }
47
SetUp()48 void ServiceRouterMgrServiceTest::SetUp()
49 {
50 serviceRouterMgrService_->OnStart();
51 }
52
TearDown()53 void ServiceRouterMgrServiceTest::TearDown()
54 {}
55
56 std::shared_ptr<ServiceRouterMgrService> ServiceRouterMgrServiceTest::serviceRouterMgrService_ =
57 DelayedSingleton<ServiceRouterMgrService>::GetInstance();
58
59 /**
60 * @tc.name: test StartUIExtensionAbility_001
61 * @tc.desc: StartUIExtensionAbility
62 */
63 HWTEST_F(ServiceRouterMgrServiceTest, StartUIExtensionAbility_001, Function | SmallTest | Level0)
64 {
65 TAG_LOGI(AAFwkTag::TEST, "StartUIExtensionAbility_001 start");
66 sptr<SessionInfo> sessionInfo = nullptr;
67 int32_t userId = 1;
68 auto ret = serviceRouterMgrService_->StartUIExtensionAbility(sessionInfo, userId);
69 EXPECT_EQ(ret, ERR_INVALID_VALUE);
70 TAG_LOGI(AAFwkTag::TEST, "StartUIExtensionAbility_001 result %{public}d", ret);
71 TAG_LOGI(AAFwkTag::TEST, "StartUIExtensionAbility_001 end");
72 }
73
74 /**
75 * @tc.name: test ConnectUIExtensionAbility_001
76 * @tc.desc: ConnectUIExtensionAbility
77 */
78 HWTEST_F(ServiceRouterMgrServiceTest, ConnectUIExtensionAbility_001, Function | SmallTest | Level0)
79 {
80 TAG_LOGI(AAFwkTag::TEST, "ConnectUIExtensionAbility_001 start");
81 Want want;
82 sptr<IAbilityConnection> connect = nullptr;
83 sptr<SessionInfo> sessionInfo = nullptr;
84 int32_t userId = 1;
85 auto ret = serviceRouterMgrService_->ConnectUIExtensionAbility(want, connect, sessionInfo, userId);
86 EXPECT_EQ(ret, ERR_INVALID_VALUE);
87 TAG_LOGI(AAFwkTag::TEST, "ConnectUIExtensionAbility_001 result %{public}d", ret);
88 TAG_LOGI(AAFwkTag::TEST, "ConnectUIExtensionAbility_001 end");
89 }
90
91 /**
92 * @tc.name: test QueryPurposeInfos_001
93 * @tc.desc: QueryPurposeInfos
94 */
95 HWTEST_F(ServiceRouterMgrServiceTest, QueryPurposeInfos_001, Function | SmallTest | Level0)
96 {
97 TAG_LOGI(AAFwkTag::TEST, "QueryPurposeInfos_001 start");
98 Want want;
99 std::vector<PurposeInfo> purposeInfos;
100 auto ret = serviceRouterMgrService_->QueryPurposeInfos(want, "", purposeInfos);
101 EXPECT_EQ(ret, RESULT_CODE);
102 TAG_LOGI(AAFwkTag::TEST, "QueryPurposeInfos_001 result %{public}d", ret);
103 TAG_LOGI(AAFwkTag::TEST, "QueryPurposeInfos_001 end");
104 }
105
106 /**
107 * @tc.name: test QueryBusinessAbilityInfos_001
108 * @tc.desc: QueryBusinessAbilityInfos
109 */
110 HWTEST_F(ServiceRouterMgrServiceTest, QueryBusinessAbilityInfos_001, Function | SmallTest | Level0)
111 {
112 TAG_LOGI(AAFwkTag::TEST, "QueryBusinessAbilityInfos_001 start");
113 BusinessAbilityFilter filter;
114 filter.businessType = BusinessType::UNSPECIFIED;
115 std::vector<BusinessAbilityInfo> abilityInfos;
116 auto ret = serviceRouterMgrService_->QueryBusinessAbilityInfos(filter, abilityInfos);
117 EXPECT_EQ(ret, RESULT_CODE);
118 TAG_LOGI(AAFwkTag::TEST, "QueryBusinessAbilityInfos_001 result %{public}d", ret);
119 TAG_LOGI(AAFwkTag::TEST, "QueryBusinessAbilityInfos_001 end");
120 }
121 }
122 }
123
124