• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_CONNECTION_MOCK_H
17 #define OHOS_CONNECTION_MOCK_H
18 
19 #include "connection.h"
20 
21 namespace DistributedDB {
22 class StoreObserver;
23 }
24 namespace OHOS::NativeRdb {
25 class RdbStoreConfig;
26 class Statement;
27 class MockConnection : public Connection {
28 public:
29     using Info = DistributedRdb::RdbDebugInfo;
30     using SConn = std::shared_ptr<Connection>;
31     using Stmt = std::shared_ptr<Statement>;
32     using Notifier = std::function<void(const DistributedRdb::RdbChangedData &rdbChangedData)>;
33     using Creator = std::pair<int32_t, SConn> (*)(const RdbStoreConfig &config, bool isWriter);
34     using Repairer = int32_t (*)(const RdbStoreConfig &config);
35     using Deleter = int32_t (*)(const RdbStoreConfig &config);
36     using Collector = std::map<std::string, Info> (*)(const RdbStoreConfig &config);
37     using Restorer = int32_t (*)(const RdbStoreConfig &config, const std::string &srcPath, const std::string &destPath);
38     using ReplicaChecker = int32_t (*)(const RdbStoreConfig &config);
39 
40     MOCK_METHOD(int32_t, VerifyAndRegisterHook, (const RdbStoreConfig &config), (override));
41     MOCK_METHOD((std::pair<int32_t, Stmt>), CreateStatement, (const std::string &sql, SConn conn), (override));
42     MOCK_METHOD((std::pair<int32_t, Stmt>), CreateReplicaStatement,
43         (const std::string &sql, SConn conn), (override));
44     MOCK_METHOD(int, CheckReplicaForRestore, (), (override));
45     MOCK_METHOD(int32_t, Rekey, (const RdbStoreConfig::CryptoParam &cryptoParam), (override));
46     MOCK_METHOD(int32_t, GetDBType, (), (const, override));
47     MOCK_METHOD(bool, IsWriter, (), (const, override));
48     MOCK_METHOD(int32_t, ResetKey, (const RdbStoreConfig &config), (override));
49     MOCK_METHOD(int32_t, TryCheckPoint, (bool timeout), (override));
50     MOCK_METHOD(int32_t, LimitWalSize, (), (override));
51     MOCK_METHOD(int32_t, ConfigLocale, (const std::string &localeStr), (override));
52     MOCK_METHOD(int32_t, CleanDirtyData, (const std::string &table, uint64_t cursor), (override));
53     MOCK_METHOD(int32_t, SubscribeTableChanges, (const Notifier &notifier), (override));
54     MOCK_METHOD(int32_t, GetMaxVariable, (), (const, override));
55     MOCK_METHOD(int32_t, GetJournalMode, (), (override));
56     MOCK_METHOD(int32_t, ClearCache, (bool isForceClear), (override));
57     MOCK_METHOD(int32_t, Subscribe, (const std::shared_ptr<DistributedDB::StoreObserver> &observer), (override));
58     MOCK_METHOD(int32_t, Unsubscribe, (const std::shared_ptr<DistributedDB::StoreObserver> &observer), (override));
59     MOCK_METHOD(int32_t, Backup,
60         (const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey, bool isAsync,
61             std::shared_ptr<SlaveStatus> slaveStatus, bool verifyDb),
62         (override));
63     MOCK_METHOD(int32_t, Restore,
64         (const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey,
65             std::shared_ptr<SlaveStatus> slaveStatus),
66         (override));
67     MOCK_METHOD(ExchangeStrategy, GenerateExchangeStrategy, (std::shared_ptr<SlaveStatus> status,
68         bool isReplay), (override));
69     MOCK_METHOD(int, SetKnowledgeSchema, (const DistributedRdb::RdbKnowledgeSchema &schema), (override));
70     MOCK_METHOD(int, CleanDirtyLog, (const std::string &table, uint64_t cursor), (override));
71     MOCK_METHOD(int, RegisterAlgo, (const std::string &clstAlgoName, ClusterAlgoFunc func), (override));
72 };
73 } // namespace OHOS::NativeRdb
74 #endif // OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_INCLUDE_CONNECTION_H
75