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 "lnn_decision_db_deps_mock.h"
17
18 #include <securec.h>
19
20 #include "softbus_common.h"
21 #include "softbus_error_code.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25 namespace OHOS {
26 void *g_decisionDbDepsInterface;
DecisionDbDepsInterfaceMock()27 DecisionDbDepsInterfaceMock::DecisionDbDepsInterfaceMock()
28 {
29 g_decisionDbDepsInterface = reinterpret_cast<void *>(this);
30 }
31
~DecisionDbDepsInterfaceMock()32 DecisionDbDepsInterfaceMock::~DecisionDbDepsInterfaceMock()
33 {
34 g_decisionDbDepsInterface = nullptr;
35 }
36
GetDecisionDbDepsInterface()37 static DecisionDbDepsInterfaceMock *GetDecisionDbDepsInterface()
38 {
39 return reinterpret_cast<DecisionDbDepsInterfaceMock *>(g_decisionDbDepsInterface);
40 }
41
DecisionDbAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)42 int32_t DecisionDbDepsInterfaceMock::DecisionDbAsyncCallbackHelper(SoftBusLooper *looper,
43 LnnAsyncCallbackFunc callback, void *para)
44 {
45 if (callback != NULL) {
46 callback(para);
47 return SOFTBUS_OK;
48 }
49 return SOFTBUS_ERR;
50 }
51
52 extern "C" {
LnnGenerateKeyByHuks(struct HksBlob * keyAlias)53 int32_t LnnGenerateKeyByHuks(struct HksBlob *keyAlias)
54 {
55 return GetDecisionDbDepsInterface()->LnnGenerateKeyByHuks(keyAlias);
56 }
57
LnnDeleteKeyByHuks(struct HksBlob * keyAlias)58 int32_t LnnDeleteKeyByHuks(struct HksBlob *keyAlias)
59 {
60 return GetDecisionDbDepsInterface()->LnnDeleteKeyByHuks(keyAlias);
61 }
62
LnnEncryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)63 int32_t LnnEncryptDataByHuks(const struct HksBlob *keyAlias,
64 const struct HksBlob *inData, struct HksBlob *outData)
65 {
66 return GetDecisionDbDepsInterface()->LnnEncryptDataByHuks(keyAlias, inData, outData);
67 }
68
LnnDecryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)69 int32_t LnnDecryptDataByHuks(const struct HksBlob *keyAlias,
70 const struct HksBlob *inData, struct HksBlob *outData)
71 {
72 return GetDecisionDbDepsInterface()->LnnDecryptDataByHuks(keyAlias, inData, outData);
73 }
74
LnnGenerateRandomByHuks(uint8_t * randomKey,uint32_t len)75 int32_t LnnGenerateRandomByHuks(uint8_t *randomKey, uint32_t len)
76 {
77 return GetDecisionDbDepsInterface()->LnnGenerateRandomByHuks(randomKey, len);
78 }
79
OpenDatabase(DbContext ** ctx)80 int32_t OpenDatabase(DbContext **ctx)
81 {
82 return GetDecisionDbDepsInterface()->OpenDatabase(ctx);
83 }
84
CloseDatabase(DbContext * ctx)85 int32_t CloseDatabase(DbContext *ctx)
86 {
87 return GetDecisionDbDepsInterface()->CloseDatabase(ctx);
88 }
89
CreateTable(DbContext * ctx,TableNameID id)90 int32_t CreateTable(DbContext *ctx, TableNameID id)
91 {
92 return GetDecisionDbDepsInterface()->CreateTable(ctx, id);
93 }
94
CheckTableExist(DbContext * ctx,TableNameID id,bool * isExist)95 int32_t CheckTableExist(DbContext *ctx, TableNameID id, bool *isExist)
96 {
97 return GetDecisionDbDepsInterface()->CheckTableExist(ctx, id, isExist);
98 }
99
RemoveRecordByKey(DbContext * ctx,TableNameID id,uint8_t * data)100 int32_t RemoveRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data)
101 {
102 return GetDecisionDbDepsInterface()->RemoveRecordByKey(ctx, id, data);
103 }
104
GetRecordNumByKey(DbContext * ctx,TableNameID id,uint8_t * data)105 int32_t GetRecordNumByKey(DbContext *ctx, TableNameID id, uint8_t *data)
106 {
107 return GetDecisionDbDepsInterface()->GetRecordNumByKey(ctx, id, data);
108 }
109
EncryptedDb(DbContext * ctx,const uint8_t * password,uint32_t len)110 int32_t EncryptedDb(DbContext *ctx, const uint8_t *password, uint32_t len)
111 {
112 return GetDecisionDbDepsInterface()->EncryptedDb(ctx, password, len);
113 }
114
UpdateDbPassword(DbContext * ctx,const uint8_t * password,uint32_t len)115 int32_t UpdateDbPassword(DbContext *ctx, const uint8_t *password, uint32_t len)
116 {
117 return GetDecisionDbDepsInterface()->UpdateDbPassword(ctx, password, len);
118 }
119
QueryRecordByKey(DbContext * ctx,TableNameID id,uint8_t * data,uint8_t ** replyInfo,int infoNum)120 int32_t QueryRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data, uint8_t **replyInfo, int infoNum)
121 {
122 return GetDecisionDbDepsInterface()->QueryRecordByKey(ctx, id, data, replyInfo, infoNum);
123 }
124
LnnGetFullStoragePath(LnnFileId id,char * path,uint32_t len)125 int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len)
126 {
127 return GetDecisionDbDepsInterface()->LnnGetFullStoragePath(id, path, len);
128 }
129
SoftBusReadFullFile(const char * fileName,char * readBuf,uint32_t maxLen)130 int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen)
131 {
132 return GetDecisionDbDepsInterface()->SoftBusReadFullFile(fileName, readBuf, maxLen);
133 }
134
SoftBusWriteFile(const char * fileName,const char * writeBuf,uint32_t len)135 int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len)
136 {
137 return GetDecisionDbDepsInterface()->SoftBusWriteFile(fileName, writeBuf, len);
138 }
139
SoftBusAccessFile(const char * pathName,int32_t mode)140 int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
141 {
142 return GetDecisionDbDepsInterface()->SoftBusAccessFile(pathName, mode);
143 }
144
LnnAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)145 int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para)
146 {
147 return GetDecisionDbDepsInterface()->LnnAsyncCallbackHelper(looper, callback, para);
148 }
149
LnnGetLocalByteInfo(InfoKey key,uint8_t * info,uint32_t len)150 int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len)
151 {
152 return GetDecisionDbDepsInterface()->LnnGetLocalByteInfo(key, info, len);
153 }
154
ConvertBytesToHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)155 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen,
156 const unsigned char *inBuf, uint32_t inLen)
157 {
158 return GetDecisionDbDepsInterface()->ConvertBytesToHexString(outBuf, outBufLen, inBuf, inLen);
159 }
160 } // extern "C"
161 } // namespace OHOS
162