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 16 #ifndef SECURITY_GUARD_RDB_STORE_MOCK_H 17 #define SECURITY_GUARD_RDB_STORE_MOCK_H 18 19 #include <cstdint> 20 #include <string> 21 22 #include "gtest/gtest.h" 23 #include "gmock/gmock.h" 24 25 #include "result_set.h" 26 #include "values_bucket.h" 27 #include "rdb_predicates.h" 28 29 namespace OHOS::NativeRdb { 30 constexpr int E_ERROR = -1; 31 constexpr int E_OK = 0; 32 33 class RdbStoreInterface { 34 public: 35 virtual ~RdbStoreInterface() = default; 36 virtual int Insert(int64_t &outRowId, const std::string &table, const NativeRdb::ValuesBucket &initialValues) = 0; 37 virtual int BatchInsert(int64_t &outInsertNum, const std::string &table, 38 const std::vector<NativeRdb::ValuesBucket> &initialBatchValues) = 0; 39 virtual int Update(int &changedRows, const NativeRdb::ValuesBucket &values, 40 const NativeRdb::AbsRdbPredicates &predicates) = 0; 41 virtual int Delete(int &deletedRows, const NativeRdb::AbsRdbPredicates &predicates) = 0; 42 virtual std::shared_ptr<NativeRdb::ResultSet> Query( 43 const NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> columns) = 0; 44 virtual int ExecuteSql(const std::string &sql, const std::vector<ValueObject> &bindArgs) = 0; 45 virtual int ExecuteSql(const std::string &sql) = 0; 46 virtual int ExecuteAndGetLong(int64_t &outValue, const std::string &sql, 47 const std::vector<NativeRdb::ValueObject> &bindArgs = std::vector<NativeRdb::ValueObject>()) = 0; 48 virtual int Count(int64_t &outValue, const NativeRdb::AbsRdbPredicates &predicates) = 0; 49 virtual int BeginTransaction() = 0; 50 virtual int RollBack() = 0; 51 virtual int Commit() = 0; 52 virtual int Attach(const std::string &alias, const std::string &pathName, 53 const std::vector<uint8_t> destEncryptKey) = 0; 54 }; 55 56 class RdbStore : public RdbStoreInterface { 57 public: 58 RdbStore() = default; 59 ~RdbStore() override = default; 60 MOCK_METHOD3(Insert, int(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues)); 61 MOCK_METHOD3(BatchInsert, int(int64_t &outInsertNum, const std::string &table, 62 const std::vector<ValuesBucket> &initialBatchValues)); 63 MOCK_METHOD2(ExecuteSql, int( 64 const std::string &sql, const std::vector<ValueObject> &bindArgs)); 65 MOCK_METHOD1(ExecuteSql, int(const std::string &sql)); 66 MOCK_METHOD3(ExecuteAndGetLong, int(int64_t &outValue, const std::string &sql, 67 const std::vector<ValueObject> &bindArgs)); 68 MOCK_METHOD3(Attach, int( 69 const std::string &alias, const std::string &pathName, const std::vector<uint8_t> destEncryptKey)); 70 MOCK_METHOD2(Count, int(int64_t &outValue, const AbsRdbPredicates &predicates)); 71 MOCK_METHOD2(Query, std::shared_ptr<ResultSet>( 72 const AbsRdbPredicates &predicates, const std::vector<std::string> columns)); 73 MOCK_METHOD3(Update, int(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates)); 74 MOCK_METHOD2(Delete, int(int &deletedRows, const AbsRdbPredicates &predicates)); 75 MOCK_METHOD0(BeginTransaction, int()); 76 MOCK_METHOD0(RollBack, int()); 77 MOCK_METHOD0(Commit, int()); 78 }; 79 } // namespace OHOS::NativeRdb 80 #endif // SECURITY_GUARD_RDB_STORE_MOCK_H