1 /*
2 * Copyright (c) 2021-2025 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
18 #include "ability_manager_proxy.h"
19 #include "ability_manager_errors.h"
20 #include "ability_record.h"
21 #include "ability_scheduler.h"
22 #include "hilog_tag_wrapper.h"
23 #include "mission_snapshot.h"
24 #include "want_sender_info.h"
25 #include "ability_manager_stub_mock.h"
26
27 using namespace testing::ext;
28 using namespace testing;
29 using namespace OHOS::AppExecFwk;
30
31 namespace OHOS {
32 namespace AAFwk {
33 namespace {
34 const int32_t ZERO = 0;
35 const std::string EMPTY_STRING = "";
36 } // namespace
37
38 class IRemoteObjectMocker : public IRemoteObject {
39 public:
IRemoteObjectMocker()40 IRemoteObjectMocker() : IRemoteObject {u"IRemoteObjectMocker"}
41 {
42 }
43
~IRemoteObjectMocker()44 ~IRemoteObjectMocker()
45 {
46 }
47
GetObjectRefCount()48 int32_t GetObjectRefCount()
49 {
50 return 0;
51 }
52
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)53 int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
54 {
55 return 0;
56 }
57
IsProxyObject() const58 bool IsProxyObject() const
59 {
60 return true;
61 }
62
CheckObjectLegality() const63 bool CheckObjectLegality() const
64 {
65 return true;
66 }
67
AddDeathRecipient(const sptr<DeathRecipient> & recipient)68 bool AddDeathRecipient(const sptr<DeathRecipient>& recipient)
69 {
70 return true;
71 }
72
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)73 bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient)
74 {
75 return true;
76 }
77
AsInterface()78 sptr<IRemoteBroker> AsInterface()
79 {
80 return nullptr;
81 }
82
Dump(int fd,const std::vector<std::u16string> & args)83 int Dump(int fd, const std::vector<std::u16string>& args)
84 {
85 return 0;
86 }
87 };
88
89 class MockIWantSender : public IWantSender {
90 public:
~MockIWantSender()91 virtual ~MockIWantSender() {};
92
AsObject()93 sptr<IRemoteObject> AsObject() override
94 {
95 return iRemoteObjectFlags_;
96 };
SetIRemoteObjectFlags(sptr<IRemoteObject> iRemoteObjectFlags)97 void SetIRemoteObjectFlags(sptr<IRemoteObject> iRemoteObjectFlags)
98 {
99 iRemoteObjectFlags_ = iRemoteObjectFlags;
100 };
101
Send(SenderInfo & senderInfo)102 void Send(SenderInfo& senderInfo) override {};
103
104 private:
105 sptr<IRemoteObject> iRemoteObjectFlags_ = nullptr;
106 };
107
108 class AbilityManagerProxyFifthTest : public testing::Test {
109 public:
110 static void SetUpTestCase(void);
111 static void TearDownTestCase(void);
112 void SetUp();
113 void TearDown();
114
115 std::shared_ptr<AbilityManagerProxy> proxy_{ nullptr };
116 sptr<AbilityManagerStubMock> mock_{ nullptr };
117 };
118
SetUpTestCase(void)119 void AbilityManagerProxyFifthTest::SetUpTestCase(void)
120 {}
TearDownTestCase(void)121 void AbilityManagerProxyFifthTest::TearDownTestCase(void)
122 {}
TearDown()123 void AbilityManagerProxyFifthTest::TearDown()
124 {}
125
SetUp()126 void AbilityManagerProxyFifthTest::SetUp()
127 {
128 mock_ = new AbilityManagerStubMock();
129 proxy_ = std::make_shared<AbilityManagerProxy>(mock_);
130 }
131
132 /**
133 * @tc.name: GetPendingWantBundleName_0100
134 * @tc.desc: Test the GetPendingWantBundleName
135 * @tc.type: FUNC
136 */
137 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingWantBundleName_0100, TestSize.Level1)
138 {
139 sptr<IWantSender> testTarget = nullptr;
140 auto res1 = proxy_->GetPendingWantBundleName(testTarget);
141 EXPECT_EQ(res1, EMPTY_STRING);
142
143 auto target = new MockIWantSender();
144 ASSERT_NE(target, nullptr);
145 auto object = new IRemoteObjectMocker();
146 target->SetIRemoteObjectFlags(object);
147 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
148 auto res2 = proxy_->GetPendingWantBundleName(target);
149 EXPECT_EQ(res2, EMPTY_STRING);
150 }
151
152 /**
153 * @tc.name: GetPendingWantBundleName_0200
154 * @tc.desc: Test the GetPendingWantBundleName
155 * @tc.type: FUNC
156 */
157 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingWantBundleName_0200, TestSize.Level1)
158 {
159 auto target = new MockIWantSender();
160 ASSERT_NE(target, nullptr);
161 auto object = new IRemoteObjectMocker();
162 target->SetIRemoteObjectFlags(object);
163 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
164 auto res = proxy_->GetPendingWantBundleName(target);
165 EXPECT_EQ(res, EMPTY_STRING);
166 }
167
168 /**
169 * @tc.name: GetPendingWantCode_0100
170 * @tc.desc: Test the GetPendingWantCode
171 * @tc.type: FUNC
172 */
173 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingWantCode_0100, TestSize.Level1)
174 {
175 sptr<IWantSender> testTarget = nullptr;
176 auto res1 = proxy_->GetPendingWantCode(testTarget);
177 EXPECT_EQ(res1, ERR_INVALID_VALUE);
178
179 auto target = new MockIWantSender();
180 ASSERT_NE(target, nullptr);
181 auto object = new IRemoteObjectMocker();
182 target->SetIRemoteObjectFlags(object);
183 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
184 auto res2 = proxy_->GetPendingWantCode(target);
185 EXPECT_EQ(res2, INNER_ERR);
186 }
187
188 /**
189 * @tc.name: GetPendingWantCode_0200
190 * @tc.desc: Test the GetPendingWantCode
191 * @tc.type: FUNC
192 */
193 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingWantCode_0200, TestSize.Level1)
194 {
195 auto target = new MockIWantSender();
196 ASSERT_NE(target, nullptr);
197 auto object = new IRemoteObjectMocker();
198 target->SetIRemoteObjectFlags(object);
199 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
200 auto res = proxy_->GetPendingWantCode(target);
201 EXPECT_EQ(res, ZERO);
202 }
203
204 /**
205 * @tc.name: GetPendingWantType_0100
206 * @tc.desc: Test the GetPendingWantType
207 * @tc.type: FUNC
208 */
209 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingWantType_0100, TestSize.Level1)
210 {
211 sptr<IWantSender> testTarget = nullptr;
212 auto res1 = proxy_->GetPendingWantType(testTarget);
213 EXPECT_EQ(res1, ERR_INVALID_VALUE);
214
215 auto target = new MockIWantSender();
216 ASSERT_NE(target, nullptr);
217 auto object = new IRemoteObjectMocker();
218 target->SetIRemoteObjectFlags(object);
219 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
220 auto res2 = proxy_->GetPendingWantType(target);
221 EXPECT_EQ(res2, INNER_ERR);
222 }
223
224 /**
225 * @tc.name: GetPendingWantType_0200
226 * @tc.desc: Test the GetPendingWantType
227 * @tc.type: FUNC
228 */
229 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingWantType_0200, TestSize.Level1)
230 {
231 auto target = new MockIWantSender();
232 ASSERT_NE(target, nullptr);
233 auto object = new IRemoteObjectMocker();
234 target->SetIRemoteObjectFlags(object);
235 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
236 auto res = proxy_->GetPendingWantType(target);
237 EXPECT_EQ(res, ZERO);
238 }
239
240 /**
241 * @tc.name: GetPendingRequestWant_0100
242 * @tc.desc: Test the GetPendingRequestWant
243 * @tc.type: FUNC
244 */
245 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingRequestWant_0100, TestSize.Level1)
246 {
247 sptr<IWantSender> testTarget = nullptr;
248 std::shared_ptr<Want> want = nullptr;
249 auto res1 = proxy_->GetPendingRequestWant(testTarget, want);
250 EXPECT_EQ(res1, INNER_ERR);
251
252 auto target = new MockIWantSender();
253 ASSERT_NE(target, nullptr);
254 auto object = new IRemoteObjectMocker();
255 target->SetIRemoteObjectFlags(object);
256 auto res2 = proxy_->GetPendingRequestWant(target, want);
257 EXPECT_EQ(res2, INNER_ERR);
258
259 auto target2 = new MockIWantSender();
260 ASSERT_NE(target2, nullptr);
261 auto object2 = new IRemoteObjectMocker();
262 target2->SetIRemoteObjectFlags(object2);
263 want = std::make_shared<Want>();
264 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
265 auto res3 = proxy_->GetPendingRequestWant(target2, want);
266 EXPECT_EQ(res3, INVALID_PARAMETERS_ERR);
267 }
268
269 /**
270 * @tc.name: GetPendingRequestWant_0200
271 * @tc.desc: Test the GetPendingRequestWant
272 * @tc.type: FUNC
273 */
274 HWTEST_F(AbilityManagerProxyFifthTest, GetPendingRequestWant_0200, TestSize.Level1)
275 {
276 auto target = new MockIWantSender();
277 ASSERT_NE(target, nullptr);
278 auto object = new IRemoteObjectMocker();
279 target->SetIRemoteObjectFlags(object);
280 auto want = std::make_shared<Want>();
281 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
282 auto res = proxy_->GetPendingRequestWant(target, want);
283 EXPECT_EQ(res, INNER_ERR);
284 }
285
286 /**
287 * @tc.name: GetWantSenderInfo_0100
288 * @tc.desc: Test the GetWantSenderInfo
289 * @tc.type: FUNC
290 */
291 HWTEST_F(AbilityManagerProxyFifthTest, GetWantSenderInfo_0100, TestSize.Level1)
292 {
293 sptr<IWantSender> testTarget = nullptr;
294 std::shared_ptr<WantSenderInfo> info = nullptr;
295 auto res1 = proxy_->GetWantSenderInfo(testTarget, info);
296 EXPECT_EQ(res1, INNER_ERR);
297
298 auto target = new MockIWantSender();
299 ASSERT_NE(target, nullptr);
300 auto object = new IRemoteObjectMocker();
301 target->SetIRemoteObjectFlags(object);
302 auto res2 = proxy_->GetWantSenderInfo(target, info);
303 EXPECT_EQ(res2, INNER_ERR);
304
305 auto target2 = new MockIWantSender();
306 ASSERT_NE(target2, nullptr);
307 auto object2 = new IRemoteObjectMocker();
308 target2->SetIRemoteObjectFlags(object2);
309 info = std::make_shared<WantSenderInfo>();
310 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
311 auto res3 = proxy_->GetWantSenderInfo(target2, info);
312 EXPECT_EQ(res3, INVALID_PARAMETERS_ERR);
313 }
314
315 /**
316 * @tc.name: GetWantSenderInfo_0200
317 * @tc.desc: Test the GetWantSenderInfo
318 * @tc.type: FUNC
319 */
320 HWTEST_F(AbilityManagerProxyFifthTest, GetWantSenderInfo_0200, TestSize.Level1)
321 {
322 auto target = new MockIWantSender();
323 ASSERT_NE(target, nullptr);
324 auto object = new IRemoteObjectMocker();
325 target->SetIRemoteObjectFlags(object);
326 auto info = std::make_shared<WantSenderInfo>();
327 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
328 auto res = proxy_->GetWantSenderInfo(target, info);
329 EXPECT_EQ(res, INNER_ERR);
330 }
331
332 /**
333 * @tc.name: GetAppMemorySize_0100
334 * @tc.desc: Test the GetAppMemorySize
335 * @tc.type: FUNC
336 */
337 HWTEST_F(AbilityManagerProxyFifthTest, GetAppMemorySize_0100, TestSize.Level1)
338 {
339 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
340 auto res = proxy_->GetAppMemorySize();
341 EXPECT_EQ(res, ZERO);
342
343 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
344 auto res2 = proxy_->GetAppMemorySize();
345 EXPECT_EQ(res2, INVALID_PARAMETERS_ERR);
346 }
347
348 /**
349 * @tc.name: IsRamConstrainedDevice_0100
350 * @tc.desc: Test the IsRamConstrainedDevice
351 * @tc.type: FUNC
352 */
353 HWTEST_F(AbilityManagerProxyFifthTest, IsRamConstrainedDevice_0100, TestSize.Level1)
354 {
355 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
356 auto res = proxy_->IsRamConstrainedDevice();
357 EXPECT_EQ(res, false);
358
359 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
360 auto res2 = proxy_->IsRamConstrainedDevice();
361 EXPECT_EQ(res2, false);
362 }
363
364 /**
365 * @tc.name: ContinueMission_0100
366 * @tc.desc: Test the ContinueMission
367 * @tc.type: FUNC
368 */
369 HWTEST_F(AbilityManagerProxyFifthTest, ContinueMission_0100, TestSize.Level1)
370 {
371 std::string srcDeviceId = "001";
372 std::string dstDeviceId = "002";
373 int32_t missionId = -1;
374 sptr<IRemoteObject> callBack = nullptr;
375 AAFwk::WantParams wantParams;
376 auto res1 = proxy_->ContinueMission(srcDeviceId, dstDeviceId, missionId, callBack, wantParams);
377 EXPECT_EQ(res1, INNER_ERR);
378
379 sptr<IRemoteObject> callBack1 = new IRemoteObjectMocker();
380 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
381 auto res2 = proxy_->ContinueMission(srcDeviceId, dstDeviceId, missionId, callBack1, wantParams);
382 EXPECT_EQ(res2, INVALID_PARAMETERS_ERR);
383
384 sptr<IRemoteObject> callBack2 = new IRemoteObjectMocker();
385 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
386 auto res3 = proxy_->ContinueMission(srcDeviceId, dstDeviceId, missionId, callBack2, wantParams);
387 EXPECT_EQ(res3, ZERO);
388 }
389
390 /**
391 * @tc.name: ContinueMission_0200
392 * @tc.desc: Test the ContinueMission
393 * @tc.type: FUNC
394 */
395 HWTEST_F(AbilityManagerProxyFifthTest, ContinueMission_0200, TestSize.Level1)
396 {
397 AAFwk::ContinueMissionInfo continueMissionInfo;
398 sptr<IRemoteObject> callBack = nullptr;
399 auto res1 = proxy_->ContinueMission(continueMissionInfo, callBack);
400 EXPECT_EQ(res1, INNER_ERR);
401
402 sptr<IRemoteObject> callBack1 = new IRemoteObjectMocker();
403 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
404 auto res2 = proxy_->ContinueMission(continueMissionInfo, callBack1);
405 EXPECT_EQ(res2, INVALID_PARAMETERS_ERR);
406
407 sptr<IRemoteObject> callBack2 = new IRemoteObjectMocker();
408 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
409 auto res3 = proxy_->ContinueMission(continueMissionInfo, callBack2);
410 EXPECT_EQ(res3, ZERO);
411 }
412
413 /**
414 * @tc.name: ContinueAbility_0100
415 * @tc.desc: Test the ContinueAbility
416 * @tc.type: FUNC
417 */
418 HWTEST_F(AbilityManagerProxyFifthTest, ContinueAbility_0100, TestSize.Level1)
419 {
420 std::string deviceId = "001";
421 int32_t missionId = 2;
422 uint32_t versionCode = 3;
423 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
424 auto res = proxy_->ContinueAbility(deviceId, missionId, versionCode);
425 EXPECT_EQ(res, INVALID_PARAMETERS_ERR);
426
427 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
428 auto res2 = proxy_->ContinueAbility(deviceId, missionId, versionCode);
429 EXPECT_EQ(res2, ZERO);
430 }
431
432 /**
433 * @tc.name: StartContinuation_0100
434 * @tc.desc: Test the StartContinuation
435 * @tc.type: FUNC
436 */
437 HWTEST_F(AbilityManagerProxyFifthTest, StartContinuation_0100, TestSize.Level1)
438 {
439 Want want;
440 sptr<IRemoteObject> abilityToken = nullptr;
441 int32_t status = 1;
442 auto res1 = proxy_->StartContinuation(want, abilityToken, status);
443 EXPECT_EQ(res1, INNER_ERR);
444
445 sptr<IRemoteObject> abilityToken2 = new IRemoteObjectMocker();
446 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
447 auto res2 = proxy_->StartContinuation(want, abilityToken2, status);
448 EXPECT_EQ(res2, INVALID_PARAMETERS_ERR);
449
450 sptr<IRemoteObject> abilityToken3 = new IRemoteObjectMocker();
451 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
452 auto res3 = proxy_->StartContinuation(want, abilityToken3, status);
453 EXPECT_EQ(res3, ZERO);
454 }
455
456 /**
457 * @tc.name: NotifyContinuationResult_0100
458 * @tc.desc: Test the NotifyContinuationResult
459 * @tc.type: FUNC
460 */
461 HWTEST_F(AbilityManagerProxyFifthTest, NotifyContinuationResult_0100, TestSize.Level1)
462 {
463 int32_t missionId = 10;
464 int32_t result = 12;
465 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
466 auto res1 = proxy_->NotifyContinuationResult(missionId, result);
467 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
468
469 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
470 auto res2 = proxy_->NotifyContinuationResult(missionId, result);
471 EXPECT_EQ(res2, ZERO);
472 }
473
474 /**
475 * @tc.name: StartSyncRemoteMissions_0100
476 * @tc.desc: Test the StartSyncRemoteMissions
477 * @tc.type: FUNC
478 */
479 HWTEST_F(AbilityManagerProxyFifthTest, StartSyncRemoteMissions_0100, TestSize.Level1)
480 {
481 std::string devId = "100";
482 bool fixConflict = false;
483 int64_t tag = 1;
484 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
485 auto res1 = proxy_->StartSyncRemoteMissions(devId, fixConflict, tag);
486 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
487
488 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
489 auto res2 = proxy_->StartSyncRemoteMissions(devId, fixConflict, tag);
490 EXPECT_EQ(res2, ZERO);
491 }
492
493 /**
494 * @tc.name: StopSyncRemoteMissions_0100
495 * @tc.desc: Test the StopSyncRemoteMissions
496 * @tc.type: FUNC
497 */
498 HWTEST_F(AbilityManagerProxyFifthTest, StopSyncRemoteMissions_0100, TestSize.Level1)
499 {
500 std::string devId = "100";
501 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
502 auto res1 = proxy_->StopSyncRemoteMissions(devId);
503 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
504
505 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
506 auto res2 = proxy_->StopSyncRemoteMissions(devId);
507 EXPECT_EQ(res2, ZERO);
508 }
509
510 /**
511 * @tc.name: LockMissionForCleanup_0100
512 * @tc.desc: Test the LockMissionForCleanup
513 * @tc.type: FUNC
514 */
515 HWTEST_F(AbilityManagerProxyFifthTest, LockMissionForCleanup_0100, TestSize.Level1)
516 {
517 int32_t missionId = 1;
518 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
519 auto res1 = proxy_->LockMissionForCleanup(missionId);
520 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
521
522 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
523 auto res2 = proxy_->LockMissionForCleanup(missionId);
524 EXPECT_EQ(res2, ZERO);
525 }
526
527 /**
528 * @tc.name: UnlockMissionForCleanup_0100
529 * @tc.desc: Test the UnlockMissionForCleanup
530 * @tc.type: FUNC
531 */
532 HWTEST_F(AbilityManagerProxyFifthTest, UnlockMissionForCleanup_0100, TestSize.Level1)
533 {
534 int32_t missionId = 1;
535 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
536 auto res1 = proxy_->UnlockMissionForCleanup(missionId);
537 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
538
539 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
540 auto res2 = proxy_->UnlockMissionForCleanup(missionId);
541 EXPECT_EQ(res2, ZERO);
542 }
543
544 /**
545 * @tc.name: GetMissionInfos_0100
546 * @tc.desc: Test the GetMissionInfos
547 * @tc.type: FUNC
548 */
549 HWTEST_F(AbilityManagerProxyFifthTest, GetMissionInfos_0100, TestSize.Level1)
550 {
551 std::string deviceId = "100";
552 int32_t numMax = 100;
553 std::vector<MissionInfo> missionInfos;
554 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
555 auto res1 = proxy_->GetMissionInfos(deviceId, numMax, missionInfos);
556 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
557
558 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
559 auto res2 = proxy_->GetMissionInfos(deviceId, numMax, missionInfos);
560 EXPECT_EQ(res2, ZERO);
561 }
562
563 /**
564 * @tc.name: GetMissionInfo_0100
565 * @tc.desc: Test the GetMissionInfo
566 * @tc.type: FUNC
567 */
568 HWTEST_F(AbilityManagerProxyFifthTest, GetMissionInfo_0100, TestSize.Level1)
569 {
570 std::string deviceId = "100";
571 int32_t numMax = 100;
572 MissionInfo missionInfo;
573 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
574 auto res1 = proxy_->GetMissionInfo(deviceId, numMax, missionInfo);
575 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
576
577 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
578 auto res2 = proxy_->GetMissionInfo(deviceId, numMax, missionInfo);
579 EXPECT_EQ(res2, ERR_UNKNOWN_OBJECT);
580 }
581
582 /**
583 * @tc.name: KillProcessWithReason_0100
584 * @tc.desc: Test the KillProcessWithReason
585 * @tc.type: FUNC
586 */
587 HWTEST_F(AbilityManagerProxyFifthTest, KillProcessWithReason_0100, TestSize.Level1)
588 {
589 int32_t pid = 100;
590 ExitReason reason;
591 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
592 auto res1 = proxy_->KillProcessWithReason(pid, reason);
593 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
594
595 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
596 auto res2 = proxy_->KillProcessWithReason(pid, reason);
597 EXPECT_EQ(res2, ZERO);
598 }
599
600 /**
601 * @tc.name: RegisterAutoStartupSystemCallback_0100
602 * @tc.desc: Test the RegisterAutoStartupSystemCallback
603 * @tc.type: FUNC
604 */
605 HWTEST_F(AbilityManagerProxyFifthTest, RegisterAutoStartupSystemCallback_0100, TestSize.Level1)
606 {
607 sptr<IRemoteObject> callback = nullptr;
608 auto res = proxy_->RegisterAutoStartupSystemCallback(callback);
609 EXPECT_EQ(res, INNER_ERR);
610
611 sptr<IRemoteObject> callback2 = new IRemoteObjectMocker();
612 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
613 auto res1 = proxy_->RegisterAutoStartupSystemCallback(callback2);
614 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
615
616 sptr<IRemoteObject> callback3 = new IRemoteObjectMocker();
617 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
618 auto res2 = proxy_->RegisterAutoStartupSystemCallback(callback3);
619 EXPECT_EQ(res2, ZERO);
620 }
621
622 /**
623 * @tc.name: UnregisterAutoStartupSystemCallback_0100
624 * @tc.desc: Test the UnregisterAutoStartupSystemCallback
625 * @tc.type: FUNC
626 */
627 HWTEST_F(AbilityManagerProxyFifthTest, UnregisterAutoStartupSystemCallback_0100, TestSize.Level1)
628 {
629 sptr<IRemoteObject> callback = nullptr;
630 auto res = proxy_->UnregisterAutoStartupSystemCallback(callback);
631 EXPECT_EQ(res, INNER_ERR);
632
633 sptr<IRemoteObject> callback2 = new IRemoteObjectMocker();
634 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
635 auto res1 = proxy_->UnregisterAutoStartupSystemCallback(callback2);
636 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
637
638 sptr<IRemoteObject> callback3 = new IRemoteObjectMocker();
639 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
640 auto res2 = proxy_->UnregisterAutoStartupSystemCallback(callback3);
641 EXPECT_EQ(res2, ZERO);
642 }
643
644 /**
645 * @tc.name: SetApplicationAutoStartup_0100
646 * @tc.desc: Test the SetApplicationAutoStartup
647 * @tc.type: FUNC
648 */
649 HWTEST_F(AbilityManagerProxyFifthTest, SetApplicationAutoStartup_0100, TestSize.Level1)
650 {
651 AutoStartupInfo info;
652 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
653 auto res1 = proxy_->SetApplicationAutoStartup(info);
654 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
655
656 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
657 auto res2 = proxy_->SetApplicationAutoStartup(info);
658 EXPECT_EQ(res2, ZERO);
659 }
660
661 /**
662 * @tc.name: CancelApplicationAutoStartup_0100
663 * @tc.desc: Test the CancelApplicationAutoStartup
664 * @tc.type: FUNC
665 */
666 HWTEST_F(AbilityManagerProxyFifthTest, CancelApplicationAutoStartup_0100, TestSize.Level1)
667 {
668 AutoStartupInfo info;
669 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
670 auto res1 = proxy_->CancelApplicationAutoStartup(info);
671 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
672
673 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
674 auto res2 = proxy_->CancelApplicationAutoStartup(info);
675 EXPECT_EQ(res2, ZERO);
676 }
677
678 /**
679 * @tc.name: QueryAllAutoStartupApplications_0100
680 * @tc.desc: Test the QueryAllAutoStartupApplications
681 * @tc.type: FUNC
682 */
683 HWTEST_F(AbilityManagerProxyFifthTest, QueryAllAutoStartupApplications_0100, TestSize.Level1)
684 {
685 std::vector<AutoStartupInfo> infoList;
686 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
687 auto res1 = proxy_->QueryAllAutoStartupApplications(infoList);
688 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
689
690 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
691 auto res2 = proxy_->QueryAllAutoStartupApplications(infoList);
692 EXPECT_EQ(res2, ZERO);
693 }
694
695 /**
696 * @tc.name: RegisterSessionHandler_0100
697 * @tc.desc: Test the RegisterSessionHandler
698 * @tc.type: FUNC
699 */
700 HWTEST_F(AbilityManagerProxyFifthTest, RegisterSessionHandler_0100, TestSize.Level1)
701 {
702 sptr<IRemoteObject> object = nullptr;
703 auto res = proxy_->RegisterSessionHandler(object);
704 EXPECT_EQ(res, ERR_INVALID_VALUE);
705
706 sptr<IRemoteObject> object2 = new IRemoteObjectMocker();
707 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
708 auto res1 = proxy_->RegisterSessionHandler(object2);
709 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
710
711 sptr<IRemoteObject> object3 = new IRemoteObjectMocker();
712 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
713 auto res2 = proxy_->RegisterSessionHandler(object3);
714 EXPECT_EQ(res2, ZERO);
715 }
716
717 /**
718 * @tc.name: RegisterAppDebugListener_0100
719 * @tc.desc: Test the RegisterAppDebugListener
720 * @tc.type: FUNC
721 */
722 HWTEST_F(AbilityManagerProxyFifthTest, RegisterAppDebugListener_0100, TestSize.Level1)
723 {
724 sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
725 auto res = proxy_->RegisterAppDebugListener(listener);
726 EXPECT_EQ(res, INNER_ERR);
727 }
728
729 /**
730 * @tc.name: UnregisterAppDebugListener_0100
731 * @tc.desc: Test the UnregisterAppDebugListener
732 * @tc.type: FUNC
733 */
734 HWTEST_F(AbilityManagerProxyFifthTest, UnregisterAppDebugListener_0100, TestSize.Level1)
735 {
736 sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
737 auto res = proxy_->UnregisterAppDebugListener(listener);
738 EXPECT_EQ(res, INNER_ERR);
739 }
740
741 /**
742 * @tc.name: AttachAppDebug_0100
743 * @tc.desc: Test the AttachAppDebug
744 * @tc.type: FUNC
745 */
746 HWTEST_F(AbilityManagerProxyFifthTest, AttachAppDebug_0100, TestSize.Level1)
747 {
748 std::string bundleName = "bundleName";
749 bool isDebugFromLocal = false;
750 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
751 auto res1 = proxy_->AttachAppDebug(bundleName, isDebugFromLocal);
752 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
753
754 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
755 auto res2 = proxy_->AttachAppDebug(bundleName, isDebugFromLocal);
756 EXPECT_EQ(res2, ZERO);
757 }
758
759 /**
760 * @tc.name: DetachAppDebug_0100
761 * @tc.desc: Test the DetachAppDebug
762 * @tc.type: FUNC
763 */
764 HWTEST_F(AbilityManagerProxyFifthTest, DetachAppDebug_0100, TestSize.Level1)
765 {
766 std::string bundleName = "bundleName";
767 bool isDebugFromLocal = false;
768 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
769 auto res1 = proxy_->DetachAppDebug(bundleName, isDebugFromLocal);
770 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
771
772 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
773 auto res2 = proxy_->DetachAppDebug(bundleName, isDebugFromLocal);
774 EXPECT_EQ(res2, ZERO);
775 }
776
777 /**
778 * @tc.name: ExecuteIntent_0100
779 * @tc.desc: Test the ExecuteIntent
780 * @tc.type: FUNC
781 */
782 HWTEST_F(AbilityManagerProxyFifthTest, ExecuteIntent_0100, TestSize.Level1)
783 {
784 uint64_t key = 1;
785 InsightIntentExecuteParam param;
786 sptr<IRemoteObject> callerToken = nullptr;
787 auto res = proxy_->ExecuteIntent(key, callerToken, param);
788 EXPECT_EQ(res, INNER_ERR);
789
790 sptr<IRemoteObject> callerToken2 = new IRemoteObjectMocker();
791 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
792 auto res1 = proxy_->ExecuteIntent(key, callerToken2, param);
793 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
794
795 sptr<IRemoteObject> callerToken3 = new IRemoteObjectMocker();
796 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
797 auto res2 = proxy_->ExecuteIntent(key, callerToken3, param);
798 EXPECT_EQ(res2, ZERO);
799 }
800
801 /**
802 * @tc.name: IsAbilityControllerStart_0100
803 * @tc.desc: Test the IsAbilityControllerStart
804 * @tc.type: FUNC
805 */
806 HWTEST_F(AbilityManagerProxyFifthTest, IsAbilityControllerStart_0100, TestSize.Level1)
807 {
808 Want want;
809 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
810 auto res1 = proxy_->IsAbilityControllerStart(want);
811 EXPECT_EQ(res1, true);
812
813 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
814 auto res2 = proxy_->IsAbilityControllerStart(want);
815 EXPECT_EQ(res2, false);
816 }
817
818 /**
819 * @tc.name: SetApplicationAutoStartupByEDM_0100
820 * @tc.desc: Test the SetApplicationAutoStartupByEDM
821 * @tc.type: FUNC
822 */
823 HWTEST_F(AbilityManagerProxyFifthTest, SetApplicationAutoStartupByEDM_0100, TestSize.Level1)
824 {
825 AutoStartupInfo info;
826 bool flag = false;
827 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
828 auto res1 = proxy_->SetApplicationAutoStartupByEDM(info, flag);
829 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
830
831 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
832 auto res2 = proxy_->SetApplicationAutoStartupByEDM(info, flag);
833 EXPECT_EQ(res2, ZERO);
834 }
835
836 /**
837 * @tc.name: CancelApplicationAutoStartupByEDM_0100
838 * @tc.desc: Test the CancelApplicationAutoStartupByEDM
839 * @tc.type: FUNC
840 */
841 HWTEST_F(AbilityManagerProxyFifthTest, CancelApplicationAutoStartupByEDM_0100, TestSize.Level1)
842 {
843 AutoStartupInfo info;
844 bool flag = false;
845 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
846 auto res1 = proxy_->CancelApplicationAutoStartupByEDM(info, flag);
847 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
848
849 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
850 auto res2 = proxy_->CancelApplicationAutoStartupByEDM(info, flag);
851 EXPECT_EQ(res2, ZERO);
852 }
853
854 /**
855 * @tc.name: GetForegroundUIAbilities_0100
856 * @tc.desc: Test the GetForegroundUIAbilities
857 * @tc.type: FUNC
858 */
859 HWTEST_F(AbilityManagerProxyFifthTest, GetForegroundUIAbilities_0100, TestSize.Level1)
860 {
861 std::vector<AppExecFwk::AbilityStateData> list;
862 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
863 auto res1 = proxy_->GetForegroundUIAbilities(list);
864 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
865
866 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(NO_ERROR));
867 auto res2 = proxy_->GetForegroundUIAbilities(list);
868 EXPECT_EQ(res2, ZERO);
869 }
870
871 /**
872 * @tc.name: OpenFile_0100
873 * @tc.desc: Test the OpenFile
874 * @tc.type: FUNC
875 */
876 HWTEST_F(AbilityManagerProxyFifthTest, OpenFile_0100, TestSize.Level1)
877 {
878 Uri uri("test");
879 uint32_t flag = 1;
880 EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
881 auto res1 = proxy_->OpenFile(uri, flag);
882 EXPECT_EQ(res1, INVALID_PARAMETERS_ERR);
883 }
884 } // namespace AAFwk
885 } // namespace OHOS
886