diff --git a/tests/core/bus_center/lnn/BUILD.gn b/tests/core/bus_center/lnn/BUILD.gn index d5b8512c74..c1e73ad73b 100644 --- a/tests/core/bus_center/lnn/BUILD.gn +++ b/tests/core/bus_center/lnn/BUILD.gn @@ -19,6 +19,8 @@ module_output_path = "dsoftbus/LNN" ohos_unittest("LNNTest") { module_out_path = module_output_path sources = [ + "ipc/bus_center_client_proxy_standard_test.cpp", + "ipc/lnn_bus_center_ipc_test.cpp", "net_builder/lnn_connection_fsm_test.cpp", "net_builder/lnn_network_info_test.cpp", "net_builder/lnn_node_weight_test.cpp", @@ -46,13 +48,18 @@ ohos_unittest("LNNTest") { "$dsoftbus_root_path/core/authentication/interface", "$dsoftbus_root_path/core/bus_center/interface", "$dsoftbus_root_path/core/bus_center/utils/include", + "$dsoftbus_root_path/core/bus_center/ipc/standard/include", + "$dsoftbus_root_path/core/bus_center/lnn/lane_hub/time_sync/include", + "$dsoftbus_root_path/core/bus_center/ipc/include", "$dsoftbus_root_path/interfaces/kits/bus_center", "$dsoftbus_root_path/interfaces/kits/common", "$dsoftbus_root_path/core/adapter/bus_center/include", + "$dsoftbus_root_path/sdk/frame/standard/include", "//commonlibrary/c_utils/base/include", "//third_party/cJSON", "unittest/common/", "$dsoftbus_root_path/core/connection/manager", + "$dsoftbus_root_path/core/frame/standard/client_manager/include", "$dsoftbus_root_path/adapter/common/bus_center/include/", "$dsoftbus_root_path/core/discovery/manager/include", "$dsoftbus_root_path/core/discovery/interface", @@ -65,6 +72,7 @@ ohos_unittest("LNNTest") { "$dsoftbus_root_path/core/common:softbus_utils", "$dsoftbus_root_path/core/frame:softbus_server", "//base/security/device_auth/services:deviceauth_sdk", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", "//third_party/googletest:gtest_main", ] diff --git a/tests/core/bus_center/lnn/ipc/bus_center_client_proxy_standard_test.cpp b/tests/core/bus_center/lnn/ipc/bus_center_client_proxy_standard_test.cpp new file mode 100644 index 0000000000..f7180bb3a5 --- /dev/null +++ b/tests/core/bus_center/lnn/ipc/bus_center_client_proxy_standard_test.cpp @@ -0,0 +1,133 @@ +/* +* Copyright (c) 2021 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "bus_center_client_proxy_standard.h" +#include "bus_center_client_proxy.h" +#include "auth_interface.h" +#include "bus_center_info_key.h" +#include "bus_center_manager.h" +#include "lnn_connection_addr_utils.h" +#include "lnn_network_manager.h" +#include "lnn_distributed_net_ledger.h" +#include "lnn_event_monitor.h" +#include "lnn_local_net_ledger.h" +#include "lnn_sync_item_info.h" +#include "softbus_bus_center.h" +#include "softbus_conn_interface.h" +#include "lnn_ipc_utils.h" +#include "lnn_meta_node_ledger.h" +#include "lnn_time_sync_manager.h" +#include "softbus_def.h" +#include "softbus_client_info_manager.h" +#include "softbus_errcode.h" +#include "softbus_ipc_def.h" +#include "softbus_log.h" +#include "message_parcel.h" +#include "softbus_permission.h" +#include "lnn_bus_center_ipc.h" + +namespace OHOS { +using namespace testing::ext; + static sptr GetClientProxy(const char *pkgName) + { + sptr clientObject = SoftbusClientInfoManager::GetInstance().GetSoftbusClientProxy(pkgName); + sptr clientProxy = new (std::nothrow) BusCenterClientProxy(clientObject); + return clientProxy; + } + + class BusCenterClientProxyStandardTest : public testing::Test { + public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + }; + + void BusCenterClientProxyStandardTest::SetUpTestCase() + { + } + + void BusCenterClientProxyStandardTest::TearDownTestCase() + { + } + + void BusCenterClientProxyStandardTest::SetUp() + { + } + + void BusCenterClientProxyStandardTest::TearDown() + { + } + + /* + * @tc.name: ON_JOIN_META_NODE_RESULT_Test_001 + * @tc.desc: On Join Meta Node Result test + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F(BusCenterClientProxyStandardTest, ON_JOIN_META_NODE_RESULT_Test_001, TestSize.Level0) + { + void *addr = nullptr; + uint32_t addrTypeLen = 0; + ConnectionAddr addrValue; + (void)memset_s(&addrValue, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); + char *networkId = nullptr; + char networkIdValue[] = "12345"; + int32_t retCode = 0; + char pkgNameValue[] = "test"; + sptr clientProxy = GetClientProxy(pkgNameValue); + int32_t ret = clientProxy->BusCenterClientProxy::OnJoinMetaNodeResult(addr, addrTypeLen, networkId, retCode); + EXPECT_EQ(ret, SOFTBUS_ERR); + retCode = 1; + ret = clientProxy->BusCenterClientProxy::OnJoinMetaNodeResult(addr, addrTypeLen, networkIdValue, retCode); + EXPECT_TRUE(ret == SOFTBUS_ERR); + ret = clientProxy->BusCenterClientProxy::OnJoinMetaNodeResult(&addrValue, addrTypeLen, networkIdValue, retCode); + EXPECT_TRUE(ret == SOFTBUS_ERR); + } + + /* + * @tc.name: ON_LEAVE_META_NODE_RESULT_Test_001 + * @tc.desc: On Leave Meta Node Result test + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F(BusCenterClientProxyStandardTest, ON_LEAVE_META_NODE_RESULT_Test_001, TestSize.Level0) + { + char *networkId = nullptr; + char pkgNameValue[] = "test"; + char networkIdValue[] = "12345"; + int32_t retCode = 0; + sptr clientProxy = GetClientProxy(pkgNameValue); + int32_t ret = clientProxy->BusCenterClientProxy::OnLeaveMetaNodeResult(networkId, retCode); + EXPECT_TRUE(ret == SOFTBUS_ERR); + ret = clientProxy->BusCenterClientProxy::OnLeaveMetaNodeResult(networkIdValue, retCode); + EXPECT_TRUE(ret == SOFTBUS_ERR); + } +} // namespace OHOS diff --git a/tests/core/bus_center/lnn/ipc/lnn_bus_center_ipc_test.cpp b/tests/core/bus_center/lnn/ipc/lnn_bus_center_ipc_test.cpp new file mode 100644 index 0000000000..9cd679ba9c --- /dev/null +++ b/tests/core/bus_center/lnn/ipc/lnn_bus_center_ipc_test.cpp @@ -0,0 +1,192 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "auth_interface.h" +#include "bus_center_info_key.h" +#include "bus_center_manager.h" +#include "lnn_connection_addr_utils.h" +#include "lnn_network_manager.h" +#include "lnn_distributed_net_ledger.h" +#include "lnn_event_monitor.h" +#include "lnn_local_net_ledger.h" +#include "lnn_sync_item_info.h" +#include "softbus_bus_center.h" +#include "softbus_conn_interface.h" +#include "lnn_ipc_utils.h" +#include "lnn_meta_node_ledger.h" +#include "lnn_time_sync_manager.h" +#include "softbus_def.h" +#include "softbus_errcode.h" +#include "softbus_log.h" +#include "softbus_permission.h" +#include "lnn_bus_center_ipc.h" + +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: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + }; + + void LnnBusCenterIpcTest::SetUpTestCase() + { + EXPECT_TRUE(InitServer() == SOFTBUS_OK); + sleep(DEFAULT_TIME); + } + + void LnnBusCenterIpcTest::TearDownTestCase() + { + } + + void LnnBusCenterIpcTest::SetUp() + { + } + + void LnnBusCenterIpcTest::TearDown() + { + } + + /* + * @tc.name: META_NODE_IPC_SERVER_JOIN_Test_001 + * @tc.desc: Meta Node Ipc Server Join test + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_SERVER_JOIN_Test_001, TestSize.Level0) + { + char *pkgName = nullptr; + void *addr = nullptr; + CustomData dataKey; + memcpy_s(dataKey.data, sizeof(CustomData), "test", DEFAULT_SIZE); + uint32_t addrTypeLen = 0; + ConnectionAddr addrValue; + (void)memset_s(&addrValue, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); + char pkgNameValue[DEFAULT_LEN] = "test"; + int32_t ret = MetaNodeIpcServerJoin(pkgName, addr, &dataKey, addrTypeLen); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ret = MetaNodeIpcServerJoin(pkgNameValue, (void *)&addrValue, &dataKey, addrTypeLen); + EXPECT_TRUE(ret == SOFTBUS_NO_INIT); + } + + /* + * @tc.name: META_NODE_IPC_SERVER_LEAVE_Test_001 + * @tc.desc: Meta Node Ipc Server Leave test + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_SERVER_LEAVE_Test_001, TestSize.Level0) + { + char *pkgName = nullptr; + char *networkId = nullptr; + char pkgNameValue[DEFAULT_LEN] = "test"; + char networkIdValue[DEFAULT_LEN] = "12345"; + int32_t ret = MetaNodeIpcServerLeave(pkgName, networkId); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ret = MetaNodeIpcServerLeave(pkgNameValue, networkId); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ret = MetaNodeIpcServerLeave(pkgNameValue, networkIdValue); + EXPECT_TRUE(ret == SOFTBUS_NO_INIT); + } + + /* + * @tc.name: META_NODE_IPC_NOTIFY_JOIN_RESULT_Test_001 + * @tc.desc: Meta Node Ipc Notify Join Result test + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_NOTIFY_JOIN_RESULT_Test_001, TestSize.Level0) + { + void *addr = nullptr; + uint32_t addrTypeLen = 0; + ConnectionAddr addrValue; + (void)memset_s(&addrValue, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); + char *networkId = nullptr; + char networkIdValue[DEFAULT_LEN] = "1234"; + int32_t retCode = 0; + CustomData dataKey; + memcpy_s(dataKey.data, sizeof(CustomData), "test", DEFAULT_SIZE); + int32_t ret = MetaNodeIpcNotifyJoinResult(addr, addrTypeLen, networkId, retCode); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ret = MetaNodeIpcNotifyJoinResult((void *)&addrValue, addrTypeLen, networkIdValue, retCode); + EXPECT_TRUE(ret == SOFTBUS_OK); + } + + /* + * @tc.name: META_NODE_IPC_NOTIFY_LEAVE_RESULT_Test_001 + * @tc.desc: Meta Node Ipc Notify Leave Result test + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_NOTIFY_LEAVE_RESULT_Test_001, TestSize.Level0) + { + char *networkId = nullptr; + char networkIdValue[DEFAULT_LEN] = "12345"; + int32_t retCode = 0; + int32_t ret = MetaNodeIpcNotifyLeaveResult(networkId, retCode); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ret = MetaNodeIpcNotifyLeaveResult(networkIdValue, retCode); + EXPECT_TRUE(ret == SOFTBUS_OK); + } +} // namespace OHOS diff --git a/tests/sdk/bus_center/unittest/BUILD.gn b/tests/sdk/bus_center/unittest/BUILD.gn index 3dbbae2f65..03acddfdc7 100644 --- a/tests/sdk/bus_center/unittest/BUILD.gn +++ b/tests/sdk/bus_center/unittest/BUILD.gn @@ -29,6 +29,7 @@ bus_center_sdk_test_inc = [ "$dsoftbus_root_path/tests/sdk/common/include", "//commonlibrary/c_utils/base/include", "//third_party/bounds_checking_function/include", + "$dsoftbus_root_path/sdk/bus_center/manager/include", ] bus_center_sdk_test_deps = [ "$dsoftbus_root_path/core/frame:softbus_server", diff --git a/tests/sdk/bus_center/unittest/bus_center_sdk_test.cpp b/tests/sdk/bus_center/unittest/bus_center_sdk_test.cpp index a7130f7a22..46272ea59b 100644 --- a/tests/sdk/bus_center/unittest/bus_center_sdk_test.cpp +++ b/tests/sdk/bus_center/unittest/bus_center_sdk_test.cpp @@ -22,6 +22,7 @@ #include "softbus_def.h" #include "softbus_errcode.h" #include "softbus_utils.h" +#include "client_bus_center_manager.h" namespace OHOS { using namespace testing::ext; @@ -500,4 +501,94 @@ HWTEST_F(BusCenterSdkTest, RefreshLNNTest002, TestSize.Level0) ret = StopRefreshLNN(TEST_PKG_NAME_1, tmpId3); EXPECT_TRUE(ret == 0); } + +/** +* @tc.name: SET_NODE_DATA_CHANGE_FLAG_INNER_Test001 +* @tc.desc: Set Node Data Change Flag Inner +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterSdkTest, SET_NODE_DATA_CHANGE_FLAG_INNER_Test001, TestSize.Level0) +{ + char pkgName[] = "test"; + char *networkId = nullptr; + uint16_t dataChangeFlag = 0; + int32_t ret = SetNodeDataChangeFlagInner(pkgName, networkId, dataChangeFlag); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); +} + +/* +* @tc.name: JOIN_META_NODE_INNER_Test001 +* @tc.desc: JoinMetaNodeInner +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterSdkTest, JOIN_META_NODE_INNER_Test001, TestSize.Level1) +{ + char pkgName[] = "test"; + CustomData dataKey; + (void)memset_s(&dataKey, sizeof(CustomData), 0, sizeof(CustomData)); + OnJoinMetaNodeResult cb = nullptr; + ConnectionAddr *target = nullptr; + int32_t ret = JoinMetaNodeInner(pkgName, target, &dataKey, cb); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); +} + +/* +* @tc.name: LEAVE_META_NODE_INNER_Test001 +* @tc.desc: Leave Meta Node Inner +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterSdkTest, LEAVE_META_NODE_INNER_Test001, TestSize.Level1) +{ + char pkgName[] = "test"; + char networkId[] = "0123456789"; + char *networkId1 = nullptr; + OnLeaveMetaNodeResult cb = nullptr; + int32_t ret = LeaveMetaNodeInner(pkgName, networkId1, cb); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + printf("LeaveMetaNodeInner ret2 = %d\n", ret); + ret = LeaveMetaNodeInner(pkgName, networkId, cb); + EXPECT_TRUE(ret == SOFTBUS_OK); + printf("LeaveMetaNodeInner ret3 = %d\n", ret); +} + +/* +* @tc.name: META_NODE_ON_JOIN_RESULT_Test001 +* @tc.desc: Meta Node On Join Result +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterSdkTest, META_NODE_ON_JOIN_RESULT_Test001, TestSize.Level1) +{ + void *addr = nullptr; + char networkId[] = "0123456789"; + int32_t retCode = SOFTBUS_OK; + int32_t ret = MetaNodeOnJoinResult(addr, networkId, retCode); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ConnectionAddr connAddr; + (void)memset_s(&connAddr, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); + addr = (void*)&connAddr; + ret = MetaNodeOnJoinResult(addr, networkId, retCode); + EXPECT_TRUE(ret == SOFTBUS_OK); +} + +/* +* @tc.name: META_NODE_ON_LEAVE_RESULT_Test001 +* @tc.desc: Meta Node On Leave Result +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(BusCenterSdkTest, META_NODE_ON_LEAVE_RESULT_Test001, TestSize.Level1) +{ + int32_t retCode = SOFTBUS_OK; + char networkId[] = "ABCDEFG"; + char *networkId1 = nullptr; + int32_t ret = MetaNodeOnLeaveResult(networkId1, retCode); + EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); + ret = MetaNodeOnLeaveResult(networkId, retCode); + EXPECT_TRUE(ret == SOFTBUS_OK); +} + } // namespace OHOS diff --git a/tests/sdk/bus_center/unittest/softbus_center_sdk_test.cpp b/tests/sdk/bus_center/unittest/softbus_center_sdk_test.cpp old mode 100755 new mode 100644