回退 'Pull Request !8116 : add lane_manage file tdd'

This commit is contained in:
oh_ci 2024-10-28 06:09:35 +00:00 committed by Gitee
parent 06eb433ac5
commit 1d026d745a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 75 additions and 1946 deletions

View File

@ -1530,11 +1530,12 @@ ohos_unittest("LNNLaneLinkTest") {
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_select.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_vap_info_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_select_rule.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_ptk_info_virtual.c",
"$dsoftbus_root_path/core/bus_center/service/src/bus_center_manager.c",
"$dsoftbus_root_path/core/bus_center/utils/src/lnn_async_callback_utils.c",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane_link/lnn_lane_link_deps_mock.cpp",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane_link/lnn_lane_link_test.cpp",
"$dsoftbus_root_path/tests/core/bus_center/mock_common/src/lnn_async_callback_mock.cpp",
]
if (dsoftbus_feature_conn_p2p && softbus_communication_wifi_feature) {
@ -2081,6 +2082,7 @@ ohos_unittest("LNNLaneLinkWifiDirectTest") {
sources = [
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_link_wifi_direct.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_vap_info_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_ptk_info_virtual.c",
"$dsoftbus_root_path/core/bus_center/service/src/bus_center_manager.c",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane_link/lnn_lane_link_deps_mock.cpp",
@ -2284,88 +2286,6 @@ ohos_unittest("LNNPhysicalSubnetManagerTest") {
}
}
ohos_unittest("LNNCtrlLaneMockTest") {
module_out_path = module_output_path
sources = [
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_ctrl_lane.c",
"$dsoftbus_root_path/core/bus_center/service/src/bus_center_manager.c",
"lane/ctrl_lane/lnn_ctrl_lane_deps_mock.cpp",
"lane/ctrl_lane/lnn_ctrl_lane_test.cpp",
"lane/src/lnn_lane_deps_mock.cpp",
]
include_dirs = [
"lane/include",
"lane/trans_lane",
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/adapter/common/bus_center/include/",
"$dsoftbus_root_path/adapter/common/net/hdi/include",
"$dsoftbus_root_path/adapter/common/net/wifi/include",
"$dsoftbus_root_path/core/adapter/bus_center/include",
"$dsoftbus_root_path/core/authentication/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/decision_center/include",
"$dsoftbus_root_path/core/bus_center/lnn/disc_mgr/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/heartbeat/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src",
"$dsoftbus_root_path/core/bus_center/lnn/meta_node/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/monitor/include",
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/bus_center/utils/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/p2p/interface",
"$dsoftbus_root_path/core/connection/p2p/common/include",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/interfaces/inner_kits/lnn",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"unittest/common/",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
]
deps = [
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/common/dfx/log:softbus_dfx_log",
]
if (is_standard_system) {
external_deps = [
"cJSON:cjson",
"c_utils:utils",
"device_auth:deviceauth_sdk",
"googletest:gmock",
"googletest:gtest_main",
"hilog:libhilog",
]
if (!defined(ohos_lite) && softbus_communication_wifi_feature == true) {
external_deps += [ "wifi:wifi_sdk" ]
}
} else {
external_deps = [
"cJSON:cjson",
"c_utils:utils",
"googletest:gmock",
"googletest:gtest_main",
"hilog:libhilog",
"wifi:wifi_sdk",
]
}
}
group("unittest") {
testonly = true
deps = [
@ -2373,7 +2293,6 @@ group("unittest") {
":LNNBtNetworkImplMockTest",
":LNNConnectionFsmMockTest",
":LNNConnectionFsmTest",
":LNNCtrlLaneMockTest",
":LNNDataCloudSyncMockTest",
":LNNDataCloudSyncTest",
":LNNDeviceNameInfoTest",

View File

@ -1,106 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "lnn_ctrl_lane_deps_mock.h"
#include "softbus_error_code.h"
using namespace testing::ext;
using namespace testing;
namespace OHOS {
void *g_ctrlLaneIf;
CtrlLaneDepsInterfaceMock::CtrlLaneDepsInterfaceMock()
{
g_ctrlLaneIf = static_cast<void *>(this);
}
CtrlLaneDepsInterfaceMock::~CtrlLaneDepsInterfaceMock()
{
g_ctrlLaneIf = nullptr;
}
static CtrlLaneDepsInterface *GetCtrlLaneIf()
{
return static_cast<CtrlLaneDepsInterfaceMock *>(g_ctrlLaneIf);
}
int32_t CtrlLaneDepsInterfaceMock::BuildLinkSuccess(const LinkRequest *reqInfo, uint32_t reqId,
const LaneLinkCb *callback)
{
LaneLinkInfo linkInfo = {};
linkInfo.type = reqInfo->linkType;
callback->onLaneLinkSuccess(reqId, reqInfo->linkType, &linkInfo);
return SOFTBUS_OK;
}
int32_t CtrlLaneDepsInterfaceMock::BuildLinkFail(const LinkRequest *reqInfo, uint32_t reqId,
const LaneLinkCb *callback)
{
callback->onLaneLinkFail(reqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL, reqInfo->linkType);
return SOFTBUS_OK;
}
extern "C" {
int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *recommendList, LanePreferredLinkList *request)
{
return GetCtrlLaneIf()->SelectAuthLane(networkId, recommendList, request);
}
int32_t BuildLink(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *callback)
{
return GetCtrlLaneIf()->BuildLink(reqInfo, reqId, callback);
}
int32_t DestroyLink(const char *networkId, uint32_t laneReqId, LaneLinkType type)
{
return GetCtrlLaneIf()->DestroyLink(networkId, laneReqId, type);
}
uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
{
return GetCtrlLaneIf()->GenerateLaneId(localUdid, remoteUdid, linkType);
}
int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide)
{
return GetCtrlLaneIf()->AddLaneResourceToPool(linkInfo, laneId, isServerSide);
}
int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide)
{
return GetCtrlLaneIf()->DelLaneResourceByLaneId(laneId, isServerSide);
}
int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resourceItem)
{
return GetCtrlLaneIf()->FindLaneResourceByLaneId(laneId, resourceItem);
}
int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource)
{
return GetCtrlLaneIf()->FindLaneResourceByLinkType(peerUdid, type, resource);
}
void FreeLaneReqId(uint32_t laneReqId)
{
GetCtrlLaneIf()->FreeLaneReqId(laneReqId);
}
int32_t LaneInfoProcess(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
{
return GetCtrlLaneIf()->LaneInfoProcess(linkInfo, connInfo, profile);
}
}
} // namespace OHOS

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LNN_CTRL_LANE_DEPS_MOCK_H
#define LNN_CTRL_LANE_DEPS_MOCK_H
#include <gmock/gmock.h>
#include "lnn_lane_link.h"
namespace OHOS {
class CtrlLaneDepsInterface {
public:
CtrlLaneDepsInterface() {};
virtual ~CtrlLaneDepsInterface() {};
virtual int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *recommendList,
LanePreferredLinkList *request) = 0;
virtual int32_t BuildLink(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *callback) = 0;
virtual int32_t DestroyLink(const char *networkId, uint32_t laneReqId, LaneLinkType type) = 0;
virtual uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType) = 0;
virtual int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide) = 0;
virtual int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide) = 0;
virtual int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resourceItem) = 0;
virtual int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource) = 0;
virtual void FreeLaneReqId(uint32_t laneReqId) = 0;
virtual int32_t LaneInfoProcess(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile) = 0;
};
class CtrlLaneDepsInterfaceMock : public CtrlLaneDepsInterface {
public:
CtrlLaneDepsInterfaceMock();
~CtrlLaneDepsInterfaceMock() override;
MOCK_METHOD3(SelectAuthLane, int32_t (const char *, LanePreferredLinkList *, LanePreferredLinkList *));
MOCK_METHOD3(BuildLink, int32_t (const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *callback));
MOCK_METHOD3(DestroyLink, int32_t (const char *networkId, uint32_t laneReqId, LaneLinkType type));
MOCK_METHOD3(GenerateLaneId, uint64_t (const char *localUdid, const char *remoteUdid, LaneLinkType linkType));
MOCK_METHOD3(AddLaneResourceToPool, int32_t (const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide));
MOCK_METHOD2(DelLaneResourceByLaneId, int32_t (uint64_t laneId, bool isServerSide));
MOCK_METHOD2(FindLaneResourceByLaneId, int32_t (uint64_t laneId, LaneResource *resourceItem));
MOCK_METHOD3(FindLaneResourceByLinkType, int32_t (const char *peerUdid, LaneLinkType type, LaneResource *resource));
MOCK_METHOD1(FreeLaneReqId, void (uint32_t laneReqId));
MOCK_METHOD3(LaneInfoProcess, int32_t (const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo,
LaneProfile *profile));
static int32_t BuildLinkSuccess(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *callback);
static int32_t BuildLinkFail(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *callback);
};
} // namespace OHOS
#endif // LNN_CTRL_LANE_DEPS_MOCK_H

View File

@ -1,370 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <thread>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <securec.h>
#include "lnn_ctrl_lane.h"
#include "lnn_ctrl_lane_deps_mock.h"
#include "lnn_lane_deps_mock.h"
#include "lnn_lane_interface.h"
#include "softbus_error_code.h"
namespace OHOS {
using namespace testing::ext;
using namespace testing;
constexpr uint64_t LANE_ID = 1122334455667788;
constexpr char NETWORK_ID[] = "123456789";
constexpr char UDID[] = "1122334455667788";
static int32_t g_errCode = SOFTBUS_LANE_ERR_BASE;
static void OnLaneAllocSuccess(uint32_t laneHandle, const LaneConnInfo *info)
{
ASSERT_NE(info, nullptr) << "invalid info";
g_errCode = SOFTBUS_OK;
}
static void OnLaneAllocFail(uint32_t laneHandle, int32_t errCode)
{
GTEST_LOG_(INFO) << "alloc lane failed, laneReqId=" << laneHandle << ", errCode=" << errCode;
g_errCode = errCode;
}
static void OnLaneFreeSuccess(uint32_t laneHandle)
{
GTEST_LOG_(INFO) << "free lane success, laneReqId=" << laneHandle;
}
static void OnLaneFreeFail(uint32_t laneHandle, int32_t errCode)
{
GTEST_LOG_(INFO) << "free lane failed, laneReqId=" << laneHandle << ", errCode=" << errCode;
}
static LaneAllocListener g_listener = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
static bool IsNegotiateChannelNeeded(const char *remoteNetworkId, enum WifiDirectLinkType linkType)
{
return false;
}
static struct WifiDirectManager g_manager = {
.isNegotiateChannelNeeded= IsNegotiateChannelNeeded,
};
class LNNCtrlLaneMockTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void LNNCtrlLaneMockTest::SetUpTestCase()
{
GTEST_LOG_(INFO) << "LNNCtrlLaneMockTest start";
LnnInitLnnLooper();
}
void LNNCtrlLaneMockTest::TearDownTestCase()
{
LnnDeinitLnnLooper();
GTEST_LOG_(INFO) << "LNNCtrlLaneMockTest end";
}
void LNNCtrlLaneMockTest::SetUp()
{
}
void LNNCtrlLaneMockTest::TearDown()
{
}
/*
* @tc.name: LNN_CRTL_ALLOC_LANE_001
* @tc.desc: ctrl alloclane -> test param check
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_ALLOC_LANE_001, TestSize.Level1)
{
LaneInterface *ctrlObj = CtrlLaneGetInstance();
EXPECT_TRUE(ctrlObj != nullptr);
ctrlObj->deinit();
ctrlObj->init(nullptr);
ctrlObj->init(nullptr);
uint32_t laneReqId = 1;
int32_t ret = ctrlObj->allocLaneByQos(INVALID_LANE_REQ_ID, nullptr, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = ctrlObj->allocLaneByQos(laneReqId, nullptr, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
LaneAllocInfo info = {};
info.type = LANE_TYPE_BUTT;
ret = ctrlObj->allocLaneByQos(laneReqId, &info, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ctrlObj->deinit();
}
/*
* @tc.name: LNN_CRTL_ALLOC_LANE_002
* @tc.desc: ctrl alloclane -> test ConvertAuthLinkToLaneLink(wifi/br/ble)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_ALLOC_LANE_002, TestSize.Level1)
{
LaneInterface *ctrlObj = CtrlLaneGetInstance();
EXPECT_TRUE(ctrlObj != nullptr);
ctrlObj->init(nullptr);
AuthLinkTypeList authList = {};
authList.linkTypeNum = 1;
authList.linkType[0] = AUTH_LINK_TYPE_WIFI;
NiceMock<CtrlLaneDepsInterfaceMock> ctrlMock;
NiceMock<LaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, GetAuthLinkTypeList).WillOnce(Return(SOFTBUS_INVALID_PARAM))
.WillOnce(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
EXPECT_CALL(ctrlMock, SelectAuthLane).WillRepeatedly(Return(SOFTBUS_LANE_NO_AVAILABLE_LINK));
EXPECT_CALL(ctrlMock, FreeLaneReqId).WillRepeatedly(Return());
uint32_t laneReqId = 1;
LaneAllocInfo info = {};
info.type = LANE_TYPE_CTRL;
int32_t ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
authList.linkType[0] = AUTH_LINK_TYPE_BR;
EXPECT_CALL(laneMock, GetAuthLinkTypeList)
.WillOnce(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
authList.linkType[0] = AUTH_LINK_TYPE_BLE;
EXPECT_CALL(laneMock, GetAuthLinkTypeList)
.WillOnce(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
ctrlObj->deinit();
}
/*
* @tc.name: LNN_CRTL_ALLOC_LANE_003
* @tc.desc: ctrl alloclane -> test ConvertAuthLinkToLaneLink(p2p/enhanced_p2p/max)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_ALLOC_LANE_003, TestSize.Level1)
{
LaneInterface *ctrlObj = CtrlLaneGetInstance();
EXPECT_TRUE(ctrlObj != nullptr);
ctrlObj->init(nullptr);
AuthLinkTypeList authList = {};
authList.linkTypeNum = 1;
authList.linkType[0] = AUTH_LINK_TYPE_P2P;
NiceMock<CtrlLaneDepsInterfaceMock> ctrlMock;
NiceMock<LaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, GetAuthLinkTypeList).WillOnce(Return(SOFTBUS_INVALID_PARAM))
.WillOnce(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
EXPECT_CALL(ctrlMock, SelectAuthLane).WillRepeatedly(Return(SOFTBUS_LANE_NO_AVAILABLE_LINK));
EXPECT_CALL(ctrlMock, FreeLaneReqId).WillRepeatedly(Return());
uint32_t laneReqId = 1;
LaneAllocInfo info = {};
info.type = LANE_TYPE_CTRL;
int32_t ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
authList.linkType[0] = AUTH_LINK_TYPE_ENHANCED_P2P;
EXPECT_CALL(laneMock, GetAuthLinkTypeList)
.WillOnce(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
authList.linkType[0] = AUTH_LINK_TYPE_MAX;
EXPECT_CALL(laneMock, GetAuthLinkTypeList)
.WillOnce(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
ctrlObj->deinit();
}
/*
* @tc.name: LNN_CRTL_ALLOC_LANE_004
* @tc.desc: ctrl alloclane -> test build fail
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_ALLOC_LANE_004, TestSize.Level1)
{
LaneInterface *ctrlObj = CtrlLaneGetInstance();
EXPECT_TRUE(ctrlObj != nullptr);
ctrlObj->init(nullptr);
AuthLinkTypeList authList = {};
authList.linkTypeNum = 1;
authList.linkType[0] = AUTH_LINK_TYPE_WIFI;
NiceMock<CtrlLaneDepsInterfaceMock> ctrlMock;
NiceMock<LaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, GetAuthLinkTypeList).WillRepeatedly(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
EXPECT_CALL(ctrlMock, SelectAuthLane).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, BuildLink).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_CALL(ctrlMock, FreeLaneReqId).WillRepeatedly(Return());
uint32_t laneReqId = 1;
LaneAllocInfo info = {};
info.type = LANE_TYPE_CTRL;
g_errCode = SOFTBUS_LANE_ERR_BASE;
int32_t ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_errCode, SOFTBUS_INVALID_PARAM);
ctrlObj->deinit();
}
/*
* @tc.name: LNN_CRTL_ALLOC_LANE_005
* @tc.desc: ctrl alloclane -> test build success
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_ALLOC_LANE_005, TestSize.Level1)
{
LaneInterface *ctrlObj = CtrlLaneGetInstance();
EXPECT_TRUE(ctrlObj != nullptr);
ctrlObj->init(nullptr);
AuthLinkTypeList authList = {};
authList.linkTypeNum = 1;
authList.linkType[0] = AUTH_LINK_TYPE_WIFI;
NiceMock<CtrlLaneDepsInterfaceMock> ctrlMock;
NiceMock<LaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, GetAuthLinkTypeList).WillRepeatedly(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
EXPECT_CALL(ctrlMock, SelectAuthLane).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, BuildLink(_, _, NotNull())).WillRepeatedly(ctrlMock.BuildLinkSuccess);
EXPECT_CALL(ctrlMock, GenerateLaneId).WillOnce(Return(INVALID_LANE_ID)).WillRepeatedly(Return(LANE_ID));
EXPECT_CALL(ctrlMock, FreeLaneReqId).WillRepeatedly(Return());
EXPECT_CALL(ctrlMock, AddLaneResourceToPool).WillOnce(Return(SOFTBUS_INVALID_PARAM))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, LaneInfoProcess).WillOnce(Return(SOFTBUS_INVALID_PARAM)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetLocalStrInfo).WillOnce(Return(SOFTBUS_INVALID_PARAM))
.WillRepeatedly(Return(SOFTBUS_OK));
uint32_t laneReqId = 1;
LaneAllocInfo info = {};
info.type = LANE_TYPE_CTRL;
g_errCode = SOFTBUS_LANE_ERR_BASE;
int32_t ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_LANE_GET_LEDGER_INFO_ERR);
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_LANE_ID_GENERATE_FAIL);
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_INVALID_PARAM);
g_errCode = SOFTBUS_LANE_ERR_BASE;
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_LANE_ERR_BASE);
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_OK);
ctrlObj->deinit();
}
/*
* @tc.name: LNN_CRTL_ALLOC_LANE_006
* @tc.desc: ctrl alloclane -> test free
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_ALLOC_LANE_006, TestSize.Level1)
{
LaneInterface *ctrlObj = CtrlLaneGetInstance();
EXPECT_TRUE(ctrlObj != nullptr);
ctrlObj->init(nullptr);
AuthLinkTypeList authList = {};
authList.linkTypeNum = 1;
authList.linkType[0] = AUTH_LINK_TYPE_WIFI;
NiceMock<CtrlLaneDepsInterfaceMock> ctrlMock;
NiceMock<LaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, GetAuthLinkTypeList).WillRepeatedly(DoAll(SetArgPointee<1>(authList), Return(SOFTBUS_OK)));
EXPECT_CALL(ctrlMock, SelectAuthLane).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, BuildLink(_, _, NotNull())).WillRepeatedly(ctrlMock.BuildLinkSuccess);
EXPECT_CALL(ctrlMock, DestroyLink).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID));
EXPECT_CALL(ctrlMock, AddLaneResourceToPool).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, DelLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, FindLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ctrlMock, FreeLaneReqId).WillRepeatedly(Return());
EXPECT_CALL(ctrlMock, LaneInfoProcess).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetNetworkIdByUdid).WillOnce(Return(SOFTBUS_INVALID_PARAM))
.WillRepeatedly(Return(SOFTBUS_OK));
uint32_t laneReqId = 1;
LaneAllocInfo info = {};
info.type = LANE_TYPE_CTRL;
g_errCode = SOFTBUS_LANE_ERR_BASE;
int32_t ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_OK);
ret = ctrlObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
g_errCode = SOFTBUS_LANE_ERR_BASE;
ret = ctrlObj->allocLaneByQos(laneReqId, &info, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(g_errCode, SOFTBUS_OK);
ret = ctrlObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = ctrlObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
ctrlObj->deinit();
}
/*
* @tc.name: LNN_CRTL_IS_AUTH_REUSE_P2P_001
* @tc.desc: test IsAuthReuseP2p
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNCtrlLaneMockTest, LNN_CRTL_IS_AUTH_REUSE_P2P_001, TestSize.Level1)
{
NiceMock<CtrlLaneDepsInterfaceMock> ctrlMock;
NiceMock<LaneDepsInterfaceMock> laneMock;
EXPECT_CALL(ctrlMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
bool ret = IsAuthReuseP2p(NETWORK_ID, UDID, AUTH_LINK_TYPE_ENHANCED_P2P);
EXPECT_TRUE(ret);
ret = IsAuthReuseP2p(NETWORK_ID, UDID, AUTH_LINK_TYPE_P2P);
EXPECT_TRUE(ret);
ret = IsAuthReuseP2p(NETWORK_ID, UDID, AUTH_LINK_TYPE_MAX);
EXPECT_FALSE(ret);
}
} // namespace OHOS

View File

@ -192,7 +192,6 @@ public:
const AuthConnCallback *callback, bool isMeta);
static int32_t ActionOfConnOpened(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback,
bool isMeta);
static int32_t socketEvent;
};
} // namespace OHOS
#endif // LNN_LANE_DEPS_MOCK_H

View File

@ -127,7 +127,6 @@ int32_t LaneDepsInterfaceMock::ActionOfStartBaseClient(ListenerModule module, co
return SOFTBUS_OK;
}
int32_t LaneDepsInterfaceMock::socketEvent = SOFTBUS_SOCKET_OUT;
int32_t LaneDepsInterfaceMock::ActionOfAddTrigger(ListenerModule module, int32_t fd, TriggerType trigger)
{
(void)trigger;
@ -136,7 +135,7 @@ int32_t LaneDepsInterfaceMock::ActionOfAddTrigger(ListenerModule module, int32_t
GTEST_LOG_(INFO) << "invalid lane onDataEvent";
return SOFTBUS_OK;
}
return g_baseListener.onDataEvent(module, socketEvent, fd);
return g_baseListener.onDataEvent(module, SOFTBUS_SOCKET_OUT, fd);
}
int32_t LaneDepsInterfaceMock::ActionOfConnOpenFailed(const AuthConnInfo *info, uint32_t requestId,

View File

@ -46,7 +46,6 @@ using namespace testing;
constexpr char NODE_NETWORK_ID[] = "111122223333abcdef";
constexpr char PEER_IP_HML[] = "172.30.0.1";
constexpr char PEER_WLAN_ADDR[] = "172.30.0.1";
constexpr char PEER_MAC[] = "a1:b2:c3:d4:e5:f6";
constexpr char LOCAL_MAC[] = "a2:b2:c3:d4:e5:f6";
constexpr char PEER_UDID[] = "111122223333abcdef";
@ -73,13 +72,13 @@ constexpr uint32_t ROM_NUM2 = 2;
static SoftBusCond g_cond = {0};
static SoftBusMutex g_lock = {0};
static int32_t g_errCode = 0;
static void OnLaneAllocSuccess(uint32_t laneHandle, const LaneConnInfo *info);
static void OnLaneAllocFail(uint32_t laneHandle, int32_t errCode);
static void OnLaneFreeSuccess(uint32_t laneHandle);
static void OnLaneFreeFail(uint32_t laneHandle, int32_t errCode);
static int32_t g_errCode = 0;
static LaneAllocListener g_listener = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
@ -236,8 +235,7 @@ static void OnLaneLinkFailForDetect(uint32_t reqId, int32_t reason, LaneLinkType
(void)reqId;
(void)linkType;
GTEST_LOG_(INFO) << "on laneLink fail for detect";
EXPECT_EQ(reason, SOFTBUS_LANE_DETECT_TIMEOUT);
CondSignal();
EXPECT_EQ(reason, SOFTBUS_OK);
}
static void OnLaneAllocSuccessForHml(uint32_t laneHandle, const LaneConnInfo *info)
@ -1237,14 +1235,6 @@ HWTEST_F(LNNLaneMockTest, LANE_INFO_005, TestSize.Level1)
info.type = LANE_COC;
ret = LaneInfoProcess(&info, &connInfo, &profile);
EXPECT_EQ(ret, SOFTBUS_OK);
info.type = LANE_HML_RAW;
ret = LaneInfoProcess(&info, &connInfo, &profile);
EXPECT_EQ(ret, SOFTBUS_OK);
info.type = LANE_LINK_TYPE_BUTT;
ret = LaneInfoProcess(&info, &connInfo, &profile);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
}
/*
@ -1308,37 +1298,6 @@ HWTEST_F(LNNLaneMockTest, LNN_LANE_PROFILE_001, TestSize.Level1)
(void)UnbindLaneIdFromProfile(0, profileId);
}
/*
* @tc.name: LNN_LANE_PROFILE_002
* @tc.desc: BindLaneIdToProfile
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LNN_LANE_PROFILE_002, TestSize.Level1)
{
uint64_t laneId = 0x1000000000000002;
uint32_t profileId = 111111;
LaneProfile profile = {};
int32_t ret = GetLaneProfile(profileId, &profile);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
uint64_t *laneReqIdList = nullptr;
uint32_t listSize = 0;
ret = GetLaneIdList(profileId, &laneReqIdList, &listSize);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
profile.linkType = LANE_P2P;
profile.content = LANE_T_FILE;
profile.priority = LANE_PRI_LOW;
ret = BindLaneIdToProfile(laneId, &profile);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = BindLaneIdToProfile(laneId, &profile);
EXPECT_EQ(ret, SOFTBUS_OK);
(void)UnbindLaneIdFromProfile(laneId, profileId);
}
/*
* @tc.name: LNN_SELECT_LANE_001
* @tc.desc: SelectLane
@ -2251,7 +2210,6 @@ HWTEST_F(LNNLaneMockTest, LANE_DETECT_RELIABILITY_001, TestSize.Level1)
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, ConnOpenClientSocket).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, AddTrigger).WillRepeatedly(Return(SOFTBUS_OK));
LaneLinkInfo linkInfo;
linkInfo.type = LANE_WLAN_2P4G;
@ -2414,73 +2372,6 @@ HWTEST_F(LNNLaneMockTest, LANE_DETECT_RELIABILITY_004, TestSize.Level1)
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LANE_DETECT_RELIABILITY_005
* @tc.desc: WLAN LANE DETECT RELIABILITY, SOFTBUS_SOCKET_EXCEPTION
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LANE_DETECT_RELIABILITY_005, TestSize.Level1)
{
const char *ipAddr = "127.0.0.1";
LaneLinkCb cb = {
.onLaneLinkSuccess = OnLaneLinkSuccessForDetect,
.onLaneLinkFail = OnLaneLinkFailForDetect,
};
LaneLinkInfo linkInfo;
linkInfo.type = LANE_WLAN_5G;
linkInfo.linkInfo.wlan.connInfo.port = PORT_A;
EXPECT_EQ(strcpy_s(linkInfo.linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN, ipAddr), EOK);
const LnnLaneManager *laneManager = GetLaneManager();
LaneType laneType = LANE_TYPE_TRANS;
int32_t laneReqId = laneManager->lnnGetLaneHandle(laneType);
EXPECT_TRUE(laneReqId != INVALID_LANE_REQ_ID);
LaneDepsInterfaceMock::socketEvent = SOFTBUS_SOCKET_EXCEPTION;
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, ConnOpenClientSocket).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, AddTrigger).WillRepeatedly(LaneDepsInterfaceMock::ActionOfAddTrigger);
char buf[] = "lanedetect";
EXPECT_CALL(mock, ConnSendSocketData).WillRepeatedly(Return(sizeof(buf)));
int32_t ret = LaneDetectReliability(laneReqId, &linkInfo, &cb);
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LANE_DETECT_RELIABILITY_006
* @tc.desc: WLAN LANE DETECT RELIABILITY TIMEOUT
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LANE_DETECT_RELIABILITY_006, TestSize.Level1)
{
const char *ipAddr = "127.0.0.1";
LaneLinkCb cb = {
.onLaneLinkSuccess = OnLaneLinkSuccessForDetect,
.onLaneLinkFail = OnLaneLinkFailForDetect,
};
LaneLinkInfo linkInfo;
linkInfo.type = LANE_WLAN_5G;
linkInfo.linkInfo.wlan.connInfo.port = PORT_A;
EXPECT_EQ(strcpy_s(linkInfo.linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN, ipAddr), EOK);
const LnnLaneManager *laneManager = GetLaneManager();
LaneType laneType = LANE_TYPE_TRANS;
int32_t laneReqId = laneManager->lnnGetLaneHandle(laneType);
EXPECT_TRUE(laneReqId != INVALID_LANE_REQ_ID);
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, ConnOpenClientSocket).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, AddTrigger).WillRepeatedly(Return(SOFTBUS_OK));
char buf[] = "lanedetect";
EXPECT_CALL(mock, ConnSendSocketData).WillRepeatedly(Return(sizeof(buf)));
int32_t ret = LaneDetectReliability(laneReqId, &linkInfo, &cb);
EXPECT_EQ(ret, SOFTBUS_OK);
CondWait();
}
/*
* @tc.name: LANE_INIT_RELIABLITY_001
* @tc.desc: LANE INIT RELIABLITY TEST
@ -3358,8 +3249,6 @@ HWTEST_F(LNNLaneMockTest, LNN_LANE_13, TestSize.Level1)
int32_t ret = LnnRequestLane(laneReqId, &requestOption, &g_listener2);
EXPECT_EQ(ret, SOFTBUS_LANE_WIFI_OFF);
ret = LnnFreeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_LANE_NOT_FOUND);
}
/*
@ -3676,172 +3565,4 @@ HWTEST_F(LNNLaneMockTest, LNN_LANE_25, TestSize.Level1)
int32_t ret = LaneCapCheck(NODE_NETWORK_ID, linkType);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: LNN_LANE_UPDATE_LANE_ID_001
* @tc.desc: test UpdateLaneResourceLaneId
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LNN_LANE_UPDATE_LANE_ID_001, TestSize.Level1)
{
LaneLinkInfo linkInfo = {};
linkInfo.type = LANE_HML;
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.p2p.connInfo.peerIp, IP_LEN, PEER_IP_HML, strlen(PEER_IP_HML)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.peerUdid, UDID_BUF_LEN, PEER_UDID, strlen(PEER_UDID)), EOK);
NiceMock<LaneDepsInterfaceMock> laneDepMock;
EXPECT_CALL(laneDepMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
uint64_t laneId = LANE_ID_BASE;
uint64_t laneIdNew = LANE_ID_BASE + 1;
int32_t ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = UpdateLaneResourceLaneId(laneId, laneIdNew, PEER_UDID);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = DelLaneResourceByLaneId(laneIdNew, false);
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LNN_LANE_DETECT_ENABLE_WIFI_DIRECT_001
* @tc.desc: test DetectEnableWifiDirectApply & DetectDisableWifiDirectApply
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LNN_LANE_DETECT_DISABLE_WIFI_DIRECT_001, TestSize.Level1)
{
LaneLinkInfo linkInfo = {};
linkInfo.type = LANE_HML;
linkInfo.linkInfo.p2p.bw = LANE_BW_160M;
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.p2p.connInfo.peerIp, IP_LEN, PEER_IP_HML, strlen(PEER_IP_HML)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.peerUdid, UDID_BUF_LEN, PEER_UDID, strlen(PEER_UDID)), EOK);
NiceMock<LaneDepsInterfaceMock> laneDepMock;
EXPECT_CALL(laneDepMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneDepMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
uint64_t laneId = LANE_ID_BASE;
int32_t ret = AddLaneResourceToPool(&linkInfo, laneId, true);
EXPECT_EQ(ret, SOFTBUS_OK);
linkInfo.type = LANE_HML_RAW;
uint64_t laneIdNew = LANE_ID_BASE + 1;
ret = AddLaneResourceToPool(&linkInfo, laneIdNew, false);
EXPECT_EQ(ret, SOFTBUS_OK);
DetectDisableWifiDirectApply();
ret = DelLaneResourceByLaneId(laneId, true);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = DelLaneResourceByLaneId(laneIdNew, false);
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LNN_CHECK_LANE_RESOURCE_NUM_001
* @tc.desc: test CheckLaneResourceNumByLinkType
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LNN_CHECK_LANE_RESOURCE_NUM_001, TestSize.Level1)
{
LaneLinkInfo linkInfo = {};
linkInfo.type = LANE_HML;
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.p2p.connInfo.peerIp, IP_LEN, PEER_IP_HML, strlen(PEER_IP_HML)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.peerUdid, UDID_BUF_LEN, PEER_UDID, strlen(PEER_UDID)), EOK);
NiceMock<LaneDepsInterfaceMock> laneDepMock;
EXPECT_CALL(laneDepMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
int32_t laneNum = 0;
int32_t ret = CheckLaneResourceNumByLinkType(nullptr, LANE_HML, &laneNum);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = CheckLaneResourceNumByLinkType(nullptr, LANE_LINK_TYPE_BUTT, &laneNum);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = CheckLaneResourceNumByLinkType(PEER_UDID, LANE_HML, &laneNum);
EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
uint64_t laneId = LANE_ID_BASE;
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = CheckLaneResourceNumByLinkType(PEER_UDID, LANE_HML, &laneNum);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = DelLaneResourceByLaneId(laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LNN_ADD_LANE_IS_VALID_LINK_ADDR_001
* @tc.desc: test IsValidLinkAddr(hml/br/ble)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LNN_ADD_LANE_IS_VALID_LINK_ADDR_001, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> laneDepMock;
EXPECT_CALL(laneDepMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
LaneLinkInfo linkInfo = {};
linkInfo.type = LANE_HML;
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.p2p.connInfo.peerIp, IP_LEN, PEER_IP_HML, strlen(PEER_IP_HML)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.br.brMac, BT_MAC_LEN, PEER_MAC, strlen(PEER_MAC)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.ble.bleMac, BT_MAC_LEN, PEER_MAC, strlen(PEER_MAC)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.peerUdid, UDID_BUF_LEN, PEER_UDID, strlen(PEER_UDID)), EOK);
uint64_t laneId = LANE_ID_BASE;
int32_t ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
linkInfo.type = LANE_BR;
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
linkInfo.type = LANE_BLE;
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = ClearLaneResourceByLaneId(laneId);
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LNN_ADD_LANE_IS_VALID_LINK_ADDR_002
* @tc.desc: test IsValidLinkAddr(coc_direct/wlan)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LNN_ADD_LANE_IS_VALID_LINK_ADDR_002, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> laneDepMock;
EXPECT_CALL(laneDepMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
LaneLinkInfo linkInfo = {};
linkInfo.type = LANE_COC_DIRECT;
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN,
PEER_WLAN_ADDR, strlen(PEER_WLAN_ADDR)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.linkInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN,
NODE_NETWORK_ID, strlen(NODE_NETWORK_ID)), EOK);
ASSERT_EQ(strncpy_s(linkInfo.peerUdid, UDID_BUF_LEN, PEER_UDID, strlen(PEER_UDID)), EOK);
uint64_t laneId = LANE_ID_BASE;
int32_t ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
linkInfo.type = LANE_WLAN_5G;
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
linkInfo.type = LANE_LINK_TYPE_BUTT;
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = AddLaneResourceToPool(&linkInfo, laneId, false);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = ClearLaneResourceByLaneId(laneId);
EXPECT_EQ(ret, SOFTBUS_OK);
}
} // namespace OHOS

View File

@ -18,9 +18,9 @@
#include <gtest/gtest.h>
#include <securec.h>
#include "lnn_trans_lane.h"
#include "lnn_lane_deps_mock.h"
#include "lnn_lane_score_virtual.c"
#include "lnn_trans_lane.h"
#include "lnn_trans_lane_deps_mock.h"
#include "softbus_error_code.h"
@ -33,11 +33,10 @@ constexpr uint32_t NEW_LANE_REQ_ID = 112;
constexpr int32_t CHANNEL_ID = 5;
constexpr int32_t INTERVAL = 2;
constexpr uint32_t LIST_SIZE = 10;
constexpr char PEER_UDID[] = "111122223333abcdef";
constexpr char PEER_IP[] = "127.30.0.1";
constexpr char NODE_NETWORK_ID[] = "123456789";
constexpr uint64_t LANE_ID_BASE = 1122334455667788;
const char PEER_UDID[] = "111122223333abcdef";
const char PEER_IP[] = "127.30.0.1";
static int32_t g_errCode = 0;
constexpr char NODE_NETWORK_ID[] = "123456789";
class LNNTransLaneMockTest : public testing::Test {
public:
@ -94,56 +93,6 @@ static void OnLaneFreeFail(uint32_t laneHandle, int32_t errCode)
GTEST_LOG_(INFO) << "free lane failed, laneReqId=" << laneHandle << ", errCode=" << errCode;
}
static void OnLaneRequestSuccess(uint32_t laneReqId, const LaneConnInfo *info)
{
(void)info;
GTEST_LOG_(INFO) << "onLaneRequestSuccess enter, laneReqId=" << laneReqId;
}
static void OnLaneRequestFail(uint32_t laneReqId, int32_t errCode)
{
GTEST_LOG_(INFO) << "onLaneRequestFail enter, laneReqId=" << laneReqId << ", errCode=" << errCode;
}
static void OnLaneAllocSuccessHml(uint32_t laneHandle, const LaneConnInfo *info)
{
(void)laneHandle;
ASSERT_NE(info, nullptr) << "invalid connInfo";
GTEST_LOG_(INFO) << "alloc lane successful, linkType=" << info->type;
EXPECT_EQ(info->type, LANE_HML);
}
static LaneAllocListener g_listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
static int32_t PrejudgeAvailabilitySucc(const char *remoteNetworkId, enum WifiDirectLinkType connectType)
{
(void)remoteNetworkId;
(void)connectType;
GTEST_LOG_(INFO) << "PrejudgeAvailabilitySucc Enter";
return SOFTBUS_OK;
}
static int32_t PrejudgeAvailabilityErr(const char *remoteNetworkId, enum WifiDirectLinkType connectType)
{
(void)remoteNetworkId;
(void)connectType;
GTEST_LOG_(INFO) << "PrejudgeAvailabilitySucc Enter";
return SOFTBUS_LANE_NOT_FOUND;
}
static struct WifiDirectManager g_managerSucc = {
.prejudgeAvailability = PrejudgeAvailabilitySucc,
};
static struct WifiDirectManager g_managerErr = {
.prejudgeAvailability = PrejudgeAvailabilityErr,
};
/*
* @tc.name: LNN_TRANS_LANE_001
* @tc.desc: Init
@ -152,7 +101,7 @@ static struct WifiDirectManager g_managerErr = {
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_001, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
@ -178,9 +127,9 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_001, TestSize.Level1)
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_002, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
TransLaneDepsInterfaceMock laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
@ -202,16 +151,22 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_002, TestSize.Level1)
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_003, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
TransLaneDepsInterfaceMock laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
uint32_t laneReqId = 1;
LaneAllocInfo allocInfo;
allocInfo.type = LANE_TYPE_TRANS;
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_TRUE(ret != SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_NO_AVAILABLE_LINK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
@ -226,9 +181,9 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_003, TestSize.Level1)
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_004, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
TransLaneDepsInterfaceMock laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
@ -236,6 +191,12 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_004, TestSize.Level1)
uint32_t laneReqId = 1;
LaneAllocInfo allocInfo;
allocInfo.type = LANE_TYPE_TRANS;
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
LanePreferredLinkList recommendLinkList;
(void)memset_s(&recommendLinkList, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList));
recommendLinkList.linkTypeNum = 0;
@ -243,7 +204,7 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_004, TestSize.Level1)
EXPECT_CALL(laneMock, SelectExpectLanesByQos).
WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink(_, _, NotNull())).WillRepeatedly(laneMock.ActionOfLaneLinkSuccess);
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
EXPECT_EQ(g_errCode, SOFTBUS_LANE_ID_GENERATE_FAIL);
@ -258,9 +219,9 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_004, TestSize.Level1)
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_005, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
TransLaneDepsInterfaceMock laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
@ -268,6 +229,12 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_005, TestSize.Level1)
uint32_t laneReqId = 1;
LaneAllocInfo allocInfo;
allocInfo.type = LANE_TYPE_TRANS;
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
LanePreferredLinkList recommendLinkList;
(void)memset_s(&recommendLinkList, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList));
recommendLinkList.linkTypeNum = 0;
@ -275,7 +242,7 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_005, TestSize.Level1)
EXPECT_CALL(laneMock, SelectExpectLanesByQos).
WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink(_, _, NotNull())).WillRepeatedly(laneMock.ActionOfLaneLinkFail);
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
EXPECT_EQ(g_errCode, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
@ -290,9 +257,9 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_005, TestSize.Level1)
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_006, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
TransLaneDepsInterfaceMock laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
@ -300,6 +267,12 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_006, TestSize.Level1)
uint32_t laneReqId = 1;
LaneAllocInfo allocInfo;
allocInfo.type = LANE_TYPE_TRANS;
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
LanePreferredLinkList recommendLinkList;
(void)memset_s(&recommendLinkList, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList));
recommendLinkList.linkTypeNum = 0;
@ -307,45 +280,13 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_006, TestSize.Level1)
EXPECT_CALL(laneMock, SelectExpectLanesByQos)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink).WillRepeatedly(Return(SOFTBUS_LANE_DETECT_FAIL));
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
EXPECT_EQ(g_errCode, SOFTBUS_LANE_DETECT_FAIL);
transObj->deinit();
}
/*
* @tc.name: LNN_TRANS_LANE_007
* @tc.desc: test alloc lane
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_007, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
uint32_t laneReqId = 1;
LaneRequestOption request = {};
request.type = LANE_TYPE_TRANS;
LanePreferredLinkList recommendLinkList = {};
recommendLinkList.linkTypeNum = 1;
recommendLinkList.linkType[0] = LANE_BR;
EXPECT_CALL(laneMock, SelectLane)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
ILaneListener listener = {
.onLaneRequestSuccess = OnLaneRequestSuccess,
.onLaneRequestFail = OnLaneRequestFail,
};
int32_t ret = transObj->allocLane(laneReqId, (const LaneRequestOption *)&request, &listener);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
transObj->deinit();
}
/*
* @tc.name: LNN_LANE_SCORE_VIRTUAL_001
* @tc.desc: lnn_lane_score_virtual.c
@ -383,9 +324,9 @@ HWTEST_F(LNNTransLaneMockTest, LNN_LANE_POST_LANE_STATE_CHANGE_MESSAGE_001, Test
laneLinkInfo.type = LANE_HML;
(void)strncpy_s(laneLinkInfo.linkInfo.p2p.connInfo.peerIp, IP_LEN, PEER_IP, IP_LEN);
NiceMock<LaneDepsInterfaceMock> laneMock;
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> transLaneMock;
TransLaneDepsInterfaceMock transLaneMock;
EXPECT_CALL(transLaneMock, LaneLinkupNotify).WillRepeatedly(Return(SOFTBUS_OK));
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
@ -409,9 +350,9 @@ HWTEST_F(LNNTransLaneMockTest, LNN_LANE_POST_LANE_STATE_CHANGE_MESSAGE_002, Test
laneLinkInfo.type = LANE_HML;
(void)strncpy_s(laneLinkInfo.linkInfo.p2p.connInfo.peerIp, IP_LEN, PEER_IP, IP_LEN);
NiceMock<LaneDepsInterfaceMock> laneMock;
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> transLaneMock;
TransLaneDepsInterfaceMock transLaneMock;
EXPECT_CALL(transLaneMock, LaneLinkdownNotify).WillRepeatedly(Return(SOFTBUS_OK));
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
@ -432,10 +373,10 @@ HWTEST_F(LNNTransLaneMockTest, LNN_LANE_DELETE_LANE_BUSINESS_INFO_001, TestSize.
{
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
NiceMock<LaneDepsInterfaceMock> laneMock;
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
transObj->init(nullptr);
NiceMock<TransLaneDepsInterfaceMock> transLaneMock;
TransLaneDepsInterfaceMock transLaneMock;
EXPECT_CALL(transLaneMock, DelLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = transObj->freeLane(LANE_REQ_ID);
EXPECT_EQ(ret, SOFTBUS_LANE_NOT_FOUND);
@ -452,7 +393,7 @@ HWTEST_F(LNNTransLaneMockTest, ALLOC_TARGET_LANE_TEST_001, TestSize.Level1)
{
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
NiceMock<LaneDepsInterfaceMock> laneMock;
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
transObj->init(nullptr);
LaneAllocInfoExt allocInfo = { .type = LANE_TYPE_TRANS, .linkList.linkTypeNum = LANE_HML_RAW, };
@ -483,9 +424,9 @@ HWTEST_F(LNNTransLaneMockTest, ALLOC_TARGET_LANE_TEST_001, TestSize.Level1)
*/
HWTEST_F(LNNTransLaneMockTest, ALLOC_LANE_BY_QOS_TEST_001, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
LaneDepsInterfaceMock mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<TransLaneDepsInterfaceMock> laneMock;
TransLaneDepsInterfaceMock laneMock;
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
@ -496,6 +437,12 @@ HWTEST_F(LNNTransLaneMockTest, ALLOC_LANE_BY_QOS_TEST_001, TestSize.Level1)
.extendInfo.linkType = LANE_LINK_TYPE_WIFI_WLAN,
};
EXPECT_EQ(EOK, strcpy_s(allocInfo.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID));
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
.onLaneFreeSuccess = OnLaneFreeSuccess,
.onLaneFreeFail = OnLaneFreeFail,
};
LanePreferredLinkList recommendLinkList;
(void)memset_s(&recommendLinkList, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList));
recommendLinkList.linkTypeNum = 0;
@ -503,22 +450,22 @@ HWTEST_F(LNNTransLaneMockTest, ALLOC_LANE_BY_QOS_TEST_001, TestSize.Level1)
EXPECT_CALL(laneMock, SelectExpectLanesByQos)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink).WillRepeatedly(Return(SOFTBUS_LANE_DETECT_FAIL));
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
allocInfo.extendInfo.linkType = LANE_LINK_TYPE_WIFI_P2P;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
allocInfo.extendInfo.linkType = LANE_LINK_TYPE_BR;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
allocInfo.extendInfo.linkType = LANE_LINK_TYPE_COC_DIRECT;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
allocInfo.extendInfo.linkType = LANE_LINK_TYPE_BLE_DIRECT;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
allocInfo.extendInfo.linkType = LANE_LINK_TYPE_HML;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
transObj->deinit();
@ -534,7 +481,7 @@ HWTEST_F(LNNTransLaneMockTest, ALLOC_RAW_LANE_TEST_001, TestSize.Level1)
{
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
NiceMock<LaneDepsInterfaceMock> laneMock;
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
RawLaneAllocInfo allocInfo = { .type = LANE_TYPE_TRANS };
LaneAllocListener listener;
@ -554,175 +501,4 @@ HWTEST_F(LNNTransLaneMockTest, ALLOC_RAW_LANE_TEST_001, TestSize.Level1)
NotifyFreeLaneResult(NEW_LANE_REQ_ID, SOFTBUS_ERR);
transObj->deinit();
}
/*
* @tc.name: LNN_FREE_LANE_DELAY_DESTROY_TEST_001
* @tc.desc: freeLane delay destroy test -> checkLinkConflict
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNTransLaneMockTest, LNN_FREE_LANE_DELAY_DESTROY_TEST_001, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(1), Return(SOFTBUS_OK)));
EXPECT_CALL(mock, LnnGetNetworkIdByUdid).WillOnce(Return(SOFTBUS_NOT_FIND)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, GetWifiDirectManager).WillRepeatedly(Return(&g_managerSucc));
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
LaneAllocInfo allocInfo = {
.type = LANE_TYPE_TRANS,
.extendInfo.linkType = LANE_LINK_TYPE_HML,
};
EXPECT_EQ(EOK, strcpy_s(allocInfo.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID));
LanePreferredLinkList recommendLinkList = {};
recommendLinkList.linkTypeNum = 0;
recommendLinkList.linkType[(recommendLinkList.linkTypeNum)++] = LANE_HML;
NiceMock<TransLaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, SelectExpectLanesByQos)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink(_, _, NotNull())).WillRepeatedly(laneMock.ActionOfLaneLinkSuccess);
EXPECT_CALL(laneMock, DestroyLink).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, DelLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, AddLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
LaneResource resourceItem = {};
resourceItem.link.type = LANE_HML;
resourceItem.clientRef = 1;
EXPECT_CALL(laneMock, FindLaneResourceByLaneId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(resourceItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, DelLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, AddLaneResourceToPool).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_BASE));
g_listenerCb.onLaneAllocSuccess = OnLaneAllocSuccessHml;
uint32_t laneReqId = 11;
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = transObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
laneReqId = 12;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = transObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(3500)); // delay 3500ms for looper completion.
transObj->deinit();
}
/*
* @tc.name: LNN_FREE_LANE_DELAY_DESTROY_TEST_002
* @tc.desc: freeLane delay destroy test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNTransLaneMockTest, LNN_FREE_LANE_DELAY_DESTROY_TEST_002, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(1), Return(SOFTBUS_OK)));
EXPECT_CALL(mock, LnnGetNetworkIdByUdid).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, GetWifiDirectManager).WillOnce(Return(&g_managerErr)).WillOnce(Return(&g_managerSucc))
.WillOnce(Return(&g_managerErr)).WillRepeatedly(Return(&g_managerSucc));
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
LaneAllocInfo allocInfo = {
.type = LANE_TYPE_TRANS,
.extendInfo.linkType = LANE_LINK_TYPE_HML,
};
EXPECT_EQ(EOK, strcpy_s(allocInfo.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID));
LanePreferredLinkList recommendLinkList = {};
recommendLinkList.linkTypeNum = 0;
recommendLinkList.linkType[(recommendLinkList.linkTypeNum)++] = LANE_HML;
NiceMock<TransLaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, SelectExpectLanesByQos)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink(_, _, NotNull())).WillRepeatedly(laneMock.ActionOfLaneLinkSuccess);
EXPECT_CALL(laneMock, DestroyLink).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, DelLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, AddLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
LaneResource resourceItem = {};
resourceItem.link.type = LANE_HML;
resourceItem.clientRef = 1;
EXPECT_CALL(laneMock, FindLaneResourceByLaneId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(resourceItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, DelLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, AddLaneResourceToPool).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_BASE));
g_listenerCb.onLaneAllocSuccess = OnLaneAllocSuccessHml;
uint32_t laneReqId = 21;
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = transObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
laneReqId = 22;
ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = transObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 3500ms for looper completion.
transObj->deinit();
}
/*
* @tc.name: LNN_FREE_LANE_DELAY_DESTROY_TEST_003
* @tc.desc: freeLane remove delay destroy test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNTransLaneMockTest, LNN_FREE_LANE_DELAY_DESTROY_TEST_003, TestSize.Level1)
{
NiceMock<LaneDepsInterfaceMock> mock;
EXPECT_CALL(mock, StartBaseClient).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(1), Return(SOFTBUS_OK)));
EXPECT_CALL(mock, LnnGetNetworkIdByUdid).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, GetWifiDirectManager).WillRepeatedly(Return(&g_managerSucc));
LaneInterface *transObj = TransLaneGetInstance();
EXPECT_TRUE(transObj != nullptr);
transObj->init(nullptr);
uint32_t laneReqId = 31;
LaneAllocInfo allocInfo = {
.type = LANE_TYPE_TRANS,
.extendInfo.linkType = LANE_LINK_TYPE_HML,
};
EXPECT_EQ(EOK, strcpy_s(allocInfo.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID));
LanePreferredLinkList recommendLinkList = {};
recommendLinkList.linkTypeNum = 0;
recommendLinkList.linkType[(recommendLinkList.linkTypeNum)++] = LANE_HML;
NiceMock<TransLaneDepsInterfaceMock> laneMock;
EXPECT_CALL(laneMock, SelectExpectLanesByQos)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(recommendLinkList), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, BuildLink(_, _, NotNull())).WillRepeatedly(laneMock.ActionOfLaneLinkSuccess);
EXPECT_CALL(laneMock, DestroyLink).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, DelLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, AddLaneBusinessInfoItem).WillRepeatedly(Return(SOFTBUS_OK));
LaneResource resourceItem = {};
resourceItem.link.type = LANE_HML;
resourceItem.clientRef = 1;
resourceItem.laneId = LANE_ID_BASE;
EXPECT_CALL(laneMock, FindLaneResourceByLaneId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(resourceItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, DelLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, AddLaneResourceToPool).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_BASE));
g_listenerCb.onLaneAllocSuccess = OnLaneAllocSuccessHml;
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &g_listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
ret = transObj->freeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_OK);
RemoveDelayDestroyMessage(LANE_ID_BASE);
ret = UpdateReqListLaneId(LANE_ID_BASE, LANE_ID_BASE + 1);
EXPECT_EQ(ret, SOFTBUS_OK);
DelLogicAndLaneRelationship(LANE_ID_BASE + 1);
transObj->deinit();
}
} // namespace OHOS

View File

@ -61,17 +61,6 @@ int32_t LaneLinkDepsInterfaceMock::ActionOfDetectSuccess(uint32_t laneReqId, con
return SOFTBUS_OK;
}
int32_t LaneLinkDepsInterfaceMock::ActionOfDetectFail(uint32_t laneReqId, const LaneLinkInfo *linkInfo,
const LaneLinkCb *callback)
{
if (linkInfo == nullptr || callback == nullptr) {
GTEST_LOG_(INFO) << "invalid param";
return SOFTBUS_INVALID_PARAM;
}
callback->onLaneLinkFail(laneReqId, SOFTBUS_LANE_DETECT_TIMEOUT, linkInfo->type);
return SOFTBUS_OK;
}
extern "C" {
int32_t GetTransReqInfoByLaneReqId(uint32_t laneReqId, TransOption *reqInfo)
{
@ -169,10 +158,5 @@ void DelLogicAndLaneRelationship(uint64_t laneId)
{
GetLaneLinkDepsInterface()->DelLogicAndLaneRelationship(laneId);
}
int32_t LnnSyncPtk(char *networkId)
{
return GetLaneLinkDepsInterface()->LnnSyncPtk(networkId);
}
}
} // namespace OHOS

View File

@ -50,7 +50,6 @@ public:
virtual int32_t ClearLaneResourceByLaneId(uint64_t laneId) = 0;
virtual void RemoveDelayDestroyMessage(uint64_t laneId) = 0;
virtual void DelLogicAndLaneRelationship(uint64_t laneId) = 0;
virtual int32_t LnnSyncPtk(char *networkId) = 0;
};
class LaneLinkDepsInterfaceMock : public LaneLinkDepsInterface {
@ -81,7 +80,6 @@ public:
MOCK_METHOD1(ClearLaneResourceByLaneId, int32_t (uint64_t laneId));
MOCK_METHOD1(RemoveDelayDestroyMessage, void (uint64_t laneId));
MOCK_METHOD1(DelLogicAndLaneRelationship, void (uint64_t laneId));
MOCK_METHOD1(LnnSyncPtk, int32_t (char *networkId));
static int32_t ActionOfChannelOpenFailed(int32_t requestId, const char *networkId,
const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback);
@ -89,8 +87,6 @@ public:
const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback);
static int32_t ActionOfDetectSuccess(uint32_t laneReqId, const LaneLinkInfo *linkInfo,
const LaneLinkCb *callback);
static int32_t ActionOfDetectFail(uint32_t laneReqId, const LaneLinkInfo *linkInfo,
const LaneLinkCb *callback);
};
} // namespace OHOS
#endif // LNN_LANE_LINK_DEPS_MOCK_H

View File

@ -45,11 +45,8 @@ constexpr int32_t LANEREQID15 = 15;
constexpr int32_t LANEVALUE = 3;
constexpr int32_t DB_MAGIC_NUMBER = 0x5A5A5A5A;
constexpr int32_t MESH_MAGIC_NUMBER = 0xA5A5A5A5;
constexpr int32_t SOFTBUS_LNN_PTK_NOT_MATCH = (SOFTBUS_ERRNO(SHORT_DISTANCE_MAPPING_MODULE_CODE) + 4);
static bool g_isRawHmlResuse = true;
int32_t g_laneLinkResult = SOFTBUS_INVALID_PARAM;
int32_t g_connFailReason = ERROR_WIFI_DIRECT_WAIT_REUSE_RESPONSE_TIMEOUT;
class LNNLaneLinkTest : public testing::Test {
public:
@ -145,28 +142,13 @@ static int32_t ConnectDevice(struct WifiDirectConnectInfo *info, struct WifiDire
if (info->pid == SYNCSUCC) {
return SOFTBUS_OK;
}
if (info->pid == ASYNCFAIL) {
callback->onConnectFailure(info->requestId, g_connFailReason);
return SOFTBUS_OK;
}
struct WifiDirectLink link = {
.linkId = 1,
.linkType = WIFI_DIRECT_LINK_TYPE_P2P,
};
callback->onConnectSuccess(info->requestId, &link);
return SOFTBUS_OK;
}
static int32_t ConnectDeviceRawHml(struct WifiDirectConnectInfo *info, struct WifiDirectConnectCallback *callback)
{
if (info->pid == ASYNCFAIL) {
callback->onConnectFailure(info->requestId, ERROR_WIFI_DIRECT_WAIT_REUSE_RESPONSE_TIMEOUT);
return SOFTBUS_OK;
}
struct WifiDirectLink link = {
.linkId = 1,
.linkType = WIFI_DIRECT_LINK_TYPE_HML,
.isReuse = g_isRawHmlResuse,
.linkType = WIFI_DIRECT_LINK_TYPE_P2P,
};
callback->onConnectSuccess(info->requestId, &link);
return SOFTBUS_OK;
@ -194,20 +176,9 @@ static int32_t DisconnectDevice2(struct WifiDirectDisconnectInfo *info, struct W
return SOFTBUS_ERR;
}
static int32_t DisconnectDeviceSuccess(struct WifiDirectDisconnectInfo *info,
struct WifiDirectDisconnectCallback *callback)
static bool SupportHmlTwo(void)
{
GTEST_LOG_(INFO) << "DisconnectDeviceSuccess enter";
callback->onDisconnectSuccess(info->requestId);
return SOFTBUS_OK;
}
static int32_t DisconnectDeviceFail(struct WifiDirectDisconnectInfo *info,
struct WifiDirectDisconnectCallback *callback)
{
GTEST_LOG_(INFO) << "DisconnectDeviceFail enter";
callback->onDisconnectFailure(info->requestId, SOFTBUS_LANE_BUILD_LINK_FAIL);
return SOFTBUS_OK;
return true;
}
static int32_t CancelConnectDevice(const struct WifiDirectConnectInfo *info)
@ -224,11 +195,6 @@ static int32_t CancelConnectDeviceFail(const struct WifiDirectConnectInfo *info)
return SOFTBUS_LANE_BUILD_LINK_FAIL;
}
static bool SupportHmlTwo(void)
{
return true;
}
static struct WifiDirectManager g_manager = {
.isNegotiateChannelNeeded= IsNegotiateChannelNeeded,
.getRequestId = GetRequestId,
@ -244,7 +210,6 @@ static struct WifiDirectManager g_manager2 = {
.connectDevice = ConnectDevice,
.cancelConnectDevice = CancelConnectDevice,
.disconnectDevice = DisconnectDevice,
.supportHmlTwo = SupportHmlTwo,
};
static struct WifiDirectManager g_manager3 = {
@ -253,7 +218,6 @@ static struct WifiDirectManager g_manager3 = {
.connectDevice = ConnectDevice,
.cancelConnectDevice = CancelConnectDevice,
.disconnectDevice = DisconnectDevice2,
.supportHmlTwo = SupportHmlTwo,
};
static bool IsNegotiateChannelNeeded2(const char *remoteNetworkId, enum WifiDirectLinkType linkType)
@ -1196,122 +1160,6 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_007, TestSize.Level1)
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeeded;
}
/*
* @tc.name: GuideChannelRetryOfAsync_008
* @tc.desc: test GuideChannelRetryOfAsync:LANE_ACTIVE_AUTH_TRIGGER(pass) for detect success
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_008, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
int32_t ret = strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
EXPECT_EQ(EOK, ret);
request.linkType = LANE_HML;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
uint32_t laneReqId = 10;
int32_t value = 3;
uint64_t local = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint64_t remote = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint32_t localBle = 1 << BIT_BLE;
uint32_t requestId = 1;
AuthConnInfo connInfo = {.type = AUTH_LINK_TYPE_WIFI};
NiceMock<LaneDepsInterfaceMock> linkMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetLocalNumU32Info)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(localBle), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(connInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, LaneDetectReliability).WillRepeatedly(laneLinkMock.ActionOfDetectSuccess);
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(linkMock, AuthOpenConn(_, requestId, NotNull(), _)).WillOnce(linkMock.ActionOfConnOpened)
.WillRepeatedly(Return(SOFTBUS_OK));
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeededTrue;
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(linkMock, AuthGetHmlConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeeded;
LnnDisconnectP2pWithoutLnn(laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: GuideChannelRetryOfAsync_009
* @tc.desc: test GuideChannelRetryOfAsync:LANE_ACTIVE_AUTH_TRIGGER(fail) for detect fail
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_009, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
int32_t ret = strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
EXPECT_EQ(EOK, ret);
request.linkType = LANE_HML;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
uint32_t laneReqId = 10;
int32_t value = 3;
uint64_t local = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint64_t remote = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint32_t localBle = 1 << BIT_BLE;
uint32_t requestId = 1;
AuthConnInfo connInfo = {.type = AUTH_LINK_TYPE_WIFI};
NiceMock<LaneDepsInterfaceMock> linkMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetLocalNumU32Info)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(localBle), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(connInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, LaneDetectReliability).WillRepeatedly(laneLinkMock.ActionOfDetectFail);
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(linkMock, AuthOpenConn(_, requestId, NotNull(), _)).WillOnce(linkMock.ActionOfConnOpened)
.WillRepeatedly(Return(SOFTBUS_OK));
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeededTrue;
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(linkMock, AuthGetHmlConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeeded;
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: GuideChannelRetry_001
* @tc.desc: test GuideChannelRetry:fist async
@ -2126,407 +1974,4 @@ HWTEST_F(LNNLaneLinkTest, LNN_LANE_SELECT_05, TestSize.Level1)
int32_t ret = SelectExpectLanesByQos(NODE_NETWORK_ID, &request, &recommendList);
EXPECT_EQ(ret, SOFTBUS_LANE_GET_LEDGER_INFO_ERR);
}
/*
* @tc.name: LNN_LANE_LINK_RAW_HML_TEST_001
* @tc.desc: test build raw hml link is resuse
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_RAW_HML_TEST_001, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML_RAW;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
bool isMateExist = false;
g_isRawHmlResuse = true;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneMock, AuthCheckMetaExist)
.WillOnce(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(isMateExist), Return(SOFTBUS_OK)))
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(!isMateExist), Return(SOFTBUS_OK)));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_RAW_HML_TEST_002
* @tc.desc: test build raw hml link is not resuse
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_RAW_HML_TEST_002, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML_RAW;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
g_isRawHmlResuse = false;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_DISCONN_TEST_001
* @tc.desc: test lane link disconn test succ
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_DISCONN_TEST_001, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML_RAW;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
g_isRawHmlResuse = false;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
g_manager.disconnectDevice = DisconnectDeviceSuccess;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_DISCONN_TEST_002
* @tc.desc: test lane link disconn test fail
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_DISCONN_TEST_002, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML_RAW;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
g_isRawHmlResuse = false;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
g_manager.disconnectDevice = DisconnectDeviceFail;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_DISCONN_TEST_003
* @tc.desc: test lane link disconn succ with auth opened succ
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_DISCONN_TEST_003, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
uint32_t requestId = 1;
g_isRawHmlResuse = false;
AuthConnInfo connInfo = {.type = AUTH_LINK_TYPE_P2P};
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
g_manager.disconnectDevice = DisconnectDeviceSuccess;
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeededTrue;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneMock, AuthGetHmlConnInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(connInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(laneMock, AuthOpenConn(_, requestId, NotNull(), _)).WillRepeatedly(laneMock.ActionOfConnOpened);
EXPECT_CALL(laneMock, AuthCloseConn).WillRepeatedly(Return());
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_DISCONN_TEST_004
* @tc.desc: test lane link disconn succ with auth opened fail
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_DISCONN_TEST_004, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
uint32_t requestId = 1;
g_isRawHmlResuse = false;
AuthConnInfo connInfo = {.type = AUTH_LINK_TYPE_P2P};
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
g_manager.disconnectDevice = DisconnectDeviceSuccess;
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeededTrue;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneMock, AuthGetHmlConnInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(connInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(laneMock, AuthOpenConn(_, requestId, NotNull(), _)).WillRepeatedly(laneMock.ActionOfConnOpenFailed);
EXPECT_CALL(laneMock, AuthCloseConn).WillRepeatedly(Return());
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_DISCONN_TEST_005
* @tc.desc: test lane link disconn fail with auth opened succ
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_DISCONN_TEST_005, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.pid = ASYNCSUCC;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
uint32_t requestId = 1;
AuthConnInfo connInfo = {.type = AUTH_LINK_TYPE_P2P};
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDeviceRawHml;
g_manager.disconnectDevice = DisconnectDevice2;
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeededTrue;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneMock, AuthGetHmlConnInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(connInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(laneMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(laneMock, AuthOpenConn(_, requestId, NotNull(), _)).WillRepeatedly(laneMock.ActionOfConnOpened);
EXPECT_CALL(laneMock, AuthCloseConn).WillRepeatedly(Return());
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_CONNDEVICE_TEST_001
* @tc.desc: test wifi directConnect fail, reason = SOFTBUS_LNN_PTK_NOT_MATCH
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_CONNDEVICE_TEST_001, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.pid = ASYNCFAIL;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
g_connFailReason = SOFTBUS_LNN_PTK_NOT_MATCH;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, LnnSyncPtk).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDevice;
g_manager.disconnectDevice = DisconnectDevice;
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeeded;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_CONNDEVICE_TEST_002
* @tc.desc: test wifiDirectConnect fail with resuse, reason = SOFTBUS_CONN_SOURCE_REUSE_LINK_FAILED
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_CONNDEVICE_TEST_002, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.pid = ASYNCFAIL;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
g_connFailReason = SOFTBUS_CONN_SOURCE_REUSE_LINK_FAILED;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDevice;
g_manager.disconnectDevice = DisconnectDevice;
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeeded;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneMock, AuthOpenConn).WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: LNN_LANE_LINK_CONNDEVICE_TEST_003
* @tc.desc: test wifiDirectConnect fail, reason = SOFTBUS_CONN_HV3_WAIT_CONNECTION_TIMEOUT
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, LNN_LANE_LINK_CONNDEVICE_TEST_003, TestSize.Level1)
{
LinkRequest request = {};
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML_RAW;
request.pid = ASYNCFAIL;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 1;
uint32_t laneReqId = 10;
int32_t value = 3;
g_connFailReason = SOFTBUS_CONN_HV2_WAIT_CONNECT_RESPONSE_TIMEOUT;
NiceMock<LaneDepsInterfaceMock> laneMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(laneMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneMock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.connectDevice = ConnectDevice;
g_manager.disconnectDevice = DisconnectDevice;
g_manager.isNegotiateChannelNeeded = IsNegotiateChannelNeeded;
EXPECT_CALL(laneMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneMock, LnnRequestCheckOnlineStatus).WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
} // namespace OHOS

View File

@ -161,24 +161,6 @@ static int32_t ForceDisconnectDeviceFail(struct WifiDirectForceDisconnectInfo *i
return SOFTBUS_OK;
}
static int32_t ForceDisconnectDeviceError(struct WifiDirectForceDisconnectInfo *info,
struct WifiDirectDisconnectCallback *callback)
{
(void)info;
(void)callback;
GTEST_LOG_(INFO) << "ForceDisconnectDeviceErr enter";
return SOFTBUS_LANE_NO_AVAILABLE_LINK;
}
static int32_t ForceDisconnectDeviceNoCallback(struct WifiDirectForceDisconnectInfo *info,
struct WifiDirectDisconnectCallback *callback)
{
(void)info;
(void)callback;
GTEST_LOG_(INFO) << "ForceDisconnectDeviceErr enter";
return SOFTBUS_OK;
}
static struct WifiDirectManager g_manager = {
.isNegotiateChannelNeeded= IsNegotiateChannelNeeded,
.getRequestId = GetRequestId,
@ -211,53 +193,6 @@ HWTEST_F(LNNLaneLinkWifiDirectTest, HandleForceDownWifiDirect_001, TestSize.Leve
EXPECT_EQ(SOFTBUS_LANE_NOT_FOUND, ret);
}
/*
* @tc.name: HandleForceDownWifiDirect_002
* @tc.desc: test rorceDownWifiDirect with auth succ but disconnectDevice error
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkWifiDirectTest, HandleForceDownWifiDirect_002, TestSize.Level1)
{
uint32_t p2pReqId = 1;
NiceMock<LaneDepsInterfaceMock> linkMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo).WillRepeatedly(Return(SOFTBUS_NOT_FIND));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.forceDisconnectDevice = ForceDisconnectDeviceNoCallback;
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneLinkMock, GetConflictTypeWithErrcode).WillRepeatedly(Return(CONFLICT_LINK_NUM_LIMITED));
LinkConflictInfo conflictItem = {};
conflictItem.devIdCnt = 1;
char (*devId)[NETWORK_ID_BUF_LEN] = (char (*)[NETWORK_ID_BUF_LEN])SoftBusCalloc(NETWORK_ID_BUF_LEN);
ASSERT_TRUE(devId != nullptr);
EXPECT_EQ(memcpy_s(devId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, NETWORK_ID_BUF_LEN), EOK);
conflictItem.devIdList = devId;
EXPECT_CALL(laneLinkMock, FindLinkConflictInfoByDevId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(conflictItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_LANE_NOT_FOUND));
EXPECT_CALL(laneLinkMock, RemoveConflictInfoTimelinessMsg).WillRepeatedly(Return());
EXPECT_CALL(laneLinkMock, DelLinkConflictInfo).WillRepeatedly(Return(SOFTBUS_OK));
g_connectDeviceTimes = 0;
g_isNeedNegotiateChannel = false;
int32_t ret = HandleForceDownWifiDirect(NODE_NETWORK_ID, CONFLICT_THREE_VAP, p2pReqId);
EXPECT_EQ(SOFTBUS_OK, ret);
g_manager.forceDisconnectDevice = ForceDisconnectDeviceError;
char (*devIdNext)[NETWORK_ID_BUF_LEN] = (char (*)[NETWORK_ID_BUF_LEN])SoftBusCalloc(NETWORK_ID_BUF_LEN);
ASSERT_TRUE(devIdNext != nullptr);
EXPECT_EQ(memcpy_s(devIdNext, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, NETWORK_ID_BUF_LEN), EOK);
conflictItem.devIdList = devIdNext;
EXPECT_CALL(laneLinkMock, FindLinkConflictInfoByDevId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(conflictItem), Return(SOFTBUS_OK)));
ret = HandleForceDownWifiDirect(NODE_NETWORK_ID, CONFLICT_THREE_VAP, p2pReqId);
g_manager.forceDisconnectDevice = ForceDisconnectDeviceSucc;
EXPECT_EQ(SOFTBUS_LANE_NO_AVAILABLE_LINK, ret);
}
/*
* @tc.name: WifiDirectForceDown_001
* @tc.desc: test WifiDirectForceDownWithoutAuth success
@ -289,13 +224,9 @@ HWTEST_F(LNNLaneLinkWifiDirectTest, WifiDirectForceDown_001, TestSize.Level1)
ASSERT_TRUE(devId != nullptr);
EXPECT_EQ(memcpy_s(devId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, NETWORK_ID_BUF_LEN), EOK);
conflictItem.devIdList = devId;
conflictItem.releaseLink = LANE_HML;
EXPECT_CALL(laneLinkMock, FindLinkConflictInfoByDevId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(conflictItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, RemoveDelayDestroyMessage).WillRepeatedly(Return());
EXPECT_CALL(laneLinkMock, DelLogicAndLaneRelationship).WillRepeatedly(Return());
EXPECT_CALL(laneLinkMock, ClearLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_LANE_NOT_FOUND));
EXPECT_CALL(laneLinkMock, RemoveConflictInfoTimelinessMsg).WillRepeatedly(Return());
EXPECT_CALL(laneLinkMock, DelLinkConflictInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthCloseConn).WillRepeatedly(Return());
@ -512,108 +443,6 @@ HWTEST_F(LNNLaneLinkWifiDirectTest, WifiDirectForceDown_005, TestSize.Level1)
g_isNeedNegotiateChannel = false;
}
/*
* @tc.name: WifiDirectForceDown_006
* @tc.desc: test WifiDirectForceDownWithAuth success, but forceDisconnect error
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkWifiDirectTest, WifiDirectForceDown_006, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 123;
uint32_t laneReqId = 24;
uint32_t authRequestId = 1;
NiceMock<LaneDepsInterfaceMock> linkMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillOnce(Return(SOFTBUS_NOT_FIND)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo).WillRepeatedly(Return(SOFTBUS_NOT_FIND));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.forceDisconnectDevice = ForceDisconnectDeviceError;
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneLinkMock, GetConflictTypeWithErrcode).WillRepeatedly(Return(CONFLICT_LINK_NUM_LIMITED));
LinkConflictInfo conflictItem = {};
conflictItem.devIdCnt = 1;
char (*devId)[NETWORK_ID_BUF_LEN] = (char (*)[NETWORK_ID_BUF_LEN])SoftBusCalloc(NETWORK_ID_BUF_LEN);
ASSERT_TRUE(devId != nullptr);
EXPECT_EQ(memcpy_s(devId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, NETWORK_ID_BUF_LEN), EOK);
conflictItem.devIdList = devId;
EXPECT_CALL(laneLinkMock, FindLinkConflictInfoByDevId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(conflictItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_LANE_NOT_FOUND));
EXPECT_CALL(laneLinkMock, RemoveConflictInfoTimelinessMsg).WillRepeatedly(Return());
EXPECT_CALL(laneLinkMock, DelLinkConflictInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthOpenConn(_, authRequestId, NotNull(), _)).WillOnce(linkMock.ActionOfConnOpened)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGetHmlConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(authRequestId));
EXPECT_CALL(linkMock, AuthCloseConn).WillRepeatedly(Return());
g_connectDeviceTimes = 0;
g_isNeedNegotiateChannel = true;
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_LANE_BUILD_LINK_FAIL, g_laneLinkResult);
g_manager.forceDisconnectDevice = ForceDisconnectDeviceSucc;
g_isNeedNegotiateChannel = false;
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: WifiDirectForceDown_007
* @tc.desc: test WifiDirectForceDownWithoutAuth, forceDisconnect error
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkWifiDirectTest, WifiDirectForceDown_007, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
EXPECT_EQ(strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID), EOK);
request.linkType = LANE_HML;
request.triggerLinkTime = SoftBusGetSysTimeMs();
request.availableLinkTime = DEFAULT_LINK_LATENCY;
request.actionAddr = 123;
uint32_t laneReqId = 23;
NiceMock<LaneDepsInterfaceMock> linkMock;
NiceMock<LaneLinkDepsInterfaceMock> laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillOnce(Return(SOFTBUS_NOT_FIND)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo).WillRepeatedly(Return(SOFTBUS_NOT_FIND));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
g_manager.forceDisconnectDevice = ForceDisconnectDeviceError;
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(laneLinkMock, GetConflictTypeWithErrcode).WillRepeatedly(Return(CONFLICT_ROLE));
LinkConflictInfo conflictItem = {};
conflictItem.devIdCnt = 1;
char (*devId)[NETWORK_ID_BUF_LEN] = (char (*)[NETWORK_ID_BUF_LEN])SoftBusCalloc(NETWORK_ID_BUF_LEN);
ASSERT_TRUE(devId != nullptr);
EXPECT_EQ(memcpy_s(devId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, NETWORK_ID_BUF_LEN), EOK);
conflictItem.devIdList = devId;
EXPECT_CALL(laneLinkMock, FindLinkConflictInfoByDevId)
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM3>(conflictItem), Return(SOFTBUS_OK)));
EXPECT_CALL(laneLinkMock, FindLaneResourceByLinkType).WillRepeatedly(Return(SOFTBUS_LANE_NOT_FOUND));
EXPECT_CALL(laneLinkMock, RemoveConflictInfoTimelinessMsg).WillRepeatedly(Return());
EXPECT_CALL(laneLinkMock, DelLinkConflictInfo).WillRepeatedly(Return(SOFTBUS_OK));
g_connectDeviceTimes = 0;
int32_t ret = LnnConnectP2p(&request, laneReqId, &g_linkCb);
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_LANE_BUILD_LINK_FAIL, g_laneLinkResult);
g_manager.forceDisconnectDevice = ForceDisconnectDeviceSucc;
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: RecycleP2pLinkedReq_001
* @tc.desc: test RecycleP2pLinkedReqByLinkType