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