• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
18 #define private public
19 #define protected public
20 #include "app_foreground_state_observer_stub.h"
21 #include "app_mgr_stub.h"
22 #undef private
23 #undef protected
24 
25 #include "hilog_tag_wrapper.h"
26 #include "ipc_types.h"
27 #include "mock_app_mgr_service.h"
28 #include "render_state_observer_stub.h"
29 #include "native_child_notify_stub.h"
30 
31 using namespace testing;
32 using namespace testing::ext;
33 
34 namespace OHOS {
35 namespace AppExecFwk {
36 namespace {
37 const int32_t USER_ID = 100;
38 }  // namespace
39 
40 class AppForegroundStateObserverMock : public AppForegroundStateObserverStub {
41 public:
42     AppForegroundStateObserverMock() = default;
43     virtual ~AppForegroundStateObserverMock() = default;
OnAppStateChanged(const AppStateData & appStateData)44     void OnAppStateChanged(const AppStateData &appStateData) override
45     {}
46 };
47 
48 class RenderStateObserverMock : public RenderStateObserverStub {
49 public:
50     RenderStateObserverMock() = default;
51     virtual ~RenderStateObserverMock() = default;
OnRenderStateChanged(const RenderStateData & renderStateData)52     void OnRenderStateChanged(const RenderStateData &renderStateData) override
53     {}
54 };
55 
56 class NativeChildCallbackMock : public NativeChildNotifyStub {
57 public:
58     NativeChildCallbackMock() = default;
59     virtual ~NativeChildCallbackMock() = default;
60 
OnNativeChildStarted(const sptr<IRemoteObject> & nativeChild)61     void OnNativeChildStarted(const sptr<IRemoteObject> &nativeChild) {}
OnError(int32_t errCode)62     void OnError(int32_t errCode) {}
OnNativeChildExit(int32_t pid,int32_t signal)63     int32_t OnNativeChildExit(int32_t pid, int32_t signal) { return 0; }
64 };
65 
66 class AppMgrStubTest : public testing::Test {
67 public:
68     static void SetUpTestCase();
69     static void TearDownTestCase();
70     void SetUp() override;
71     void TearDown() override;
72 
73     sptr<MockAppMgrService> mockAppMgrService_;
74 
75     void WriteInterfaceToken(MessageParcel& data);
76 };
77 
SetUpTestCase(void)78 void AppMgrStubTest::SetUpTestCase(void)
79 {}
80 
TearDownTestCase(void)81 void AppMgrStubTest::TearDownTestCase(void)
82 {}
83 
SetUp()84 void AppMgrStubTest::SetUp()
85 {
86     GTEST_LOG_(INFO) << "AppMgrStubTest::SetUp()";
87 
88     mockAppMgrService_ = new MockAppMgrService();
89 }
90 
TearDown()91 void AppMgrStubTest::TearDown()
92 {}
93 
WriteInterfaceToken(MessageParcel & data)94 void AppMgrStubTest::WriteInterfaceToken(MessageParcel& data)
95 {
96     GTEST_LOG_(INFO) << "AppMgrStubTest::WriteInterfaceToken()";
97 
98     data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
99 }
100 
101 /**
102  * @tc.name: AppMgrStub_GetProcessRunningInfosByUserId_0100
103  * @tc.desc: GetProcessRunningInfosByUserId
104  * @tc.type: FUNC
105  * @tc.require: SR000GH1GO
106  */
107 HWTEST_F(AppMgrStubTest, AppMgrStub_GetProcessRunningInfosByUserId_0100, TestSize.Level1)
108 {
109     GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 start";
110 
111     MessageParcel data;
112     MessageParcel reply;
113     MessageOption option;
114 
115     WriteInterfaceToken(data);
116     data.WriteInt32(USER_ID);
117 
118     EXPECT_CALL(*mockAppMgrService_, GetProcessRunningInfosByUserId(_, _)).Times(1);
119 
120     auto result = mockAppMgrService_->OnRemoteRequest(
121         static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID), data, reply, option);
122     EXPECT_EQ(result, NO_ERROR);
123 
124     GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 end";
125 }
126 
127 /**
128  * @tc.name: HandleGetAppRunningStateByBundleName_0100
129  * @tc.desc: Handle get app running state by bundle name.
130  * @tc.type: FUNC
131  * @tc.require: issueI581VW
132  */
133 HWTEST_F(AppMgrStubTest, HandleGetAppRunningStateByBundleName_0100, TestSize.Level1)
134 {
135     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
136 
137     MessageParcel data;
138     MessageParcel reply;
139     MessageOption option;
140 
141     WriteInterfaceToken(data);
142     std::string bundleName = "testBundleName";
143     data.WriteString(bundleName);
144 
145     EXPECT_CALL(*mockAppMgrService_, GetAppRunningStateByBundleName(_)).Times(1);
146 
147     auto result = mockAppMgrService_->OnRemoteRequest(
148         static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_STATE), data, reply, option);
149     EXPECT_EQ(result, NO_ERROR);
150 
151     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
152 }
153 
154 /**
155  * @tc.name: HandleNotifyLoadRepairPatch_0100
156  * @tc.desc: Handle notify load repair patch.
157  * @tc.type: FUNC
158  * @tc.require: issueI581VW
159  */
160 HWTEST_F(AppMgrStubTest, HandleNotifyLoadRepairPatch_0100, TestSize.Level1)
161 {
162     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
163 
164     MessageParcel data;
165     MessageParcel reply;
166     MessageOption option;
167 
168     WriteInterfaceToken(data);
169     std::string bundleName = "testBundleName";
170     data.WriteString(bundleName);
171     mockAppMgrService_->HandleNotifyLoadRepairPatch(data, reply);
172     EXPECT_TRUE(mockAppMgrService_ != nullptr);
173 
174     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
175 }
176 
177 /**
178  * @tc.name: HandleNotifyHotReloadPage_0100
179  * @tc.desc: Handle notify ace hot reload page.
180  * @tc.type: FUNC
181  * @tc.require: issueI581VW
182  */
183 HWTEST_F(AppMgrStubTest, HandleNotifyHotReloadPage_0100, TestSize.Level1)
184 {
185     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
186 
187     MessageParcel data;
188     MessageParcel reply;
189     MessageOption option;
190 
191     WriteInterfaceToken(data);
192     std::string bundleName = "testBundleName";
193     data.WriteString(bundleName);
194     mockAppMgrService_->HandleNotifyHotReloadPage(data, reply);
195     EXPECT_TRUE(mockAppMgrService_ != nullptr);
196 
197     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
198 }
199 
200 /**
201  * @tc.name: HandleNotifyUnLoadRepairPatch_0100
202  * @tc.desc: Handle notify unload repair patch.
203  * @tc.type: FUNC
204  * @tc.require: issueI581VW
205  */
206 HWTEST_F(AppMgrStubTest, HandleNotifyUnLoadRepairPatch_0100, TestSize.Level1)
207 {
208     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
209 
210     MessageParcel data;
211     MessageParcel reply;
212     MessageOption option;
213 
214     WriteInterfaceToken(data);
215     std::string bundleName = "testBundleName";
216     data.WriteString(bundleName);
217     mockAppMgrService_->HandleNotifyUnLoadRepairPatch(data, reply);
218     EXPECT_TRUE(mockAppMgrService_ != nullptr);
219 
220     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
221 }
222 
223 /**
224  * @tc.name: PreStartNWebSpawnProcess_001
225  * @tc.desc: prestart nwebspawn process.
226  * @tc.type: FUNC
227  * @tc.require: issueI5W4S7
228  */
229 HWTEST_F(AppMgrStubTest, PreStartNWebSpawnProcess_001, TestSize.Level1)
230 {
231     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
232     MessageParcel data;
233     MessageParcel reply;
234     MessageOption option;
235     WriteInterfaceToken(data);
236     EXPECT_CALL(*mockAppMgrService_, PreStartNWebSpawnProcess()).Times(1);
237 
238     auto result = mockAppMgrService_->OnRemoteRequest(
239         static_cast<uint32_t>(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS), data, reply, option);
240     EXPECT_EQ(result, NO_ERROR);
241 
242     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
243 }
244 
245 /**
246  * @tc.name: GetProcessMemoryByPid_001
247  * @tc.desc: Get memorySize by pid.
248  * @tc.type: FUNC
249  * @tc.require: issueI76JBF
250  */
251 HWTEST_F(AppMgrStubTest, GetProcessMemoryByPid_001, TestSize.Level1)
252 {
253     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
254     MessageParcel data;
255     MessageParcel reply;
256     MessageOption option;
257 
258     WriteInterfaceToken(data);
259     int32_t pid = 0;
260     data.WriteInt32(pid);
261 
262     EXPECT_CALL(*mockAppMgrService_, GetProcessMemoryByPid(_, _)).Times(1);
263 
264     auto result = mockAppMgrService_->OnRemoteRequest(
265         static_cast<uint32_t>(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID), data, reply, option);
266     EXPECT_EQ(result, NO_ERROR);
267 
268     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
269 }
270 
271 /**
272  * @tc.name: GetRunningProcessInformation_001
273  * @tc.desc: Get pid list by bundleName.
274  * @tc.type: FUNC
275  * @tc.require: issueI76JBF
276  */
277 HWTEST_F(AppMgrStubTest, GetRunningProcessInformation_001, TestSize.Level1)
278 {
279     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
280     MessageParcel data;
281     MessageParcel reply;
282     MessageOption option;
283 
284     WriteInterfaceToken(data);
285     std::string bundleName = "testBundleName";
286     int32_t userId = 0;
287     data.WriteString(bundleName);
288     data.WriteInt32(userId);
289 
290     EXPECT_CALL(*mockAppMgrService_, GetRunningProcessInformation(_, _, _)).Times(1);
291 
292     auto result = mockAppMgrService_->OnRemoteRequest(
293         static_cast<uint32_t>(AppMgrInterfaceCode::GET_PIDS_BY_BUNDLENAME), data, reply, option);
294     EXPECT_EQ(result, NO_ERROR);
295 
296     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
297 }
298 
299 /**
300  * @tc.name: HandleNotifyFault_001
301  * @tc.desc: Handle notify fault.
302  * @tc.type: FUNC
303  * @tc.require: issueI79RY8
304  */
305 HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level1)
306 {
307     MessageParcel data;
308     MessageParcel reply;
309     MessageOption option;
310     WriteInterfaceToken(data);
311     FaultData faultData;
312     faultData.errorObject.name = "testName";
313     faultData.errorObject.message = "testMessage";
314     faultData.errorObject.stack = "testStack";
315     faultData.faultType = FaultDataType::UNKNOWN;
316     data.WriteParcelable(&faultData);
317     EXPECT_CALL(*mockAppMgrService_, NotifyAppFault(_)).Times(1);
318     auto result = mockAppMgrService_->OnRemoteRequest(
319         static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT), data, reply, option);
320     EXPECT_EQ(result, NO_ERROR);
321 }
322 
323 /**
324  * @tc.name: HandleNotifyFaultBySA_001
325  * @tc.desc: Handle notify fault by SA.
326  * @tc.type: FUNC
327  * @tc.require: issueI79RY8
328  */
329 HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level1)
330 {
331     MessageParcel data;
332     MessageParcel reply;
333     MessageOption option;
334     WriteInterfaceToken(data);
335     AppFaultDataBySA faultData;
336     faultData.errorObject.name = "testName";
337     faultData.errorObject.message = "testMessage";
338     faultData.errorObject.stack = "testStack";
339     faultData.faultType = FaultDataType::UNKNOWN;
340     faultData.pid = 24;
341     data.WriteParcelable(&faultData);
342     EXPECT_CALL(*mockAppMgrService_, NotifyAppFaultBySA(_)).Times(1);
343     auto result = mockAppMgrService_->OnRemoteRequest(
344         static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA), data, reply, option);
345     EXPECT_EQ(result, NO_ERROR);
346 }
347 
348 /**
349  * @tc.name: HandleSetAppFreezeFilter_001
350  * @tc.desc: Handle Set AppFreeze Filter.
351  * @tc.type: FUNC
352  */
353 HWTEST_F(AppMgrStubTest, HandleSetAppFreezeFilter_001, TestSize.Level1)
354 {
355     MessageParcel data;
356     MessageParcel reply;
357     MessageOption option;
358     WriteInterfaceToken(data);
359     data.WriteInt32(0);
360     auto result = mockAppMgrService_->OnRemoteRequest(
361         static_cast<uint32_t>(AppMgrInterfaceCode::SET_APPFREEZE_FILTER), data, reply, option);
362     EXPECT_EQ(result, NO_ERROR);
363 }
364 
365 /**
366  * @tc.name: HandleChangeAppGcState_001
367  * @tc.desc: Handle change app Gc state.
368  * @tc.type: FUNC
369  * @tc.require: issuesI85VVU
370  */
371 HWTEST_F(AppMgrStubTest, HandleChangeAppGcState_001, TestSize.Level1)
372 {
373     MessageParcel data;
374     MessageParcel reply;
375     MessageOption option;
376     WriteInterfaceToken(data);
377     data.WriteInt32(0);
378     data.WriteInt32(0);
379     data.WriteInt32(1);
380     auto result = mockAppMgrService_->OnRemoteRequest(
381             static_cast<uint32_t>(AppMgrInterfaceCode::CHANGE_APP_GC_STATE), data, reply, option);
382     EXPECT_EQ(result, NO_ERROR);
383 }
384 
385 /**
386  * @tc.name: IsAppRunning_001
387  * @tc.desc: On remote request to query the running status of the application.
388  * @tc.type: FUNC
389  */
390 HWTEST_F(AppMgrStubTest, IsAppRunning_0100, TestSize.Level1)
391 {
392     MessageParcel data;
393     MessageParcel reply;
394     MessageOption option;
395 
396     WriteInterfaceToken(data);
397     std::string bundleName = "testBundleName";
398     int32_t appCloneIndex = 0;
399     bool isRunning = false;
400     data.WriteString(bundleName);
401     data.WriteInt32(appCloneIndex);
402     data.WriteBool(isRunning);
403 
404     EXPECT_CALL(*mockAppMgrService_, IsAppRunning(_, _, _)).Times(1);
405 
406     auto result = mockAppMgrService_->OnRemoteRequest(
407         static_cast<uint32_t>(AppMgrInterfaceCode::IS_APP_RUNNING), data, reply, option);
408     EXPECT_EQ(result, NO_ERROR);
409 }
410 
411 /**
412  * @tc.name: IsApplicationRunning_001
413  * @tc.desc: On remote request to query the running status of the application.
414  * @tc.type: FUNC
415  */
416 HWTEST_F(AppMgrStubTest, IsApplicationRunning_0100, TestSize.Level1)
417 {
418     MessageParcel data;
419     MessageParcel reply;
420     MessageOption option;
421 
422     WriteInterfaceToken(data);
423     std::string bundleName = "testBundleName";
424     bool isRunning = false;
425     data.WriteString(bundleName);
426     data.WriteBool(isRunning);
427 
428     EXPECT_CALL(*mockAppMgrService_, IsApplicationRunning(_, _)).Times(1);
429 
430     auto result = mockAppMgrService_->OnRemoteRequest(
431         static_cast<uint32_t>(AppMgrInterfaceCode::IS_APPLICATION_RUNNING), data, reply, option);
432     EXPECT_EQ(result, NO_ERROR);
433 }
434 
435 /**
436  * @tc.number: HandleRegisterAbilityForegroundStateObserver_0100
437  * @tc.desc: Verify it when write result success.
438  * @tc.type: FUNC
439  */
440 HWTEST_F(AppMgrStubTest, HandleRegisterAbilityForegroundStateObserver_0100, TestSize.Level1)
441 {
442     MessageParcel data;
443     MessageParcel reply;
444     mockAppMgrService_->HandleRegisterAbilityForegroundStateObserver(data, reply);
445     EXPECT_TRUE(mockAppMgrService_ != nullptr);
446 }
447 
448 /**
449  * @tc.number: HandleUnregisterAbilityForegroundStateObserver_0100
450  * @tc.desc: Verify it when write result success.
451  * @tc.type: FUNC
452  */
453 HWTEST_F(AppMgrStubTest, HandleUnregisterAbilityForegroundStateObserver_0100, TestSize.Level1)
454 {
455     MessageParcel data;
456     MessageParcel reply;
457     auto result = mockAppMgrService_->HandleUnregisterAbilityForegroundStateObserver(data, reply);
458     EXPECT_EQ(result, NO_ERROR);
459 }
460 
461 /**
462  * @tc.name: HandleRegisterAppForegroundStateObserver_0100
463  * @tc.desc: Test when callback is not nullptr the return of writeInt32 is true.
464  * @tc.type: FUNC
465  */
466 HWTEST_F(AppMgrStubTest, HandleRegisterAppForegroundStateObserver_0100, TestSize.Level1)
467 {
468     MessageParcel data;
469     MessageParcel reply;
470     sptr<IRemoteObject> object = new (std::nothrow) AppForegroundStateObserverMock();
471     data.WriteRemoteObject(object);
472     int32_t pid = 1;
473     reply.WriteInt32(pid);
474     auto res = mockAppMgrService_->HandleRegisterAppForegroundStateObserver(data, reply);
475     EXPECT_EQ(res, NO_ERROR);
476 }
477 
478 /**
479  * @tc.name: HandleUnregisterAppForegroundStateObserver_0100
480  * @tc.desc: Test when callback is not nullptr the return of writeInt32 is true.
481  * @tc.type: FUNC
482  */
483 HWTEST_F(AppMgrStubTest, HandleUnregisterAppForegroundStateObserver_0100, TestSize.Level1)
484 {
485     MessageParcel data;
486     MessageParcel reply;
487     sptr<IRemoteObject> object = new (std::nothrow) AppForegroundStateObserverMock();
488     data.WriteRemoteObject(object);
489     int32_t pid = 1;
490     reply.WriteInt32(pid);
491     auto res = mockAppMgrService_->HandleUnregisterAppForegroundStateObserver(data, reply);
492     EXPECT_EQ(res, NO_ERROR);
493 }
494 
495 /**
496  * @tc.name: HandleRegisterNativeChildExitNotify_0100
497  * @tc.desc: Test when callback is not nullptr the return of writeInt32 is true.
498  * @tc.type: FUNC
499  */
500 HWTEST_F(AppMgrStubTest, HandleRegisterNativeChildExitNotify_0100, TestSize.Level1)
501 {
502     MessageParcel data;
503     MessageParcel reply;
504     sptr<IRemoteObject> object = new (std::nothrow) NativeChildCallbackMock();
505     data.WriteRemoteObject(object);
506     reply.WriteInt32(0);
507     auto res = mockAppMgrService_->HandleRegisterNativeChildExitNotify(data, reply);
508     EXPECT_EQ(res, NO_ERROR);
509 }
510 
511 /**
512  * @tc.name: HandleUnregisterNativeChildExitNotify_0100
513  * @tc.desc: Test when callback is not nullptr the return of writeInt32 is true.
514  * @tc.type: FUNC
515  */
516 HWTEST_F(AppMgrStubTest, HandleUnregisterNativeChildExitNotify_0100, TestSize.Level1)
517 {
518     MessageParcel data;
519     MessageParcel reply;
520     sptr<IRemoteObject> object = new (std::nothrow) NativeChildCallbackMock();
521     data.WriteRemoteObject(object);
522     reply.WriteInt32(0);
523     auto res = mockAppMgrService_->HandleUnregisterNativeChildExitNotify(data, reply);
524     EXPECT_EQ(res, NO_ERROR);
525 }
526 
527 /**
528  * @tc.name: HandleRegisterRenderStateObserver_0100
529  * @tc.desc: Test register observer success.
530  * @tc.type: FUNC
531  */
532 HWTEST_F(AppMgrStubTest, HandleRegisterRenderStateObserver_0100, TestSize.Level1)
533 {
534     MessageParcel data;
535     MessageParcel reply;
536     sptr<IRemoteObject> object = new (std::nothrow) RenderStateObserverMock();
537     data.WriteRemoteObject(object);
538     EXPECT_CALL(*mockAppMgrService_, RegisterRenderStateObserver(_)).Times(1);
539     auto res = mockAppMgrService_->HandleRegisterRenderStateObserver(data, reply);
540     EXPECT_EQ(res, NO_ERROR);
541 }
542 
543 /**
544  * @tc.name: HandleUnregisterRenderStateObserver_0100
545  * @tc.desc: Test unregister observer success.
546  * @tc.type: FUNC
547  */
548 HWTEST_F(AppMgrStubTest, HandleUnregisterRenderStateObserver_0100, TestSize.Level1)
549 {
550     MessageParcel data;
551     MessageParcel reply;
552     sptr<IRemoteObject> object = new (std::nothrow) RenderStateObserverMock();
553     data.WriteRemoteObject(object);
554     EXPECT_CALL(*mockAppMgrService_, UnregisterRenderStateObserver(_)).Times(1);
555     auto res = mockAppMgrService_->HandleUnregisterRenderStateObserver(data, reply);
556     EXPECT_EQ(res, NO_ERROR);
557 }
558 
559 /**
560  * @tc.name: HandleUpdateRenderState_0100
561  * @tc.desc: Test update render state success.
562  * @tc.type: FUNC
563  */
564 HWTEST_F(AppMgrStubTest, HandleUpdateRenderState_0100, TestSize.Level1)
565 {
566     MessageParcel data;
567     MessageParcel reply;
568     pid_t renderPid = 0;
569     data.WriteInt32(renderPid);
570     int32_t state = 0;
571     data.WriteInt32(state);
572     EXPECT_CALL(*mockAppMgrService_, UpdateRenderState(_, _)).Times(1);
573     auto res = mockAppMgrService_->HandleUpdateRenderState(data, reply);
574     EXPECT_EQ(res, NO_ERROR);
575 }
576 
577 /**
578  * @tc.name: HandleSignRestartAppFlag_0100
579  * @tc.desc: Test sign restart app flag success.
580  * @tc.type: FUNC
581  */
582 HWTEST_F(AppMgrStubTest, HandleSignRestartAppFlag_0100, TestSize.Level1)
583 {
584     MessageParcel data;
585     MessageParcel reply;
586     int32_t uid = 0;
587     data.WriteInt32(uid);
588     auto res = mockAppMgrService_->HandleSignRestartAppFlag(data, reply);
589     EXPECT_EQ(res, NO_ERROR);
590 }
591 
592 /**
593  * @tc.name: HandleNotifyMemorySizeStateChanged_0100
594  * @tc.desc: Test notify memory size state changed.
595  * @tc.type: FUNC
596  */
597 HWTEST_F(AppMgrStubTest, HandleNotifyMemorySizeStateChanged_0100, TestSize.Level1)
598 {
599     MessageParcel data;
600     MessageParcel reply;
601     data.WriteBool(true);
602     auto res = mockAppMgrService_->HandleNotifyMemorySizeStateChanged(data, reply);
603     EXPECT_EQ(res, NO_ERROR);
604 }
605 
606 /**
607  * @tc.name: HandleNotifyMemorySizeStateChanged_0200
608  * @tc.desc: Test notify memory size state changed.
609  * @tc.type: FUNC
610  */
611 HWTEST_F(AppMgrStubTest, HandleNotifyMemorySizeStateChanged_0200, TestSize.Level1)
612 {
613     MessageParcel data;
614     MessageParcel reply;
615     data.WriteBool(false);
616     auto res = mockAppMgrService_->HandleNotifyMemorySizeStateChanged(data, reply);
617     EXPECT_EQ(res, NO_ERROR);
618 }
619 
620 /**
621  * @tc.name: HandleGetAllUIExtensionRootHostPid_0100
622  * @tc.desc: Get all ui extension root host pid.
623  * @tc.type: FUNC
624  */
625 HWTEST_F(AppMgrStubTest, HandleGetAllUIExtensionRootHostPid_0100, TestSize.Level1)
626 {
627     MessageParcel data;
628     MessageParcel reply;
629     pid_t pid = 1;
630     data.WriteInt32(pid);
631     auto res = mockAppMgrService_->HandleGetAllUIExtensionRootHostPid(data, reply);
632     EXPECT_EQ(res, NO_ERROR);
633     int32_t size = reply.ReadInt32();
634     EXPECT_EQ(size, 0);
635 }
636 
637 /**
638  * @tc.name: HandleGetAllUIExtensionProviderPid_0100
639  * @tc.desc: Get all ui extension root host pid.
640  * @tc.type: FUNC
641  */
642 HWTEST_F(AppMgrStubTest, HandleGetAllUIExtensionProviderPid_0100, TestSize.Level1)
643 {
644     MessageParcel data;
645     MessageParcel reply;
646     pid_t hostPid = 1;
647     data.WriteInt32(hostPid);
648     auto res = mockAppMgrService_->HandleGetAllUIExtensionProviderPid(data, reply);
649     EXPECT_EQ(res, NO_ERROR);
650     int32_t size = reply.ReadInt32();
651     EXPECT_EQ(size, 0);
652 }
653 
654 /**
655  * @tc.name: PreloadApplication_0100
656  * @tc.desc: Preload application.
657  * @tc.type: FUNC
658  */
659 HWTEST_F(AppMgrStubTest, PreloadApplication_0100, TestSize.Level1)
660 {
661     MessageParcel data;
662     MessageParcel reply;
663     MessageOption option;
664 
665     WriteInterfaceToken(data);
666     std::string bundleName = "com.acts.preloadtest";
667     int32_t userId = 100;
668     PreloadMode preloadMode = PreloadMode::PRE_MAKE;
669     int32_t appIndex = 0;
670 
671     data.WriteString16(Str8ToStr16(bundleName));
672     data.WriteInt32(userId);
673     data.WriteInt32(static_cast<int32_t>(preloadMode));
674     data.WriteInt32(appIndex);
675 
676     auto result = mockAppMgrService_->OnRemoteRequest(
677         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION), data, reply, option);
678     EXPECT_EQ(result, NO_ERROR);
679 }
680 
681 /**
682  * @tc.name: PreloadModuleFinished_0100
683  * @tc.desc: Preload application.
684  * @tc.type: FUNC
685  */
686 HWTEST_F(AppMgrStubTest, PreloadModuleFinished_0100, TestSize.Level1)
687 {
688     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
689     MessageParcel data;
690     MessageParcel reply;
691     MessageOption option;
692 
693     int32_t recordId = 0;
694     data.WriteInt32(recordId);
695 
696     auto result = mockAppMgrService_->OnRemoteRequest(
697         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_MODULE_FINISHED), data, reply, option);
698     EXPECT_NE(result, NO_ERROR);
699     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
700 }
701 
702 /**
703  * @tc.name: SetSupportedProcessCacheSelf_001
704  * @tc.desc: The application sets itself whether or not to support process cache.
705  * @tc.type: FUNC
706  */
707 HWTEST_F(AppMgrStubTest, SetSupportedProcessCacheSelf_001, TestSize.Level1)
708 {
709     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
710     MessageParcel data;
711     MessageParcel reply;
712     MessageOption option;
713 
714     WriteInterfaceToken(data);
715     bool isSupported = false;
716     data.WriteBool(isSupported);
717 
718     EXPECT_CALL(*mockAppMgrService_, SetSupportedProcessCacheSelf(_)).Times(1);
719 
720     auto result = mockAppMgrService_->OnRemoteRequest(
721         static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF), data, reply, option);
722     EXPECT_EQ(result, NO_ERROR);
723 
724     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
725 }
726 
727 /**
728  * @tc.name: GetRunningMultiAppInfoByBundleName_001
729  * @tc.desc: Get multiapp information by bundleName.
730  * @tc.type: FUNC
731  * @tc.require: issueI9HMAO
732  */
733 HWTEST_F(AppMgrStubTest, GetRunningMultiAppInfoByBundleName_001, TestSize.Level1)
734 {
735     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
736     MessageParcel data;
737     MessageParcel reply;
738     MessageOption option;
739 
740     WriteInterfaceToken(data);
741     std::string bundleName = "testBundleName";
742     data.WriteString(bundleName);
743 
744     EXPECT_CALL(*mockAppMgrService_, GetRunningMultiAppInfoByBundleName(_, _)).Times(1);
745 
746     auto result = mockAppMgrService_->OnRemoteRequest(
747         static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME), data, reply, option);
748     EXPECT_EQ(result, NO_ERROR);
749 
750     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
751 }
752 
753 /**
754  * @tc.name: GetAllRunningInstanceKeysBySelf_001
755  * @tc.desc: GetAllRunningInstanceKeysBySelf.
756  * @tc.type: FUNC
757  * @tc.require: issueI9HMAO
758  */
759 HWTEST_F(AppMgrStubTest, GetAllRunningInstanceKeysBySelf_001, TestSize.Level1)
760 {
761     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
762     MessageParcel data;
763     MessageParcel reply;
764     MessageOption option;
765 
766     WriteInterfaceToken(data);
767 
768     EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysBySelf(_)).Times(1);
769 
770     auto result = mockAppMgrService_->OnRemoteRequest(
771         static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_SELF), data, reply, option);
772     EXPECT_EQ(result, NO_ERROR);
773 
774     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
775 }
776 
777 /**
778  * @tc.name: GetAllRunningInstanceKeysByBundleName_001
779  * @tc.desc: GetAllRunningInstanceKeysByBundleName.
780  * @tc.type: FUNC
781  * @tc.require: issueI9HMAO
782  */
783 HWTEST_F(AppMgrStubTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Level1)
784 {
785     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
786     MessageParcel data;
787     MessageParcel reply;
788     MessageOption option;
789 
790     WriteInterfaceToken(data);
791     std::string bundleName = "testBundleName";
792     data.WriteString(bundleName);
793     int32_t userId = -1;
794     data.WriteInt32(userId);
795 
796     EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1);
797 
798     auto result = mockAppMgrService_->OnRemoteRequest(
799         static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option);
800     EXPECT_EQ(result, NO_ERROR);
801 
802     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
803 }
804 
805 /**
806  * @tc.name: GetSupportedProcessCachePids_001
807  * @tc.desc: Get pids of processes which belong to specific bundle name and support process cache feature.
808  * @tc.type: FUNC
809  * @tc.require: issueIAGZ7H
810  */
811 HWTEST_F(AppMgrStubTest, GetSupportedProcessCachePids_001, TestSize.Level1)
812 {
813     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
814     MessageParcel data;
815     MessageParcel reply;
816     MessageOption option;
817 
818     WriteInterfaceToken(data);
819     std::string bundleName = "testBundleName";
820     data.WriteString(bundleName);
821 
822     EXPECT_CALL(*mockAppMgrService_, GetSupportedProcessCachePids(_, _)).Times(1);
823 
824     auto result = mockAppMgrService_->OnRemoteRequest(
825         static_cast<uint32_t>(AppMgrInterfaceCode::GET_SUPPORTED_PROCESS_CACHE_PIDS), data, reply, option);
826     EXPECT_EQ(result, NO_ERROR);
827 
828     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
829 }
830 
831 /**
832  * @tc.name: UpdateConfigurationForBackgroundApp_001
833  * @tc.desc: UpdateConfigurationForBackgroundApp.
834  * @tc.type: FUNC
835  * @tc.require:
836  */
837 HWTEST_F(AppMgrStubTest, UpdateConfigurationForBackgroundApp_001, TestSize.Level1)
838 {
839     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
840     MessageParcel data;
841     MessageParcel reply;
842     MessageOption option;
843 
844     WriteInterfaceToken(data);
845 
846     std::vector<BackgroundAppInfo> appInfos;
847     AppExecFwk::ConfigurationPolicy policy;
848     int32_t userId = -1;
849 
850     BackgroundAppInfo info;
851     appInfos.push_back(info);
852     auto size = appInfos.size();
853     data.WriteUint32(size);
854 
855     for (const auto &info: appInfos) {
856         data.WriteParcelable(&info);
857     }
858     data.WriteParcelable(&policy);
859     data.WriteInt32(userId);
860 
861     EXPECT_CALL(*mockAppMgrService_, UpdateConfigurationForBackgroundApp(_, _, _)).Times(1);
862 
863     auto result = mockAppMgrService_->OnRemoteRequest(
864         static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION_POLICY), data, reply, option);
865     EXPECT_EQ(result, NO_ERROR);
866 
867     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
868 }
869 
870 /**
871  * @tc.name: HandleIsProcessCacheSupported_0100
872  * @tc.desc: Test HandleIsProcessCacheSupported.
873  * @tc.type: FUNC
874  */
875 HWTEST_F(AppMgrStubTest, HandleIsProcessCacheSupported_0100, TestSize.Level1)
876 {
877     MessageParcel data;
878     MessageParcel reply;
879     MessageOption option;
880 
881     WriteInterfaceToken(data);
882     int32_t pid = 1;
883     bool isSupport = false;
884     data.WriteInt32(pid);
885     data.WriteBool(isSupport);
886 
887     EXPECT_CALL(*mockAppMgrService_, IsProcessCacheSupported(_, _)).Times(1);
888 
889     auto result = mockAppMgrService_->OnRemoteRequest(
890         static_cast<uint32_t>(AppMgrInterfaceCode::IS_PROCESS_CACHE_SUPPORTED), data, reply, option);
891     EXPECT_EQ(result, NO_ERROR);
892 }
893 
894 /**
895  * @tc.name: HandleSetProcessCacheEnable_0100
896  * @tc.desc: Test HandleSetProcessCacheEnable.
897  * @tc.type: FUNC
898  */
899 HWTEST_F(AppMgrStubTest, HandleSetProcessCacheEnable_0100, TestSize.Level1)
900 {
901     MessageParcel data;
902     MessageParcel reply;
903     MessageOption option;
904 
905     WriteInterfaceToken(data);
906     int32_t pid = 1;
907     bool enable = false;
908     data.WriteInt32(pid);
909     data.WriteBool(enable);
910 
911     EXPECT_CALL(*mockAppMgrService_, SetProcessCacheEnable(_, _)).Times(1);
912 
913     auto result = mockAppMgrService_->OnRemoteRequest(
914         static_cast<uint32_t>(AppMgrInterfaceCode::SET_PROCESS_CACHE_ENABLE), data, reply, option);
915     EXPECT_EQ(result, NO_ERROR);
916 }
917 
918 /**
919  * @tc.name: HandleQueryRunningSharedBundles_0100
920  * @tc.desc: Test HandleQueryRunningSharedBundles.
921  * @tc.type: FUNC
922  */
923 HWTEST_F(AppMgrStubTest, HandleQueryRunningSharedBundles_0100, TestSize.Level1)
924 {
925     TAG_LOGI(AAFwkTag::TEST, "HandleQueryRunningSharedBundles_0100 start.");
926     MessageParcel data;
927     MessageParcel reply;
928     MessageOption option;
929 
930     WriteInterfaceToken(data);
931     pid_t pid = 1;
932     bool enable = false;
933     data.WriteInt32(pid);
934     data.WriteBool(enable);
935 
936     EXPECT_CALL(*mockAppMgrService_, QueryRunningSharedBundles(_, _))
937         .Times(1)
938         .WillOnce(Return(ERR_INVALID_VALUE));
939 
940     auto ret = mockAppMgrService_->OnRemoteRequest(
941         static_cast<uint32_t>(AppMgrInterfaceCode::QUERY_RUNNING_SHARED_BUNDLES), data, reply, option);
942     EXPECT_EQ(ret, NO_ERROR);
943 
944     auto replyResult = reply.ReadInt32();
945     EXPECT_EQ(replyResult, ERR_INVALID_VALUE);
946     TAG_LOGI(AAFwkTag::TEST, "HandleQueryRunningSharedBundles_0100 end.");
947 }
948 
949 /**
950  * @tc.name: HandleQueryRunningSharedBundles_0200
951  * @tc.desc: Test HandleQueryRunningSharedBundles.
952  * @tc.type: FUNC
953  */
954 HWTEST_F(AppMgrStubTest, HandleQueryRunningSharedBundles_0200, TestSize.Level1)
955 {
956     TAG_LOGI(AAFwkTag::TEST, "HandleQueryRunningSharedBundles_0200 start.");
957     MessageParcel data;
958     MessageParcel reply;
959     MessageOption option;
960 
961     WriteInterfaceToken(data);
962     pid_t pid = 1;
963     bool enable = false;
964     data.WriteInt32(pid);
965     data.WriteBool(enable);
966 
967     EXPECT_CALL(*mockAppMgrService_, QueryRunningSharedBundles(_, _))
968         .Times(1)
969         .WillOnce(Return(ERR_OK));
970 
971     auto ret = mockAppMgrService_->OnRemoteRequest(
972         static_cast<uint32_t>(AppMgrInterfaceCode::QUERY_RUNNING_SHARED_BUNDLES), data, reply, option);
973     EXPECT_EQ(ret, NO_ERROR);
974 
975     auto replyResult = reply.ReadInt32();
976     EXPECT_EQ(replyResult, ERR_OK);
977     TAG_LOGI(AAFwkTag::TEST, "HandleQueryRunningSharedBundles_0200 end.");
978 }
979 } // namespace AppExecFwk
980 } // namespace OHOS
981