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_BUNDLE_MANAGER_H 17 #define MOCK_BUNDLE_MANAGER_H 18 19 #include <vector> 20 #include <gmock/gmock.h> 21 #include "bundlemgr/bundle_mgr_interface.h" 22 #include "iremote_proxy.h" 23 #include "iremote_stub.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 28 class BundleMgrProxy : public IRemoteProxy<IBundleMgr> { 29 public: BundleMgrProxy(const sptr<IRemoteObject> & impl)30 explicit BundleMgrProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IBundleMgr>(impl) 31 { 32 } ~BundleMgrProxy()33 virtual ~BundleMgrProxy() 34 { 35 } 36 ErrCode GetBundleInfoV9( 37 const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId) override; 38 bool GetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, 39 int32_t userId = Constants::UNSPECIFIED_USERID) override; 40 bool GetBundleInfo(const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, 41 int32_t userId = Constants::UNSPECIFIED_USERID) override; 42 bool GetBundleNameForUid(const int uid, std::string& bundleName) override; 43 bool ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault, 44 std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos, 45 bool &findDefaultApp) override; 46 }; 47 48 class BundleMgrStub : public IRemoteStub<IBundleMgr> { 49 public: 50 virtual int OnRemoteRequest( 51 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; 52 }; 53 54 class MocBundleMgrService : public BundleMgrStub { 55 public: MocBundleMgrService()56 MocBundleMgrService(){}; ~MocBundleMgrService()57 ~MocBundleMgrService(){}; 58 59 MOCK_METHOD(ErrCode, GetBundleInfoV9, 60 (const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId), (override)); 61 MOCK_METHOD(bool, GetBundleInfo, 62 (const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId), (override)); 63 MOCK_METHOD(bool, GetBundleInfo, 64 (const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId), (override)); 65 MOCK_METHOD(bool, GetBundleNameForUid, (const int uid, std::string& bundleName), (override)); 66 MOCK_METHOD(bool, ImplicitQueryInfos, 67 (const Want& want, int32_t flags, int32_t userId, bool withDefault, std::vector<AbilityInfo>& abilityInfos, 68 std::vector<ExtensionAbilityInfo>& extensionInfos, bool& findDefaultApp), 69 (override)); 70 }; 71 72 class BundleMgrService : public BundleMgrStub { 73 public: BundleMgrService()74 BundleMgrService(){}; ~BundleMgrService()75 ~BundleMgrService(){}; 76 77 ErrCode GetBundleInfoV9( 78 const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId) override; 79 bool GetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, 80 int32_t userId = Constants::UNSPECIFIED_USERID) override; 81 bool GetBundleInfo(const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, 82 int32_t userId = Constants::UNSPECIFIED_USERID) override; 83 bool GetBundleNameForUid(const int uid, std::string& bundleName) override; 84 bool ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault, 85 std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos, 86 bool &findDefaultApp) override; 87 std::shared_ptr<MocBundleMgrService> impl = nullptr; 88 }; 89 90 } // namespace AppExecFwk 91 } // namespace OHOS 92 #endif // MOCK_BUNDLE_MANAGER_H 93