• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 };
44 
45 class BundleMgrStub : public IRemoteStub<IBundleMgr> {
46 public:
47     virtual int OnRemoteRequest(
48         uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
49 };
50 
51 class MocBundleMgrService : public BundleMgrStub {
52 public:
MocBundleMgrService()53     MocBundleMgrService(){};
~MocBundleMgrService()54     ~MocBundleMgrService(){};
55 
56     MOCK_METHOD(ErrCode, GetBundleInfoV9,
57         (const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId), (override));
58     MOCK_METHOD(bool, GetBundleInfo,
59         (const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId), (override));
60     MOCK_METHOD(bool, GetBundleInfo,
61         (const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId), (override));
62     MOCK_METHOD(bool, GetBundleNameForUid, (const int uid, std::string& bundleName), (override));
63 };
64 
65 class BundleMgrService : public BundleMgrStub {
66 public:
BundleMgrService()67     BundleMgrService(){};
~BundleMgrService()68     ~BundleMgrService(){};
69 
70     ErrCode GetBundleInfoV9(
71         const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId) override;
72     bool GetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo,
73         int32_t userId = Constants::UNSPECIFIED_USERID) override;
74     bool GetBundleInfo(const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo,
75         int32_t userId = Constants::UNSPECIFIED_USERID) override;
76     bool GetBundleNameForUid(const int uid, std::string& bundleName) override;
77     std::shared_ptr<MocBundleMgrService> impl = nullptr;
78 };
79 
80 }  // namespace AppExecFwk
81 }  // namespace OHOS
82 #endif  // MOCK_BUNDLE_MANAGER_H
83