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
17 #define private public
18 #define protected public
19 #include "ability_manager_service.h"
20 #include "ability_record.h"
21 #undef private
22 #undef protected
23
24 #include <gtest/gtest.h>
25 #include "ability_manager_errors.h"
26 #include "distributed_client.h"
27
28 using namespace testing;
29 using namespace testing::ext;
30 using namespace OHOS::AppExecFwk;
31
32 namespace OHOS {
33 namespace AAFwk {
34 namespace {
35 const int32_t API_VERSION = 9;
36 const int32_t USER_ID_U100 = 100;
37 }
38 class AbilityManagerServiceDistributedTest : public testing::Test {
39 public:
40 static void SetUpTestCase(void);
41 static void TearDownTestCase(void);
42 void SetUp() override;
43 void TearDown() override;
44 public:
45 inline static std::shared_ptr<AbilityManagerService> abilityMs_ {nullptr};
46 inline static std::shared_ptr<AbilityRecord> abilityRecord_ {nullptr};
47 };
48
SetUpTestCase(void)49 void AbilityManagerServiceDistributedTest::SetUpTestCase(void)
50 {
51 GTEST_LOG_(INFO) << "AbilityManagerServiceDistributedTest SetUpTestCase called";
52 abilityMs_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
53 abilityMs_->OnStart();
54 Want want;
55 OHOS::AppExecFwk::AbilityInfo abilityInfo;
56 OHOS::AppExecFwk::ApplicationInfo applicationInfo;
57 applicationInfo.apiTargetVersion = API_VERSION;
58 abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
59 abilityRecord_->Init();
60 }
TearDownTestCase(void)61 void AbilityManagerServiceDistributedTest::TearDownTestCase(void)
62 {
63 GTEST_LOG_(INFO) << "AbilityManagerServiceDistributedTest TearDownTestCase called";
64 abilityMs_->OnStop();
65 }
SetUp()66 void AbilityManagerServiceDistributedTest::SetUp()
67 {}
TearDown()68 void AbilityManagerServiceDistributedTest::TearDown()
69 {}
70
71 /**
72 * @tc.name: StartRemoteAbility_0001
73 * @tc.desc: StartRemoteAbility Test
74 * @tc.type: FUNC
75 * @tc.require: issueI5T6HF
76 */
77 HWTEST_F(AbilityManagerServiceDistributedTest, StartRemoteAbility_0001, TestSize.Level3)
78 {
79 Want want;
80 int result = abilityMs_->StartRemoteAbility(want, 0, USER_ID_U100, nullptr);
81 EXPECT_NE(result, ERR_OK);
82 }
83
84 /**
85 * @tc.name: StartRemoteAbility_0002
86 * @tc.desc: StartRemoteAbility Test
87 * @tc.type: FUNC
88 * @tc.require: issueI5T6HF
89 */
90 HWTEST_F(AbilityManagerServiceDistributedTest, StartRemoteAbility_0002, TestSize.Level3)
91 {
92 Want want;
93 int result = abilityMs_->StartRemoteAbility(want, 0, USER_ID_U100, abilityRecord_->GetToken());
94 EXPECT_NE(result, ERR_OK);
95 }
96
97 /**
98 * @tc.name: StartRemoteAbility_0003
99 * @tc.desc: StartRemoteAbility Test
100 * @tc.type: FUNC
101 * @tc.require: issueI5T6HF
102 */
103 HWTEST_F(AbilityManagerServiceDistributedTest, StartRemoteAbility_0003, TestSize.Level3)
104 {
105 Want want;
106 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
107 int result = abilityMs_->StartRemoteAbility(want, 0, USER_ID_U100, abilityRecord_->GetToken());
108 EXPECT_NE(result, ERR_OK);
109 }
110
111 /**
112 * @tc.name: StartRemoteAbility_0004
113 * @tc.desc: StartRemoteAbility Test
114 * @tc.type: FUNC
115 * @tc.require: issueI5T6HF
116 */
117 HWTEST_F(AbilityManagerServiceDistributedTest, StartRemoteAbility_0004, TestSize.Level3)
118 {
119 Want want;
120 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
121 want.SetParam(Want::PARAM_RESV_FOR_RESULT, true);
122 int result = abilityMs_->StartRemoteAbility(want, 0, USER_ID_U100, abilityRecord_->GetToken());
123 EXPECT_EQ(result, ERR_INVALID_VALUE);
124 }
125
126 /**
127 * @tc.name: ConnectRemoteAbility_0001
128 * @tc.desc: ConnectRemoteAbility Test
129 * @tc.type: FUNC
130 * @tc.require: issueI5T6HF
131 */
132 HWTEST_F(AbilityManagerServiceDistributedTest, ConnectRemoteAbility_0001, TestSize.Level3)
133 {
134 Want want;
135 int result = abilityMs_->ConnectRemoteAbility(want, nullptr, nullptr);
136 EXPECT_NE(result, ERR_OK);
137 }
138
139 /**
140 * @tc.name: ConnectRemoteAbility_0002
141 * @tc.desc: ConnectRemoteAbility Test
142 * @tc.type: FUNC
143 * @tc.require: issueI5T6HF
144 */
145 HWTEST_F(AbilityManagerServiceDistributedTest, ConnectRemoteAbility_0002, TestSize.Level3)
146 {
147 Want want;
148 int result = abilityMs_->ConnectRemoteAbility(want, abilityRecord_->GetToken(), nullptr);
149 EXPECT_TRUE(result != ERR_OK);
150 }
151
152 /**
153 * @tc.name: StartRemoteAbilityByCall_0001
154 * @tc.desc: StartRemoteAbilityByCall Test
155 * @tc.type: FUNC
156 * @tc.require: issueI5T6HF
157 */
158 HWTEST_F(AbilityManagerServiceDistributedTest, StartRemoteAbilityByCall_0001, TestSize.Level3)
159 {
160 Want want;
161 int result = abilityMs_->StartRemoteAbilityByCall(want, nullptr, nullptr);
162 EXPECT_NE(result, ERR_OK);
163 }
164
165 /**
166 * @tc.name: StartRemoteAbilityByCall_0002
167 * @tc.desc: StartRemoteAbilityByCall Test
168 * @tc.type: FUNC
169 * @tc.require: issueI5T6HF
170 */
171 HWTEST_F(AbilityManagerServiceDistributedTest, StartRemoteAbilityByCall_0002, TestSize.Level3)
172 {
173 Want want;
174 int result = abilityMs_->StartRemoteAbilityByCall(want, abilityRecord_->GetToken(), nullptr);
175 EXPECT_TRUE(result != ERR_OK);
176 }
177
178 /**
179 * @tc.name: AddStartControlParam_0001
180 * @tc.desc: AddStartControlParam Test
181 * @tc.type: FUNC
182 * @tc.require: issueI5T6HF
183 */
184 HWTEST_F(AbilityManagerServiceDistributedTest, AddStartControlParam_0001, TestSize.Level3)
185 {
186 Want want;
187 int result = abilityMs_->AddStartControlParam(want, nullptr);
188 EXPECT_EQ(result, ERR_OK);
189 }
190
191 /**
192 * @tc.name: AddStartControlParam_0002
193 * @tc.desc: AddStartControlParam Test
194 * @tc.type: FUNC
195 * @tc.require: issueI5T6HF
196 */
197 HWTEST_F(AbilityManagerServiceDistributedTest, AddStartControlParam_0002, TestSize.Level3)
198 {
199 Want want;
200 int result = abilityMs_->AddStartControlParam(want, abilityRecord_->GetToken());
201 EXPECT_EQ(result, ERR_OK);
202 }
203
204 /**
205 * @tc.name: AddStartControlParam_0003
206 * @tc.desc: AddStartControlParam Test
207 * @tc.type: FUNC
208 * @tc.require: issueI5T6HF
209 */
210 HWTEST_F(AbilityManagerServiceDistributedTest, AddStartControlParam_0003, TestSize.Level3)
211 {
212 Want want;
213 abilityMs_->backgroundJudgeFlag_ = false;
214 int result = abilityMs_->AddStartControlParam(want, abilityRecord_->GetToken());
215 EXPECT_EQ(result, ERR_OK);
216 }
217 } // namespace AAFwk
218 } // namespace OHOS
219