• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include <gtest/gtest.h>
17 #include <hdf_log.h>
18 #include "../../../chip/hdi_service/iface_tool.h"
19 #include "../../../chip/hdi_service/wifi_chip.h"
20 #include "wifi_hal_fn.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::HDI::Wlan::Chip::V2_0;
24 
25 namespace WifiChipTest {
26 const std::string TEST_AP_IFNAME = "wlan1";
27 const std::string TEST_STA_IFNAME = "wlan0";
28 const std::string TEST_P2P_IFNAME = "p2p0";
29 
30 class WifiChipTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {}
TearDownTestCase()33     static void TearDownTestCase() {}
SetUp()34     void SetUp()
35     {
36         int32_t chipId = 0;
37         bool isPrimary = true;
38         ifaceTool = std::make_shared<IfaceTool>();
39         WifiHalFn fn;
40         InitWifiHalFuncTable(&fn);
41         wifiVendorHalTest = std::make_shared<WifiVendorHal>(ifaceTool, fn, true);
42         wifiChip = new WifiChip(chipId, isPrimary, wifiVendorHalTest,
43             std::make_shared<IfaceUtil>(ifaceTool), HandlerMock);
44     }
TearDown()45     void TearDown() {}
46 
HandlerMock(const std::string & ifName)47     static void HandlerMock(const std::string& ifName)
48     {
49         HDF_LOGI("HandlerMock enter");
50     }
51 
52 public:
53     std::shared_ptr<WifiVendorHal> wifiVendorHalTest;
54     std::shared_ptr<IfaceTool> ifaceTool;
55     sptr<WifiChip> wifiChip;
56 };
57 
58 /**
59  * @tc.name: GetCurrentModeTest
60  * @tc.desc: GetCurrentMode
61  * @tc.type: FUNC
62  * @tc.require:
63  */
64 HWTEST_F(WifiChipTest, GetCurrentModeTest, TestSize.Level0)
65 {
66     HDF_LOGI("GetCurrentModeTest started");
67     uint32_t modeId = -1;
68     EXPECT_TRUE(wifiChip->GetCurrentMode(modeId) == HDF_ERR_INVALID_PARAM);
69     modeId = 0;
70     wifiChip->GetCurrentMode(modeId);
71     wifiChip->RegisterChipEventCallback(nullptr);
72 }
73 
74 /**
75  * @tc.name: SetChipModeTest
76  * @tc.desc: SetChipMode
77  * @tc.type: FUNC
78  * @tc.require:
79  */
80 HWTEST_F(WifiChipTest, SetChipModeTest, TestSize.Level0)
81 {
82     HDF_LOGI("SetChipModeTest started");
83     uint32_t modeId = UINT32_MAX;
84     EXPECT_TRUE(wifiChip->SetChipMode(modeId) == HDF_FAILURE);
85 }
86 
87 /**
88  * @tc.name: CreateApServiceTest
89  * @tc.desc: CreateApService
90  * @tc.type: FUNC
91  * @tc.require:
92  */
93 HWTEST_F(WifiChipTest, CreateApServiceTest, TestSize.Level0)
94 {
95     HDF_LOGI("CreateApServiceTest started");
96     std::vector<std::string> instances;
97     std::weak_ptr<IfaceTool> ifaceTool = std::make_shared<IfaceTool>();
98     WifiHalFn fn;
99     std::weak_ptr<WifiVendorHal> vendorHal = std::make_shared<WifiVendorHal>(ifaceTool, fn, true);
100     sptr<IChipIface> apIface = new (std::nothrow) WifiApIface(TEST_AP_IFNAME, instances, vendorHal,
101         std::make_shared<IfaceUtil>(ifaceTool));
102     wifiChip->CreateApService(apIface);
103     std::vector<std::string> ifnames;
104     wifiChip->GetApServiceIfNames(ifnames);
105     std::string ifname1;
106     wifiChip->GetApService(ifname1, apIface);
107     wifiChip->RemoveApService(ifname1);
108     EXPECT_TRUE(wifiChip->GetApServiceIfNames(ifnames) == HDF_FAILURE);
109     EXPECT_TRUE(wifiChip->GetApService(ifname1, apIface) == HDF_FAILURE);
110 }
111 
112 /**
113  * @tc.name: CreateP2pIfaceTest
114  * @tc.desc: CreateP2pIface
115  * @tc.type: FUNC
116  * @tc.require:
117  */
118 HWTEST_F(WifiChipTest, CreateP2pIfaceTest, TestSize.Level0)
119 {
120     HDF_LOGI("CreateP2pIfaceTest started");
121     std::weak_ptr<IfaceTool> ifaceTool = std::make_shared<IfaceTool>();
122     WifiHalFn fn;
123     std::weak_ptr<WifiVendorHal> vendorHal = std::make_shared<WifiVendorHal>(ifaceTool, fn, true);
124     sptr<IChipIface> p2pIface = new (std::nothrow) WifiP2pIface(TEST_P2P_IFNAME, vendorHal,
125         std::make_shared<IfaceUtil>(ifaceTool));
126     wifiChip->CreateP2pService(p2pIface);
127     std::vector<std::string> ifnames;
128     wifiChip->GetP2pServiceIfNames(ifnames);
129     std::string ifname1;
130     wifiChip->GetP2pService(ifname1, p2pIface);
131     wifiChip->RemoveP2pService(ifname1);
132     EXPECT_TRUE(wifiChip->GetP2pServiceIfNames(ifnames) == HDF_FAILURE);
133     EXPECT_TRUE(wifiChip->GetP2pService(ifname1, p2pIface) == HDF_FAILURE);
134 }
135 
136 /**
137  * @tc.name: CreateStaIfaceTest
138  * @tc.desc: CreateStaIface
139  * @tc.type: FUNC
140  * @tc.require:
141  */
142 HWTEST_F(WifiChipTest, CreateStaIfaceTest, TestSize.Level0)
143 {
144     HDF_LOGI("CreateStaIfaceTest started");
145     std::weak_ptr<IfaceTool> ifaceTool = std::make_shared<IfaceTool>();
146     WifiHalFn fn;
147     std::weak_ptr<WifiVendorHal> vendorHal = std::make_shared<WifiVendorHal>(ifaceTool, fn, true);
148     sptr<IChipIface> staIface = new (std::nothrow) WifiStaIface(TEST_STA_IFNAME, vendorHal,
149         std::make_shared<IfaceUtil>(ifaceTool));
150     wifiChip->CreateStaService(staIface);
151 
152     std::vector<std::string> ifnames;
153     wifiChip->GetStaServiceIfNames(ifnames);
154     std::string ifname1;
155     wifiChip->GetStaService(ifname1, staIface);
156     wifiChip->RemoveStaService(ifname1);
157     EXPECT_TRUE(wifiChip->GetStaServiceIfNames(ifnames) == HDF_FAILURE);
158     EXPECT_TRUE(wifiChip->GetStaService(ifname1, staIface) == HDF_FAILURE);
159 }
160 }
161 
162