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 #include "notification_rdb_data_mgr.h"
16 #include "rdb_errno.h"
17
18 namespace {
19 bool g_mockInitRet = true;
20 bool g_mockQueryDataRet = true;
21 bool g_mockInsertDataRet = true;
22 bool g_mockInsertBatchDataRet = true;
23 bool g_mockQueryDataBeginWithKeyRet = true;
24 bool g_mockDeleteBathchDataRet = true;
25 bool g_mockDeleteDataRet = true;
26 bool g_mockQueryAllData = true;
27 bool g_mockDropTable = true;
28 }
29
MockInit(bool mockRet)30 void MockInit(bool mockRet)
31 {
32 g_mockInitRet = mockRet;
33 }
34
MockQueryData(bool mockRet)35 void MockQueryData(bool mockRet)
36 {
37 g_mockQueryDataRet = mockRet;
38 }
39
MockInsertData(bool mockRet)40 void MockInsertData(bool mockRet)
41 {
42 g_mockInsertDataRet = mockRet;
43 }
44
MockInsertBatchData(bool mockRet)45 void MockInsertBatchData(bool mockRet)
46 {
47 g_mockInsertBatchDataRet = mockRet;
48 }
49
MockQueryDataBeginWithKey(bool mockRet)50 void MockQueryDataBeginWithKey(bool mockRet)
51 {
52 g_mockQueryDataBeginWithKeyRet = mockRet;
53 }
54
MockDeleteBathchData(bool mockRet)55 void MockDeleteBathchData(bool mockRet)
56 {
57 g_mockDeleteBathchDataRet = mockRet;
58 }
59
MockDeleteData(bool mockRet)60 void MockDeleteData(bool mockRet)
61 {
62 g_mockDeleteDataRet = mockRet;
63 }
64
MockQueryAllData(bool mockRet)65 void MockQueryAllData(bool mockRet)
66 {
67 g_mockQueryAllData = mockRet;
68 }
69
MockDropTable(bool mockRet)70 void MockDropTable(bool mockRet)
71 {
72 g_mockDropTable = mockRet;
73 }
74 namespace OHOS {
75 namespace Notification {
NotificationDataMgr(const NotificationRdbConfig & notificationRdbConfig)76 NotificationDataMgr::NotificationDataMgr(const NotificationRdbConfig ¬ificationRdbConfig)
77 : notificationRdbConfig_(notificationRdbConfig)
78 {
79 }
80
Init()81 int32_t NotificationDataMgr::Init()
82 {
83 if (g_mockInitRet == false) {
84 return NativeRdb::E_ERROR;
85 }
86 return NativeRdb::E_OK;
87 }
88
Destroy()89 int32_t NotificationDataMgr::Destroy()
90 {
91 if (g_mockInitRet == false) {
92 return NativeRdb::E_ERROR;
93 }
94 return NativeRdb::E_OK;
95 }
96
QueryData(const std::string & key,std::string & value,const int32_t & userId)97 int32_t NotificationDataMgr::QueryData(const std::string &key, std::string &value, const int32_t &userId)
98 {
99 if (g_mockQueryDataRet == false) {
100 return NativeRdb::E_EMPTY_VALUES_BUCKET;
101 }
102 return NativeRdb::E_ERROR;
103 }
104
InsertData(const std::string & key,const std::string & value,const int32_t & userId)105 int32_t NotificationDataMgr::InsertData(const std::string &key, const std::string &value, const int32_t &userId)
106 {
107 if (g_mockInsertDataRet == false) {
108 return NativeRdb::E_ERROR;
109 }
110 return NativeRdb::E_OK;
111 }
112
InsertBatchData(const std::unordered_map<std::string,std::string> & values,const int32_t & userId)113 int32_t NotificationDataMgr::InsertBatchData(const std::unordered_map<std::string, std::string> &values,
114 const int32_t &userId)
115 {
116 if (g_mockInsertBatchDataRet == false) {
117 return NativeRdb::E_ERROR;
118 }
119 return NativeRdb::E_OK;
120 }
121
QueryDataBeginWithKey(const std::string & key,std::unordered_map<std::string,std::string> & values,const int32_t & userId)122 int32_t NotificationDataMgr::QueryDataBeginWithKey(
123 const std::string &key, std::unordered_map<std::string, std::string> &values, const int32_t &userId)
124 {
125 if (g_mockQueryDataBeginWithKeyRet == false) {
126 return NativeRdb::E_ERROR;
127 }
128 return NativeRdb::E_OK;
129 }
130
DeleteBathchData(const std::vector<std::string> & keys,const int32_t & userId)131 int32_t NotificationDataMgr::DeleteBathchData(const std::vector<std::string> &keys, const int32_t &userId)
132 {
133 if (g_mockDeleteBathchDataRet == false) {
134 return NativeRdb::E_ERROR;
135 }
136 return NativeRdb::E_OK;
137 }
138
DeleteData(const std::string & key,const int32_t & userId)139 int32_t NotificationDataMgr::DeleteData(const std::string &key, const int32_t &userId)
140 {
141 if (g_mockDeleteDataRet == false) {
142 return NativeRdb::E_ERROR;
143 }
144 return NativeRdb::E_OK;
145 }
146
QueryAllData(std::unordered_map<std::string,std::string> & values,const int32_t & userId)147 int32_t NotificationDataMgr::QueryAllData(std::unordered_map<std::string, std::string> &values, const int32_t &userId)
148 {
149 if (g_mockQueryAllData == false) {
150 return NativeRdb::E_ERROR;
151 }
152 return NativeRdb::E_OK;
153 }
154
DropUserTable(const int32_t userId)155 int32_t NotificationDataMgr::DropUserTable(const int32_t userId)
156 {
157 if (g_mockDropTable == false) {
158 return NativeRdb::E_ERROR;
159 }
160 return NativeRdb::E_OK;
161 }
162 }
163 }
164