• 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 "lnn_local_ledger_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 
26 namespace OHOS {
27 void *g_localLedgerDepsInterface;
28 constexpr char DEFAULT_DEVICE_NAME[] = "OpenHarmony";
29 constexpr char DEFAULT_DEVICE_UDID[] = "aaabbbcccdddeeefffggghhh";
30 constexpr char DEFAULT_DEVICE_TYPE[] = "default_type";
31 constexpr int32_t SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO_FD = -1;
32 
LocalLedgerDepsInterfaceMock()33 LocalLedgerDepsInterfaceMock::LocalLedgerDepsInterfaceMock()
34 {
35     g_localLedgerDepsInterface = reinterpret_cast<void *>(this);
36 }
37 
~LocalLedgerDepsInterfaceMock()38 LocalLedgerDepsInterfaceMock::~LocalLedgerDepsInterfaceMock()
39 {
40     g_localLedgerDepsInterface = nullptr;
41 }
42 
GetLocalLedgerDepsInterface()43 static LocalLedgerDepsInterfaceMock *GetLocalLedgerDepsInterface()
44 {
45     return reinterpret_cast<LocalLedgerDepsInterfaceMock *>(g_localLedgerDepsInterface);
46 }
47 
LedgerGetCommonDevInfo(const CommonDeviceKey key,char * value,uint32_t len)48 int32_t LocalLedgerDepsInterfaceMock::LedgerGetCommonDevInfo(const CommonDeviceKey key,
49     char *value, uint32_t len)
50 {
51     if (value == nullptr) {
52         return SOFTBUS_ERR;
53     }
54     switch (key) {
55         case COMM_DEVICE_KEY_DEVNAME:
56             if (strcpy_s(value, len, DEFAULT_DEVICE_NAME) != EOK) {
57                 return SOFTBUS_ERR;
58             }
59             break;
60         case COMM_DEVICE_KEY_UDID:
61             if (strcpy_s(value, len, DEFAULT_DEVICE_UDID) != EOK) {
62                 return SOFTBUS_ERR;
63             }
64             break;
65         case COMM_DEVICE_KEY_DEVTYPE:
66             if (strcpy_s(value, len, DEFAULT_DEVICE_TYPE) != EOK) {
67                 return SOFTBUS_ERR;
68             }
69             break;
70         default:
71             break;
72     }
73     return SOFTBUS_OK;
74 }
75 
LedgerSoftBusRegBusCenterVarDump(char * dumpVar,SoftBusVarDumpCb cb)76 int32_t LocalLedgerDepsInterfaceMock::LedgerSoftBusRegBusCenterVarDump(char *dumpVar, SoftBusVarDumpCb cb)
77 {
78     int32_t ret = SOFTBUS_ERR;
79     if (cb != nullptr) {
80         ret = cb(SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO_FD);
81     }
82     return ret;
83 }
84 
85 extern "C" {
LnnGetNetCapabilty(void)86 uint32_t LnnGetNetCapabilty(void)
87 {
88     return GetLocalLedgerDepsInterface()->LnnGetNetCapabilty();
89 }
90 
SoftBusGenerateRandomArray(unsigned char * randStr,uint32_t len)91 int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
92 {
93     return GetLocalLedgerDepsInterface()->SoftBusGenerateRandomArray(randStr, len);
94 }
95 
GetCommonDevInfo(const CommonDeviceKey key,char * value,uint32_t len)96 int32_t GetCommonDevInfo(const CommonDeviceKey key, char *value, uint32_t len)
97 {
98     return GetLocalLedgerDepsInterface()->GetCommonDevInfo(key, value, len);
99 }
100 
LnnInitLocalP2pInfo(NodeInfo * info)101 int32_t LnnInitLocalP2pInfo(NodeInfo *info)
102 {
103     return GetLocalLedgerDepsInterface()->LnnInitLocalP2pInfo(info);
104 }
105 
SoftBusRegBusCenterVarDump(char * dumpVar,SoftBusVarDumpCb cb)106 int32_t SoftBusRegBusCenterVarDump(char *dumpVar, SoftBusVarDumpCb cb)
107 {
108     return GetLocalLedgerDepsInterface()->SoftBusRegBusCenterVarDump(dumpVar, cb);
109 }
110 
LnnInitOhosAccount(void)111 int32_t LnnInitOhosAccount(void)
112 {
113     return GetLocalLedgerDepsInterface()->LnnInitOhosAccount();
114 }
115 } // extern "C"
116 } // namespace OHOS
117