• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License") = 0;
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 OHOS_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H
17 #define OHOS_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H
18 
19 #include <gmock/gmock.h>
20 
21 #include "module_ipc/svc_session_manager.h"
22 
23 namespace OHOS::FileManagement::Backup {
24 class BSvcSessionManager {
25 public:
26     virtual ErrCode Active(struct SvcSessionManager::Impl, bool) = 0;
27     virtual sptr<IServiceReverse> GetServiceReverseProxy() = 0;
28     virtual IServiceReverseType::Scenario GetScenario() = 0;
29     virtual int32_t GetSessionUserId() = 0;
30     virtual std::string GetSessionCallerName() = 0;
31     virtual std::string GetSessionActiveTime() = 0;
32     virtual bool OnBundleFileReady(const std::string&, const std::string&) = 0;
33     virtual UniqueFd OnBundleExtManageInfo(const std::string&, UniqueFd) = 0;
34     virtual wptr<SvcBackupConnection> GetExtConnection(const BundleName&) = 0;
35     virtual std::weak_ptr<SABackupConnection> GetSAExtConnection(const BundleName&) = 0;
36     virtual std::set<std::string> GetExtFileNameRequest(const std::string&) = 0;
37     virtual BConstants::ServiceSchedAction GetServiceSchedAction(const std::string&) = 0;
38     virtual bool GetSchedBundleName(std::string&) = 0;
39     virtual std::string GetBackupExtName(const std::string&) = 0;
40     virtual std::string GetBackupExtInfo(const std::string&) = 0;
41     virtual sptr<SvcBackupConnection> CreateBackupConnection(const BundleName&) = 0;
42     virtual bool IsOnAllBundlesFinished() = 0;
43     virtual bool IsOnOnStartSched() = 0;
44     virtual bool NeedToUnloadService() = 0;
45     virtual RestoreTypeEnum GetBundleRestoreType(const std::string&) = 0;
46     virtual int64_t GetBundleVersionCode(const std::string&) = 0;
47     virtual std::string GetBundleVersionName(const std::string&) = 0;
48     virtual bool StartFwkTimer(const std::string&, const Utils::Timer::TimerCallback&) = 0;
49     virtual bool StopFwkTimer(const std::string&) = 0;
50     virtual bool StartExtTimer(const std::string&, const Utils::Timer::TimerCallback&) = 0;
51     virtual bool StopExtTimer(const std::string&) = 0;
52     virtual bool UpdateTimer(const std::string&, uint32_t, const Utils::Timer::TimerCallback&) = 0;
53     virtual bool GetIsIncrementalBackup() = 0;
54     virtual int32_t GetIncrementalManifestFd(const std::string&) = 0;
55     virtual int64_t GetLastIncrementalTime(const std::string&) = 0;
56     virtual int32_t GetMemParaCurSize() = 0;
57     virtual bool ValidRestoreDataType(RestoreTypeEnum) = 0;
58     virtual uint32_t GetTimeoutValue(const std::string &) = 0;
59     virtual bool GetClearDataFlag(const std::string&) = 0;
60     virtual bool CleanAndCheckIfNeedWait(ErrCode &, std::vector<std::string> &) = 0;
61     virtual ErrCode ClearSessionData() = 0;
62     virtual int GetSessionCnt() = 0;
63     virtual SvcSessionManager::Impl GetImpl() = 0;
64     virtual std::string GetOldBackupVersion() = 0;
65     virtual void UpdateDfxInfo(const BundleName &bundleName, uint64_t uniqId) = 0;
66     virtual void HandleOnRelease(sptr<IExtension> proxy) = 0;
67     virtual void SetIsRestoreEnd(const std::string &bundleName) = 0;
68     virtual bool GetIsRestoreEnd(const std::string &bundleName) = 0;
69 public:
70     BSvcSessionManager() = default;
71     virtual ~BSvcSessionManager() = default;
72 public:
73     static inline std::shared_ptr<BSvcSessionManager> sessionManager = nullptr;
74 };
75 
76 class SvcSessionManagerMock : public BSvcSessionManager {
77 public:
78     MOCK_METHOD(ErrCode, Active, (struct SvcSessionManager::Impl, bool));
79     MOCK_METHOD((sptr<IServiceReverse>), GetServiceReverseProxy, ());
80     MOCK_METHOD(IServiceReverseType::Scenario, GetScenario, ());
81     MOCK_METHOD(int32_t, GetSessionUserId, ());
82     MOCK_METHOD(std::string, GetSessionCallerName, ());
83     MOCK_METHOD(std::string, GetSessionActiveTime, ());
84     MOCK_METHOD(bool, OnBundleFileReady, (const std::string&, const std::string&));
85     MOCK_METHOD(UniqueFd, OnBundleExtManageInfo, (const std::string&, UniqueFd));
86     MOCK_METHOD((wptr<SvcBackupConnection>), GetExtConnection, (const BundleName&));
87     MOCK_METHOD((std::weak_ptr<SABackupConnection>), GetSAExtConnection, (const BundleName&));
88     MOCK_METHOD((std::set<std::string>), GetExtFileNameRequest, (const std::string&));
89     MOCK_METHOD(BConstants::ServiceSchedAction, GetServiceSchedAction, (const std::string&));
90     MOCK_METHOD(bool, GetSchedBundleName, (std::string&));
91     MOCK_METHOD(std::string, GetBackupExtName, (const std::string&));
92     MOCK_METHOD(std::string, GetBackupExtInfo, (const std::string&));
93     MOCK_METHOD(sptr<SvcBackupConnection>, CreateBackupConnection, (const BundleName&));
94     MOCK_METHOD(bool, IsOnAllBundlesFinished, ());
95     MOCK_METHOD(bool, IsOnOnStartSched, ());
96     MOCK_METHOD(bool, NeedToUnloadService, ());
97     MOCK_METHOD(RestoreTypeEnum, GetBundleRestoreType, (const std::string&));
98     MOCK_METHOD(int64_t, GetBundleVersionCode, (const std::string&));
99     MOCK_METHOD(std::string, GetBundleVersionName, (const std::string&));
100     MOCK_METHOD(bool, StartFwkTimer, (const std::string&, const Utils::Timer::TimerCallback&));
101     MOCK_METHOD(bool, StopFwkTimer, (const std::string&));
102     MOCK_METHOD(bool, StartExtTimer, (const std::string&, const Utils::Timer::TimerCallback&));
103     MOCK_METHOD(bool, StopExtTimer, (const std::string&));
104     MOCK_METHOD(bool, UpdateTimer, (const std::string&, uint32_t, const Utils::Timer::TimerCallback&));
105     MOCK_METHOD(bool, GetIsIncrementalBackup, ());
106     MOCK_METHOD(int32_t, GetIncrementalManifestFd, (const std::string&));
107     MOCK_METHOD(int64_t, GetLastIncrementalTime, (const std::string&));
108     MOCK_METHOD(int32_t, GetMemParaCurSize, ());
109     MOCK_METHOD(bool, ValidRestoreDataType, (RestoreTypeEnum));
110     MOCK_METHOD(uint32_t, GetTimeoutValue, (const std::string &));
111     MOCK_METHOD(bool, GetClearDataFlag, (const std::string&));
112     MOCK_METHOD(bool, CleanAndCheckIfNeedWait, (ErrCode &, std::vector<std::string> &));
113     MOCK_METHOD(ErrCode, ClearSessionData, ());
114     MOCK_METHOD(int, GetSessionCnt, ());
115     MOCK_METHOD(SvcSessionManager::Impl, GetImpl, ());
116     MOCK_METHOD(std::string, GetOldBackupVersion, ());
117     MOCK_METHOD(void, UpdateDfxInfo, (const std::string &, uint64_t));
118     MOCK_METHOD(void, HandleOnRelease, (sptr<IExtension>));
119     MOCK_METHOD(void, SetIsRestoreEnd, (const std::string &));
120     MOCK_METHOD(bool, GetIsRestoreEnd, (const std::string &));
121 };
122 } // namespace OHOS::FileManagement::Backup
123 #endif // OHOS_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H
124