1 /*
2  * Copyright (c) 2022 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 #include "distributed_preferences_database.h"
17 
18 namespace {
19     bool g_mockGetEntriesFromDistributedDBRet = true;
20     bool g_mockPutToDistributedDBRet = true;
21     bool g_mockDeleteToDistributedDBRet = true;
22     bool g_mockClearDatabaseRet = true;
23 }
24 
MockGetEntriesFromDistributedDB(bool mockRet)25 void MockGetEntriesFromDistributedDB(bool mockRet)
26 {
27     g_mockGetEntriesFromDistributedDBRet = mockRet;
28 }
29 
MockPutToDistributedDB(bool mockRet)30 void MockPutToDistributedDB(bool mockRet)
31 {
32     g_mockPutToDistributedDBRet = mockRet;
33 }
34 
MockDeleteToDistributedDB(bool mockRet)35 void MockDeleteToDistributedDB(bool mockRet)
36 {
37     g_mockDeleteToDistributedDBRet = mockRet;
38 }
39 
MockClearDatabase(bool mockRet)40 void MockClearDatabase(bool mockRet)
41 {
42     g_mockClearDatabaseRet = mockRet;
43 }
44 
45 namespace OHOS {
46 namespace Notification {
47 
DistributedPreferencesDatabase()48 DistributedPreferencesDatabase::DistributedPreferencesDatabase() : DistributedFlowControl()
49 {
50     GetKvDataManager();
51 }
52 
~DistributedPreferencesDatabase()53 DistributedPreferencesDatabase::~DistributedPreferencesDatabase()
54 {}
55 
GetEntriesFromDistributedDB(const std::string & prefixKey,std::vector<Entry> & entries)56 bool DistributedPreferencesDatabase::GetEntriesFromDistributedDB(
57     const std::string &prefixKey, std::vector<Entry> &entries)
58 {
59     Entry entry;
60     entry.key = "GetEntriesFromDistributedDB";
61     entries.emplace_back(entry);
62     return g_mockGetEntriesFromDistributedDBRet;
63 }
64 
PutToDistributedDB(const std::string & key,const std::string & value)65 bool DistributedPreferencesDatabase::PutToDistributedDB(const std::string &key, const std::string &value)
66 {
67     return g_mockPutToDistributedDBRet;
68 }
69 
DeleteToDistributedDB(const std::string & key)70 bool DistributedPreferencesDatabase::DeleteToDistributedDB(const std::string &key)
71 {
72     return g_mockDeleteToDistributedDBRet;
73 }
74 
ClearDatabase()75 bool DistributedPreferencesDatabase::ClearDatabase()
76 {
77     return g_mockClearDatabaseRet;
78 }
79 }  // namespace Notification
80 }  // namespace OHOS