1 /* 2 * Copyright (c) 2022-2024 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_I_SERVICE_MOCK_H 17 #define MOCK_I_SERVICE_MOCK_H 18 19 #include <fcntl.h> 20 #include <gmock/gmock.h> 21 #include <sys/stat.h> 22 #include <sys/types.h> 23 24 #include "b_error/b_error.h" 25 #include "i_service.h" 26 #include "b_resources/b_constants.h" 27 #include "iremote_stub.h" 28 #include "test_manager.h" 29 30 namespace OHOS::FileManagement::Backup { 31 class IServiceMock : public IRemoteStub<IService> { 32 public: 33 int code_ = 0; IServiceMock()34 IServiceMock() : code_(0) {} ~IServiceMock()35 virtual ~IServiceMock() {} 36 37 MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); 38 InvokeSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 40 { 41 code_ = code; 42 reply.WriteInt32(BError(BError::Codes::OK)); 43 return BError(BError::Codes::OK); 44 } 45 InvokeMsgSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int32_t InvokeMsgSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 47 { 48 code_ = code; 49 reply.WriteString(""); 50 reply.WriteInt32(BError(BError::Codes::OK)); 51 return BError(BError::Codes::OK); 52 } 53 InvokeGetLocalSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)54 int32_t InvokeGetLocalSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 55 { 56 code_ = code; 57 std::string fileName = "1.tar"; 58 TestManager tm("GetLocalCap_GetFd_0100"); 59 std::string filePath = tm.GetRootDirCurTest().append(fileName); 60 UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); 61 reply.WriteFileDescriptor(fd); 62 return BError(BError::Codes::OK); 63 } 64 InitRestoreSession(sptr<IServiceReverse> remote)65 ErrCode InitRestoreSession(sptr<IServiceReverse> remote) override 66 { 67 return BError(BError::Codes::OK); 68 } 69 InitRestoreSession(sptr<IServiceReverse> remote,std::string & errMsg)70 ErrCode InitRestoreSession(sptr<IServiceReverse> remote, std::string &errMsg) override 71 { 72 return BError(BError::Codes::OK); 73 } 74 InitBackupSession(sptr<IServiceReverse> remote)75 ErrCode InitBackupSession(sptr<IServiceReverse> remote) override 76 { 77 return BError(BError::Codes::OK); 78 } 79 InitBackupSession(sptr<IServiceReverse> remote,std::string & errMsg)80 ErrCode InitBackupSession(sptr<IServiceReverse> remote, std::string &errMsg) override 81 { 82 return BError(BError::Codes::OK); 83 } 84 Start()85 ErrCode Start() override 86 { 87 return BError(BError::Codes::OK); 88 } 89 GetLocalCapabilities()90 UniqueFd GetLocalCapabilities() override 91 { 92 return UniqueFd(-1); 93 } 94 GetLocalCapabilitiesForBundleInfos()95 UniqueFd GetLocalCapabilitiesForBundleInfos() override 96 { 97 return UniqueFd(-1); 98 } 99 PublishFile(const BFileInfo & fileInfo)100 ErrCode PublishFile(const BFileInfo &fileInfo) override 101 { 102 return BError(BError::Codes::OK); 103 } 104 AppFileReady(const std::string & fileName,UniqueFd fd,int32_t errCode)105 ErrCode AppFileReady(const std::string &fileName, UniqueFd fd, int32_t errCode) override 106 { 107 return BError(BError::Codes::OK); 108 } 109 AppDone(ErrCode errCode)110 ErrCode AppDone(ErrCode errCode) override 111 { 112 return BError(BError::Codes::OK); 113 } 114 ServiceResultReport(const std::string restoreRetInfo,BackupRestoreScenario scenario,ErrCode errCode)115 ErrCode ServiceResultReport(const std::string restoreRetInfo, 116 BackupRestoreScenario scenario, ErrCode errCode) override 117 { 118 return BError(BError::Codes::OK); 119 } 120 GetFileHandle(const std::string & bundleName,const std::string & fileName)121 ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override 122 { 123 return BError(BError::Codes::OK); 124 } 125 AppendBundlesRestoreSession(UniqueFd fd,const std::vector<BundleName> & bundleNames,const std::vector<std::string> & detailInfos,RestoreTypeEnum restoreType,int32_t userId)126 ErrCode AppendBundlesRestoreSession(UniqueFd fd, 127 const std::vector<BundleName> &bundleNames, 128 const std::vector<std::string> &detailInfos, 129 RestoreTypeEnum restoreType, 130 int32_t userId) override 131 { 132 return BError(BError::Codes::OK); 133 } 134 AppendBundlesRestoreSession(UniqueFd fd,const std::vector<BundleName> & bundleNames,RestoreTypeEnum restoreType,int32_t userId)135 ErrCode AppendBundlesRestoreSession(UniqueFd fd, 136 const std::vector<BundleName> &bundleNames, 137 RestoreTypeEnum restoreType, 138 int32_t userId) override 139 { 140 return BError(BError::Codes::OK); 141 } 142 AppendBundlesBackupSession(const std::vector<BundleName> & bundleNames)143 ErrCode AppendBundlesBackupSession(const std::vector<BundleName> &bundleNames) override 144 { 145 return BError(BError::Codes::OK); 146 } 147 AppendBundlesDetailsBackupSession(const std::vector<BundleName> & bundleNames,const std::vector<std::string> & bundleInfos)148 ErrCode AppendBundlesDetailsBackupSession(const std::vector<BundleName> &bundleNames, 149 const std::vector<std::string> &bundleInfos) override 150 { 151 return BError(BError::Codes::OK); 152 } 153 Finish()154 ErrCode Finish() override 155 { 156 return BError(BError::Codes::OK); 157 } 158 GetBackupInfo(BundleName & bundleName,std::string & result)159 ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override 160 { 161 return BError(BError::Codes::OK); 162 } 163 UpdateTimer(BundleName & bundleName,uint32_t timeout,bool & result)164 ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) override 165 { 166 return BError(BError::Codes::OK); 167 } 168 StartExtTimer(bool & isExtStart)169 ErrCode StartExtTimer(bool &isExtStart) override 170 { 171 return BError(BError::Codes::OK); 172 } 173 StartFwkTimer(bool & isFwkStart)174 ErrCode StartFwkTimer(bool &isFwkStart) override 175 { 176 return BError(BError::Codes::OK); 177 } 178 StopExtTimer(bool & isExtStop)179 ErrCode StopExtTimer(bool &isExtStop) override 180 { 181 return BError(BError::Codes::OK); 182 } 183 RefreshDataSize(int64_t totalsize)184 ErrCode RefreshDataSize(int64_t totalsize) override 185 { 186 return BError(BError::Codes::OK); 187 } 188 UpdateSendRate(std::string & bundleName,int32_t sendRate,bool & result)189 ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override 190 { 191 return BError(BError::Codes::OK); 192 } 193 Release()194 ErrCode Release() override 195 { 196 return BError(BError::Codes::OK); 197 } 198 Cancel(std::string bundleName,int32_t & result)199 ErrCode Cancel(std::string bundleName, int32_t &result) override 200 { 201 result = BError(BError::Codes::OK); 202 return BError(BError::Codes::OK); 203 } 204 GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> & bundleNames)205 UniqueFd GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> &bundleNames) override 206 { 207 return UniqueFd(-1); 208 } 209 GetAppLocalListAndDoIncrementalBackup()210 ErrCode GetAppLocalListAndDoIncrementalBackup() override 211 { 212 return BError(BError::Codes::OK); 213 } 214 InitIncrementalBackupSession(sptr<IServiceReverse> remote)215 ErrCode InitIncrementalBackupSession(sptr<IServiceReverse> remote) override 216 { 217 return BError(BError::Codes::OK); 218 } 219 InitIncrementalBackupSession(sptr<IServiceReverse> remote,std::string & errMsg)220 ErrCode InitIncrementalBackupSession(sptr<IServiceReverse> remote, std::string &errMsg) override 221 { 222 return BError(BError::Codes::OK); 223 } 224 AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> & bundlesToBackup)225 ErrCode AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> &bundlesToBackup) override 226 { 227 return BError(BError::Codes::OK); 228 } 229 AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> & bundlesToBackup,const std::vector<std::string> & infos)230 ErrCode AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> &bundlesToBackup, 231 const std::vector<std::string> &infos) override 232 { 233 return BError(BError::Codes::OK); 234 } 235 PublishIncrementalFile(const BFileInfo & fileInfo)236 ErrCode PublishIncrementalFile(const BFileInfo &fileInfo) override 237 { 238 return BError(BError::Codes::OK); 239 } 240 PublishSAIncrementalFile(const BFileInfo & fileInfo,UniqueFd fd)241 ErrCode PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) override 242 { 243 return BError(BError::Codes::OK); 244 } 245 AppIncrementalFileReady(const std::string & fileName,UniqueFd fd,UniqueFd manifestFd,int32_t errCode)246 ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode) 247 { 248 return BError(BError::Codes::OK); 249 } 250 AppIncrementalDone(ErrCode errCode)251 ErrCode AppIncrementalDone(ErrCode errCode) 252 { 253 return BError(BError::Codes::OK); 254 } 255 GetIncrementalFileHandle(const std::string & bundleName,const std::string & fileName)256 ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) 257 { 258 return BError(BError::Codes::OK); 259 } 260 ReportAppProcessInfo(const std::string processInfo,const BackupRestoreScenario sennario)261 ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) 262 { 263 return BError(BError::Codes::OK); 264 } 265 GetBackupDataSize(bool isPreciseScan,std::vector<BIncrementalData> bundleNameList)266 ErrCode GetBackupDataSize(bool isPreciseScan, std::vector<BIncrementalData> bundleNameList) 267 { 268 return BError(BError::Codes::OK); 269 } 270 }; 271 } // namespace OHOS::FileManagement::Backup 272 #endif // MOCK_I_SERVICE_MOCK_H