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
16 #include "softbus_utils_mock.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS {
22 void *g_utilsInterface;
23
UtilsInterfaceMock()24 UtilsInterfaceMock::UtilsInterfaceMock()
25 {
26 g_utilsInterface = reinterpret_cast<void *>(this);
27 }
28
~UtilsInterfaceMock()29 UtilsInterfaceMock::~UtilsInterfaceMock()
30 {
31 g_utilsInterface = nullptr;
32 }
33
GetUtilsInterface()34 static UtilsInterface *GetUtilsInterface()
35 {
36 return reinterpret_cast<UtilsInterfaceMock *>(g_utilsInterface);
37 }
38
39 extern "C" {
RegisterTimeoutCallback(int32_t timerFunId,TimerFunCallback callback)40 int32_t RegisterTimeoutCallback(int32_t timerFunId, TimerFunCallback callback)
41 {
42 return GetUtilsInterface()->RegisterTimeoutCallback(timerFunId, callback);
43 }
44
SoftBusTimerInit(void)45 int32_t SoftBusTimerInit(void)
46 {
47 return GetUtilsInterface()->SoftBusTimerInit();
48 }
49
SoftBusTimerDeInit(void)50 void SoftBusTimerDeInit(void)
51 {
52 GetUtilsInterface()->SoftBusTimerDeInit();
53 }
54
CreateSoftBusList(void)55 SoftBusList *CreateSoftBusList(void)
56 {
57 return GetUtilsInterface()->CreateSoftBusList();
58 }
59
DestroySoftBusList(SoftBusList * list)60 void DestroySoftBusList(SoftBusList *list)
61 {
62 GetUtilsInterface()->DestroySoftBusList(list);
63 }
64
ConvertBytesToHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)65 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen)
66 {
67 return GetUtilsInterface()->ConvertBytesToHexString(outBuf, outBufLen, inBuf, inLen);
68 }
69
ConvertBtMacToStrNoColon(char * strMac,uint32_t strMacLen,const uint8_t * binMac,uint32_t binMacLen)70 int32_t ConvertBtMacToStrNoColon(char *strMac, uint32_t strMacLen, const uint8_t *binMac,
71 uint32_t binMacLen)
72 {
73 return GetUtilsInterface()->ConvertBtMacToStrNoColon(strMac, strMacLen, binMac, binMacLen);
74 }
75
ConvertHexStringToBytes(unsigned char * outBuf,uint32_t outBufLen,const char * inBuf,uint32_t inLen)76 int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, const char *inBuf, uint32_t inLen)
77 {
78 return GetUtilsInterface()->ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
79 }
80
ConvertBytesToUpperCaseHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)81 int32_t ConvertBytesToUpperCaseHexString(char *outBuf, uint32_t outBufLen,
82 const unsigned char *inBuf, uint32_t inLen)
83 {
84 return GetUtilsInterface()->ConvertBytesToUpperCaseHexString(outBuf, outBufLen, inBuf, inLen);
85 }
86
GenerateRandomStr(char * str,uint32_t size)87 int32_t GenerateRandomStr(char *str, uint32_t size)
88 {
89 return GetUtilsInterface()->GenerateRandomStr(str, size);
90 }
91
IsValidString(const char * input,uint32_t maxLen)92 bool IsValidString(const char *input, uint32_t maxLen)
93 {
94 return GetUtilsInterface()->IsValidString(input, maxLen);
95 }
96
ConvertBtMacToBinary(const char * strMac,uint32_t strMacLen,uint8_t * binMac,uint32_t binMacLen)97 int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, uint32_t binMacLen)
98 {
99 return GetUtilsInterface()->ConvertBtMacToBinary(strMac, strMacLen, binMac, binMacLen);
100 }
101
ConvertBtMacToStr(char * strMac,uint32_t strMacLen,const uint8_t * binMac,uint32_t binMacLen)102 int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen)
103 {
104 return GetUtilsInterface()->ConvertBtMacToStr(strMac, strMacLen, binMac, binMacLen);
105 }
106
ConvertReverseBtMacToStr(char * strMac,uint32_t strMacLen,const uint8_t * binMac,uint32_t binMacLen)107 int32_t ConvertReverseBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen)
108 {
109 return GetUtilsInterface()->ConvertReverseBtMacToStr(strMac, strMacLen, binMac, binMacLen);
110 }
111
ConvertBtMacToU64(const char * strMac,uint32_t strMacLen,uint64_t * u64Mac)112 int32_t ConvertBtMacToU64(const char *strMac, uint32_t strMacLen, uint64_t *u64Mac)
113 {
114 return GetUtilsInterface()->ConvertBtMacToU64(strMac, strMacLen, u64Mac);
115 }
116
ConvertU64MacToStr(uint64_t u64Mac,char * strMac,uint32_t strMacLen)117 int32_t ConvertU64MacToStr(uint64_t u64Mac, char *strMac, uint32_t strMacLen)
118 {
119 return GetUtilsInterface()->ConvertU64MacToStr(u64Mac, strMac, strMacLen);
120 }
121
Int64ToString(int64_t src,char * buf,uint32_t bufLen)122 bool Int64ToString(int64_t src, char *buf, uint32_t bufLen)
123 {
124 return GetUtilsInterface()->Int64ToString(src, buf, bufLen);
125 }
126
StrCmpIgnoreCase(const char * str1,const char * str2)127 int32_t StrCmpIgnoreCase(const char *str1, const char *str2)
128 {
129 return GetUtilsInterface()->StrCmpIgnoreCase(str1, str2);
130 }
131
StringToUpperCase(const char * str,char * buf,int32_t size)132 int32_t StringToUpperCase(const char *str, char *buf, int32_t size)
133 {
134 return GetUtilsInterface()->StringToUpperCase(str, buf, size);
135 }
136
StringToLowerCase(const char * str,char * buf,int32_t size)137 int32_t StringToLowerCase(const char *str, char *buf, int32_t size)
138 {
139 return GetUtilsInterface()->StringToLowerCase(str, buf, size);
140 }
141
WriteInt32ToBuf(uint8_t * buf,uint32_t dataLen,int32_t * offSet,int32_t data)142 int32_t WriteInt32ToBuf(uint8_t *buf, uint32_t dataLen, int32_t *offSet, int32_t data)
143 {
144 return GetUtilsInterface()->WriteInt32ToBuf(buf, dataLen, offSet, data);
145 }
146
WriteUint8ToBuf(uint8_t * buf,uint32_t dataLen,int32_t * offSet,uint8_t data)147 int32_t WriteUint8ToBuf(uint8_t *buf, uint32_t dataLen, int32_t *offSet, uint8_t data)
148 {
149 return GetUtilsInterface()->WriteUint8ToBuf(buf, dataLen, offSet, data);
150 }
151
ReadInt32FromBuf(uint8_t * buf,uint32_t dataLen,int32_t * offSet,int32_t * data)152 int32_t ReadInt32FromBuf(uint8_t *buf, uint32_t dataLen, int32_t *offSet, int32_t *data)
153 {
154 return GetUtilsInterface()->ReadInt32FromBuf(buf, dataLen, offSet, data);
155 }
156
157
ReadUint8FromBuf(uint8_t * buf,uint32_t dataLen,int32_t * offSet,uint8_t * data)158 int32_t ReadUint8FromBuf(uint8_t *buf, uint32_t dataLen, int32_t *offSet, uint8_t *data)
159 {
160 return GetUtilsInterface()->ReadUint8FromBuf(buf, dataLen, offSet, data);
161 }
162
SetSignalingMsgSwitchOn(void)163 void SetSignalingMsgSwitchOn(void)
164 {
165 GetUtilsInterface()->SetSignalingMsgSwitchOn();
166 }
167
SetSignalingMsgSwitchOff(void)168 void SetSignalingMsgSwitchOff(void)
169 {
170 GetUtilsInterface()->SetSignalingMsgSwitchOff();
171 }
172
GetSignalingMsgSwitch(void)173 bool GetSignalingMsgSwitch(void)
174 {
175 return GetUtilsInterface()->GetSignalingMsgSwitch();
176 }
177 }
178 } // namespace OHOS