• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
19 #include "bus_center_info_key.h"
20 #include "lnn_connection_addr_utils.h"
21 #include "lnn_network_id.h"
22 #include "softbus_bus_center.h"
23 #include "softbus_errcode.h"
24 
25 namespace OHOS {
26 using namespace testing::ext;
27 
28 constexpr char BT_MAC[] = "12:34:56:78";
29 constexpr char WLAN_IP[] = "10.146.181.134";
30 
31 class NetBuilderTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase()39 void NetBuilderTest::SetUpTestCase()
40 {
41 }
42 
TearDownTestCase()43 void NetBuilderTest::TearDownTestCase()
44 {
45 }
46 
SetUp()47 void NetBuilderTest::SetUp()
48 {
49 }
50 
TearDown()51 void NetBuilderTest::TearDown()
52 {
53 }
54 
55 /*
56 * @tc.name: NET_BUILDER_GEN_ID_Test_001
57 * @tc.desc: generate network id interface test
58 * @tc.type: FUNC
59 * @tc.require: AR000FK6J3
60 */
61 HWTEST_F(NetBuilderTest, NET_BUILDER_GEN_ID_Test_001, TestSize.Level0)
62 {
63     char networkIdFirst[NETWORK_ID_BUF_LEN] = {0};
64     char networkIdSecond[NETWORK_ID_BUF_LEN] = {0};
65 
66     EXPECT_TRUE(LnnGenLocalNetworkId(networkIdFirst, NETWORK_ID_BUF_LEN) == SOFTBUS_OK);
67     EXPECT_TRUE(LnnGenLocalNetworkId(networkIdSecond, NETWORK_ID_BUF_LEN) == SOFTBUS_OK);
68     EXPECT_TRUE(strncmp(networkIdFirst, networkIdSecond, NETWORK_ID_BUF_LEN) != 0);
69 }
70 
71 /*
72 * @tc.name: NET_BUILDER_GEN_ID_Test_002
73 * @tc.desc: generate uuid interface test
74 * @tc.type: FUNC
75 * @tc.require: AR000FK6J3
76 */
77 HWTEST_F(NetBuilderTest, NET_BUILDER_GEN_ID_Test_002, TestSize.Level0)
78 {
79     char uuidFirst[UUID_BUF_LEN] = {0};
80     char uuidSecond[UUID_BUF_LEN] = {0};
81 
82     EXPECT_TRUE(LnnGenLocalUuid(uuidFirst, UUID_BUF_LEN) == SOFTBUS_OK);
83     EXPECT_TRUE(LnnGenLocalUuid(uuidSecond, UUID_BUF_LEN) == SOFTBUS_OK);
84     EXPECT_TRUE(strncmp(uuidFirst, uuidSecond, UUID_BUF_LEN) == 0);
85 }
86 
87 /*
88 * @tc.name: NET_BUILDER_CONNECTION_ADDR_Test_001
89 * @tc.desc: connection address compare interface test
90 * @tc.type: FUNC
91 * @tc.require: AR000FK6J2
92 */
93 HWTEST_F(NetBuilderTest, NET_BUILDER_CONNECTION_ADDR_Test_001, TestSize.Level0)
94 {
95     ConnectionAddr bleAddr = {
96         .type = CONNECTION_ADDR_BR,
97     };
98     ConnectionAddr ethAddr = {
99         .type = CONNECTION_ADDR_ETH,
100     };
101 
102     EXPECT_TRUE(strncpy_s(bleAddr.info.br.brMac, BT_MAC_LEN, BT_MAC, strlen(BT_MAC)) == EOK);
103     EXPECT_TRUE(strncpy_s(bleAddr.info.ip.ip, IP_STR_MAX_LEN, WLAN_IP, strlen(WLAN_IP)) == EOK);
104     EXPECT_TRUE(LnnIsSameConnectionAddr(&bleAddr, &bleAddr));
105     EXPECT_TRUE(LnnIsSameConnectionAddr(&ethAddr, &ethAddr));
106     EXPECT_FALSE(LnnIsSameConnectionAddr(&bleAddr, &ethAddr));
107 }
108 } // namespace OHOS
109