1 /* 2 * Copyright (c) 2022-2025 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_SERVICE_REVERSE_MOCK_H 17 #define MOCK_SERVICE_REVERSE_MOCK_H 18 19 #include <gmock/gmock.h> 20 21 #include "b_error/b_error.h" 22 #include "iservice_reverse.h" 23 #include "iremote_stub.h" 24 25 namespace OHOS::FileManagement::Backup { 26 class ServiceReverseMock : public IRemoteStub<IServiceReverse> { 27 public: 28 int code_ = 0; 29 bool restoreBundleStartCalled_ = false; 30 bool incRestoreBundleStartCalled_ = false; 31 bool backupOnBundleStartedCalled_ = false; ServiceReverseMock()32 ServiceReverseMock() : code_(0) {} ~ServiceReverseMock()33 virtual ~ServiceReverseMock() {} 34 35 MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); 36 InvokeSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)37 int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 38 { 39 code_ = code; 40 return BError(BError::Codes::OK); 41 } BackupOnFileReady(const std::string & bundleName,const std::string & fileName,int fd,int32_t errCode)42 ErrCode BackupOnFileReady(const std::string &bundleName, 43 const std::string &fileName, 44 int fd, 45 int32_t errCode) override 46 { 47 return BError(BError::Codes::OK); 48 } BackupOnFileReadyWithoutFd(const std::string & bundleName,const std::string & fileName,int32_t errCode)49 ErrCode BackupOnFileReadyWithoutFd(const std::string &bundleName, 50 const std::string &fileName, 51 int32_t errCode) override 52 { 53 return BError(BError::Codes::OK); 54 } 55 BackupOnBundleStarted(int32_t errCode,const std::string & bundleName)56 ErrCode BackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override 57 { 58 backupOnBundleStartedCalled_ = true; 59 return BError(BError::Codes::OK); 60 } 61 BackupOnResultReport(const std::string & result,const std::string & bundleName)62 ErrCode BackupOnResultReport(const std::string &result, const std::string &bundleName) override 63 { 64 return BError(BError::Codes::OK); 65 }; 66 BackupOnBundleFinished(int32_t errCode,const std::string & bundleName)67 ErrCode BackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override 68 { 69 return BError(BError::Codes::OK); 70 } 71 BackupOnAllBundlesFinished(int32_t errCode)72 ErrCode BackupOnAllBundlesFinished(int32_t errCode) override 73 { 74 return BError(BError::Codes::OK); 75 } 76 BackupOnProcessInfo(const std::string & bundleName,const std::string & processInfo)77 ErrCode BackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override 78 { 79 return BError(BError::Codes::OK); 80 } 81 BackupOnScanningInfo(const std::string & scannedInfo)82 ErrCode BackupOnScanningInfo(const std::string &scannedInfo) override 83 { 84 return BError(BError::Codes::OK); 85 } 86 RestoreOnBundleStarted(int32_t errCode,const std::string & bundleName)87 ErrCode RestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override 88 { 89 GTEST_LOG_(INFO) << "call RestoreOnBundleStarted"; 90 restoreBundleStartCalled_ = true; 91 return BError(BError::Codes::OK); 92 } 93 RestoreOnBundleFinished(int32_t errCode,const std::string & bundleName)94 ErrCode RestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override 95 { 96 return BError(BError::Codes::OK); 97 } 98 RestoreOnAllBundlesFinished(int32_t errCode)99 ErrCode RestoreOnAllBundlesFinished(int32_t errCode) override 100 { 101 return BError(BError::Codes::OK); 102 } 103 RestoreOnFileReady(const std::string & bundleName,const std::string & fileName,int fd,int32_t errCode)104 ErrCode RestoreOnFileReady(const std::string &bundleName, 105 const std::string &fileName, 106 int fd, 107 int32_t errCode) override 108 { 109 return BError(BError::Codes::OK); 110 } 111 RestoreOnFileReadyWithoutFd(const std::string & bundleName,const std::string & fileName,int32_t errCode)112 ErrCode RestoreOnFileReadyWithoutFd(const std::string &bundleName, 113 const std::string &fileName, 114 int32_t errCode) override 115 { 116 return BError(BError::Codes::OK); 117 } 118 RestoreOnResultReport(const std::string & result,const std::string & bundleName,ErrCode errCode)119 ErrCode RestoreOnResultReport(const std::string &result, const std::string &bundleName, ErrCode errCode) override 120 { 121 return BError(BError::Codes::OK); 122 } 123 RestoreOnProcessInfo(const std::string & bundleName,const std::string & processInfo)124 ErrCode RestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override 125 { 126 return BError(BError::Codes::OK); 127 } 128 IncrementalBackupOnFileReady(const std::string & bundleName,const std::string & fileName,int fd,int manifestFd,int32_t errCode)129 ErrCode IncrementalBackupOnFileReady(const std::string &bundleName, 130 const std::string &fileName, 131 int fd, 132 int manifestFd, 133 int32_t errCode) override 134 { 135 return BError(BError::Codes::OK); 136 } 137 IncrementalSaBackupOnFileReady(const std::string & bundleName,const std::string & fileName,int fd,int32_t errCode)138 ErrCode IncrementalSaBackupOnFileReady(const std::string &bundleName, 139 const std::string &fileName, 140 int fd, 141 int32_t errCode) override 142 { 143 return BError(BError::Codes::OK); 144 } 145 IncrementalBackupOnFileReadyWithoutFd(const std::string & bundleName,const std::string & fileName,int32_t errCode)146 ErrCode IncrementalBackupOnFileReadyWithoutFd(const std::string &bundleName, 147 const std::string &fileName, 148 int32_t errCode) override 149 { 150 return BError(BError::Codes::OK); 151 } 152 IncrementalBackupOnBundleStarted(int32_t errCode,const std::string & bundleName)153 ErrCode IncrementalBackupOnBundleStarted(int32_t errCode, const std::string &bundleName) override 154 { 155 return BError(BError::Codes::OK); 156 } 157 IncrementalBackupOnResultReport(const std::string & result,const std::string & bundleName)158 ErrCode IncrementalBackupOnResultReport(const std::string &result, const std::string &bundleName) override 159 { 160 return BError(BError::Codes::OK); 161 } 162 IncrementalBackupOnBundleFinished(int32_t errCode,const std::string & bundleName)163 ErrCode IncrementalBackupOnBundleFinished(int32_t errCode, const std::string &bundleName) override 164 { 165 return BError(BError::Codes::OK); 166 } 167 IncrementalBackupOnAllBundlesFinished(int32_t errCode)168 ErrCode IncrementalBackupOnAllBundlesFinished(int32_t errCode) override 169 { 170 return BError(BError::Codes::OK); 171 } 172 IncrementalBackupOnProcessInfo(const std::string & bundleName,const std::string & processInfo)173 ErrCode IncrementalBackupOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override 174 { 175 return BError(BError::Codes::OK); 176 } 177 IncrementalBackupOnScanningInfo(const std::string & scannedInfo)178 ErrCode IncrementalBackupOnScanningInfo(const std::string &scannedInfo) override 179 { 180 return BError(BError::Codes::OK); 181 } 182 IncrementalRestoreOnBundleStarted(int32_t errCode,const std::string & bundleName)183 ErrCode IncrementalRestoreOnBundleStarted(int32_t errCode, const std::string &bundleName) override 184 { 185 GTEST_LOG_(INFO) << "call IncrementalRestoreOnBundleStarted"; 186 incRestoreBundleStartCalled_ = true; 187 return BError(BError::Codes::OK); 188 } 189 IncrementalRestoreOnBundleFinished(int32_t errCode,const std::string & bundleName)190 ErrCode IncrementalRestoreOnBundleFinished(int32_t errCode, const std::string &bundleName) override 191 { 192 return BError(BError::Codes::OK); 193 } 194 IncrementalRestoreOnAllBundlesFinished(int32_t errCode)195 ErrCode IncrementalRestoreOnAllBundlesFinished(int32_t errCode) override 196 { 197 return BError(BError::Codes::OK); 198 } 199 IncrementalRestoreOnFileReady(const std::string & bundleName,const std::string & fileName,int fd,int manifestFd,int32_t errCode)200 ErrCode IncrementalRestoreOnFileReady(const std::string &bundleName, 201 const std::string &fileName, 202 int fd, 203 int manifestFd, 204 int32_t errCode) override 205 { 206 return BError(BError::Codes::OK); 207 } 208 IncrementalRestoreOnFileReadyWithoutFd(const std::string & bundleName,const std::string & fileName,int32_t errCode)209 ErrCode IncrementalRestoreOnFileReadyWithoutFd(const std::string &bundleName, 210 const std::string &fileName, 211 int32_t errCode) override 212 { 213 return BError(BError::Codes::OK); 214 } 215 IncrementalRestoreOnResultReport(const std::string & result,const std::string & bundleName,int32_t errCode)216 ErrCode IncrementalRestoreOnResultReport(const std::string &result, 217 const std::string &bundleName, 218 int32_t errCode) override 219 { 220 return BError(BError::Codes::OK); 221 } 222 IncrementalRestoreOnProcessInfo(const std::string & bundleName,const std::string & processInfo)223 ErrCode IncrementalRestoreOnProcessInfo(const std::string &bundleName, const std::string &processInfo) override 224 { 225 return BError(BError::Codes::OK); 226 } 227 }; 228 } // namespace OHOS::FileManagement::Backup 229 #endif // MOCK_SERVICE_REVERSE_MOCK_H