1 /* 2 * Copyright (c) 2021 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 #ifndef FOUNDATION_APPEXECFWK_KITS_APPKIT_TEST_MOCK_ABILITY_MGR_SERVICE_H 17 #define FOUNDATION_APPEXECFWK_KITS_APPKIT_TEST_MOCK_ABILITY_MGR_SERVICE_H 18 19 #include "gmock/gmock.h" 20 #include "semaphore_ex.h" 21 #include "ability_manager_stub.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 class MockAbilityMgrService : public AbilityManagerStub { 26 public: 27 MOCK_METHOD2(StartAbility, int(const Want &want, int requestCode)); 28 MOCK_METHOD3(StartAbility, int(const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode)); 29 MOCK_METHOD3(TerminateAbility, int(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)); 30 MOCK_METHOD3(ConnectAbility, 31 int(const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken)); 32 MOCK_METHOD1(DisconnectAbility, int(const sptr<IAbilityConnection> &connect)); 33 MOCK_METHOD3(AcquireDataAbility, sptr<IAbilityScheduler>(const Uri &, bool, const sptr<IRemoteObject> &)); 34 MOCK_METHOD2(ReleaseDataAbility, int(sptr<IAbilityScheduler>, const sptr<IRemoteObject> &)); 35 MOCK_METHOD2(AddWindowInfo, void(const sptr<IRemoteObject> &token, int32_t windowToken)); 36 MOCK_METHOD2(AttachAbilityThread, int(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token)); 37 MOCK_METHOD2(AbilityTransitionDone, int(const sptr<IRemoteObject> &token, int state)); 38 MOCK_METHOD2( 39 ScheduleConnectAbilityDone, int(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject)); 40 MOCK_METHOD1(ScheduleDisconnectAbilityDone, int(const sptr<IRemoteObject> &token)); 41 MOCK_METHOD1(ScheduleCommandAbilityDone, int(const sptr<IRemoteObject> &token)); DumpState(const std::string & args,std::vector<std::string> & state)42 void DumpState(const std::string &args, std::vector<std::string> &state) 43 { 44 GTEST_LOG_(INFO) << "MockAbilityMgrService::DumpState called"; 45 DumpStateCalled_ = true; 46 EXPECT_TRUE(DumpStateCalled_); 47 return; 48 } 49 MOCK_METHOD2(TerminateAbilityResult, int(const sptr<IRemoteObject> &, int startId)); 50 MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr<IRemoteObject> &callerToken, int requestCode)); 51 MOCK_METHOD1(StopServiceAbility, int(const Want &)); 52 MOCK_METHOD1(GetAllStackInfo, int(StackInfo &stackInfo)); 53 MOCK_METHOD3(GetRecentMissions, int(const int32_t, const int32_t, std::vector<AbilityMissionInfo> &)); 54 MOCK_METHOD2(GetMissionSnapshot, int(const int32_t, MissionSnapshotInfo &)); 55 MOCK_METHOD1(RemoveMission, int(int)); 56 MOCK_METHOD1(RemoveStack, int(int)); 57 MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); 58 59 MOCK_METHOD1(MoveMissionToTop, int(int32_t)); 60 MOCK_METHOD1(KillProcess, int(const std::string &bundleName)); 61 MOCK_METHOD1(UninstallApp, int(const std::string &bundleName)); 62 MOCK_METHOD1(TerminateAbilityByRecordId, int(const int64_t recordId)); 63 Wait()64 void Wait() 65 { 66 sem_.Wait(); 67 } 68 Post()69 int Post() 70 { 71 sem_.Post(); 72 return 0; 73 } 74 PostVoid()75 void PostVoid() 76 { 77 sem_.Post(); 78 } 79 80 private: 81 bool DumpStateCalled_ = false; 82 Semaphore sem_; 83 }; 84 85 } // namespace AAFwk 86 } // namespace OHOS 87 #endif // FOUNDATION_APPEXECFWK_KITS_APPKIT_TEST_MOCK_ABILITY_MGR_SERVICE_H