• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_FILEMGMT_BACKUP_B_JSONUTIL_MOCK_MOCK_H
17 #define OHOS_FILEMGMT_BACKUP_B_JSONUTIL_MOCK_MOCK_H
18 
19 #include <gmock/gmock.h>
20 
21 #include "b_jsonutil/b_jsonutil.h"
22 
23 namespace OHOS::FileManagement::Backup {
24 class BBJsonUtil {
25 public:
26     virtual BJsonUtil::BundleDetailInfo ParseBundleNameIndexStr (const std::string&) = 0;
27     virtual std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> BuildBundleInfos(
28         const std::vector<std::string>&, const std::vector<std::string>&, std::vector<std::string>&, int32_t,
29         std::map<std::string, bool>&) = 0;
30     virtual void ParseBundleInfoJson(const std::string&, std::vector<BJsonUtil::BundleDetailInfo>&,
31         BJsonUtil::BundleDetailInfo, bool&, int32_t) = 0;
32     virtual bool FindBundleInfoByName(std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>>&, std::string&,
33         const std::string&, BJsonUtil::BundleDetailInfo&) = 0;
34     virtual bool BuildExtensionErrInfo(std::string&, int, std::string) = 0;
35     virtual std::string BuildBundleNameIndexInfo(const std::string&, int) = 0;
36     virtual bool BuildExtensionErrInfo(std::string&, std::map<std::string, std::vector<int>>) = 0;
37     virtual bool BuildOnProcessRetInfo(std::string&, std::string) = 0;
38     virtual bool BuildOnProcessErrInfo(std::string&, std::string, int) = 0;
39     virtual bool BuildBundleInfoJson(int32_t, std::string&) = 0;
40     virtual bool HasUnicastInfo(std::string&) = 0;
41     virtual std::string BuildInitSessionErrInfo(int32_t, std::string, std::string) = 0;
42     virtual bool WriteToStr(std::vector<BJsonUtil::BundleDataSize>&, size_t, std::string, std::string&) = 0;
43 public:
44     BBJsonUtil() = default;
45     virtual ~BBJsonUtil() = default;
46 public:
47     static inline std::shared_ptr<BBJsonUtil> jsonUtil = nullptr;
48 };
49 
50 class BJsonUtilMock : public BBJsonUtil {
51 public:
52     MOCK_METHOD(BJsonUtil::BundleDetailInfo, ParseBundleNameIndexStr, (const std::string&));
53     MOCK_METHOD((std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>>), BuildBundleInfos,
54         ((const std::vector<std::string>&), (const std::vector<std::string>&), (std::vector<std::string>&), int32_t,
55         (std::map<std::string, bool>&)));
56     MOCK_METHOD(void, ParseBundleInfoJson, (const std::string&, (std::vector<BJsonUtil::BundleDetailInfo>&),
57         BJsonUtil::BundleDetailInfo, bool&, int32_t));
58     MOCK_METHOD(bool, FindBundleInfoByName, ((std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>>&),
59         std::string&, const std::string&, BJsonUtil::BundleDetailInfo&));
60     MOCK_METHOD(bool, BuildExtensionErrInfo, (std::string&, int, std::string));
61     MOCK_METHOD(std::string, BuildBundleNameIndexInfo, (const std::string&, int));
62     MOCK_METHOD(bool, BuildExtensionErrInfo, (std::string&, (std::map<std::string, std::vector<int>>)));
63     MOCK_METHOD(bool, BuildOnProcessRetInfo, (std::string&, std::string));
64     MOCK_METHOD(bool, BuildOnProcessErrInfo, (std::string&, std::string, int));
65     MOCK_METHOD(bool, BuildBundleInfoJson, (int32_t, std::string&));
66     MOCK_METHOD(bool, HasUnicastInfo, (std::string&));
67     MOCK_METHOD(std::string, BuildInitSessionErrInfo, (int32_t, std::string, std::string));
68     MOCK_METHOD(bool, WriteToStr, (std::vector<BJsonUtil::BundleDataSize>&, size_t, std::string, std::string&));
69 };
70 } // namespace OHOS::FileManagement::Backup
71 #endif // OHOS_FILEMGMT_BACKUP_B_JSONUTIL_MOCK_MOCK_H
72