1 /*
2 * Copyright (c) 2022-2023 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 <numeric>
18 #define private public
19 #include "ability_manager_helper.h"
20 #undef private
21 #include "mock_common_event_stub.h"
22 #include "static_subscriber_connection.h"
23
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::EventFwk;
27 using namespace OHOS::AppExecFwk;
28
29 class AbilityManagerHelperTest : public testing::Test {
30 public:
AbilityManagerHelperTest()31 AbilityManagerHelperTest()
32 {}
~AbilityManagerHelperTest()33 ~AbilityManagerHelperTest()
34 {}
35
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase(void)42 void AbilityManagerHelperTest::SetUpTestCase(void)
43 {}
44
TearDownTestCase(void)45 void AbilityManagerHelperTest::TearDownTestCase(void)
46 {}
47
SetUp(void)48 void AbilityManagerHelperTest::SetUp(void)
49 {}
50
TearDown(void)51 void AbilityManagerHelperTest::TearDown(void)
52 {}
53
54 using TestAbilityManager = AAFwk::IAbilityManager;
55
56 class TestAbilityMgr : public TestAbilityManager {
57 public:
58 TestAbilityMgr() = default;
~TestAbilityMgr()59 virtual ~TestAbilityMgr()
60 {};
AsObject()61 sptr<IRemoteObject> AsObject() override
62 {
63 return nullptr;
64 }
65
StartAbility(const Want & want,int32_t userId,int requestCode)66 int StartAbility(const Want &want, int32_t userId, int requestCode) override
67 {
68 return 1;
69 }
70
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)71 int StartAbility(
72 const Want &want, const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode) override
73 {
74 return 1;
75 }
76
StartAbility(const Want & want,const AbilityStartSetting & abilityStartSetting,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)77 int StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting,
78 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode) override
79 {
80 return 1;
81 }
82
StartAbilityByInsightIntent(const Want & want,const sptr<IRemoteObject> & callerToken,uint64_t intentId,int32_t userId=DEFAULT_INVAL_VALUE)83 int32_t StartAbilityByInsightIntent(const Want &want, const sptr<IRemoteObject> &callerToken,
84 uint64_t intentId, int32_t userId = DEFAULT_INVAL_VALUE) override
85 {
86 return 1;
87 }
88
StartAbility(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)89 int StartAbility(const Want &want, const StartOptions &startOptions,
90 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode) override
91 {
92 return 1;
93 }
94
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant=nullptr)95 int TerminateAbility(
96 const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant = nullptr) override
97 {
98 return 1;
99 }
100
CloseAbility(const sptr<IRemoteObject> & token,int resultCode=DEFAULT_INVAL_VALUE,const Want * resultWant=nullptr)101 int CloseAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
102 const Want *resultWant = nullptr) override
103 {
104 return 1;
105 }
106
MinimizeAbility(const sptr<IRemoteObject> & token,bool fromUser=false)107 int MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser = false) override
108 {
109 return 1;
110 }
111
ConnectAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId)112 int ConnectAbility(const Want &want, const sptr<IAbilityConnection> &connect,
113 const sptr<IRemoteObject> &callerToken, int32_t userId) override
114 {
115 return 1;
116 }
117
DisconnectAbility(sptr<IAbilityConnection> connect)118 int DisconnectAbility(sptr<IAbilityConnection> connect) override
119 {
120 return 1;
121 }
122
AcquireDataAbility(const Uri & uri,bool tryBind,const sptr<IRemoteObject> & callerToken)123 sptr<IAbilityScheduler> AcquireDataAbility(
124 const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken) override
125 {
126 return nullptr;
127 }
128
ReleaseDataAbility(sptr<IAbilityScheduler> dataAbilityScheduler,const sptr<IRemoteObject> & callerToken)129 int ReleaseDataAbility(
130 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) override
131 {
132 return 1;
133 }
134
AttachAbilityThread(const sptr<IAbilityScheduler> & scheduler,const sptr<IRemoteObject> & token)135 int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) override
136 {
137 return 1;
138 }
139
AbilityTransitionDone(const sptr<IRemoteObject> & token,int state,const PacMap & saveData)140 int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData)override
141 {
142 return 1;
143 }
144
ScheduleConnectAbilityDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & remoteObject)145 int ScheduleConnectAbilityDone(
146 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) override
147 {
148 return 1;
149 }
150
ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> & token)151 int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) override
152 {
153 return 1;
154 }
155
ScheduleCommandAbilityDone(const sptr<IRemoteObject> & token)156 int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) override
157 {
158 return 1;
159 }
160
ScheduleCommandAbilityWindowDone(const sptr<IRemoteObject> & token,const sptr<AAFwk::SessionInfo> & sessionInfo,AAFwk::WindowCommand winCmd,AAFwk::AbilityCommand abilityCmd)161 int ScheduleCommandAbilityWindowDone(
162 const sptr<IRemoteObject> &token,
163 const sptr<AAFwk::SessionInfo> &sessionInfo,
164 AAFwk::WindowCommand winCmd,
165 AAFwk::AbilityCommand abilityCmd) override
166 {
167 return 1;
168 }
169
DumpState(const std::string & args,std::vector<std::string> & state)170 void DumpState(const std::string &args, std::vector<std::string> &state) override
171 {}
172
DumpSysState(const std::string & args,std::vector<std::string> & state,bool isClient,bool isUserID,int UserID)173 void DumpSysState(
174 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserID, int UserID) override
175 {}
176
StopServiceAbility(const Want & want,int32_t userId,const sptr<IRemoteObject> & token=nullptr)177 int StopServiceAbility(const Want &want, int32_t userId, const sptr<IRemoteObject> &token = nullptr) override
178 {
179 return 1;
180 }
181
KillProcess(const std::string & bundleName,const bool clearPageStack)182 int KillProcess(const std::string &bundleName, const bool clearPageStack) override
183 {
184 return 1;
185 }
186
UninstallApp(const std::string & bundleName,int32_t uid)187 int UninstallApp(const std::string &bundleName, int32_t uid) override
188 {
189 return 1;
190 }
191
GetWantSender(const WantSenderInfo & wantSenderInfo,const sptr<IRemoteObject> & callerToken,int32_t uid)192 sptr<IWantSender> GetWantSender(
193 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, int32_t uid) override
194 {
195 return nullptr;
196 }
197
SendWantSender(sptr<IWantSender> target,const SenderInfo & senderInfo)198 int SendWantSender(sptr<IWantSender> target, const SenderInfo &senderInfo) override
199 {
200 return 1;
201 }
202
CancelWantSender(const sptr<IWantSender> & sender)203 void CancelWantSender(const sptr<IWantSender> &sender) override
204 {}
205
GetPendingWantUid(const sptr<IWantSender> & target)206 int GetPendingWantUid(const sptr<IWantSender> &target) override
207 {
208 return 1;
209 }
210
GetPendingWantUserId(const sptr<IWantSender> & target)211 int GetPendingWantUserId(const sptr<IWantSender> &target) override
212 {
213 return 1;
214 }
215
GetPendingWantBundleName(const sptr<IWantSender> & target)216 std::string GetPendingWantBundleName(const sptr<IWantSender> &target) override
217 {
218 return "";
219 }
220
GetPendingWantCode(const sptr<IWantSender> & target)221 int GetPendingWantCode(const sptr<IWantSender> &target) override
222 {
223 return 1;
224 }
225
GetPendingWantType(const sptr<IWantSender> & target)226 int GetPendingWantType(const sptr<IWantSender> &target) override
227 {
228 return 1;
229 }
230
RegisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)231 void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override
232 {}
233
UnregisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)234 void UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override
235 {}
236
GetPendingRequestWant(const sptr<IWantSender> & target,std::shared_ptr<Want> & want)237 int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) override
238 {
239 return 1;
240 }
241
GetWantSenderInfo(const sptr<IWantSender> & target,std::shared_ptr<WantSenderInfo> & info)242 int GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info) override
243 {
244 return 1;
245 }
246
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,int32_t missionId,const sptr<IRemoteObject> & callBack,AAFwk::WantParams & wantParams)247 int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId,
248 const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override
249 {
250 return 1;
251 }
252
ContinueAbility(const std::string & deviceId,int32_t missionId,uint32_t versionCode)253 int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override
254 {
255 return 1;
256 }
257
StartContinuation(const Want & want,const sptr<IRemoteObject> & abilityToken,int32_t status)258 int StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status) override
259 {
260 return 1;
261 }
262
NotifyCompleteContinuation(const std::string & deviceId,int32_t sessionId,bool isSuccess)263 void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override
264 {}
265
NotifyContinuationResult(int32_t missionId,int32_t result)266 int NotifyContinuationResult(int32_t missionId, int32_t result) override
267 {
268 return 1;
269 }
270
LockMissionForCleanup(int32_t missionId)271 int LockMissionForCleanup(int32_t missionId) override
272 {
273 return 1;
274 }
275
UnlockMissionForCleanup(int32_t missionId)276 int UnlockMissionForCleanup(int32_t missionId) override
277 {
278 return 1;
279 }
280
RegisterMissionListener(const sptr<IMissionListener> & listener)281 int RegisterMissionListener(const sptr<IMissionListener> &listener) override
282 {
283 return 1;
284 }
285
UnRegisterMissionListener(const sptr<IMissionListener> & listener)286 int UnRegisterMissionListener(const sptr<IMissionListener> &listener) override
287 {
288 return 1;
289 }
290
GetMissionInfos(const std::string & deviceId,int32_t numMax,std::vector<MissionInfo> & missionInfos)291 int GetMissionInfos(
292 const std::string &deviceId, int32_t numMax, std::vector<MissionInfo> &missionInfos) override
293 {
294 return 1;
295 }
296
GetMissionInfo(const std::string & deviceId,int32_t missionId,MissionInfo & missionInfo)297 int GetMissionInfo(const std::string &deviceId, int32_t missionId, MissionInfo &missionInfo) override
298 {
299 return 1;
300 }
301
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)302 int GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
303 MissionSnapshot& snapshot, bool isLowResolution) override
304 {
305 return 1;
306 }
307
CleanMission(int32_t missionId)308 int CleanMission(int32_t missionId) override
309 {
310 return 1;
311 }
312
CleanAllMissions()313 int CleanAllMissions() override
314 {
315 return 1;
316 }
317
MoveMissionToFront(int32_t missionId)318 int MoveMissionToFront(int32_t missionId) override
319 {
320 return 1;
321 }
322
MoveMissionToFront(int32_t missionId,const StartOptions & startOptions)323 int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override
324 {
325 return 1;
326 }
327
StartAbilityByCall(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId)328 int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
329 const sptr<IRemoteObject> &callerToken, int32_t accountId) override
330 {
331 return 1;
332 }
333
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)334 int ReleaseCall(const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element) override
335 {
336 return 1;
337 }
338
StartUser(int userId,sptr<IUserCallback> callback)339 int StartUser(int userId, sptr<IUserCallback> callback) override
340 {
341 return 1;
342 }
343
StopUser(int userId,const sptr<IUserCallback> & callback)344 int StopUser(int userId, const sptr<IUserCallback> &callback) override
345 {
346 return 1;
347 }
348
SetMissionLabel(const sptr<IRemoteObject> & abilityToken,const std::string & label)349 int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) override
350 {
351 return 1;
352 }
353
SetMissionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<OHOS::Media::PixelMap> & icon)354 int SetMissionIcon(const sptr<IRemoteObject> &token,
355 const std::shared_ptr<OHOS::Media::PixelMap> &icon) override
356 {
357 return 1;
358 }
359
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler,bool animationEnabled)360 int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
361 bool animationEnabled) override
362 {
363 return 1;
364 }
365
CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)366 void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) override
367 {}
368
GetAbilityRunningInfos(std::vector<AbilityRunningInfo> & info)369 int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) override
370 {
371 return 1;
372 }
373
GetExtensionRunningInfos(int upperLimit,std::vector<ExtensionRunningInfo> & info)374 int GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info) override
375 {
376 return 1;
377 }
378
GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> & info)379 int GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info) override
380 {
381 return 1;
382 }
383
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)384 int StartSyncRemoteMissions(const std::string &devId, bool fixConflict, int64_t tag) override
385 {
386 return 1;
387 }
388
StopSyncRemoteMissions(const std::string & devId)389 int StopSyncRemoteMissions(const std::string &devId) override
390 {
391 return 1;
392 }
393
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)394 int RegisterMissionListener(const std::string &deviceId, const sptr<IRemoteMissionListener> &listener) override
395 {
396 return 1;
397 }
398
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)399 int UnRegisterMissionListener(const std::string &deviceId,
400 const sptr<IRemoteMissionListener> &listener) override
401 {
402 return 1;
403 }
404
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)405 int SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController,
406 bool imAStabilityTest) override
407 {
408 return 1;
409 }
410
IsRunningInStabilityTest()411 bool IsRunningInStabilityTest() override
412 {
413 return false;
414 }
415
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)416 int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override
417 {
418 return 1;
419 }
420
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)421 int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override
422 {
423 return 1;
424 }
425
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)426 int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override
427 {
428 return 1;
429 }
430
GetTopAbility(sptr<IRemoteObject> & token)431 int GetTopAbility(sptr<IRemoteObject> &token) override
432 {
433 return 1;
434 }
435
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)436 int DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token) override
437 {
438 return 1;
439 }
440
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)441 int DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token) override
442 {
443 return 1;
444 }
445
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)446 int DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag) override
447 {
448 return 1;
449 }
450
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)451 int DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag) override
452 {
453 return 1;
454 }
455
GetMissionIdByToken(const sptr<IRemoteObject> & token)456 int32_t GetMissionIdByToken(const sptr<IRemoteObject> &token) override
457 {
458 return 1;
459 }
460
GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> & callStub,sptr<IRemoteObject> & token)461 void GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token) override
462 {}
463
IsValidMissionIds(const std::vector<int32_t> & missionIds,std::vector<MissionValidResult> & results)464 int32_t IsValidMissionIds(
465 const std::vector<int32_t> &missionIds, std::vector<MissionValidResult> &results) override
466 {
467 return 1;
468 }
469
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)470 int32_t ReportDrawnCompleted(const sptr<IRemoteObject> &callerToken) override
471 {
472 return 1;
473 }
474
RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)475 int32_t RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener) override
476 {
477 return 1;
478 }
479
UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)480 int32_t UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener) override
481 {
482 return 1;
483 }
484
AttachAppDebug(const std::string & bundleName)485 int32_t AttachAppDebug(const std::string &bundleName) override
486 {
487 return 1;
488 }
489
DetachAppDebug(const std::string & bundleName)490 int32_t DetachAppDebug(const std::string &bundleName) override
491 {
492 return 1;
493 }
494
ExecuteIntent(uint64_t key,const sptr<IRemoteObject> & callerToken,const InsightIntentExecuteParam & param)495 int32_t ExecuteIntent(uint64_t key, const sptr<IRemoteObject> &callerToken,
496 const InsightIntentExecuteParam ¶m) override
497 {
498 return 1;
499 }
500
ExecuteInsightIntentDone(const sptr<IRemoteObject> & token,uint64_t intentId,const InsightIntentExecuteResult & result)501 int32_t ExecuteInsightIntentDone(const sptr<IRemoteObject> &token, uint64_t intentId,
502 const InsightIntentExecuteResult &result) override
503 {
504 return 1;
505 }
506
SetApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)507 int32_t SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override
508 {
509 return 0;
510 }
511
CancelApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)512 int32_t CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override
513 {
514 return 0;
515 }
516
GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> & list)517 int32_t GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list) override
518 {
519 return 1;
520 }
521
StartAbilityWithSpecifyTokenId(const Want & want,const sptr<IRemoteObject> & callerToken,uint32_t specifyTokenId,int32_t userId=DEFAULT_INVAL_VALUE,int requestCode=DEFAULT_INVAL_VALUE)522 int32_t StartAbilityWithSpecifyTokenId(const Want& want,
523 const sptr<IRemoteObject>& callerToken,
524 uint32_t specifyTokenId,
525 int32_t userId = DEFAULT_INVAL_VALUE,
526 int requestCode = DEFAULT_INVAL_VALUE) override
527 {
528 return 1;
529 }
530 };
531
532 /**
533 * @tc.name: AbilityManagerHelper_0100
534 * @tc.desc: test GetAbilityMgrProxy function and abilityMgr_ is not nullptr.
535 * @tc.type: FUNC
536 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0100,Level1)537 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0100, Level1)
538 {
539 GTEST_LOG_(INFO) << "AbilityManagerHelper_0100 start";
540 AbilityManagerHelper abilityManagerHelper;
541 abilityManagerHelper.abilityMgr_ = new (std::nothrow) TestAbilityMgr();
542 EXPECT_EQ(true, abilityManagerHelper.GetAbilityMgrProxy());
543 GTEST_LOG_(INFO) << "AbilityManagerHelper_0100 end";
544 }
545
546 /**
547 * @tc.name: AbilityManagerHelper_0200
548 * @tc.desc: test GetAbilityMgrProxy function and abilityMgr_ is nullptr.
549 * @tc.type: FUNC
550 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0200,Level1)551 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0200, Level1)
552 {
553 GTEST_LOG_(INFO) << "AbilityManagerHelper_0200 start";
554 AbilityManagerHelper abilityManagerHelper;
555 abilityManagerHelper.abilityMgr_ = nullptr;
556 EXPECT_EQ(false, abilityManagerHelper.GetAbilityMgrProxy());
557 GTEST_LOG_(INFO) << "AbilityManagerHelper_0200 end";
558 }
559
560 /**
561 * @tc.name: AbilityManagerHelper_0300
562 * @tc.desc: test ConnectAbility function and GetAbilityMgrProxy is false.
563 * @tc.type: FUNC
564 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0300,Level1)565 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0300, Level1)
566 {
567 GTEST_LOG_(INFO) << "AbilityManagerHelper_0300 start";
568 AbilityManagerHelper abilityManagerHelper;
569 abilityManagerHelper.abilityMgr_ = nullptr;
570 Want want;
571 CommonEventData event;
572 sptr<IRemoteObject> callerToken = nullptr;
573 const int32_t userId = 1;
574 EXPECT_EQ(-1, abilityManagerHelper.ConnectAbility(want, event, callerToken, userId));
575 GTEST_LOG_(INFO) << "AbilityManagerHelper_0300 end";
576 }
577
578 /**
579 * @tc.name: AbilityManagerHelper_0400
580 * @tc.desc: test Clear function and abilityMgr_ is nullptr.
581 * @tc.type: FUNC
582 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0400,Level1)583 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0400, Level1)
584 {
585 GTEST_LOG_(INFO) << "AbilityManagerHelper_0400 start";
586 std::shared_ptr<AbilityManagerHelper> abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
587 ASSERT_NE(nullptr, abilityManagerHelper);
588 abilityManagerHelper->abilityMgr_ = nullptr;
589 abilityManagerHelper->Clear();
590 GTEST_LOG_(INFO) << "AbilityManagerHelper_0400 end";
591 }
592
593 /**
594 * @tc.name: AbilityManagerHelper_0500
595 * @tc.desc: test Clear function and abilityMgr_ is not nullptr.
596 * @tc.type: FUNC
597 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0500,Level1)598 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0500, Level1)
599 {
600 GTEST_LOG_(INFO) << "AbilityManagerHelper_0500 start";
601 std::shared_ptr<AbilityManagerHelper> abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
602 ASSERT_NE(nullptr, abilityManagerHelper);
603 sptr<IRemoteObject> remoteObject = sptr<IRemoteObject>(new MockCommonEventStub());
604 abilityManagerHelper->abilityMgr_ = iface_cast<AAFwk::IAbilityManager>(remoteObject);
605 abilityManagerHelper->Clear();
606 GTEST_LOG_(INFO) << "AbilityManagerHelper_0500 end";
607 }
608
609 /**
610 * @tc.name : test SetEventHandler
611 * @tc.number: AbilityManagerHelper_0600
612 * @tc.desc : Test SetEventHandler succeeded.
613 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0600,Level1)614 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0600, Level1)
615 {
616 GTEST_LOG_(INFO) << "AbilityManagerHelper_0600 start";
617 auto abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
618 CommonEventData data;
619 sptr<StaticSubscriberConnection> connection = new (std::nothrow) StaticSubscriberConnection(data);
620 abilityManagerHelper->subscriberConnection_.emplace(connection);
621 auto handler = std::make_shared<EventHandler>(EventRunner::Create());
622 abilityManagerHelper->SetEventHandler(handler);
623 EXPECT_NE(abilityManagerHelper->subscriberConnection_.size(), 0);
624 GTEST_LOG_(INFO) << "AbilityManagerHelper_0600 end";
625 }
626
627 /**
628 * @tc.name : test DisconnectAbility
629 * @tc.number: AbilityManagerHelper_0700
630 * @tc.desc : Test the DisconnectAbility function when the connection is nullptr.
631 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0700,Level1)632 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0700, Level1)
633 {
634 GTEST_LOG_(INFO) << "AbilityManagerHelper_0700 start";
635 auto abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
636 CommonEventData data;
637 sptr<StaticSubscriberConnection> connection = new (std::nothrow) StaticSubscriberConnection(data);
638 abilityManagerHelper->subscriberConnection_.emplace(connection);
639 abilityManagerHelper->DisconnectAbility(nullptr);
640 EXPECT_NE(abilityManagerHelper->subscriberConnection_.size(), 0);
641 GTEST_LOG_(INFO) << "AbilityManagerHelper_0700 end";
642 }
643
644 /**
645 * @tc.name : test DisconnectAbility
646 * @tc.number: AbilityManagerHelper_0800
647 * @tc.desc : Test the DisconnectAbility function when the connection is not nullptr.
648 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0800,Level1)649 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0800, Level1)
650 {
651 GTEST_LOG_(INFO) << "AbilityManagerHelper_0800 start";
652 auto abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
653 CommonEventData data;
654 sptr<StaticSubscriberConnection> connection = new (std::nothrow) StaticSubscriberConnection(data);
655 abilityManagerHelper->subscriberConnection_.emplace(connection);
656 abilityManagerHelper->DisconnectAbility(connection);
657 EXPECT_NE(abilityManagerHelper->subscriberConnection_.size(), 0);
658 GTEST_LOG_(INFO) << "AbilityManagerHelper_0800 end";
659 }
660
661 /**
662 * @tc.name : test DisconnectServiceAbilityDelay
663 * @tc.number: AbilityManagerHelper_0900
664 * @tc.desc : Test the DisconnectServiceAbilityDelay function when the connection is nullptr.
665 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_0900,Level1)666 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_0900, Level1)
667 {
668 GTEST_LOG_(INFO) << "AbilityManagerHelper_0900 start";
669 auto abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
670 auto handler = std::make_shared<EventHandler>(EventRunner::Create());
671 abilityManagerHelper->SetEventHandler(handler);
672 CommonEventData data;
673 sptr<StaticSubscriberConnection> connection = new (std::nothrow) StaticSubscriberConnection(data);
674 abilityManagerHelper->subscriberConnection_.emplace(connection);
675 abilityManagerHelper->DisconnectServiceAbilityDelay(nullptr);
676 EXPECT_NE(abilityManagerHelper->subscriberConnection_.size(), 0);
677 GTEST_LOG_(INFO) << "AbilityManagerHelper_0900 end";
678 }
679
680 /**
681 * @tc.name : test DisconnectServiceAbilityDelay
682 * @tc.number: AbilityManagerHelper_1000
683 * @tc.desc : Test the DisconnectServiceAbilityDelay function when the eventHandler_ is nullptr.
684 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_1000,Level1)685 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_1000, Level1)
686 {
687 GTEST_LOG_(INFO) << "AbilityManagerHelper_1000 start";
688 auto abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
689 CommonEventData data;
690 sptr<StaticSubscriberConnection> connection = new (std::nothrow) StaticSubscriberConnection(data);
691 abilityManagerHelper->subscriberConnection_.emplace(connection);
692 abilityManagerHelper->DisconnectServiceAbilityDelay(connection);
693 EXPECT_NE(abilityManagerHelper->subscriberConnection_.size(), 0);
694 GTEST_LOG_(INFO) << "AbilityManagerHelper_1000 end";
695 }
696
697 /**
698 * @tc.name : test DisconnectServiceAbilityDelay
699 * @tc.number: AbilityManagerHelper_1100
700 * @tc.desc : Test the DisconnectServiceAbilityDelay function when the input parameters meet the requirements.
701 */
HWTEST_F(AbilityManagerHelperTest,AbilityManagerHelper_1100,Level1)702 HWTEST_F(AbilityManagerHelperTest, AbilityManagerHelper_1100, Level1)
703 {
704 GTEST_LOG_(INFO) << "AbilityManagerHelper_1100 start";
705 auto abilityManagerHelper = std::make_shared<AbilityManagerHelper>();
706 CommonEventData data;
707 sptr<StaticSubscriberConnection> firstConnection = new (std::nothrow) StaticSubscriberConnection(data);
708 abilityManagerHelper->subscriberConnection_.emplace(firstConnection);
709 auto handler = std::make_shared<EventHandler>(EventRunner::Create());
710 abilityManagerHelper->SetEventHandler(handler);
711 sptr<StaticSubscriberConnection> SecondConnection = new (std::nothrow) StaticSubscriberConnection(data);
712 abilityManagerHelper->DisconnectServiceAbilityDelay(SecondConnection);
713 EXPECT_NE(abilityManagerHelper->subscriberConnection_.size(), 0);
714 GTEST_LOG_(INFO) << "AbilityManagerHelper_1100 end";
715 }