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 <map> 18 #include <string> 19 #include <vector> 20 #include "store/cursor.h" 21 #include "store/general_value.h" 22 namespace OHOS { 23 namespace DistributedData { 24 class CursorMock : public DistributedData::Cursor { 25 public: 26 using ResultSet = std::vector<std::map<std::string, DistributedData::Value>>; 27 explicit CursorMock(std::shared_ptr<ResultSet> resultSet); 28 ~CursorMock(); 29 int32_t GetColumnNames(std::vector<std::string> &names) const override; 30 int32_t GetColumnName(int32_t col, std::string &name) const override; 31 int32_t GetColumnType(int32_t col) const override; 32 int32_t GetCount() const override; 33 int32_t MoveToFirst() override; 34 int32_t MoveToNext() override; 35 int32_t MoveToPrev() override; 36 int32_t GetEntry(DistributedData::VBucket &entry) override; 37 int32_t GetRow(DistributedData::VBucket &data) override; 38 int32_t Get(int32_t col, DistributedData::Value &value) override; 39 int32_t Get(const std::string &col, DistributedData::Value &value) override; 40 int32_t Close() override; 41 bool IsEnd() override; 42 43 private: 44 std::shared_ptr<ResultSet> resultSet_; 45 int32_t index_ = 0; 46 }; 47 } // namespace DistributedData 48 } // namespace OHOS 49 #endif // OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CURSOR_MOCK_H 50