• 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 #ifndef OHOS_DM_DISTRIBUTED_KV_DATA_MANAGER_MOCK_H
16 #define OHOS_DM_DISTRIBUTED_KV_DATA_MANAGER_MOCK_H
17 
18 #include <gmock/gmock.h>
19 
20 #include "distributed_kv_data_manager.h"
21 
22 namespace OHOS {
23 namespace DistributedKv {
24 class IDistributedKvDataManager {
25 public:
26     virtual ~IDistributedKvDataManager() = default;
27 
28     virtual Status GetSingleKvStore(const Options &options, const AppId &appId, const StoreId &storeId,
29                                        std::shared_ptr<SingleKvStore> &singleKvStore) = 0;
30     virtual Status GetAllKvStoreId(const AppId &appId, std::vector<StoreId> &storeIds) = 0;
31     virtual Status CloseKvStore(const AppId &appId, const StoreId &storeId) = 0;
32     virtual Status CloseKvStore(const AppId &appId, std::shared_ptr<SingleKvStore> &kvStore) = 0;
33     virtual Status CloseAllKvStore(const AppId &appId) = 0;
34     virtual Status DeleteKvStore(const AppId &appId, const StoreId &storeId, const std::string &path) = 0;
35     virtual Status DeleteAllKvStore(const AppId &appId, const std::string &path);
36     virtual void RegisterKvStoreServiceDeathRecipient(std::shared_ptr<KvStoreDeathRecipient> deathRecipient) = 0;
37     virtual void UnRegisterKvStoreServiceDeathRecipient(std::shared_ptr<KvStoreDeathRecipient> deathRecipient) = 0;
38 
39     virtual void SetExecutors(std::shared_ptr<ExecutorPool> executors) = 0;
40     virtual Status SetEndpoint(std::shared_ptr<Endpoint> endpoint) = 0;
41     virtual Status PutSwitch(const AppId &appId, const SwitchData &data) = 0;
42     virtual std::pair<Status, SwitchData> GetSwitch(const AppId &appId, const std::string &networkId) = 0;
43     virtual Status SubscribeSwitchData(const AppId &appId, std::shared_ptr<KvStoreObserver> observer) = 0;
44     virtual Status UnsubscribeSwitchData(const AppId &appId, std::shared_ptr<KvStoreObserver> observer) = 0;
45     static std::shared_ptr<IDistributedKvDataManager> GetOrCreateDistributedKvDataManager();
46     static void ReleaseDistributedKvDataManager();
47 private:
48     static std::shared_ptr<IDistributedKvDataManager> kvDataMgr_;
49 };
50 
51 class DistributedKvDataManagerMock : public IDistributedKvDataManager {
52 public:
53     MOCK_METHOD(Status, GetSingleKvStore, (const Options &, const AppId &, const StoreId &,
54                             std::shared_ptr<SingleKvStore> &));
55     MOCK_METHOD(Status, GetAllKvStoreId, (const AppId &, std::vector<StoreId> &));
56     MOCK_METHOD(Status, CloseKvStore, (const AppId &, const StoreId &));
57     MOCK_METHOD(Status, CloseKvStore, (const AppId &, std::shared_ptr<SingleKvStore> &));
58     MOCK_METHOD(Status, CloseAllKvStore, (const AppId &));
59     MOCK_METHOD(Status, DeleteKvStore, (const AppId &, const StoreId &, const std::string &));
60     MOCK_METHOD(Status, DeleteAllKvStore, (const AppId &, const std::string &));
61     MOCK_METHOD(void, RegisterKvStoreServiceDeathRecipient, (std::shared_ptr<KvStoreDeathRecipient>));
62     MOCK_METHOD(void, UnRegisterKvStoreServiceDeathRecipient, (std::shared_ptr<KvStoreDeathRecipient>));
63     MOCK_METHOD(void, SetExecutors, (std::shared_ptr<ExecutorPool>));
64     MOCK_METHOD(Status, SetEndpoint, (std::shared_ptr<Endpoint>));
65     MOCK_METHOD(Status, PutSwitch, (const AppId &, const SwitchData &));
66     MOCK_METHOD((std::pair<Status, SwitchData>), GetSwitch, (const AppId &, const std::string &));
67     MOCK_METHOD(Status, SubscribeSwitchData, (const AppId &, std::shared_ptr<KvStoreObserver>));
68     MOCK_METHOD(Status, UnsubscribeSwitchData, (const AppId &, std::shared_ptr<KvStoreObserver>));
69 };
70 }
71 }
72 #endif  // OHOS_DM_DISTRIBUTED_KV_DATA_MANAGER_MOCK_H