1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <securec.h> 18 #include <cstring> 19 #include <mutex> 20 #include <vector> 21 #include <arpa/inet.h> 22 #include <net/if.h> 23 #include <cstdint> 24 #include <cstdlib> 25 #include <string> 26 #include <sys/ioctl.h> 27 #include <sys/socket.h> 28 #include <sys/types.h> 29 #include <unistd.h> 30 #include <cerrno> 31 #include "auth_interface.h" 32 #include "bus_center_info_key.h" 33 #include "bus_center_manager.h" 34 #include "lnn_connection_addr_utils.h" 35 #include "lnn_network_manager.h" 36 #include "lnn_distributed_net_ledger.h" 37 #include "lnn_event_monitor.h" 38 #include "lnn_local_net_ledger.h" 39 #include "lnn_sync_item_info.h" 40 #include "softbus_bus_center.h" 41 #include "softbus_conn_interface.h" 42 #include "lnn_ipc_utils.h" 43 #include "lnn_meta_node_ledger.h" 44 #include "lnn_time_sync_manager.h" 45 #include "softbus_def.h" 46 #include "softbus_errcode.h" 47 #include "softbus_log.h" 48 #include "softbus_permission.h" 49 #include "lnn_bus_center_ipc.h" 50 51 namespace OHOS { 52 using namespace testing::ext; 53 constexpr uint8_t DEFAULT_LEN = 32; 54 constexpr uint8_t DEFAULT_SIZE = 5; 55 56 class LnnBusCenterIpcTest : public testing::Test { 57 public: 58 static void SetUpTestCase(); 59 static void TearDownTestCase(); 60 void SetUp(); 61 void TearDown(); 62 }; 63 SetUpTestCase()64 void LnnBusCenterIpcTest::SetUpTestCase() 65 { 66 } 67 TearDownTestCase()68 void LnnBusCenterIpcTest::TearDownTestCase() 69 { 70 } 71 SetUp()72 void LnnBusCenterIpcTest::SetUp() 73 { 74 } 75 TearDown()76 void LnnBusCenterIpcTest::TearDown() 77 { 78 } 79 80 /* 81 * @tc.name: META_NODE_IPC_SERVER_JOIN_Test_001 82 * @tc.desc: Meta Node Ipc Server Join test 83 * @tc.type: FUNC 84 * @tc.require: 85 */ 86 HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_SERVER_JOIN_Test_001, TestSize.Level0) 87 { 88 char *pkgName = nullptr; 89 void *addr = nullptr; 90 CustomData customData; 91 memcpy_s(customData.data, sizeof(CustomData), "test", DEFAULT_SIZE); 92 uint32_t addrTypeLen = 0; 93 ConnectionAddr addrValue; 94 (void)memset_s(&addrValue, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); 95 char pkgNameValue[DEFAULT_LEN] = "test"; 96 int32_t ret = MetaNodeIpcServerJoin(pkgName, addr, &customData, addrTypeLen); 97 EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); 98 ret = MetaNodeIpcServerJoin(pkgNameValue, (void *)&addrValue, &customData, addrTypeLen); 99 EXPECT_TRUE(ret == SOFTBUS_NO_INIT); 100 } 101 102 /* 103 * @tc.name: META_NODE_IPC_SERVER_LEAVE_Test_001 104 * @tc.desc: Meta Node Ipc Server Leave test 105 * @tc.type: FUNC 106 * @tc.require: 107 */ 108 HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_SERVER_LEAVE_Test_001, TestSize.Level0) 109 { 110 char *pkgName = nullptr; 111 char *networkId = nullptr; 112 char pkgNameValue[DEFAULT_LEN] = "test"; 113 char networkIdValue[DEFAULT_LEN] = "12345"; 114 int32_t ret = MetaNodeIpcServerLeave(pkgName, networkId); 115 EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); 116 ret = MetaNodeIpcServerLeave(pkgNameValue, networkId); 117 EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); 118 ret = MetaNodeIpcServerLeave(pkgNameValue, networkIdValue); 119 EXPECT_TRUE(ret == SOFTBUS_NO_INIT); 120 } 121 122 /* 123 * @tc.name: META_NODE_IPC_NOTIFY_JOIN_RESULT_Test_001 124 * @tc.desc: Meta Node Ipc Notify Join Result test 125 * @tc.type: FUNC 126 * @tc.require: 127 */ 128 HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_NOTIFY_JOIN_RESULT_Test_001, TestSize.Level0) 129 { 130 void *addr = nullptr; 131 uint32_t addrTypeLen = 0; 132 ConnectionAddr addrValue; 133 (void)memset_s(&addrValue, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr)); 134 char *networkId = nullptr; 135 char networkIdValue[DEFAULT_LEN] = "1234"; 136 int32_t retCode = 0; 137 CustomData customData; 138 memcpy_s(customData.data, sizeof(CustomData), "test", DEFAULT_SIZE); 139 int32_t ret = MetaNodeIpcNotifyJoinResult(addr, addrTypeLen, networkId, retCode); 140 EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); 141 ret = MetaNodeIpcNotifyJoinResult((void *)&addrValue, addrTypeLen, networkIdValue, retCode); 142 EXPECT_TRUE(ret == SOFTBUS_OK); 143 } 144 145 /* 146 * @tc.name: META_NODE_IPC_NOTIFY_LEAVE_RESULT_Test_001 147 * @tc.desc: Meta Node Ipc Notify Leave Result test 148 * @tc.type: FUNC 149 * @tc.require: 150 */ 151 HWTEST_F(LnnBusCenterIpcTest, META_NODE_IPC_NOTIFY_LEAVE_RESULT_Test_001, TestSize.Level0) 152 { 153 char *networkId = nullptr; 154 char networkIdValue[DEFAULT_LEN] = "12345"; 155 int32_t retCode = 0; 156 int32_t ret = MetaNodeIpcNotifyLeaveResult(networkId, retCode); 157 EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM); 158 ret = MetaNodeIpcNotifyLeaveResult(networkIdValue, retCode); 159 EXPECT_TRUE(ret == SOFTBUS_OK); 160 } 161 } // namespace OHOS 162