/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_FORM_FWK_MOCK_BUNDLE_MANAGER_H #define OHOS_FORM_FWK_MOCK_BUNDLE_MANAGER_H #include #include "ability_info.h" #include "application_info.h" #include "bundle_mgr_interface.h" #include "gmock/gmock.h" #include "iremote_proxy.h" #include "iremote_stub.h" #include "want.h" namespace OHOS { namespace AppExecFwk { const int32_t APP_600 = 600; const uint32_t COMPATIBLE_VERSION = 1; const uint32_t TARGET_VERSION = 1; class BundleMgrProxy : public IRemoteProxy { public: explicit BundleMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} virtual ~BundleMgrProxy() {} MOCK_METHOD5(QueryAbilityInfo, bool(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo, const sptr &callBack)); bool QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) override { return true; } std::string GetAppType(const std::string &bundleName) override { return "system"; } virtual int GetUidByBundleName(const std::string &bundleName, const int userId) override { if (bundleName.compare("com.form.host.app600") == 0) { return APP_600; } return 0; } virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override { bundleName = "com.form.provider.service"; return true; } virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfo) override; virtual bool GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName, std::vector &formInfo) override; }; class BundleMgrStub : public IRemoteStub { public: virtual int OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; class BundleMgrService : public BundleMgrStub { public: static bool IsSystemApp; bool QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) override; MOCK_METHOD5(QueryAbilityInfo, bool(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo, const sptr &callBack)); virtual int GetUidByBundleName(const std::string &bundleName, const int userId) override; virtual bool GetBundleInfo( const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId) override; virtual ErrCode GetBundleInfoV9(const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId) override; virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override { bundleName = "com.form.provider.service"; return true; }; virtual std::string GetAppType(const std::string &bundleName); virtual bool CheckIsSystemAppByUid(const int uid) override { return IsSystemApp; } virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfo) override; virtual bool GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName, std::vector &formInfo) override; virtual bool ImplicitQueryInfoByPriority(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo, ExtensionAbilityInfo &extensionInfo) override { abilityInfo.name = "MainAbility"; abilityInfo.bundleName = "com.ohos.launcher"; extensionInfo.name = "MainAbility"; extensionInfo.bundleName = "com.ohos.launcher"; return true; } MOCK_METHOD3(SetModuleRemovable, bool(const std::string &bundleName, const std::string &moduleName, bool isEnable)); MOCK_METHOD2(GetNameForUid, int32_t(const int, std::string &)); }; class MockBundleMgrService : public BundleMgrService { public: MOCK_METHOD(bool, GetBundleInfo, (const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId), (override)); MOCK_METHOD(ErrCode, GetBundleInfoV9, (const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId), (override)); MOCK_METHOD(ErrCode, GetApplicationInfoV9, (const std::string &, int32_t, int32_t, ApplicationInfo &), (override)); MOCK_METHOD2(GetBundleNameForUid, bool(const int, std::string &)); MOCK_METHOD1(CheckIsSystemAppByUid, bool(const int)); MOCK_METHOD2(GetNameForUid, int32_t(const int, std::string &)); }; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_FORM_FWK_MOCK_BUNDLE_MANAGER_H