• 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_DISTRIBUTED_DATA_FRAMEWORKS_CONVERTOR_MOCK_H
17 #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_CONVERTOR_MOCK_H
18 #include "convertor.h"
19 #include <gmock/gmock.h>
20 #include <memory>
21 
22 namespace OHOS::DistributedKv {
23 using Key = OHOS::DistributedKv::Blob;
24 using DBKey = DistributedDB::Key;
25 using DBQuery = DistributedDB::Query;
26 
27 class BConvertor {
28 public:
29     virtual std::vector<uint8_t> ToLocalDBKey(const Key&) const = 0;
30     virtual std::vector<uint8_t> ToWholeDBKey(const Key&) const = 0;
31     virtual Key ToKey(DBKey &&key, std::string&) const = 0;
32     virtual std::vector<uint8_t> GetPrefix(const Key&) const = 0;
33     virtual std::vector<uint8_t> GetPrefix(const DataQuery&) const = 0;
34     virtual std::string GetRealKey(const std::string&, const DataQuery&) const = 0;
35     virtual DBQuery GetDBQuery(const DataQuery&) const = 0;
36     virtual std::vector<uint8_t> TrimKey(const Key&) const = 0;
37     BConvertor() = default;
38     virtual ~BConvertor() = default;
39 public:
40     static inline std::shared_ptr<BConvertor> convertor = nullptr;
41 };
42 
43 class ConvertorMock : public BConvertor {
44 public:
45     MOCK_METHOD(std::vector<uint8_t>, ToLocalDBKey, (const Key&), (const));
46     MOCK_METHOD(std::vector<uint8_t>, ToWholeDBKey, (const Key&), (const));
47     MOCK_METHOD(Key, ToKey, (DBKey&&, std::string&), (const));
48     MOCK_METHOD(std::vector<uint8_t>, GetPrefix, (const Key&), (const));
49     MOCK_METHOD(std::vector<uint8_t>, GetPrefix, (const DataQuery&), (const));
50     MOCK_METHOD(std::string, GetRealKey, (const std::string&, const DataQuery&), (const));
51     MOCK_METHOD(DBQuery, GetDBQuery, (const DataQuery&), (const));
52     MOCK_METHOD(std::vector<uint8_t>, TrimKey, (const Key&), (const));
53 };
54 } // namespace OHOS::DistributedKv
55 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_CONVERTOR_MOCK_H