diff --git a/tests/core/bus_center/lnn/BUILD.gn b/tests/core/bus_center/lnn/BUILD.gn index c1e73ad73b6fb511b276fb90a28e8b2edccae852..e437112efd29826a8a95ad0216886643df7fa0f8 100644 --- a/tests/core/bus_center/lnn/BUILD.gn +++ b/tests/core/bus_center/lnn/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -20,6 +20,7 @@ ohos_unittest("LNNTest") { module_out_path = module_output_path sources = [ "ipc/bus_center_client_proxy_standard_test.cpp", + "ipc/bus_center_client_proxy_test.cpp", "ipc/lnn_bus_center_ipc_test.cpp", "net_builder/lnn_connection_fsm_test.cpp", "net_builder/lnn_network_info_test.cpp", @@ -30,6 +31,7 @@ ohos_unittest("LNNTest") { "unittest/ledger_lane_hub_test.cpp", "unittest/lnn_huks_test.cpp", "unittest/net_builder_test.cpp", + "unittest/net_ledger_test.cpp", ] include_dirs = [ @@ -39,6 +41,9 @@ ohos_unittest("LNNTest") { "$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include", "$dsoftbus_root_path/core/bus_center/lnn/net_builder/sync_info/include", "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include", + "$dsoftbus_root_path/core/bus_center/lnn/lane_hub/heartbeat/include", + "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/include", + "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/src", "$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", diff --git a/tests/core/bus_center/lnn/ipc/bus_center_client_proxy_test.cpp b/tests/core/bus_center/lnn/ipc/bus_center_client_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5eacfa8fc034d7a812bbf36ffe53303adc08764e --- /dev/null +++ b/tests/core/bus_center/lnn/ipc/bus_center_client_proxy_test.cpp @@ -0,0 +1,88 @@ +/* +* 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 +#include +#include "softbus_errcode.h" +#include "bus_center_client_proxy.h" + +namespace OHOS { +using namespace testing::ext; +constexpr uint32_t TEST_DATA_LEN = 10; + +class BusCenterClientProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void BusCenterClientProxyTest::SetUpTestCase() +{ +} + +void BusCenterClientProxyTest::TearDownTestCase() +{ +} + +void BusCenterClientProxyTest::SetUp() +{ +} + +void BusCenterClientProxyTest::TearDown() +{ +} + +/* +* @tc.name: CLIENT_ON_JOIN_META_NODE_RESULT_Test_001 +* @tc.desc: client on join meta node result test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterClientProxyTest, CLIENT_ON_JOIN_META_NODE_RESULT_Test_001, TestSize.Level1) +{ + const char *pkgName = "000"; + void *addr = nullptr; + uint32_t addrTypeLen = TEST_DATA_LEN; + const char *networkId = "1234"; + int32_t retCode = 0; + int32_t ret; + + ret = ClientOnJoinMetaNodeResult(nullptr, addr, addrTypeLen, networkId, retCode); + EXPECT_EQ(ret, SOFTBUS_ERR); + ret = ClientOnJoinMetaNodeResult(pkgName, addr, addrTypeLen, networkId, retCode); + EXPECT_EQ(ret, SOFTBUS_ERR); +} + +/* +* @tc.name: CLIENT_ON_LEAVE_META_NODE_RESULT_Test_001 +* @tc.desc: client on leave meta node result test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterClientProxyTest, CLIENT_ON_LEAVE_META_NODE_RESULT_Test_001, TestSize.Level0) +{ + const char *pkgName = "000"; + const char *networkId = "1234"; + int32_t retCode = 0; + int32_t ret; + + ret = ClientOnLeaveMetaNodeResult(nullptr, networkId, retCode); + EXPECT_EQ(ret, SOFTBUS_ERR); + ret = ClientOnLeaveMetaNodeResult(pkgName, networkId, retCode); + EXPECT_EQ(ret, SOFTBUS_ERR); +} +} // namespace OHOS diff --git a/tests/core/bus_center/lnn/net_builder/lnn_connection_fsm_test.cpp b/tests/core/bus_center/lnn/net_builder/lnn_connection_fsm_test.cpp index f0e052df5f5e8a02353cf990abbbf784e195018c..fc0206be5caf3ca85de6499b66482547f827abaf 100644 --- a/tests/core/bus_center/lnn/net_builder/lnn_connection_fsm_test.cpp +++ b/tests/core/bus_center/lnn/net_builder/lnn_connection_fsm_test.cpp @@ -219,4 +219,26 @@ HWTEST_F(LnnConnectionFsmTest, LNN_STOP_CONNECTION_FSM_TEST_001, TestSize.Level0 int32_t ret = LnnStopConnectionFsm(fsm, FsmStopCallback); EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); } + +/* +* @tc.name: ON_JOIN_META_NODE_TEST_001 +* @tc.desc: test OnJoinMetaNode +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(LnnConnectionFsmTest, ON_JOIN_META_NODE_TEST_001, TestSize.Level1) +{ + MetaJoinRequestNode metaJoinNode; + CustomData dataKey = {0}; + int32_t ret; + + (void)memset_s(&metaJoinNode, sizeof(MetaJoinRequestNode), 0, sizeof(MetaJoinRequestNode)); + ret = OnJoinMetaNode(nullptr, &dataKey); + EXPECT_TRUE(ret == SOFTBUS_ERR); + ret = OnJoinMetaNode(&metaJoinNode, nullptr); + EXPECT_TRUE(ret == SOFTBUS_ERR); + metaJoinNode.addr.type = CONNECTION_ADDR_SESSION; + ret = OnJoinMetaNode(&metaJoinNode, &dataKey); + EXPECT_TRUE(ret == SOFTBUS_ERR); +} } // namespace OHOS diff --git a/tests/core/bus_center/lnn/net_builder/lnn_net_builder_test.cpp b/tests/core/bus_center/lnn/net_builder/lnn_net_builder_test.cpp index ac68273ff1da52420b69955692a4575ea678ea00..8df91536cf2e43e2ee971729f51faf2ac6c2ae13 100644 --- a/tests/core/bus_center/lnn/net_builder/lnn_net_builder_test.cpp +++ b/tests/core/bus_center/lnn/net_builder/lnn_net_builder_test.cpp @@ -23,6 +23,7 @@ #include "softbus_errcode.h" #include "softbus_log.h" #include "bus_center_event.h" +#include "bus_center_manager.h" constexpr char NETWORKID[] = "ABCDEFG"; constexpr char OLD_NETWORKID[] = "ABCDEFG"; @@ -210,4 +211,45 @@ HWTEST_F(LnnNetBuilderTest, LNN_UPDATE_NODE_ADDR_TEST_001, TestSize.Level0) ret = LnnUpdateNodeAddr(MASTER_UDID); EXPECT_TRUE(ret == SOFTBUS_OK); } + +/* +* @tc.name: META_NODE_SERVER_JOIN_TEST_001 +* @tc.desc: test MetaNodeServerJoin +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(LnnNetBuilderTest, META_NODE_SERVER_JOIN_TEST_001, TestSize.Level0) +{ + ConnectionAddr addr = { + .type = CONNECTION_ADDR_WLAN, + .info.ip.port = PORT + }; + CustomData dataKey = {0}; + int32_t ret; + + (void)memset_s(&addr, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); + ret = LnnInitNetBuilder(); + EXPECT_TRUE(ret == SOFTBUS_OK); + ret = MetaNodeServerJoin(&addr, &dataKey); + EXPECT_TRUE(ret == SOFTBUS_OK); +} + +/* +* @tc.name: META_NODE_SERVER_LEAVE_TEST_001 +* @tc.desc: test MetaNodeServerLeave +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(LnnNetBuilderTest, META_NODE_SERVER_LEAVE_TEST_001, TestSize.Level0) +{ + const char *networkId = "1234"; + int32_t ret; + + ret = MetaNodeServerLeave(networkId); + EXPECT_TRUE(ret == SOFTBUS_NO_INIT); + ret = LnnInitNetBuilder(); + EXPECT_TRUE(ret == SOFTBUS_OK); + ret = MetaNodeServerLeave(networkId); + EXPECT_TRUE(ret == SOFTBUS_OK); +} } // namespace OHOS diff --git a/tests/core/bus_center/lnn/unittest/net_ledger_test.cpp b/tests/core/bus_center/lnn/unittest/net_ledger_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91485e858aa2028e3a80f90444407c7a596333a1 --- /dev/null +++ b/tests/core/bus_center/lnn/unittest/net_ledger_test.cpp @@ -0,0 +1,83 @@ +/* + * 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 +#include +#include "lnn_decision_db.h" +#include "lnn_decision_db.c" + +namespace OHOS { +using namespace testing::ext; +constexpr uint32_t TEST_DATA_LEN = 10; + +class NetLedgerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void NetLedgerTest::SetUpTestCase() +{ +} + +void NetLedgerTest::TearDownTestCase() +{ +} + +void NetLedgerTest::SetUp() +{ + LOG_INFO("NetLedgerTest start."); +} + +void NetLedgerTest::TearDown() +{ +} + +/* +* @tc.name: BUILD_TRUSTED_DEV_INFO_RECORD_Test_001 +* @tc.desc: build trusted dev info record test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(NetLedgerTest, BUILD_TRUSTED_DEV_INFO_RECORD_Test_001, TestSize.Level1) +{ + const char *udid = "testdata"; + TrustedDevInfoRecord record; + int32_t ret; + + (void)memset_s(&record, sizeof(TrustedDevInfoRecord), 0, sizeof(TrustedDevInfoRecord)); + ret = BuildTrustedDevInfoRecord(udid, &record); + EXPECT_TRUE(ret == SOFTBUS_OK); +} + +/* +* @tc.name: LNN_GET_TRUSTED_DEV_INFO_FROM_DB_Test_001 +* @tc.desc: lnn get trusted dev info from db test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(NetLedgerTest, LNN_GET_TRUSTED_DEV_INFO_FROM_DB_Test_001, TestSize.Level1) +{ + uint32_t num = 0; + int32_t ret; + + char *udidArray = (char *)SoftBusMalloc(TEST_DATA_LEN); + ret = LnnGetTrustedDevInfoFromDb(&udidArray, &num); + EXPECT_TRUE(ret == SOFTBUS_ERR); + SoftBusFree(udidArray); +} +} // namespace OHOS