• 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 #include <gtest/gtest.h>
17 #include <securec.h>
18 
19 #include "lnn_net_builder_deps_mock.h"
20 #include "softbus_adapter_mem.h"
21 #include "softbus_errcode.h"
22 #include "softbus_log.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 void *g_netBuilderDepsInterface;
NetBuilderDepsInterfaceMock()29 NetBuilderDepsInterfaceMock::NetBuilderDepsInterfaceMock()
30 {
31     g_netBuilderDepsInterface = reinterpret_cast<void *>(this);
32 }
33 
~NetBuilderDepsInterfaceMock()34 NetBuilderDepsInterfaceMock::~NetBuilderDepsInterfaceMock()
35 {
36     g_netBuilderDepsInterface = nullptr;
37 }
38 
GetNetBuilderDepsInterface()39 static NetBuilderDepsInterface *GetNetBuilderDepsInterface()
40 {
41     return reinterpret_cast<NetBuilderDepsInterfaceMock *>(g_netBuilderDepsInterface);
42 }
43 
44 extern "C" {
LnnGetSettingDeviceName(char * deviceName,uint32_t len)45 int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
46 {
47     return GetNetBuilderDepsInterface()->LnnGetSettingDeviceName(deviceName, len);
48 }
49 
AuthGetDeviceUuid(int64_t authId,char * uuid,uint16_t size)50 int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size)
51 {
52     return GetNetBuilderDepsInterface()->AuthGetDeviceUuid(authId, uuid, size);
53 }
54 
LnnDeleteMetaInfo(const char * udid,ConnectionAddrType type)55 int32_t LnnDeleteMetaInfo(const char *udid, ConnectionAddrType type)
56 {
57     return GetNetBuilderDepsInterface()->LnnDeleteMetaInfo(udid, type);
58 }
59 
TransGetConnByChanId(int32_t channelId,int32_t channelType,int32_t * connId)60 int32_t TransGetConnByChanId(int32_t channelId, int32_t channelType, int32_t* connId)
61 {
62     return GetNetBuilderDepsInterface()->TransGetConnByChanId(channelId, channelType, connId);
63 }
64 
AuthMetaStartVerify(uint32_t connectionId,const uint8_t * key,uint32_t keyLen,uint32_t requestId,const AuthVerifyCallback * callBack)65 int32_t AuthMetaStartVerify(uint32_t connectionId, const uint8_t *key, uint32_t keyLen,
66     uint32_t requestId, const AuthVerifyCallback *callBack)
67 {
68     return GetNetBuilderDepsInterface()->AuthMetaStartVerify(connectionId, key, keyLen, requestId, callBack);
69 }
70 
AuthGenRequestId(void)71 uint32_t AuthGenRequestId(void)
72 {
73     return GetNetBuilderDepsInterface()->AuthGenRequestId();
74 }
75 
AuthHandleLeaveLNN(int64_t authId)76 void AuthHandleLeaveLNN(int64_t authId)
77 {
78     return GetNetBuilderDepsInterface()->AuthHandleLeaveLNN(authId);
79 }
80 
ActionOfLnnGetSettingDeviceName(char * deviceName,uint32_t len)81 int32_t NetBuilderDepsInterfaceMock::ActionOfLnnGetSettingDeviceName(char *deviceName, uint32_t len)
82 {
83     if (deviceName == NULL) {
84         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid para");
85         return SOFTBUS_ERR;
86     }
87     if (memcpy_s(deviceName, len, "abc", strlen("abc") + 1) != EOK) {
88         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy info fail");
89         return SOFTBUS_ERR;
90     }
91     return SOFTBUS_OK;
92 }
93 }
94 }