fix:Supplemental UT test Cases

Signed-off-by: koujiaxin <koujiaxin@huawei.com>
This commit is contained in:
seanpeak 2022-11-01 19:53:02 +08:00
parent a4de440658
commit a249668ed8
7 changed files with 341 additions and 34 deletions

View File

@ -30,6 +30,7 @@ ohos_unittest("LNNTest") {
"unittest/lane_test.cpp",
"unittest/ledger_lane_hub_test.cpp",
"unittest/lnn_huks_test.cpp",
"unittest/lnn_net_ledger_test.cpp",
"unittest/net_builder_test.cpp",
"unittest/net_ledger_test.cpp",
]
@ -70,6 +71,10 @@ ohos_unittest("LNNTest") {
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/interfaces/kits/discovery",
"//base/security/huks/interfaces/innerkits/huks_standard/main/include",
"$dsoftbus_root_path/sdk/bus_center/manager/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/src",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
]
deps = [

View File

@ -52,35 +52,6 @@ namespace OHOS {
using namespace testing::ext;
constexpr uint8_t DEFAULT_LEN = 32;
constexpr uint8_t DEFAULT_SIZE = 5;
constexpr uint8_t DEFAULT_TIME = 2;
static int InitServer()
{
if (ConnServerInit() == SOFTBUS_ERR) {
printf("softbus conn server init failed.");
return SOFTBUS_ERR;
}
if (AuthInit() == SOFTBUS_ERR) {
printf("softbus auth init failed.");
return SOFTBUS_ERR;
}
if (LnnInitLocalLedger() != SOFTBUS_OK) {
printf("init local net ledger fail!");
return SOFTBUS_ERR;
}
if (LnnInitDistributedLedger() != SOFTBUS_OK) {
printf("init distributed net ledger fail!");
return SOFTBUS_ERR;
}
if (LnnInitEventMonitor() != SOFTBUS_OK) {
printf("init event monitor failed");
return SOFTBUS_ERR;
}
if (LnnInitNetworkManager() != SOFTBUS_OK) {
printf("init lnn network manager fail!");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
class LnnBusCenterIpcTest : public testing::Test {
public:
@ -92,8 +63,6 @@ using namespace testing::ext;
void LnnBusCenterIpcTest::SetUpTestCase()
{
EXPECT_TRUE(InitServer() == SOFTBUS_OK);
sleep(DEFAULT_TIME);
}
void LnnBusCenterIpcTest::TearDownTestCase()

0
tests/core/bus_center/lnn/unittest/lane_test.cpp Executable file → Normal file
View File

View File

@ -0,0 +1,174 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include <securec.h>
#include "bus_center_info_key.h"
#include "lnn_net_ledger.h"
#include "lnn_connection_addr_utils.h"
#include "lnn_network_id.h"
#include "bus_center_manager.h"
#include "client_bus_center_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_huks_utils.h"
#include "lnn_local_net_ledger.h"
#include "lnn_meta_node_ledger.h"
#include "lnn_node_info.h"
#include "softbus_bus_center.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
#include "softbus_utils.h"
#include "softbus_adapter_mem.h"
#include "lnn_net_ledger.c"
namespace OHOS {
using namespace testing::ext;
class LnnNetLedgerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void LnnNetLedgerTest::SetUpTestCase()
{
}
void LnnNetLedgerTest::TearDownTestCase()
{
}
void LnnNetLedgerTest::SetUp()
{
}
void LnnNetLedgerTest::TearDown()
{
}
/*
* @tc.name: LNN_SET_NODE_DATA_CHANGE_FLAG_Test_001
* @tc.desc: Lnn Set Node Data Change Flag test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, LNN_SET_NODE_DATA_CHANGE_FLAG_Test_001, TestSize.Level0)
{
char *networkId = nullptr;
char networkIdSecond[NETWORK_ID_BUF_LEN] = "1234";
uint16_t dataChangeFlag = 0;
EXPECT_TRUE(LnnSetNodeDataChangeFlag(networkId, dataChangeFlag) == SOFTBUS_ERR);
EXPECT_TRUE(LnnSetNodeDataChangeFlag(networkIdSecond, dataChangeFlag) == SOFTBUS_ERR);
}
/*
* @tc.name: SOFTBUS_DUMP_PRINT_NET_CAPACITY_Test_001
* @tc.desc: SoftbusDumpPrintNetCapacity test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, SOFTBUS_DUMP_PRINT_NET_CAPACITY_Test_001, TestSize.Level0)
{
int fd = 0;
NodeBasicInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeBasicInfo), 0, sizeof(NodeBasicInfo));
EXPECT_TRUE(SoftbusDumpPrintNetCapacity(fd, &nodeInfo) == SOFTBUS_OK);
}
/*
* @tc.name: SOFTBUS_DUMP_PRINT_NET_TYPE_Test_001
* @tc.desc: SoftbusDumpPrintNetType test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, SOFTBUS_DUMP_PRINT_NET_TYPE_Test_001, TestSize.Level0)
{
int fd = 0;
NodeBasicInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeBasicInfo), 0, sizeof(NodeBasicInfo));
EXPECT_TRUE(SoftbusDumpPrintNetType(fd, &nodeInfo) == SOFTBUS_OK);
}
/*
* @tc.name: LNN_SET_DATA_CHANGE_FLAG_Test_001
* @tc.desc: Lnn Set Data Change Flag test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, LNN_SET_DATA_CHANGE_FLAG_Test_001, TestSize.Level0)
{
NodeInfo info;
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
NodeInfo *nodeinfo = nullptr;
uint16_t dataChangeFlag = 0;
EXPECT_TRUE(LnnSetDataChangeFlag(nodeinfo, dataChangeFlag) == SOFTBUS_INVALID_PARAM);
nodeinfo = &info;
EXPECT_TRUE(LnnSetDataChangeFlag(nodeinfo, dataChangeFlag) == SOFTBUS_OK);
}
/*
* @tc.name: LNN_GET_DATA_CHANGE_FLAG_Test_001
* @tc.desc: Lnn Get Data Change Flag test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, LNN_GET_DATA_CHANGE_FLAG_Test_001, TestSize.Level0)
{
NodeInfo info;
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
NodeInfo *nodeinfo = nullptr;
EXPECT_TRUE(LnnGetDataChangeFlag(nodeinfo) == 0);
nodeinfo = &info;
EXPECT_TRUE(LnnGetDataChangeFlag(nodeinfo) == 0);
}
/*
* @tc.name: LNN_GET_LOCAL_STR_INFO_Test_001
* @tc.desc: Lnn Get Local Str Info test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, LNN_GET_LOCAL_STR_INFO_Test_001, TestSize.Level0)
{
NodeInfo info;
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
char *nodeInfo = reinterpret_cast<char*>(&info);
uint32_t len = 0;
EXPECT_TRUE(LnnSetLocalStrInfo(NUM_KEY_DATA_CHANGE_FLAG, nodeInfo) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_AUTH_PORT, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_SESSION_PORT, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_PROXY_PORT, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_NET_CAP, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_DISCOVERY_TYPE, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_DEV_TYPE_ID, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_MASTER_NODE_WEIGHT, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_P2P_ROLE, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetLocalStrInfo(NUM_KEY_DATA_CHANGE_FLAG, nodeInfo, len) == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: LNN_INIT_LOCAL_LEDGER_DELAY_Test_001
* @tc.desc: Lnn Init Local Ledger Delay test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnNetLedgerTest, LNN_INIT_LOCAL_LEDGER_DELAY_Test_001, TestSize.Level0)
{
EXPECT_TRUE(LnnInitLocalLedgerDelay() == SOFTBUS_OK);
}
} // namespace OHOS

View File

@ -15,12 +15,29 @@
#include <gtest/gtest.h>
#include <securec.h>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "auth_interface.h"
#include "lnn_decision_db.h"
#include "lnn_decision_db.c"
#include "lnn_distributed_net_ledger.h"
#include "lnn_event_monitor.h"
#include "lnn_local_net_ledger.h"
#include "lnn_network_manager.h"
#include "softbus_log.h"
#include "softbus_utils.h"
#include "softbus_errcode.h"
#include "softbus_conn_interface.h"
namespace OHOS {
using namespace testing::ext;
constexpr uint32_t TEST_DATA_LEN = 10;
constexpr uint8_t DEFAULT_SIZE = 5;
class NetLedgerTest : public testing::Test {
public:
@ -75,9 +92,87 @@ HWTEST_F(NetLedgerTest, LNN_GET_TRUSTED_DEV_INFO_FROM_DB_Test_001, TestSize.Leve
uint32_t num = 0;
int32_t ret;
char *udidArray = (char *)SoftBusMalloc(TEST_DATA_LEN);
char *udidArray = new char[TEST_DATA_LEN];
ret = LnnGetTrustedDevInfoFromDb(&udidArray, &num);
EXPECT_TRUE(ret == SOFTBUS_ERR);
SoftBusFree(udidArray);
delete[] udidArray;
}
/*
* @tc.name: DL_GET_Test_001
* @tc.desc: Dl Get Auth test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(NetLedgerTest, DL_GET_Test_001, TestSize.Level0)
{
char networkId[DEFAULT_SIZE] = "1234";
int32_t info = 1234;
EXPECT_TRUE(LnnGetRemoteNumInfo(nullptr, NUM_KEY_SESSION_PORT, &info) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetRemoteNumInfo(networkId, STRING_KEY_END, &info) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetRemoteNumInfo(networkId, NUM_KEY_END, &info) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetRemoteNumInfo(networkId, NUM_KEY_END, nullptr) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnGetRemoteNumInfo(networkId, NUM_KEY_AUTH_PORT, &info) == SOFTBUS_ERR);
}
/*
* @tc.name: LNN_ADD_META_INFO_Test_001
* @tc.desc: Lnn Add Meta Info test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(NetLedgerTest, LNN_ADD_META_INFO_Test_001, TestSize.Level0)
{
NodeInfo info;
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
EXPECT_TRUE(LnnAddMetaInfo(&info) == SOFTBUS_OK);
}
/*
* @tc.name: LNN_DELETE_META_INFO_Test_001
* @tc.desc: Lnn Delete Meta Info test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(NetLedgerTest, LNN_DELETE_META_INFO_Test_001, TestSize.Level0)
{
char udid[DEFAULT_SIZE] = "1234";
ConnectionAddrType type = CONNECTION_ADDR_WLAN;
EXPECT_TRUE(LnnDeleteMetaInfo(udid, type) == SOFTBUS_ERR);
}
/*
* @tc.name: LNN_ADD_ONLINE_NODE_Test_001
* @tc.desc: Lnn Add Online Node test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(NetLedgerTest, LNN_ADD_ONLINE_NODE_Test_001, TestSize.Level0)
{
NodeInfo *info = nullptr;
EXPECT_TRUE(LnnAddOnlineNode(info) == REPORT_NONE);
NodeInfo infoValue;
(void)memset_s(&infoValue, sizeof(NodeInfo), 0, sizeof(NodeInfo));
EXPECT_TRUE(LnnAddOnlineNode(&infoValue) == REPORT_ONLINE);
}
/*
* @tc.name: GET_ALL_ONLINE_AND_META_NODE_INFO_Test_001
* @tc.desc: Get All Online And Meta Node Info test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(NetLedgerTest, GET_ALL_ONLINE_AND_META_NODE_INFO_Test_001, TestSize.Level0)
{
NodeBasicInfo base;
NodeBasicInfo *info = nullptr;
int32_t infoNum = 0;
EXPECT_TRUE(LnnGetAllOnlineAndMetaNodeInfo(nullptr, &infoNum) == SOFTBUS_ERR);
info = &base;
(void)memset_s(info, sizeof(NodeBasicInfo), 0, sizeof(NodeBasicInfo));
EXPECT_TRUE(LnnGetAllOnlineAndMetaNodeInfo(&info, nullptr) == SOFTBUS_ERR);
EXPECT_TRUE(LnnGetAllOnlineAndMetaNodeInfo(&info, &infoNum) == SOFTBUS_OK);
infoNum = DEFAULT_SIZE;
EXPECT_TRUE(LnnGetAllOnlineAndMetaNodeInfo(&info, &infoNum) == SOFTBUS_OK);
}
} // namespace OHOS

View File

@ -30,12 +30,17 @@ bus_center_sdk_test_inc = [
"//commonlibrary/c_utils/base/include",
"//third_party/bounds_checking_function/include",
"$dsoftbus_root_path/sdk/bus_center/manager/include",
"$dsoftbus_root_path/sdk/bus_center/ipc/standard/include",
"$dsoftbus_root_path/sdk/bus_center/ipc/include",
"$dsoftbus_root_path/core/frame/standard/init/include",
"$dsoftbus_root_path/core/transmission/common/include",
]
bus_center_sdk_test_deps = [
"$dsoftbus_root_path/core/frame:softbus_server",
"$dsoftbus_root_path/sdk:softbus_client",
"//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken",
"//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//third_party/bounds_checking_function:libsec_static",
]

View File

@ -16,7 +16,8 @@
#include <gtest/gtest.h>
#include <securec.h>
#include "bus_center_server_proxy.h"
#include "bus_center_server_proxy_standard.h"
#include "softbus_access_token_test.h"
#include "softbus_bus_center.h"
#include "softbus_def.h"
@ -591,4 +592,62 @@ HWTEST_F(BusCenterSdkTest, META_NODE_ON_LEAVE_RESULT_Test001, TestSize.Level1)
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: SERVER_IPC_SET_NODE_DATA_CHANGE_FLAG_Test001
* @tc.desc: ServerIpcSetNodeDataChangeFlag Result
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(BusCenterSdkTest, SERVER_IPC_SET_NODE_DATA_CHANGE_FLAG_Test001, TestSize.Level1)
{
char pkgName[] = "test";
char networkId[] = "ABCDEFG";
char *networkId1 = nullptr;
uint16_t dataChangeFlag = false;
int32_t ret = ServerIpcSetNodeDataChangeFlag(pkgName, networkId1, dataChangeFlag);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = ServerIpcSetNodeDataChangeFlag(pkgName, networkId, dataChangeFlag);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: SERVER_IPC_JOIN_META_NODE_Test001
* @tc.desc: Server Ipc Join Meta Node Result
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(BusCenterSdkTest, SERVER_IPC_JOIN_META_NODE_Test001, TestSize.Level1)
{
char *pkgName = nullptr;
void *addr = nullptr;
uint32_t addrTypeLen = 0;
CustomData dataKey;
ConnectionAddr connAddr;
(void)memset_s(&connAddr, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr));
(void)memset_s(&dataKey, sizeof(CustomData), 0, sizeof(CustomData));
char pkgNameValue[] = "test";
int32_t ret = ServerIpcJoinMetaNode(pkgName, addr, &dataKey, addrTypeLen);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
addr = (void*)&connAddr;
ret = ServerIpcJoinMetaNode(pkgNameValue, addr, &dataKey, addrTypeLen);
EXPECT_TRUE(ret == SOFTBUS_IPC_ERR);
}
/*
* @tc.name: SERVER_IPC_LEAVE_META_NODE_Test001
* @tc.desc: Server Ipc Leave Meta Node Result
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(BusCenterSdkTest, SERVER_IPC_LEAVE_META_NODE_Test001, TestSize.Level1)
{
char *pkgName = nullptr;
char pkgNameValue[] = "test";
char networkId[] = "ABCDEFG";
char *networkId1 = nullptr;
int32_t ret = ServerIpcLeaveMetaNode(pkgName, networkId1);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = ServerIpcLeaveMetaNode(pkgNameValue, networkId);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
} // namespace OHOS