• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LNN_DECISION_DB_DEPS_MOCK_H
17 #define LNN_DECISION_DB_DEPS_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include <securec.h>
21 
22 #include "auth_interface.h"
23 #include "bus_center_event.h"
24 #include "bus_center_manager.h"
25 #include "lnn_async_callback_utils.h"
26 #include "lnn_file_utils.h"
27 #include "lnn_heartbeat_medium_mgr.h"
28 #include "lnn_heartbeat_utils.h"
29 #include "lnn_huks_utils.h"
30 #include "sqlite3_utils.h"
31 
32 #include "softbus_adapter_file.h"
33 #include "softbus_common.h"
34 #include "softbus_error_code.h"
35 #include "softbus_utils.h"
36 
37 namespace OHOS {
38 class DecisionDbDepsInterface {
39 public:
DecisionDbDepsInterface()40     DecisionDbDepsInterface() {};
~DecisionDbDepsInterface()41     virtual ~DecisionDbDepsInterface() {};
42 
43     virtual int32_t LnnGenerateKeyByHuks(struct HksBlob *keyAlias);
44     virtual int32_t LnnDeleteKeyByHuks(struct HksBlob *keyAlias);
45     virtual int32_t LnnEncryptDataByHuks(
46         const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData);
47     virtual int32_t LnnDecryptDataByHuks(
48         const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData);
49     virtual int32_t LnnGenerateRandomByHuks(uint8_t *randomKey, uint32_t len);
50     virtual int32_t OpenDatabase(DbContext **ctx);
51     virtual int32_t CloseDatabase(DbContext *ctx);
52     virtual int32_t CreateTable(DbContext *ctx, TableNameID id);
53     virtual int32_t CheckTableExist(DbContext *ctx, TableNameID id, bool *isExist);
54     virtual int32_t RemoveRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data);
55     virtual int32_t GetRecordNumByKey(DbContext *ctx, TableNameID id, uint8_t *data);
56     virtual int32_t EncryptedDb(DbContext *ctx, const uint8_t *password, uint32_t len);
57     virtual int32_t UpdateDbPassword(DbContext *ctx, const uint8_t *password, uint32_t len);
58     virtual int32_t QueryRecordByKey(
59         DbContext *ctx, TableNameID id, uint8_t *data, uint8_t **replyInfo, int32_t infoNum);
60     virtual int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len);
61     virtual int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen);
62     virtual int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len);
63     virtual int32_t SoftBusAccessFile(const char *pathName, int32_t mode);
64     virtual int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para);
65     virtual int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len);
66     virtual int32_t ConvertBytesToHexString(
67         char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen);
68     virtual void LnnNotifyNetworkStateChanged(SoftBusNetworkState state) = 0;
69     virtual TrustedReturnType AuthHasTrustedRelation(void) = 0;
70     virtual bool IsEnableSoftBusHeartbeat(void) = 0;
71     virtual void LnnNotifyHBRepeat(void) = 0;
72     virtual void LnnHbClearRecvList(void) = 0;
73     virtual int32_t LnnConvertHbTypeToId(LnnHeartbeatType type) = 0;
74     virtual bool LnnVisitHbTypeSet(VisitHbTypeCb callback, LnnHeartbeatType *typeSet, void *data) = 0;
75     virtual int32_t LnnCeEncryptDataByHuks(
76         const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData);
77     virtual int32_t LnnCeDecryptDataByHuks(
78         const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData);
79 };
80 class DecisionDbDepsInterfaceMock : public DecisionDbDepsInterface {
81 public:
82     DecisionDbDepsInterfaceMock();
83     ~DecisionDbDepsInterfaceMock() override;
84     MOCK_METHOD1(LnnGenerateKeyByHuks, int32_t(struct HksBlob *));
85     MOCK_METHOD1(LnnDeleteKeyByHuks, int32_t(struct HksBlob *));
86     MOCK_METHOD3(LnnEncryptDataByHuks, int32_t(const struct HksBlob *, const struct HksBlob *, struct HksBlob *));
87     MOCK_METHOD3(LnnDecryptDataByHuks, int32_t(const struct HksBlob *, const struct HksBlob *, struct HksBlob *));
88     MOCK_METHOD2(LnnGenerateRandomByHuks, int32_t(uint8_t *, uint32_t));
89     MOCK_METHOD1(OpenDatabase, int32_t(DbContext **));
90     MOCK_METHOD1(CloseDatabase, int32_t(DbContext *));
91     MOCK_METHOD2(CreateTable, int32_t(DbContext *, TableNameID));
92     MOCK_METHOD3(CheckTableExist, int32_t(DbContext *, TableNameID, bool *));
93     MOCK_METHOD3(RemoveRecordByKey, int32_t(DbContext *, TableNameID, uint8_t *));
94     MOCK_METHOD3(GetRecordNumByKey, int32_t(DbContext *, TableNameID, uint8_t *));
95     MOCK_METHOD3(EncryptedDb, int32_t(DbContext *, const uint8_t *, uint32_t));
96     MOCK_METHOD3(UpdateDbPassword, int32_t(DbContext *, const uint8_t *, uint32_t));
97     MOCK_METHOD5(QueryRecordByKey, int32_t(DbContext *, TableNameID, uint8_t *, uint8_t **, int));
98     MOCK_METHOD3(LnnGetFullStoragePath, int32_t(LnnFileId, char *, uint32_t));
99     MOCK_METHOD3(SoftBusReadFullFile, int32_t(const char *, char *, uint32_t));
100     MOCK_METHOD3(SoftBusWriteFile, int32_t(const char *, const char *, uint32_t));
101     MOCK_METHOD2(SoftBusAccessFile, int32_t(const char *, int32_t));
102     MOCK_METHOD3(LnnAsyncCallbackHelper, int32_t(SoftBusLooper *, LnnAsyncCallbackFunc, void *));
103     MOCK_METHOD3(LnnGetLocalByteInfo, int32_t(InfoKey, uint8_t *, uint32_t));
104     MOCK_METHOD4(ConvertBytesToHexString, int32_t(char *, uint32_t, const unsigned char *, uint32_t));
105     MOCK_METHOD1(LnnNotifyNetworkStateChanged, void(SoftBusNetworkState));
106     MOCK_METHOD0(AuthHasTrustedRelation, TrustedReturnType(void));
107     MOCK_METHOD0(IsEnableSoftBusHeartbeat, bool(void));
108     MOCK_METHOD0(LnnNotifyHBRepeat, void(void));
109     MOCK_METHOD0(LnnHbClearRecvList, void(void));
110     MOCK_METHOD3(LnnVisitHbTypeSet, bool(VisitHbTypeCb, LnnHeartbeatType *, void *));
111     MOCK_METHOD1(LnnConvertHbTypeToId, int32_t(LnnHeartbeatType));
112     static int32_t DecisionDbAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para);
113     MOCK_METHOD3(LnnCeEncryptDataByHuks, int32_t(const struct HksBlob *, const struct HksBlob *, struct HksBlob *));
114     MOCK_METHOD3(LnnCeDecryptDataByHuks, int32_t(const struct HksBlob *, const struct HksBlob *, struct HksBlob *));
115 };
116 } // namespace OHOS
117 #endif // LNN_DECISION_DB_DEPS_MOCK_H
118