1 /* 2 * Copyright (c) 2023 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 #ifndef OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CURSOR_MOCK_H 16 #define OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CURSOR_MOCK_H 17 #include <gmock/gmock.h> 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "store/cursor.h" 24 #include "store/general_value.h" 25 namespace OHOS { 26 namespace DistributedData { 27 class CursorMock : public DistributedData::Cursor { 28 public: 29 using ResultSet = std::vector<std::map<std::string, DistributedData::Value>>; 30 explicit CursorMock(std::shared_ptr<ResultSet> resultSet); 31 ~CursorMock(); 32 int32_t GetColumnNames(std::vector<std::string> &names) const override; 33 int32_t GetColumnName(int32_t col, std::string &name) const override; 34 int32_t GetColumnType(int32_t col) const override; 35 int32_t GetCount() const override; 36 int32_t MoveToFirst() override; 37 int32_t MoveToNext() override; 38 int32_t MoveToPrev() override; 39 int32_t GetEntry(DistributedData::VBucket &entry) override; 40 int32_t GetRow(DistributedData::VBucket &data) override; 41 int32_t Get(int32_t col, DistributedData::Value &value) override; 42 int32_t Get(const std::string &col, DistributedData::Value &value) override; 43 int32_t Close() override; 44 bool IsEnd() override; 45 46 private: 47 std::shared_ptr<ResultSet> resultSet_; 48 int32_t index_ = 0; 49 }; 50 51 class MockCursor : public DistributedData::Cursor { 52 MOCK_METHOD(int32_t, GetColumnNames, (std::vector<std::string> &names), (const, override)); 53 MOCK_METHOD(int32_t, GetColumnName, (int32_t col, std::string &name), (const, override)); 54 MOCK_METHOD(int32_t, GetColumnType, (int32_t col), (const, override)); 55 MOCK_METHOD(int32_t, GetCount, (), (const, override)); 56 MOCK_METHOD(int32_t, MoveToFirst, (), (override)); 57 MOCK_METHOD(int32_t, MoveToNext, (), (override)); 58 MOCK_METHOD(int32_t, MoveToPrev, (), (override)); 59 MOCK_METHOD(int32_t, GetEntry, (VBucket &entry), (override)); 60 MOCK_METHOD(int32_t, GetRow, (VBucket &data), (override)); 61 MOCK_METHOD(int32_t, Get, (int32_t col, Value &value), (override)); 62 MOCK_METHOD(int32_t, Get, (const std::string &col, Value &value), (override)); 63 MOCK_METHOD(int32_t, Close, (), (override)); 64 MOCK_METHOD(bool, IsEnd, (), (override)); 65 }; 66 } // namespace DistributedData 67 } // namespace OHOS 68 #endif // OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CURSOR_MOCK_H 69