• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MOCK_SYNC_TASK_CONTEXT_H
17 #define MOCK_SYNC_TASK_CONTEXT_H
18 
19 #include <gmock/gmock.h>
20 #include "single_ver_kv_sync_task_context.h"
21 
22 namespace DistributedDB {
23 class MockSyncTaskContext : public SingleVerKvSyncTaskContext {
24 public:
CallIsCurrentSyncTaskCanBeSkipped()25     bool CallIsCurrentSyncTaskCanBeSkipped()
26     {
27         return SingleVerKvSyncTaskContext::IsCurrentSyncTaskCanBeSkipped();
28     }
29 
CallSetSyncMode(int mode)30     void CallSetSyncMode(int mode)
31     {
32         SingleVerKvSyncTaskContext::SetMode(mode);
33     }
34 
35     MOCK_CONST_METHOD0(GetTimerId, TimerId(void));
36 
37     MOCK_CONST_METHOD0(IsTargetQueueEmpty, bool(void));
38 
39     MOCK_METHOD0(MoveToNextTarget, void(void));
40 
41     MOCK_CONST_METHOD0(IsCurrentSyncTaskCanBeSkipped, bool(void));
42 
43     MOCK_METHOD1(SetOperationStatus, void(int));
44 
45     MOCK_METHOD1(SetTaskExecStatus, void(int));
46 
47     MOCK_METHOD0(Clear, void(void));
48 
49     MOCK_CONST_METHOD0(GetRequestSessionId, uint32_t(void));
50 
51     MOCK_CONST_METHOD1(GetSyncStrategy, SyncStrategy(QuerySyncObject &));
52 
CallCommErrHandlerFuncInner(int errCode,uint32_t sessionId)53     void CallCommErrHandlerFuncInner(int errCode, uint32_t sessionId)
54     {
55         SyncTaskContext::CommErrHandlerFuncInner(errCode, sessionId);
56     }
57 
CallSetTaskExecStatus(int status)58     void CallSetTaskExecStatus(int status)
59     {
60         SyncTaskContext::SetTaskExecStatus(status);
61     }
62 
SetLastFullSyncTaskStatus(SyncOperation::Status lastFullSyncTaskStatus)63     void SetLastFullSyncTaskStatus(SyncOperation::Status lastFullSyncTaskStatus)
64     {
65         lastFullSyncTaskStatus_ = static_cast<int>(lastFullSyncTaskStatus);
66     }
67 
RegForkGetDeviceIdFunc(const std::function<void ()> & forkGetDeviceIdFunc)68     void RegForkGetDeviceIdFunc(const std::function<void ()> &forkGetDeviceIdFunc)
69     {
70         forkGetDeviceIdFunc_ = forkGetDeviceIdFunc;
71     }
72 
GetDeviceId()73     std::string GetDeviceId() const override
74     {
75         if (forkGetDeviceIdFunc_) {
76             forkGetDeviceIdFunc_();
77         }
78         return SingleVerKvSyncTaskContext::GetDeviceId();
79     }
80 
SetSyncOperation(SyncOperation * operation)81     void SetSyncOperation(SyncOperation *operation)
82     {
83         syncOperation_ = operation;
84     }
85 private:
86     std::function<void ()> forkGetDeviceIdFunc_;
87 };
88 } // namespace DistributedDB
89 #endif  // #define MOCK_SINGLE_VER_STATE_MACHINE_H