From 5fa876da039cff191737ade96059b0a218e8bbd6 Mon Sep 17 00:00:00 2001 From: wangpggg Date: Thu, 15 Aug 2024 17:57:40 +0800 Subject: [PATCH] add ut Signed-off-by: wangpeng --- .../backup_ext/include/ext_backup_js_mock.h | 91 +++ .../backup_ext/include/ext_extension_mock.h | 125 ++++ .../include/ext_extension_stub_mock.h | 41 ++ .../mock/backup_ext/include/js_runtime_mock.h | 52 ++ .../backup_ext/src/ext_backup_js_mock.cpp | 101 ++++ .../backup_ext/src/ext_extension_mock.cpp | 220 +++++++ .../src/ext_extension_stub_mock.cpp | 28 + .../include/bms_adapter_mock.h | 56 ++ .../include/sms_adapter_mock.h | 47 ++ .../module_external/src/bms_adapter_mock.cpp | 57 ++ .../module_external/src/sms_adapter_mock.cpp | 43 ++ .../include/sa_backup_connection_mock.h | 57 ++ .../module_ipc/include/service_stub_mock.h | 98 ++++ .../include/svc_backup_connection_mock.h | 45 ++ .../include/svc_extension_proxy_mock.h | 42 ++ .../include/svc_session_manager_mock.h | 89 +++ .../src/sa_backup_connection_mock.cpp | 74 +++ .../mock/module_ipc/src/service_stub_mock.cpp | 159 +++++ .../src/svc_backup_connection_mock.cpp | 50 ++ .../src/svc_session_manager_mock.cpp | 213 +++++++ .../utils_mock/include/backup_para_mock.h | 43 ++ .../mock/utils_mock/src/backup_para_mock.cpp | 41 ++ tests/unittests/backup_sa/module_ipc/BUILD.gn | 69 +++ .../module_ipc/service_incremental_test.cpp | 543 ++++++++++++++++++ 24 files changed, 2384 insertions(+) create mode 100644 tests/mock/backup_ext/include/ext_backup_js_mock.h create mode 100644 tests/mock/backup_ext/include/ext_extension_mock.h create mode 100644 tests/mock/backup_ext/include/ext_extension_stub_mock.h create mode 100644 tests/mock/backup_ext/include/js_runtime_mock.h create mode 100644 tests/mock/backup_ext/src/ext_backup_js_mock.cpp create mode 100644 tests/mock/backup_ext/src/ext_extension_mock.cpp create mode 100644 tests/mock/backup_ext/src/ext_extension_stub_mock.cpp create mode 100644 tests/mock/module_external/include/bms_adapter_mock.h create mode 100644 tests/mock/module_external/include/sms_adapter_mock.h create mode 100644 tests/mock/module_external/src/bms_adapter_mock.cpp create mode 100644 tests/mock/module_external/src/sms_adapter_mock.cpp create mode 100644 tests/mock/module_ipc/include/sa_backup_connection_mock.h create mode 100644 tests/mock/module_ipc/include/service_stub_mock.h create mode 100644 tests/mock/module_ipc/include/svc_backup_connection_mock.h create mode 100644 tests/mock/module_ipc/include/svc_extension_proxy_mock.h create mode 100644 tests/mock/module_ipc/include/svc_session_manager_mock.h create mode 100644 tests/mock/module_ipc/src/sa_backup_connection_mock.cpp create mode 100644 tests/mock/module_ipc/src/service_stub_mock.cpp create mode 100644 tests/mock/module_ipc/src/svc_backup_connection_mock.cpp create mode 100644 tests/mock/module_ipc/src/svc_session_manager_mock.cpp create mode 100644 tests/mock/utils_mock/include/backup_para_mock.h create mode 100644 tests/mock/utils_mock/src/backup_para_mock.cpp create mode 100644 tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp diff --git a/tests/mock/backup_ext/include/ext_backup_js_mock.h b/tests/mock/backup_ext/include/ext_backup_js_mock.h new file mode 100644 index 000000000..001051de5 --- /dev/null +++ b/tests/mock/backup_ext/include/ext_backup_js_mock.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_EXT_BACKUP_JS_MOCK_H +#define OHOS_FILEMGMT_BACKUP_EXT_BACKUP_JS_MOCK_H + +#include + +#include "ability_info.h" +#include "ext_backup_js.h" + +namespace OHOS::FileManagement::Backup { +class BExtBackupJs { +public: + BExtBackupJs() = default; + virtual ~BExtBackupJs() = default; +public: + virtual void Init(const std::shared_ptr &, + const std::shared_ptr &, + std::shared_ptr &, + const sptr &) = 0; + virtual ExtBackupJs *Create(const std::unique_ptr &) = 0; + virtual ErrCode OnBackup(std::function, + std::function) = 0; + virtual ErrCode OnRestore(std::function, + std::function) = 0; + virtual ErrCode GetBackupInfo(std::function); + virtual ErrCode InvokeAppExtMethod(ErrCode, const std::string) = 0; + virtual int CallJsMethod(const std::string &, AbilityRuntime::JsRuntime &, NativeReference *, InputArgsParser, + ResultValueParser) = 0; + virtual std::tuple CallObjectMethod(std::string_view, const std::vector &) = 0; + virtual std::function &argv)> ParseRestoreExInfo() = 0; + virtual std::function &argv)> ParseRestoreInfo() = 0; + virtual std::function &argv)> ParseBackupExInfo() = 0; + virtual std::function &argv)> ParseBackupInfo() = 0; + virtual ErrCode CallJSRestoreEx() = 0; + virtual ErrCode CallJSRestore() = 0; + virtual ErrCode CallJsOnBackupEx() = 0; + virtual ErrCode CallJsOnBackup() = 0; + virtual void ExportJsContext() = 0; +public: + virtual bool GetProfileFromAbility(const OHOS::AppExecFwk::AbilityInfo &, const std::string &, + std::vector &) const = 0; +public: + static inline std::shared_ptr extBackupJs = nullptr; +}; + +class ExtBackupJsMock : public BExtBackupJs { +public: + MOCK_METHOD(void, Init, (const std::shared_ptr &, + const std::shared_ptr &, + std::shared_ptr &, + const sptr &)); + MOCK_METHOD(ExtBackupJs *, Create, (const std::unique_ptr &)); + MOCK_METHOD(ErrCode, OnBackup, (std::function, + std::function)); + MOCK_METHOD(ErrCode, OnRestore, (std::function, + std::function)); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::function)); + MOCK_METHOD(ErrCode, InvokeAppExtMethod, (ErrCode, const std::string)); + MOCK_METHOD(int, CallJsMethod, (const std::string&, AbilityRuntime::JsRuntime&, NativeReference*, InputArgsParser, + ResultValueParser)); + MOCK_METHOD((std::tuple), CallObjectMethod, + (std::string_view, const std::vector &)); + MOCK_METHOD((std::function &argv)>), ParseRestoreExInfo, ()); + MOCK_METHOD((std::function &argv)>), ParseRestoreInfo, ()); + MOCK_METHOD((std::function &argv)>), ParseBackupExInfo, ()); + MOCK_METHOD((std::function &argv)>), ParseBackupInfo, ()); + MOCK_METHOD(ErrCode, CallJSRestoreEx, ()); + MOCK_METHOD(ErrCode, CallJSRestore, ()); + MOCK_METHOD(ErrCode, CallJsOnBackupEx, ()); + MOCK_METHOD(ErrCode, CallJsOnBackup, ()); + MOCK_METHOD(void, ExportJsContext, ()); +public: + MOCK_METHOD(bool, GetProfileFromAbility, (const OHOS::AppExecFwk::AbilityInfo&, const std::string&, + std::vector&), (const)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_EXT_BACKUP_JS_MOCK_H diff --git a/tests/mock/backup_ext/include/ext_extension_mock.h b/tests/mock/backup_ext/include/ext_extension_mock.h new file mode 100644 index 000000000..1e97a71f6 --- /dev/null +++ b/tests/mock/backup_ext/include/ext_extension_mock.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_EXT_EXTENSION_MOCK_H +#define OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_MOCK_H + +#include + +#include "ext_extension.h" + +namespace OHOS::FileManagement::Backup { +class BExtExtension { +public: + virtual ErrCode GetIncrementalFileHandle(const string &) = 0; + virtual UniqueFd GetFileHandle(const string &, int32_t &) = 0; + virtual ErrCode HandleClear() = 0; + virtual ErrCode BigFileReady(sptr) = 0; + virtual ErrCode PublishFile(const std::string &) = 0; + virtual ErrCode PublishIncrementalFile(const string &) = 0; + virtual ErrCode HandleBackup() = 0; + virtual int DoBackup(const BJsonEntityExtensionConfig &) = 0; + virtual int DoRestore(const string &) = 0; + virtual int DoIncrementalRestore() = 0; + virtual void AsyncTaskBackup(const string) = 0; + virtual void AsyncTaskRestore(std::set, const std::vector) = 0; + virtual void AsyncTaskIncrementalRestore() = 0; + virtual void AsyncTaskIncreRestoreSpecialVersion() = 0; + virtual void AsyncTaskRestoreForUpgrade() = 0; + virtual void ExtClear() = 0; + virtual void AsyncTaskIncrementalRestoreForUpgrade() = 0; + virtual void DoClear() = 0; + virtual void AppDone(ErrCode) = 0; + virtual void AppResultReport(const std::string, BackupRestoreScenario, ErrCode) = 0; + virtual void AsyncTaskOnBackup() = 0; + virtual ErrCode HandleRestore() = 0; + virtual void CompareFiles(UniqueFd, UniqueFd, std::vector&, + std::vector&, std::vector&) = 0; + virtual ErrCode HandleIncrementalBackup(UniqueFd, UniqueFd) = 0; + virtual ErrCode IncrementalOnBackup() = 0; + virtual tuple GetIncrementalBackupFileHandle() = 0; + virtual ErrCode IncrementalBigFileReady(const TarMap&, const std::vector&, + sptr) = 0; + virtual void AsyncTaskDoIncrementalBackup(UniqueFd, UniqueFd) = 0; + virtual void AsyncTaskOnIncrementalBackup() = 0; + virtual void IncrementalPacket(const std::vector&, TarMap&, sptr) = 0; + virtual int DoIncrementalBackup(const std::vector&, + const std::vector&, const std::vector&) = 0; + virtual void AppIncrementalDone(ErrCode) = 0; + virtual ErrCode GetBackupInfo(std::string&) = 0; + virtual ErrCode UpdateFdSendRate(std::string&, int32_t) = 0; + virtual std::function RestoreResultCallbackEx(wptr) = 0; + virtual std::function AppDoneCallbackEx(wptr) = 0; + virtual std::function IncRestoreResultCallbackEx(wptr) = 0; + virtual std::function HandleBackupEx(wptr) = 0; + virtual std::function HandleTaskBackupEx(wptr) = 0; + virtual void WaitToSendFd(std::chrono::system_clock::time_point&, int&) = 0; + virtual void RefreshTimeInfo(std::chrono::system_clock::time_point&, int&) = 0; +public: + BExtExtension() = default; + virtual ~BExtExtension() = default; +public: + static inline std::shared_ptr extExtension = nullptr; +}; + +class ExtExtensionMock : public BExtExtension { +public: + MOCK_METHOD(UniqueFd, GetFileHandle, (const string &, int32_t &)); + MOCK_METHOD(ErrCode, GetIncrementalFileHandle, (const string &)); + MOCK_METHOD(ErrCode, HandleClear, ()); + MOCK_METHOD(ErrCode, BigFileReady, (sptr)); + MOCK_METHOD(ErrCode, PublishFile, (const std::string &)); + MOCK_METHOD(ErrCode, PublishIncrementalFile, (const string &)); + MOCK_METHOD(ErrCode, HandleBackup, ()); + MOCK_METHOD(int, DoBackup, (const BJsonEntityExtensionConfig &)); + MOCK_METHOD(int, DoRestore, (const string &)); + MOCK_METHOD(int, DoIncrementalRestore, ()); + MOCK_METHOD(void, AsyncTaskBackup, (const string)); + MOCK_METHOD(void, AsyncTaskRestore, (std::set, const std::vector)); + MOCK_METHOD(void, AsyncTaskIncrementalRestore, ()); + MOCK_METHOD(void, AsyncTaskIncreRestoreSpecialVersion, ()); + MOCK_METHOD(void, AsyncTaskRestoreForUpgrade, ()); + MOCK_METHOD(void, ExtClear, ()); + MOCK_METHOD(void, AsyncTaskIncrementalRestoreForUpgrade, ()); + MOCK_METHOD(void, DoClear, ()); + MOCK_METHOD(void, AppDone, (ErrCode)); + MOCK_METHOD(void, AppResultReport, (const std::string, BackupRestoreScenario, ErrCode)); + MOCK_METHOD(void, AsyncTaskOnBackup, ()); + MOCK_METHOD(ErrCode, HandleRestore, ()); + MOCK_METHOD(void, CompareFiles, (UniqueFd, UniqueFd, (std::vector&), + (std::vector&), (std::vector&))); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(ErrCode, IncrementalOnBackup, ()); + MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); + MOCK_METHOD(ErrCode, IncrementalBigFileReady, (const TarMap&, (const std::vector&), + sptr)); + MOCK_METHOD(void, AsyncTaskDoIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(void, AsyncTaskOnIncrementalBackup, ()); + MOCK_METHOD(void, IncrementalPacket, ((const std::vector&), TarMap&, sptr)); + MOCK_METHOD(int, DoIncrementalBackup, ((const std::vector&), + (const std::vector&), (const std::vector&))); + MOCK_METHOD(void, AppIncrementalDone, (ErrCode)); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::string&)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string&, int32_t)); + MOCK_METHOD((std::function), RestoreResultCallbackEx, (wptr)); + MOCK_METHOD((std::function), AppDoneCallbackEx, (wptr)); + MOCK_METHOD((std::function), IncRestoreResultCallbackEx, (wptr)); + MOCK_METHOD((std::function), HandleBackupEx, (wptr)); + MOCK_METHOD((std::function), HandleTaskBackupEx, (wptr)); + MOCK_METHOD(void, WaitToSendFd, ((std::chrono::system_clock::time_point&), int&)); + MOCK_METHOD(void, RefreshTimeInfo, ((std::chrono::system_clock::time_point&), int&)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_MOCK_H \ No newline at end of file diff --git a/tests/mock/backup_ext/include/ext_extension_stub_mock.h b/tests/mock/backup_ext/include/ext_extension_stub_mock.h new file mode 100644 index 000000000..6cc34071e --- /dev/null +++ b/tests/mock/backup_ext/include/ext_extension_stub_mock.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_MOCK_H +#define OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_MOCK_H + +#include + +#include "ext_extension_stub.h" + +namespace OHOS::FileManagement::Backup { +class ExtExtensionStubMock : public ExtExtensionStub { +public: + MOCK_METHOD(int, OnRemoteRequest, (uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + MOCK_METHOD(ErrCode, CmdGetFileHandle, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdHandleClear, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdHandleBackup, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdPublishFile, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdHandleRestore, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdGetIncrementalFileHandle, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdPublishIncrementalFile, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdHandleIncrementalBackup, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdIncrementalOnBackup, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdGetIncrementalBackupFileHandle, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdGetBackupInfo, (MessageParcel &, MessageParcel &)); + MOCK_METHOD(ErrCode, CmdUpdateFdSendRate, (MessageParcel &, MessageParcel &)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_EXT_EXTENSION_STUB_MOCK_H diff --git a/tests/mock/backup_ext/include/js_runtime_mock.h b/tests/mock/backup_ext/include/js_runtime_mock.h new file mode 100644 index 000000000..c78c842a0 --- /dev/null +++ b/tests/mock/backup_ext/include/js_runtime_mock.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_JS_RUNTIME_MOCK_H +#define OHOS_FILEMGMT_BACKUP_JS_RUNTIME_MOCK_H + +#include + +#include "runtime.h" + +namespace OHOS::FileManagement::Backup { +class JsRuntimeMock : public AbilityRuntime::JsRuntime { +public: + MOCK_METHOD(Language, GetLanguage, (), (const)); + MOCK_METHOD(void, StartDebugMode, (const DebugOption debugOption)); + MOCK_METHOD(void, DumpHeapSnapshot, (bool isPrivate)); + MOCK_METHOD(void, DumpCpuProfile, ()); + MOCK_METHOD(void, DestroyHeapProfiler, ()); + MOCK_METHOD(void, ForceFullGC, ()); + MOCK_METHOD(void, ForceFullGC, (uint32_t tid)); + MOCK_METHOD(void, DumpHeapSnapshot, (uint32_t tid, bool isFullGC)); + MOCK_METHOD(void, AllowCrossThreadExecution, ()); + MOCK_METHOD(void, GetHeapPrepare, ()); + MOCK_METHOD(void, NotifyApplicationState, (bool isBackground)); + MOCK_METHOD(bool, SuspendVM, (uint32_t tid)); + MOCK_METHOD(void, ResumeVM, (uint32_t tid)); + MOCK_METHOD(void, PreloadSystemModule, (const std::string& moduleName)); + MOCK_METHOD(void, FinishPreload, ()); + MOCK_METHOD(bool, LoadRepairPatch, (const std::string& patchFile, const std::string& baseFile)); + MOCK_METHOD(bool, NotifyHotReloadPage, ()); + MOCK_METHOD(bool, UnLoadRepairPatch, (const std::string& patchFile)); + MOCK_METHOD(void, RegisterQuickFixQueryFunc, ((const std::map&) moduleAndPath)); + MOCK_METHOD(void, StartProfiler, (const DebugOption debugOption)); + MOCK_METHOD(void, DoCleanWorkAfterStageCleaned, ()); + MOCK_METHOD(void, SetModuleLoadChecker, (const std::shared_ptr), (const)); + MOCK_METHOD(void, SetDeviceDisconnectCallback, (const std::function &cb)); + MOCK_METHOD(void, UpdatePkgContextInfoJson, (std::string moduleName, std::string hapPath, std::string packageName)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_JS_RUNTIME_MOCK_H diff --git a/tests/mock/backup_ext/src/ext_backup_js_mock.cpp b/tests/mock/backup_ext/src/ext_backup_js_mock.cpp new file mode 100644 index 000000000..1f97308fd --- /dev/null +++ b/tests/mock/backup_ext/src/ext_backup_js_mock.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2022-2024 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. + */ + +#include "ext_backup_js.h" +#include "ext_backup_js_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +void ExtBackupJs::Init(const shared_ptr &record, + const shared_ptr &application, + shared_ptr &handler, + const sptr &token) +{ + BExtBackupJs::extBackupJs->Init(record, application, handler, token); +} + +void ExtBackupJs::ExportJsContext(void) +{ + BExtBackupJs::extBackupJs->ExportJsContext(); +} + +ExtBackupJs *ExtBackupJs::Create(const unique_ptr &runtime) +{ + return BExtBackupJs::extBackupJs->Create(runtime); +} + +ErrCode ExtBackupJs::OnBackup(function callback, + function callbackEx) +{ + return BExtBackupJs::extBackupJs->OnBackup(callback, callbackEx); +} + +ErrCode ExtBackupJs::CallJsOnBackupEx() +{ + return BExtBackupJs::extBackupJs->CallJsOnBackupEx(); +} + +ErrCode ExtBackupJs::CallJsOnBackup() +{ + return BExtBackupJs::extBackupJs->CallJsOnBackup(); +} + +ErrCode ExtBackupJs::OnRestore(function callback, + function callbackEx) +{ + return BExtBackupJs::extBackupJs->OnRestore(callback, callbackEx); +} + +ErrCode ExtBackupJs::CallJSRestoreEx() +{ + return BExtBackupJs::extBackupJs->CallJSRestoreEx(); +} + +ErrCode ExtBackupJs::CallJSRestore() +{ + return BExtBackupJs::extBackupJs->CallJSRestore(); +} + +ErrCode ExtBackupJs::GetBackupInfo(function callback) +{ + return BExtBackupJs::extBackupJs->GetBackupInfo(callback); +} + +int ExtBackupJs::CallJsMethod(const string &funcName, AbilityRuntime::JsRuntime &jsRuntime, NativeReference *jsObj, + InputArgsParser argParser, ResultValueParser retParser) +{ + return BExtBackupJs::extBackupJs->CallJsMethod(funcName, jsRuntime, jsObj, argParser, retParser); +} + +function &argv)> ExtBackupJs::ParseBackupExInfo() +{ + return BExtBackupJs::extBackupJs->ParseBackupExInfo(); +} + +function &argv)> ExtBackupJs::ParseRestoreExInfo() +{ + return BExtBackupJs::extBackupJs->ParseRestoreExInfo(); +} + +function &argv)> ExtBackupJs::ParseRestoreInfo() +{ + return BExtBackupJs::extBackupJs->ParseRestoreInfo(); +} + +ErrCode ExtBackupJs::InvokeAppExtMethod(ErrCode errCode, const string result) +{ + return BExtBackupJs::extBackupJs->InvokeAppExtMethod(errCode, result); +} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/backup_ext/src/ext_extension_mock.cpp b/tests/mock/backup_ext/src/ext_extension_mock.cpp new file mode 100644 index 000000000..80b8d6dc6 --- /dev/null +++ b/tests/mock/backup_ext/src/ext_extension_mock.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "ext_extension.h" +#include "ext_extension_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +void BackupExtExtension::VerifyCaller() +{ +} + +UniqueFd BackupExtExtension::GetFileHandle(const string &fileName, int32_t &errCode) +{ + return BExtExtension::extExtension->GetFileHandle(fileName, errCode); +} + +ErrCode BackupExtExtension::GetIncrementalFileHandle(const string &fileName) +{ + return BExtExtension::extExtension->GetIncrementalFileHandle(fileName); +} + +ErrCode BackupExtExtension::HandleClear() +{ + return BExtExtension::extExtension->HandleClear(); +} + +ErrCode BackupExtExtension::BigFileReady(sptr proxy) +{ + return BExtExtension::extExtension->BigFileReady(proxy); +} + +ErrCode BackupExtExtension::PublishFile(const std::string &fileName) +{ + return BExtExtension::extExtension->PublishFile(fileName); +} + +ErrCode BackupExtExtension::PublishIncrementalFile(const string &fileName) +{ + return BExtExtension::extExtension->PublishIncrementalFile(fileName); +} + +ErrCode BackupExtExtension::HandleBackup() +{ + return BExtExtension::extExtension->HandleBackup(); +} + +int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) +{ + return BExtExtension::extExtension->DoBackup(usrConfig); +} + +int BackupExtExtension::DoRestore(const string &fileName) +{ + return BExtExtension::extExtension->DoRestore(fileName); +} + +int BackupExtExtension::DoIncrementalRestore() +{ + return BExtExtension::extExtension->DoIncrementalRestore(); +} + +void BackupExtExtension::AsyncTaskBackup(const string config) +{ +} + +void BackupExtExtension::AsyncTaskRestore(std::set fileSet, + const std::vector extManageInfo) +{ +} + +void BackupExtExtension::AsyncTaskIncrementalRestore() +{ +} + +void BackupExtExtension::AsyncTaskIncreRestoreSpecialVersion() +{ +} + +void BackupExtExtension::AsyncTaskRestoreForUpgrade() +{ +} + +void BackupExtExtension::ExtClear() +{ +} + +void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() +{ +} + +void BackupExtExtension::DoClear() +{ +} + +void BackupExtExtension::AppDone(ErrCode errCode) +{ +} + +void BackupExtExtension::AppResultReport(const std::string restoreRetInfo, + BackupRestoreScenario scenario, ErrCode errCode) +{ +} + +void BackupExtExtension::AsyncTaskOnBackup() +{ +} + +ErrCode BackupExtExtension::HandleRestore() +{ + return BExtExtension::extExtension->HandleRestore(); +} + +void BackupExtExtension::CompareFiles(UniqueFd incrementalFd, + UniqueFd manifestFd, + vector &allFiles, + vector &smallFiles, + vector &bigFiles) +{ +} + +ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +{ + return BExtExtension::extExtension->HandleIncrementalBackup(std::move(incrementalFd), std::move(manifestFd)); +} + +ErrCode BackupExtExtension::IncrementalOnBackup() +{ + return BExtExtension::extExtension->IncrementalOnBackup(); +} + +tuple BackupExtExtension::GetIncrementalBackupFileHandle() +{ + return BExtExtension::extExtension->GetIncrementalBackupFileHandle(); +} + +ErrCode BackupExtExtension::IncrementalBigFileReady(const TarMap &pkgInfo, + const vector &bigInfos, sptr proxy) +{ + return BExtExtension::extExtension->IncrementalBigFileReady(pkgInfo, bigInfos, proxy); +} + +void BackupExtExtension::AsyncTaskDoIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +{ +} + +void BackupExtExtension::AsyncTaskOnIncrementalBackup() +{ +} + +void BackupExtExtension::IncrementalPacket(const vector &, TarMap &, sptr) +{ +} + +int BackupExtExtension::DoIncrementalBackup(const vector &allFiles, + const vector &smallFiles, + const vector &bigFiles) +{ + return BExtExtension::extExtension->DoIncrementalBackup(allFiles, smallFiles, bigFiles); +} + +void BackupExtExtension::AppIncrementalDone(ErrCode errCode) +{ +} + +ErrCode BackupExtExtension::GetBackupInfo(std::string &result) +{ + return BExtExtension::extExtension->GetBackupInfo(result); +} + +ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) +{ + return BExtExtension::extExtension->UpdateFdSendRate(bundleName, sendRate); +} + +std::function BackupExtExtension::RestoreResultCallbackEx(wptr obj) +{ + return BExtExtension::extExtension->RestoreResultCallbackEx(obj); +} + +std::function BackupExtExtension::AppDoneCallbackEx(wptr obj) +{ + return BExtExtension::extExtension->AppDoneCallbackEx(obj); +} + +std::function BackupExtExtension::IncRestoreResultCallbackEx(wptr obj) +{ + return BExtExtension::extExtension->IncRestoreResultCallbackEx(obj); +} + +std::function BackupExtExtension::HandleBackupEx(wptr obj) +{ + return BExtExtension::extExtension->HandleBackupEx(obj); +} + +std::function BackupExtExtension::HandleTaskBackupEx(wptr obj) +{ + return BExtExtension::extExtension->HandleTaskBackupEx(obj); +} + +void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point &startTime, int &fdSendNum) +{ +} + +void BackupExtExtension::RefreshTimeInfo(std::chrono::system_clock::time_point &startTime, int &fdSendNum) +{ +} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp b/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp new file mode 100644 index 000000000..6f9309402 --- /dev/null +++ b/tests/mock/backup_ext/src/ext_extension_stub_mock.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "ext_extension_stub_mock.h" + +namespace OHOS::FileManagement::Backup { +ExtExtensionStub::ExtExtensionStub() +{ +} + +int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + return static_cast(this)->OnRemoteRequest(code, data, reply, option); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_external/include/bms_adapter_mock.h b/tests/mock/module_external/include/bms_adapter_mock.h new file mode 100644 index 000000000..adb1e1cf5 --- /dev/null +++ b/tests/mock/module_external/include/bms_adapter_mock.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_BMS_ADAPTER_MOCK_H +#define OHOS_FILEMGMT_BACKUP_BMS_ADAPTER_MOCK_H + +#include + +#include "module_external/bms_adapter.h" + +namespace OHOS::FileManagement::Backup { +class BBundleMgrAdapter { +public: + virtual std::vector GetBundleInfos(const std::vector&, int32_t) = 0; + virtual std::string GetAppGalleryBundleName() = 0; + virtual std::vector GetBundleInfosForIncremental( + const std::vector&, int32_t) = 0; + virtual std::vector GetBundleInfosForIncremental(int32_t, + const std::vector&) = 0; + virtual std::string GetExtName(string, int32_t) = 0; + virtual std::vector GetBundleInfosForSA() = 0; + virtual void GetBundleInfoForSA(std::string, std::vector&) = 0; +public: + BBundleMgrAdapter() = default; + virtual ~BBundleMgrAdapter() = default; +public: + static inline std::shared_ptr bms = nullptr; +}; + +class BundleMgrAdapterMock : public BBundleMgrAdapter { +public: + MOCK_METHOD((std::vector), GetBundleInfos, + ((const std::vector&), int32_t)); + MOCK_METHOD(std::string, GetAppGalleryBundleName, ()); + MOCK_METHOD((std::vector), GetBundleInfosForIncremental, + ((const std::vector&), int32_t)); + MOCK_METHOD((std::vector), GetBundleInfosForIncremental, (int32_t, + (const std::vector&))); + MOCK_METHOD(std::string, GetExtName, (std::string, int32_t)); + MOCK_METHOD((std::vector), GetBundleInfosForSA, ()); + MOCK_METHOD(void, GetBundleInfoForSA, (std::string, (std::vector&))); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_BMS_ADAPTER_MOCK_H diff --git a/tests/mock/module_external/include/sms_adapter_mock.h b/tests/mock/module_external/include/sms_adapter_mock.h new file mode 100644 index 000000000..4ec9d27cc --- /dev/null +++ b/tests/mock/module_external/include/sms_adapter_mock.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_SMS_ADAPTER_MOCK_H +#define OHOS_FILEMGMT_BACKUP_SMS_ADAPTER_MOCK_H + +#include + +#include "module_external/sms_adapter.h" + +namespace OHOS::FileManagement::Backup { +class BStorageMgrAdapter { +public: + virtual StorageManager::BundleStats GetBundleStats(const std::string&) = 0; + virtual int64_t GetUserStorageStats(const std::string&, int32_t) = 0; + virtual int32_t UpdateMemPara(int32_t) = 0; + virtual int32_t GetBundleStatsForIncrease(uint32_t, const std::vector&, + const std::vector&, std::vector&, std::vector&) = 0; +public: + BStorageMgrAdapter() = default; + virtual ~BStorageMgrAdapter() = default; +public: + static inline std::shared_ptr sms = nullptr; +}; + +class StorageMgrAdapterMock : public BStorageMgrAdapter { +public: + MOCK_METHOD(StorageManager::BundleStats, GetBundleStats, (const std::string&)); + MOCK_METHOD(int64_t, GetUserStorageStats, (const std::string&, int32_t)); + MOCK_METHOD(int32_t, UpdateMemPara, (int32_t)); + MOCK_METHOD(int32_t, GetBundleStatsForIncrease, (uint32_t, (const std::vector&), + (const std::vector&), (std::vector&), (std::vector&))); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SMS_ADAPTER_MOCK_H diff --git a/tests/mock/module_external/src/bms_adapter_mock.cpp b/tests/mock/module_external/src/bms_adapter_mock.cpp new file mode 100644 index 000000000..7421fcaba --- /dev/null +++ b/tests/mock/module_external/src/bms_adapter_mock.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "bms_adapter_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +vector BundleMgrAdapter::GetBundleInfos(const vector &bundleNames, int32_t userId) +{ + return BBundleMgrAdapter::bms->GetBundleInfos(bundleNames, userId); +} + +string BundleMgrAdapter::GetAppGalleryBundleName() +{ + return BBundleMgrAdapter::bms->GetAppGalleryBundleName(); +} + +vector BundleMgrAdapter::GetBundleInfosForIncremental( + const vector &incrementalDataList, int32_t userId) +{ + return BBundleMgrAdapter::bms->GetBundleInfosForIncremental(incrementalDataList, userId); +} + +vector BundleMgrAdapter::GetBundleInfosForIncremental(int32_t userId, + const std::vector &extraIncreData) +{ + return BBundleMgrAdapter::bms->GetBundleInfosForIncremental(userId, extraIncreData); +} + +string BundleMgrAdapter::GetExtName(string bundleName, int32_t userId) +{ + return BBundleMgrAdapter::bms->GetExtName(bundleName, userId); +} + +std::vector BundleMgrAdapter::GetBundleInfosForSA() +{ + return BBundleMgrAdapter::bms->GetBundleInfosForSA(); +} + +void BundleMgrAdapter::GetBundleInfoForSA(std::string bundleName, std::vector& bundleInfos) +{ + return BBundleMgrAdapter::bms->GetBundleInfoForSA(bundleName, bundleInfos); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_external/src/sms_adapter_mock.cpp b/tests/mock/module_external/src/sms_adapter_mock.cpp new file mode 100644 index 000000000..a687d86cb --- /dev/null +++ b/tests/mock/module_external/src/sms_adapter_mock.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "sms_adapter_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +StorageManager::BundleStats StorageMgrAdapter::GetBundleStats(const string &bundleName) +{ + return BStorageMgrAdapter::sms->GetBundleStats(bundleName); +} + +int64_t StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, int32_t userId) +{ + return BStorageMgrAdapter::sms->GetUserStorageStats(bundleName, userId); +} + +int32_t StorageMgrAdapter::UpdateMemPara(int32_t size) +{ + return BStorageMgrAdapter::sms->UpdateMemPara(size); +} + +int32_t StorageMgrAdapter::GetBundleStatsForIncrease(uint32_t userId, const std::vector &bundleNames, + const std::vector &incrementalBackTimes, std::vector &pkgFileSizes, + std::vector &incPkgFileSizes) +{ + return BStorageMgrAdapter::sms->GetBundleStatsForIncrease(userId, bundleNames, incrementalBackTimes, pkgFileSizes, + incPkgFileSizes); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/include/sa_backup_connection_mock.h b/tests/mock/module_ipc/include/sa_backup_connection_mock.h new file mode 100644 index 000000000..2b883d275 --- /dev/null +++ b/tests/mock/module_ipc/include/sa_backup_connection_mock.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") = 0; + * 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_FILEMGMT_BACKUP_SA_BACKUP_CONNECTION_MOCK_H +#define OHOS_FILEMGMT_BACKUP_SA_BACKUP_CONNECTION_MOCK_H + +#include + +#include "module_ipc/sa_backup_connection.h" + +namespace OHOS::FileManagement::Backup { +class BSABackupConnection : public RefBase { +public: + virtual bool InputParaSet(MessageParcel&) = 0; + virtual bool OutputParaGet(MessageParcel&) = 0; + virtual ErrCode ConnectBackupSAExt(std::string, std::string, std::string) = 0; + virtual ErrCode DisconnectBackupSAExt() = 0; + virtual bool IsSAExtConnected() = 0; + virtual sptr GetBackupSAExtProxy() = 0; + virtual ErrCode LoadBackupSAExt() = 0; + virtual ErrCode LoadBackupSAExtInner() = 0; + virtual ErrCode CallBackupSA() = 0; + virtual ErrCode CallRestoreSA(UniqueFd) = 0; +public: + BSABackupConnection() = default; + virtual ~BSABackupConnection() = default; +public: + static inline sptr saConnect = nullptr; +}; + +class SABackupConnectionMock : public BSABackupConnection { +public: + MOCK_METHOD(bool, InputParaSet, (MessageParcel&)); + MOCK_METHOD(bool, OutputParaGet, (MessageParcel&)); + MOCK_METHOD(ErrCode, ConnectBackupSAExt, (std::string, std::string, std::string)); + MOCK_METHOD(ErrCode, DisconnectBackupSAExt, ()); + MOCK_METHOD(bool, IsSAExtConnected, ()); + MOCK_METHOD((sptr), GetBackupSAExtProxy, ()); + MOCK_METHOD(ErrCode, LoadBackupSAExt, ()); + MOCK_METHOD(ErrCode, LoadBackupSAExtInner, ()); + MOCK_METHOD(ErrCode, CallBackupSA, ()); + MOCK_METHOD(ErrCode, CallRestoreSA, (UniqueFd)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SA_BACKUP_CONNECTION_MOCK_H \ No newline at end of file diff --git a/tests/mock/module_ipc/include/service_stub_mock.h b/tests/mock/module_ipc/include/service_stub_mock.h new file mode 100644 index 000000000..85a71336f --- /dev/null +++ b/tests/mock/module_ipc/include/service_stub_mock.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H + +#include + +namespace OHOS::FileManagement::Backup { +class BServiceStub { +public: + virtual int32_t OnRemoteRequest(uint32_t, MessageParcel&, MessageParcel&, MessageOption&) = 0; + virtual int32_t CmdInitRestoreSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdInitBackupSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdStart(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdGetLocalCapabilities(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdPublishFile(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppFileReady(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppDone(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdResultReport(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdGetFileHandle(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppendBundlesRestoreSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppendBundlesBackupSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppendBundlesDetailsBackupSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdFinish(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdRelease(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdGetLocalCapabilitiesIncremental(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdInitIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppendBundlesIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdPublishIncrementalFile(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdPublishSAIncrementalFile(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppIncrementalFileReady(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdAppIncrementalDone(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdGetIncrementalFileHandle(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdGetBackupInfo(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdUpdateTimer(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdUpdateSendRate(MessageParcel&, MessageParcel&) = 0; + virtual void ServiceStubSupplement() = 0; + virtual void ServiceStubSuppAppendBundles() = 0; + +public: + BServiceStub() = default; + virtual ~BServiceStub() = default; +public: + static inline std::shared_ptr stub = nullptr; +}; + +class ServiceStubMock : public BServiceStub { +public: + MOCK_METHOD(int32_t, OnRemoteRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); + MOCK_METHOD(int32_t, CmdInitRestoreSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdInitBackupSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdStart, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdGetLocalCapabilities, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdPublishFile, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppFileReady, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppDone, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdResultReport, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdGetFileHandle, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppendBundlesRestoreSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppendBundlesDetailsRestoreSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppendBundlesBackupSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppendBundlesDetailsBackupSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdFinish, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdRelease, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdGetLocalCapabilitiesIncremental, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdGetAppLocalListAndDoIncrementalBackup, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdInitIncrementalBackupSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppendBundlesIncrementalBackupSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppendBundlesDetailsIncrementalBackupSession, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdPublishIncrementalFile, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdPublishSAIncrementalFile, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppIncrementalFileReady, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdAppIncrementalDone, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdGetIncrementalFileHandle, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdGetBackupInfo, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdUpdateTimer, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdUpdateSendRate, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(void, ServiceStubSupplement, ()); + MOCK_METHOD(void, ServiceStubSuppAppendBundles, ()); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_STUB_MOCK_H diff --git a/tests/mock/module_ipc/include/svc_backup_connection_mock.h b/tests/mock/module_ipc/include/svc_backup_connection_mock.h new file mode 100644 index 000000000..a82219d88 --- /dev/null +++ b/tests/mock/module_ipc/include/svc_backup_connection_mock.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") = 0; + * 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_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_MOCK_H +#define OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_MOCK_H + +#include + +#include "module_ipc/svc_backup_connection.h" + +namespace OHOS::FileManagement::Backup { +class BSvcBackupConnection : public RefBase { +public: + virtual ErrCode ConnectBackupExtAbility(AAFwk::Want&, int32_t) = 0; + virtual ErrCode DisconnectBackupExtAbility() = 0; + virtual bool IsExtAbilityConnected() = 0; + virtual sptr GetBackupExtProxy() = 0; +public: + BSvcBackupConnection() = default; + virtual ~BSvcBackupConnection() = default; +public: + static inline sptr connect = nullptr; +}; + +class SvcBackupConnectionMock : public BSvcBackupConnection { +public: + MOCK_METHOD(ErrCode, ConnectBackupExtAbility, (AAFwk::Want&, int32_t)); + MOCK_METHOD(ErrCode, DisconnectBackupExtAbility, ()); + MOCK_METHOD(bool, IsExtAbilityConnected, ()); + MOCK_METHOD((sptr), GetBackupExtProxy, ()); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SVC_EXTENSION_PROXY_MOCK_H \ No newline at end of file diff --git a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h new file mode 100644 index 000000000..82c94f9eb --- /dev/null +++ b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") = 0; + * 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_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H +#define OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H + +#include + +#include "module_ipc/svc_extension_proxy.h" + +namespace OHOS::FileManagement::Backup { +class SvcExtensionProxyMock : public SvcExtensionProxy { +public: + SvcExtensionProxyMock() : SvcExtensionProxy(nullptr) {}; +public: + MOCK_METHOD(UniqueFd, GetFileHandle, (const std::string&, int32_t&)); + MOCK_METHOD(ErrCode, HandleClear, ()); + MOCK_METHOD(ErrCode, HandleBackup, ()); + MOCK_METHOD(ErrCode, PublishFile, (const std::string&)); + MOCK_METHOD(ErrCode, HandleRestore, ()); + MOCK_METHOD(ErrCode, GetIncrementalFileHandle, (const std::string&)); + MOCK_METHOD(ErrCode, PublishIncrementalFile, (const std::string&)); + MOCK_METHOD(ErrCode, HandleIncrementalBackup, (UniqueFd, UniqueFd)); + MOCK_METHOD(ErrCode, IncrementalOnBackup, ()); + MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); + MOCK_METHOD(ErrCode, GetBackupInfo, (std::string&)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string&, int32_t)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SVC_BACKUP_CONNECTION_MOCK_H \ No newline at end of file diff --git a/tests/mock/module_ipc/include/svc_session_manager_mock.h b/tests/mock/module_ipc/include/svc_session_manager_mock.h new file mode 100644 index 000000000..97467322c --- /dev/null +++ b/tests/mock/module_ipc/include/svc_session_manager_mock.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") = 0; + * 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_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H +#define OHOS_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H + +#include + +#include "module_ipc/svc_session_manager.h" + +namespace OHOS::FileManagement::Backup { +class BSvcSessionManager { +public: + virtual ErrCode Active(struct SvcSessionManager::Impl) = 0; + virtual sptr GetServiceReverseProxy() = 0; + virtual IServiceReverse::Scenario GetScenario() = 0; + virtual int32_t GetSessionUserId() = 0; + virtual bool OnBundleFileReady(const std::string&, const std::string&) = 0; + virtual UniqueFd OnBundleExtManageInfo(const std::string&, UniqueFd) = 0; + virtual wptr GetExtConnection(const BundleName&) = 0; + virtual std::weak_ptr GetSAExtConnection(const BundleName&) = 0; + virtual std::set GetExtFileNameRequest(const std::string&) = 0; + virtual BConstants::ServiceSchedAction GetServiceSchedAction(const std::string&) = 0; + virtual bool GetSchedBundleName(std::string&) = 0; + virtual std::string GetBackupExtName(const std::string&) = 0; + virtual std::string GetBackupExtInfo(const std::string&) = 0; + virtual sptr CreateBackupConnection(BundleName&) = 0; + virtual bool IsOnAllBundlesFinished() = 0; + virtual bool IsOnOnStartSched() = 0; + virtual bool NeedToUnloadService() = 0; + virtual RestoreTypeEnum GetBundleRestoreType(const std::string&) = 0; + virtual int64_t GetBundleVersionCode(const std::string&) = 0; + virtual std::string GetBundleVersionName(const std::string&) = 0; + virtual bool UpdateTimer(const std::string&, uint32_t, const Utils::Timer::TimerCallback&) = 0; + virtual bool GetIsIncrementalBackup() = 0; + virtual int32_t GetIncrementalManifestFd(const std::string&) = 0; + virtual int64_t GetLastIncrementalTime(const std::string&) = 0; + virtual int32_t GetMemParaCurSize() = 0; + virtual bool ValidRestoreDataType(RestoreTypeEnum) = 0; +public: + BSvcSessionManager() = default; + virtual ~BSvcSessionManager() = default; +public: + static inline std::shared_ptr sessionManager = nullptr; +}; + +class SvcSessionManagerMock : public BSvcSessionManager { +public: + MOCK_METHOD(ErrCode, Active, (struct SvcSessionManager::Impl)); + MOCK_METHOD((sptr), GetServiceReverseProxy, ()); + MOCK_METHOD(IServiceReverse::Scenario, GetScenario, ()); + MOCK_METHOD(int32_t, GetSessionUserId, ()); + MOCK_METHOD(bool, OnBundleFileReady, (const std::string&, const std::string&)); + MOCK_METHOD(UniqueFd, OnBundleExtManageInfo, (const std::string&, UniqueFd)); + MOCK_METHOD((wptr), GetExtConnection, (const BundleName&)); + MOCK_METHOD((std::weak_ptr), GetSAExtConnection, (const BundleName&)); + MOCK_METHOD((std::set), GetExtFileNameRequest, (const std::string&)); + MOCK_METHOD(BConstants::ServiceSchedAction, GetServiceSchedAction, (const std::string&)); + MOCK_METHOD(bool, GetSchedBundleName, (std::string&)); + MOCK_METHOD(std::string, GetBackupExtName, (const std::string&)); + MOCK_METHOD(std::string, GetBackupExtInfo, (const std::string&)); + MOCK_METHOD(sptr, CreateBackupConnection, (BundleName&)); + MOCK_METHOD(bool, IsOnAllBundlesFinished, ()); + MOCK_METHOD(bool, IsOnOnStartSched, ()); + MOCK_METHOD(bool, NeedToUnloadService, ()); + MOCK_METHOD(RestoreTypeEnum, GetBundleRestoreType, (const std::string&)); + MOCK_METHOD(int64_t, GetBundleVersionCode, (const std::string&)); + MOCK_METHOD(std::string, GetBundleVersionName, (const std::string&)); + MOCK_METHOD(bool, UpdateTimer, (const std::string&, uint32_t, const Utils::Timer::TimerCallback&)); + MOCK_METHOD(bool, GetIsIncrementalBackup, ()); + MOCK_METHOD(int32_t, GetIncrementalManifestFd, (const std::string&)); + MOCK_METHOD(int64_t, GetLastIncrementalTime, (const std::string&)); + MOCK_METHOD(int32_t, GetMemParaCurSize, ()); + MOCK_METHOD(bool, ValidRestoreDataType, (RestoreTypeEnum)); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_SVC_SESSION_MANAGER_MOCK_H diff --git a/tests/mock/module_ipc/src/sa_backup_connection_mock.cpp b/tests/mock/module_ipc/src/sa_backup_connection_mock.cpp new file mode 100644 index 000000000..8418d4cf9 --- /dev/null +++ b/tests/mock/module_ipc/src/sa_backup_connection_mock.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "sa_backup_connection_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +ErrCode SABackupConnection::ConnectBackupSAExt(std::string bundleName, std::string extension, std::string extInfo) +{ + return BSABackupConnection::saConnect->ConnectBackupSAExt(bundleName, extension, extInfo); +} + +ErrCode SABackupConnection::DisconnectBackupSAExt() +{ + return BSABackupConnection::saConnect->DisconnectBackupSAExt(); +} + +bool SABackupConnection::IsSAExtConnected() +{ + return BSABackupConnection::saConnect->IsSAExtConnected(); +} + +sptr SABackupConnection::GetBackupSAExtProxy() +{ + return BSABackupConnection::saConnect->GetBackupSAExtProxy(); +} + +ErrCode SABackupConnection::LoadBackupSAExt() +{ + return BSABackupConnection::saConnect->LoadBackupSAExt(); +} + +ErrCode SABackupConnection::LoadBackupSAExtInner() +{ + return BSABackupConnection::saConnect->LoadBackupSAExtInner(); +} + +bool SABackupConnection::InputParaSet(MessageParcel &data) +{ + return BSABackupConnection::saConnect->InputParaSet(data); +} + +bool SABackupConnection::OutputParaGet(MessageParcel &reply) +{ + return BSABackupConnection::saConnect->OutputParaGet(reply); +} + +ErrCode SABackupConnection::CallBackupSA() +{ + return BSABackupConnection::saConnect->CallBackupSA(); +} + +ErrCode SABackupConnection::CallRestoreSA(UniqueFd fd) +{ + return BSABackupConnection::saConnect->CallRestoreSA(std::move(fd)); +} + +void SABackupConnection::SALoadCallback::OnLoadSystemAbilitySuccess(int32_t, const OHOS::sptr&) {} + +void SABackupConnection::SALoadCallback::OnLoadSystemAbilityFail(int32_t) {} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp new file mode 100644 index 000000000..df67aac7d --- /dev/null +++ b/tests/mock/module_ipc/src/service_stub_mock.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "module_ipc/service_stub.h" +#include "service_stub_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +ServiceStub::ServiceStub() +{ +} + +void ServiceStub::ServiceStubSupplement() +{ +} + +int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + return BServiceStub::stub->OnRemoteRequest(code, data, reply, option); +} + +int32_t ServiceStub::CmdInitRestoreSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdInitRestoreSession(data, reply); +} + +int32_t ServiceStub::CmdInitBackupSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdInitBackupSession(data, reply); +} + +int32_t ServiceStub::CmdStart(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdStart(data, reply); +} + +int32_t ServiceStub::CmdGetLocalCapabilities(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdGetLocalCapabilities(data, reply); +} + +int32_t ServiceStub::CmdPublishFile(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdPublishFile(data, reply); +} + +int32_t ServiceStub::CmdAppFileReady(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppFileReady(data, reply); +} + +int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppDone(data, reply); +} + +int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdResultReport(data, reply); +} + +int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdGetFileHandle(data, reply); +} + +int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppendBundlesRestoreSession(data, reply); +} + +int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppendBundlesDetailsRestoreSession(data, reply); +} + +int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppendBundlesBackupSession(data, reply); +} + +int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdFinish(data, reply); +} + +int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdGetBackupInfo(data, reply); +} + +int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdUpdateTimer(data, reply); +} + +int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdUpdateSendRate(data, reply); +} + +int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdRelease(data, reply); +} + +int32_t ServiceStub::CmdGetLocalCapabilitiesIncremental(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdGetLocalCapabilitiesIncremental(data, reply); +} + +int32_t ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdGetAppLocalListAndDoIncrementalBackup(data, reply); +} + +int32_t ServiceStub::CmdInitIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdInitIncrementalBackupSession(data, reply); +} + +int32_t ServiceStub::CmdAppendBundlesIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppendBundlesIncrementalBackupSession(data, reply); +} + +int32_t ServiceStub::CmdAppendBundlesDetailsIncrementalBackupSession(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppendBundlesDetailsIncrementalBackupSession(data, reply); +} + +int32_t ServiceStub::CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdPublishIncrementalFile(data, reply); +} + +int32_t ServiceStub::CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdAppIncrementalFileReady(data, reply); +} + +int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdGetIncrementalFileHandle(data, reply); +} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/svc_backup_connection_mock.cpp b/tests/mock/module_ipc/src/svc_backup_connection_mock.cpp new file mode 100644 index 000000000..0ab65af18 --- /dev/null +++ b/tests/mock/module_ipc/src/svc_backup_connection_mock.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "module_ipc/svc_backup_connection.h" + +#include "svc_backup_connection_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +void SvcBackupConnection::OnAbilityConnectDone(const AppExecFwk::ElementName&, const sptr&, int) {} + +void SvcBackupConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName&, int) {} + +ErrCode SvcBackupConnection::ConnectBackupExtAbility(AAFwk::Want &want, int32_t userId) +{ + return BSvcBackupConnection::connect->ConnectBackupExtAbility(want, userId); +} + +ErrCode SvcBackupConnection::DisconnectBackupExtAbility() +{ + return BSvcBackupConnection::connect->DisconnectBackupExtAbility(); +} + +bool SvcBackupConnection::IsExtAbilityConnected() +{ + return BSvcBackupConnection::connect->IsExtAbilityConnected(); +} + +void SvcBackupConnection::SetCallback(function) {} + +void SvcBackupConnection::SetCallDied(function) {} + +sptr SvcBackupConnection::GetBackupExtProxy() +{ + return BSvcBackupConnection::connect->GetBackupExtProxy(); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp new file mode 100644 index 000000000..1cd650835 --- /dev/null +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "module_ipc/svc_session_manager.h" + +#include "svc_session_manager_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +void SvcSessionManager::VerifyCallerAndScenario(uint32_t, IServiceReverse::Scenario) const {} + +ErrCode SvcSessionManager::Active(Impl newImpl) +{ + return BSvcSessionManager::sessionManager->Active(newImpl); +} + +void SvcSessionManager::Deactive(const wptr &, bool) {} + +void SvcSessionManager::VerifyBundleName(string &bundleName) {} + +sptr SvcSessionManager::GetServiceReverseProxy() +{ + return BSvcSessionManager::sessionManager->GetServiceReverseProxy(); +} + +IServiceReverse::Scenario SvcSessionManager::GetScenario() +{ + return BSvcSessionManager::sessionManager->GetScenario(); +} + +bool SvcSessionManager::OnBundleFileReady(const string &bundleName, const string &fileName) +{ + return BSvcSessionManager::sessionManager->OnBundleFileReady(bundleName, fileName); +} + +UniqueFd SvcSessionManager::OnBundleExtManageInfo(const string &bundleName, UniqueFd fd) +{ + return BSvcSessionManager::sessionManager->OnBundleExtManageInfo(bundleName, std::move(fd)); +} + +void SvcSessionManager::RemoveExtInfo(const string &) {} + +wptr SvcSessionManager::GetExtConnection(const BundleName &bundleName) +{ + return BSvcSessionManager::sessionManager->GetExtConnection(bundleName); +} + +sptr SvcSessionManager::GetBackupAbilityExt(const string &bundleName) +{ + return nullptr; +} + +void SvcSessionManager::DumpInfo(const int, const std::vector &) {} + +void SvcSessionManager::InitClient(Impl &) {} + +void SvcSessionManager::SetExtFileNameRequest(const string &bundleName, const string &) {} + +std::set SvcSessionManager::GetExtFileNameRequest(const std::string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetExtFileNameRequest(bundleName); +} + +map::iterator SvcSessionManager::GetBackupExtNameMap(const string &) +{ + return {}; +} + +bool SvcSessionManager::GetSchedBundleName(string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetSchedBundleName(bundleName); +} + +BConstants::ServiceSchedAction SvcSessionManager::GetServiceSchedAction(const std::string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetServiceSchedAction(bundleName); +} + +void SvcSessionManager::SetServiceSchedAction(const string &, BConstants::ServiceSchedAction) {} + +string SvcSessionManager::GetBackupExtName(const string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetBackupExtName(bundleName); +} + +void SvcSessionManager::SetBackupExtInfo(const string &, const string &) {} + +std::string SvcSessionManager::GetBackupExtInfo(const string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetBackupExtInfo(bundleName); +} + +void SvcSessionManager::SetBackupExtName(const string &, const string &) {} + +std::weak_ptr SvcSessionManager::GetSAExtConnection(const BundleName &bundleName) +{ + return BSvcSessionManager::sessionManager->GetSAExtConnection(bundleName); +} + +void SvcSessionManager::AppendBundles(const vector &) {} + +sptr SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +{ + return BSvcSessionManager::sessionManager->CreateBackupConnection(bundleName); +} + +void SvcSessionManager::Start() {} + +void SvcSessionManager::Finish() {} + +bool SvcSessionManager::IsOnAllBundlesFinished() +{ + return BSvcSessionManager::sessionManager->IsOnAllBundlesFinished(); +} + +bool SvcSessionManager::IsOnOnStartSched() +{ + return BSvcSessionManager::sessionManager->IsOnOnStartSched(); +} + +bool SvcSessionManager::NeedToUnloadService() +{ + return BSvcSessionManager::sessionManager->NeedToUnloadService(); +} + +int32_t SvcSessionManager::GetSessionUserId() +{ + return BSvcSessionManager::sessionManager->GetSessionUserId(); +} + +void SvcSessionManager::SetSessionUserId(int32_t) {} + +void SvcSessionManager::SetBundleRestoreType(const std::string &, RestoreTypeEnum) {} + +RestoreTypeEnum SvcSessionManager::GetBundleRestoreType(const std::string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetBundleRestoreType(bundleName); +} + +void SvcSessionManager::SetBundleVersionCode(const std::string &, int64_t) {} + +int64_t SvcSessionManager::GetBundleVersionCode(const std::string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetBundleVersionCode(bundleName); +} + +void SvcSessionManager::SetBundleVersionName(const std::string &, std::string) {} + +std::string SvcSessionManager::GetBundleVersionName(const std::string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetBundleVersionName(bundleName); +} + +void SvcSessionManager::SetBundleDataSize(const std::string &, int64_t) {} + +void SvcSessionManager::BundleExtTimerStart(const std::string &, const Utils::Timer::TimerCallback &) {} + +bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t timeOut, + const Utils::Timer::TimerCallback &callback) +{ + return BSvcSessionManager::sessionManager->UpdateTimer(bundleName, timeOut, callback); +} + +void SvcSessionManager::BundleExtTimerStop(const std::string &) {} + +void SvcSessionManager::IncreaseSessionCnt() {} + +void SvcSessionManager::DecreaseSessionCnt() {} + +int32_t SvcSessionManager::GetMemParaCurSize() +{ + return BSvcSessionManager::sessionManager->GetMemParaCurSize(); +} + +void SvcSessionManager::SetMemParaCurSize(int32_t) {} + +void SvcSessionManager::ClearSessionData() {} + +bool SvcSessionManager::GetIsIncrementalBackup() +{ + return BSvcSessionManager::sessionManager->GetIsIncrementalBackup(); +} + +bool SvcSessionManager::ValidRestoreDataType(RestoreTypeEnum restoreDataType) +{ + return BSvcSessionManager::sessionManager->ValidRestoreDataType(restoreDataType); +} + +void SvcSessionManager::SetIncrementalData(const BIncrementalData &) {} + +int32_t SvcSessionManager::GetIncrementalManifestFd(const string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetIncrementalManifestFd(bundleName); +} + +int64_t SvcSessionManager::GetLastIncrementalTime(const string &bundleName) +{ + return BSvcSessionManager::sessionManager->GetLastIncrementalTime(bundleName); +} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/utils_mock/include/backup_para_mock.h b/tests/mock/utils_mock/include/backup_para_mock.h new file mode 100644 index 000000000..362c4b57a --- /dev/null +++ b/tests/mock/utils_mock/include/backup_para_mock.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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_FILEMGMT_BACKUP_PARA_MOCK_H +#define OHOS_FILEMGMT_BACKUP_PARA_MOCK_H + +#include + +namespace OHOS::FileManagement::Backup { +class BBackupPara { +public: + virtual bool GetBackupDebugOverrideExtensionConfig() = 0; + virtual bool GetBackupOverrideBackupSARelease() = 0; + virtual bool GetBackupOverrideIncrementalRestore() = 0; + virtual std::tuple GetBackupDebugOverrideAccount() = 0; +public: + BBackupPara() = default; + virtual ~BBackupPara() = default; +public: + static inline std::shared_ptr backupPara = nullptr; +}; + +class BackupParaMock : public BBackupPara { +public: + MOCK_METHOD(bool, GetBackupDebugOverrideExtensionConfig, ()); + MOCK_METHOD(bool, GetBackupOverrideBackupSARelease, ()); + MOCK_METHOD(bool, GetBackupOverrideIncrementalRestore, ()); + MOCK_METHOD((std::tuple), GetBackupDebugOverrideAccount, ()); +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_PARA_MOCK_H diff --git a/tests/mock/utils_mock/src/backup_para_mock.cpp b/tests/mock/utils_mock/src/backup_para_mock.cpp new file mode 100644 index 000000000..52f9d9530 --- /dev/null +++ b/tests/mock/utils_mock/src/backup_para_mock.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022-2023 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. + */ + +#include "b_ohos/startup/backup_para.h" +#include "backup_para_mock.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +bool BackupPara::GetBackupDebugOverrideExtensionConfig() +{ + return BBackupPara::backupPara->GetBackupDebugOverrideExtensionConfig(); +} + +bool BackupPara::GetBackupOverrideBackupSARelease() +{ + return BBackupPara::backupPara->GetBackupOverrideBackupSARelease(); +} + +bool BackupPara::GetBackupOverrideIncrementalRestore() +{ + return BBackupPara::backupPara->GetBackupOverrideIncrementalRestore(); +} + +tuple BackupPara::GetBackupDebugOverrideAccount() +{ + return BBackupPara::backupPara->GetBackupDebugOverrideAccount(); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 1c9051f27..88e1adfe8 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -398,10 +398,79 @@ ohos_unittest("backup_restore_deps_manager_test") { use_exceptions = true } +ohos_unittest("backup_service_incremental_test") { + branch_protector_ret = "pac_ret" + + module_out_path = path_module_out_tests + + sources = [ + "${path_backup_mock}/accesstoken/accesstoken_kit_mock.cpp", + "${path_backup_mock}/module_external/src/bms_adapter_mock.cpp", + "${path_backup_mock}/module_external/src/sms_adapter_mock.cpp", + "${path_backup_mock}/module_ipc/src/sa_backup_connection_mock.cpp", + "${path_backup_mock}/module_ipc/src/service_stub_mock.cpp", + "${path_backup_mock}/module_ipc/src/svc_backup_connection_mock.cpp", + "${path_backup_mock}/module_ipc/src/svc_session_manager_mock.cpp", + "${path_backup_mock}/module_sched/sched_scheduler_mock.cpp", + "${path_backup_mock}/utils_mock/src/backup_para_mock.cpp", + "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_incremental_proxy.cpp", + "${path_backup}/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp", + "service_incremental_test.cpp", + ] + + include_dirs = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/services/backup_sa/include", + "${path_backup}/services/backup_sa/include/module_ipc", + "${path_backup}/services/backup_sa/src/module_ipc", + "${path_backup}/tests/unittests/backup_api/backup_impl/include", + "${path_backup}/tests/utils/include/", + "${path_backup_mock}/module_external/include", + "${path_backup_mock}/module_ipc/include", + "${path_backup_mock}/utils_mock/include", + "${path_access_token}/interfaces/innerkits/accesstoken/include", + ] + + deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/tests/utils:backup_test_utils", + "${path_backup}/utils:backup_utils", + "${path_googletest}:gmock_main", + "${path_jsoncpp}:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + + defines = [ "private=public" ] + use_exceptions = true +} + group("backup_sa_ipc_test") { testonly = true deps = [ ":backup_restore_deps_manager_test", + ":backup_service_incremental_test", ":backup_service_scheduler_test", ":backup_service_session_test", ":backup_service_test", diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp new file mode 100644 index 000000000..0ec8befa3 --- /dev/null +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -0,0 +1,543 @@ +/* + * Copyright (c) 2024 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. + */ + +#include + +#include "backup_para_mock.h" +#include "bms_adapter_mock.h" +#include "sa_backup_connection_mock.h" +#include "svc_backup_connection_mock.h" +#include "svc_extension_proxy_mock.h" +#include "svc_session_manager_mock.h" + +#include "service_incremental.cpp" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +void Service::OnStart() {} + +void Service::OnStop() {} + +UniqueFd Service::GetLocalCapabilities() +{ + return UniqueFd(-1); +} + +void Service::StopAll(const wptr &obj, bool force) {} + +string Service::VerifyCallerAndGetCallerName() +{ + return ""; +} + +ErrCode Service::InitRestoreSession(sptr remote) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::InitBackupSession(sptr remote) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::Start() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishFile(const BFileInfo &fileInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppDone(ErrCode errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, + BackupRestoreScenario sennario, ErrCode errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &bundleInfos) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::Finish() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) +{ + return BError(BError::Codes::OK); +} + +void Service::OnBackupExtensionDied(const string &&bundleName) {} + +void Service::ExtConnectDied(const string &callName) {} + +void Service::ExtStart(const string &bundleName) {} + +int Service::Dump(int fd, const vector &args) +{ + return 0; +} + +void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) +{ + GTEST_LOG_(INFO) << "ExtConnectFailed is OK"; +} + +void Service::ExtConnectDone(string bundleName) {} + +void Service::ClearSessionAndSchedInfo(const string &bundleName) {} + +void Service::VerifyCaller() {} + +void Service::VerifyCaller(IServiceReverse::Scenario scenario) {} + +void Service::OnAllBundlesFinished(ErrCode errCode) {} + +void Service::OnStartSched() {} + +void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} + +void Service::SessionDeactive() {} + +ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +{ + return BError(BError::Codes::OK); +} + +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) +{ +} + +void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {} + +void Service::SendEndAppGalleryNotify(const BundleName &bundleName) +{ +} + +void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) +{ +} + +bool SvcRestoreDepsManager::UpdateToRestoreBundleMap(const string &bundleName, const string &fileName) +{ + return true; +} +} // namespace OHOS::FileManagement::Backup + +namespace OHOS::FileManagement::Backup { +using namespace std; +using namespace testing; +using namespace testing::ext; + +constexpr int32_t SERVICE_ID = 5203; + +class ServiceIncrementalTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp() {}; + void TearDown() {}; + + static inline sptr service = nullptr; + static inline shared_ptr param = nullptr; + static inline shared_ptr session = nullptr; + static inline shared_ptr bms = nullptr; + static inline sptr proxy = nullptr; + static inline sptr connect = nullptr; + static inline sptr saConnect = nullptr; +}; + +void ServiceIncrementalTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase enter"; + service = sptr(new Service(SERVICE_ID)); + param = make_shared(); + session = make_shared(); + SvcSessionManagerMock::sessionManager = session; + proxy = sptr(new SvcExtensionProxyMock()); + bms = make_shared(); + BundleMgrAdapterMock::bms = bms; + connect = sptr(new SvcBackupConnectionMock()); + SvcBackupConnectionMock::connect = connect; + saConnect = sptr(new SABackupConnectionMock()); + SABackupConnectionMock::saConnect = saConnect; +} + +void ServiceIncrementalTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "TearDownTestCase enter"; + service = nullptr; + param = nullptr; + SvcSessionManagerMock::sessionManager = nullptr; + session = nullptr; + proxy = nullptr; + BundleMgrAdapterMock::bms = nullptr; + bms = nullptr; + SvcBackupConnectionMock::connect = nullptr; + connect = nullptr; + SABackupConnectionMock::saConnect = nullptr; + saConnect = nullptr; +} + +/** + * @tc.number: SUB_ServiceIncremental_GetUserIdDefault_0000 + * @tc.name: SUB_ServiceIncremental_GetUserIdDefault_0000 + * @tc.desc: 测试 GetUserIdDefault 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetUserIdDefault_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_GetUserIdDefault_0000"; + try { + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(true, 0))); + auto ret = GetUserIdDefault(); + EXPECT_EQ(ret, 0); + + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) + .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); + ret = GetUserIdDefault(); + EXPECT_EQ(ret, DEBUG_ID + 1); + + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()).WillOnce(Return(make_pair(false, 0))); + ret = GetUserIdDefault(); + EXPECT_EQ(ret, BConstants::DEFAULT_USER_ID); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by GetUserIdDefault."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_GetUserIdDefault_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_GetLocalCapabilitiesIncremental_0000 + * @tc.name: SUB_ServiceIncremental_GetLocalCapabilitiesIncremental_0000 + * @tc.desc: 测试 GetLocalCapabilitiesIncremental 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetLocalCapabilitiesIncremental_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_GetLocalCapabilitiesIncremental_0000"; + try { + auto session_ = service->session_; + service->session_ = nullptr; + auto fd = service->GetLocalCapabilitiesIncremental({}); + service->session_ = session_; + EXPECT_EQ(static_cast(fd), -ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by GetLocalCapabilitiesIncremental."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_GetLocalCapabilitiesIncremental_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_StartGetFdTask_0000 + * @tc.name: SUB_ServiceIncremental_StartGetFdTask_0000 + * @tc.desc: 测试 StartGetFdTask 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_StartGetFdTask_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_StartGetFdTask_0000"; + try { + service->StartGetFdTask("", sptr(new Service(SERVICE_ID))); + EXPECT_TRUE(true); + + auto session_ = service->session_; + service->session_ = nullptr; + EXPECT_THROW(service->StartGetFdTask("", service), BError); + + service->session_ = session_; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); + EXPECT_THROW(service->StartGetFdTask("", service), BError); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); + EXPECT_THROW(service->StartGetFdTask("", service), BError); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); + EXPECT_THROW(service->StartGetFdTask("", service), BError); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(proxy)); + EXPECT_THROW(service->StartGetFdTask("", service), BError); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by StartGetFdTask."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_StartGetFdTask_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_GetAppLocalListAndDoIncrementalBackup_0000 + * @tc.name: SUB_ServiceIncremental_GetAppLocalListAndDoIncrementalBackup_0000 + * @tc.desc: 测试 GetAppLocalListAndDoIncrementalBackup 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetAppLocalListAndDoIncrementalBackup_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceIncrementalTest-begin SUB_ServiceIncremental_GetAppLocalListAndDoIncrementalBackup_0000"; + try { + auto session_ = service->session_; + service->session_ = nullptr; + EXPECT_EQ(service->GetAppLocalListAndDoIncrementalBackup(), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + service->session_ = session_; + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by GetAppLocalListAndDoIncrementalBackup."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_GetAppLocalListAndDoIncrementalBackup_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_InitIncrementalBackupSession_0000 + * @tc.name: SUB_ServiceIncremental_InitIncrementalBackupSession_0000 + * @tc.desc: 测试 InitIncrementalBackupSession 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_InitIncrementalBackupSession_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_InitIncrementalBackupSession_0000"; + try { + auto session_ = service->session_; + service->session_ = nullptr; + EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + service->session_ = session_; + + EXPECT_CALL(*session, Active(_)).WillOnce(Return(BError(BError::Codes::OK))); + EXPECT_EQ(service->InitIncrementalBackupSession(nullptr), BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by InitIncrementalBackupSession."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_InitIncrementalBackupSession_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0000 + * @tc.name: SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0000 + * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceIncrementalTest-begin SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0000"; + try { + auto session_ = service->session_; + service->session_ = nullptr; + EXPECT_EQ(service->AppendBundlesIncrementalBackupSession({}), BError(BError::Codes::SA_INVAL_ARG).GetCode()); + service->session_ = session_; + + vector bundleInfos {{ .allToBackup = true }}; + EXPECT_CALL(*bms, GetBundleInfos(_, _)).WillOnce(Return(bundleInfos)); + EXPECT_EQ(service->AppendBundlesIncrementalBackupSession({}), BError(BError::Codes::OK).GetCode()); + + bundleInfos[0].allToBackup = false; + EXPECT_CALL(*bms, GetBundleInfos(_, _)).WillOnce(Return(bundleInfos)); + EXPECT_EQ(service->AppendBundlesIncrementalBackupSession({}), BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by AppendBundlesIncrementalBackupSession."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0100 + * @tc.name: SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0100 + * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << + "ServiceIncrementalTest-begin SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0100"; + try { + vector bundleInfos {{ .allToBackup = true }}; + EXPECT_CALL(*bms, GetBundleInfos(_, _)).WillOnce(Return(bundleInfos)); + EXPECT_EQ(service->AppendBundlesIncrementalBackupSession({}), BError(BError::Codes::OK).GetCode()); + + bundleInfos[0].allToBackup = false; + EXPECT_CALL(*bms, GetBundleInfos(_, _)).WillOnce(Return(bundleInfos)); + EXPECT_EQ(service->AppendBundlesIncrementalBackupSession({}), BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by AppendBundlesIncrementalBackupSession."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_AppendBundlesIncrementalBackupSession_0100"; +} + +/** + * @tc.number: SUB_ServiceIncremental_PublishIncrementalFile_0000 + * @tc.name: SUB_ServiceIncremental_PublishIncrementalFile_0000 + * @tc.desc: 测试 PublishIncrementalFile 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_PublishIncrementalFile_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_PublishIncrementalFile_0000"; + try { + BFileInfo fileInfo; + auto ret = service->PublishIncrementalFile(fileInfo); + EXPECT_EQ(ret, EPERM); + + fileInfo.fileName = "test"; + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); + ret = service->PublishIncrementalFile(fileInfo); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(nullptr)); + ret = service->PublishIncrementalFile(fileInfo); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(proxy)); + EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); + ret = service->PublishIncrementalFile(fileInfo); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); + EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(proxy)); + EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + ret = service->PublishIncrementalFile(fileInfo); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by PublishIncrementalFile."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_PublishIncrementalFile_0000"; +} + +/** + * @tc.number: SUB_ServiceIncremental_PublishSAIncrementalFile_0000 + * @tc.name: SUB_ServiceIncremental_PublishSAIncrementalFile_0000 + * @tc.desc: 测试 PublishSAIncrementalFile 的正常/异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issueIAKC3I + */ +HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_PublishSAIncrementalFile_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceIncrementalTest-begin SUB_ServiceIncremental_PublishSAIncrementalFile_0000"; + try { + BFileInfo fileInfo; + auto ret = service->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); + EXPECT_EQ(ret, BError(BError::Codes::SA_EXT_ERR_CALL).GetCode()); + + fileInfo.owner = "123"; + ret = service->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); + EXPECT_EQ(ret, BError(BError::Codes::SA_EXT_ERR_CALL).GetCode()); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); + ret = service->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); + EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(saConnect)); + EXPECT_CALL(*saConnect, CallRestoreSA(_)).WillOnce(Return(BError(BError::Codes::OK).GetCode())); + ret = service->PublishSAIncrementalFile(fileInfo, UniqueFd(-1)); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by PublishSAIncrementalFile."; + } + GTEST_LOG_(INFO) << "ServiceIncrementalTest-end SUB_ServiceIncremental_PublishSAIncrementalFile_0000"; +} +} \ No newline at end of file -- Gitee