1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MOCK_OHOS_EDM_MOCK_BUNDLE_MANAGER_H 17 #define MOCK_OHOS_EDM_MOCK_BUNDLE_MANAGER_H 18 19 #include <vector> 20 #include "gmock/gmock.h" 21 #include "bundle_info.h" 22 #include "want.h" 23 #include "iremote_proxy.h" 24 #include "iremote_stub.h" 25 #include "bundle_mgr_interface.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class BundleMgrProxy : public IRemoteProxy<IBundleMgr> { 30 public: BundleMgrProxy(const sptr<IRemoteObject> & impl)31 explicit BundleMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IBundleMgr>(impl) {} ~BundleMgrProxy()32 virtual ~BundleMgrProxy() {} 33 34 bool QueryExtensionAbilityInfos(const Want &want, const ExtensionAbilityType &extensionType, 35 const int32_t &flag, const int32_t &userId, std::vector<ExtensionAbilityInfo> &extensionInfos) override; 36 37 ErrCode GetNameForUid(const int uid, std::string &name) override; 38 39 bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, 40 BundleInfo &bundleInfo, int32_t userId) override; 41 private: 42 std::string bundleNameMock_; 43 }; 44 45 class BundleMgrStub : public IRemoteStub<IBundleMgr> { 46 public: 47 int OnRemoteRequest( 48 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 49 }; 50 51 class BundleMgrService : public BundleMgrStub { 52 public: 53 BundleMgrService(); 54 explicit BundleMgrService(const std::string &bundleNameMock); ~BundleMgrService()55 virtual ~BundleMgrService() {} 56 57 bool QueryExtensionAbilityInfos(const Want &want, const ExtensionAbilityType &extensionType, 58 const int32_t &flag, const int32_t &userId, std::vector<ExtensionAbilityInfo> &extensionInfos) override; 59 60 ErrCode GetNameForUid(const int uid, std::string &name) override; 61 62 bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, 63 BundleInfo &bundleInfo, int32_t userId) override; 64 private: 65 std::string bundleNameMock_; 66 }; 67 } // namespace AppExecFwk 68 } // namespace OHOS 69 70 #endif // MOCK_OHOS_EDM_MOCK_BUNDLE_MANAGER_H 71