• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 PROCESSCOMMUNICATOR_TEST_STUB_H_H
17 #define PROCESSCOMMUNICATOR_TEST_STUB_H_H
18 
19 #include <string>
20 #include <vector>
21 #include <cstdint>
22 #include <functional>
23 
24 #include "iprocess_communicator.h"
25 #include "store_types.h"
26 
27 namespace DistributedDB {
28 class ProcessCommunicatorTestStub : public IProcessCommunicator {
29 public:
ProcessCommunicatorTestStub()30     ProcessCommunicatorTestStub() {}
~ProcessCommunicatorTestStub()31     ~ProcessCommunicatorTestStub() override {}
32 
Start(const std::string & processLabel)33     DBStatus Start(const std::string &processLabel) override
34     {
35         return OK;
36     }
37 
38     // The Stop should only be called after Start successfully
Stop()39     DBStatus Stop() override
40     {
41         return OK;
42     }
43 
RegOnDeviceChange(const OnDeviceChange & callback)44     DBStatus RegOnDeviceChange(const OnDeviceChange &callback) override
45     {
46         return OK;
47     }
RegOnDataReceive(const OnDataReceive & callback)48     DBStatus RegOnDataReceive(const OnDataReceive &callback) override
49     {
50         return OK;
51     }
52 
SendData(const DeviceInfos & dstDevInfo,const uint8_t * data,uint32_t length)53     DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) override
54     {
55         if (isCommErr) {
56             return COMM_FAILURE;
57         }
58         return OK;
59     }
60 
GetMtuSize()61     uint32_t GetMtuSize() override
62     {
63         return 1 * 1024 * 1024; // 1MB
64     }
65 
GetLocalDeviceInfos()66     DeviceInfos GetLocalDeviceInfos() override
67     {
68         DeviceInfos info;
69         info.identifier = "default";
70         return info;
71     }
72 
GetRemoteOnlineDeviceInfosList()73     std::vector<DeviceInfos> GetRemoteOnlineDeviceInfosList() override
74     {
75         std::vector<DeviceInfos> info;
76         return info;
77     }
78 
IsSameProcessLabelStartedOnPeerDevice(const DeviceInfos & peerDevInfo)79     bool IsSameProcessLabelStartedOnPeerDevice(const DeviceInfos &peerDevInfo) override
80     {
81         return true;
82     }
83 
SetCommErr(bool commErr)84     void SetCommErr(bool commErr)
85     {
86         isCommErr = commErr;
87     }
88 
GetDataHeadInfo(DataHeadInfo dataHeadInfo,uint32_t & headLength)89     DBStatus GetDataHeadInfo(DataHeadInfo dataHeadInfo, uint32_t &headLength) override
90     {
91         headLength = dataHeadInfo_.second;
92         return dataHeadInfo_.first;
93     }
94 
GetDataUserInfo(DataUserInfo dataUserInfo,std::vector<UserInfo> & userInfos)95     DBStatus GetDataUserInfo(DataUserInfo dataUserInfo, std::vector<UserInfo> &userInfos) override
96     {
97         userInfos = userInfos_;
98         return getDataUserInfoRet_;
99     }
100 
SetDataUserInfo(const std::vector<UserInfo> & userInfos)101     void SetDataUserInfo(const std::vector<UserInfo> &userInfos)
102     {
103         userInfos_ = userInfos;
104     }
105 
SetDataHeadInfo(std::pair<DBStatus,uint32_t> dataHeadInfo)106     void SetDataHeadInfo(std::pair<DBStatus, uint32_t> dataHeadInfo)
107     {
108         dataHeadInfo_ = dataHeadInfo;
109     }
110 
SetGetDataUserInfoRet(DBStatus ret)111     void SetGetDataUserInfoRet(DBStatus ret)
112     {
113         getDataUserInfoRet_ = ret;
114     }
115 private:
116     bool isCommErr = false;
117     DBStatus getDataUserInfoRet_ = OK;
118     std::vector<UserInfo> userInfos_;
119     std::pair<DBStatus, uint32_t> dataHeadInfo_;
120 };
121 } // namespace DistributedDB
122 
123 #endif // PROCESSCOMMUNICATOR_TEST_STUB_H_H
124