1 /*
2  * Copyright (C) 2024 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 #include <net/if_arp.h>
16 #include <gtest/gtest.h>
17 #include "mock_wifi_settings.h"
18 #include "multi_gateway.h"
19 
20 using ::testing::ext::TestSize;
21 
22 namespace OHOS {
23 namespace Wifi {
24 constexpr int32_t NUM_TEN = 10;
25 class MultiGatewayTest : public testing::Test {
26 public:
SetUpTestCase()27     static void SetUpTestCase() {}
TearDownTestCase()28     static void TearDownTestCase() {}
SetUp()29     virtual void SetUp() {}
TearDown()30     virtual void TearDown() {}
31 };
32 
33 HWTEST_F(MultiGatewayTest, GetGatewayAddr_test, TestSize.Level1)
34 {
35     DelayedSingleton<MultiGateway>::GetInstance()->GetGatewayAddr(0);
36 }
37 
38 HWTEST_F(MultiGatewayTest, IsMultiGateway_test, TestSize.Level1)
39 {
40     DelayedSingleton<MultiGateway>::GetInstance()->IsMultiGateway();
41 }
42 
43 HWTEST_F(MultiGatewayTest, GetNextGatewayMac_test, TestSize.Level1)
44 {
45     std::string mac = "";
46     DelayedSingleton<MultiGateway>::GetInstance()->GetNextGatewayMac(mac);
47 }
48 
49 HWTEST_F(MultiGatewayTest, SetStaticArp_test, TestSize.Level1)
50 {
51     std::string iface = "";
52     std::string ipAddr = "";
53     std::string macAddr = "";
54     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->SetStaticArp(iface, ipAddr, macAddr) == -1);
55     iface = "wlan0";
56     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->SetStaticArp(iface, ipAddr, macAddr) == -1);
57     ipAddr = "12.12.12.12";
58     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->SetStaticArp(iface, ipAddr, macAddr) == -1);
59     macAddr = "00:00:11:11:11:11";
60     DelayedSingleton<MultiGateway>::GetInstance()->SetStaticArp(iface, ipAddr, macAddr);
61 }
62 
63 HWTEST_F(MultiGatewayTest, DelStaticArp_test, TestSize.Level1)
64 {
65     std::string iface = "";
66     std::string ipAddr = "";
67     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->DelStaticArp(iface, ipAddr) == -1);
68     iface = "wlan0";
69     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->DelStaticArp(iface, ipAddr) == -1);
70     ipAddr = "12.12.12.12";
71     DelayedSingleton<MultiGateway>::GetInstance()->DelStaticArp(iface, ipAddr);
72 }
73 
74 HWTEST_F(MultiGatewayTest, DoArpItem_test, TestSize.Level1)
75 {
76     int32_t cmd = 1;
77     struct arpreq *req = nullptr;
78     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->DoArpItem(cmd, req) == -1);
79 }
80 
81 HWTEST_F(MultiGatewayTest, GetMacAddr_test, TestSize.Level1)
82 {
83     char *buff = nullptr;
84     const char *macAddr = nullptr;
85     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->GetMacAddr(buff, macAddr) == -1);
86     char buff1[NUM_TEN] = {0};
87     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->GetMacAddr(buff1, macAddr) == -1);
88     const char *macAddr1 = "11:22:33:44:55:66";
89     EXPECT_TRUE(DelayedSingleton<MultiGateway>::GetInstance()->GetMacAddr(buff1, macAddr1) == 0);
90 }
91 }
92 }